Skip to content

Commit

Permalink
add num_point_read and num_existing_point_read counter
Browse files Browse the repository at this point in the history
  • Loading branch information
littlepig2013 committed Dec 17, 2023
1 parent eb5dbf4 commit aa6063b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
7 changes: 6 additions & 1 deletion db/version_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,20 @@ struct FileDescriptor {
};

struct FileSampledStats {
FileSampledStats() : num_reads_sampled(0) {}
FileSampledStats()
: num_reads_sampled(0), num_point_reads(0), num_existing_point_reads(0) {}
FileSampledStats(const FileSampledStats& other) { *this = other; }
FileSampledStats& operator=(const FileSampledStats& other) {
num_reads_sampled = other.num_reads_sampled.load();
num_point_reads = other.num_point_reads.load();
num_existing_point_reads = other.num_existing_point_reads.load();
return *this;
}

// number of user reads to this file.
mutable std::atomic<uint64_t> num_reads_sampled;
mutable std::atomic<uint64_t> num_point_reads;
mutable std::atomic<uint64_t> num_existing_point_reads;
};

struct FileMetaData {
Expand Down
15 changes: 15 additions & 0 deletions db/version_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,8 @@ void Version::GetColumnFamilyMetaData(ColumnFamilyMetaData* cf_meta) {
file->fd.largest_seqno, file->smallest.user_key().ToString(),
file->largest.user_key().ToString(),
file->stats.num_reads_sampled.load(std::memory_order_relaxed),
file->stats.num_point_reads.load(std::memory_order_relaxed),
file->stats.num_existing_point_reads.load(std::memory_order_relaxed),
file->being_compacted, file->temperature,
file->oldest_blob_file_number, file->TryGetOldestAncesterTime(),
file->TryGetFileCreationTime(), file->epoch_number,
Expand Down Expand Up @@ -2412,6 +2414,7 @@ void Version::Get(const ReadOptions& read_options, const LookupKey& k,
if (get_context.sample()) {
sample_file_read_inc(f->file_metadata);
}
file_point_read_inc(f->file_metadata, 1);

bool timer_enabled =
GetPerfLevel() >= PerfLevel::kEnableTimeExceptForMutex &&
Expand Down Expand Up @@ -2451,6 +2454,7 @@ void Version::Get(const ReadOptions& read_options, const LookupKey& k,
// TODO: update per-level perfcontext user_key_return_count for kMerge
break;
case GetContext::kFound:
file_existing_point_read_inc(f->file_metadata, 1);
if (fp.GetHitFileLevel() == 0) {
RecordTick(db_statistics_, GET_HIT_L0);
} else if (fp.GetHitFileLevel() == 1) {
Expand Down Expand Up @@ -4954,6 +4958,12 @@ std::string Version::DebugString(bool hex, bool print_stats) const {
r.append("(");
r.append(std::to_string(
files[i]->stats.num_reads_sampled.load(std::memory_order_relaxed)));
r.append(",");
r.append(std::to_string(
files[i]->stats.num_point_reads.load(std::memory_order_relaxed)));
r.append(",");
r.append(std::to_string(files[i]->stats.num_existing_point_reads.load(
std::memory_order_relaxed)));
r.append(")");
}
r.append("\n");
Expand Down Expand Up @@ -7073,6 +7083,11 @@ void VersionSet::GetLiveFilesMetaData(std::vector<LiveFileMetaData>* metadata) {
filemetadata.largest_seqno = file->fd.largest_seqno;
filemetadata.num_reads_sampled =
file->stats.num_reads_sampled.load(std::memory_order_relaxed);
filemetadata.num_point_reads =
file->stats.num_point_reads.load(std::memory_order_relaxed);
filemetadata.num_existing_point_reads =
file->stats.num_existing_point_reads.load(
std::memory_order_relaxed);
filemetadata.being_compacted = file->being_compacted;
filemetadata.num_entries = file->num_entries;
filemetadata.num_deletions = file->num_deletions;
Expand Down
7 changes: 7 additions & 0 deletions include/rocksdb/metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct SstFileMetaData : public FileStorageInfo {
SequenceNumber _smallest_seqno, SequenceNumber _largest_seqno,
const std::string& _smallestkey,
const std::string& _largestkey, uint64_t _num_reads_sampled,
uint64_t _num_point_reads, uint64_t _num_existing_point_reads,
bool _being_compacted, Temperature _temperature,
uint64_t _oldest_blob_file_number,
uint64_t _oldest_ancester_time, uint64_t _file_creation_time,
Expand All @@ -89,6 +90,8 @@ struct SstFileMetaData : public FileStorageInfo {
smallestkey(_smallestkey),
largestkey(_largestkey),
num_reads_sampled(_num_reads_sampled),
num_point_reads(_num_point_reads),
num_existing_point_reads(_num_existing_point_reads),
being_compacted(_being_compacted),
num_entries(0),
num_deletions(0),
Expand Down Expand Up @@ -123,6 +126,10 @@ struct SstFileMetaData : public FileStorageInfo {
std::string smallestkey; // Smallest user defined key in the file.
std::string largestkey; // Largest user defined key in the file.
uint64_t num_reads_sampled = 0; // How many times the file is read.
// How many times the file is read by a point query.
uint64_t num_point_reads = 0;
// How many times the file is read by a point query with a "Found" result.
uint64_t num_existing_point_reads = 0;
bool being_compacted =
false; // true if the file is currently being compacted.

Expand Down
4 changes: 4 additions & 0 deletions java/rocksjni/portal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7486,6 +7486,8 @@ class LiveFileMetaDataJni : public JavaClass {
static_cast<jlong>(live_file_meta_data->largest_seqno), jsmallest_key,
jlargest_key,
static_cast<jlong>(live_file_meta_data->num_reads_sampled),
static_cast<jlong>(live_file_meta_data->num_point_reads),
static_cast<jlong>(live_file_meta_data->num_existing_point_reads),
static_cast<jboolean>(live_file_meta_data->being_compacted),
static_cast<jlong>(live_file_meta_data->num_entries),
static_cast<jlong>(live_file_meta_data->num_deletions));
Expand Down Expand Up @@ -7581,6 +7583,8 @@ class SstFileMetaDataJni : public JavaClass {
static_cast<jint>(sst_file_meta_data->smallest_seqno),
static_cast<jlong>(sst_file_meta_data->largest_seqno), jsmallest_key,
jlargest_key, static_cast<jlong>(sst_file_meta_data->num_reads_sampled),
static_cast<jlong>(sst_file_meta_data->num_point_reads),
static_cast<jlong>(sst_file_meta_data->num_existing_point_reads),
static_cast<jboolean>(sst_file_meta_data->being_compacted),
static_cast<jlong>(sst_file_meta_data->num_entries),
static_cast<jlong>(sst_file_meta_data->num_deletions));
Expand Down
9 changes: 9 additions & 0 deletions monitoring/file_read_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ inline void sample_file_read_inc(FileMetaData* meta) {
meta->stats.num_reads_sampled.fetch_add(kFileReadSampleRate,
std::memory_order_relaxed);
}

inline void file_point_read_inc(FileMetaData* meta, uint64_t increment) {
meta->stats.num_point_reads.fetch_add(increment, std::memory_order_relaxed);
}
inline void file_existing_point_read_inc(FileMetaData* meta,
uint64_t increment) {
meta->stats.num_existing_point_reads.fetch_add(increment,
std::memory_order_relaxed);
}
} // namespace ROCKSDB_NAMESPACE

0 comments on commit aa6063b

Please sign in to comment.