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

Option to disable leveldb's recovery log #225

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
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
46 changes: 32 additions & 14 deletions db/db_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ DBImpl::DBImpl(const Options& options, const std::string& dbname)
DBImpl::~DBImpl() {
DBList()->ReleaseDB(this, options_.is_internal_db);

// maybe push memory buffer(s) to disk if recovery log disabled
if (options_.disable_recovery_log)
CompactMemTableSynchronous();

// Wait for background work to finish
mutex_.Lock();
shutting_down_.Release_Store(this); // Any non-NULL value is ok
Expand Down Expand Up @@ -1830,10 +1834,13 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
// into mem_.
{
mutex_.Unlock();
status = log_->AddRecord(WriteBatchInternal::Contents(updates));
if (status.ok() && options.sync) {
status = logfile_->Sync();
}
if (!options_.disable_recovery_log)
{
status = log_->AddRecord(WriteBatchInternal::Contents(updates));
if (status.ok() && options.sync) {
status = logfile_->Sync();
} // if
} // if
if (status.ok()) {
status = WriteBatchInternal::InsertInto(updates, mem_, &options_);
}
Expand Down Expand Up @@ -2017,7 +2024,8 @@ Status DBImpl::MakeRoomForWrite(bool force) {
Log(options_.info_log, "waiting 2...\n");
gPerfCounters->Inc(ePerfWriteWaitImm);
MaybeScheduleCompaction();
if (!shutting_down_.Acquire_Load())
while (imm_ != NULL && bg_error_.ok()
&& !shutting_down_.Acquire_Load())
bg_cv_.Wait();
Log(options_.info_log, "running 2...\n");
} else if (versions_->NumLevelFiles(0) >= config::kL0_StopWritesTrigger) {
Expand Down Expand Up @@ -2070,19 +2078,29 @@ Status DBImpl::NewRecoveryLog(
Status s;
WritableFile * lfile(NULL);

s = env_->NewWriteOnlyFile(LogFileName(dbname_, NewLogNumber), &lfile,
options_.env->RecoveryMmapSize(&options_));
if (s.ok())
if (!options_.disable_recovery_log)
{
// close any existing
delete log_;
delete logfile_;
s = env_->NewWriteOnlyFile(LogFileName(dbname_, NewLogNumber), &lfile,
options_.env->RecoveryMmapSize(&options_));
if (s.ok())
{
// close any existing
delete log_;
delete logfile_;

logfile_ = lfile;
logfile_number_ = NewLogNumber;
log_ = new log::Writer(lfile);
logfile_ = lfile;
logfile_number_ = NewLogNumber;
log_ = new log::Writer(lfile);
} // if
} // if

// keep asserts valid
else
{
logfile_number_ = NewLogNumber;
} // else


return(s);

} // DBImpl::NewRecoveryLog
Expand Down
9 changes: 8 additions & 1 deletion db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class DBTest {
kDefault,
kFilter,
kUncompressed,
kDisableRecovery,
kEnd
};
int option_config_;
Expand Down Expand Up @@ -202,6 +203,9 @@ class DBTest {
case kUncompressed:
options.compression = kNoCompression;
break;
case kDisableRecovery:
options.disable_recovery_log = true;
break;
default:
break;
}
Expand Down Expand Up @@ -1073,7 +1077,10 @@ TEST(DBTest, ApproximateSizes) {
}

ASSERT_EQ(NumTableFilesAtLevel(0), 0);
ASSERT_GT(NumTableFilesAtLevel(1), 0);
if (!CurrentOptions().disable_recovery_log)
ASSERT_GT(NumTableFilesAtLevel(1), 0);
else
ASSERT_GT(NumTableFilesAtLevel(3), 0); // code path uses move
}
} while (ChangeOptions());
}
Expand Down
6 changes: 6 additions & 0 deletions include/leveldb/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ struct Options {
// upon restart.
bool cache_object_warming;

// Riak specific option to disable writing of recovery log
// during DB::Write() / Put() calls. This speeds performance
// but can lead to loss of tens of megabytes of data if
// system crashes. Used in Riak for temporary tables only.
bool disable_recovery_log;

// Riak specific object that defines expiry policy for data
// written to leveldb.
ExpiryPtr_t expiry_module;
Expand Down
4 changes: 3 additions & 1 deletion util/options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ Options::Options()
delete_threshold(1000),
fadvise_willneed(false),
tiered_slow_level(0),
cache_object_warming(true)
cache_object_warming(true),
disable_recovery_log(false)
{

}
Expand Down Expand Up @@ -89,6 +90,7 @@ Options::Dump(
Log(log," Options.tiered_slow_prefix: %s", tiered_slow_prefix.c_str());
Log(log," crc32c: %s", crc32c::IsHardwareCRC() ? "hardware" : "software");
Log(log," Options.cache_object_warming: %s", cache_object_warming ? "true" : "false");
Log(log," Options.disable_recovery_log: %s", disable_recovery_log ? "true" : "false");
Log(log," Options.ExpiryActivated: %s", ExpiryActivated() ? "true" : "false");

if (NULL!=expiry_module.get())
Expand Down