fdb_transaction_add_conflict_range not work as expected?
here is my unit test
FDBDatabase* db; // Simplify the code
// step 1: set key1 value1
{
// create transaction tr
fdb_transaction_set(tr, (uint8_t*)"key1", 4, (uint8_t*)"value1", 6);
// commit tr
}
// step 2: get read version
int64_t version;
{
FDBTransaction* tr = nullptr;
fdb_error_t err = fdb_database_create_transaction(db, &tr);
ASSERT_EQ(err, 0);
FDBFuture* future = fdb_transaction_get_read_version(tr);
err = fdb_future_block_until_ready(future);
ASSERT_EQ(err, 0);
err = fdb_future_get_int64(future, &version);
ASSERT_EQ(err, 0);
fdb_future_destroy(future);
fdb_transaction_destroy(tr);
}
// step 3: rewrite key1 ----- set key1 value2
{
// create transaction tr
fdb_transaction_set(tr, (uint8_t*)"key1", 4, (uint8_t*)"value2", 6);
// commit tr
}
// step 4: expect a write conflict with step 3 when use step 2's read version
FDBTransaction* txn1_tr = nullptr;
{
fdb_error_t err = fdb_database_create_transaction(db, &txn1_tr);
ASSERT_EQ(err, 0);
// set read version from step 2
fdb_transaction_set_read_version(txn1_tr, version);
fdb_transaction_set(txn1_tr, (uint8_t*)"key1", 4, (uint8_t*)"value3", 6);
ASSERT_EQ(err, 0);
ASSERT_EQ(fdb_transaction_add_conflict_range(txn1_tr, (uint8_t*)"key0", 4, (uint8_t*)"key2", 4, FDB_CONFLICT_RANGE_TYPE_READ), 0);
// commit txn1
err = WaitError(fdb_transaction_commit(txn1_tr));
ASSERT_EQ(err, 1020 /*transaction not committed due to conflict with another transaction*/);
}
In Document, FDB_CONFLICT_RANGE_TYPE_READ
means read the range
, step 4 should be conflicted with step 3 when use read version from step 2.
However, the ASSERT_EQ(err, 1020 /*transaction not committed due to conflict with another transaction*/);
is failed, err is 0(means success).
Is there something wrong with my usage?