mirror of
https://github.com/openvswitch/ovs
synced 2025-10-17 14:28:02 +00:00
ovsdb: Get rid of "declare" operation.
It's more elegant, and just as easy to implement, if we allow a "named-uuid" to be a forward reference to a "uuid-name" in a later "insert" operation.
This commit is contained in:
@@ -229,14 +229,9 @@ parse_json_pair(const struct json *json,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct ovsdb_error *
|
||||
static struct ovsdb_error * WARN_UNUSED_RESULT
|
||||
ovsdb_atom_parse_uuid(struct uuid *uuid, const struct json *json,
|
||||
const struct ovsdb_symbol_table *symtab)
|
||||
WARN_UNUSED_RESULT;
|
||||
|
||||
static struct ovsdb_error *
|
||||
ovsdb_atom_parse_uuid(struct uuid *uuid, const struct json *json,
|
||||
const struct ovsdb_symbol_table *symtab)
|
||||
struct ovsdb_symbol_table *symtab)
|
||||
{
|
||||
struct ovsdb_error *error0;
|
||||
const struct json *value;
|
||||
@@ -254,18 +249,10 @@ ovsdb_atom_parse_uuid(struct uuid *uuid, const struct json *json,
|
||||
error1 = unwrap_json(json, "named-uuid", JSON_STRING, &value);
|
||||
if (!error1) {
|
||||
const char *name = json_string(value);
|
||||
const struct ovsdb_symbol *symbol;
|
||||
|
||||
ovsdb_error_destroy(error0);
|
||||
|
||||
symbol = ovsdb_symbol_table_get(symtab, name);
|
||||
if (symbol) {
|
||||
*uuid = symbol->uuid;
|
||||
return NULL;
|
||||
} else {
|
||||
return ovsdb_syntax_error(json, NULL,
|
||||
"unknown named-uuid \"%s\"", name);
|
||||
}
|
||||
*uuid = ovsdb_symbol_table_insert(symtab, name)->uuid;
|
||||
return NULL;
|
||||
}
|
||||
ovsdb_error_destroy(error1);
|
||||
}
|
||||
@@ -276,7 +263,7 @@ ovsdb_atom_parse_uuid(struct uuid *uuid, const struct json *json,
|
||||
static struct ovsdb_error * WARN_UNUSED_RESULT
|
||||
ovsdb_atom_from_json__(union ovsdb_atom *atom, enum ovsdb_atomic_type type,
|
||||
const struct json *json,
|
||||
const struct ovsdb_symbol_table *symtab)
|
||||
struct ovsdb_symbol_table *symtab)
|
||||
{
|
||||
switch (type) {
|
||||
case OVSDB_TYPE_VOID:
|
||||
@@ -332,7 +319,7 @@ struct ovsdb_error *
|
||||
ovsdb_atom_from_json(union ovsdb_atom *atom,
|
||||
const struct ovsdb_base_type *base,
|
||||
const struct json *json,
|
||||
const struct ovsdb_symbol_table *symtab)
|
||||
struct ovsdb_symbol_table *symtab)
|
||||
{
|
||||
struct ovsdb_error *error;
|
||||
|
||||
@@ -906,7 +893,7 @@ struct ovsdb_error *
|
||||
ovsdb_datum_from_json(struct ovsdb_datum *datum,
|
||||
const struct ovsdb_type *type,
|
||||
const struct json *json,
|
||||
const struct ovsdb_symbol_table *symtab)
|
||||
struct ovsdb_symbol_table *symtab)
|
||||
{
|
||||
struct ovsdb_error *error;
|
||||
|
||||
@@ -1527,7 +1514,7 @@ ovsdb_symbol_table_get(const struct ovsdb_symbol_table *symtab,
|
||||
return shash_find_data(&symtab->sh, name);
|
||||
}
|
||||
|
||||
void
|
||||
struct ovsdb_symbol *
|
||||
ovsdb_symbol_table_put(struct ovsdb_symbol_table *symtab, const char *name,
|
||||
const struct uuid *uuid, bool used)
|
||||
{
|
||||
@@ -1538,6 +1525,23 @@ ovsdb_symbol_table_put(struct ovsdb_symbol_table *symtab, const char *name,
|
||||
symbol->uuid = *uuid;
|
||||
symbol->used = used;
|
||||
shash_add(&symtab->sh, name, symbol);
|
||||
return symbol;
|
||||
}
|
||||
|
||||
struct ovsdb_symbol *
|
||||
ovsdb_symbol_table_insert(struct ovsdb_symbol_table *symtab,
|
||||
const char *name)
|
||||
{
|
||||
struct ovsdb_symbol *symbol;
|
||||
|
||||
symbol = ovsdb_symbol_table_get(symtab, name);
|
||||
if (!symbol) {
|
||||
struct uuid uuid;
|
||||
|
||||
uuid_generate(&uuid);
|
||||
symbol = ovsdb_symbol_table_put(symtab, name, &uuid, false);
|
||||
}
|
||||
return symbol;
|
||||
}
|
||||
|
||||
/* Extracts a token from the beginning of 's' and returns a pointer just after
|
||||
|
@@ -69,7 +69,7 @@ static inline bool ovsdb_atom_equals(const union ovsdb_atom *a,
|
||||
struct ovsdb_error *ovsdb_atom_from_json(union ovsdb_atom *,
|
||||
const struct ovsdb_base_type *,
|
||||
const struct json *,
|
||||
const struct ovsdb_symbol_table *)
|
||||
struct ovsdb_symbol_table *)
|
||||
WARN_UNUSED_RESULT;
|
||||
struct json *ovsdb_atom_to_json(const union ovsdb_atom *,
|
||||
enum ovsdb_atomic_type);
|
||||
@@ -131,7 +131,7 @@ struct ovsdb_error *ovsdb_datum_check_constraints(
|
||||
struct ovsdb_error *ovsdb_datum_from_json(struct ovsdb_datum *,
|
||||
const struct ovsdb_type *,
|
||||
const struct json *,
|
||||
const struct ovsdb_symbol_table *)
|
||||
struct ovsdb_symbol_table *)
|
||||
WARN_UNUSED_RESULT;
|
||||
struct json *ovsdb_datum_to_json(const struct ovsdb_datum *,
|
||||
const struct ovsdb_type *);
|
||||
@@ -206,8 +206,11 @@ struct ovsdb_symbol_table *ovsdb_symbol_table_create(void);
|
||||
void ovsdb_symbol_table_destroy(struct ovsdb_symbol_table *);
|
||||
struct ovsdb_symbol *ovsdb_symbol_table_get(const struct ovsdb_symbol_table *,
|
||||
const char *name);
|
||||
void ovsdb_symbol_table_put(struct ovsdb_symbol_table *, const char *name,
|
||||
const struct uuid *, bool used);
|
||||
struct ovsdb_symbol *ovsdb_symbol_table_put(struct ovsdb_symbol_table *,
|
||||
const char *name,
|
||||
const struct uuid *, bool used);
|
||||
struct ovsdb_symbol *ovsdb_symbol_table_insert(struct ovsdb_symbol_table *,
|
||||
const char *name);
|
||||
|
||||
/* Tokenization
|
||||
*
|
||||
|
@@ -1103,16 +1103,6 @@ ovsdb_idl_txn_commit(struct ovsdb_idl_txn *txn)
|
||||
&column->type));
|
||||
}
|
||||
}
|
||||
if (row->new && !row->old) {
|
||||
struct json *op;
|
||||
|
||||
op = json_object_create();
|
||||
json_array_add(operations, op);
|
||||
json_object_put_string(op, "op", "declare");
|
||||
json_object_put(op, "uuid-name",
|
||||
json_string_create_nocopy(
|
||||
uuid_name_from_uuid(&row->uuid)));
|
||||
}
|
||||
}
|
||||
|
||||
/* Add updates. */
|
||||
|
64
ovsdb/SPECS
64
ovsdb/SPECS
@@ -582,13 +582,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"]
|
||||
|
||||
@@ -773,21 +773,11 @@ Semantics:
|
||||
|
||||
- "uuid": 00000000-0000-0000-0000-000000000000
|
||||
|
||||
If "uuid-name" is not supplied, the new row receives a new,
|
||||
randomly generated UUID.
|
||||
The new row receives a new, randomly generated UUID.
|
||||
|
||||
If "uuid-name" is supplied, then it is an error if <id> has
|
||||
previously appeared as the "uuid-name" in an "insert" operation.
|
||||
|
||||
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".
|
||||
|
||||
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.
|
||||
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.
|
||||
@@ -796,7 +786,7 @@ 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"
|
||||
@@ -1046,36 +1036,6 @@ Errors:
|
||||
|
||||
This operation always fails with this error.
|
||||
|
||||
declare
|
||||
.......
|
||||
|
||||
Request object members:
|
||||
|
||||
"op": "declare" required
|
||||
"uuid-name": <id> required
|
||||
|
||||
Result object members:
|
||||
|
||||
"uuid": <uuid>
|
||||
|
||||
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.
|
||||
|
||||
Errors:
|
||||
|
||||
"error": "duplicate uuid-name"
|
||||
|
||||
The same "uuid-name" appeared on an earlier "insert" or
|
||||
"declare" operation within this transaction.
|
||||
|
||||
comment
|
||||
.......
|
||||
|
||||
|
@@ -55,7 +55,7 @@ ovsdb_function_to_string(enum ovsdb_function function)
|
||||
static WARN_UNUSED_RESULT struct ovsdb_error *
|
||||
ovsdb_clause_from_json(const struct ovsdb_table_schema *ts,
|
||||
const struct json *json,
|
||||
const struct ovsdb_symbol_table *symtab,
|
||||
struct ovsdb_symbol_table *symtab,
|
||||
struct ovsdb_clause *clause)
|
||||
{
|
||||
const struct json_array *array;
|
||||
@@ -167,7 +167,7 @@ compare_clauses_3way(const void *a_, const void *b_)
|
||||
struct ovsdb_error *
|
||||
ovsdb_condition_from_json(const struct ovsdb_table_schema *ts,
|
||||
const struct json *json,
|
||||
const struct ovsdb_symbol_table *symtab,
|
||||
struct ovsdb_symbol_table *symtab,
|
||||
struct ovsdb_condition *cnd)
|
||||
{
|
||||
const struct json_array *array = json_array(json);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2009 Nicira Networks
|
||||
/* Copyright (c) 2009, 2010 Nicira Networks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -62,7 +62,7 @@ struct ovsdb_condition {
|
||||
|
||||
struct ovsdb_error *ovsdb_condition_from_json(
|
||||
const struct ovsdb_table_schema *,
|
||||
const struct json *, const struct ovsdb_symbol_table *,
|
||||
const struct json *, struct ovsdb_symbol_table *,
|
||||
struct ovsdb_condition *) WARN_UNUSED_RESULT;
|
||||
struct json *ovsdb_condition_to_json(const struct ovsdb_condition *);
|
||||
void ovsdb_condition_destroy(struct ovsdb_condition *);
|
||||
|
@@ -56,7 +56,6 @@ static ovsdb_operation_executor ovsdb_execute_delete;
|
||||
static ovsdb_operation_executor ovsdb_execute_wait;
|
||||
static ovsdb_operation_executor ovsdb_execute_commit;
|
||||
static ovsdb_operation_executor ovsdb_execute_abort;
|
||||
static ovsdb_operation_executor ovsdb_execute_declare;
|
||||
static ovsdb_operation_executor ovsdb_execute_comment;
|
||||
|
||||
static ovsdb_operation_executor *
|
||||
@@ -76,7 +75,6 @@ lookup_executor(const char *name)
|
||||
{ "wait", ovsdb_execute_wait },
|
||||
{ "commit", ovsdb_execute_commit },
|
||||
{ "abort", ovsdb_execute_abort },
|
||||
{ "declare", ovsdb_execute_declare },
|
||||
{ "comment", ovsdb_execute_comment },
|
||||
};
|
||||
|
||||
@@ -240,7 +238,7 @@ parse_table(struct ovsdb_execution *x,
|
||||
static WARN_UNUSED_RESULT struct ovsdb_error *
|
||||
parse_row(struct ovsdb_parser *parser, const char *member,
|
||||
const struct ovsdb_table *table,
|
||||
const struct ovsdb_symbol_table *symtab,
|
||||
struct ovsdb_symbol_table *symtab,
|
||||
struct ovsdb_row **rowp, struct ovsdb_column_set *columns)
|
||||
{
|
||||
struct ovsdb_error *error;
|
||||
@@ -285,20 +283,14 @@ ovsdb_execute_insert(struct ovsdb_execution *x, struct ovsdb_parser *parser,
|
||||
if (uuid_name) {
|
||||
struct ovsdb_symbol *symbol;
|
||||
|
||||
symbol = ovsdb_symbol_table_get(x->symtab, json_string(uuid_name));
|
||||
if (symbol) {
|
||||
if (symbol->used) {
|
||||
return ovsdb_syntax_error(uuid_name, "duplicate uuid-name",
|
||||
"This \"uuid-name\" appeared on an "
|
||||
"earlier \"insert\" operation.");
|
||||
}
|
||||
row_uuid = symbol->uuid;
|
||||
symbol->used = true;
|
||||
} else {
|
||||
uuid_generate(&row_uuid);
|
||||
ovsdb_symbol_table_put(x->symtab, json_string(uuid_name),
|
||||
&row_uuid, true);
|
||||
symbol = ovsdb_symbol_table_insert(x->symtab, json_string(uuid_name));
|
||||
if (symbol->used) {
|
||||
return ovsdb_syntax_error(uuid_name, "duplicate uuid-name",
|
||||
"This \"uuid-name\" appeared on an "
|
||||
"earlier \"insert\" operation.");
|
||||
}
|
||||
row_uuid = symbol->uuid;
|
||||
symbol->used = true;
|
||||
} else {
|
||||
uuid_generate(&row_uuid);
|
||||
}
|
||||
@@ -689,35 +681,6 @@ ovsdb_execute_wait(struct ovsdb_execution *x, struct ovsdb_parser *parser,
|
||||
return error;
|
||||
}
|
||||
|
||||
static struct ovsdb_error *
|
||||
ovsdb_execute_declare(struct ovsdb_execution *x, struct ovsdb_parser *parser,
|
||||
struct json *result)
|
||||
{
|
||||
const struct json *uuid_name;
|
||||
struct uuid uuid;
|
||||
|
||||
uuid_name = ovsdb_parser_member(parser, "uuid-name", OP_ID);
|
||||
if (!uuid_name) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ovsdb_symbol_table_get(x->symtab, json_string(uuid_name))) {
|
||||
return ovsdb_syntax_error(uuid_name, "duplicate uuid-name",
|
||||
"This \"uuid-name\" appeared on an "
|
||||
"earlier \"declare\" or \"insert\" "
|
||||
"operation.");
|
||||
}
|
||||
|
||||
uuid_generate(&uuid);
|
||||
ovsdb_symbol_table_put(x->symtab, json_string(uuid_name), &uuid, false);
|
||||
json_object_put(result, "uuid",
|
||||
json_array_create_2(
|
||||
json_string_create("uuid"),
|
||||
json_string_create_nocopy(
|
||||
xasprintf(UUID_FMT, UUID_ARGS(&uuid)))));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct ovsdb_error *
|
||||
ovsdb_execute_comment(struct ovsdb_execution *x, struct ovsdb_parser *parser,
|
||||
struct json *result UNUSED)
|
||||
|
@@ -72,7 +72,7 @@ type_mismatch(const struct ovsdb_mutation *m, const struct json *json)
|
||||
static WARN_UNUSED_RESULT struct ovsdb_error *
|
||||
ovsdb_mutation_from_json(const struct ovsdb_table_schema *ts,
|
||||
const struct json *json,
|
||||
const struct ovsdb_symbol_table *symtab,
|
||||
struct ovsdb_symbol_table *symtab,
|
||||
struct ovsdb_mutation *m)
|
||||
{
|
||||
const struct json_array *array;
|
||||
@@ -164,7 +164,7 @@ ovsdb_mutation_free(struct ovsdb_mutation *m)
|
||||
struct ovsdb_error *
|
||||
ovsdb_mutation_set_from_json(const struct ovsdb_table_schema *ts,
|
||||
const struct json *json,
|
||||
const struct ovsdb_symbol_table *symtab,
|
||||
struct ovsdb_symbol_table *symtab,
|
||||
struct ovsdb_mutation_set *set)
|
||||
{
|
||||
const struct json_array *array = json_array(json);
|
||||
|
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2009 Nicira Networks
|
||||
/* Copyright (c) 2009, 2010 Nicira Networks
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -62,7 +62,7 @@ struct ovsdb_mutation_set {
|
||||
|
||||
struct ovsdb_error *ovsdb_mutation_set_from_json(
|
||||
const struct ovsdb_table_schema *,
|
||||
const struct json *, const struct ovsdb_symbol_table *,
|
||||
const struct json *, struct ovsdb_symbol_table *,
|
||||
struct ovsdb_mutation_set *) WARN_UNUSED_RESULT;
|
||||
struct json *ovsdb_mutation_set_to_json(const struct ovsdb_mutation_set *);
|
||||
void ovsdb_mutation_set_destroy(struct ovsdb_mutation_set *);
|
||||
|
@@ -160,7 +160,7 @@ ovsdb_row_update_columns(struct ovsdb_row *dst,
|
||||
|
||||
struct ovsdb_error *
|
||||
ovsdb_row_from_json(struct ovsdb_row *row, const struct json *json,
|
||||
const struct ovsdb_symbol_table *symtab,
|
||||
struct ovsdb_symbol_table *symtab,
|
||||
struct ovsdb_column_set *included)
|
||||
{
|
||||
struct ovsdb_table_schema *schema = row->table->schema;
|
||||
|
@@ -57,7 +57,7 @@ void ovsdb_row_update_columns(struct ovsdb_row *, const struct ovsdb_row *,
|
||||
|
||||
struct ovsdb_error *ovsdb_row_from_json(struct ovsdb_row *,
|
||||
const struct json *,
|
||||
const struct ovsdb_symbol_table *,
|
||||
struct ovsdb_symbol_table *,
|
||||
struct ovsdb_column_set *included)
|
||||
WARN_UNUSED_RESULT;
|
||||
struct json *ovsdb_row_to_json(const struct ovsdb_row *,
|
||||
|
@@ -443,11 +443,7 @@ OVSDB_CHECK_EXECUTION([referential integrity -- simple],
|
||||
|
||||
OVSDB_CHECK_EXECUTION([referential integrity -- mutual references],
|
||||
[CONSTRAINT_SCHEMA],
|
||||
[[[[{"op": "declare",
|
||||
"uuid-name": "row1"},
|
||||
{"op": "declare",
|
||||
"uuid-name": "row2"},
|
||||
{"op": "insert",
|
||||
[[[[{"op": "insert",
|
||||
"table": "a",
|
||||
"row": {"a": 0,
|
||||
"a2b": ["set", [["named-uuid", "row2"]]],
|
||||
@@ -481,7 +477,7 @@ OVSDB_CHECK_EXECUTION([referential integrity -- mutual references],
|
||||
{"op": "delete",
|
||||
"table": "b",
|
||||
"where": [["b", "==", 1]]}]]]],
|
||||
[[[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]
|
||||
[[[{"uuid":["uuid","<0>"]},{"uuid":["uuid","<1>"]}]
|
||||
[{"uuid":["uuid","<2>"]},{"details":"reference to nonexistent row <3>","error":"referential integrity violation"}]
|
||||
[{"count":1},{"details":"cannot delete a row <0> because of 1 remaining reference(s)","error":"referential integrity violation"}]
|
||||
[{"count":1},{"details":"cannot delete b row <1> because of 1 remaining reference(s)","error":"referential integrity violation"}]
|
||||
|
@@ -184,11 +184,7 @@ OVSDB_CHECK_IDL([self-linking idl, consistent ops],
|
||||
"table": "link1",
|
||||
"row": {"i": 0, "k": ["named-uuid", "self"]},
|
||||
"uuid-name": "self"}]' \
|
||||
'[{"op": "declare",
|
||||
"uuid-name": "row1"},
|
||||
{"op": "declare",
|
||||
"uuid-name": "row2"},
|
||||
{"op": "insert",
|
||||
'[{"op": "insert",
|
||||
"table": "link1",
|
||||
"row": {"i": 1, "k": ["named-uuid", "row2"]},
|
||||
"uuid-name": "row1"},
|
||||
@@ -207,7 +203,7 @@ OVSDB_CHECK_IDL([self-linking idl, consistent ops],
|
||||
[[000: empty
|
||||
001: {"error":null,"result":[{"uuid":["uuid","<0>"]}]}
|
||||
002: i=0 k=0 ka=[] l2= uuid=<0>
|
||||
003: {"error":null,"result":[{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]},{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]}]}
|
||||
003: {"error":null,"result":[{"uuid":["uuid","<1>"]},{"uuid":["uuid","<2>"]}]}
|
||||
004: i=0 k=0 ka=[] l2= uuid=<0>
|
||||
004: i=1 k=2 ka=[] l2= uuid=<1>
|
||||
004: i=2 k=1 ka=[] l2= uuid=<2>
|
||||
|
Reference in New Issue
Block a user