Skip to content

Commit 49d22aa

Browse files
committed
support calculate blob info of valid blob and valid entry, this entry will benifit from value handle bytedance#199
add tickers of read blob valid bytedance#199 fix invalid_file_cnt statistic fix invalid_file_cnt_ statistic bytedance#199 refine code style bytedance#199
1 parent feeb6ee commit 49d22aa

File tree

8 files changed

+76
-2
lines changed

8 files changed

+76
-2
lines changed

db/compaction_job.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,14 @@ Status CompactionJob::Install(const MutableCFOptions& mutable_cf_options) {
14901490
stream.EndArray();
14911491
stream << "blob_count";
14921492
stream << vstorage->NumLevelFiles(-1);
1493+
stream << "invalid_file_cnt";
1494+
stream << vstorage->invalid_file_cnt();
1495+
stream << "valid_file_cnt";
1496+
stream << vstorage->valid_file_cnt();
1497+
stream << "invalid_entry_cnt";
1498+
stream << vstorage->invalid_entry_cnt();
1499+
stream << "valid_entry_cnt";
1500+
stream << vstorage->valid_entry_cnt();
14931501

14941502
CleanupCompaction();
14951503
return status;

db/flush_job.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ Status FlushJob::Run(LogsWithPrepTracker* prep_tracker) {
283283
stream.EndArray();
284284
stream << "blob_count";
285285
stream << vstorage->NumLevelFiles(-1);
286+
stream << "invalid_file_cnt";
287+
stream << vstorage->invalid_file_cnt();
288+
stream << "valid_file_cnt";
289+
stream << vstorage->valid_file_cnt();
290+
stream << "invalid_entry_cnt";
291+
stream << vstorage->invalid_entry_cnt();
292+
stream << "valid_entry_cnt";
293+
stream << vstorage->valid_entry_cnt();
286294

287295
stream << "immutable_memtables" << cfd_->imm()->NumNotFlushed();
288296

db/version_builder.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,7 @@ class VersionBuilder::Rep {
735735
vstorage->ResetVersionBuilderContext(context_.release());
736736
vstorage->ComputeBlobOverlapScore();
737737
vstorage->CalculateEdge();
738+
vstorage->CalculateBlobInfo();
738739
}
739740

740741
void LoadTableHandlers(InternalStats* internal_stats,

db/version_set.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,11 @@ VersionStorageInfo::VersionStorageInfo(
12161216
file_indexer_(user_comparator),
12171217
compaction_style_(compaction_style),
12181218
files_(new std::vector<FileMetaData*>[num_levels_ + 1]),
1219+
edge_cnt_levels_(num_levels_),
1220+
valid_file_cnt_(0),
1221+
valid_entry_cnt_(0),
1222+
invalid_file_cnt_(0),
1223+
invalid_entry_cnt_(0),
12191224
base_level_(num_levels_ == 1 ? -1 : 1),
12201225
level_multiplier_(0.0),
12211226
files_by_compaction_pri_(num_levels_),
@@ -1275,6 +1280,11 @@ Status Version::fetch_buffer(LazyBuffer* buffer) const {
12751280
context->data[1]);
12761281
uint64_t sequence = context->data[2];
12771282
auto pair = *reinterpret_cast<DependenceMap::value_type*>(context->data[3]);
1283+
if (pair.second->fd.GetNumber() != pair.first) {
1284+
RecordTick(db_statistics_, READ_BLOB_INVALID);
1285+
} else {
1286+
RecordTick(db_statistics_, READ_BLOB_VALID);
1287+
}
12781288
bool value_found = false;
12791289
SequenceNumber context_seq;
12801290
GetContext get_context(cfd_->internal_comparator().user_comparator(), nullptr,
@@ -4864,4 +4874,31 @@ void VersionStorageInfo::CalculateEdge() {
48644874
}
48654875
}
48664876

4877+
void VersionStorageInfo::CalculateBlobInfo() {
4878+
valid_file_cnt_ = 0;
4879+
valid_entry_cnt_ = 0;
4880+
invalid_file_cnt_ = 0;
4881+
invalid_entry_cnt_ = 0;
4882+
chash_map<uint64_t, uint64_t> file_map;
4883+
chash_set<uint64_t> invalid_file_set;
4884+
for (int i = 0; i < num_levels_; i++) {
4885+
for (auto& f : LevelFiles(i)) {
4886+
for (auto fn : f->prop.dependence) {
4887+
file_map[fn.file_number] += fn.entry_count;
4888+
}
4889+
}
4890+
}
4891+
for (auto f : file_map) {
4892+
uint64_t newest_file_number =
4893+
dependence_map_.find(f.first)->second->fd.GetNumber();
4894+
if (newest_file_number != f.first) {
4895+
invalid_file_set.insert(newest_file_number);
4896+
invalid_entry_cnt_ += f.second;
4897+
} else {
4898+
valid_file_cnt_++;
4899+
valid_entry_cnt_ += f.second;
4900+
}
4901+
}
4902+
invalid_file_cnt_ = invalid_file_set.size();
4903+
}
48674904
} // namespace TERARKDB_NAMESPACE

db/version_set.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,12 @@ class VersionStorageInfo {
503503
void CalculateEdge();
504504
std::vector<uint64_t> edge_cnt_levels() const { return edge_cnt_levels_; }
505505

506+
void CalculateBlobInfo();
507+
uint64_t valid_file_cnt() const { return valid_file_cnt_; }
508+
uint64_t valid_entry_cnt() const { return valid_entry_cnt_; }
509+
uint64_t invalid_file_cnt() const { return invalid_file_cnt_; }
510+
uint64_t invalid_entry_cnt() const { return invalid_entry_cnt_; }
511+
506512
private:
507513
const InternalKeyComparator* internal_comparator_;
508514
const Comparator* user_comparator_;
@@ -527,6 +533,11 @@ class VersionStorageInfo {
527533
// We Change it when new version is build
528534
std::vector<uint64_t> edge_cnt_levels_;
529535

536+
uint64_t valid_file_cnt_;
537+
uint64_t valid_entry_cnt_;
538+
uint64_t invalid_file_cnt_;
539+
uint64_t invalid_entry_cnt_;
540+
530541
// Dependence files both in files[-1] and dependence_map
531542
DependenceMap dependence_map_;
532543

include/rocksdb/statistics.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ enum Tickers : uint32_t {
258258
GC_TOUCH_FILES,
259259
GC_SKIP_GET_BY_SEQ,
260260
GC_SKIP_GET_BY_FILE,
261+
262+
READ_BLOB_VALID,
263+
READ_BLOB_INVALID,
264+
261265
TICKER_ENUM_MAX
262266
};
263267

java/rocksjni/portal.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3476,9 +3476,12 @@ class TickerTypeJni {
34763476
return 0x63;
34773477
case TERARKDB_NAMESPACE::Tickers::GC_SKIP_GET_BY_FILE:
34783478
return 0x64;
3479-
case TERARKDB_NAMESPACE::Tickers::TICKER_ENUM_MAX:
3479+
case TERARKDB_NAMESPACE::Tickers::READ_BLOB_VALID:
34803480
return 0x65;
3481-
3481+
case TERARKDB_NAMESPACE::Tickers::READ_BLOB_INVALID:
3482+
return 0x66;
3483+
case TERARKDB_NAMESPACE::Tickers::TICKER_ENUM_MAX:
3484+
return 0x67;
34823485
default:
34833486
// undefined/default
34843487
return 0x0;

monitoring/statistics.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ const std::vector<std::pair<Tickers, std::string>> TickersNameMap = {
139139
{GC_TOUCH_FILES, "rocksdb.num.gc.touch_files"},
140140
{GC_SKIP_GET_BY_SEQ, "rocksdb.num.gc.skip_by_seqno"},
141141
{GC_SKIP_GET_BY_FILE, "rocksdb.num.gc.skip_by_file_meta"},
142+
{READ_BLOB_VALID, "rocksdb.num.read.blob_valid"},
143+
{READ_BLOB_INVALID, "rocksdb.num.read.blob_invalid"},
142144
};
143145

144146
const std::vector<std::pair<Histograms, std::string>> HistogramsNameMap = {

0 commit comments

Comments
 (0)