Skip to content

Commit 5d0074c

Browse files
author
Lei Jin
committed
set bytes_per_sync to 1MB if rate limiter is enabled
Summary: as title Test Plan: make all check Reviewers: igor, yhchiang, sdong Reviewed By: sdong Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D21201
1 parent 2fa6434 commit 5d0074c

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

db/db_impl.cc

+6
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,12 @@ DBOptions SanitizeOptions(const std::string& dbname, const DBOptions& src) {
271271
}
272272
}
273273

274+
if (!result.rate_limiter) {
275+
if (result.bytes_per_sync == 0) {
276+
result.bytes_per_sync = 1024 * 1024;
277+
}
278+
}
279+
274280
if (result.wal_dir.empty()) {
275281
// Use dbname as default
276282
result.wal_dir = dbname;

include/rocksdb/options.h

+11-6
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,7 @@ struct DBOptions {
636636

637637
// Use to control write rate of flush and compaction. Flush has higher
638638
// priority than compaction. Rate limiting is disabled if nullptr.
639+
// If rate limiter is enabled, bytes_per_sync is set to 1MB by default.
639640
// Default: nullptr
640641
std::shared_ptr<RateLimiter> rate_limiter;
641642

@@ -857,12 +858,6 @@ struct DBOptions {
857858
// Default: false
858859
bool use_adaptive_mutex;
859860

860-
// Allows OS to incrementally sync files to disk while they are being
861-
// written, asynchronously, in the background.
862-
// Issue one request for every bytes_per_sync written. 0 turns it off.
863-
// Default: 0
864-
uint64_t bytes_per_sync;
865-
866861
// Allow RocksDB to use thread local storage to optimize performance.
867862
// Default: true
868863
bool allow_thread_local;
@@ -873,6 +868,16 @@ struct DBOptions {
873868
explicit DBOptions(const Options& options);
874869

875870
void Dump(Logger* log) const;
871+
872+
// Allows OS to incrementally sync files to disk while they are being
873+
// written, asynchronously, in the background.
874+
// Issue one request for every bytes_per_sync written. 0 turns it off.
875+
// Default: 0
876+
//
877+
// You may consider using rate_limiter to regulate write rate to device.
878+
// When rate limiter is enabled, it automatically enables bytes_per_sync
879+
// to 1MB.
880+
uint64_t bytes_per_sync;
876881
};
877882

878883
// Options to control the behavior of a database (passed to DB::Open)

util/options.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ DBOptions::DBOptions()
199199
advise_random_on_open(true),
200200
access_hint_on_compaction_start(NORMAL),
201201
use_adaptive_mutex(false),
202-
bytes_per_sync(0),
203-
allow_thread_local(true) {}
202+
allow_thread_local(true),
203+
bytes_per_sync(0) {}
204204

205205
DBOptions::DBOptions(const Options& options)
206206
: create_if_missing(options.create_if_missing),
@@ -243,8 +243,8 @@ DBOptions::DBOptions(const Options& options)
243243
advise_random_on_open(options.advise_random_on_open),
244244
access_hint_on_compaction_start(options.access_hint_on_compaction_start),
245245
use_adaptive_mutex(options.use_adaptive_mutex),
246-
bytes_per_sync(options.bytes_per_sync),
247-
allow_thread_local(options.allow_thread_local) {}
246+
allow_thread_local(options.allow_thread_local),
247+
bytes_per_sync(options.bytes_per_sync) {}
248248

249249
static const char* const access_hints[] = {
250250
"NONE", "NORMAL", "SEQUENTIAL", "WILLNEED"
@@ -308,6 +308,8 @@ void DBOptions::Dump(Logger* log) const {
308308
access_hints[access_hint_on_compaction_start]);
309309
Log(log, " Options.use_adaptive_mutex: %d",
310310
use_adaptive_mutex);
311+
Log(log, " Options.rate_limiter: %p",
312+
rate_limiter.get());
311313
Log(log, " Options.bytes_per_sync: %lu",
312314
(unsigned long)bytes_per_sync);
313315
} // DBOptions::Dump

0 commit comments

Comments
 (0)