|
|
|
@ -96,11 +96,11 @@ void TestValueAsSecondaryIndexHelper(std::vector<Entry> entries, |
|
|
|
|
ColumnFamilyHandleImplDummy index(8, BytewiseComparator()); |
|
|
|
|
for (auto& e : entries) { |
|
|
|
|
if (e.type == kPutRecord) { |
|
|
|
|
batch->Put(&data, e.key, e.value); |
|
|
|
|
batch->Put(&index, e.value, e.key); |
|
|
|
|
ASSERT_OK(batch->Put(&data, e.key, e.value)); |
|
|
|
|
ASSERT_OK(batch->Put(&index, e.value, e.key)); |
|
|
|
|
} else if (e.type == kMergeRecord) { |
|
|
|
|
batch->Merge(&data, e.key, e.value); |
|
|
|
|
batch->Put(&index, e.value, e.key); |
|
|
|
|
ASSERT_OK(batch->Merge(&data, e.key, e.value)); |
|
|
|
|
ASSERT_OK(batch->Put(&index, e.value, e.key)); |
|
|
|
|
} else { |
|
|
|
|
assert(e.type == kDeleteRecord); |
|
|
|
|
std::unique_ptr<WBWIIterator> iter(batch->NewIterator(&data)); |
|
|
|
@ -109,8 +109,8 @@ void TestValueAsSecondaryIndexHelper(std::vector<Entry> entries, |
|
|
|
|
auto write_entry = iter->Entry(); |
|
|
|
|
ASSERT_EQ(e.key, write_entry.key.ToString()); |
|
|
|
|
ASSERT_EQ(e.value, write_entry.value.ToString()); |
|
|
|
|
batch->Delete(&data, e.key); |
|
|
|
|
batch->Put(&index, e.value, ""); |
|
|
|
|
ASSERT_OK(batch->Delete(&data, e.key)); |
|
|
|
|
ASSERT_OK(batch->Put(&index, e.value, "")); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -243,7 +243,7 @@ void TestValueAsSecondaryIndexHelper(std::vector<Entry> entries, |
|
|
|
|
|
|
|
|
|
// Verify WriteBatch can be iterated
|
|
|
|
|
TestHandler handler; |
|
|
|
|
batch->GetWriteBatch()->Iterate(&handler); |
|
|
|
|
ASSERT_OK(batch->GetWriteBatch()->Iterate(&handler)); |
|
|
|
|
|
|
|
|
|
// Verify data column family
|
|
|
|
|
{ |
|
|
|
@ -315,18 +315,18 @@ TEST_F(WriteBatchWithIndexTest, TestComparatorForCF) { |
|
|
|
|
ColumnFamilyHandleImplDummy cf2(88, BytewiseComparator()); |
|
|
|
|
WriteBatchWithIndex batch(BytewiseComparator(), 20); |
|
|
|
|
|
|
|
|
|
batch.Put(&cf1, "ddd", ""); |
|
|
|
|
batch.Put(&cf2, "aaa", ""); |
|
|
|
|
batch.Put(&cf2, "eee", ""); |
|
|
|
|
batch.Put(&cf1, "ccc", ""); |
|
|
|
|
batch.Put(&reverse_cf, "a11", ""); |
|
|
|
|
batch.Put(&cf1, "bbb", ""); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "ddd", "")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf2, "aaa", "")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf2, "eee", "")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "ccc", "")); |
|
|
|
|
ASSERT_OK(batch.Put(&reverse_cf, "a11", "")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "bbb", "")); |
|
|
|
|
|
|
|
|
|
Slice key_slices[] = {"a", "3", "3"}; |
|
|
|
|
Slice value_slice = ""; |
|
|
|
|
batch.Put(&reverse_cf, SliceParts(key_slices, 3), |
|
|
|
|
SliceParts(&value_slice, 1)); |
|
|
|
|
batch.Put(&reverse_cf, "a22", ""); |
|
|
|
|
ASSERT_OK(batch.Put(&reverse_cf, SliceParts(key_slices, 3), |
|
|
|
|
SliceParts(&value_slice, 1))); |
|
|
|
|
ASSERT_OK(batch.Put(&reverse_cf, "a22", "")); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
std::unique_ptr<WBWIIterator> iter(batch.NewIterator(&cf1)); |
|
|
|
@ -402,20 +402,20 @@ TEST_F(WriteBatchWithIndexTest, TestOverwriteKey) { |
|
|
|
|
ColumnFamilyHandleImplDummy cf2(88, BytewiseComparator()); |
|
|
|
|
WriteBatchWithIndex batch(BytewiseComparator(), 20, true); |
|
|
|
|
|
|
|
|
|
batch.Put(&cf1, "ddd", ""); |
|
|
|
|
batch.Merge(&cf1, "ddd", ""); |
|
|
|
|
batch.Delete(&cf1, "ddd"); |
|
|
|
|
batch.Put(&cf2, "aaa", ""); |
|
|
|
|
batch.Delete(&cf2, "aaa"); |
|
|
|
|
batch.Put(&cf2, "aaa", "aaa"); |
|
|
|
|
batch.Put(&cf2, "eee", "eee"); |
|
|
|
|
batch.Put(&cf1, "ccc", ""); |
|
|
|
|
batch.Put(&reverse_cf, "a11", ""); |
|
|
|
|
batch.Delete(&cf1, "ccc"); |
|
|
|
|
batch.Put(&reverse_cf, "a33", "a33"); |
|
|
|
|
batch.Put(&reverse_cf, "a11", "a11"); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "ddd", "")); |
|
|
|
|
ASSERT_OK(batch.Merge(&cf1, "ddd", "")); |
|
|
|
|
ASSERT_OK(batch.Delete(&cf1, "ddd")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf2, "aaa", "")); |
|
|
|
|
ASSERT_OK(batch.Delete(&cf2, "aaa")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf2, "aaa", "aaa")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf2, "eee", "eee")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "ccc", "")); |
|
|
|
|
ASSERT_OK(batch.Put(&reverse_cf, "a11", "")); |
|
|
|
|
ASSERT_OK(batch.Delete(&cf1, "ccc")); |
|
|
|
|
ASSERT_OK(batch.Put(&reverse_cf, "a33", "a33")); |
|
|
|
|
ASSERT_OK(batch.Put(&reverse_cf, "a11", "a11")); |
|
|
|
|
Slice slices[] = {"a", "3", "3"}; |
|
|
|
|
batch.Delete(&reverse_cf, SliceParts(slices, 3)); |
|
|
|
|
ASSERT_OK(batch.Delete(&reverse_cf, SliceParts(slices, 3))); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
std::unique_ptr<WBWIIterator> iter(batch.NewIterator(&cf1)); |
|
|
|
@ -570,10 +570,10 @@ TEST_F(WriteBatchWithIndexTest, TestRandomIteraratorWithBase) { |
|
|
|
|
WriteBatchWithIndex batch(BytewiseComparator(), 20, true); |
|
|
|
|
|
|
|
|
|
if (rand_seed % 2 == 0) { |
|
|
|
|
batch.Put(&cf2, "zoo", "bar"); |
|
|
|
|
ASSERT_OK(batch.Put(&cf2, "zoo", "bar")); |
|
|
|
|
} |
|
|
|
|
if (rand_seed % 4 == 1) { |
|
|
|
|
batch.Put(&cf3, "zoo", "bar"); |
|
|
|
|
ASSERT_OK(batch.Put(&cf3, "zoo", "bar")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
KVMap map; |
|
|
|
@ -589,24 +589,24 @@ TEST_F(WriteBatchWithIndexTest, TestRandomIteraratorWithBase) { |
|
|
|
|
break; |
|
|
|
|
case 1: |
|
|
|
|
// only delta has it
|
|
|
|
|
batch.Put(&cf1, key, value); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, key, value)); |
|
|
|
|
map[key] = value; |
|
|
|
|
merged_map[key] = value; |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
// both has it. Delta should win
|
|
|
|
|
batch.Put(&cf1, key, value); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, key, value)); |
|
|
|
|
map[key] = "wrong_value"; |
|
|
|
|
merged_map[key] = value; |
|
|
|
|
break; |
|
|
|
|
case 3: |
|
|
|
|
// both has it. Delta is delete
|
|
|
|
|
batch.Delete(&cf1, key); |
|
|
|
|
ASSERT_OK(batch.Delete(&cf1, key)); |
|
|
|
|
map[key] = "wrong_value"; |
|
|
|
|
break; |
|
|
|
|
case 4: |
|
|
|
|
// only delta has it. Delta is delete
|
|
|
|
|
batch.Delete(&cf1, key); |
|
|
|
|
ASSERT_OK(batch.Delete(&cf1, key)); |
|
|
|
|
map[key] = "wrong_value"; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
@ -675,6 +675,8 @@ TEST_F(WriteBatchWithIndexTest, TestRandomIteraratorWithBase) { |
|
|
|
|
AssertItersEqual(iter.get(), result_iter.get()); |
|
|
|
|
is_valid = iter->Valid(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ASSERT_OK(iter->status()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -722,8 +724,8 @@ TEST_F(WriteBatchWithIndexTest, TestIteraratorWithBase) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Test the case that there is one element in the write batch
|
|
|
|
|
batch.Put(&cf2, "zoo", "bar"); |
|
|
|
|
batch.Put(&cf1, "a", "aa"); |
|
|
|
|
ASSERT_OK(batch.Put(&cf2, "zoo", "bar")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "a", "aa")); |
|
|
|
|
{ |
|
|
|
|
KVMap empty_map; |
|
|
|
|
std::unique_ptr<Iterator> iter( |
|
|
|
@ -736,10 +738,10 @@ TEST_F(WriteBatchWithIndexTest, TestIteraratorWithBase) { |
|
|
|
|
ASSERT_TRUE(!iter->Valid()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
batch.Delete(&cf1, "b"); |
|
|
|
|
batch.Put(&cf1, "c", "cc"); |
|
|
|
|
batch.Put(&cf1, "d", "dd"); |
|
|
|
|
batch.Delete(&cf1, "e"); |
|
|
|
|
ASSERT_OK(batch.Delete(&cf1, "b")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "c", "cc")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "d", "dd")); |
|
|
|
|
ASSERT_OK(batch.Delete(&cf1, "e")); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
KVMap map; |
|
|
|
@ -847,8 +849,8 @@ TEST_F(WriteBatchWithIndexTest, TestIteraratorWithBaseReverseCmp) { |
|
|
|
|
WriteBatchWithIndex batch(BytewiseComparator(), 20, true); |
|
|
|
|
|
|
|
|
|
// Test the case that there is one element in the write batch
|
|
|
|
|
batch.Put(&cf2, "zoo", "bar"); |
|
|
|
|
batch.Put(&cf1, "a", "aa"); |
|
|
|
|
ASSERT_OK(batch.Put(&cf2, "zoo", "bar")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "a", "aa")); |
|
|
|
|
{ |
|
|
|
|
KVMap empty_map; |
|
|
|
|
std::unique_ptr<Iterator> iter( |
|
|
|
@ -861,7 +863,7 @@ TEST_F(WriteBatchWithIndexTest, TestIteraratorWithBaseReverseCmp) { |
|
|
|
|
ASSERT_TRUE(!iter->Valid()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
batch.Put(&cf1, "c", "cc"); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "c", "cc")); |
|
|
|
|
{ |
|
|
|
|
KVMap map; |
|
|
|
|
std::unique_ptr<Iterator> iter( |
|
|
|
@ -894,7 +896,7 @@ TEST_F(WriteBatchWithIndexTest, TestIteraratorWithBaseReverseCmp) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// default column family
|
|
|
|
|
batch.Put("a", "b"); |
|
|
|
|
ASSERT_OK(batch.Put("a", "b")); |
|
|
|
|
{ |
|
|
|
|
KVMap map; |
|
|
|
|
map["b"] = ""; |
|
|
|
@ -936,14 +938,14 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatch) { |
|
|
|
|
s = batch.GetFromBatch(options, "b", &value); |
|
|
|
|
ASSERT_TRUE(s.IsNotFound()); |
|
|
|
|
|
|
|
|
|
batch.Put("a", "a"); |
|
|
|
|
batch.Put("b", "b"); |
|
|
|
|
batch.Put("c", "c"); |
|
|
|
|
batch.Put("a", "z"); |
|
|
|
|
batch.Delete("c"); |
|
|
|
|
batch.Delete("d"); |
|
|
|
|
batch.Delete("e"); |
|
|
|
|
batch.Put("e", "e"); |
|
|
|
|
ASSERT_OK(batch.Put("a", "a")); |
|
|
|
|
ASSERT_OK(batch.Put("b", "b")); |
|
|
|
|
ASSERT_OK(batch.Put("c", "c")); |
|
|
|
|
ASSERT_OK(batch.Put("a", "z")); |
|
|
|
|
ASSERT_OK(batch.Delete("c")); |
|
|
|
|
ASSERT_OK(batch.Delete("d")); |
|
|
|
|
ASSERT_OK(batch.Delete("e")); |
|
|
|
|
ASSERT_OK(batch.Put("e", "e")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatch(options, "b", &value); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
@ -966,7 +968,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatch) { |
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
ASSERT_EQ("e", value); |
|
|
|
|
|
|
|
|
|
batch.Merge("z", "z"); |
|
|
|
|
ASSERT_OK(batch.Merge("z", "z")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatch(options, "z", &value); |
|
|
|
|
ASSERT_NOK(s); // No merge operator specified.
|
|
|
|
@ -984,7 +986,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchMerge) { |
|
|
|
|
|
|
|
|
|
std::string dbname = test::PerThreadDBPath("write_batch_with_index_test"); |
|
|
|
|
|
|
|
|
|
DestroyDB(dbname, options); |
|
|
|
|
EXPECT_OK(DestroyDB(dbname, options)); |
|
|
|
|
Status s = DB::Open(options, dbname, &db); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
|
|
|
|
@ -995,18 +997,18 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchMerge) { |
|
|
|
|
s = batch.GetFromBatch(options, "x", &value); |
|
|
|
|
ASSERT_TRUE(s.IsNotFound()); |
|
|
|
|
|
|
|
|
|
batch.Put("x", "X"); |
|
|
|
|
ASSERT_OK(batch.Put("x", "X")); |
|
|
|
|
std::string expected = "X"; |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 5; i++) { |
|
|
|
|
batch.Merge("x", ToString(i)); |
|
|
|
|
ASSERT_OK(batch.Merge("x", ToString(i))); |
|
|
|
|
expected = expected + "," + ToString(i); |
|
|
|
|
|
|
|
|
|
if (i % 2 == 0) { |
|
|
|
|
batch.Put("y", ToString(i / 2)); |
|
|
|
|
ASSERT_OK(batch.Put("y", ToString(i / 2))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
batch.Merge("z", "z"); |
|
|
|
|
ASSERT_OK(batch.Merge("z", "z")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatch(column_family, options, "x", &value); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
@ -1021,7 +1023,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchMerge) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
delete db; |
|
|
|
|
DestroyDB(dbname, options); |
|
|
|
|
EXPECT_OK(DestroyDB(dbname, options)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(WriteBatchWithIndexTest, TestGetFromBatchMerge2) { |
|
|
|
@ -1032,7 +1034,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchMerge2) { |
|
|
|
|
|
|
|
|
|
std::string dbname = test::PerThreadDBPath("write_batch_with_index_test"); |
|
|
|
|
|
|
|
|
|
DestroyDB(dbname, options); |
|
|
|
|
EXPECT_OK(DestroyDB(dbname, options)); |
|
|
|
|
Status s = DB::Open(options, dbname, &db); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
|
|
|
|
@ -1045,43 +1047,43 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchMerge2) { |
|
|
|
|
s = batch.GetFromBatch(column_family, options, "X", &value); |
|
|
|
|
ASSERT_TRUE(s.IsNotFound()); |
|
|
|
|
|
|
|
|
|
batch.Put(column_family, "X", "x"); |
|
|
|
|
ASSERT_OK(batch.Put(column_family, "X", "x")); |
|
|
|
|
s = batch.GetFromBatch(column_family, options, "X", &value); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
ASSERT_EQ("x", value); |
|
|
|
|
|
|
|
|
|
batch.Put(column_family, "X", "x2"); |
|
|
|
|
ASSERT_OK(batch.Put(column_family, "X", "x2")); |
|
|
|
|
s = batch.GetFromBatch(column_family, options, "X", &value); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
ASSERT_EQ("x2", value); |
|
|
|
|
|
|
|
|
|
batch.Merge(column_family, "X", "aaa"); |
|
|
|
|
ASSERT_OK(batch.Merge(column_family, "X", "aaa")); |
|
|
|
|
s = batch.GetFromBatch(column_family, options, "X", &value); |
|
|
|
|
ASSERT_TRUE(s.IsMergeInProgress()); |
|
|
|
|
|
|
|
|
|
batch.Merge(column_family, "X", "bbb"); |
|
|
|
|
ASSERT_OK(batch.Merge(column_family, "X", "bbb")); |
|
|
|
|
s = batch.GetFromBatch(column_family, options, "X", &value); |
|
|
|
|
ASSERT_TRUE(s.IsMergeInProgress()); |
|
|
|
|
|
|
|
|
|
batch.Put(column_family, "X", "x3"); |
|
|
|
|
ASSERT_OK(batch.Put(column_family, "X", "x3")); |
|
|
|
|
s = batch.GetFromBatch(column_family, options, "X", &value); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
ASSERT_EQ("x3", value); |
|
|
|
|
|
|
|
|
|
batch.Merge(column_family, "X", "ccc"); |
|
|
|
|
ASSERT_OK(batch.Merge(column_family, "X", "ccc")); |
|
|
|
|
s = batch.GetFromBatch(column_family, options, "X", &value); |
|
|
|
|
ASSERT_TRUE(s.IsMergeInProgress()); |
|
|
|
|
|
|
|
|
|
batch.Delete(column_family, "X"); |
|
|
|
|
ASSERT_OK(batch.Delete(column_family, "X")); |
|
|
|
|
s = batch.GetFromBatch(column_family, options, "X", &value); |
|
|
|
|
ASSERT_TRUE(s.IsNotFound()); |
|
|
|
|
|
|
|
|
|
batch.Merge(column_family, "X", "ddd"); |
|
|
|
|
ASSERT_OK(batch.Merge(column_family, "X", "ddd")); |
|
|
|
|
s = batch.GetFromBatch(column_family, options, "X", &value); |
|
|
|
|
ASSERT_TRUE(s.IsMergeInProgress()); |
|
|
|
|
|
|
|
|
|
delete db; |
|
|
|
|
DestroyDB(dbname, options); |
|
|
|
|
EXPECT_OK(DestroyDB(dbname, options)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDB) { |
|
|
|
@ -1090,7 +1092,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDB) { |
|
|
|
|
options.create_if_missing = true; |
|
|
|
|
std::string dbname = test::PerThreadDBPath("write_batch_with_index_test"); |
|
|
|
|
|
|
|
|
|
DestroyDB(dbname, options); |
|
|
|
|
EXPECT_OK(DestroyDB(dbname, options)); |
|
|
|
|
Status s = DB::Open(options, dbname, &db); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
|
|
|
|
@ -1108,8 +1110,8 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDB) { |
|
|
|
|
s = db->Put(write_options, "c", "c"); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
|
|
|
|
|
batch.Put("a", "batch.a"); |
|
|
|
|
batch.Delete("b"); |
|
|
|
|
ASSERT_OK(batch.Put("a", "batch.a")); |
|
|
|
|
ASSERT_OK(batch.Delete("b")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatchAndDB(db, read_options, "a", &value); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
@ -1125,13 +1127,13 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDB) { |
|
|
|
|
s = batch.GetFromBatchAndDB(db, read_options, "x", &value); |
|
|
|
|
ASSERT_TRUE(s.IsNotFound()); |
|
|
|
|
|
|
|
|
|
db->Delete(write_options, "x"); |
|
|
|
|
ASSERT_OK(db->Delete(write_options, "x")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatchAndDB(db, read_options, "x", &value); |
|
|
|
|
ASSERT_TRUE(s.IsNotFound()); |
|
|
|
|
|
|
|
|
|
delete db; |
|
|
|
|
DestroyDB(dbname, options); |
|
|
|
|
EXPECT_OK(DestroyDB(dbname, options)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge) { |
|
|
|
@ -1143,9 +1145,9 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge) { |
|
|
|
|
|
|
|
|
|
options.merge_operator = MergeOperators::CreateFromStringId("stringappend"); |
|
|
|
|
|
|
|
|
|
DestroyDB(dbname, options); |
|
|
|
|
EXPECT_OK(DestroyDB(dbname, options)); |
|
|
|
|
Status s = DB::Open(options, dbname, &db); |
|
|
|
|
assert(s.ok()); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
|
|
|
|
|
WriteBatchWithIndex batch; |
|
|
|
|
ReadOptions read_options; |
|
|
|
@ -1167,11 +1169,11 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge) { |
|
|
|
|
s = db->Merge(write_options, "d", "d0"); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
|
|
|
|
|
batch.Merge("a", "a1"); |
|
|
|
|
batch.Merge("a", "a2"); |
|
|
|
|
batch.Merge("b", "b2"); |
|
|
|
|
batch.Merge("d", "d1"); |
|
|
|
|
batch.Merge("e", "e0"); |
|
|
|
|
ASSERT_OK(batch.Merge("a", "a1")); |
|
|
|
|
ASSERT_OK(batch.Merge("a", "a2")); |
|
|
|
|
ASSERT_OK(batch.Merge("b", "b2")); |
|
|
|
|
ASSERT_OK(batch.Merge("d", "d1")); |
|
|
|
|
ASSERT_OK(batch.Merge("e", "e0")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatchAndDB(db, read_options, "a", &value); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
@ -1214,7 +1216,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge) { |
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
ASSERT_EQ("a0,a1,a2", value); |
|
|
|
|
|
|
|
|
|
batch.Delete("a"); |
|
|
|
|
ASSERT_OK(batch.Delete("a")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatchAndDB(db, read_options, "a", &value); |
|
|
|
|
ASSERT_TRUE(s.IsNotFound()); |
|
|
|
@ -1257,7 +1259,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge) { |
|
|
|
|
|
|
|
|
|
db->ReleaseSnapshot(snapshot); |
|
|
|
|
delete db; |
|
|
|
|
DestroyDB(dbname, options); |
|
|
|
|
EXPECT_OK(DestroyDB(dbname, options)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge2) { |
|
|
|
@ -1269,9 +1271,9 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge2) { |
|
|
|
|
|
|
|
|
|
options.merge_operator = MergeOperators::CreateFromStringId("stringappend"); |
|
|
|
|
|
|
|
|
|
DestroyDB(dbname, options); |
|
|
|
|
EXPECT_OK(DestroyDB(dbname, options)); |
|
|
|
|
Status s = DB::Open(options, dbname, &db); |
|
|
|
|
assert(s.ok()); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
|
|
|
|
|
// Test batch with overwrite_key=true
|
|
|
|
|
WriteBatchWithIndex batch(BytewiseComparator(), 0, true); |
|
|
|
@ -1283,12 +1285,12 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge2) { |
|
|
|
|
s = batch.GetFromBatchAndDB(db, read_options, "A", &value); |
|
|
|
|
ASSERT_TRUE(s.IsNotFound()); |
|
|
|
|
|
|
|
|
|
batch.Merge("A", "xxx"); |
|
|
|
|
ASSERT_OK(batch.Merge("A", "xxx")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatchAndDB(db, read_options, "A", &value); |
|
|
|
|
ASSERT_TRUE(s.IsMergeInProgress()); |
|
|
|
|
|
|
|
|
|
batch.Merge("A", "yyy"); |
|
|
|
|
ASSERT_OK(batch.Merge("A", "yyy")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatchAndDB(db, read_options, "A", &value); |
|
|
|
|
ASSERT_TRUE(s.IsMergeInProgress()); |
|
|
|
@ -1299,13 +1301,13 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge2) { |
|
|
|
|
s = batch.GetFromBatchAndDB(db, read_options, "A", &value); |
|
|
|
|
ASSERT_TRUE(s.IsMergeInProgress()); |
|
|
|
|
|
|
|
|
|
batch.Delete("A"); |
|
|
|
|
ASSERT_OK(batch.Delete("A")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatchAndDB(db, read_options, "A", &value); |
|
|
|
|
ASSERT_TRUE(s.IsNotFound()); |
|
|
|
|
|
|
|
|
|
delete db; |
|
|
|
|
DestroyDB(dbname, options); |
|
|
|
|
EXPECT_OK(DestroyDB(dbname, options)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge3) { |
|
|
|
@ -1317,9 +1319,9 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge3) { |
|
|
|
|
|
|
|
|
|
options.merge_operator = MergeOperators::CreateFromStringId("stringappend"); |
|
|
|
|
|
|
|
|
|
DestroyDB(dbname, options); |
|
|
|
|
EXPECT_OK(DestroyDB(dbname, options)); |
|
|
|
|
Status s = DB::Open(options, dbname, &db); |
|
|
|
|
assert(s.ok()); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
|
|
|
|
|
|
ReadOptions read_options; |
|
|
|
|
WriteOptions write_options; |
|
|
|
@ -1336,7 +1338,7 @@ TEST_F(WriteBatchWithIndexTest, TestGetFromBatchAndDBMerge3) { |
|
|
|
|
ASSERT_EQ(value, "1,2"); |
|
|
|
|
|
|
|
|
|
delete db; |
|
|
|
|
DestroyDB(dbname, options); |
|
|
|
|
EXPECT_OK(DestroyDB(dbname, options)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AssertKey(std::string key, WBWIIterator* iter) { |
|
|
|
@ -1354,7 +1356,7 @@ void AssertValue(std::string value, WBWIIterator* iter) { |
|
|
|
|
TEST_F(WriteBatchWithIndexTest, MutateWhileIteratingCorrectnessTest) { |
|
|
|
|
WriteBatchWithIndex batch(BytewiseComparator(), 0, true); |
|
|
|
|
for (char c = 'a'; c <= 'z'; ++c) { |
|
|
|
|
batch.Put(std::string(1, c), std::string(1, c)); |
|
|
|
|
ASSERT_OK(batch.Put(std::string(1, c), std::string(1, c))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::unique_ptr<WBWIIterator> iter(batch.NewIterator()); |
|
|
|
@ -1362,14 +1364,14 @@ TEST_F(WriteBatchWithIndexTest, MutateWhileIteratingCorrectnessTest) { |
|
|
|
|
AssertKey("k", iter.get()); |
|
|
|
|
iter->Next(); |
|
|
|
|
AssertKey("l", iter.get()); |
|
|
|
|
batch.Put("ab", "cc"); |
|
|
|
|
ASSERT_OK(batch.Put("ab", "cc")); |
|
|
|
|
iter->Next(); |
|
|
|
|
AssertKey("m", iter.get()); |
|
|
|
|
batch.Put("mm", "kk"); |
|
|
|
|
ASSERT_OK(batch.Put("mm", "kk")); |
|
|
|
|
iter->Next(); |
|
|
|
|
AssertKey("mm", iter.get()); |
|
|
|
|
AssertValue("kk", iter.get()); |
|
|
|
|
batch.Delete("mm"); |
|
|
|
|
ASSERT_OK(batch.Delete("mm")); |
|
|
|
|
|
|
|
|
|
iter->Next(); |
|
|
|
|
AssertKey("n", iter.get()); |
|
|
|
@ -1379,7 +1381,7 @@ TEST_F(WriteBatchWithIndexTest, MutateWhileIteratingCorrectnessTest) { |
|
|
|
|
|
|
|
|
|
iter->Seek("ab"); |
|
|
|
|
AssertKey("ab", iter.get()); |
|
|
|
|
batch.Delete("x"); |
|
|
|
|
ASSERT_OK(batch.Delete("x")); |
|
|
|
|
iter->Seek("x"); |
|
|
|
|
AssertKey("x", iter.get()); |
|
|
|
|
ASSERT_EQ(kDeleteRecord, iter->Entry().type); |
|
|
|
@ -1401,7 +1403,7 @@ void AssertIterValue(std::string value, Iterator* iter) { |
|
|
|
|
TEST_F(WriteBatchWithIndexTest, MutateWhileIteratingBaseCorrectnessTest) { |
|
|
|
|
WriteBatchWithIndex batch(BytewiseComparator(), 0, true); |
|
|
|
|
for (char c = 'a'; c <= 'z'; ++c) { |
|
|
|
|
batch.Put(std::string(1, c), std::string(1, c)); |
|
|
|
|
ASSERT_OK(batch.Put(std::string(1, c), std::string(1, c))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
KVMap map; |
|
|
|
@ -1416,14 +1418,14 @@ TEST_F(WriteBatchWithIndexTest, MutateWhileIteratingBaseCorrectnessTest) { |
|
|
|
|
AssertIterKey("k", iter.get()); |
|
|
|
|
iter->Next(); |
|
|
|
|
AssertIterKey("l", iter.get()); |
|
|
|
|
batch.Put("ab", "cc"); |
|
|
|
|
ASSERT_OK(batch.Put("ab", "cc")); |
|
|
|
|
iter->Next(); |
|
|
|
|
AssertIterKey("m", iter.get()); |
|
|
|
|
batch.Put("mm", "kk"); |
|
|
|
|
ASSERT_OK(batch.Put("mm", "kk")); |
|
|
|
|
iter->Next(); |
|
|
|
|
AssertIterKey("mm", iter.get()); |
|
|
|
|
AssertIterValue("kk", iter.get()); |
|
|
|
|
batch.Delete("mm"); |
|
|
|
|
ASSERT_OK(batch.Delete("mm")); |
|
|
|
|
iter->Next(); |
|
|
|
|
AssertIterKey("n", iter.get()); |
|
|
|
|
iter->Prev(); |
|
|
|
@ -1436,13 +1438,13 @@ TEST_F(WriteBatchWithIndexTest, MutateWhileIteratingBaseCorrectnessTest) { |
|
|
|
|
AssertIterKey("aa", iter.get()); |
|
|
|
|
iter->Prev(); |
|
|
|
|
AssertIterKey("a", iter.get()); |
|
|
|
|
batch.Delete("aa"); |
|
|
|
|
ASSERT_OK(batch.Delete("aa")); |
|
|
|
|
iter->Next(); |
|
|
|
|
AssertIterKey("ab", iter.get()); |
|
|
|
|
iter->Prev(); |
|
|
|
|
AssertIterKey("a", iter.get()); |
|
|
|
|
|
|
|
|
|
batch.Delete("x"); |
|
|
|
|
ASSERT_OK(batch.Delete("x")); |
|
|
|
|
iter->Seek("x"); |
|
|
|
|
AssertIterKey("y", iter.get()); |
|
|
|
|
iter->Next(); |
|
|
|
@ -1451,11 +1453,11 @@ TEST_F(WriteBatchWithIndexTest, MutateWhileIteratingBaseCorrectnessTest) { |
|
|
|
|
iter->Prev(); |
|
|
|
|
AssertIterKey("w", iter.get()); |
|
|
|
|
|
|
|
|
|
batch.Delete("e"); |
|
|
|
|
ASSERT_OK(batch.Delete("e")); |
|
|
|
|
iter->Seek("e"); |
|
|
|
|
AssertIterKey("ee", iter.get()); |
|
|
|
|
AssertIterValue("ee", iter.get()); |
|
|
|
|
batch.Put("ee", "xx"); |
|
|
|
|
ASSERT_OK(batch.Put("ee", "xx")); |
|
|
|
|
// still the same value
|
|
|
|
|
AssertIterValue("ee", iter.get()); |
|
|
|
|
iter->Next(); |
|
|
|
@ -1463,13 +1465,15 @@ TEST_F(WriteBatchWithIndexTest, MutateWhileIteratingBaseCorrectnessTest) { |
|
|
|
|
iter->Prev(); |
|
|
|
|
// new value
|
|
|
|
|
AssertIterValue("xx", iter.get()); |
|
|
|
|
|
|
|
|
|
ASSERT_OK(iter->status()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// stress testing mutations with IteratorWithBase
|
|
|
|
|
TEST_F(WriteBatchWithIndexTest, MutateWhileIteratingBaseStressTest) { |
|
|
|
|
WriteBatchWithIndex batch(BytewiseComparator(), 0, true); |
|
|
|
|
for (char c = 'a'; c <= 'z'; ++c) { |
|
|
|
|
batch.Put(std::string(1, c), std::string(1, c)); |
|
|
|
|
ASSERT_OK(batch.Put(std::string(1, c), std::string(1, c))); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
KVMap map; |
|
|
|
@ -1486,16 +1490,16 @@ TEST_F(WriteBatchWithIndexTest, MutateWhileIteratingBaseStressTest) { |
|
|
|
|
char c = static_cast<char>(rnd.Uniform(26) + 'a'); |
|
|
|
|
switch (random) { |
|
|
|
|
case 0: |
|
|
|
|
batch.Put(std::string(1, c), "xxx"); |
|
|
|
|
ASSERT_OK(batch.Put(std::string(1, c), "xxx")); |
|
|
|
|
break; |
|
|
|
|
case 1: |
|
|
|
|
batch.Put(std::string(2, c), "xxx"); |
|
|
|
|
ASSERT_OK(batch.Put(std::string(2, c), "xxx")); |
|
|
|
|
break; |
|
|
|
|
case 2: |
|
|
|
|
batch.Delete(std::string(1, c)); |
|
|
|
|
ASSERT_OK(batch.Delete(std::string(1, c))); |
|
|
|
|
break; |
|
|
|
|
case 3: |
|
|
|
|
batch.Delete(std::string(2, c)); |
|
|
|
|
ASSERT_OK(batch.Delete(std::string(2, c))); |
|
|
|
|
break; |
|
|
|
|
case 4: |
|
|
|
|
iter->Seek(std::string(1, c)); |
|
|
|
@ -1517,12 +1521,12 @@ TEST_F(WriteBatchWithIndexTest, MutateWhileIteratingBaseStressTest) { |
|
|
|
|
assert(false); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ASSERT_OK(iter->status()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static std::string PrintContents(WriteBatchWithIndex* batch, |
|
|
|
|
ColumnFamilyHandle* column_family) { |
|
|
|
|
std::string result; |
|
|
|
|
|
|
|
|
|
static void PrintContents(WriteBatchWithIndex* batch, |
|
|
|
|
ColumnFamilyHandle* column_family, |
|
|
|
|
std::string* result) { |
|
|
|
|
WBWIIterator* iter; |
|
|
|
|
if (column_family == nullptr) { |
|
|
|
|
iter = batch->NewIterator(); |
|
|
|
@ -1532,41 +1536,50 @@ static std::string PrintContents(WriteBatchWithIndex* batch, |
|
|
|
|
|
|
|
|
|
iter->SeekToFirst(); |
|
|
|
|
while (iter->Valid()) { |
|
|
|
|
ASSERT_OK(iter->status()); |
|
|
|
|
|
|
|
|
|
WriteEntry e = iter->Entry(); |
|
|
|
|
|
|
|
|
|
if (e.type == kPutRecord) { |
|
|
|
|
result.append("PUT("); |
|
|
|
|
result.append(e.key.ToString()); |
|
|
|
|
result.append("):"); |
|
|
|
|
result.append(e.value.ToString()); |
|
|
|
|
result->append("PUT("); |
|
|
|
|
result->append(e.key.ToString()); |
|
|
|
|
result->append("):"); |
|
|
|
|
result->append(e.value.ToString()); |
|
|
|
|
} else if (e.type == kMergeRecord) { |
|
|
|
|
result.append("MERGE("); |
|
|
|
|
result.append(e.key.ToString()); |
|
|
|
|
result.append("):"); |
|
|
|
|
result.append(e.value.ToString()); |
|
|
|
|
result->append("MERGE("); |
|
|
|
|
result->append(e.key.ToString()); |
|
|
|
|
result->append("):"); |
|
|
|
|
result->append(e.value.ToString()); |
|
|
|
|
} else if (e.type == kSingleDeleteRecord) { |
|
|
|
|
result.append("SINGLE-DEL("); |
|
|
|
|
result.append(e.key.ToString()); |
|
|
|
|
result.append(")"); |
|
|
|
|
result->append("SINGLE-DEL("); |
|
|
|
|
result->append(e.key.ToString()); |
|
|
|
|
result->append(")"); |
|
|
|
|
} else { |
|
|
|
|
assert(e.type == kDeleteRecord); |
|
|
|
|
result.append("DEL("); |
|
|
|
|
result.append(e.key.ToString()); |
|
|
|
|
result.append(")"); |
|
|
|
|
result->append("DEL("); |
|
|
|
|
result->append(e.key.ToString()); |
|
|
|
|
result->append(")"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
result.append(","); |
|
|
|
|
result->append(","); |
|
|
|
|
iter->Next(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ASSERT_OK(iter->status()); |
|
|
|
|
|
|
|
|
|
delete iter; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static std::string PrintContents(WriteBatchWithIndex* batch, KVMap* base_map, |
|
|
|
|
static std::string PrintContents(WriteBatchWithIndex* batch, |
|
|
|
|
ColumnFamilyHandle* column_family) { |
|
|
|
|
std::string result; |
|
|
|
|
PrintContents(batch, column_family, &result); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void PrintContents(WriteBatchWithIndex* batch, KVMap* base_map, |
|
|
|
|
ColumnFamilyHandle* column_family, |
|
|
|
|
std::string* result) { |
|
|
|
|
Iterator* iter; |
|
|
|
|
if (column_family == nullptr) { |
|
|
|
|
iter = batch->NewIteratorWithBase(new KVIter(base_map)); |
|
|
|
@ -1576,20 +1589,28 @@ static std::string PrintContents(WriteBatchWithIndex* batch, KVMap* base_map, |
|
|
|
|
|
|
|
|
|
iter->SeekToFirst(); |
|
|
|
|
while (iter->Valid()) { |
|
|
|
|
assert(iter->status().ok()); |
|
|
|
|
ASSERT_OK(iter->status()); |
|
|
|
|
|
|
|
|
|
Slice key = iter->key(); |
|
|
|
|
Slice value = iter->value(); |
|
|
|
|
|
|
|
|
|
result.append(key.ToString()); |
|
|
|
|
result.append(":"); |
|
|
|
|
result.append(value.ToString()); |
|
|
|
|
result.append(","); |
|
|
|
|
result->append(key.ToString()); |
|
|
|
|
result->append(":"); |
|
|
|
|
result->append(value.ToString()); |
|
|
|
|
result->append(","); |
|
|
|
|
|
|
|
|
|
iter->Next(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ASSERT_OK(iter->status()); |
|
|
|
|
|
|
|
|
|
delete iter; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static std::string PrintContents(WriteBatchWithIndex* batch, KVMap* base_map, |
|
|
|
|
ColumnFamilyHandle* column_family) { |
|
|
|
|
std::string result; |
|
|
|
|
PrintContents(batch, base_map, column_family, &result); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1598,34 +1619,34 @@ TEST_F(WriteBatchWithIndexTest, SavePointTest) { |
|
|
|
|
ColumnFamilyHandleImplDummy cf1(1, BytewiseComparator()); |
|
|
|
|
Status s; |
|
|
|
|
|
|
|
|
|
batch.Put("A", "a"); |
|
|
|
|
batch.Put("B", "b"); |
|
|
|
|
batch.Put("A", "aa"); |
|
|
|
|
batch.Put(&cf1, "A", "a1"); |
|
|
|
|
batch.Delete(&cf1, "B"); |
|
|
|
|
batch.Put(&cf1, "C", "c1"); |
|
|
|
|
batch.Put(&cf1, "E", "e1"); |
|
|
|
|
ASSERT_OK(batch.Put("A", "a")); |
|
|
|
|
ASSERT_OK(batch.Put("B", "b")); |
|
|
|
|
ASSERT_OK(batch.Put("A", "aa")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "A", "a1")); |
|
|
|
|
ASSERT_OK(batch.Delete(&cf1, "B")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "C", "c1")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "E", "e1")); |
|
|
|
|
|
|
|
|
|
batch.SetSavePoint(); // 1
|
|
|
|
|
|
|
|
|
|
batch.Put("C", "cc"); |
|
|
|
|
batch.Put("B", "bb"); |
|
|
|
|
batch.Delete("A"); |
|
|
|
|
batch.Put(&cf1, "B", "b1"); |
|
|
|
|
batch.Delete(&cf1, "A"); |
|
|
|
|
batch.SingleDelete(&cf1, "E"); |
|
|
|
|
ASSERT_OK(batch.Put("C", "cc")); |
|
|
|
|
ASSERT_OK(batch.Put("B", "bb")); |
|
|
|
|
ASSERT_OK(batch.Delete("A")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "B", "b1")); |
|
|
|
|
ASSERT_OK(batch.Delete(&cf1, "A")); |
|
|
|
|
ASSERT_OK(batch.SingleDelete(&cf1, "E")); |
|
|
|
|
batch.SetSavePoint(); // 2
|
|
|
|
|
|
|
|
|
|
batch.Put("A", "aaa"); |
|
|
|
|
batch.Put("A", "xxx"); |
|
|
|
|
batch.Delete("B"); |
|
|
|
|
batch.Put(&cf1, "B", "b2"); |
|
|
|
|
batch.Delete(&cf1, "C"); |
|
|
|
|
ASSERT_OK(batch.Put("A", "aaa")); |
|
|
|
|
ASSERT_OK(batch.Put("A", "xxx")); |
|
|
|
|
ASSERT_OK(batch.Delete("B")); |
|
|
|
|
ASSERT_OK(batch.Put(&cf1, "B", "b2")); |
|
|
|
|
ASSERT_OK(batch.Delete(&cf1, "C")); |
|
|
|
|
batch.SetSavePoint(); // 3
|
|
|
|
|
batch.SetSavePoint(); // 4
|
|
|
|
|
batch.SingleDelete("D"); |
|
|
|
|
batch.Delete(&cf1, "D"); |
|
|
|
|
batch.Delete(&cf1, "E"); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("D")); |
|
|
|
|
ASSERT_OK(batch.Delete(&cf1, "D")); |
|
|
|
|
ASSERT_OK(batch.Delete(&cf1, "E")); |
|
|
|
|
|
|
|
|
|
ASSERT_EQ( |
|
|
|
|
"PUT(A):a,PUT(A):aa,DEL(A),PUT(A):aaa,PUT(A):xxx,PUT(B):b,PUT(B):bb,DEL(" |
|
|
|
@ -1672,7 +1693,7 @@ TEST_F(WriteBatchWithIndexTest, SavePointTest) { |
|
|
|
|
PrintContents(&batch, &cf1)); |
|
|
|
|
|
|
|
|
|
batch.SetSavePoint(); // 5
|
|
|
|
|
batch.Put("X", "x"); |
|
|
|
|
ASSERT_OK(batch.Put("X", "x")); |
|
|
|
|
|
|
|
|
|
ASSERT_EQ("PUT(A):a,PUT(A):aa,DEL(A),PUT(B):b,PUT(B):bb,PUT(C):cc,PUT(X):x,", |
|
|
|
|
PrintContents(&batch, nullptr)); |
|
|
|
@ -1715,7 +1736,7 @@ TEST_F(WriteBatchWithIndexTest, SingleDeleteTest) { |
|
|
|
|
std::string value; |
|
|
|
|
DBOptions db_options; |
|
|
|
|
|
|
|
|
|
batch.SingleDelete("A"); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("A")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatch(db_options, "A", &value); |
|
|
|
|
ASSERT_TRUE(s.IsNotFound()); |
|
|
|
@ -1725,10 +1746,10 @@ TEST_F(WriteBatchWithIndexTest, SingleDeleteTest) { |
|
|
|
|
ASSERT_EQ("SINGLE-DEL(A),", value); |
|
|
|
|
|
|
|
|
|
batch.Clear(); |
|
|
|
|
batch.Put("A", "a"); |
|
|
|
|
batch.Put("A", "a2"); |
|
|
|
|
batch.Put("B", "b"); |
|
|
|
|
batch.SingleDelete("A"); |
|
|
|
|
ASSERT_OK(batch.Put("A", "a")); |
|
|
|
|
ASSERT_OK(batch.Put("A", "a2")); |
|
|
|
|
ASSERT_OK(batch.Put("B", "b")); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("A")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatch(db_options, "A", &value); |
|
|
|
|
ASSERT_TRUE(s.IsNotFound()); |
|
|
|
@ -1739,11 +1760,11 @@ TEST_F(WriteBatchWithIndexTest, SingleDeleteTest) { |
|
|
|
|
value = PrintContents(&batch, nullptr); |
|
|
|
|
ASSERT_EQ("PUT(A):a,PUT(A):a2,SINGLE-DEL(A),PUT(B):b,", value); |
|
|
|
|
|
|
|
|
|
batch.Put("C", "c"); |
|
|
|
|
batch.Put("A", "a3"); |
|
|
|
|
batch.Delete("B"); |
|
|
|
|
batch.SingleDelete("B"); |
|
|
|
|
batch.SingleDelete("C"); |
|
|
|
|
ASSERT_OK(batch.Put("C", "c")); |
|
|
|
|
ASSERT_OK(batch.Put("A", "a3")); |
|
|
|
|
ASSERT_OK(batch.Delete("B")); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("B")); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("C")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatch(db_options, "A", &value); |
|
|
|
|
ASSERT_OK(s); |
|
|
|
@ -1761,12 +1782,12 @@ TEST_F(WriteBatchWithIndexTest, SingleDeleteTest) { |
|
|
|
|
",PUT(C):c,SINGLE-DEL(C),", |
|
|
|
|
value); |
|
|
|
|
|
|
|
|
|
batch.Put("B", "b4"); |
|
|
|
|
batch.Put("C", "c4"); |
|
|
|
|
batch.Put("D", "d4"); |
|
|
|
|
batch.SingleDelete("D"); |
|
|
|
|
batch.SingleDelete("D"); |
|
|
|
|
batch.Delete("A"); |
|
|
|
|
ASSERT_OK(batch.Put("B", "b4")); |
|
|
|
|
ASSERT_OK(batch.Put("C", "c4")); |
|
|
|
|
ASSERT_OK(batch.Put("D", "d4")); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("D")); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("D")); |
|
|
|
|
ASSERT_OK(batch.Delete("A")); |
|
|
|
|
|
|
|
|
|
s = batch.GetFromBatch(db_options, "A", &value); |
|
|
|
|
ASSERT_TRUE(s.IsNotFound()); |
|
|
|
@ -1788,15 +1809,15 @@ TEST_F(WriteBatchWithIndexTest, SingleDeleteTest) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST_F(WriteBatchWithIndexTest, SingleDeleteDeltaIterTest) { |
|
|
|
|
Status s; |
|
|
|
|
std::string value; |
|
|
|
|
DBOptions db_options; |
|
|
|
|
WriteBatchWithIndex batch(BytewiseComparator(), 20, true /* overwrite_key */); |
|
|
|
|
batch.Put("A", "a"); |
|
|
|
|
batch.Put("A", "a2"); |
|
|
|
|
batch.Put("B", "b"); |
|
|
|
|
batch.SingleDelete("A"); |
|
|
|
|
batch.Delete("B"); |
|
|
|
|
|
|
|
|
|
ASSERT_OK(batch.Put("A", "a")); |
|
|
|
|
ASSERT_OK(batch.Put("A", "a2")); |
|
|
|
|
ASSERT_OK(batch.Put("B", "b")); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("A")); |
|
|
|
|
ASSERT_OK(batch.Delete("B")); |
|
|
|
|
|
|
|
|
|
KVMap map; |
|
|
|
|
value = PrintContents(&batch, &map, nullptr); |
|
|
|
@ -1806,20 +1827,20 @@ TEST_F(WriteBatchWithIndexTest, SingleDeleteDeltaIterTest) { |
|
|
|
|
map["C"] = "cc"; |
|
|
|
|
map["D"] = "dd"; |
|
|
|
|
|
|
|
|
|
batch.SingleDelete("B"); |
|
|
|
|
batch.SingleDelete("C"); |
|
|
|
|
batch.SingleDelete("Z"); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("B")); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("C")); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("Z")); |
|
|
|
|
|
|
|
|
|
value = PrintContents(&batch, &map, nullptr); |
|
|
|
|
ASSERT_EQ("D:dd,", value); |
|
|
|
|
|
|
|
|
|
batch.Put("A", "a3"); |
|
|
|
|
batch.Put("B", "b3"); |
|
|
|
|
batch.SingleDelete("A"); |
|
|
|
|
batch.SingleDelete("A"); |
|
|
|
|
batch.SingleDelete("D"); |
|
|
|
|
batch.SingleDelete("D"); |
|
|
|
|
batch.Delete("D"); |
|
|
|
|
ASSERT_OK(batch.Put("A", "a3")); |
|
|
|
|
ASSERT_OK(batch.Put("B", "b3")); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("A")); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("A")); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("D")); |
|
|
|
|
ASSERT_OK(batch.SingleDelete("D")); |
|
|
|
|
ASSERT_OK(batch.Delete("D")); |
|
|
|
|
|
|
|
|
|
map["E"] = "ee"; |
|
|
|
|
|
|
|
|
|