]>
Commit | Line | Data |
---|---|---|
f85f8ebb BP |
1 | =================================================== |
2 | Open vSwitch Configuration Database Specification | |
3 | =================================================== | |
4 | ||
5 | Basic Notation | |
6 | -------------- | |
7 | ||
8 | The descriptions below use the following shorthand notations for JSON | |
9 | values. Additional notation is presented later. | |
10 | ||
11 | <string> | |
12 | ||
12996ef9 | 13 | A JSON string. Any Unicode string is allowed, as specified by RFC |
bd76d25d | 14 | 4627. Implementations may disallow null bytes. |
f85f8ebb BP |
15 | |
16 | <id> | |
17 | ||
18 | A JSON string matching [a-zA-Z_][a-zA-Z0-9_]*. | |
19 | ||
20 | <id>s that begin with _ are reserved to the implementation and may | |
21 | not be used by the user. | |
22 | ||
23 | <boolean> | |
24 | ||
25 | A JSON true or false value. | |
26 | ||
27 | <number> | |
28 | ||
29 | A JSON number. | |
30 | ||
31 | <integer> | |
32 | ||
33 | A JSON number with an integer value, within a certain range | |
34 | (currently -2**63...+2**63-1). | |
35 | ||
6e79e210 BP |
36 | <value> |
37 | ||
38 | Any JSON value. | |
39 | ||
bd76d25d BP |
40 | <error> |
41 | ||
42 | A JSON object with the following members: | |
43 | ||
44 | "error": <string> required | |
45 | "details": <string> optional | |
46 | ||
47 | The value of the "error" member is a short string, specified in | |
48 | this document, that broadly indicates the class of the error. | |
49 | Most "error" strings are specific to contexts described elsewhere | |
50 | in this document, but the following "error" strings may appear in | |
51 | any context where an <error> is permitted: | |
52 | ||
53 | "error": "resources exhausted" | |
54 | ||
55 | The operation requires more resources (memory, disk, CPU, | |
56 | etc.) than are currently available to the database server. | |
57 | ||
58 | "error": "I/O error" | |
59 | ||
60 | Problems accessing the disk, network, or other required | |
61 | resources prevented the operation from completing. | |
62 | ||
63 | Database implementations may use "error" strings not specified | |
64 | in this document to indicate errors that do not fit into any of | |
65 | the specified categories. | |
66 | ||
67 | Optionally, an <error> may include a "details" member, whose value | |
68 | is a string that describes the error in more detail for the | |
69 | benefit of a human user or administrator. This document does not | |
70 | specify the format or content of the "details" string. | |
71 | ||
72 | An <error> may also have other members that describe the error in | |
73 | more detail. This document does not specify the names or values | |
74 | of these members. | |
75 | ||
f85f8ebb BP |
76 | Schema Format |
77 | ------------- | |
78 | ||
79 | An Open vSwitch configuration database consists of a set of tables, | |
80 | each of which has a number of columns and zero or more rows. A schema | |
81 | is represented by <database-schema>, as described below. | |
82 | ||
83 | <database-schema> | |
84 | ||
85 | A JSON object with the following members: | |
86 | ||
87 | "name": <id> required | |
88 | "comment": <string> optional | |
89 | "tables": {<id>: <table-schema>, ...} required | |
90 | ||
91 | The "name" identifies the database as a whole. The "comment" | |
92 | optionally provides more information about the database. The | |
93 | value of "tables" is a JSON object whose names are table names and | |
94 | whose values are <table-schema>s. | |
95 | ||
96 | <table-schema> | |
97 | ||
98 | A JSON object with the following members: | |
99 | ||
100 | "comment": <string> optional | |
101 | "columns": {<id>: <column-schema>, ...} required | |
102 | ||
103 | The "comment" optionally provides information about this table for | |
e68c3e48 JP |
104 | a human reader. The value of "columns" is a JSON object whose |
105 | names are column names and whose values are <column-schema>s. | |
f85f8ebb BP |
106 | |
107 | Every table has the following columns whose definitions are not | |
108 | included in the schema: | |
109 | ||
110 | "_uuid": This column, which contains exactly one UUID value, | |
111 | is initialized to a random value by the database engine when | |
112 | it creates a row. It is read-only, and its value never | |
113 | changes during the lifetime of a row. | |
114 | ||
115 | "_version": Like "_uuid", this column contains exactly one | |
116 | UUID value, initialized to a random value by the database | |
117 | engine when it creates a row, and it is read-only. However, | |
118 | its value changes to a new random value whenever any other | |
119 | field in the row changes. Furthermore, its value is | |
120 | ephemeral: when the database is closed and reopened, or when | |
121 | the database process is stopped and then started again, each | |
122 | "_version" also changes to a new random value. | |
123 | ||
124 | <column-schema> | |
125 | ||
126 | A JSON object with the following members: | |
127 | ||
128 | "comment": <string> optional | |
129 | "type": <type> required | |
130 | "ephemeral": <boolean> optional | |
131 | ||
132 | The "comment" optionally provides information about this column | |
133 | for a human reader. The "type" specifies the type of data stored | |
134 | in this column. If "ephemeral" is specified as true, then this | |
135 | column's values are not guaranteed to be durable; they may be lost | |
136 | when the database restarts. | |
137 | ||
138 | <type> | |
139 | ||
140 | The type of a database column. Either an <atomic-type> or a JSON | |
141 | object that describes the type of a database column, with the | |
142 | following members: | |
143 | ||
bd76d25d BP |
144 | "key": <base-type> required |
145 | "value": <base-type> optional | |
f85f8ebb BP |
146 | "min": <integer> optional |
147 | "max": <integer> or "unlimited" optional | |
148 | ||
149 | If "min" or "max" is not specified, each defaults to 1. If "max" | |
150 | is specified as "unlimited", then there is no specified maximum | |
151 | number of elements, although the implementation will enforce some | |
31a763d7 BP |
152 | limit. After considering defaults, "min" must be exactly 0 or |
153 | exactly 1, "max" must be at least 1, and "max" must be greater | |
154 | than or equal to "min". | |
f85f8ebb BP |
155 | |
156 | If "min" and "max" are both 1 and "value" is not specified, the | |
157 | type is the scalar type specified by "key". | |
158 | ||
159 | If "min" is not 1 or "max" is not 1, or both, and "value" is not | |
160 | specified, the type is a set of scalar type "key". | |
161 | ||
162 | If "value" is specified, the type is a map from type "key" to type | |
163 | "value". | |
164 | ||
bd76d25d BP |
165 | <base-type> |
166 | ||
167 | The type of a key or value in a database column. Either an | |
168 | <atomic-type> or a JSON object with the following members: | |
169 | ||
170 | "type": <atomic-type> required | |
171 | "minInteger": <integer> optional, integers only | |
172 | "maxInteger": <integer> optional, integers only | |
173 | "minReal": <real> optional, reals only | |
174 | "maxReal": <real> optional, reals only | |
175 | "reMatch": <string> optional, strings only | |
176 | "reComment": <string> optional, strings only | |
177 | "minLength": <integer> optional, strings only | |
178 | "maxLength": <integer> optional, strings only | |
179 | "refTable": <id> optional, uuids only | |
180 | ||
181 | An <atomic-type> by itself is equivalent to a JSON object with a | |
182 | single member "type" whose value is the <atomic-type>. | |
183 | ||
184 | If "type" is "integer", then "minInteger" or "maxInteger" or both | |
185 | may also be specified, restricting the valid integer range. If | |
186 | both are specified, then the maxInteger must be greater than or | |
187 | equal to minInteger. | |
188 | ||
189 | If "type" is "real", then "minReal" or "maxReal" or both may also | |
190 | be specified, restricting the valid real range. If both are | |
191 | specified, then the maxReal must be greater than or equal to | |
192 | minReal. | |
193 | ||
194 | If "type" is "string", then: | |
195 | ||
196 | "reMatch" may be a JavaScript (Perl 5-like) regular expression | |
197 | that restricts the allowed values. The regular expression | |
198 | must match the entire string value, that is, it is treated as | |
199 | if it begins with ^ and ends with $, regardless of whether it | |
200 | really does. | |
201 | ||
202 | If "reMatch" is specified, then "reComment" may be a string | |
203 | that describes the allowed values, phrased so that it fits | |
204 | into a sentence such as "This value must be...". | |
205 | ||
206 | "minLength" and "maxLength" or both may be specified, | |
207 | restricting the valid length of value strings. If both are | |
208 | specified, then maxLength must be greater than or equal to | |
209 | minLength. String length is measured in characters (not bytes | |
210 | or UTF-16 code units). | |
211 | ||
0d0f05b9 BP |
212 | If "type" is "uuid", then "refTable", if present, must be the name |
213 | of a table within this database. If "refTable" is set, the | |
214 | allowed UUIDs are limited to UUIDs for rows in the named table. | |
215 | ||
216 | "refTable" constraints are "deferred" constraints: they are | |
217 | enforced only at transaction commit time (see the "transact" | |
218 | request below). The other contraints on <base-type> are | |
219 | "immediate", enforced immediately by each operation. | |
bd76d25d | 220 | |
f85f8ebb BP |
221 | <atomic-type> |
222 | ||
223 | One of the strings "integer", "real", "boolean", "string", or | |
224 | "uuid", representing the specified scalar type. | |
225 | ||
226 | Wire Protocol | |
227 | ------------- | |
228 | ||
12996ef9 BP |
229 | The database wire protocol is implemented in JSON-RPC 1.0. We |
230 | encourage use of JSON-RPC over stream connections instead of JSON-RPC | |
231 | over HTTP, for these reasons: | |
232 | ||
233 | * JSON-RPC is a peer-to-peer protocol, but HTTP is a client-server | |
234 | protocol, which is a poor match. Thus, JSON-RPC over HTTP | |
235 | requires the client to periodically poll the server to receive | |
236 | server requests. | |
237 | ||
238 | * HTTP is more complicated than stream connections and doesn't | |
239 | provide any corresponding advantage. | |
240 | ||
241 | * The JSON-RPC specification for HTTP transport is incomplete. | |
242 | ||
243 | The database wire protocol consists of the following JSON-RPC methods: | |
f85f8ebb BP |
244 | |
245 | get_schema | |
246 | .......... | |
247 | ||
248 | Request object members: | |
249 | ||
250 | "method": "get_schema" required | |
251 | "params": [] required | |
252 | "id": any JSON value except null required | |
253 | ||
254 | Response object members: | |
255 | ||
256 | "result": <database-schema> | |
257 | "error": null | |
258 | "id": same "id" as request | |
259 | ||
260 | This operation retrieves a <database-schema> that describes the | |
261 | hosted database. | |
262 | ||
263 | transact | |
264 | ........ | |
265 | ||
266 | Request object members: | |
267 | ||
268 | "method": "transact" required | |
269 | "params": [<operation>*] required | |
270 | "id": any JSON value except null required | |
271 | ||
272 | Response object members: | |
273 | ||
274 | "result": [<object>*] | |
275 | "error": null | |
276 | "id": same "id" as request | |
277 | ||
278 | The "params" array for this method consists of zero or more JSON | |
279 | objects, each of which represents a single database operation. The | |
280 | "Operations" section below describes the valid operations. | |
281 | ||
282 | The value of "id" must be unique among all in-flight transactions | |
283 | within the current JSON-RPC session. Otherwise, the server may return | |
284 | a JSON-RPC error. | |
285 | ||
286 | The database server executes each of the specified operations in the | |
287 | specified order, except that if an operation fails, then the remaining | |
288 | operations are not executed. | |
289 | ||
290 | The set of operations is executed as a single atomic, consistent, | |
291 | isolated transaction. The transaction is committed only if every | |
292 | operation succeeds. Durability of the commit is not guaranteed unless | |
293 | the "commit" operation, with "durable" set to true, is included in the | |
294 | operation set (see below). | |
295 | ||
296 | Regardless of whether errors occur, the response is always a JSON-RPC | |
297 | response with null "error" and a "result" member that is an array with | |
298 | the same number of elements as "params". Each element of the "result" | |
299 | array corresponds to the same element of the "params" array. The | |
300 | "result" array elements may be interpreted as follows: | |
301 | ||
302 | - A JSON object that does not contain an "error" member indicates | |
303 | that the operation completed successfully. The specific members | |
304 | of the object are specified below in the descriptions of | |
305 | individual operations. Some operations do not produce any | |
306 | results, in which case the object will have no members. | |
307 | ||
bd76d25d BP |
308 | - An <error>, which indicates that the operation completed with an |
309 | error. | |
f85f8ebb BP |
310 | |
311 | - A JSON null value indicates that the operation was not attempted | |
312 | because a prior operation failed. | |
313 | ||
314 | In general, "result" contains some number of successful results, | |
315 | possibly followed by an error, in turn followed by enough JSON null | |
316 | values to match the number of elements in "params". There is one | |
317 | exception: if all of the operations succeed, but the results cannot be | |
0d0f05b9 BP |
318 | committed, then "result" will have one more element than "params", |
319 | with the additional element an <error>. The possible "error" strings | |
320 | include at least the following: | |
321 | ||
322 | "error": "referential integrity violation" | |
323 | ||
324 | When the commit was attempted, a column's value referenced the | |
325 | UUID for a row that did not exist in the table named by the | |
326 | column's <base-type> key or value "refTable". (This can be | |
327 | caused by inserting a row that references a nonexistent row, | |
328 | by deleting a row that is still referenced by another row, by | |
329 | specifying the UUID for a row in the wrong table, and other | |
330 | ways.) | |
f85f8ebb BP |
331 | |
332 | If "params" contains one or more "wait" operations, then the | |
333 | transaction may take an arbitrary amount of time to complete. The | |
334 | database implementation must be capable of accepting, executing, and | |
335 | replying to other transactions and other JSON-RPC requests while a | |
336 | transaction or transactions containing "wait" operations are | |
337 | outstanding on the same or different JSON-RPC sessions. | |
338 | ||
339 | The section "Notation for the Wire Protocol" below describes | |
340 | additional notation for use with the wire protocol. After that, the | |
341 | "Operations" section describes each operation. | |
342 | ||
343 | cancel | |
344 | ...... | |
345 | ||
346 | Request object members: | |
347 | ||
348 | "method": "cancel" required | |
6e79e210 | 349 | "params": [the "id" for an outstanding request] required |
f85f8ebb BP |
350 | "id": null required |
351 | ||
352 | Response object members: | |
353 | ||
354 | <no response> | |
355 | ||
356 | This JSON-RPC notification instructs the database server to | |
357 | immediately complete or cancel the "transact" request whose "id" is | |
358 | the same as the notification's "params" value. | |
359 | ||
360 | If the "transact" request can be completed immediately, then the | |
361 | server sends a response in the form described for "transact", above. | |
362 | Otherwise, the server sends a JSON-RPC error response of the following | |
363 | form: | |
364 | ||
365 | "result": null | |
366 | "error": "canceled" | |
367 | "id": the request "id" member | |
368 | ||
369 | The "cancel" notification itself has no reply. | |
370 | ||
a8425c53 BP |
371 | monitor |
372 | ....... | |
373 | ||
374 | Request object members: | |
375 | ||
376 | "method": "monitor" required | |
377 | "params": [<value>, <monitor-requests>] required | |
378 | "id": any JSON value except null required | |
379 | ||
380 | <monitor-requests> is an object that maps from a table name to a | |
381 | <monitor-request>. | |
382 | ||
383 | Each <monitor-request> is an object with the following members: | |
384 | ||
385 | "columns": [<column>*] optional | |
386 | "select": <monitor-select> optional | |
387 | ||
388 | <monitor-select> is an object with the following members: | |
389 | ||
390 | "initial": <boolean> optional | |
391 | "insert": <boolean> optional | |
392 | "delete": <boolean> optional | |
393 | "modify": <boolean> optional | |
394 | ||
395 | Response object members: | |
396 | ||
397 | "result": <table-updates> | |
398 | "error": null | |
399 | "id": same "id" as request | |
400 | ||
401 | This JSON-RPC request enables a client to replicate tables or subsets | |
402 | of tables. Each <monitor-request> specifies a table to be replicated. | |
403 | The JSON-RPC response to the "monitor" includes the initial contents | |
404 | of each table. Afterward, when changes to those tables are committed, | |
405 | the changes are automatically sent to the client using the "update" | |
406 | monitor notification. This monitoring persists until the JSON-RPC | |
407 | session terminates or until the client sends a "monitor_cancel" | |
408 | JSON-RPC request. | |
409 | ||
410 | Each <monitor-request> describes how to monitor a table: | |
411 | ||
412 | The circumstances in which an "update" notification is sent for a | |
413 | row within the table are determined by <monitor-select>: | |
414 | ||
415 | If "initial" is omitted or true, every row in the table is | |
416 | sent as part of the reply to the "monitor" request. | |
417 | ||
418 | If "insert" is omitted or true, "update" notifications are | |
419 | sent for rows newly inserted into the table. | |
420 | ||
421 | If "delete" is omitted or true, "update" notifications are | |
422 | sent for rows deleted from the table. | |
423 | ||
424 | If "modify" is omitted or true, "update" notifications are | |
425 | sent whenever when a row in the table is modified. | |
426 | ||
427 | The "columns" member specifies the columns whose values are | |
428 | monitored. If "columns" is omitted, all columns in the table, | |
429 | except for "_uuid", are monitored. | |
430 | ||
431 | The "result" in the JSON-RPC response to the "monitor" request is a | |
432 | <table-updates> object (see below) that contains the contents of the | |
433 | tables for which "initial" rows are selected. If no tables' initial | |
434 | contents are requested, then "result" is an empty object. | |
435 | ||
436 | update | |
437 | ...... | |
438 | ||
439 | Notification object members: | |
440 | ||
441 | "method": "update" | |
442 | "params": [<value>, <table-updates>] | |
443 | "id": null | |
444 | ||
445 | The <value> in "params" is the same as the value passed as the <value> | |
446 | in "params" for the "monitor" request. | |
447 | ||
448 | <table-updates> is an object that maps from a table name to a | |
449 | <table-update>. | |
450 | ||
451 | A <table-update> is an object that maps from the row's UUID (as a | |
452 | 36-byte string) to a <row-update> object. | |
453 | ||
454 | A <row-update> is an object with the following members: | |
455 | ||
456 | "old": <row> present for "delete" and "modify" updates | |
457 | "new": <row> present for "initial", "insert", and "modify" updates | |
458 | ||
459 | This JSON-RPC notification is sent from the server to the client to | |
460 | tell it about changes to a monitored table (or the initial state of a | |
461 | modified table). Each table in which one or more rows has changed (or | |
462 | whose initial view is being presented) is represented in "updates". | |
463 | Each row that has changed (or whose initial view is being presented) | |
464 | is represented in its <table-update> as a member with its name taken | |
465 | from the row's _uuid member. The corresponding value is a | |
466 | <row-update>: | |
467 | ||
468 | The "old" member is present for "delete" and "modify" updates. | |
469 | For "delete" updates, each monitored column is included. For | |
470 | "modify" updates, the prior value of each monitored column whose | |
471 | value has changed is included (monitored columns that have not | |
472 | changed are represented in "new"). | |
473 | ||
474 | The "new" member is present for "initial", "insert", and "modify" | |
475 | updates. For "initial" and "insert" updates, each monitored | |
476 | column is included. For "modify" updates, the new value of each | |
477 | monitored column is included. | |
478 | ||
479 | monitor_cancel | |
480 | .............. | |
481 | ||
482 | Request object members: | |
483 | ||
484 | "method": "monitor_cancel" required | |
485 | "params": [<value>] required | |
486 | "id": any JSON value except null required | |
487 | ||
488 | Response object members: | |
489 | ||
490 | "result": {} | |
491 | "error": null | |
492 | "id": the request "id" member | |
493 | ||
494 | Cancels the ongoing table monitor request, identified by the <value> | |
495 | in "params" matching the <value> in "params" for an ongoing "monitor" | |
496 | request. No more "update" messages will be sent for this table | |
497 | monitor. | |
498 | ||
6c2882f9 BP |
499 | echo |
500 | .... | |
501 | ||
502 | Request object members: | |
503 | ||
504 | "method": "echo" required | |
6e79e210 BP |
505 | "params": JSON array with any contents required |
506 | "id": <value> required | |
6c2882f9 BP |
507 | |
508 | Response object members: | |
509 | ||
510 | "result": same as "params" | |
511 | "error": null | |
512 | "id": the request "id" member | |
513 | ||
514 | Both the JSON-RPC client and the server must implement this request. | |
515 | ||
516 | This JSON-RPC request and response can be used to implement connection | |
517 | keepalives, by allowing the server to check that the client is still | |
518 | there or vice versa. | |
519 | ||
520 | ||
f85f8ebb BP |
521 | Notation for the Wire Protocol |
522 | ------------------------------ | |
523 | ||
524 | <table> | |
525 | ||
526 | An <id> that names a table. | |
527 | ||
528 | <column> | |
529 | ||
530 | An <id> that names a table column. | |
531 | ||
532 | <row> | |
533 | ||
534 | A JSON object that describes a table row or a subset of a table | |
535 | row. Each member is the name of a table column paired with the | |
536 | <value> of that column. | |
537 | ||
538 | <value> | |
539 | ||
540 | A JSON value that represents the value of a column in a table row, | |
541 | one of <atom>, a <set>, or a <map>. | |
542 | ||
543 | <atom> | |
544 | ||
545 | A JSON value that represents a scalar value for a column, one of | |
546 | <string>, <number>, <boolean>, <uuid>, <named-uuid>. | |
547 | ||
548 | <set> | |
549 | ||
550 | A 2-element JSON array that represents a database set value. The | |
551 | first element of the array must be the string "set" and the second | |
552 | element must be an array of zero or more <atom>s giving the values | |
553 | in the set. All of the <atom>s must have the same type. | |
554 | ||
555 | <map> | |
556 | ||
557 | A 2-element JSON array that represents a database map value. The | |
558 | first element of the array must be the string "map" and the second | |
559 | element must be an array of zero or more <pair>s giving the values | |
560 | in the map. All of the <pair>s must have the same key and value | |
561 | types. | |
562 | ||
563 | (JSON objects are not used to represent <map> because JSON only | |
564 | allows string names in an object.) | |
565 | ||
566 | <pair> | |
567 | ||
568 | A 2-element JSON array that represents a pair within a database | |
569 | map. The first element is an <atom> that represents the key, the | |
570 | second element is an <atom> that represents the value. | |
571 | ||
572 | <uuid> | |
573 | ||
574 | A 2-element JSON array that represents a UUID. The first element | |
575 | of the array must be the string "uuid" and the second element must | |
576 | be a 36-character string giving the UUID in the format described | |
577 | by RFC 4122. For example, the following <uuid> represents the | |
578 | UUID 550e8400-e29b-41d4-a716-446655440000: | |
579 | ||
580 | ["uuid", "550e8400-e29b-41d4-a716-446655440000"] | |
581 | ||
582 | <named-uuid> | |
583 | ||
584 | A 2-element JSON array that represents the UUID of a row inserted | |
fbf925e4 BP |
585 | in an "insert" operation within the same transaction. The first |
586 | element of the array must be the string "named-uuid" and the | |
587 | second element should be the string specified as the "uuid-name" | |
588 | for an "insert" operation within the same transaction. For | |
589 | example, if an "insert" operation within this transaction | |
590 | specifies a "uuid-name" of "myrow", the following <named-uuid> | |
591 | represents the UUID created by that operation: | |
f85f8ebb BP |
592 | |
593 | ["named-uuid", "myrow"] | |
594 | ||
6e30ca63 BP |
595 | A <named-uuid> may be used anywhere a <uuid> is valid. |
596 | ||
f85f8ebb BP |
597 | <condition> |
598 | ||
599 | A 3-element JSON array of the form [<column>, <function>, | |
600 | <value>] that represents a test on a column value. | |
601 | ||
602 | Except as otherwise specified below, <value> must have the same | |
603 | type as <column>. | |
604 | ||
605 | The meaning depends on the type of <column>: | |
606 | ||
607 | integer | |
608 | real | |
609 | ||
610 | <function> must be "<", "<=", "==", "!=", ">=", ">", | |
611 | "includes", or "excludes". | |
612 | ||
613 | The test is true if the column's value satisfies the | |
614 | relation <function> <value>, e.g. if the column has value | |
615 | 1 and <value> is 2, the test is true if <function> is "<", | |
616 | "<=" or "!=", but not otherwise. | |
617 | ||
618 | "includes" is equivalent to "=="; "excludes" is equivalent | |
619 | to "!=". | |
620 | ||
621 | boolean | |
622 | string | |
623 | uuid | |
624 | ||
625 | <function> must be "!=", "==", "includes", or "excludes". | |
626 | ||
627 | If <function> is "==" or "includes", the test is true if | |
628 | the column's value equals <value>. If <function> is "!=" | |
629 | or "excludes", the test is inverted. | |
630 | ||
631 | set | |
632 | map | |
633 | ||
634 | <function> must be "!=", "==", "includes", or "excludes". | |
635 | ||
636 | If <function> is "==", the test is true if the column's | |
637 | value contains exactly the same values (for sets) or pairs | |
638 | (for maps). If <function> is "!=", the test is inverted. | |
639 | ||
640 | If <function> is "includes", the test is true if the | |
641 | column's value contains all of the values (for sets) or | |
642 | pairs (for maps) in <value>. The column's value may also | |
643 | contain other values or pairs. | |
644 | ||
645 | If <function> is "excludes", the test is true if the | |
646 | column's value does not contain any of the values (for | |
647 | sets) or pairs (for maps) in <value>. The column's value | |
648 | may contain other values or pairs not in <value>. | |
649 | ||
650 | If <function> is "includes" or "excludes", then the | |
651 | required type of <value> is slightly relaxed, in that it | |
652 | may have fewer than the minimum number of elements | |
653 | specified by the column's type. If <function> is | |
654 | "excludes", then the required type is additionally relaxed | |
655 | in that <value> may have more than the maximum number of | |
656 | elements specified by the column's type. | |
657 | ||
658 | <function> | |
659 | ||
660 | One of "<", "<=", "==", "!=", ">=", ">", "includes", "excludes". | |
661 | ||
e9f8f936 BP |
662 | <mutation> |
663 | ||
664 | A 3-element JSON array of the form [<column>, <mutator>, <value>] | |
665 | that represents a change to a column value. | |
666 | ||
667 | Except as otherwise specified below, <value> must have the same | |
668 | type as <column>. | |
669 | ||
670 | The meaning depends on the type of <column>: | |
671 | ||
672 | integer | |
673 | real | |
674 | ||
675 | <mutator> must be "+=", "-=", "*=", "/=" or (integer only) | |
676 | "%=". The value of <column> is changed to the sum, | |
677 | difference, product, quotient, or remainder, respectively, | |
678 | of <column> and <value>. | |
679 | ||
bd76d25d BP |
680 | Constraints on <column> are ignored when parsing <value>. |
681 | ||
e9f8f936 BP |
682 | boolean |
683 | string | |
684 | uuid | |
685 | ||
686 | No valid <mutator>s are currently defined for these types. | |
687 | ||
688 | set | |
689 | ||
690 | Any <mutator> valid for the set's element type may be | |
691 | applied to the set, in which case the mutation is applied | |
692 | to each member of the set individually. <value> must be a | |
bd76d25d BP |
693 | scalar value of the same type as the set's element type, |
694 | except that contraints are ignored. | |
e9f8f936 BP |
695 | |
696 | If <mutator> is "insert", then each of the values in the | |
697 | set in <value> is added to <column> if it is not already | |
698 | present. The required type of <value> is slightly | |
699 | relaxed, in that it may have fewer than the minimum number | |
700 | of elements specified by the column's type. | |
701 | ||
702 | If <mutator> is "delete", then each of the values in the | |
703 | set in <value> is removed from <column> if it is present | |
704 | there. The required type is slightly relaxed in that | |
705 | <value> may have more or less than the maximum number of | |
706 | elements specified by the column's type. | |
707 | ||
708 | map | |
709 | ||
710 | <mutator> must be "insert" or "delete". | |
711 | ||
712 | If <mutator> is "insert", then each of the key-value pairs | |
03b1f24e BP |
713 | in the map in <value> is added to <column> only if its key |
714 | is not already present. The required type of <value> is | |
e9f8f936 BP |
715 | slightly relaxed, in that it may have fewer than the |
716 | minimum number of elements specified by the column's type. | |
717 | ||
718 | If <mutator> is "delete", then <value> may have the same | |
719 | type as <column> (a map type) or it may be a set whose | |
720 | element type is the same as <column>'s key type: | |
721 | ||
722 | - If <value> is a map, the mutation deletes each | |
723 | key-value pair in <column> whose key and value equal | |
724 | one of the key-value pairs in <value>. | |
725 | ||
726 | - If <value> is a set, the mutation deletes each | |
727 | key-value pair in <column> whose key equals one of | |
728 | the values in <value>. | |
729 | ||
730 | For "delete", <value> may have any number of elements, | |
731 | regardless of restrictions on the number of elements in | |
732 | <column>. | |
733 | ||
734 | <mutator> | |
735 | ||
736 | One of "+=", "-=", "*=", "/=", "%=", "insert", "delete". | |
737 | ||
f85f8ebb BP |
738 | Operations |
739 | ---------- | |
740 | ||
741 | Each of the available operations is described below. | |
742 | ||
743 | insert | |
744 | ...... | |
745 | ||
746 | Request object members: | |
747 | ||
748 | "op": "insert" required | |
749 | "table": <table> required | |
750 | "row": <row> required | |
2d2d6d4a | 751 | "uuid-name": <id> optional |
f85f8ebb BP |
752 | |
753 | Result object members: | |
754 | ||
755 | "uuid": <uuid> | |
756 | ||
757 | Semantics: | |
758 | ||
bd76d25d BP |
759 | Inserts "row" into "table". |
760 | ||
761 | If "row" does not specify values for all the columns in "table", | |
762 | those columns receive default values. The default value for a | |
763 | column depends on its type. The default for a column whose <type> | |
764 | specifies a "min" of 0 is an empty set or empty map. Otherwise, | |
765 | the default is a single value or a single key-value pair, whose | |
766 | value(s) depend on its <atomic-type>: | |
767 | ||
768 | - "integer" or "real": 0 | |
769 | ||
770 | - "boolean": false | |
771 | ||
772 | - "string": "" (the empty string) | |
773 | ||
774 | - "uuid": 00000000-0000-0000-0000-000000000000 | |
f85f8ebb | 775 | |
fbf925e4 | 776 | The new row receives a new, randomly generated UUID. |
2d2d6d4a | 777 | |
fbf925e4 BP |
778 | If "uuid-name" is supplied, then it is an error if <id> is not |
779 | unique among the "uuid-name"s supplied on all the "insert" | |
780 | operations within this transaction. | |
2d2d6d4a BP |
781 | |
782 | The UUID for the new row is returned as the "uuid" member of the | |
783 | result. | |
784 | ||
785 | Errors: | |
786 | ||
787 | "error": "duplicate uuid-name" | |
788 | ||
fbf925e4 | 789 | The same "uuid-name" appears on another "insert" operation |
2d2d6d4a | 790 | within this transaction. |
f85f8ebb | 791 | |
bd76d25d BP |
792 | "error": "constraint violation" |
793 | ||
794 | One of the values in "row" does not satisfy the immediate | |
795 | constraints for its column's <base-type>. This error will | |
796 | occur for columns that are not explicitly set by "row" if the | |
797 | default value does not satisfy the column's constraints. | |
798 | ||
f85f8ebb BP |
799 | select |
800 | ...... | |
801 | ||
802 | Request object members: | |
803 | ||
804 | "op": "select" required | |
805 | "table": <table> required | |
806 | "where": [<condition>*] required | |
807 | "columns": [<column>*] optional | |
808 | ||
809 | Result object members: | |
810 | ||
811 | "rows": [<row>*] | |
812 | ||
813 | Semantics: | |
814 | ||
815 | Searches "table" for rows that match all the conditions specified | |
816 | in "where". If "where" is an empty array, every row in "table" is | |
817 | selected. | |
818 | ||
819 | The "rows" member of the result is an array of objects. Each | |
820 | object corresponds to a matching row, with each column | |
821 | specified in "columns" as a member, the column's name as the | |
822 | member name and its value as the member value. If "columns" | |
823 | is not specified, all the table's columns are included. If | |
824 | two rows of the result have the same values for all included | |
825 | columns, only one copy of that row is included in "rows". | |
826 | Specifying "_uuid" within "columns" will avoid dropping | |
827 | duplicates, since every row has a unique UUID. | |
828 | ||
829 | The ordering of rows within "rows" is unspecified. | |
830 | ||
831 | update | |
832 | ...... | |
833 | ||
834 | Request object members: | |
835 | ||
836 | "op": "update" required | |
837 | "table": <table> required | |
838 | "where": [<condition>*] required | |
839 | "row": <row> required | |
840 | ||
841 | Result object members: | |
842 | ||
843 | "count": <integer> | |
844 | ||
845 | Semantics: | |
846 | ||
847 | Updates rows in a table. | |
848 | ||
849 | Searches "table" for rows that match all the conditions | |
850 | specified in "where". For each matching row, changes the | |
851 | value of each column specified in "row" to the value for that | |
852 | column specified in "row". | |
853 | ||
e68c3e48 JP |
854 | The "_uuid" and "_version" columns of a table may not be directly |
855 | updated with this operation. Columns designated read-only in the | |
856 | schema also may not be updated. | |
f85f8ebb BP |
857 | |
858 | The "count" member of the result specifies the number of rows | |
859 | that matched. | |
860 | ||
bd76d25d BP |
861 | Errors: |
862 | ||
863 | "error": "constraint violation" | |
864 | ||
865 | One of the values in "row" does not satisfy the immediate | |
866 | constraints for its column's <base-type>. | |
e9f8f936 BP |
867 | mutate |
868 | ...... | |
869 | ||
870 | Request object members: | |
871 | ||
872 | "op": "mutate" required | |
873 | "table": <table> required | |
874 | "where": [<condition>*] required | |
875 | "mutations": [<mutation>*] required | |
876 | ||
877 | Result object members: | |
878 | ||
879 | "count": <integer> | |
880 | ||
881 | Semantics: | |
882 | ||
883 | Mutates rows in a table. | |
884 | ||
885 | Searches "table" for rows that match all the conditions specified | |
886 | in "where". For each matching row, mutates its columns as | |
887 | specified by each <mutation> in "mutations", in the order | |
888 | specified. | |
889 | ||
890 | The "_uuid" and "_version" columns of a table may not be directly | |
891 | modified with this operation. Columns designated read-only in the | |
892 | schema also may not be updated. | |
893 | ||
894 | The "count" member of the result specifies the number of rows | |
895 | that matched. | |
896 | ||
897 | Errors: | |
898 | ||
899 | "error": "domain error" | |
900 | ||
901 | The result of the mutation is not mathematically defined, | |
902 | e.g. division by zero. | |
903 | ||
904 | "error": "range error" | |
905 | ||
906 | The result of the mutation is not representable within the | |
907 | database's format, e.g. an integer result outside the range | |
908 | INT64_MIN...INT64_MAX or a real result outside the range | |
909 | -DBL_MAX...DBL_MAX. | |
910 | ||
911 | "error": "constraint violation" | |
912 | ||
913 | The mutation caused the column's value to violate a | |
914 | constraint, e.g. it caused a column to have more or fewer | |
bd76d25d BP |
915 | values than are allowed, an arithmetic operation caused a set |
916 | or map to have duplicate elements, or it violated a constraint | |
917 | specified by a column's <base-type>. | |
e9f8f936 | 918 | |
f85f8ebb BP |
919 | delete |
920 | ...... | |
921 | ||
922 | Request object members: | |
923 | ||
924 | "op": "delete" required | |
925 | "table": <table> required | |
926 | "where": [<condition>*] required | |
927 | ||
928 | Result object members: | |
929 | ||
930 | "count": <integer> | |
931 | ||
932 | Semantics: | |
933 | ||
934 | Deletes all the rows from "table" that match all the conditions | |
935 | specified in "where". | |
936 | ||
937 | The "count" member of the result specifies the number of deleted | |
938 | rows. | |
939 | ||
940 | wait | |
941 | .... | |
942 | ||
943 | Request object members: | |
944 | ||
945 | "op": "wait" required | |
946 | "timeout": <integer> optional | |
947 | "table": <table> required | |
948 | "where": [<condition>*] required | |
949 | "columns": [<column>*] required | |
950 | "until": "==" or "!=" required | |
951 | "rows": [<row>*] required | |
952 | ||
953 | Result object members: | |
954 | ||
955 | none | |
956 | ||
957 | Semantics: | |
958 | ||
959 | Waits until a condition becomes true. | |
960 | ||
961 | If "until" is "==", checks whether the query on "table" specified | |
962 | by "where" and "columns", which is evaluated in the same way as | |
963 | specified for "select", returns the result set specified by | |
964 | "rows". If it does, then the operation completes successfully. | |
965 | Otherwise, the entire transaction rolls back. It is automatically | |
966 | restarted later, after a change in the database makes it possible | |
967 | for the operation to succeed. The client will not receive a | |
968 | response until the operation permanently succeeds or fails. | |
969 | ||
970 | If "until" is "!=", the sense of the test is negated. That is, as | |
971 | long as the query on "table" specified by "where" and "columns" | |
972 | returns "rows", the transaction will be rolled back and restarted | |
973 | later. | |
974 | ||
975 | If "timeout" is specified, then the transaction aborts after the | |
976 | specified number of milliseconds. The transaction is guaranteed | |
977 | to be attempted at least once before it aborts. A "timeout" of 0 | |
978 | will abort the transaction on the first mismatch. | |
979 | ||
980 | Errors: | |
981 | ||
982 | "error": "not supported" | |
983 | ||
984 | One or more of the columns in this table do not support | |
985 | triggers. This error will not occur if "timeout" is 0. | |
986 | ||
987 | "error": "timed out" | |
988 | ||
989 | The "timeout" was reached before the transaction was able to | |
990 | complete. | |
991 | ||
992 | commit | |
993 | ...... | |
994 | ||
995 | Request object members: | |
996 | ||
997 | "op": "commit" required | |
998 | "durable": <boolean> required | |
999 | ||
1000 | Result object members: | |
1001 | ||
1002 | none | |
1003 | ||
1004 | Semantics: | |
1005 | ||
1006 | If "durable" is specified as true, then the transaction, if it | |
1007 | commits, will be stored durably (to disk) before the reply is sent | |
1008 | to the client. | |
1009 | ||
1010 | Errors: | |
1011 | ||
1012 | "error": "not supported" | |
1013 | ||
1014 | When "durable" is true, this database implementation does not | |
1015 | support durable commits. | |
1016 | ||
1017 | abort | |
1018 | ..... | |
1019 | ||
1020 | Request object members: | |
1021 | ||
1022 | "op": "abort" required | |
1023 | ||
1024 | Result object members: | |
1025 | ||
1026 | (never succeeds) | |
1027 | ||
1028 | Semantics: | |
1029 | ||
1030 | Aborts the transaction with an error. This may be useful for | |
1031 | testing. | |
1032 | ||
1033 | Errors: | |
1034 | ||
1035 | "error": "aborted" | |
1036 | ||
1037 | This operation always fails with this error. | |
2d2d6d4a | 1038 | |
d171b584 BP |
1039 | comment |
1040 | ....... | |
1041 | ||
1042 | ||
1043 | Request object members: | |
1044 | ||
1045 | "op": "comment" required | |
1046 | "comment": <string> required | |
1047 | ||
1048 | Result object members: | |
1049 | ||
1050 | none | |
1051 | ||
1052 | Semantics: | |
1053 | ||
1054 | Provides information to a database administrator on the purpose of | |
1055 | a transaction. The OVSDB server, for example, adds comments in | |
1056 | transactions that modify the database to the database journal. |