From c3096afd61c9a88ae76dc5e8d7c38a31c5e8691a Mon Sep 17 00:00:00 2001 From: Dhruba Borthakur Date: Fri, 3 Aug 2012 15:20:58 -0700 Subject: [PATCH] Introduce a new option disableDataSync for opening the database. If this is set to true, then the data written to newly created data files are not sycned to disk, instead depend on the OS to flush dirty data to stable storage. This option is good for bulk Test Plan: manual tests Task ID: # Blame Rev: Differential Revision: https://reviews.facebook.net/D4515 --- db/db_impl.cc | 2 +- include/leveldb/options.h | 8 ++++++++ util/options.cc | 3 ++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/db/db_impl.cc b/db/db_impl.cc index c2e853c885..72e85f9361 100644 --- a/db/db_impl.cc +++ b/db/db_impl.cc @@ -810,7 +810,7 @@ Status DBImpl::FinishCompactionOutputFile(CompactionState* compact, compact->builder = NULL; // Finish and check for file errors - if (s.ok()) { + if (s.ok() && !options_.disableDataSync) { s = compact->outfile->Sync(); } if (s.ok()) { diff --git a/include/leveldb/options.h b/include/leveldb/options.h index 41c356ffbc..d0b5a4cf93 100644 --- a/include/leveldb/options.h +++ b/include/leveldb/options.h @@ -190,6 +190,14 @@ struct Options { // If non-null, then we should collect metrics about database operations Statistics* statistics; + // If true, then the contents of data files are not synced + // to stable storage. Their contents remain in the OS buffers till the + // OS decides to flush them. This option is good for bulk-loading + // of data. Once the bulk-loading is complete, please issue a + // sync to the OS to flush all dirty buffesrs to stable storage. + // Default: false + bool disableDataSync; + // Create an Options object with default values for all fields. Options(); }; diff --git a/util/options.cc b/util/options.cc index 0ad742ce20..50ed00f9c0 100644 --- a/util/options.cc +++ b/util/options.cc @@ -34,7 +34,8 @@ Options::Options() expanded_compaction_factor(25), max_grandparent_overlap_factor(10), filter_policy(NULL), - statistics(NULL) { + statistics(NULL), + disableDataSync(false) { } } // namespace leveldb