In current IDL index code it doesn't updated index when handling "update2" messages, which is the default case. The consequence is that when a row is updated, the index is not updated accordingly, and even worse, it causes crash when calling ovsdb_idl_destroy(). It can be easily reproduced by the test cases added in this patch.
Signed-off-by: Han Zhou <[email protected]> --- lib/ovsdb-idl.c | 2 ++ tests/ovsdb-idl.at | 34 ++++++++++++++++++++++------------ tests/test-ovsdb.c | 22 ++++++++++++++++++++++ 3 files changed, 46 insertions(+), 12 deletions(-) diff --git a/lib/ovsdb-idl.c b/lib/ovsdb-idl.c index 40c29cb..8fdd18f 100644 --- a/lib/ovsdb-idl.c +++ b/lib/ovsdb-idl.c @@ -3040,11 +3040,13 @@ ovsdb_idl_modify_row_by_diff(struct ovsdb_idl_row *row, { bool changed; + ovsdb_idl_remove_from_indexes(row); ovsdb_idl_row_unparse(row); ovsdb_idl_row_clear_arcs(row, true); changed = ovsdb_idl_row_apply_diff(row, diff_json, OVSDB_IDL_CHANGE_MODIFY); ovsdb_idl_row_parse(row); + ovsdb_idl_add_to_indexes(row); return changed; } diff --git a/tests/ovsdb-idl.at b/tests/ovsdb-idl.at index 0143828..8db6aa4 100644 --- a/tests/ovsdb-idl.at +++ b/tests/ovsdb-idl.at @@ -1509,16 +1509,21 @@ OVSDB_CHECK_IDL_COMPOUND_INDEX_SINGLE_COLUMN_C([Compound_index, single column te 006: i=19 006: i=20 006: i=54 -007: i=1 -007: i=1 -007: i=2 -007: i=2 -007: i=2 007: i=5 -007: i=10 007: i=19 007: i=20 +007: i=30 007: i=54 +008: i=1 +008: i=1 +008: i=2 +008: i=2 +008: i=2 +008: i=5 +008: i=19 +008: i=20 +008: i=30 +008: i=54 ], [002: i=1 s=List000 b=True r=101.000000 002: i=1 s=List001 b=False r=110.000000 @@ -1538,16 +1543,21 @@ OVSDB_CHECK_IDL_COMPOUND_INDEX_SINGLE_COLUMN_C([Compound_index, single column te 006: i=20 s=List020 b=True r=220.000000 006: i=5 s=List005 b=True r=130.000000 006: i=54 s=Lista054 b=False r=0.000000 -007: i=1 s=List000 b=True r=101.000000 -007: i=1 s=List001 b=False r=110.000000 -007: i=10 s=List000 b=True r=110.000000 007: i=19 s=List020 b=True r=219.000000 -007: i=2 s=List000 b=False r=102.000000 -007: i=2 s=List001 b=True r=120.000000 -007: i=2 s=List001 b=True r=122.000000 007: i=20 s=List020 b=True r=220.000000 +007: i=30 s=List000 b=True r=110.000000 007: i=5 s=List005 b=True r=130.000000 007: i=54 s=Lista054 b=False r=0.000000 +008: i=1 s=List000 b=True r=101.000000 +008: i=1 s=List001 b=False r=110.000000 +008: i=19 s=List020 b=True r=219.000000 +008: i=2 s=List000 b=False r=102.000000 +008: i=2 s=List001 b=True r=120.000000 +008: i=2 s=List001 b=True r=122.000000 +008: i=20 s=List020 b=True r=220.000000 +008: i=30 s=List000 b=True r=110.000000 +008: i=5 s=List005 b=True r=130.000000 +008: i=54 s=Lista054 b=False r=0.000000 ]) # Tests to verify the functionality of two column compound index. diff --git a/tests/test-ovsdb.c b/tests/test-ovsdb.c index e4e7d90..7932204 100644 --- a/tests/test-ovsdb.c +++ b/tests/test-ovsdb.c @@ -2895,6 +2895,27 @@ test_idl_compound_index_single_column(struct ovsdb_idl *idl, myRow->s, myRow->b?"True":"False", myRow->r); } + /* Update record i=10 to i=30, make sure index is updated accordingly */ + ++step; + struct idltest_simple *toUpdate; + toUpdate = idltest_simple_index_init_row(i_index); + idltest_simple_index_set_i(toUpdate, 10); + ovs_assert(toUpdate->i == 10); + myRow = idltest_simple_index_find(i_index, toUpdate); + ovs_assert(myRow); + ovs_assert(myRow->i == 10); + txn = ovsdb_idl_txn_create(idl); + idltest_simple_set_i(myRow, 30); + ovsdb_idl_txn_commit_block(txn); + ovsdb_idl_txn_destroy(txn); + idltest_simple_index_set_i(to, 60); + printf("Expected 60, stored %"PRId64"\n", to->i); + ovs_assert(to->i == 60); + IDLTEST_SIMPLE_FOR_EACH_RANGE (myRow, from, to, i_index) { + printf("%03d: i=%"PRId64" s=%s b=%s r=%f\n", step, myRow->i, + myRow->s, myRow->b?"True":"False", myRow->r); + } + /* Test special-case range, "from" and "to" are both NULL, * which is interpreted as the range from -infinity to +infinity. */ ++step; @@ -2908,6 +2929,7 @@ test_idl_compound_index_single_column(struct ovsdb_idl *idl, idltest_simple_index_destroy_row(to); idltest_simple_index_destroy_row(equal); idltest_simple_index_destroy_row(toDelete); + idltest_simple_index_destroy_row(toUpdate); return step; } -- 2.1.0 _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
