@ -404,7 +404,7 @@ const Status DBImpl::CreateArchivalDirectory() {
}
void DBImpl : : PrintStatistics ( ) {
auto dbstats = options_ . statistics ;
auto dbstats = options_ . statistics . get ( ) ;
if ( dbstats ) {
Log ( options_ . info_log ,
" STATISTCS: \n %s " ,
@ -860,7 +860,7 @@ Status DBImpl::Recover(VersionEdit* edit, MemTable* external_table,
if ( versions_ - > LastSequence ( ) < max_sequence ) {
versions_ - > SetLastSequence ( max_sequence ) ;
}
SetTickerCount ( options_ . statistics , SEQUENCE_NUMBER ,
SetTickerCount ( options_ . statistics . get ( ) , SEQUENCE_NUMBER ,
versions_ - > LastSequence ( ) ) ;
}
}
@ -1297,7 +1297,7 @@ SequenceNumber DBImpl::GetLatestSequenceNumber() const {
Status DBImpl : : GetUpdatesSince ( SequenceNumber seq ,
unique_ptr < TransactionLogIterator > * iter ) {
RecordTick ( options_ . statistics , GET_UPDATES_SINCE_CALLS ) ;
RecordTick ( options_ . statistics . get ( ) , GET_UPDATES_SINCE_CALLS ) ;
if ( seq > versions_ - > LastSequence ( ) ) {
return Status : : IOError ( " Requested sequence not yet written in the db " ) ;
}
@ -1971,10 +1971,12 @@ Status DBImpl::FinishCompactionOutputFile(CompactionState* compact,
// Finish and check for file errors
if ( s . ok ( ) & & ! options_ . disableDataSync ) {
if ( options_ . use_fsync ) {
StopWatch sw ( env_ , options_ . statistics , COMPACTION_OUTFILE_SYNC_MICROS ) ;
StopWatch sw ( env_ , options_ . statistics . get ( ) ,
COMPACTION_OUTFILE_SYNC_MICROS ) ;
s = compact - > outfile - > Fsync ( ) ;
} else {
StopWatch sw ( env_ , options_ . statistics , COMPACTION_OUTFILE_SYNC_MICROS ) ;
StopWatch sw ( env_ , options_ . statistics . get ( ) ,
COMPACTION_OUTFILE_SYNC_MICROS ) ;
s = compact - > outfile - > Sync ( ) ;
}
}
@ -2212,7 +2214,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
ParseInternalKey ( key , & ikey ) ;
// no value associated with delete
value . clear ( ) ;
RecordTick ( options_ . statistics , COMPACTION_KEY_DROP_USER ) ;
RecordTick ( options_ . statistics . get ( ) , COMPACTION_KEY_DROP_USER ) ;
} else if ( value_changed ) {
value = compaction_filter_value ;
}
@ -2238,7 +2240,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
// TODO: why not > ?
assert ( last_sequence_for_key > = ikey . sequence ) ;
drop = true ; // (A)
RecordTick ( options_ . statistics , COMPACTION_KEY_DROP_NEWER_ENTRY ) ;
RecordTick ( options_ . statistics . get ( ) , COMPACTION_KEY_DROP_NEWER_ENTRY ) ;
} else if ( ikey . type = = kTypeDeletion & &
ikey . sequence < = earliest_snapshot & &
compact - > compaction - > IsBaseLevelForKey ( ikey . user_key ) ) {
@ -2250,7 +2252,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
// few iterations of this loop (by rule (A) above).
// Therefore this deletion marker is obsolete and can be dropped.
drop = true ;
RecordTick ( options_ . statistics , COMPACTION_KEY_DROP_OBSOLETE ) ;
RecordTick ( options_ . statistics . get ( ) , COMPACTION_KEY_DROP_OBSOLETE ) ;
} else if ( ikey . type = = kTypeMerge ) {
// We know the merge type entry is not hidden, otherwise we would
// have hit (A)
@ -2259,7 +2261,7 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
// logic could also be nicely re-used for memtable flush purge
// optimization in BuildTable.
merge . MergeUntil ( input . get ( ) , prev_snapshot , bottommost_level ,
options_ . statistics ) ;
options_ . statistics . get ( ) ) ;
current_entry_is_merging = true ;
if ( merge . IsSuccess ( ) ) {
// Successfully found Put/Delete/(end-of-key-range) while merging
@ -2412,8 +2414,8 @@ Status DBImpl::DoCompactionWork(CompactionState* compact,
CompactionStats stats ;
stats . micros = env_ - > NowMicros ( ) - start_micros - imm_micros ;
if ( options_ . statistics ) {
options_ . statistics - > measureTime ( COMPACTION_TIME , stats . micros ) ;
if ( options_ . statistics . get ( ) ) {
options_ . statistics . get ( ) - > measureTime ( COMPACTION_TIME , stats . micros ) ;
}
stats . files_in_leveln = compact - > compaction - > num_input_files ( 0 ) ;
stats . files_in_levelnp1 = compact - > compaction - > num_input_files ( 1 ) ;
@ -2554,7 +2556,7 @@ Status DBImpl::GetImpl(const ReadOptions& options,
bool * value_found ) {
Status s ;
StopWatch sw ( env_ , options_ . statistics , DB_GET ) ;
StopWatch sw ( env_ , options_ . statistics . get ( ) , DB_GET ) ;
SequenceNumber snapshot ;
mutex_ . Lock ( ) ;
if ( options . snapshot ! = nullptr ) {
@ -2605,8 +2607,8 @@ Status DBImpl::GetImpl(const ReadOptions& options,
LogFlush ( options_ . info_log ) ;
// Note, tickers are atomic now - no lock protection needed any more.
RecordTick ( options_ . statistics , NUMBER_KEYS_READ ) ;
RecordTick ( options_ . statistics , BYTES_READ , value - > size ( ) ) ;
RecordTick ( options_ . statistics . get ( ) , NUMBER_KEYS_READ ) ;
RecordTick ( options_ . statistics . get ( ) , BYTES_READ , value - > size ( ) ) ;
return s ;
}
@ -2614,7 +2616,7 @@ std::vector<Status> DBImpl::MultiGet(const ReadOptions& options,
const std : : vector < Slice > & keys ,
std : : vector < std : : string > * values ) {
StopWatch sw ( env_ , options_ . statistics , DB_MULTIGET ) ;
StopWatch sw ( env_ , options_ . statistics . get ( ) , DB_MULTIGET ) ;
SequenceNumber snapshot ;
mutex_ . Lock ( ) ;
if ( options . snapshot ! = nullptr ) {
@ -2683,9 +2685,9 @@ std::vector<Status> DBImpl::MultiGet(const ReadOptions& options,
mutex_ . Unlock ( ) ;
LogFlush ( options_ . info_log ) ;
RecordTick ( options_ . statistics , NUMBER_MULTIGET_CALLS ) ;
RecordTick ( options_ . statistics , NUMBER_MULTIGET_KEYS_READ , numKeys ) ;
RecordTick ( options_ . statistics , NUMBER_MULTIGET_BYTES_READ , bytesRead ) ;
RecordTick ( options_ . statistics . get ( ) , NUMBER_MULTIGET_CALLS ) ;
RecordTick ( options_ . statistics . get ( ) , NUMBER_MULTIGET_KEYS_READ , numKeys ) ;
RecordTick ( options_ . statistics . get ( ) , NUMBER_MULTIGET_BYTES_READ , bytesRead ) ;
return statList ;
}
@ -2760,7 +2762,7 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
w . disableWAL = options . disableWAL ;
w . done = false ;
StopWatch sw ( env_ , options_ . statistics , DB_WRITE ) ;
StopWatch sw ( env_ , options_ . statistics . get ( ) , DB_WRITE ) ;
MutexLock l ( & mutex_ ) ;
writers_ . push_back ( & w ) ;
while ( ! w . done & & & w ! = writers_ . front ( ) ) {
@ -2793,8 +2795,9 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
int my_batch_count = WriteBatchInternal : : Count ( updates ) ;
last_sequence + = my_batch_count ;
// Record statistics
RecordTick ( options_ . statistics , NUMBER_KEYS_WRITTEN , my_batch_count ) ;
RecordTick ( options_ . statistics ,
RecordTick ( options_ . statistics . get ( ) ,
NUMBER_KEYS_WRITTEN , my_batch_count ) ;
RecordTick ( options_ . statistics . get ( ) ,
BYTES_WRITTEN ,
WriteBatchInternal : : ByteSize ( updates ) ) ;
if ( options . disableWAL ) {
@ -2808,10 +2811,10 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
BumpPerfTime ( & perf_context . wal_write_time , & timer ) ;
if ( status . ok ( ) & & options . sync ) {
if ( options_ . use_fsync ) {
StopWatch ( env_ , options_ . statistics , WAL_FILE_SYNC_MICROS ) ;
StopWatch ( env_ , options_ . statistics . get ( ) , WAL_FILE_SYNC_MICROS ) ;
status = log_ - > file ( ) - > Fsync ( ) ;
} else {
StopWatch ( env_ , options_ . statistics , WAL_FILE_SYNC_MICROS ) ;
StopWatch ( env_ , options_ . statistics . get ( ) , WAL_FILE_SYNC_MICROS ) ;
status = log_ - > file ( ) - > Sync ( ) ;
}
}
@ -2826,7 +2829,8 @@ Status DBImpl::Write(const WriteOptions& options, WriteBatch* my_batch) {
// have succeeded in memtable but Status reports error for all writes.
throw std : : runtime_error ( " In memory WriteBatch corruption! " ) ;
}
SetTickerCount ( options_ . statistics , SEQUENCE_NUMBER , last_sequence ) ;
SetTickerCount ( options_ . statistics . get ( ) ,
SEQUENCE_NUMBER , last_sequence ) ;
}
LogFlush ( options_ . info_log ) ;
mutex_ . Lock ( ) ;
@ -2975,7 +2979,7 @@ Status DBImpl::MakeRoomForWrite(bool force) {
mutex_ . Unlock ( ) ;
uint64_t delayed ;
{
StopWatch sw ( env_ , options_ . statistics , STALL_L0_SLOWDOWN_COUNT ) ;
StopWatch sw ( env_ , options_ . statistics . get ( ) , STALL_L0_SLOWDOWN_COUNT ) ;
env_ - > SleepForMicroseconds (
SlowdownAmount ( versions_ - > NumLevelFiles ( 0 ) ,
options_ . level0_slowdown_writes_trigger ,
@ -2983,7 +2987,7 @@ Status DBImpl::MakeRoomForWrite(bool force) {
) ;
delayed = sw . ElapsedMicros ( ) ;
}
RecordTick ( options_ . statistics , STALL_L0_SLOWDOWN_MICROS , delayed ) ;
RecordTick ( options_ . statistics . get ( ) , STALL_L0_SLOWDOWN_MICROS , delayed ) ;
stall_level0_slowdown_ + = delayed ;
stall_level0_slowdown_count_ + + ;
allow_delay = false ; // Do not delay a single write more than once
@ -3003,12 +3007,13 @@ Status DBImpl::MakeRoomForWrite(bool force) {
Log ( options_ . info_log , " wait for memtable compaction... \n " ) ;
uint64_t stall ;
{
StopWatch sw ( env_ , options_ . statistics ,
StopWatch sw ( env_ , options_ . statistics . get ( ) ,
STALL_MEMTABLE_COMPACTION_COUNT ) ;
bg_cv_ . Wait ( ) ;
stall = sw . ElapsedMicros ( ) ;
}
RecordTick ( options_ . statistics , STALL_MEMTABLE_COMPACTION_MICROS , stall ) ;
RecordTick ( options_ . statistics . get ( ) ,
STALL_MEMTABLE_COMPACTION_MICROS , stall ) ;
stall_memtable_compaction_ + = stall ;
stall_memtable_compaction_count_ + + ;
} else if ( versions_ - > NumLevelFiles ( 0 ) > =
@ -3018,11 +3023,12 @@ Status DBImpl::MakeRoomForWrite(bool force) {
Log ( options_ . info_log , " wait for fewer level0 files... \n " ) ;
uint64_t stall ;
{
StopWatch sw ( env_ , options_ . statistics , STALL_L0_NUM_FILES_COUNT ) ;
StopWatch sw ( env_ , options_ . statistics . get ( ) ,
STALL_L0_NUM_FILES_COUNT ) ;
bg_cv_ . Wait ( ) ;
stall = sw . ElapsedMicros ( ) ;
}
RecordTick ( options_ . statistics , STALL_L0_NUM_FILES_MICROS , stall ) ;
RecordTick ( options_ . statistics . get ( ) , STALL_L0_NUM_FILES_MICROS , stall ) ;
stall_level0_num_files_ + = stall ;
stall_level0_num_files_count_ + + ;
} else if (
@ -3034,7 +3040,8 @@ Status DBImpl::MakeRoomForWrite(bool force) {
mutex_ . Unlock ( ) ;
uint64_t delayed ;
{
StopWatch sw ( env_ , options_ . statistics , HARD_RATE_LIMIT_DELAY_COUNT ) ;
StopWatch sw ( env_ , options_ . statistics . get ( ) ,
HARD_RATE_LIMIT_DELAY_COUNT ) ;
env_ - > SleepForMicroseconds ( 1000 ) ;
delayed = sw . ElapsedMicros ( ) ;
}
@ -3043,7 +3050,8 @@ Status DBImpl::MakeRoomForWrite(bool force) {
// Make sure the following value doesn't round to zero.
uint64_t rate_limit = std : : max ( ( delayed / 1000 ) , ( uint64_t ) 1 ) ;
rate_limit_delay_millis + = rate_limit ;
RecordTick ( options_ . statistics , RATE_LIMIT_DELAY_MILLIS , rate_limit ) ;
RecordTick ( options_ . statistics . get ( ) ,
RATE_LIMIT_DELAY_MILLIS , rate_limit ) ;
if ( options_ . rate_limit_delay_max_milliseconds > 0 & &
rate_limit_delay_millis > =
( unsigned ) options_ . rate_limit_delay_max_milliseconds ) {
@ -3058,7 +3066,8 @@ Status DBImpl::MakeRoomForWrite(bool force) {
// TODO: add statistics
mutex_ . Unlock ( ) ;
{
StopWatch sw ( env_ , options_ . statistics , SOFT_RATE_LIMIT_DELAY_COUNT ) ;
StopWatch sw ( env_ , options_ . statistics . get ( ) ,
SOFT_RATE_LIMIT_DELAY_COUNT ) ;
env_ - > SleepForMicroseconds ( SlowdownAmount (
score ,
options_ . soft_rate_limit ,