Expose num entries and deletions of sst files (#4623)

Summary:
he ratio of num_deletions to num_entries of a level can be useful to determine if a manual compaction needs to be triggered on a level.
Also refer #3980
Pull Request resolved: https://github.com/facebook/rocksdb/pull/4623

Differential Revision: D13045744

Pulled By: sagar0

fbshipit-source-id: 71f3c8e363a8ffd194ec3bb0ed0b69612231f0b3
This commit is contained in:
QingpingWang 2018-11-13 11:50:22 -08:00 committed by Facebook Github Bot
parent 5945e16dfc
commit 4f0fcb78ae
4 changed files with 21 additions and 0 deletions

12
db/c.cc
View File

@ -3550,6 +3550,18 @@ const char* rocksdb_livefiles_largestkey(
return lf->rep[index].largestkey.data(); return lf->rep[index].largestkey.data();
} }
uint64_t rocksdb_livefiles_entries(
const rocksdb_livefiles_t* lf,
int index) {
return lf->rep[index].num_entries;
}
uint64_t rocksdb_livefiles_deletions(
const rocksdb_livefiles_t* lf,
int index) {
return lf->rep[index].num_deletions;
}
extern void rocksdb_livefiles_destroy( extern void rocksdb_livefiles_destroy(
const rocksdb_livefiles_t* lf) { const rocksdb_livefiles_t* lf) {
delete lf; delete lf;

View File

@ -4405,6 +4405,8 @@ void VersionSet::GetLiveFilesMetaData(std::vector<LiveFileMetaData>* metadata) {
filemetadata.largestkey = file->largest.user_key().ToString(); filemetadata.largestkey = file->largest.user_key().ToString();
filemetadata.smallest_seqno = file->fd.smallest_seqno; filemetadata.smallest_seqno = file->fd.smallest_seqno;
filemetadata.largest_seqno = file->fd.largest_seqno; filemetadata.largest_seqno = file->fd.largest_seqno;
filemetadata.num_entries = file->num_entries;
filemetadata.num_deletions = file->num_deletions;
metadata->push_back(filemetadata); metadata->push_back(filemetadata);
} }
} }

View File

@ -1422,6 +1422,10 @@ extern ROCKSDB_LIBRARY_API const char* rocksdb_livefiles_smallestkey(
const rocksdb_livefiles_t*, int index, size_t* size); const rocksdb_livefiles_t*, int index, size_t* size);
extern ROCKSDB_LIBRARY_API const char* rocksdb_livefiles_largestkey( extern ROCKSDB_LIBRARY_API const char* rocksdb_livefiles_largestkey(
const rocksdb_livefiles_t*, int index, size_t* size); const rocksdb_livefiles_t*, int index, size_t* size);
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_livefiles_entries(
const rocksdb_livefiles_t*, int index);
extern ROCKSDB_LIBRARY_API uint64_t rocksdb_livefiles_deletions(
const rocksdb_livefiles_t*, int index);
extern ROCKSDB_LIBRARY_API void rocksdb_livefiles_destroy( extern ROCKSDB_LIBRARY_API void rocksdb_livefiles_destroy(
const rocksdb_livefiles_t*); const rocksdb_livefiles_t*);

View File

@ -93,6 +93,9 @@ struct SstFileMetaData {
std::string largestkey; // Largest user defined key in the file. std::string largestkey; // Largest user defined key in the file.
uint64_t num_reads_sampled; // How many times the file is read. uint64_t num_reads_sampled; // How many times the file is read.
bool being_compacted; // true if the file is currently being compacted. bool being_compacted; // true if the file is currently being compacted.
uint64_t num_entries;
uint64_t num_deletions;
}; };
// The full set of metadata associated with each SST file. // The full set of metadata associated with each SST file.