|
|
|
@ -37,9 +37,10 @@ class DBOptionsTest : public DBTestBase { |
|
|
|
|
ConfigOptions config_options; |
|
|
|
|
config_options.delimiter = "; "; |
|
|
|
|
|
|
|
|
|
GetStringFromMutableDBOptions(config_options, MutableDBOptions(options), |
|
|
|
|
&options_str); |
|
|
|
|
StringToMap(options_str, &mutable_map); |
|
|
|
|
EXPECT_OK(GetStringFromMutableDBOptions( |
|
|
|
|
config_options, MutableDBOptions(options), &options_str)); |
|
|
|
|
EXPECT_OK(StringToMap(options_str, &mutable_map)); |
|
|
|
|
|
|
|
|
|
return mutable_map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -50,9 +51,9 @@ class DBOptionsTest : public DBTestBase { |
|
|
|
|
config_options.delimiter = "; "; |
|
|
|
|
|
|
|
|
|
std::unordered_map<std::string, std::string> mutable_map; |
|
|
|
|
GetStringFromMutableCFOptions(config_options, MutableCFOptions(options), |
|
|
|
|
&options_str); |
|
|
|
|
StringToMap(options_str, &mutable_map); |
|
|
|
|
EXPECT_OK(GetStringFromMutableCFOptions( |
|
|
|
|
config_options, MutableCFOptions(options), &options_str)); |
|
|
|
|
EXPECT_OK(StringToMap(options_str, &mutable_map)); |
|
|
|
|
return mutable_map; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -134,7 +135,7 @@ TEST_F(DBOptionsTest, SetBytesPerSync) { |
|
|
|
|
WriteOptions write_opts; |
|
|
|
|
// should sync approximately 40MB/1MB ~= 40 times.
|
|
|
|
|
for (i = 0; i < 40; i++) { |
|
|
|
|
Put(Key(i), kValue, write_opts); |
|
|
|
|
ASSERT_OK(Put(Key(i), kValue, write_opts)); |
|
|
|
|
} |
|
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing(); |
|
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr)); |
|
|
|
@ -150,7 +151,7 @@ TEST_F(DBOptionsTest, SetBytesPerSync) { |
|
|
|
|
// should sync approximately 40MB*2/8MB ~= 10 times.
|
|
|
|
|
// data will be 40*2MB because of previous Puts too.
|
|
|
|
|
for (i = 0; i < 40; i++) { |
|
|
|
|
Put(Key(i), kValue, write_opts); |
|
|
|
|
ASSERT_OK(Put(Key(i), kValue, write_opts)); |
|
|
|
|
} |
|
|
|
|
ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing(); |
|
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr)); |
|
|
|
@ -181,7 +182,7 @@ TEST_F(DBOptionsTest, SetWalBytesPerSync) { |
|
|
|
|
const std::string kValue(kValueSize, 'v'); |
|
|
|
|
int i = 0; |
|
|
|
|
for (; i < 10; i++) { |
|
|
|
|
Put(Key(i), kValue); |
|
|
|
|
ASSERT_OK(Put(Key(i), kValue)); |
|
|
|
|
} |
|
|
|
|
// Do not flush. If we flush here, SwitchWAL will reuse old WAL file since its
|
|
|
|
|
// empty and will not get the new wal_bytes_per_sync value.
|
|
|
|
@ -192,7 +193,7 @@ TEST_F(DBOptionsTest, SetWalBytesPerSync) { |
|
|
|
|
counter = 0; |
|
|
|
|
i = 0; |
|
|
|
|
for (; i < 10; i++) { |
|
|
|
|
Put(Key(i), kValue); |
|
|
|
|
ASSERT_OK(Put(Key(i), kValue)); |
|
|
|
|
} |
|
|
|
|
ASSERT_GT(counter, 0); |
|
|
|
|
ASSERT_GT(low_bytes_per_sync, 0); |
|
|
|
@ -227,9 +228,9 @@ TEST_F(DBOptionsTest, WritableFileMaxBufferSize) { |
|
|
|
|
for (; i < 3; i++) { |
|
|
|
|
ASSERT_OK(Put("foo", ToString(i))); |
|
|
|
|
ASSERT_OK(Put("bar", ToString(i))); |
|
|
|
|
Flush(); |
|
|
|
|
ASSERT_OK(Flush()); |
|
|
|
|
} |
|
|
|
|
dbfull()->TEST_WaitForCompact(); |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact()); |
|
|
|
|
ASSERT_EQ(unmatch_cnt, 0); |
|
|
|
|
ASSERT_GE(match_cnt, 11); |
|
|
|
|
|
|
|
|
@ -245,9 +246,9 @@ TEST_F(DBOptionsTest, WritableFileMaxBufferSize) { |
|
|
|
|
for (; i < 3; i++) { |
|
|
|
|
ASSERT_OK(Put("foo", ToString(i))); |
|
|
|
|
ASSERT_OK(Put("bar", ToString(i))); |
|
|
|
|
Flush(); |
|
|
|
|
ASSERT_OK(Flush()); |
|
|
|
|
} |
|
|
|
|
dbfull()->TEST_WaitForCompact(); |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact()); |
|
|
|
|
ASSERT_EQ(unmatch_cnt, 0); |
|
|
|
|
ASSERT_GE(match_cnt, 11); |
|
|
|
|
} |
|
|
|
@ -283,14 +284,14 @@ TEST_F(DBOptionsTest, EnableAutoCompactionAndTriggerStall) { |
|
|
|
|
DestroyAndReopen(options); |
|
|
|
|
int i = 0; |
|
|
|
|
for (; i < 1024; i++) { |
|
|
|
|
Put(Key(i), kValue); |
|
|
|
|
ASSERT_OK(Put(Key(i), kValue)); |
|
|
|
|
} |
|
|
|
|
Flush(); |
|
|
|
|
ASSERT_OK(Flush()); |
|
|
|
|
for (; i < 1024 * 2; i++) { |
|
|
|
|
Put(Key(i), kValue); |
|
|
|
|
ASSERT_OK(Put(Key(i), kValue)); |
|
|
|
|
} |
|
|
|
|
Flush(); |
|
|
|
|
dbfull()->TEST_WaitForFlushMemTable(); |
|
|
|
|
ASSERT_OK(Flush()); |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable()); |
|
|
|
|
ASSERT_EQ(2, NumTableFilesAtLevel(0)); |
|
|
|
|
uint64_t l0_size = SizeAtLevel(0); |
|
|
|
|
|
|
|
|
@ -312,7 +313,7 @@ TEST_F(DBOptionsTest, EnableAutoCompactionAndTriggerStall) { |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
Reopen(options); |
|
|
|
|
dbfull()->TEST_WaitForCompact(); |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact()); |
|
|
|
|
ASSERT_FALSE(dbfull()->TEST_write_controler().IsStopped()); |
|
|
|
|
ASSERT_FALSE(dbfull()->TEST_write_controler().NeedsDelay()); |
|
|
|
|
|
|
|
|
@ -359,7 +360,7 @@ TEST_F(DBOptionsTest, EnableAutoCompactionAndTriggerStall) { |
|
|
|
|
TEST_SYNC_POINT("DBOptionsTest::EnableAutoCompactionAndTriggerStall:3"); |
|
|
|
|
|
|
|
|
|
// Background compaction executed.
|
|
|
|
|
dbfull()->TEST_WaitForCompact(); |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact()); |
|
|
|
|
ASSERT_FALSE(dbfull()->TEST_write_controler().IsStopped()); |
|
|
|
|
ASSERT_FALSE(dbfull()->TEST_write_controler().NeedsDelay()); |
|
|
|
|
} |
|
|
|
@ -376,12 +377,12 @@ TEST_F(DBOptionsTest, SetOptionsMayTriggerCompaction) { |
|
|
|
|
// Need to insert two keys to avoid trivial move.
|
|
|
|
|
ASSERT_OK(Put("foo", ToString(i))); |
|
|
|
|
ASSERT_OK(Put("bar", ToString(i))); |
|
|
|
|
Flush(); |
|
|
|
|
ASSERT_OK(Flush()); |
|
|
|
|
} |
|
|
|
|
ASSERT_EQ("3", FilesPerLevel()); |
|
|
|
|
ASSERT_OK( |
|
|
|
|
dbfull()->SetOptions({{"level0_file_num_compaction_trigger", "3"}})); |
|
|
|
|
dbfull()->TEST_WaitForCompact(); |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact()); |
|
|
|
|
ASSERT_EQ("0,1", FilesPerLevel()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -503,7 +504,7 @@ TEST_F(DBOptionsTest, MaxTotalWalSizeChange) { |
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"max_total_wal_size", "10"}})); |
|
|
|
|
|
|
|
|
|
for (size_t cf = 0; cf < handles_.size(); ++cf) { |
|
|
|
|
dbfull()->TEST_WaitForFlushMemTable(handles_[cf]); |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForFlushMemTable(handles_[cf])); |
|
|
|
|
ASSERT_EQ("1", FilesPerLevel(static_cast<int>(cf))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -716,13 +717,13 @@ TEST_F(DBOptionsTest, SetFIFOCompactionOptions) { |
|
|
|
|
|
|
|
|
|
// No files should be compacted as ttl is set to 1 hour.
|
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().ttl, 3600); |
|
|
|
|
dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr); |
|
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr)); |
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 10); |
|
|
|
|
|
|
|
|
|
// Set ttl to 1 minute. So all files should get deleted.
|
|
|
|
|
ASSERT_OK(dbfull()->SetOptions({{"ttl", "60"}})); |
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().ttl, 60); |
|
|
|
|
dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr); |
|
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr)); |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact()); |
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 0); |
|
|
|
|
|
|
|
|
@ -738,7 +739,7 @@ TEST_F(DBOptionsTest, SetFIFOCompactionOptions) { |
|
|
|
|
for (int j = 0; j < 10; j++) { |
|
|
|
|
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); |
|
|
|
|
} |
|
|
|
|
Flush(); |
|
|
|
|
ASSERT_OK(Flush()); |
|
|
|
|
} |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact()); |
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 10); |
|
|
|
@ -746,7 +747,7 @@ TEST_F(DBOptionsTest, SetFIFOCompactionOptions) { |
|
|
|
|
// No files should be compacted as max_table_files_size is set to 500 KB.
|
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().compaction_options_fifo.max_table_files_size, |
|
|
|
|
500 << 10); |
|
|
|
|
dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr); |
|
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr)); |
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 10); |
|
|
|
|
|
|
|
|
|
// Set max_table_files_size to 12 KB. So only 1 file should remain now.
|
|
|
|
@ -754,7 +755,7 @@ TEST_F(DBOptionsTest, SetFIFOCompactionOptions) { |
|
|
|
|
{{"compaction_options_fifo", "{max_table_files_size=12288;}"}})); |
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().compaction_options_fifo.max_table_files_size, |
|
|
|
|
12 << 10); |
|
|
|
|
dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr); |
|
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr)); |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact()); |
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 1); |
|
|
|
|
|
|
|
|
@ -770,7 +771,7 @@ TEST_F(DBOptionsTest, SetFIFOCompactionOptions) { |
|
|
|
|
for (int j = 0; j < 10; j++) { |
|
|
|
|
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); |
|
|
|
|
} |
|
|
|
|
Flush(); |
|
|
|
|
ASSERT_OK(Flush()); |
|
|
|
|
} |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact()); |
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 10); |
|
|
|
@ -779,7 +780,7 @@ TEST_F(DBOptionsTest, SetFIFOCompactionOptions) { |
|
|
|
|
// allow_compaction is false
|
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().compaction_options_fifo.allow_compaction, |
|
|
|
|
false); |
|
|
|
|
dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr); |
|
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr)); |
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 10); |
|
|
|
|
|
|
|
|
|
// Set allow_compaction to true. So number of files should be between 1 and 5.
|
|
|
|
@ -787,7 +788,7 @@ TEST_F(DBOptionsTest, SetFIFOCompactionOptions) { |
|
|
|
|
{{"compaction_options_fifo", "{allow_compaction=true;}"}})); |
|
|
|
|
ASSERT_EQ(dbfull()->GetOptions().compaction_options_fifo.allow_compaction, |
|
|
|
|
true); |
|
|
|
|
dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr); |
|
|
|
|
ASSERT_OK(dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr)); |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact()); |
|
|
|
|
ASSERT_GE(NumTableFilesAtLevel(0), 1); |
|
|
|
|
ASSERT_LE(NumTableFilesAtLevel(0), 5); |
|
|
|
@ -808,14 +809,14 @@ TEST_F(DBOptionsTest, CompactionReadaheadSizeChange) { |
|
|
|
|
ASSERT_OK(dbfull()->SetDBOptions({{"compaction_readahead_size", "256"}})); |
|
|
|
|
ASSERT_EQ(256, dbfull()->GetDBOptions().compaction_readahead_size); |
|
|
|
|
for (int i = 0; i < 1024; i++) { |
|
|
|
|
Put(Key(i), kValue); |
|
|
|
|
ASSERT_OK(Put(Key(i), kValue)); |
|
|
|
|
} |
|
|
|
|
Flush(); |
|
|
|
|
ASSERT_OK(Flush()); |
|
|
|
|
for (int i = 0; i < 1024 * 2; i++) { |
|
|
|
|
Put(Key(i), kValue); |
|
|
|
|
ASSERT_OK(Put(Key(i), kValue)); |
|
|
|
|
} |
|
|
|
|
Flush(); |
|
|
|
|
dbfull()->TEST_WaitForCompact(); |
|
|
|
|
ASSERT_OK(Flush()); |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact()); |
|
|
|
|
ASSERT_EQ(256, env_->compaction_readahead_size_); |
|
|
|
|
Close(); |
|
|
|
|
} |
|
|
|
@ -834,7 +835,7 @@ TEST_F(DBOptionsTest, FIFOTtlBackwardCompatible) { |
|
|
|
|
for (int j = 0; j < 10; j++) { |
|
|
|
|
ASSERT_OK(Put(ToString(i * 20 + j), rnd.RandomString(980))); |
|
|
|
|
} |
|
|
|
|
Flush(); |
|
|
|
|
ASSERT_OK(Flush()); |
|
|
|
|
} |
|
|
|
|
ASSERT_OK(dbfull()->TEST_WaitForCompact()); |
|
|
|
|
ASSERT_EQ(NumTableFilesAtLevel(0), 10); |
|
|
|
|