catch config errors with L0 file count triggers

Test Plan: Run "make clean && make all check"

Reviewers: rven, igor, yhchiang, kradhakrishnan, MarkCallaghan, sdong

Reviewed By: sdong

Subscribers: dhruba

Differential Revision: https://reviews.facebook.net/D33627
This commit is contained in:
Jinfu Leng 2015-02-23 16:08:27 -08:00
parent 62f7a1be4f
commit 96d989f70d
5 changed files with 77 additions and 4 deletions

View File

@ -101,7 +101,8 @@ const Comparator* ColumnFamilyHandleImpl::user_comparator() const {
}
ColumnFamilyOptions SanitizeOptions(const InternalKeyComparator* icmp,
const ColumnFamilyOptions& src) {
const ColumnFamilyOptions& src,
Logger* info_log) {
ColumnFamilyOptions result = src;
result.comparator = icmp;
#ifdef OS_MACOSX
@ -163,6 +164,37 @@ ColumnFamilyOptions SanitizeOptions(const InternalKeyComparator* icmp,
result.level0_stop_writes_trigger = std::numeric_limits<int>::max();
}
if (result.level0_stop_writes_trigger <
result.level0_slowdown_writes_trigger ||
result.level0_slowdown_writes_trigger <
result.level0_file_num_compaction_trigger) {
Warn(info_log,
"This condition must be satisfied: "
"level0_stop_writes_trigger(%d) >= "
"level0_slowdown_writes_trigger(%d) >= "
"level0_file_num_compaction_trigger(%d)",
result.level0_stop_writes_trigger,
result.level0_slowdown_writes_trigger,
result.level0_file_num_compaction_trigger);
if (result.level0_slowdown_writes_trigger <
result.level0_file_num_compaction_trigger) {
result.level0_slowdown_writes_trigger =
result.level0_file_num_compaction_trigger;
}
if (result.level0_stop_writes_trigger <
result.level0_slowdown_writes_trigger) {
result.level0_stop_writes_trigger = result.level0_slowdown_writes_trigger;
}
Warn(info_log,
"Adjust the value to "
"level0_stop_writes_trigger(%d)"
"level0_slowdown_writes_trigger(%d)"
"level0_file_num_compaction_trigger(%d)",
result.level0_stop_writes_trigger,
result.level0_slowdown_writes_trigger,
result.level0_file_num_compaction_trigger);
}
return result;
}
@ -237,7 +269,8 @@ ColumnFamilyData::ColumnFamilyData(
refs_(0),
dropped_(false),
internal_comparator_(cf_options.comparator),
options_(*db_options, SanitizeOptions(&internal_comparator_, cf_options)),
options_(*db_options, SanitizeOptions(&internal_comparator_, cf_options,
db_options->info_log.get())),
ioptions_(options_),
mutable_cf_options_(options_, ioptions_),
write_buffer_(write_buffer),

View File

@ -123,7 +123,8 @@ struct SuperVersion {
};
extern ColumnFamilyOptions SanitizeOptions(const InternalKeyComparator* icmp,
const ColumnFamilyOptions& src);
const ColumnFamilyOptions& src,
Logger* info_log);
class ColumnFamilySet;

View File

@ -326,6 +326,13 @@ class ColumnFamilyTest {
Random rnd_;
};
class DumbLogger : public Logger {
public:
using Logger::Logv;
virtual void Logv(const char* format, va_list ap) {}
virtual size_t GetLogFileSize() const { return 0; }
};
TEST(ColumnFamilyTest, DontReuseColumnFamilyID) {
for (int iter = 0; iter < 3; ++iter) {
Open();
@ -1012,6 +1019,27 @@ TEST(ColumnFamilyTest, CreateMissingColumnFamilies) {
Close();
}
TEST(ColumnFamilyTest, SanitizeOptions) {
DumbLogger logger;
for (int i = 1; i <= 3; i++) {
for (int j = 1; j <= 3; j++) {
for (int k = 1; k <= 3; k++) {
ColumnFamilyOptions original;
original.level0_stop_writes_trigger = i;
original.level0_slowdown_writes_trigger = j;
original.level0_file_num_compaction_trigger = k;
ColumnFamilyOptions result = SanitizeOptions(NULL, original, &logger);
ASSERT_TRUE(result.level0_stop_writes_trigger >=
result.level0_slowdown_writes_trigger);
ASSERT_TRUE(result.level0_slowdown_writes_trigger >=
result.level0_file_num_compaction_trigger);
ASSERT_TRUE(result.level0_file_num_compaction_trigger ==
original.level0_file_num_compaction_trigger);
}
}
}
}
} // namespace rocksdb
int main(int argc, char** argv) {

View File

@ -108,7 +108,8 @@ Options SanitizeOptions(const std::string& dbname,
const InternalKeyComparator* icmp,
const Options& src) {
auto db_options = SanitizeOptions(dbname, DBOptions(src));
auto cf_options = SanitizeOptions(icmp, ColumnFamilyOptions(src));
auto cf_options = SanitizeOptions(icmp, ColumnFamilyOptions(src),
db_options.info_log.get());
return Options(db_options, cf_options);
}

View File

@ -1742,6 +1742,16 @@ TEST(DBTest, GetLevel0Ordering) {
} while (ChangeOptions());
}
TEST(DBTest, WrongLevel0Config) {
Options options = CurrentOptions();
Close();
ASSERT_OK(DestroyDB(dbname_, options));
options.level0_stop_writes_trigger = 1;
options.level0_slowdown_writes_trigger = 2;
options.level0_file_num_compaction_trigger = 3;
ASSERT_OK(DB::Open(options, dbname_, &db_));
}
TEST(DBTest, GetOrderedByLevels) {
do {
CreateAndReopenWithCF({"pikachu"}, CurrentOptions());