Skip to content
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

Add an option to enable/disable auto flush for specific DB #183

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion include/libjungle/db_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class DBConfig {
DBConfig()
: allowOverwriteSeqNum(false)
, logSectionOnly(false)
, autoLogFlush(true)
, truncateInconsecutiveLogs(true)
, logFileTtl_sec(0)
, maxKeepingMemtables(0)
Expand Down Expand Up @@ -179,11 +180,21 @@ class DBConfig {
*/
bool allowOverwriteSeqNum;

/*
/**
* Disable table section and use logging part only.
*/
bool logSectionOnly;

/**
* If it is normal DB instance (`readOnly = false` and `logSectionOnly = false`),
* background flusher thread will automatically flush logs to L0 tables.
*
* WARNING:
* If it is set to `false`, users should manually call `flushLogs()`.
* The more unflushed logs, the more memory consumption.
*/
bool autoLogFlush;

/*
* (Only when `logSectionOnly == true`)
* Truncate tail logs if they are inconsecutive,
Expand Down
7 changes: 4 additions & 3 deletions src/log_mgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1884,18 +1884,19 @@ Status LogMgr::getLastSyncedSeqNum(uint64_t& seq_num_out) {
return Status();
}


bool LogMgr::checkTimeToFlush(const GlobalConfig& config) {
Status s;
uint64_t l_last_flush = 0;
uint64_t l_max = 0;
uint64_t seq_last_flush = NOT_INITIALIZED;
uint64_t seq_max = NOT_INITIALIZED;

if (getDbConfig()->readOnly) return false;
const DBConfig* db_config = getDbConfig();
if (db_config->readOnly) return false;
if (syncSema.grabbed) return false;
if (flushSema.grabbed) return false;
if (getDbConfig()->logSectionOnly) return false;
if (db_config->logSectionOnly) return false;
if (!db_config->autoLogFlush) return false;

const size_t MAX_TRY = 10;
size_t num_try = 0;
Expand Down
52 changes: 52 additions & 0 deletions tests/jungle/basic_op_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3114,6 +3114,57 @@ int serialized_sync_and_flush_test() {
return 0;
}

int disabling_auto_flush_test() {
std::string filename;
TEST_SUITE_PREPARE_PATH(filename);

jungle::Status s;
jungle::DBConfig config;
TEST_CUSTOM_DB_CONFIG(config);
jungle::DB* db1 = nullptr;
jungle::DB* db2 = nullptr;

jungle::GlobalConfig g_config;
g_config.numFlusherThreads = 1;
g_config.flusherMinRecordsToTrigger = 100;
jungle::init(g_config);

config.maxEntriesInLogFile = 100;
std::string db1_file = filename + "_db1";
CHK_Z(jungle::DB::open(&db1, db1_file, config));

config.autoLogFlush = false;
std::string db2_file = filename + "_db2";
CHK_Z(jungle::DB::open(&db2, db2_file, config));

auto insert_keys = [&](size_t from, size_t to) {
for (size_t ii = from; ii < to; ++ii) {
std::string key_str = "key" + TestSuite::lzStr(5, ii);
std::string val_str = "val" + TestSuite::lzStr(5, ii);
CHK_Z( db1->set( jungle::KV(key_str, val_str) ) );
CHK_Z( db2->set( jungle::KV(key_str, val_str) ) );
}
return 0;
};

CHK_Z( insert_keys(0, 200) );

// Wait longer than flusher sleep time.
TestSuite::sleep_ms(g_config.flusherSleepDuration_ms * 2, "wait for flusher..");

uint64_t db1_flushed_seqnum = 0, db2_flushed_seqnum = 0;
CHK_Z(db1->getLastFlushedSeqNum(db1_flushed_seqnum));
CHK_EQ(jungle::Status::INVALID_SEQNUM,
db2->getLastFlushedSeqNum(db2_flushed_seqnum).getValue());

CHK_Z(jungle::DB::close(db1));
CHK_Z(jungle::DB::close(db2));
CHK_Z(jungle::shutdown());

TEST_SUITE_CLEANUP_PATH();
return 0;
}

int main(int argc, char** argv) {
TestSuite ts(argc, argv);

Expand Down Expand Up @@ -3169,6 +3220,7 @@ int main(int argc, char** argv) {
ts.doTest("sample key test", sample_key_test);
ts.doTest("log flush add new file race test", log_flush_add_new_file_race_test);
ts.doTest("serialized sync and flush test", serialized_sync_and_flush_test);
ts.doTest("disabling auto flush test", disabling_auto_flush_test);

return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions tests/jungle/log_reclaim_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,6 @@ int dedicated_flusher_test() {
return 0;
}


} using namespace log_reclaim_test;

int main(int argc, char** argv) {
Expand Down Expand Up @@ -1741,7 +1740,6 @@ int main(int argc, char** argv) {
ts.doTest("snapshot on purged memtable test",
snapshot_on_purged_memtable_test);


ts.doTest("dedicated flusher test",
dedicated_flusher_test);

Expand Down
Loading