dynamic setting of stats_dump_period_sec through SetDBOption()

Summary:
Resolved the following issue: https://github.com/facebook/rocksdb/issues/1930
Closes https://github.com/facebook/rocksdb/pull/2004

Differential Revision: D4736764

Pulled By: yiwu-arbug

fbshipit-source-id: 64fe0b7
main
Raza Hussain 8 years ago committed by Facebook Github Bot
parent 93c68b642e
commit 6908e24b56
  1. 2
      HISTORY.md
  2. 9
      db/db_impl.cc
  3. 16
      db/db_options_test.cc
  4. 4
      java/src/main/java/org/rocksdb/DBOptionsInterface.java
  5. 11
      util/db_options.cc
  6. 2
      util/db_options.h
  7. 2
      util/options_helper.cc
  8. 3
      util/options_helper.h

@ -1,5 +1,7 @@
# Rocksdb Change Log # Rocksdb Change Log
## Unreleased ## Unreleased
### Public API Change
* Support dynamically change `stats_dump_period_sec` option via SetDBOptions().
## 5.3.0 (03/08/2017) ## 5.3.0 (03/08/2017)
### Public API Change ### Public API Change

@ -618,12 +618,15 @@ static void DumpMallocStats(std::string* stats) {
#endif // !ROCKSDB_LITE #endif // !ROCKSDB_LITE
void DBImpl::MaybeDumpStats() { void DBImpl::MaybeDumpStats() {
if (immutable_db_options_.stats_dump_period_sec == 0) return; mutex_.Lock();
unsigned int stats_dump_period_sec =
mutable_db_options_.stats_dump_period_sec;
mutex_.Unlock();
if (stats_dump_period_sec == 0) return;
const uint64_t now_micros = env_->NowMicros(); const uint64_t now_micros = env_->NowMicros();
if (last_stats_dump_time_microsec_ + if (last_stats_dump_time_microsec_ + stats_dump_period_sec * 1000000 <=
immutable_db_options_.stats_dump_period_sec * 1000000 <=
now_micros) { now_micros) {
// Multiple threads could race in here simultaneously. // Multiple threads could race in here simultaneously.
// However, the last one will update last_stats_dump_time_microsec_ // However, the last one will update last_stats_dump_time_microsec_

@ -326,6 +326,22 @@ TEST_F(DBOptionsTest, MaxTotalWalSizeChange) {
} }
} }
TEST_F(DBOptionsTest, SetStatsDumpPeriodSec) {
Options options;
options.create_if_missing = true;
options.stats_dump_period_sec = 5;
options.env = env_;
Reopen(options);
ASSERT_EQ(5, dbfull()->GetDBOptions().stats_dump_period_sec);
for (int i = 0; i < 20; i++) {
int num = rand() % 5000 + 1;
ASSERT_OK(dbfull()->SetDBOptions(
{{"stats_dump_period_sec", std::to_string(num)}}));
ASSERT_EQ(num, dbfull()->GetDBOptions().stats_dump_period_sec);
}
}
static void assert_candidate_files_empty(DBImpl* dbfull, const bool empty) { static void assert_candidate_files_empty(DBImpl* dbfull, const bool empty) {
dbfull->TEST_LockMutex(); dbfull->TEST_LockMutex();
JobContext job_context(0); JobContext job_context(0);

@ -715,7 +715,7 @@ public interface DBOptionsInterface {
/** /**
* if not zero, dump rocksdb.stats to LOG every stats_dump_period_sec * if not zero, dump rocksdb.stats to LOG every stats_dump_period_sec
* Default: 3600 (1 hour) * Default: 600 (10 minutes)
* *
* @param statsDumpPeriodSec time interval in seconds. * @param statsDumpPeriodSec time interval in seconds.
* @return the instance of the current Object. * @return the instance of the current Object.
@ -724,7 +724,7 @@ public interface DBOptionsInterface {
/** /**
* If not zero, dump rocksdb.stats to LOG every stats_dump_period_sec * If not zero, dump rocksdb.stats to LOG every stats_dump_period_sec
* Default: 3600 (1 hour) * Default: 600 (10 minutes)
* *
* @return time interval in seconds. * @return time interval in seconds.
*/ */

@ -56,7 +56,6 @@ ImmutableDBOptions::ImmutableDBOptions(const DBOptions& options)
use_direct_writes(options.use_direct_writes), use_direct_writes(options.use_direct_writes),
allow_fallocate(options.allow_fallocate), allow_fallocate(options.allow_fallocate),
is_fd_close_on_exec(options.is_fd_close_on_exec), is_fd_close_on_exec(options.is_fd_close_on_exec),
stats_dump_period_sec(options.stats_dump_period_sec),
advise_random_on_open(options.advise_random_on_open), advise_random_on_open(options.advise_random_on_open),
db_write_buffer_size(options.db_write_buffer_size), db_write_buffer_size(options.db_write_buffer_size),
write_buffer_manager(options.write_buffer_manager), write_buffer_manager(options.write_buffer_manager),
@ -154,8 +153,6 @@ void ImmutableDBOptions::Dump(Logger* log) const {
manifest_preallocation_size); manifest_preallocation_size);
ROCKS_LOG_HEADER(log, " Options.is_fd_close_on_exec: %d", ROCKS_LOG_HEADER(log, " Options.is_fd_close_on_exec: %d",
is_fd_close_on_exec); is_fd_close_on_exec);
ROCKS_LOG_HEADER(log, " Options.stats_dump_period_sec: %u",
stats_dump_period_sec);
ROCKS_LOG_HEADER(log, " Options.advise_random_on_open: %d", ROCKS_LOG_HEADER(log, " Options.advise_random_on_open: %d",
advise_random_on_open); advise_random_on_open);
ROCKS_LOG_HEADER( ROCKS_LOG_HEADER(
@ -223,7 +220,8 @@ MutableDBOptions::MutableDBOptions()
avoid_flush_during_shutdown(false), avoid_flush_during_shutdown(false),
delayed_write_rate(2 * 1024U * 1024U), delayed_write_rate(2 * 1024U * 1024U),
max_total_wal_size(0), max_total_wal_size(0),
delete_obsolete_files_period_micros(6ULL * 60 * 60 * 1000000) {} delete_obsolete_files_period_micros(6ULL * 60 * 60 * 1000000),
stats_dump_period_sec(600) {}
MutableDBOptions::MutableDBOptions(const DBOptions& options) MutableDBOptions::MutableDBOptions(const DBOptions& options)
: base_background_compactions(options.base_background_compactions), : base_background_compactions(options.base_background_compactions),
@ -232,7 +230,8 @@ MutableDBOptions::MutableDBOptions(const DBOptions& options)
delayed_write_rate(options.delayed_write_rate), delayed_write_rate(options.delayed_write_rate),
max_total_wal_size(options.max_total_wal_size), max_total_wal_size(options.max_total_wal_size),
delete_obsolete_files_period_micros( delete_obsolete_files_period_micros(
options.delete_obsolete_files_period_micros) {} options.delete_obsolete_files_period_micros),
stats_dump_period_sec(options.stats_dump_period_sec) {}
void MutableDBOptions::Dump(Logger* log) const { void MutableDBOptions::Dump(Logger* log) const {
ROCKS_LOG_HEADER(log, " Options.base_background_compactions: %d", ROCKS_LOG_HEADER(log, " Options.base_background_compactions: %d",
@ -248,6 +247,8 @@ void MutableDBOptions::Dump(Logger* log) const {
ROCKS_LOG_HEADER( ROCKS_LOG_HEADER(
log, " Options.delete_obsolete_files_period_micros: %" PRIu64, log, " Options.delete_obsolete_files_period_micros: %" PRIu64,
delete_obsolete_files_period_micros); delete_obsolete_files_period_micros);
ROCKS_LOG_HEADER(log, " Options.stats_dump_period_sec: %u",
stats_dump_period_sec);
} }
} // namespace rocksdb } // namespace rocksdb

@ -51,7 +51,6 @@ struct ImmutableDBOptions {
bool use_direct_writes; bool use_direct_writes;
bool allow_fallocate; bool allow_fallocate;
bool is_fd_close_on_exec; bool is_fd_close_on_exec;
unsigned int stats_dump_period_sec;
bool advise_random_on_open; bool advise_random_on_open;
size_t db_write_buffer_size; size_t db_write_buffer_size;
std::shared_ptr<WriteBufferManager> write_buffer_manager; std::shared_ptr<WriteBufferManager> write_buffer_manager;
@ -94,6 +93,7 @@ struct MutableDBOptions {
uint64_t delayed_write_rate; uint64_t delayed_write_rate;
uint64_t max_total_wal_size; uint64_t max_total_wal_size;
uint64_t delete_obsolete_files_period_micros; uint64_t delete_obsolete_files_period_micros;
unsigned int stats_dump_period_sec;
}; };
} // namespace rocksdb } // namespace rocksdb

@ -76,7 +76,7 @@ DBOptions BuildDBOptions(const ImmutableDBOptions& immutable_db_options,
options.use_direct_writes = immutable_db_options.use_direct_writes; options.use_direct_writes = immutable_db_options.use_direct_writes;
options.allow_fallocate = immutable_db_options.allow_fallocate; options.allow_fallocate = immutable_db_options.allow_fallocate;
options.is_fd_close_on_exec = immutable_db_options.is_fd_close_on_exec; options.is_fd_close_on_exec = immutable_db_options.is_fd_close_on_exec;
options.stats_dump_period_sec = immutable_db_options.stats_dump_period_sec; options.stats_dump_period_sec = mutable_db_options.stats_dump_period_sec;
options.advise_random_on_open = immutable_db_options.advise_random_on_open; options.advise_random_on_open = immutable_db_options.advise_random_on_open;
options.db_write_buffer_size = immutable_db_options.db_write_buffer_size; options.db_write_buffer_size = immutable_db_options.db_write_buffer_size;
options.write_buffer_manager = immutable_db_options.write_buffer_manager; options.write_buffer_manager = immutable_db_options.write_buffer_manager;

@ -330,7 +330,8 @@ static std::unordered_map<std::string, OptionTypeInfo> db_options_type_info = {
OptionVerificationType::kNormal, false, 0}}, OptionVerificationType::kNormal, false, 0}},
{"stats_dump_period_sec", {"stats_dump_period_sec",
{offsetof(struct DBOptions, stats_dump_period_sec), OptionType::kUInt, {offsetof(struct DBOptions, stats_dump_period_sec), OptionType::kUInt,
OptionVerificationType::kNormal, false, 0}}, OptionVerificationType::kNormal, true,
offsetof(struct MutableDBOptions, stats_dump_period_sec)}},
{"fail_if_options_file_error", {"fail_if_options_file_error",
{offsetof(struct DBOptions, fail_if_options_file_error), {offsetof(struct DBOptions, fail_if_options_file_error),
OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}}, OptionType::kBoolean, OptionVerificationType::kNormal, false, 0}},

Loading…
Cancel
Save