Skip to content

Commit

Permalink
db-ctl-base: Don't die in get_row_by_id() on multiple matches.
Browse files Browse the repository at this point in the history
Signal that multiple rows match the record identifier via a new output
parameter instead of reporting the problem and dying, so that the caller
can handle the error without terminating the process if needed.

Signed-off-by: Jakub Sitnicki <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
Jakub Sitnicki authored and blp committed Jul 3, 2018
1 parent 9065ca4 commit 28fcaca
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions lib/db-ctl-base.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,11 @@ record_id_equals(const union ovsdb_atom *name, enum ovsdb_atomic_type type,
static const struct ovsdb_idl_row *
get_row_by_id(struct ctl_context *ctx,
const struct ovsdb_idl_table_class *table,
const struct ctl_row_id *id, const char *record_id)
const struct ctl_row_id *id, const char *record_id,
bool *multiple_matches)
{
ovs_assert(multiple_matches);
*multiple_matches = false;

if (!id->name_column) {
return NULL;
Expand Down Expand Up @@ -336,8 +339,8 @@ get_row_by_id(struct ctl_context *ctx,
/* If the name equals 'record_id', take it. */
if (record_id_equals(name, name_type, record_id)) {
if (referrer) {
ctl_fatal("multiple rows in %s match \"%s\"",
id_table->name, record_id);
*multiple_matches = true;
return NULL;
}
referrer = row;
}
Expand Down Expand Up @@ -386,8 +389,18 @@ ctl_get_row(struct ctl_context *ctx,
const struct ctl_table_class *ctl_class
= &ctl_classes[table - idl_classes];
for (int i = 0; i < ARRAY_SIZE(ctl_class->row_ids); i++) {
row = get_row_by_id(ctx, table, &ctl_class->row_ids[i],
record_id);
const struct ctl_row_id *id = &ctl_class->row_ids[i];
bool multiple_matches;

row = get_row_by_id(ctx, table, id, record_id, &multiple_matches);
if (multiple_matches) {
const struct ovsdb_idl_class *class =
ovsdb_idl_get_class(ctx->idl);
const struct ovsdb_idl_table_class *table_class =
ovsdb_idl_table_class_from_column(class, id->name_column);
ctl_fatal("multiple rows in %s match \"%s\"",
table_class->name, record_id);
}
if (row) {
break;
}
Expand Down

0 comments on commit 28fcaca

Please sign in to comment.