summaryrefslogtreecommitdiff
path: root/ovsdb/execution.c
blob: a96abfcaf959d6f463fb0f8b7348228ef34dddf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
/* 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.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <config.h>

#include <assert.h>
#include <limits.h>

#include "column.h"
#include "condition.h"
#include "file.h"
#include "json.h"
#include "mutation.h"
#include "ovsdb-data.h"
#include "ovsdb-error.h"
#include "ovsdb-parser.h"
#include "ovsdb.h"
#include "query.h"
#include "row.h"
#include "table.h"
#include "timeval.h"
#include "transaction.h"

struct ovsdb_execution {
    struct ovsdb *db;
    struct ovsdb_txn *txn;
    struct ovsdb_symbol_table *symtab;
    bool durable;

    /* Triggers. */
    long long int elapsed_msec;
    long long int timeout_msec;
};

typedef struct ovsdb_error *ovsdb_operation_executor(struct ovsdb_execution *,
                                                     struct ovsdb_parser *,
                                                     struct json *result);

static ovsdb_operation_executor ovsdb_execute_insert;
static ovsdb_operation_executor ovsdb_execute_select;
static ovsdb_operation_executor ovsdb_execute_update;
static ovsdb_operation_executor ovsdb_execute_mutate;
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_comment;

static ovsdb_operation_executor *
lookup_executor(const char *name)
{
    struct ovsdb_operation {
        const char *name;
        ovsdb_operation_executor *executor;
    };

    static const struct ovsdb_operation operations[] = {
        { "insert", ovsdb_execute_insert },
        { "select", ovsdb_execute_select },
        { "update", ovsdb_execute_update },
        { "mutate", ovsdb_execute_mutate },
        { "delete", ovsdb_execute_delete },
        { "wait", ovsdb_execute_wait },
        { "commit", ovsdb_execute_commit },
        { "abort", ovsdb_execute_abort },
        { "comment", ovsdb_execute_comment },
    };

    size_t i;

    for (i = 0; i < ARRAY_SIZE(operations); i++) {
        const struct ovsdb_operation *c = &operations[i];
        if (!strcmp(c->name, name)) {
            return c->executor;
        }
    }
    return NULL;
}

struct json *
ovsdb_execute(struct ovsdb *db, const struct json *params,
              long long int elapsed_msec, long long int *timeout_msec)
{
    struct ovsdb_execution x;
    struct ovsdb_error *error;
    struct json *results;
    size_t n_operations;
    size_t i;

    if (params->type != JSON_ARRAY
        || !params->u.array.n
        || params->u.array.elems[0]->type != JSON_STRING
        || strcmp(params->u.array.elems[0]->u.string, db->schema->name)) {
        if (params->type != JSON_ARRAY) {
            error = ovsdb_syntax_error(params, NULL, "array expected");
        } else {
            error = ovsdb_syntax_error(params, NULL, "database name expected "
                                       "as first parameter");
        }

        results = ovsdb_error_to_json(error);
        ovsdb_error_destroy(error);
        return results;
    }

    x.db = db;
    x.txn = ovsdb_txn_create(db);
    x.symtab = ovsdb_symbol_table_create();
    x.durable = false;
    x.elapsed_msec = elapsed_msec;
    x.timeout_msec = LLONG_MAX;
    results = NULL;

    results = json_array_create_empty();
    n_operations = params->u.array.n - 1;
    error = NULL;
    for (i = 1; i <= n_operations; i++) {
        struct json *operation = params->u.array.elems[i];
        struct ovsdb_error *parse_error;
        struct ovsdb_parser parser;
        struct json *result;
        const struct json *op;

        /* Parse and execute operation. */
        ovsdb_parser_init(&parser, operation,
                          "ovsdb operation %zu of %zu", i, n_operations);
        op = ovsdb_parser_member(&parser, "op", OP_ID);
        result = json_object_create();
        if (op) {
            const char *op_name = json_string(op);
            ovsdb_operation_executor *executor = lookup_executor(op_name);
            if (executor) {
                error = executor(&x, &parser, result);
            } else {
                ovsdb_parser_raise_error(&parser, "No operation \"%s\"",
                                         op_name);
            }
        } else {
            assert(ovsdb_parser_has_error(&parser));
        }

        /* A parse error overrides any other error.
         * An error overrides any other result. */
        parse_error = ovsdb_parser_finish(&parser);
        if (parse_error) {
            ovsdb_error_destroy(error);
            error = parse_error;
        }
        if (error) {
            json_destroy(result);
            result = ovsdb_error_to_json(error);
        }
        if (error && !strcmp(ovsdb_error_get_tag(error), "not supported")
            && timeout_msec) {
            ovsdb_txn_abort(x.txn);
            *timeout_msec = x.timeout_msec;

            json_destroy(result);
            json_destroy(results);
            results = NULL;
            goto exit;
        }

        /* Add result to array. */
        json_array_add(results, result);
        if (error) {
            break;
        }
    }

    if (!error) {
        error = ovsdb_txn_commit(x.txn, x.durable);
        if (error) {
            json_array_add(results, ovsdb_error_to_json(error));
        }
    } else {
        ovsdb_txn_abort(x.txn);
    }

    while (json_array(results)->n < n_operations) {
        json_array_add(results, json_null_create());
    }

exit:
    ovsdb_error_destroy(error);
    ovsdb_symbol_table_destroy(x.symtab);

    return results;
}

struct ovsdb_error *
ovsdb_execute_commit(struct ovsdb_execution *x, struct ovsdb_parser *parser,
                     struct json *result OVS_UNUSED)
{
    const struct json *durable;

    durable = ovsdb_parser_member(parser, "durable", OP_BOOLEAN);
    if (durable && json_boolean(durable)) {
        x->durable = true;
    }
    return NULL;
}

static struct ovsdb_error *
ovsdb_execute_abort(struct ovsdb_execution *x OVS_UNUSED,
                    struct ovsdb_parser *parser OVS_UNUSED,
                    struct json *result OVS_UNUSED)
{
    return ovsdb_error("aborted", "aborted by request");
}

static struct ovsdb_table *
parse_table(struct ovsdb_execution *x,
            struct ovsdb_parser *parser, const char *member)
{
    struct ovsdb_table *table;
    const char *table_name;
    const struct json *json;

    json = ovsdb_parser_member(parser, member, OP_ID);
    if (!json) {
        return NULL;
    }
    table_name = json_string(json);

    table = shash_find_data(&x->db->tables, table_name);
    if (!table) {
        ovsdb_parser_raise_error(parser, "No table named %s.", table_name);
    }
    return table;
}

static WARN_UNUSED_RESULT struct ovsdb_error *
parse_row(struct ovsdb_parser *parser, const char *member,
          const struct ovsdb_table *table,
          struct ovsdb_symbol_table *symtab,
          struct ovsdb_row **rowp, struct ovsdb_column_set *columns)
{
    struct ovsdb_error *error;
    const struct json *json;
    struct ovsdb_row *row;

    *rowp = NULL;

    if (!table) {
        return OVSDB_BUG("null table");
    }
    json = ovsdb_parser_member(parser, member, OP_OBJECT);
    if (!json) {
        return OVSDB_BUG("null row member");
    }

    row = ovsdb_row_create(table);
    error = ovsdb_row_from_json(row, json, symtab, columns);
    if (error) {
        ovsdb_row_destroy(row);
        return error;
    } else {
        *rowp = row;
        return NULL;
    }
}

struct ovsdb_error *
ovsdb_execute_insert(struct ovsdb_execution *x, struct ovsdb_parser *parser,
                     struct json *result)
{
    struct ovsdb_table *table;
    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);

    if (uuid_name) {
        struct ovsdb_symbol *symbol;

        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);
    }

    if (!error) {
        error = parse_row(parser, "row", table, x->symtab, &row, NULL);
    }
    if (!error) {
        /* Check constraints for columns not included in "row", in case the
         * default values do not satisfy the constraints.  We could check only
         * the columns that have their default values by supplying an
         * ovsdb_column_set to parse_row() above, but I suspect that this is
         * cheaper.  */
        const struct shash_node *node;

        SHASH_FOR_EACH (node, &table->schema->columns) {
            const struct ovsdb_column *column = node->data;
            const struct ovsdb_datum *datum = &row->fields[column->index];

            /* If there are 0 keys or pairs, there's nothing to check.
             * If there is 1, it might be a default value.
             * If there are more, it can't be a default value, so the value has
             * already been checked. */
            if (datum->n == 1) {
                error = ovsdb_datum_check_constraints(datum, &column->type);
                if (error) {
                    ovsdb_row_destroy(row);
                    break;
                }
            }
        }
    }
    if (!error) {
        *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],
                                            &ovsdb_type_uuid));
    }
    return error;
}

struct ovsdb_error *
ovsdb_execute_select(struct ovsdb_execution *x, struct ovsdb_parser *parser,
                     struct json *result)
{
    struct ovsdb_table *table;
    const struct json *where, *columns_json, *sort_json;
    struct ovsdb_condition condition = OVSDB_CONDITION_INITIALIZER;
    struct ovsdb_column_set columns = OVSDB_COLUMN_SET_INITIALIZER;
    struct ovsdb_column_set sort = OVSDB_COLUMN_SET_INITIALIZER;
    struct ovsdb_error *error;

    table = parse_table(x, parser, "table");
    where = ovsdb_parser_member(parser, "where", OP_ARRAY);
    columns_json = ovsdb_parser_member(parser, "columns",
                                       OP_ARRAY | OP_OPTIONAL);
    sort_json = ovsdb_parser_member(parser, "sort", OP_ARRAY | OP_OPTIONAL);

    error = ovsdb_parser_get_error(parser);
    if (!error) {
        error = ovsdb_condition_from_json(table->schema, where, x->symtab,
                                          &condition);
    }
    if (!error) {
        error = ovsdb_column_set_from_json(columns_json, table, &columns);
    }
    if (!error) {
        error = ovsdb_column_set_from_json(sort_json, table, &sort);
    }
    if (!error) {
        struct ovsdb_row_set rows = OVSDB_ROW_SET_INITIALIZER;

        ovsdb_query_distinct(table, &condition, &columns, &rows);
        ovsdb_row_set_sort(&rows, &sort);
        json_object_put(result, "rows",
                        ovsdb_row_set_to_json(&rows, &columns));

        ovsdb_row_set_destroy(&rows);
    }

    ovsdb_column_set_destroy(&columns);
    ovsdb_column_set_destroy(&sort);
    ovsdb_condition_destroy(&condition);

    return error;
}

struct update_row_cbdata {
    size_t n_matches;
    struct ovsdb_txn *txn;
    const struct ovsdb_row *row;
    const struct ovsdb_column_set *columns;
};

static bool
update_row_cb(const struct ovsdb_row *row, void *ur_)
{
    struct update_row_cbdata *ur = ur_;

    ur->n_matches++;
    if (!ovsdb_row_equal_columns(row, ur->row, ur->columns)) {
        ovsdb_row_update_columns(ovsdb_txn_row_modify(ur->txn, row),
                                 ur->row, ur->columns);
    }

    return true;
}

struct ovsdb_error *
ovsdb_execute_update(struct ovsdb_execution *x, struct ovsdb_parser *parser,
                     struct json *result)
{
    struct ovsdb_table *table;
    const struct json *where;
    struct ovsdb_condition condition = OVSDB_CONDITION_INITIALIZER;
    struct ovsdb_column_set columns = OVSDB_COLUMN_SET_INITIALIZER;
    struct ovsdb_row *row = NULL;
    struct update_row_cbdata ur;
    struct ovsdb_error *error;

    table = parse_table(x, parser, "table");
    where = ovsdb_parser_member(parser, "where", OP_ARRAY);
    error = ovsdb_parser_get_error(parser);
    if (!error) {
        error = parse_row(parser, "row", table, x->symtab, &row, &columns);
    }
    if (!error) {
        error = ovsdb_condition_from_json(table->schema, where, x->symtab,
                                          &condition);
    }
    if (!error) {
        ur.n_matches = 0;
        ur.txn = x->txn;
        ur.row = row;
        ur.columns = &columns;
        ovsdb_query(table, &condition, update_row_cb, &ur);
        json_object_put(result, "count", json_integer_create(ur.n_matches));
    }

    ovsdb_row_destroy(row);
    ovsdb_column_set_destroy(&columns);
    ovsdb_condition_destroy(&condition);

    return error;
}

struct mutate_row_cbdata {
    size_t n_matches;
    struct ovsdb_txn *txn;
    const struct ovsdb_mutation_set *mutations;
};

static bool
mutate_row_cb(const struct ovsdb_row *row, void *mr_)
{
    struct mutate_row_cbdata *mr = mr_;

    mr->n_matches++;
    ovsdb_mutation_set_execute(ovsdb_txn_row_modify(mr->txn, row),
                               mr->mutations);

    return true;
}

struct ovsdb_error *
ovsdb_execute_mutate(struct ovsdb_execution *x, struct ovsdb_parser *parser,
                     struct json *result)
{
    struct ovsdb_table *table;
    const struct json *where;
    const struct json *mutations_json;
    struct ovsdb_condition condition = OVSDB_CONDITION_INITIALIZER;
    struct ovsdb_mutation_set mutations = OVSDB_MUTATION_SET_INITIALIZER;
    struct ovsdb_row *row = NULL;
    struct mutate_row_cbdata mr;
    struct ovsdb_error *error;

    table = parse_table(x, parser, "table");
    where = ovsdb_parser_member(parser, "where", OP_ARRAY);
    mutations_json = ovsdb_parser_member(parser, "mutations", OP_ARRAY);
    error = ovsdb_parser_get_error(parser);
    if (!error) {
        error = ovsdb_mutation_set_from_json(table->schema, mutations_json,
                                             x->symtab, &mutations);
    }
    if (!error) {
        error = ovsdb_condition_from_json(table->schema, where, x->symtab,
                                          &condition);
    }
    if (!error) {
        mr.n_matches = 0;
        mr.txn = x->txn;
        mr.mutations = &mutations;
        ovsdb_query(table, &condition, mutate_row_cb, &mr);
        json_object_put(result, "count", json_integer_create(mr.n_matches));
    }

    ovsdb_row_destroy(row);
    ovsdb_mutation_set_destroy(&mutations);
    ovsdb_condition_destroy(&condition);

    return error;
}

struct delete_row_cbdata {
    size_t n_matches;
    const struct ovsdb_table *table;
    struct ovsdb_txn *txn;
};

static bool
delete_row_cb(const struct ovsdb_row *row, void *dr_)
{
    struct delete_row_cbdata *dr = dr_;

    dr->n_matches++;
    ovsdb_txn_row_delete(dr->txn, row);

    return true;
}

struct ovsdb_error *
ovsdb_execute_delete(struct ovsdb_execution *x, struct ovsdb_parser *parser,
                     struct json *result)
{
    struct ovsdb_table *table;
    const struct json *where;
    struct ovsdb_condition condition = OVSDB_CONDITION_INITIALIZER;
    struct ovsdb_error *error;

    where = ovsdb_parser_member(parser, "where", OP_ARRAY);
    table = parse_table(x, parser, "table");
    error = ovsdb_parser_get_error(parser);
    if (!error) {
        error = ovsdb_condition_from_json(table->schema, where, x->symtab,
                                          &condition);
    }
    if (!error) {
        struct delete_row_cbdata dr;

        dr.n_matches = 0;
        dr.table = table;
        dr.txn = x->txn;
        ovsdb_query(table, &condition, delete_row_cb, &dr);

        json_object_put(result, "count", json_integer_create(dr.n_matches));
    }

    ovsdb_condition_destroy(&condition);

    return error;
}

struct wait_auxdata {
    struct ovsdb_row_hash *actual;
    struct ovsdb_row_hash *expected;
    bool *equal;
};

static bool
ovsdb_execute_wait_query_cb(const struct ovsdb_row *row, void *aux_)
{
    struct wait_auxdata *aux = aux_;

    if (ovsdb_row_hash_contains(aux->expected, row)) {
        ovsdb_row_hash_insert(aux->actual, row);
        return true;
    } else {
        /* The query row isn't in the expected result set, so the actual and
         * expected results sets definitely differ and we can short-circuit the
         * rest of the query. */
        *aux->equal = false;
        return false;
    }
}

static struct ovsdb_error *
ovsdb_execute_wait(struct ovsdb_execution *x, struct ovsdb_parser *parser,
                   struct json *result OVS_UNUSED)
{
    struct ovsdb_table *table;
    const struct json *timeout, *where, *columns_json, *until, *rows;
    struct ovsdb_condition condition = OVSDB_CONDITION_INITIALIZER;
    struct ovsdb_column_set columns = OVSDB_COLUMN_SET_INITIALIZER;
    struct ovsdb_row_hash expected = OVSDB_ROW_HASH_INITIALIZER(expected);
    struct ovsdb_row_hash actual = OVSDB_ROW_HASH_INITIALIZER(actual);
    struct ovsdb_error *error;
    struct wait_auxdata aux;
    long long int timeout_msec = 0;
    size_t i;

    timeout = ovsdb_parser_member(parser, "timeout", OP_NUMBER | OP_OPTIONAL);
    where = ovsdb_parser_member(parser, "where", OP_ARRAY);
    columns_json = ovsdb_parser_member(parser, "columns",
                                       OP_ARRAY | OP_OPTIONAL);
    until = ovsdb_parser_member(parser, "until", OP_STRING);
    rows = ovsdb_parser_member(parser, "rows", OP_ARRAY);
    table = parse_table(x, parser, "table");
    error = ovsdb_parser_get_error(parser);
    if (!error) {
        error = ovsdb_condition_from_json(table->schema, where, x->symtab,
                                          &condition);
    }
    if (!error) {
        error = ovsdb_column_set_from_json(columns_json, table, &columns);
    }
    if (!error) {
        if (timeout) {
            timeout_msec = MIN(LLONG_MAX, json_real(timeout));
            if (timeout_msec < 0) {
                error = ovsdb_syntax_error(timeout, NULL,
                                           "timeout must be nonnegative");
            } else if (timeout_msec < x->timeout_msec) {
                x->timeout_msec = timeout_msec;
            }
        } else {
            timeout_msec = LLONG_MAX;
        }
        if (strcmp(json_string(until), "==")
            && strcmp(json_string(until), "!=")) {
            error = ovsdb_syntax_error(until, NULL,
                                       "\"until\" must be \"==\" or \"!=\"");
        }
    }
    if (!error) {
        /* Parse "rows" into 'expected'. */
        ovsdb_row_hash_init(&expected, &columns);
        for (i = 0; i < rows->u.array.n; i++) {
            struct ovsdb_row *row;

            row = ovsdb_row_create(table);
            error = ovsdb_row_from_json(row, rows->u.array.elems[i], x->symtab,
                                        NULL);
            if (error) {
                break;
            }

            if (!ovsdb_row_hash_insert(&expected, row)) {
                /* XXX Perhaps we should abort with an error or log a
                 * warning. */
                ovsdb_row_destroy(row);
            }
        }
    }
    if (!error) {
        /* Execute query. */
        bool equal = true;
        ovsdb_row_hash_init(&actual, &columns);
        aux.actual = &actual;
        aux.expected = &expected;
        aux.equal = &equal;
        ovsdb_query(table, &condition, ovsdb_execute_wait_query_cb, &aux);
        if (equal) {
            /* We know that every row in 'actual' is also in 'expected'.  We
             * also know that all of the rows in 'actual' are distinct and that
             * all of the rows in 'expected' are distinct.  Therefore, if
             * 'actual' and 'expected' have the same number of rows, then they
             * have the same content. */
            size_t n_actual = ovsdb_row_hash_count(&actual);
            size_t n_expected = ovsdb_row_hash_count(&expected);
            equal = n_actual == n_expected;
        }
        if (!strcmp(json_string(until), "==") != equal) {
            if (timeout && x->elapsed_msec >= timeout_msec) {
                if (x->elapsed_msec) {
                    error = ovsdb_error("timed out",
                                        "\"wait\" timed out after %lld ms",
                                        x->elapsed_msec);
                } else {
                    error = ovsdb_error("timed out", "\"wait\" timed out");
                }
            } else {
                /* ovsdb_execute() will change this, if triggers really are
                 * supported. */
                error = ovsdb_error("not supported", "triggers not supported");
            }
        }
    }


    ovsdb_row_hash_destroy(&expected, true);
    ovsdb_row_hash_destroy(&actual, false);
    ovsdb_column_set_destroy(&columns);
    ovsdb_condition_destroy(&condition);

    return error;
}

static struct ovsdb_error *
ovsdb_execute_comment(struct ovsdb_execution *x, struct ovsdb_parser *parser,
                      struct json *result OVS_UNUSED)
{
    const struct json *comment;

    comment = ovsdb_parser_member(parser, "comment", OP_STRING);
    if (!comment) {
        return NULL;
    }
    ovsdb_txn_add_comment(x->txn, json_string(comment));

    return NULL;
}