ovsdb: Document the "mutable" feature for columns.
[sliver-openvswitch.git] / ovsdb / SPECS
index 9fd654b..260786e 100644 (file)
@@ -5,13 +5,26 @@
 Basic Notation
 --------------
 
+OVSDB uses JSON, as defined by RFC 4627, for its schema format and its
+wire protocol format.  The JSON implementation in Open vSwitch has the
+following limitations:
+
+     - Null bytes (\u0000) are not allowed in strings.
+
+     - Only UTF-8 encoding is supported.  (RFC 4627 also mentions
+       UTF-16BE, UTF-16LE, and UTF-32.)
+
+     - RFC 4627 says that names within a JSON object should be unique.
+       The Open vSwitch JSON parser discards all but the last value
+       for a name that is specified more than once.
+
 The descriptions below use the following shorthand notations for JSON
 values.  Additional notation is presented later.
 
 <string>
 
     A JSON string.  Any Unicode string is allowed, as specified by RFC
-    4627.  Implementations may disallowed null bytes.
+    4627.  Implementations may disallow null bytes.
 
 <id>
 
@@ -33,10 +46,50 @@ values.  Additional notation is presented later.
     A JSON number with an integer value, within a certain range
     (currently -2**63...+2**63-1).
 
-<value>
+<json-value>
 
     Any JSON value.
 
+<nonnull-json-value>
+
+    Any JSON value except null.
+
+<error>
+
+    A JSON object with the following members:
+
+        "error": <string>                       required
+        "details": <string>                     optional
+
+    The value of the "error" member is a short string, specified in
+    this document, that broadly indicates the class of the error.
+    Most "error" strings are specific to contexts described elsewhere
+    in this document, but the following "error" strings may appear in
+    any context where an <error> is permitted:
+
+    "error": "resources exhausted"
+
+        The operation requires more resources (memory, disk, CPU,
+        etc.) than are currently available to the database server.
+
+    "error": "I/O error"
+
+        Problems accessing the disk, network, or other required
+        resources prevented the operation from completing.
+
+    Database implementations may use "error" strings not specified
+    in this document to indicate errors that do not fit into any of
+    the specified categories.
+
+    Optionally, an <error> may include a "details" member, whose value
+    is a string that describes the error in more detail for the
+    benefit of a human user or administrator.  This document does not
+    specify the format or content of the "details" string.
+
+    An <error> may also have other members that describe the error in
+    more detail.  This document does not specify the names or values
+    of these members.
+
 Schema Format
 -------------
 
@@ -49,24 +102,22 @@ is represented by <database-schema>, as described below.
     A JSON object with the following members:
 
         "name": <id>                            required
-        "comment": <string>                     optional
         "tables": {<id>: <table-schema>, ...}   required
 
-    The "name" identifies the database as a whole.  The "comment"
-    optionally provides more information about the database.  The
-    value of "tables" is a JSON object whose names are table names and
-    whose values are <table-schema>s.
+    The "name" identifies the database as a whole.  It must be
+    provided to most JSON-RPC requests to identify the database being
+    operated on.  The value of "tables" is a JSON object whose names
+    are table names and whose values are <table-schema>s.
 
 <table-schema>
 
     A JSON object with the following members:
 
-        "comment": <string>                       optional
         "columns": {<id>: <column-schema>, ...}   required
+        "maxRows": <integer>                      optional
 
-    The "comment" optionally provides information about this table for
-    a human reader.  The value of "columns" is a JSON object whose
-    names are column names and whose values are <column-schema>s.
+    The value of "columns" is a JSON object whose names are column
+    names and whose values are <column-schema>s.
 
     Every table has the following columns whose definitions are not
     included in the schema:
@@ -85,19 +136,27 @@ is represented by <database-schema>, as described below.
         the database process is stopped and then started again, each
         "_version" also changes to a new random value.
 
+    If "maxRows" is specified, as a positive integer, it limits the
+    maximum number of rows that may be present in the table.  This is
+    a "deferred" constraint, enforced only at transaction commit time
+    (see the "transact" request below).  If "maxRows" is not
+    specified, the size of the table is limited only by the resources
+    available to the database server.
+
 <column-schema>
 
     A JSON object with the following members:
 
-        "comment": <string>                       optional
         "type": <type>                            required
         "ephemeral": <boolean>                    optional
+        "mutable": <boolean>                      optional
 
-    The "comment" optionally provides information about this column
-    for a human reader.  The "type" specifies the type of data stored
-    in this column.  If "ephemeral" is specified as true, then this
-    column's values are not guaranteed to be durable; they may be lost
-    when the database restarts.
+    The "type" specifies the type of data stored in this column.  If
+    "ephemeral" is specified as true, then this column's values are
+    not guaranteed to be durable; they may be lost when the database
+    restarts.  If "mutable" is specified as false, then this column's
+    values may not be modified after they are initially set with the
+    "insert" operation.
 
 <type>
 
@@ -105,17 +164,17 @@ is represented by <database-schema>, as described below.
     object that describes the type of a database column, with the
     following members:
 
-        "key": <atomic-type>               required
-        "value": <atomic-type>             optional
+        "key": <base-type>                 required
+        "value": <base-type>               optional
         "min": <integer>                   optional
         "max": <integer> or "unlimited"    optional
 
     If "min" or "max" is not specified, each defaults to 1.  If "max"
     is specified as "unlimited", then there is no specified maximum
     number of elements, although the implementation will enforce some
-    limit.  After considering defaults, "min" must be at least 0,
-    "max" must be at least 1, and "max" must be greater than or equal
-    to "min".
+    limit.  After considering defaults, "min" must be exactly 0 or
+    exactly 1, "max" must be at least 1, and "max" must be greater
+    than or equal to "min".
 
     If "min" and "max" are both 1 and "value" is not specified, the
     type is the scalar type specified by "key".
@@ -126,6 +185,66 @@ is represented by <database-schema>, as described below.
     If "value" is specified, the type is a map from type "key" to type
     "value".
 
+<base-type>
+
+    The type of a key or value in a database column.  Either an
+    <atomic-type> or a JSON object with the following members:
+
+        "type": <atomic-type>              required
+        "enum": <value>                    optional
+        "minInteger": <integer>            optional, integers only
+        "maxInteger": <integer>            optional, integers only
+        "minReal": <real>                  optional, reals only
+        "maxReal": <real>                  optional, reals only 
+        "minLength": <integer>             optional, strings only
+        "maxLength": <integer>             optional, strings only
+        "refTable": <id>                   optional, uuids only
+        "refType": "strong" or "weak"      optional, only with "refTable"
+
+    An <atomic-type> by itself is equivalent to a JSON object with a
+    single member "type" whose value is the <atomic-type>.
+
+    "enum" may be specified as a <value> whose type is a set of one
+    or more values specified for the member "type".  If "enum" is
+    specified, then the valid values of the <base-type> are limited to
+    those in the <value>.
+
+    "enum" is mutually exclusive with the following constraints.
+
+    If "type" is "integer", then "minInteger" or "maxInteger" or both
+    may also be specified, restricting the valid integer range.  If
+    both are specified, then the maxInteger must be greater than or
+    equal to minInteger.
+
+    If "type" is "real", then "minReal" or "maxReal" or both may also
+    be specified, restricting the valid real range.  If both are
+    specified, then the maxReal must be greater than or equal to
+    minReal.
+
+    If "type" is "string", then "minLength" and "maxLength" or both
+    may be specified, restricting the valid length of value strings.
+    If both are specified, then maxLength must be greater than or
+    equal to minLength.  String length is measured in characters (not
+    bytes or UTF-16 code units).
+
+    If "type" is "uuid", then "refTable", if present, must be the name
+    of a table within this database.  If "refTable" is specified, then
+    "refType" may also be specified.  If "refTable" is set, the effect
+    depends on "refType":
+
+        - If "refType" is "strong" or if "refType" is omitted, the
+          allowed UUIDs are limited to UUIDs for rows in the named
+          table.
+
+        - If "refType" is "weak", then any UUIDs are allowed, but
+          UUIDs that do not correspond to rows in the named table will
+          be automatically deleted.
+
+    "refTable" constraints are "deferred" constraints: they are
+    enforced only at transaction commit time (see the "transact"
+    request below).  The other contraints on <base-type> are
+    "immediate", enforced immediately by each operation.
+
 <atomic-type>
 
     One of the strings "integer", "real", "boolean", "string", or
@@ -148,16 +267,37 @@ over HTTP, for these reasons:
 
     * The JSON-RPC specification for HTTP transport is incomplete.
 
+We are using TCP port 6632 for the database JSON-RPC connection.
+
 The database wire protocol consists of the following JSON-RPC methods:
 
+list_dbs
+........
+
+Request object members:
+
+    "method": "list_dbs"              required
+    "params": []                      required
+    "id": <nonnull-json-value>        required
+
+Response object members:
+
+    "result": [<db-name>, ...]
+    "error": null
+    "id": same "id" as request
+
+This operation retrieves an array whose elements are <db-name>s
+that name the databases that can be accessed over this JSON-RPC
+connection.
+
 get_schema
 ..........
 
 Request object members:
 
     "method": "get_schema"            required
-    "params": []                      required
-    "id": any JSON value except null  required
+    "params": [<db-name>]             required
+    "id": <nonnull-json-value>        required
 
 Response object members:
 
@@ -165,17 +305,17 @@ Response object members:
     "error": null
     "id": same "id" as request
 
-This operation retrieves a <database-schema> that describes the
-hosted database.
+This operation retrieves a <database-schema> that describes hosted
+database <db-name>.
 
 transact
 ........
 
 Request object members:
 
-    "method": "transact"              required
-    "params": [<operation>*]          required
-    "id": any JSON value except null  required
+    "method": "transact"                  required
+    "params": [<db-name>, <operation>*]   required
+    "id": <nonnull-json-value>            required
 
 Response object members:
 
@@ -183,9 +323,11 @@ Response object members:
     "error": null
     "id": same "id" as request
 
-The "params" array for this method consists of zero or more JSON
-objects, each of which represents a single database operation.  The
-"Operations" section below describes the valid operations.
+The "params" array for this method consists of a <db-name> that
+identifies the database to which the transaction applies, followed by
+zero or more JSON objects, each of which represents a single database
+operation.  The "Operations" section below describes the valid
+operations.
 
 The value of "id" must be unique among all in-flight transactions
 within the current JSON-RPC session.  Otherwise, the server may return
@@ -213,37 +355,8 @@ array corresponds to the same element of the "params" array.  The
       individual operations.  Some operations do not produce any
       results, in which case the object will have no members.
 
-    - A JSON object that contains an "error" member indicates that the
-      operation completed with an error.  The value of the "error"
-      member is a short string, specified in this document, that
-      broadly indicates the class of the error.  Besides the ones
-      listed for a specific operation, any operation may result in one
-      the following "error"s:
-
-      "error": "resources exhausted"
-
-          The operation or the transaction requires more resources
-          (memory, disk, CPU, etc.) than are currently available to
-          the database server.
-
-      "error": "syntax error"
-
-          The operation is not specified correctly: a required request
-          object member is missing, an unknown or unsupported request
-          object member is present, the operation attempts to act on a
-          table that does not exist, the operation modifies a
-          read-only table column, etc.
-
-      Database implementations may use "error" strings not specified
-      in this document to indicate errors that do not fit into any of
-      the specified categories.
-
-      Optionally, the object may include a "details" member, whose
-      value is a string that describes the error in more detail for
-      the benefit of a human user or administrator.  The object may
-      also have other members that describe the error in more detail.
-      This document does not specify the names or values of these
-      members.
+    - An <error>, which indicates that the operation completed with an
+      error.
 
     - A JSON null value indicates that the operation was not attempted
       because a prior operation failed.
@@ -252,9 +365,33 @@ In general, "result" contains some number of successful results,
 possibly followed by an error, in turn followed by enough JSON null
 values to match the number of elements in "params".  There is one
 exception: if all of the operations succeed, but the results cannot be
-committed (e.g. due to I/O errors), then "result" will have one more
-element than "params", with the additional element describing the
-error.
+committed, then "result" will have one more element than "params",
+with the additional element an <error>.  The possible "error" strings
+include at least the following:
+
+    "error": "referential integrity violation"
+
+        When the commit was attempted, a column's value referenced the
+        UUID for a row that did not exist in the table named by the
+        column's <base-type> key or value "refTable" that has a
+        "refType" of "strong".  (This can be caused by inserting a row
+        that references a nonexistent row, by deleting a row that is
+        still referenced by another row, by specifying the UUID for a
+        row in the wrong table, and other ways.)
+
+    "error": "constraint violation"
+
+        A column with a <base-type> key or value "refTable" whose
+        "refType" is "weak" became empty due to deletion(s) caused
+        because the rows that it referenced were deleted (or never
+        existed, if the column's row was inserted within the
+        transaction), and this column is not allowed to be empty
+        because its <type> has a "min" of 1.
+
+    "error": "constraint violation"
+
+        The number of rows in a table exceeds the maximum number
+        permitted by the table's "maxRows" value (see <table-schema>).
 
 If "params" contains one or more "wait" operations, then the
 transaction may take an arbitrary amount of time to complete.  The
@@ -300,12 +437,14 @@ monitor
 
 Request object members:
 
-    "method": "monitor"                        required
-    "params": [<value>, <monitor-requests>]    required
-    "id": any JSON value except null           required
+    "method": "monitor"                                       required
+    "params": [<db-name>, <json-value>, <monitor-requests>]   required
+    "id": <nonnull-json-value>                                required
 
-<monitor-requests> is an object that maps from a table name to a
-<monitor-request>.
+<monitor-requests> is an object that maps from a table name to an
+array of <monitor-request> objects.  For backward compatibility, a
+single <monitor-request> may be used instead of an array; it is
+treated as a single-element array.
 
 Each <monitor-request> is an object with the following members:
 
@@ -326,15 +465,16 @@ Response object members:
     "id": same "id" as request
 
 This JSON-RPC request enables a client to replicate tables or subsets
-of tables.  Each <monitor-request> specifies a table to be replicated.
-The JSON-RPC response to the "monitor" includes the initial contents
-of each table.  Afterward, when changes to those tables are committed,
-the changes are automatically sent to the client using the "update"
-monitor notification.  This monitoring persists until the JSON-RPC
-session terminates or until the client sends a "monitor_cancel"
-JSON-RPC request.
+of tables within database <db-name>.  Each element of
+<monitor-requests> specifies a table to be replicated.  The JSON-RPC
+response to the "monitor" includes the initial contents of each table,
+unless disabled (see below).  Afterward, when changes to those tables
+are committed, the changes are automatically sent to the client using
+the "update" monitor notification.  This monitoring persists until the
+JSON-RPC session terminates or until the client sends a
+"monitor_cancel" JSON-RPC request.
 
-Each <monitor-request> describes how to monitor a table:
+Each <monitor-request> describes how to monitor columns in a table:
 
     The circumstances in which an "update" notification is sent for a
     row within the table are determined by <monitor-select>:
@@ -352,8 +492,13 @@ Each <monitor-request> describes how to monitor a table:
         sent whenever when a row in the table is modified.
 
     The "columns" member specifies the columns whose values are
-    monitored.  If "columns" is omitted, all columns in the table,
-    except for "_uuid", are monitored.
+    monitored.  It must not contain duplicates.  If "columns" is
+    omitted, all columns in the table, except for "_uuid", are
+    monitored.
+
+If there is more than one <monitor-request> in an array of them, then
+each <monitor-request> in the array should specify both "columns" and
+"select", and the "columns" must be non-overlapping sets.
 
 The "result" in the JSON-RPC response to the "monitor" request is a
 <table-updates> object (see below) that contains the contents of the
@@ -366,11 +511,11 @@ update
 Notification object members:
 
     "method": "update"
-    "params": [<value>, <table-updates>]
+    "params": [<json-value>, <table-updates>]
     "id": null
 
-The <value> in "params" is the same as the value passed as the <value>
-in "params" for the "monitor" request.
+The <json-value> in "params" is the same as the value passed as the
+<json-value> in "params" for the "monitor" request.
 
 <table-updates> is an object that maps from a table name to a
 <table-update>.
@@ -409,8 +554,8 @@ monitor_cancel
 Request object members:
 
     "method": "monitor_cancel"                              required
-    "params": [<value>]                                     required
-    "id": any JSON value except null                        required
+    "params": [<json-value>]                                required
+    "id": <nonnull-json-value>                              required
 
 Response object members:
 
@@ -418,10 +563,10 @@ Response object members:
     "error": null
     "id": the request "id" member
 
-Cancels the ongoing table monitor request, identified by the <value>
-in "params" matching the <value> in "params" for an ongoing "monitor"
-request.  No more "update" messages will be sent for this table
-monitor.
+Cancels the ongoing table monitor request, identified by the
+<json-value> in "params" matching the <json-value> in "params" for an
+ongoing "monitor" request.  No more "update" messages will be sent for
+this table monitor.
 
 echo
 ....
@@ -430,7 +575,7 @@ Request object members:
 
     "method": "echo"                                required
     "params": JSON array with any contents          required
-    "id": <value>                                   required
+    "id": <json-value>                              required
 
 Response object members:
 
@@ -448,6 +593,12 @@ there or vice versa.
 Notation for the Wire Protocol
 ------------------------------
 
+<db-name>
+
+    An <id> that names a database.  The valid <db-name>s can be
+    obtained using a "list-db" request.  The <db-name> is taken from
+    the "name" member of <database-schema>.
+
 <table>
 
     An <id> that names a table.
@@ -474,7 +625,8 @@ Notation for the Wire Protocol
 
 <set>
 
-    A 2-element JSON array that represents a database set value.  The
+    Either an <atom>, representing a set with exactly one element, or
+    a 2-element JSON array that represents a database set value.  The
     first element of the array must be the string "set" and the second
     element must be an array of zero or more <atom>s giving the values
     in the set.  All of the <atom>s must have the same type.
@@ -509,13 +661,13 @@ Notation for the Wire Protocol
 <named-uuid>
 
     A 2-element JSON array that represents the UUID of a row inserted
-    in a previous "insert" operation within the same transaction.  The
-    first element of the array must be the string "named-uuid" and the
-    second element must be the string specified on this "insert"
-    operation's "uuid-name" or on a preceding "insert" within the same
-    transaction.  For example, if this or a previous "insert"
-    operation specified a "uuid-name" of "myrow", the following
-    <named-uuid> represents the UUID created by that operation:
+    in an "insert" operation within the same transaction.  The first
+    element of the array must be the string "named-uuid" and the
+    second element should be the string specified as the "uuid-name"
+    for an "insert" operation within the same transaction.  For
+    example, if an "insert" operation within this transaction
+    specifies a "uuid-name" of "myrow", the following <named-uuid>
+    represents the UUID created by that operation:
 
         ["named-uuid", "myrow"]
 
@@ -604,6 +756,8 @@ Notation for the Wire Protocol
             difference, product, quotient, or remainder, respectively,
             of <column> and <value>.
 
+            Constraints on <column> are ignored when parsing <value>.
+
         boolean
         string
         uuid
@@ -615,7 +769,8 @@ Notation for the Wire Protocol
             Any <mutator> valid for the set's element type may be
             applied to the set, in which case the mutation is applied
             to each member of the set individually.  <value> must be a
-            scalar value of the same type as the set's element type.
+            scalar value of the same type as the set's element type,
+            except that contraints are ignored.
 
             If <mutator> is "insert", then each of the values in the
             set in <value> is added to <column> if it is not already
@@ -634,8 +789,8 @@ Notation for the Wire Protocol
             <mutator> must be "insert" or "delete".
 
             If <mutator> is "insert", then each of the key-value pairs
-            in the map in <value> is added to <column> if its key is
-            not already present.  The required type of <value> is
+            in the map in <value> is added to <column> only if its key
+            is not already present.  The required type of <value> is
             slightly relaxed, in that it may have fewer than the
             minimum number of elements specified by the column's type.
 
@@ -680,25 +835,28 @@ Result object members:
 
 Semantics:
 
-    Inserts "row" into "table".  If "row" does not specify values
-    for all the columns in "table", those columns receive default
-    values.
+    Inserts "row" into "table".
 
-    If "uuid-name" is not supplied, the new row receives a new,
-    randomly generated UUID.
+    If "row" does not specify values for all the columns in "table",
+    those columns receive default values.  The default value for a
+    column depends on its type.  The default for a column whose <type>
+    specifies a "min" of 0 is an empty set or empty map.  Otherwise,
+    the default is a single value or a single key-value pair, whose
+    value(s) depend on its <atomic-type>:
 
-    If "uuid-name" is supplied, then it is an error if <id> has
-    previously appeared as the "uuid-name" in an "insert" operation.
+        - "integer" or "real": 0
 
-    If "uuid-name" is supplied and its <id> previously appeared as the
-    "uuid-name" in a "declare" operation, then the new row receives
-    the UUID associated with that "uuid-name".
+        - "boolean": false
 
-    If "uuid-name" is supplied and its <id> has not previously
-    appeared as the "uuid-name" in a "declare" operation, then the new
-    row also receives a new, randomly generated UUID.  This UUID is
-    also made available under that name to this operation and later
-    operations within the same transaction.
+        - "string": "" (the empty string)
+
+        - "uuid": 00000000-0000-0000-0000-000000000000
+
+    The new row receives a new, randomly generated UUID.
+
+    If "uuid-name" is supplied, then it is an error if <id> is not
+    unique among the "uuid-name"s supplied on all the "insert"
+    operations within this transaction.
 
     The UUID for the new row is returned as the "uuid" member of the
     result.
@@ -707,9 +865,16 @@ Errors:
 
     "error": "duplicate uuid-name"
 
-        The same "uuid-name" appeared on an earlier "insert" operation
+        The same "uuid-name" appears on another "insert" operation
         within this transaction.
 
+    "error": "constraint violation"
+
+        One of the values in "row" does not satisfy the immediate
+        constraints for its column's <base-type>.  This error will
+        occur for columns that are not explicitly set by "row" if the
+        default value does not satisfy the column's constraints.
+
 select
 ......
 
@@ -772,6 +937,12 @@ Semantics:
     The "count" member of the result specifies the number of rows
     that matched.
 
+Errors:
+
+    "error": "constraint violation"
+
+        One of the values in "row" does not satisfy the immediate
+        constraints for its column's <base-type>.
 mutate
 ......
 
@@ -820,8 +991,9 @@ Errors:
 
         The mutation caused the column's value to violate a
         constraint, e.g. it caused a column to have more or fewer
-        values than are allowed or an arithmetic operation caused a
-        set or map to have duplicate elements.
+        values than are allowed, an arithmetic operation caused a set
+        or map to have duplicate elements, or it violated a constraint
+        specified by a column's <base-type>.
 
 delete
 ......
@@ -943,13 +1115,14 @@ Errors:
 
         This operation always fails with this error.
 
-declare
+comment
 .......
 
+
 Request object members:
 
-    "op": "declare"                    required
-    "uuid-name": <id>                  required
+    "op": "comment"                    required
+    "comment": <string>                required
 
 Result object members:
 
@@ -957,22 +1130,6 @@ Result object members:
 
 Semantics:
 
-    Predeclares a UUID named <id> that may be referenced in later
-    operations as ["named-uuid", <id>] or (at most once) in an
-    "insert" operation as "uuid-name".
-
-    It is an error if <id> has appeared as the "uuid-name" in a prior
-    "insert" or "declare" operation within this transaction.
-
-    The generated UUID is returned as the "uuid" member of the result.
-
-Result object members:
-
-    "uuid": <uuid>
-
-Errors:
-
-    "error": "duplicate uuid-name"
-
-        The same "uuid-name" appeared on an earlier "insert" or
-        "declare" operation within this transaction.
+    Provides information to a database administrator on the purpose of
+    a transaction.  The OVSDB server, for example, adds comments in
+    transactions that modify the database to the database journal.