|
|
@ -1,4 +1,3 @@ |
|
|
|
|
|
|
|
|
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
@ -14,15 +13,41 @@ |
|
|
|
|
|
|
|
|
|
|
|
namespace rocksdb { |
|
|
|
namespace rocksdb { |
|
|
|
|
|
|
|
|
|
|
|
bool InternalStats::GetProperty(const Slice& property, std::string* value, |
|
|
|
DBPropertyType GetPropertyType(const Slice& property) { |
|
|
|
ColumnFamilyData* cfd) { |
|
|
|
|
|
|
|
Slice in = property; |
|
|
|
Slice in = property; |
|
|
|
Slice prefix("rocksdb."); |
|
|
|
Slice prefix("rocksdb."); |
|
|
|
if (!in.starts_with(prefix)) return false; |
|
|
|
if (!in.starts_with(prefix)) return kUnknown; |
|
|
|
in.remove_prefix(prefix.size()); |
|
|
|
in.remove_prefix(prefix.size()); |
|
|
|
|
|
|
|
|
|
|
|
if (in.starts_with("num-files-at-level")) { |
|
|
|
if (in.starts_with("num-files-at-level")) { |
|
|
|
in.remove_prefix(strlen("num-files-at-level")); |
|
|
|
return kNumFilesAtLevel; |
|
|
|
|
|
|
|
} else if (in == "levelstats") { |
|
|
|
|
|
|
|
return kLevelStats; |
|
|
|
|
|
|
|
} else if (in == "stats") { |
|
|
|
|
|
|
|
return kStats; |
|
|
|
|
|
|
|
} else if (in == "sstables") { |
|
|
|
|
|
|
|
return kSsTables; |
|
|
|
|
|
|
|
} else if (in == "num-immutable-mem-table") { |
|
|
|
|
|
|
|
return kNumImmutableMemTable; |
|
|
|
|
|
|
|
} else if (in == "mem-table-flush-pending") { |
|
|
|
|
|
|
|
return kMemtableFlushPending; |
|
|
|
|
|
|
|
} else if (in == "compaction-pending") { |
|
|
|
|
|
|
|
return kCompactionPending; |
|
|
|
|
|
|
|
} else if (in == "background-errors") { |
|
|
|
|
|
|
|
return kBackgroundErrors; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return kUnknown; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InternalStats::GetProperty(DBPropertyType property_type, |
|
|
|
|
|
|
|
const Slice& property, std::string* value, |
|
|
|
|
|
|
|
ColumnFamilyData* cfd) { |
|
|
|
|
|
|
|
Version* current = cfd->current(); |
|
|
|
|
|
|
|
Slice in = property; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (property_type) { |
|
|
|
|
|
|
|
case kNumFilesAtLevel: { |
|
|
|
|
|
|
|
in.remove_prefix(strlen("rocksdb.num-files-at-level")); |
|
|
|
uint64_t level; |
|
|
|
uint64_t level; |
|
|
|
bool ok = ConsumeDecimalNumber(&in, &level) && in.empty(); |
|
|
|
bool ok = ConsumeDecimalNumber(&in, &level) && in.empty(); |
|
|
|
if (!ok || (int)level >= number_levels_) { |
|
|
|
if (!ok || (int)level >= number_levels_) { |
|
|
@ -30,11 +55,12 @@ bool InternalStats::GetProperty(const Slice& property, std::string* value, |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
char buf[100]; |
|
|
|
char buf[100]; |
|
|
|
snprintf(buf, sizeof(buf), "%d", |
|
|
|
snprintf(buf, sizeof(buf), "%d", |
|
|
|
cfd->current()->NumLevelFiles(static_cast<int>(level))); |
|
|
|
current->NumLevelFiles(static_cast<int>(level))); |
|
|
|
*value = buf; |
|
|
|
*value = buf; |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (in == "levelstats") { |
|
|
|
} |
|
|
|
|
|
|
|
case kLevelStats: { |
|
|
|
char buf[1000]; |
|
|
|
char buf[1000]; |
|
|
|
snprintf(buf, sizeof(buf), |
|
|
|
snprintf(buf, sizeof(buf), |
|
|
|
"Level Files Size(MB)\n" |
|
|
|
"Level Files Size(MB)\n" |
|
|
@ -43,13 +69,13 @@ bool InternalStats::GetProperty(const Slice& property, std::string* value, |
|
|
|
|
|
|
|
|
|
|
|
for (int level = 0; level < number_levels_; level++) { |
|
|
|
for (int level = 0; level < number_levels_; level++) { |
|
|
|
snprintf(buf, sizeof(buf), "%3d %8d %8.0f\n", level, |
|
|
|
snprintf(buf, sizeof(buf), "%3d %8d %8.0f\n", level, |
|
|
|
cfd->current()->NumLevelFiles(level), |
|
|
|
current->NumLevelFiles(level), |
|
|
|
cfd->current()->NumLevelBytes(level) / 1048576.0); |
|
|
|
current->NumLevelBytes(level) / 1048576.0); |
|
|
|
value->append(buf); |
|
|
|
value->append(buf); |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} else if (in == "stats") { |
|
|
|
case kStats: { |
|
|
|
char buf[1000]; |
|
|
|
char buf[1000]; |
|
|
|
|
|
|
|
|
|
|
|
uint64_t wal_bytes = 0; |
|
|
|
uint64_t wal_bytes = 0; |
|
|
@ -79,21 +105,29 @@ bool InternalStats::GetProperty(const Slice& property, std::string* value, |
|
|
|
write_with_wal = statistics_->getTickerCount(WRITE_WITH_WAL); |
|
|
|
write_with_wal = statistics_->getTickerCount(WRITE_WITH_WAL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Pardon the long line but I think it is easier to read this way.
|
|
|
|
snprintf( |
|
|
|
snprintf(buf, sizeof(buf), |
|
|
|
buf, sizeof(buf), |
|
|
|
" Compactions\n" |
|
|
|
" Compactions\n" |
|
|
|
"Level Files Size(MB) Score Time(sec) Read(MB) Write(MB) Rn(MB) Rnp1(MB) Wnew(MB) RW-Amplify Read(MB/s) Write(MB/s) Rn Rnp1 Wnp1 NewW Count msComp msStall Ln-stall Stall-cnt\n" |
|
|
|
"Level Files Size(MB) Score Time(sec) Read(MB) Write(MB) Rn(MB) " |
|
|
|
"------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n" |
|
|
|
" " |
|
|
|
); |
|
|
|
"Rnp1(MB) Wnew(MB) RW-Amplify Read(MB/s) Write(MB/s) Rn " |
|
|
|
|
|
|
|
"Rnp1 " |
|
|
|
|
|
|
|
" Wnp1 NewW Count msComp msStall Ln-stall Stall-cnt\n" |
|
|
|
|
|
|
|
"--------------------------------------------------------------------" |
|
|
|
|
|
|
|
"--" |
|
|
|
|
|
|
|
"--------------------------------------------------------------------" |
|
|
|
|
|
|
|
"--" |
|
|
|
|
|
|
|
"----------------------------------------------------------------\n"); |
|
|
|
value->append(buf); |
|
|
|
value->append(buf); |
|
|
|
for (int level = 0; level < number_levels_; level++) { |
|
|
|
for (int level = 0; level < number_levels_; level++) { |
|
|
|
int files = cfd->current()->NumLevelFiles(level); |
|
|
|
int files = current->NumLevelFiles(level); |
|
|
|
if (compaction_stats_[level].micros > 0 || files > 0) { |
|
|
|
if (compaction_stats_[level].micros > 0 || files > 0) { |
|
|
|
int64_t bytes_read = compaction_stats_[level].bytes_readn + |
|
|
|
int64_t bytes_read = compaction_stats_[level].bytes_readn + |
|
|
|
compaction_stats_[level].bytes_readnp1; |
|
|
|
compaction_stats_[level].bytes_readnp1; |
|
|
|
int64_t bytes_new = compaction_stats_[level].bytes_written - |
|
|
|
int64_t bytes_new = compaction_stats_[level].bytes_written - |
|
|
|
compaction_stats_[level].bytes_readnp1; |
|
|
|
compaction_stats_[level].bytes_readnp1; |
|
|
|
double amplify = (compaction_stats_[level].bytes_readn == 0) |
|
|
|
double amplify = |
|
|
|
|
|
|
|
(compaction_stats_[level].bytes_readn == 0) |
|
|
|
? 0.0 |
|
|
|
? 0.0 |
|
|
|
: (compaction_stats_[level].bytes_written + |
|
|
|
: (compaction_stats_[level].bytes_written + |
|
|
|
compaction_stats_[level].bytes_readnp1 + |
|
|
|
compaction_stats_[level].bytes_readnp1 + |
|
|
@ -117,10 +151,11 @@ bool InternalStats::GetProperty(const Slice& property, std::string* value, |
|
|
|
"%3d %8d %8.0f %5.1f %9.0f %9.0f %9.0f %9.0f %9.0f %9.0f " |
|
|
|
"%3d %8d %8.0f %5.1f %9.0f %9.0f %9.0f %9.0f %9.0f %9.0f " |
|
|
|
"%10.1f %9.1f %11.1f %8d %8d %8d %8d %8d %8d %9.1f %9.1f " |
|
|
|
"%10.1f %9.1f %11.1f %8d %8d %8d %8d %8d %8d %9.1f %9.1f " |
|
|
|
"%9lu\n", |
|
|
|
"%9lu\n", |
|
|
|
level, files, cfd->current()->NumLevelBytes(level) / 1048576.0, |
|
|
|
level, files, current->NumLevelBytes(level) / 1048576.0, |
|
|
|
cfd->current()->NumLevelBytes(level) / |
|
|
|
current->NumLevelBytes(level) / |
|
|
|
cfd->compaction_picker()->MaxBytesForLevel(level), |
|
|
|
cfd->compaction_picker()->MaxBytesForLevel(level), |
|
|
|
compaction_stats_[level].micros / 1e6, bytes_read / 1048576.0, |
|
|
|
compaction_stats_[level].micros / 1e6, |
|
|
|
|
|
|
|
bytes_read / 1048576.0, |
|
|
|
compaction_stats_[level].bytes_written / 1048576.0, |
|
|
|
compaction_stats_[level].bytes_written / 1048576.0, |
|
|
|
compaction_stats_[level].bytes_readn / 1048576.0, |
|
|
|
compaction_stats_[level].bytes_readn / 1048576.0, |
|
|
|
compaction_stats_[level].bytes_readnp1 / 1048576.0, |
|
|
|
compaction_stats_[level].bytes_readnp1 / 1048576.0, |
|
|
@ -138,8 +173,8 @@ bool InternalStats::GetProperty(const Slice& property, std::string* value, |
|
|
|
compaction_stats_[level].count, |
|
|
|
compaction_stats_[level].count, |
|
|
|
(int)((double)compaction_stats_[level].micros / 1000.0 / |
|
|
|
(int)((double)compaction_stats_[level].micros / 1000.0 / |
|
|
|
(compaction_stats_[level].count + 1)), |
|
|
|
(compaction_stats_[level].count + 1)), |
|
|
|
(double)stall_us / 1000.0 / (stalls + 1), stall_us / 1000000.0, |
|
|
|
(double)stall_us / 1000.0 / (stalls + 1), |
|
|
|
(unsigned long)stalls); |
|
|
|
stall_us / 1000000.0, (unsigned long)stalls); |
|
|
|
total_slowdown += stall_leveln_slowdown_[level]; |
|
|
|
total_slowdown += stall_leveln_slowdown_[level]; |
|
|
|
total_slowdown_count += stall_leveln_slowdown_count_[level]; |
|
|
|
total_slowdown_count += stall_leveln_slowdown_count_[level]; |
|
|
|
value->append(buf); |
|
|
|
value->append(buf); |
|
|
@ -147,7 +182,8 @@ bool InternalStats::GetProperty(const Slice& property, std::string* value, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interval_bytes_new = user_bytes_written - last_stats_.ingest_bytes_; |
|
|
|
interval_bytes_new = user_bytes_written - last_stats_.ingest_bytes_; |
|
|
|
interval_bytes_read = total_bytes_read - last_stats_.compaction_bytes_read_; |
|
|
|
interval_bytes_read = |
|
|
|
|
|
|
|
total_bytes_read - last_stats_.compaction_bytes_read_; |
|
|
|
interval_bytes_written = |
|
|
|
interval_bytes_written = |
|
|
|
total_bytes_written - last_stats_.compaction_bytes_written_; |
|
|
|
total_bytes_written - last_stats_.compaction_bytes_written_; |
|
|
|
interval_seconds_up = seconds_up - last_stats_.seconds_up_; |
|
|
|
interval_seconds_up = seconds_up - last_stats_.seconds_up_; |
|
|
@ -168,7 +204,8 @@ bool InternalStats::GetProperty(const Slice& property, std::string* value, |
|
|
|
snprintf(buf, sizeof(buf), |
|
|
|
snprintf(buf, sizeof(buf), |
|
|
|
"WAL cumulative: %llu WAL writes, %llu WAL syncs, " |
|
|
|
"WAL cumulative: %llu WAL writes, %llu WAL syncs, " |
|
|
|
"%.2f writes per sync, %.2f GB written\n", |
|
|
|
"%.2f writes per sync, %.2f GB written\n", |
|
|
|
(unsigned long long)write_with_wal, (unsigned long long)wal_synced, |
|
|
|
(unsigned long long)write_with_wal, |
|
|
|
|
|
|
|
(unsigned long long)wal_synced, |
|
|
|
write_with_wal / (double)(wal_synced + 1), |
|
|
|
write_with_wal / (double)(wal_synced + 1), |
|
|
|
wal_bytes / (1048576.0 * 1024)); |
|
|
|
wal_bytes / (1048576.0 * 1024)); |
|
|
|
value->append(buf); |
|
|
|
value->append(buf); |
|
|
@ -182,7 +219,8 @@ bool InternalStats::GetProperty(const Slice& property, std::string* value, |
|
|
|
(total_bytes_read + total_bytes_written) / (1048576.0 * 1024)); |
|
|
|
(total_bytes_read + total_bytes_written) / (1048576.0 * 1024)); |
|
|
|
value->append(buf); |
|
|
|
value->append(buf); |
|
|
|
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), |
|
|
|
snprintf( |
|
|
|
|
|
|
|
buf, sizeof(buf), |
|
|
|
"Compaction IO cumulative (MB/sec): " |
|
|
|
"Compaction IO cumulative (MB/sec): " |
|
|
|
"%.1f new, %.1f read, %.1f write, %.1f read+write\n", |
|
|
|
"%.1f new, %.1f read, %.1f write, %.1f read+write\n", |
|
|
|
user_bytes_written / 1048576.0 / seconds_up, |
|
|
|
user_bytes_written / 1048576.0 / seconds_up, |
|
|
@ -250,7 +288,8 @@ bool InternalStats::GetProperty(const Slice& property, std::string* value, |
|
|
|
snprintf( |
|
|
|
snprintf( |
|
|
|
buf, sizeof(buf), |
|
|
|
buf, sizeof(buf), |
|
|
|
"Amplification interval: %.1f write, %.1f compaction\n", |
|
|
|
"Amplification interval: %.1f write, %.1f compaction\n", |
|
|
|
(double)(interval_bytes_written + wal_bytes) / (interval_bytes_new + 1), |
|
|
|
(double)(interval_bytes_written + wal_bytes) / |
|
|
|
|
|
|
|
(interval_bytes_new + 1), |
|
|
|
(double)(interval_bytes_written + interval_bytes_read + wal_bytes) / |
|
|
|
(double)(interval_bytes_written + interval_bytes_read + wal_bytes) / |
|
|
|
(interval_bytes_new + 1)); |
|
|
|
(interval_bytes_new + 1)); |
|
|
|
value->append(buf); |
|
|
|
value->append(buf); |
|
|
@ -284,15 +323,31 @@ bool InternalStats::GetProperty(const Slice& property, std::string* value, |
|
|
|
last_stats_.write_self_ = write_self; |
|
|
|
last_stats_.write_self_ = write_self; |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} else if (in == "sstables") { |
|
|
|
} |
|
|
|
*value = cfd->current()->DebugString(); |
|
|
|
case kSsTables: |
|
|
|
|
|
|
|
*value = current->DebugString(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} else if (in == "num-immutable-mem-table") { |
|
|
|
case kNumImmutableMemTable: |
|
|
|
*value = std::to_string(cfd->imm()->size()); |
|
|
|
*value = std::to_string(cfd->imm()->size()); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
case kMemtableFlushPending: |
|
|
|
|
|
|
|
// Return number of mem tables that are ready to flush (made immutable)
|
|
|
|
|
|
|
|
*value = std::to_string(cfd->imm()->IsFlushPending() ? 1 : 0); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
case kCompactionPending: |
|
|
|
|
|
|
|
// 1 if the system already determines at least one compacdtion is needed.
|
|
|
|
|
|
|
|
// 0 otherwise,
|
|
|
|
|
|
|
|
*value = std::to_string(current->NeedsCompaction() ? 1 : 0); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
/////////////
|
|
|
|
|
|
|
|
case kBackgroundErrors: |
|
|
|
|
|
|
|
// Accumulated number of errors in background flushes or compactions.
|
|
|
|
|
|
|
|
*value = std::to_string(GetBackgroundErrorCount()); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
/////////
|
|
|
|
|
|
|
|
default: |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} // namespace rocksdb
|
|
|
|
} // namespace rocksdb
|
|
|
|