Skip to content

Commit 4a27a2f

Browse files
committed
Don't sync manifest when disableDataSync = true
Summary: As we discussed offline Test Plan: compiles Reviewers: yhchiang, sdong, ljin, dhruba Reviewed By: sdong Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D22989
1 parent 9b8480d commit 4a27a2f

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

HISTORY.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Behavior changes
88
* We have refactored our system of stalling writes. Any stall-related statistics' meanings are changed. Instead of per-write stall counts, we now count stalls per-epoch, where epochs are periods between flushes and compactions. You'll find more information in our Tuning Perf Guide once we release RocksDB 3.6.
9+
* When disableDataSync=true, we no longer sync the MANIFEST file.
910

1011
----- Past Releases -----
1112

db/db_test.cc

+31-1
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ class SpecialEnv : public EnvWrapper {
151151

152152
std::atomic<int64_t> bytes_written_;
153153

154+
std::atomic<int> sync_counter_;
155+
154156
explicit SpecialEnv(Env* base) : EnvWrapper(base) {
155157
delay_sstable_sync_.Release_Store(nullptr);
156158
drop_writes_.Release_Store(nullptr);
@@ -162,6 +164,7 @@ class SpecialEnv : public EnvWrapper {
162164
manifest_write_error_.Release_Store(nullptr);
163165
log_write_error_.Release_Store(nullptr);
164166
bytes_written_ = 0;
167+
sync_counter_ = 0;
165168
}
166169

167170
Status NewWritableFile(const std::string& f, unique_ptr<WritableFile>* r,
@@ -190,6 +193,7 @@ class SpecialEnv : public EnvWrapper {
190193
Status Close() { return base_->Close(); }
191194
Status Flush() { return base_->Flush(); }
192195
Status Sync() {
196+
++env_->sync_counter_;
193197
while (env_->delay_sstable_sync_.Acquire_Load() != nullptr) {
194198
env_->SleepForMicroseconds(100000);
195199
}
@@ -216,6 +220,7 @@ class SpecialEnv : public EnvWrapper {
216220
Status Close() { return base_->Close(); }
217221
Status Flush() { return base_->Flush(); }
218222
Status Sync() {
223+
++env_->sync_counter_;
219224
if (env_->manifest_sync_error_.Acquire_Load() != nullptr) {
220225
return Status::IOError("simulated sync error");
221226
} else {
@@ -239,7 +244,10 @@ class SpecialEnv : public EnvWrapper {
239244
}
240245
Status Close() { return base_->Close(); }
241246
Status Flush() { return base_->Flush(); }
242-
Status Sync() { return base_->Sync(); }
247+
Status Sync() {
248+
++env_->sync_counter_;
249+
return base_->Sync();
250+
}
243251
};
244252

245253
if (non_writable_.Acquire_Load() != nullptr) {
@@ -8379,6 +8387,28 @@ TEST(DBTest, WriteSingleThreadEntry) {
83798387
}
83808388
}
83818389

8390+
TEST(DBTest, DisableDataSyncTest) {
8391+
// iter 0 -- no sync
8392+
// iter 1 -- sync
8393+
for (int iter = 0; iter < 2; ++iter) {
8394+
Options options = CurrentOptions();
8395+
options.disableDataSync = iter == 0;
8396+
options.create_if_missing = true;
8397+
options.env = env_;
8398+
Reopen(&options);
8399+
CreateAndReopenWithCF({"pikachu"}, &options);
8400+
8401+
MakeTables(10, "a", "z");
8402+
Compact("a", "z");
8403+
8404+
if (iter == 0) {
8405+
ASSERT_EQ(env_->sync_counter_.load(), 0);
8406+
} else {
8407+
ASSERT_GT(env_->sync_counter_.load(), 0);
8408+
}
8409+
Destroy(&options);
8410+
}
8411+
}
83828412

83838413

83848414
} // namespace rocksdb

db/version_set.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1891,7 +1891,7 @@ Status VersionSet::LogAndApply(ColumnFamilyData* column_family_data,
18911891
break;
18921892
}
18931893
}
1894-
if (s.ok()) {
1894+
if (s.ok() && db_options_->disableDataSync == false) {
18951895
if (db_options_->use_fsync) {
18961896
StopWatch sw(env_, db_options_->statistics.get(),
18971897
MANIFEST_FILE_SYNC_MICROS);
@@ -1928,7 +1928,7 @@ Status VersionSet::LogAndApply(ColumnFamilyData* column_family_data,
19281928
// new CURRENT file that points to it.
19291929
if (s.ok() && new_descriptor_log) {
19301930
s = SetCurrentFile(env_, dbname_, pending_manifest_file_number_,
1931-
db_directory);
1931+
db_options_->disableDataSync ? nullptr : db_directory);
19321932
if (s.ok() && pending_manifest_file_number_ > manifest_file_number_) {
19331933
// delete old manifest file
19341934
Log(db_options_->info_log,

include/rocksdb/options.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ struct DBOptions {
610610
// it does not use any locks to prevent concurrent updates.
611611
std::shared_ptr<Statistics> statistics;
612612

613-
// If true, then the contents of data files are not synced
613+
// If true, then the contents of manifest and data files are not synced
614614
// to stable storage. Their contents remain in the OS buffers till the
615615
// OS decides to flush them. This option is good for bulk-loading
616616
// of data. Once the bulk-loading is complete, please issue a

0 commit comments

Comments
 (0)