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