@@ -404,7 +404,7 @@ const Status DBImpl::CreateArchivalDirectory() {
404
404
}
405
405
406
406
void DBImpl::PrintStatistics () {
407
- auto dbstats = options_.statistics ;
407
+ auto dbstats = options_.statistics . get () ;
408
408
if (dbstats) {
409
409
Log (options_.info_log ,
410
410
" STATISTCS:\n %s" ,
@@ -860,7 +860,7 @@ Status DBImpl::Recover(VersionEdit* edit, MemTable* external_table,
860
860
if (versions_->LastSequence () < max_sequence) {
861
861
versions_->SetLastSequence (max_sequence);
862
862
}
863
- SetTickerCount (options_.statistics , SEQUENCE_NUMBER,
863
+ SetTickerCount (options_.statistics . get () , SEQUENCE_NUMBER,
864
864
versions_->LastSequence ());
865
865
}
866
866
}
@@ -1297,7 +1297,7 @@ SequenceNumber DBImpl::GetLatestSequenceNumber() const {
1297
1297
Status DBImpl::GetUpdatesSince (SequenceNumber seq,
1298
1298
unique_ptr<TransactionLogIterator>* iter) {
1299
1299
1300
- RecordTick (options_.statistics , GET_UPDATES_SINCE_CALLS);
1300
+ RecordTick (options_.statistics . get () , GET_UPDATES_SINCE_CALLS);
1301
1301
if (seq > versions_->LastSequence ()) {
1302
1302
return Status::IOError (" Requested sequence not yet written in the db" );
1303
1303
}
@@ -1971,10 +1971,12 @@ Status DBImpl::FinishCompactionOutputFile(CompactionState* compact,
1971
1971
// Finish and check for file errors
1972
1972
if (s.ok () && !options_.disableDataSync ) {
1973
1973
if (options_.use_fsync ) {
1974
- StopWatch sw (env_, options_.statistics , COMPACTION_OUTFILE_SYNC_MICROS);
1974
+ StopWatch sw (env_, options_.statistics .get (),
1975
+ COMPACTION_OUTFILE_SYNC_MICROS);
1975
1976
s = compact->outfile ->Fsync ();
1976
1977
} else {
1977
- StopWatch sw (env_, options_.statistics , COMPACTION_OUTFILE_SYNC_MICROS);
1978
+ StopWatch sw (env_, options_.statistics .get (),
1979
+ COMPACTION_OUTFILE_SYNC_MICROS);
1978
1980
s = compact->outfile ->Sync ();
1979
1981
}
1980
1982
}
@@ -2212,7 +2214,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
2212
2214
ParseInternalKey (key, &ikey);
2213
2215
// no value associated with delete
2214
2216
value.clear ();
2215
- RecordTick (options_.statistics , COMPACTION_KEY_DROP_USER);
2217
+ RecordTick (options_.statistics . get () , COMPACTION_KEY_DROP_USER);
2216
2218
} else if (value_changed) {
2217
2219
value = compaction_filter_value;
2218
2220
}
@@ -2238,7 +2240,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
2238
2240
// TODO: why not > ?
2239
2241
assert (last_sequence_for_key >= ikey.sequence );
2240
2242
drop = true ; // (A)
2241
- RecordTick (options_.statistics , COMPACTION_KEY_DROP_NEWER_ENTRY);
2243
+ RecordTick (options_.statistics . get () , COMPACTION_KEY_DROP_NEWER_ENTRY);
2242
2244
} else if (ikey.type == kTypeDeletion &&
2243
2245
ikey.sequence <= earliest_snapshot &&
2244
2246
compact->compaction ->IsBaseLevelForKey (ikey.user_key )) {
@@ -2250,7 +2252,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
2250
2252
// few iterations of this loop (by rule (A) above).
2251
2253
// Therefore this deletion marker is obsolete and can be dropped.
2252
2254
drop = true ;
2253
- RecordTick (options_.statistics , COMPACTION_KEY_DROP_OBSOLETE);
2255
+ RecordTick (options_.statistics . get () , COMPACTION_KEY_DROP_OBSOLETE);
2254
2256
} else if (ikey.type == kTypeMerge ) {
2255
2257
// We know the merge type entry is not hidden, otherwise we would
2256
2258
// have hit (A)
@@ -2259,7 +2261,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
2259
2261
// logic could also be nicely re-used for memtable flush purge
2260
2262
// optimization in BuildTable.
2261
2263
merge.MergeUntil (input.get (), prev_snapshot, bottommost_level,
2262
- options_.statistics );
2264
+ options_.statistics . get () );
2263
2265
current_entry_is_merging = true ;
2264
2266
if (merge.IsSuccess ()) {
2265
2267
// Successfully found Put/Delete/(end-of-key-range) while merging
@@ -2412,8 +2414,8 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
2412
2414
2413
2415
CompactionStats stats;
2414
2416
stats.micros = env_->NowMicros () - start_micros - imm_micros;
2415
- if (options_.statistics ) {
2416
- options_.statistics ->measureTime (COMPACTION_TIME, stats.micros );
2417
+ if (options_.statistics . get () ) {
2418
+ options_.statistics . get () ->measureTime (COMPACTION_TIME, stats.micros );
2417
2419
}
2418
2420
stats.files_in_leveln = compact->compaction ->num_input_files (0 );
2419
2421
stats.files_in_levelnp1 = compact->compaction ->num_input_files (1 );
@@ -2554,7 +2556,7 @@ Status DBImpl::GetImpl(const ReadOptions& options,
2554
2556
bool * value_found) {
2555
2557
Status s;
2556
2558
2557
- StopWatch sw (env_, options_.statistics , DB_GET);
2559
+ StopWatch sw (env_, options_.statistics . get () , DB_GET);
2558
2560
SequenceNumber snapshot;
2559
2561
mutex_.Lock ();
2560
2562
if (options.snapshot != nullptr ) {
@@ -2605,16 +2607,16 @@ Status DBImpl::GetImpl(const ReadOptions& options,
2605
2607
2606
2608
LogFlush (options_.info_log );
2607
2609
// Note, tickers are atomic now - no lock protection needed any more.
2608
- RecordTick (options_.statistics , NUMBER_KEYS_READ);
2609
- RecordTick (options_.statistics , BYTES_READ, value->size ());
2610
+ RecordTick (options_.statistics . get () , NUMBER_KEYS_READ);
2611
+ RecordTick (options_.statistics . get () , BYTES_READ, value->size ());
2610
2612
return s;
2611
2613
}
2612
2614
2613
2615
std::vector<Status> DBImpl::MultiGet (const ReadOptions& options,
2614
2616
const std::vector<Slice>& keys,
2615
2617
std::vector<std::string>* values) {
2616
2618
2617
- StopWatch sw (env_, options_.statistics , DB_MULTIGET);
2619
+ StopWatch sw (env_, options_.statistics . get () , DB_MULTIGET);
2618
2620
SequenceNumber snapshot;
2619
2621
mutex_.Lock ();
2620
2622
if (options.snapshot != nullptr ) {
@@ -2683,9 +2685,9 @@ std::vector<Status> DBImpl::MultiGet(const ReadOptions& options,
2683
2685
mutex_.Unlock ();
2684
2686
2685
2687
LogFlush (options_.info_log );
2686
- RecordTick (options_.statistics , NUMBER_MULTIGET_CALLS);
2687
- RecordTick (options_.statistics , NUMBER_MULTIGET_KEYS_READ, numKeys);
2688
- RecordTick (options_.statistics , NUMBER_MULTIGET_BYTES_READ, bytesRead);
2688
+ RecordTick (options_.statistics . get () , NUMBER_MULTIGET_CALLS);
2689
+ RecordTick (options_.statistics . get () , NUMBER_MULTIGET_KEYS_READ, numKeys);
2690
+ RecordTick (options_.statistics . get () , NUMBER_MULTIGET_BYTES_READ, bytesRead);
2689
2691
2690
2692
return statList;
2691
2693
}
@@ -2760,7 +2762,7 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
2760
2762
w.disableWAL = options.disableWAL ;
2761
2763
w.done = false ;
2762
2764
2763
- StopWatch sw (env_, options_.statistics , DB_WRITE);
2765
+ StopWatch sw (env_, options_.statistics . get () , DB_WRITE);
2764
2766
MutexLock l (&mutex_);
2765
2767
writers_.push_back (&w);
2766
2768
while (!w.done && &w != writers_.front ()) {
@@ -2793,8 +2795,9 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
2793
2795
int my_batch_count = WriteBatchInternal::Count (updates);
2794
2796
last_sequence += my_batch_count;
2795
2797
// Record statistics
2796
- RecordTick (options_.statistics , NUMBER_KEYS_WRITTEN, my_batch_count);
2797
- RecordTick (options_.statistics ,
2798
+ RecordTick (options_.statistics .get (),
2799
+ NUMBER_KEYS_WRITTEN, my_batch_count);
2800
+ RecordTick (options_.statistics .get (),
2798
2801
BYTES_WRITTEN,
2799
2802
WriteBatchInternal::ByteSize (updates));
2800
2803
if (options.disableWAL ) {
@@ -2808,10 +2811,10 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
2808
2811
BumpPerfTime (&perf_context.wal_write_time , &timer);
2809
2812
if (status.ok () && options.sync ) {
2810
2813
if (options_.use_fsync ) {
2811
- StopWatch (env_, options_.statistics , WAL_FILE_SYNC_MICROS);
2814
+ StopWatch (env_, options_.statistics . get () , WAL_FILE_SYNC_MICROS);
2812
2815
status = log_->file ()->Fsync ();
2813
2816
} else {
2814
- StopWatch (env_, options_.statistics , WAL_FILE_SYNC_MICROS);
2817
+ StopWatch (env_, options_.statistics . get () , WAL_FILE_SYNC_MICROS);
2815
2818
status = log_->file ()->Sync ();
2816
2819
}
2817
2820
}
@@ -2826,7 +2829,8 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
2826
2829
// have succeeded in memtable but Status reports error for all writes.
2827
2830
throw std::runtime_error (" In memory WriteBatch corruption!" );
2828
2831
}
2829
- SetTickerCount (options_.statistics , SEQUENCE_NUMBER, last_sequence);
2832
+ SetTickerCount (options_.statistics .get (),
2833
+ SEQUENCE_NUMBER, last_sequence);
2830
2834
}
2831
2835
LogFlush (options_.info_log );
2832
2836
mutex_.Lock ();
@@ -2975,15 +2979,15 @@ Status DBImpl::MakeRoomForWrite(bool force) {
2975
2979
mutex_.Unlock ();
2976
2980
uint64_t delayed;
2977
2981
{
2978
- StopWatch sw (env_, options_.statistics , STALL_L0_SLOWDOWN_COUNT);
2982
+ StopWatch sw (env_, options_.statistics . get () , STALL_L0_SLOWDOWN_COUNT);
2979
2983
env_->SleepForMicroseconds (
2980
2984
SlowdownAmount (versions_->NumLevelFiles (0 ),
2981
2985
options_.level0_slowdown_writes_trigger ,
2982
2986
options_.level0_stop_writes_trigger )
2983
2987
);
2984
2988
delayed = sw.ElapsedMicros ();
2985
2989
}
2986
- RecordTick (options_.statistics , STALL_L0_SLOWDOWN_MICROS, delayed);
2990
+ RecordTick (options_.statistics . get () , STALL_L0_SLOWDOWN_MICROS, delayed);
2987
2991
stall_level0_slowdown_ += delayed;
2988
2992
stall_level0_slowdown_count_++;
2989
2993
allow_delay = false ; // Do not delay a single write more than once
@@ -3003,12 +3007,13 @@ Status DBImpl::MakeRoomForWrite(bool force) {
3003
3007
Log (options_.info_log , " wait for memtable compaction...\n " );
3004
3008
uint64_t stall;
3005
3009
{
3006
- StopWatch sw (env_, options_.statistics ,
3010
+ StopWatch sw (env_, options_.statistics . get () ,
3007
3011
STALL_MEMTABLE_COMPACTION_COUNT);
3008
3012
bg_cv_.Wait ();
3009
3013
stall = sw.ElapsedMicros ();
3010
3014
}
3011
- RecordTick (options_.statistics , STALL_MEMTABLE_COMPACTION_MICROS, stall);
3015
+ RecordTick (options_.statistics .get (),
3016
+ STALL_MEMTABLE_COMPACTION_MICROS, stall);
3012
3017
stall_memtable_compaction_ += stall;
3013
3018
stall_memtable_compaction_count_++;
3014
3019
} else if (versions_->NumLevelFiles (0 ) >=
@@ -3018,11 +3023,12 @@ Status DBImpl::MakeRoomForWrite(bool force) {
3018
3023
Log (options_.info_log , " wait for fewer level0 files...\n " );
3019
3024
uint64_t stall;
3020
3025
{
3021
- StopWatch sw (env_, options_.statistics , STALL_L0_NUM_FILES_COUNT);
3026
+ StopWatch sw (env_, options_.statistics .get (),
3027
+ STALL_L0_NUM_FILES_COUNT);
3022
3028
bg_cv_.Wait ();
3023
3029
stall = sw.ElapsedMicros ();
3024
3030
}
3025
- RecordTick (options_.statistics , STALL_L0_NUM_FILES_MICROS, stall);
3031
+ RecordTick (options_.statistics . get () , STALL_L0_NUM_FILES_MICROS, stall);
3026
3032
stall_level0_num_files_ += stall;
3027
3033
stall_level0_num_files_count_++;
3028
3034
} else if (
@@ -3034,7 +3040,8 @@ Status DBImpl::MakeRoomForWrite(bool force) {
3034
3040
mutex_.Unlock ();
3035
3041
uint64_t delayed;
3036
3042
{
3037
- StopWatch sw (env_, options_.statistics , HARD_RATE_LIMIT_DELAY_COUNT);
3043
+ StopWatch sw (env_, options_.statistics .get (),
3044
+ HARD_RATE_LIMIT_DELAY_COUNT);
3038
3045
env_->SleepForMicroseconds (1000 );
3039
3046
delayed = sw.ElapsedMicros ();
3040
3047
}
@@ -3043,7 +3050,8 @@ Status DBImpl::MakeRoomForWrite(bool force) {
3043
3050
// Make sure the following value doesn't round to zero.
3044
3051
uint64_t rate_limit = std::max ((delayed / 1000 ), (uint64_t ) 1 );
3045
3052
rate_limit_delay_millis += rate_limit;
3046
- RecordTick (options_.statistics , RATE_LIMIT_DELAY_MILLIS, rate_limit);
3053
+ RecordTick (options_.statistics .get (),
3054
+ RATE_LIMIT_DELAY_MILLIS, rate_limit);
3047
3055
if (options_.rate_limit_delay_max_milliseconds > 0 &&
3048
3056
rate_limit_delay_millis >=
3049
3057
(unsigned )options_.rate_limit_delay_max_milliseconds ) {
@@ -3058,7 +3066,8 @@ Status DBImpl::MakeRoomForWrite(bool force) {
3058
3066
// TODO: add statistics
3059
3067
mutex_.Unlock ();
3060
3068
{
3061
- StopWatch sw (env_, options_.statistics , SOFT_RATE_LIMIT_DELAY_COUNT);
3069
+ StopWatch sw (env_, options_.statistics .get (),
3070
+ SOFT_RATE_LIMIT_DELAY_COUNT);
3062
3071
env_->SleepForMicroseconds (SlowdownAmount (
3063
3072
score,
3064
3073
options_.soft_rate_limit ,
0 commit comments