add disable WAL option

Summary: add disable WAL option

Test Plan: new testcase in db_test.cc

Reviewers: dhruba

Reviewed By: dhruba

Differential Revision: https://reviews.facebook.net/D4011
This commit is contained in:
heyongqiang
2012-07-05 13:39:28 -07:00
parent 7600228072
commit a347d4ac0d
3 changed files with 52 additions and 4 deletions

View File

@@ -40,6 +40,7 @@ struct DBImpl::Writer {
Status status;
WriteBatch* batch;
bool sync;
bool disableWAL;
bool done;
port::CondVar cv;
@@ -1140,6 +1141,7 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
Writer w(&mutex_);
w.batch = my_batch;
w.sync = options.sync;
w.disableWAL = options.disableWAL;
w.done = false;
MutexLock l(&mutex_);
@@ -1166,9 +1168,11 @@ 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.disableWAL) {
status = log_->AddRecord(WriteBatchInternal::Contents(updates));
if (status.ok() && options.sync) {
status = logfile_->Sync();
}
}
if (status.ok()) {
status = WriteBatchInternal::InsertInto(updates, mem_);
@@ -1227,6 +1231,12 @@ WriteBatch* DBImpl::BuildBatchGroup(Writer** last_writer) {
break;
}
if (!w->disableWAL && first->disableWAL) {
// Do not include a write that needs WAL into a batch that has
// WAL disabled.
break;
}
if (w->batch != NULL) {
size += WriteBatchInternal::ByteSize(w->batch);
if (size > max_size) {