-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support flexiable num of L0 (blocking approach) #180
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,8 +28,8 @@ namespace jungle { | |
// | ||
Status TableMgr::compactLevelItr(const CompactOptions& options, | ||
TableInfo* victim_table, | ||
size_t level) | ||
{ | ||
size_t level, | ||
bool adjusting_num_l0) { | ||
if (level >= mani->getNumLevels()) return Status::INVALID_LEVEL; | ||
|
||
Status s; | ||
|
@@ -376,7 +376,7 @@ Status TableMgr::compactLevelItr(const CompactOptions& options, | |
// 1) number of files after split, and | ||
// 2) min keys for each new file. | ||
do { | ||
if (!isCompactionAllowed()) { | ||
if (!isCompactionAllowed() && !adjusting_num_l0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not acceptable. No matter what the reason is, compaction should be cancelled upon the close of DB instance. |
||
throw Status(Status::COMPACTION_CANCELLED); | ||
} | ||
|
||
|
@@ -445,6 +445,7 @@ Status TableMgr::compactLevelItr(const CompactOptions& options, | |
? &twh.leasedWriters[worker_idx]->writerArgs | ||
: &local_args; | ||
w_args->callerAwaiter.reset(); | ||
w_args->adjustingNumL0 = adjusting_num_l0; | ||
|
||
uint64_t count = (jj + 1 == num_new_tables) | ||
? offsets.size() - new_tables[jj]->index | ||
|
@@ -482,7 +483,7 @@ Status TableMgr::compactLevelItr(const CompactOptions& options, | |
} | ||
} | ||
|
||
if (!isCompactionAllowed()) { | ||
if (!isCompactionAllowed() && !adjusting_num_l0) { | ||
// NOTE: keys will be freed below. | ||
for (LsmFlushResult& rr: results) delete rr.tFile; | ||
throw Status(Status::COMPACTION_CANCELLED); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,12 +182,6 @@ Status TableMgr::init(const TableMgrOptions& _options) { | |
opt.compressionEnabled = true; | ||
} | ||
|
||
compactStatus.resize(db_config->numL0Partitions); | ||
for (size_t ii=0; ii<compactStatus.size(); ++ii) { | ||
std::atomic<bool>*& entry = compactStatus[ii]; | ||
entry = new std::atomic<bool>(false); | ||
} | ||
|
||
Status s; | ||
mani = new TableManifest(this, opt.fOps); | ||
mani->setLogger(myLog); | ||
|
@@ -252,6 +246,57 @@ Status TableMgr::init(const TableMgrOptions& _options) { | |
} | ||
} | ||
|
||
// Adjust num L0 partitions blockingly only when it is not logSectionOnly mdoe, | ||
// not read only mode, and the number of L0 partitions read from existing manifest | ||
// file is different from the number specified in db config. | ||
if (!db_config->logSectionOnly && !db_config->readOnly | ||
&& numL0Partitions != db_config->numL0Partitions) { | ||
_log_info(myLog, | ||
"adjust numL0 partitions: %zu -> %zu", | ||
numL0Partitions, | ||
db_config->numL0Partitions); | ||
|
||
if (!db_config->nextLevelExtension) { | ||
_log_err(myLog, "[Adjust numL0] not allowed in L0 only mode"); | ||
throw Status(Status::INVALID_CONFIG); | ||
Comment on lines
+260
to
+261
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should not return error, but follow the previous behavior (accept the existing number). |
||
} | ||
|
||
// Need to compact all existing L0 tables to L1 and recreate empty L0 tables, | ||
// otherwise hash will be messed up. | ||
for (size_t ii = 0; ii < numL0Partitions; ++ii) { | ||
// Force compact L0 table to L1 in blocking manner to reduce L0 | ||
// partitions. | ||
std::list<TableInfo*> tables; | ||
s = mani->getL0Tables(ii, tables); | ||
if (tables.size() != 1 || !s) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There can be more than 1 tables for the same hash, if previous L0 table was in the middle of compaction and the DB was closed. |
||
_log_err(myLog, "[Adjust numL0] tables of hash %zu not found", ii); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
throw s; | ||
} | ||
s = compactLevelItr(CompactOptions(), tables.back(), 0, true); | ||
if (!s) { | ||
_log_err(myLog, "[Adjust numL0] compaction error: %d", s); | ||
throw s; | ||
} | ||
// The compacted table is remove from manifest in compactLevelItr, | ||
// just release | ||
for (TableInfo*& table: tables) { | ||
table->done(); | ||
} | ||
Comment on lines
+275
to
+284
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not that simple problem. What if the process is force-closed (or crashed) in the middle so that a few tables are removed and the others are not, and then we reopen the DB? L0 is screwed up and how are you going to continue adjusting L0? Data loss or letting DB instance unavailable is not acceptable. And this scenario should be thoroughly tested. Adjusting L0 is very risky and vulnerable. |
||
} | ||
for (size_t ii = 0; ii < db_config->numL0Partitions; ++ii) { | ||
TableFile* t_file = nullptr; | ||
TableFileOptions t_opt; | ||
// Set 1M bits as an initial size. | ||
// It will be converging to some value as compaction happens. | ||
t_opt.bloomFilterSize = 1024 * 1024; | ||
EP(createNewTableFile(0, t_file, t_opt)); | ||
EP(mani->addTableFile(0, ii, SizedBuf(), t_file)); | ||
} | ||
// Store manifest file. | ||
mani->store(true); | ||
numL0Partitions = db_config->numL0Partitions; | ||
} | ||
|
||
} else { | ||
// Not exist, initial setup phase. | ||
|
||
|
@@ -287,6 +332,13 @@ Status TableMgr::init(const TableMgrOptions& _options) { | |
// Store manifest file. | ||
mani->store(true); | ||
} | ||
|
||
compactStatus.resize(numL0Partitions); | ||
for (size_t ii = 0; ii < compactStatus.size(); ++ii) { | ||
std::atomic<bool>*& entry = compactStatus[ii]; | ||
entry = new std::atomic<bool>(false); | ||
} | ||
|
||
logTableSettings(db_config); | ||
|
||
removeStaleFiles(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If passing
adjusting_num_l0
is for blocking compaction cancellation, we should remove it.