ovsdb: Allow a named-uuid to be used within the operation that creates it.
authorBen Pfaff <blp@nicira.com>
Wed, 2 Dec 2009 00:35:33 +0000 (16:35 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 2 Dec 2009 19:18:59 +0000 (11:18 -0800)
This allows a transaction like this:

[{"op": "insert",
  "table": "mytable",
  "row": {"i": 0, "k": ["named-uuid", "self"]},
  "uuid-name": "self"}]

It was already possible to do this by following up on the "insert" with an
"update", but since this was easy to implement I did it.

ovsdb/SPECS
ovsdb/execution.c

index a4e9ab4..3acf32d 100644 (file)
@@ -497,13 +497,16 @@ Notation for the Wire Protocol
     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 a previous "insert"
-    operation's "uuid-name".  For example, if a previous "insert"
+    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:
 
         ["named-uuid", "myrow"]
 
+    A <named-uuid> may be used anywhere a <uuid> is valid.
+
 <condition>
 
     A 3-element JSON array of the form [<column>, <function>,
@@ -595,9 +598,9 @@ Semantics:
     values.
 
     The new row receives a new, randomly generated UUID, which is
-    returned as the "uuid" member of the result.  If "uuid-name"
-    is supplied, then the UUID is made available under that name
-    to later operations within the same transaction.
+    returned as the "uuid" member of the result.  If "uuid-name" is
+    supplied, then the UUID is made available under that name to this
+    operation and later operations within the same transaction.
 
 select
 ......
index 9edc1a9..0bfe86f 100644 (file)
@@ -266,19 +266,22 @@ ovsdb_execute_insert(struct ovsdb_execution *x, struct ovsdb_parser *parser,
     struct ovsdb_row *row = NULL;
     const struct json *uuid_name;
     struct ovsdb_error *error;
+    struct uuid row_uuid;
 
     table = parse_table(x, parser, "table");
     uuid_name = ovsdb_parser_member(parser, "uuid-name", OP_ID | OP_OPTIONAL);
     error = ovsdb_parser_get_error(parser);
+
+    uuid_generate(&row_uuid);
+    if (uuid_name) {
+        ovsdb_symbol_table_put(x->symtab, json_string(uuid_name), &row_uuid);
+    }
+
     if (!error) {
         error = parse_row(parser, "row", table, x->symtab, &row, NULL);
     }
     if (!error) {
-        uuid_generate(ovsdb_row_get_uuid_rw(row));
-        if (uuid_name) {
-            ovsdb_symbol_table_put(x->symtab, json_string(uuid_name),
-                                   ovsdb_row_get_uuid(row));
-        }
+        *ovsdb_row_get_uuid_rw(row) = row_uuid;
         ovsdb_txn_row_insert(x->txn, row);
         json_object_put(result, "uuid",
                         ovsdb_datum_to_json(&row->fields[OVSDB_COL_UUID],