300c247a3d98a3485b217006c5eb9c978e07229a
[sliver-openvswitch.git] / ovsdb / execution.c
1 /* Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <config.h>
17
18 #include <assert.h>
19 #include <limits.h>
20
21 #include "column.h"
22 #include "condition.h"
23 #include "file.h"
24 #include "json.h"
25 #include "mutation.h"
26 #include "ovsdb-data.h"
27 #include "ovsdb-error.h"
28 #include "ovsdb-parser.h"
29 #include "ovsdb.h"
30 #include "query.h"
31 #include "row.h"
32 #include "server.h"
33 #include "table.h"
34 #include "timeval.h"
35 #include "transaction.h"
36
37 struct ovsdb_execution {
38     struct ovsdb *db;
39     const struct ovsdb_session *session;
40     struct ovsdb_txn *txn;
41     struct ovsdb_symbol_table *symtab;
42     bool durable;
43
44     /* Triggers. */
45     long long int elapsed_msec;
46     long long int timeout_msec;
47 };
48
49 typedef struct ovsdb_error *ovsdb_operation_executor(struct ovsdb_execution *,
50                                                      struct ovsdb_parser *,
51                                                      struct json *result);
52
53 static ovsdb_operation_executor ovsdb_execute_insert;
54 static ovsdb_operation_executor ovsdb_execute_select;
55 static ovsdb_operation_executor ovsdb_execute_update;
56 static ovsdb_operation_executor ovsdb_execute_mutate;
57 static ovsdb_operation_executor ovsdb_execute_delete;
58 static ovsdb_operation_executor ovsdb_execute_wait;
59 static ovsdb_operation_executor ovsdb_execute_commit;
60 static ovsdb_operation_executor ovsdb_execute_abort;
61 static ovsdb_operation_executor ovsdb_execute_comment;
62 static ovsdb_operation_executor ovsdb_execute_assert;
63
64 static ovsdb_operation_executor *
65 lookup_executor(const char *name)
66 {
67     struct ovsdb_operation {
68         const char *name;
69         ovsdb_operation_executor *executor;
70     };
71
72     static const struct ovsdb_operation operations[] = {
73         { "insert", ovsdb_execute_insert },
74         { "select", ovsdb_execute_select },
75         { "update", ovsdb_execute_update },
76         { "mutate", ovsdb_execute_mutate },
77         { "delete", ovsdb_execute_delete },
78         { "wait", ovsdb_execute_wait },
79         { "commit", ovsdb_execute_commit },
80         { "abort", ovsdb_execute_abort },
81         { "comment", ovsdb_execute_comment },
82         { "assert", ovsdb_execute_assert },
83     };
84
85     size_t i;
86
87     for (i = 0; i < ARRAY_SIZE(operations); i++) {
88         const struct ovsdb_operation *c = &operations[i];
89         if (!strcmp(c->name, name)) {
90             return c->executor;
91         }
92     }
93     return NULL;
94 }
95
96 struct json *
97 ovsdb_execute(struct ovsdb *db, const struct ovsdb_session *session,
98               const struct json *params,
99               long long int elapsed_msec, long long int *timeout_msec)
100 {
101     struct ovsdb_execution x;
102     struct ovsdb_error *error;
103     struct json *results;
104     size_t n_operations;
105     size_t i;
106
107     if (params->type != JSON_ARRAY
108         || !params->u.array.n
109         || params->u.array.elems[0]->type != JSON_STRING
110         || strcmp(params->u.array.elems[0]->u.string, db->schema->name)) {
111         if (params->type != JSON_ARRAY) {
112             error = ovsdb_syntax_error(params, NULL, "array expected");
113         } else {
114             error = ovsdb_syntax_error(params, NULL, "database name expected "
115                                        "as first parameter");
116         }
117
118         results = ovsdb_error_to_json(error);
119         ovsdb_error_destroy(error);
120         return results;
121     }
122
123     x.db = db;
124     x.session = session;
125     x.txn = ovsdb_txn_create(db);
126     x.symtab = ovsdb_symbol_table_create();
127     x.durable = false;
128     x.elapsed_msec = elapsed_msec;
129     x.timeout_msec = LLONG_MAX;
130     results = NULL;
131
132     results = json_array_create_empty();
133     n_operations = params->u.array.n - 1;
134     error = NULL;
135     for (i = 1; i <= n_operations; i++) {
136         struct json *operation = params->u.array.elems[i];
137         struct ovsdb_error *parse_error;
138         struct ovsdb_parser parser;
139         struct json *result;
140         const struct json *op;
141
142         /* Parse and execute operation. */
143         ovsdb_parser_init(&parser, operation,
144                           "ovsdb operation %zu of %zu", i, n_operations);
145         op = ovsdb_parser_member(&parser, "op", OP_ID);
146         result = json_object_create();
147         if (op) {
148             const char *op_name = json_string(op);
149             ovsdb_operation_executor *executor = lookup_executor(op_name);
150             if (executor) {
151                 error = executor(&x, &parser, result);
152             } else {
153                 ovsdb_parser_raise_error(&parser, "No operation \"%s\"",
154                                          op_name);
155             }
156         } else {
157             assert(ovsdb_parser_has_error(&parser));
158         }
159
160         /* A parse error overrides any other error.
161          * An error overrides any other result. */
162         parse_error = ovsdb_parser_finish(&parser);
163         if (parse_error) {
164             ovsdb_error_destroy(error);
165             error = parse_error;
166         }
167         if (error) {
168             json_destroy(result);
169             result = ovsdb_error_to_json(error);
170         }
171         if (error && !strcmp(ovsdb_error_get_tag(error), "not supported")
172             && timeout_msec) {
173             ovsdb_txn_abort(x.txn);
174             *timeout_msec = x.timeout_msec;
175
176             json_destroy(result);
177             json_destroy(results);
178             results = NULL;
179             goto exit;
180         }
181
182         /* Add result to array. */
183         json_array_add(results, result);
184         if (error) {
185             break;
186         }
187     }
188
189     if (!error) {
190         error = ovsdb_txn_commit(x.txn, x.durable);
191         if (error) {
192             json_array_add(results, ovsdb_error_to_json(error));
193         }
194     } else {
195         ovsdb_txn_abort(x.txn);
196     }
197
198     while (json_array(results)->n < n_operations) {
199         json_array_add(results, json_null_create());
200     }
201
202 exit:
203     ovsdb_error_destroy(error);
204     ovsdb_symbol_table_destroy(x.symtab);
205
206     return results;
207 }
208
209 static struct ovsdb_error *
210 ovsdb_execute_commit(struct ovsdb_execution *x, struct ovsdb_parser *parser,
211                      struct json *result OVS_UNUSED)
212 {
213     const struct json *durable;
214
215     durable = ovsdb_parser_member(parser, "durable", OP_BOOLEAN);
216     if (durable && json_boolean(durable)) {
217         x->durable = true;
218     }
219     return NULL;
220 }
221
222 static struct ovsdb_error *
223 ovsdb_execute_abort(struct ovsdb_execution *x OVS_UNUSED,
224                     struct ovsdb_parser *parser OVS_UNUSED,
225                     struct json *result OVS_UNUSED)
226 {
227     return ovsdb_error("aborted", "aborted by request");
228 }
229
230 static struct ovsdb_table *
231 parse_table(struct ovsdb_execution *x,
232             struct ovsdb_parser *parser, const char *member)
233 {
234     struct ovsdb_table *table;
235     const char *table_name;
236     const struct json *json;
237
238     json = ovsdb_parser_member(parser, member, OP_ID);
239     if (!json) {
240         return NULL;
241     }
242     table_name = json_string(json);
243
244     table = shash_find_data(&x->db->tables, table_name);
245     if (!table) {
246         ovsdb_parser_raise_error(parser, "No table named %s.", table_name);
247     }
248     return table;
249 }
250
251 static WARN_UNUSED_RESULT struct ovsdb_error *
252 parse_row(const struct json *json, const struct ovsdb_table *table,
253           struct ovsdb_symbol_table *symtab,
254           struct ovsdb_row **rowp, struct ovsdb_column_set *columns)
255 {
256     struct ovsdb_error *error;
257     struct ovsdb_row *row;
258
259     *rowp = NULL;
260
261     if (!table) {
262         return OVSDB_BUG("null table");
263     }
264     if (!json) {
265         return OVSDB_BUG("null row");
266     }
267
268     row = ovsdb_row_create(table);
269     error = ovsdb_row_from_json(row, json, symtab, columns);
270     if (error) {
271         ovsdb_row_destroy(row);
272         return error;
273     } else {
274         *rowp = row;
275         return NULL;
276     }
277 }
278
279 static struct ovsdb_error *
280 ovsdb_execute_insert(struct ovsdb_execution *x, struct ovsdb_parser *parser,
281                      struct json *result)
282 {
283     struct ovsdb_table *table;
284     struct ovsdb_row *row = NULL;
285     const struct json *uuid_name, *row_json;
286     struct ovsdb_error *error;
287     struct uuid row_uuid;
288
289     table = parse_table(x, parser, "table");
290     uuid_name = ovsdb_parser_member(parser, "uuid-name", OP_ID | OP_OPTIONAL);
291     row_json = ovsdb_parser_member(parser, "row", OP_OBJECT);
292     error = ovsdb_parser_get_error(parser);
293     if (error) {
294         return error;
295     }
296
297     if (uuid_name) {
298         struct ovsdb_symbol *symbol;
299
300         symbol = ovsdb_symbol_table_insert(x->symtab, json_string(uuid_name));
301         if (symbol->created) {
302             return ovsdb_syntax_error(uuid_name, "duplicate uuid-name",
303                                       "This \"uuid-name\" appeared on an "
304                                       "earlier \"insert\" operation.");
305         }
306         row_uuid = symbol->uuid;
307         symbol->created = true;
308     } else {
309         uuid_generate(&row_uuid);
310     }
311
312     if (!error) {
313         error = parse_row(row_json, table, x->symtab, &row, NULL);
314     }
315     if (!error) {
316         /* Check constraints for columns not included in "row", in case the
317          * default values do not satisfy the constraints.  We could check only
318          * the columns that have their default values by supplying an
319          * ovsdb_column_set to parse_row() above, but I suspect that this is
320          * cheaper.  */
321         const struct shash_node *node;
322
323         SHASH_FOR_EACH (node, &table->schema->columns) {
324             const struct ovsdb_column *column = node->data;
325             const struct ovsdb_datum *datum = &row->fields[column->index];
326
327             /* If there are 0 keys or pairs, there's nothing to check.
328              * If there is 1, it might be a default value.
329              * If there are more, it can't be a default value, so the value has
330              * already been checked. */
331             if (datum->n == 1) {
332                 error = ovsdb_datum_check_constraints(datum, &column->type);
333                 if (error) {
334                     ovsdb_row_destroy(row);
335                     break;
336                 }
337             }
338         }
339     }
340     if (!error) {
341         *ovsdb_row_get_uuid_rw(row) = row_uuid;
342         ovsdb_txn_row_insert(x->txn, row);
343         json_object_put(result, "uuid",
344                         ovsdb_datum_to_json(&row->fields[OVSDB_COL_UUID],
345                                             &ovsdb_type_uuid));
346     }
347     return error;
348 }
349
350 static struct ovsdb_error *
351 ovsdb_execute_select(struct ovsdb_execution *x, struct ovsdb_parser *parser,
352                      struct json *result)
353 {
354     struct ovsdb_table *table;
355     const struct json *where, *columns_json, *sort_json;
356     struct ovsdb_condition condition = OVSDB_CONDITION_INITIALIZER;
357     struct ovsdb_column_set columns = OVSDB_COLUMN_SET_INITIALIZER;
358     struct ovsdb_column_set sort = OVSDB_COLUMN_SET_INITIALIZER;
359     struct ovsdb_error *error;
360
361     table = parse_table(x, parser, "table");
362     where = ovsdb_parser_member(parser, "where", OP_ARRAY);
363     columns_json = ovsdb_parser_member(parser, "columns",
364                                        OP_ARRAY | OP_OPTIONAL);
365     sort_json = ovsdb_parser_member(parser, "sort", OP_ARRAY | OP_OPTIONAL);
366
367     error = ovsdb_parser_get_error(parser);
368     if (!error) {
369         error = ovsdb_condition_from_json(table->schema, where, x->symtab,
370                                           &condition);
371     }
372     if (!error) {
373         error = ovsdb_column_set_from_json(columns_json, table->schema,
374                                            &columns);
375     }
376     if (!error) {
377         error = ovsdb_column_set_from_json(sort_json, table->schema, &sort);
378     }
379     if (!error) {
380         struct ovsdb_row_set rows = OVSDB_ROW_SET_INITIALIZER;
381
382         ovsdb_query_distinct(table, &condition, &columns, &rows);
383         ovsdb_row_set_sort(&rows, &sort);
384         json_object_put(result, "rows",
385                         ovsdb_row_set_to_json(&rows, &columns));
386
387         ovsdb_row_set_destroy(&rows);
388     }
389
390     ovsdb_column_set_destroy(&columns);
391     ovsdb_column_set_destroy(&sort);
392     ovsdb_condition_destroy(&condition);
393
394     return error;
395 }
396
397 struct update_row_cbdata {
398     size_t n_matches;
399     struct ovsdb_txn *txn;
400     const struct ovsdb_row *row;
401     const struct ovsdb_column_set *columns;
402 };
403
404 static bool
405 update_row_cb(const struct ovsdb_row *row, void *ur_)
406 {
407     struct update_row_cbdata *ur = ur_;
408
409     ur->n_matches++;
410     if (!ovsdb_row_equal_columns(row, ur->row, ur->columns)) {
411         ovsdb_row_update_columns(ovsdb_txn_row_modify(ur->txn, row),
412                                  ur->row, ur->columns);
413     }
414
415     return true;
416 }
417
418 static struct ovsdb_error *
419 ovsdb_execute_update(struct ovsdb_execution *x, struct ovsdb_parser *parser,
420                      struct json *result)
421 {
422     struct ovsdb_table *table;
423     const struct json *where, *row_json;
424     struct ovsdb_condition condition = OVSDB_CONDITION_INITIALIZER;
425     struct ovsdb_column_set columns = OVSDB_COLUMN_SET_INITIALIZER;
426     struct ovsdb_row *row = NULL;
427     struct update_row_cbdata ur;
428     struct ovsdb_error *error;
429
430     table = parse_table(x, parser, "table");
431     where = ovsdb_parser_member(parser, "where", OP_ARRAY);
432     row_json = ovsdb_parser_member(parser, "row", OP_OBJECT);
433     error = ovsdb_parser_get_error(parser);
434     if (!error) {
435         error = parse_row(row_json, table, x->symtab, &row, &columns);
436     }
437     if (!error) {
438         size_t i;
439
440         for (i = 0; i < columns.n_columns; i++) {
441             const struct ovsdb_column *column = columns.columns[i];
442
443             if (!column->mutable) {
444                 error = ovsdb_syntax_error(parser->json,
445                                            "constraint violation",
446                                            "Cannot update immutable column %s "
447                                            "in table %s.",
448                                            column->name, table->schema->name);
449                 break;
450             }
451         }
452     }
453     if (!error) {
454         error = ovsdb_condition_from_json(table->schema, where, x->symtab,
455                                           &condition);
456     }
457     if (!error) {
458         ur.n_matches = 0;
459         ur.txn = x->txn;
460         ur.row = row;
461         ur.columns = &columns;
462         ovsdb_query(table, &condition, update_row_cb, &ur);
463         json_object_put(result, "count", json_integer_create(ur.n_matches));
464     }
465
466     ovsdb_row_destroy(row);
467     ovsdb_column_set_destroy(&columns);
468     ovsdb_condition_destroy(&condition);
469
470     return error;
471 }
472
473 struct mutate_row_cbdata {
474     size_t n_matches;
475     struct ovsdb_txn *txn;
476     const struct ovsdb_mutation_set *mutations;
477     struct ovsdb_error **error;
478 };
479
480 static bool
481 mutate_row_cb(const struct ovsdb_row *row, void *mr_)
482 {
483     struct mutate_row_cbdata *mr = mr_;
484
485     mr->n_matches++;
486     *mr->error = ovsdb_mutation_set_execute(ovsdb_txn_row_modify(mr->txn, row),
487                                             mr->mutations);
488     return *mr->error == NULL;
489 }
490
491 static struct ovsdb_error *
492 ovsdb_execute_mutate(struct ovsdb_execution *x, struct ovsdb_parser *parser,
493                      struct json *result)
494 {
495     struct ovsdb_table *table;
496     const struct json *where;
497     const struct json *mutations_json;
498     struct ovsdb_condition condition = OVSDB_CONDITION_INITIALIZER;
499     struct ovsdb_mutation_set mutations = OVSDB_MUTATION_SET_INITIALIZER;
500     struct ovsdb_row *row = NULL;
501     struct mutate_row_cbdata mr;
502     struct ovsdb_error *error;
503
504     table = parse_table(x, parser, "table");
505     where = ovsdb_parser_member(parser, "where", OP_ARRAY);
506     mutations_json = ovsdb_parser_member(parser, "mutations", OP_ARRAY);
507     error = ovsdb_parser_get_error(parser);
508     if (!error) {
509         error = ovsdb_mutation_set_from_json(table->schema, mutations_json,
510                                              x->symtab, &mutations);
511     }
512     if (!error) {
513         error = ovsdb_condition_from_json(table->schema, where, x->symtab,
514                                           &condition);
515     }
516     if (!error) {
517         mr.n_matches = 0;
518         mr.txn = x->txn;
519         mr.mutations = &mutations;
520         mr.error = &error;
521         ovsdb_query(table, &condition, mutate_row_cb, &mr);
522         json_object_put(result, "count", json_integer_create(mr.n_matches));
523     }
524
525     ovsdb_row_destroy(row);
526     ovsdb_mutation_set_destroy(&mutations);
527     ovsdb_condition_destroy(&condition);
528
529     return error;
530 }
531
532 struct delete_row_cbdata {
533     size_t n_matches;
534     const struct ovsdb_table *table;
535     struct ovsdb_txn *txn;
536 };
537
538 static bool
539 delete_row_cb(const struct ovsdb_row *row, void *dr_)
540 {
541     struct delete_row_cbdata *dr = dr_;
542
543     dr->n_matches++;
544     ovsdb_txn_row_delete(dr->txn, row);
545
546     return true;
547 }
548
549 static struct ovsdb_error *
550 ovsdb_execute_delete(struct ovsdb_execution *x, struct ovsdb_parser *parser,
551                      struct json *result)
552 {
553     struct ovsdb_table *table;
554     const struct json *where;
555     struct ovsdb_condition condition = OVSDB_CONDITION_INITIALIZER;
556     struct ovsdb_error *error;
557
558     where = ovsdb_parser_member(parser, "where", OP_ARRAY);
559     table = parse_table(x, parser, "table");
560     error = ovsdb_parser_get_error(parser);
561     if (!error) {
562         error = ovsdb_condition_from_json(table->schema, where, x->symtab,
563                                           &condition);
564     }
565     if (!error) {
566         struct delete_row_cbdata dr;
567
568         dr.n_matches = 0;
569         dr.table = table;
570         dr.txn = x->txn;
571         ovsdb_query(table, &condition, delete_row_cb, &dr);
572
573         json_object_put(result, "count", json_integer_create(dr.n_matches));
574     }
575
576     ovsdb_condition_destroy(&condition);
577
578     return error;
579 }
580
581 struct wait_auxdata {
582     struct ovsdb_row_hash *actual;
583     struct ovsdb_row_hash *expected;
584     bool *equal;
585 };
586
587 static bool
588 ovsdb_execute_wait_query_cb(const struct ovsdb_row *row, void *aux_)
589 {
590     struct wait_auxdata *aux = aux_;
591
592     if (ovsdb_row_hash_contains(aux->expected, row)) {
593         ovsdb_row_hash_insert(aux->actual, row);
594         return true;
595     } else {
596         /* The query row isn't in the expected result set, so the actual and
597          * expected results sets definitely differ and we can short-circuit the
598          * rest of the query. */
599         *aux->equal = false;
600         return false;
601     }
602 }
603
604 static struct ovsdb_error *
605 ovsdb_execute_wait(struct ovsdb_execution *x, struct ovsdb_parser *parser,
606                    struct json *result OVS_UNUSED)
607 {
608     struct ovsdb_table *table;
609     const struct json *timeout, *where, *columns_json, *until, *rows;
610     struct ovsdb_condition condition = OVSDB_CONDITION_INITIALIZER;
611     struct ovsdb_column_set columns = OVSDB_COLUMN_SET_INITIALIZER;
612     struct ovsdb_row_hash expected = OVSDB_ROW_HASH_INITIALIZER(expected);
613     struct ovsdb_row_hash actual = OVSDB_ROW_HASH_INITIALIZER(actual);
614     struct ovsdb_error *error;
615     struct wait_auxdata aux;
616     long long int timeout_msec = 0;
617     size_t i;
618
619     timeout = ovsdb_parser_member(parser, "timeout", OP_NUMBER | OP_OPTIONAL);
620     where = ovsdb_parser_member(parser, "where", OP_ARRAY);
621     columns_json = ovsdb_parser_member(parser, "columns",
622                                        OP_ARRAY | OP_OPTIONAL);
623     until = ovsdb_parser_member(parser, "until", OP_STRING);
624     rows = ovsdb_parser_member(parser, "rows", OP_ARRAY);
625     table = parse_table(x, parser, "table");
626     error = ovsdb_parser_get_error(parser);
627     if (!error) {
628         error = ovsdb_condition_from_json(table->schema, where, x->symtab,
629                                           &condition);
630     }
631     if (!error) {
632         error = ovsdb_column_set_from_json(columns_json, table->schema,
633                                            &columns);
634     }
635     if (!error) {
636         if (timeout) {
637             timeout_msec = MIN(LLONG_MAX, json_real(timeout));
638             if (timeout_msec < 0) {
639                 error = ovsdb_syntax_error(timeout, NULL,
640                                            "timeout must be nonnegative");
641             } else if (timeout_msec < x->timeout_msec) {
642                 x->timeout_msec = timeout_msec;
643             }
644         } else {
645             timeout_msec = LLONG_MAX;
646         }
647         if (strcmp(json_string(until), "==")
648             && strcmp(json_string(until), "!=")) {
649             error = ovsdb_syntax_error(until, NULL,
650                                        "\"until\" must be \"==\" or \"!=\"");
651         }
652     }
653     if (!error) {
654         /* Parse "rows" into 'expected'. */
655         ovsdb_row_hash_init(&expected, &columns);
656         for (i = 0; i < rows->u.array.n; i++) {
657             struct ovsdb_row *row;
658
659             row = ovsdb_row_create(table);
660             error = ovsdb_row_from_json(row, rows->u.array.elems[i], x->symtab,
661                                         NULL);
662             if (error) {
663                 break;
664             }
665
666             if (!ovsdb_row_hash_insert(&expected, row)) {
667                 /* XXX Perhaps we should abort with an error or log a
668                  * warning. */
669                 ovsdb_row_destroy(row);
670             }
671         }
672     }
673     if (!error) {
674         /* Execute query. */
675         bool equal = true;
676         ovsdb_row_hash_init(&actual, &columns);
677         aux.actual = &actual;
678         aux.expected = &expected;
679         aux.equal = &equal;
680         ovsdb_query(table, &condition, ovsdb_execute_wait_query_cb, &aux);
681         if (equal) {
682             /* We know that every row in 'actual' is also in 'expected'.  We
683              * also know that all of the rows in 'actual' are distinct and that
684              * all of the rows in 'expected' are distinct.  Therefore, if
685              * 'actual' and 'expected' have the same number of rows, then they
686              * have the same content. */
687             size_t n_actual = ovsdb_row_hash_count(&actual);
688             size_t n_expected = ovsdb_row_hash_count(&expected);
689             equal = n_actual == n_expected;
690         }
691         if (!strcmp(json_string(until), "==") != equal) {
692             if (timeout && x->elapsed_msec >= timeout_msec) {
693                 if (x->elapsed_msec) {
694                     error = ovsdb_error("timed out",
695                                         "\"wait\" timed out after %lld ms",
696                                         x->elapsed_msec);
697                 } else {
698                     error = ovsdb_error("timed out", "\"wait\" timed out");
699                 }
700             } else {
701                 /* ovsdb_execute() will change this, if triggers really are
702                  * supported. */
703                 error = ovsdb_error("not supported", "triggers not supported");
704             }
705         }
706     }
707
708
709     ovsdb_row_hash_destroy(&expected, true);
710     ovsdb_row_hash_destroy(&actual, false);
711     ovsdb_column_set_destroy(&columns);
712     ovsdb_condition_destroy(&condition);
713
714     return error;
715 }
716
717 static struct ovsdb_error *
718 ovsdb_execute_comment(struct ovsdb_execution *x, struct ovsdb_parser *parser,
719                       struct json *result OVS_UNUSED)
720 {
721     const struct json *comment;
722
723     comment = ovsdb_parser_member(parser, "comment", OP_STRING);
724     if (!comment) {
725         return NULL;
726     }
727     ovsdb_txn_add_comment(x->txn, json_string(comment));
728
729     return NULL;
730 }
731
732 static struct ovsdb_error *
733 ovsdb_execute_assert(struct ovsdb_execution *x, struct ovsdb_parser *parser,
734                      struct json *result OVS_UNUSED)
735 {
736     const struct json *lock_name;
737
738     lock_name = ovsdb_parser_member(parser, "lock", OP_ID);
739     if (!lock_name) {
740         return NULL;
741     }
742
743     if (x->session) {
744         const struct ovsdb_lock_waiter *waiter;
745
746         waiter = ovsdb_session_get_lock_waiter(x->session,
747                                                json_string(lock_name));
748         if (waiter && ovsdb_lock_waiter_is_owner(waiter)) {
749             return NULL;
750         }
751     }
752
753     return ovsdb_error("not owner", "Asserted lock %s not held.",
754                        json_string(lock_name));
755 }