Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a metric to track the number of managed files per column family in RocksDb #19214

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions crates/typed-store/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ impl SamplingInterval {
pub struct ColumnFamilyMetrics {
pub rocksdb_total_sst_files_size: IntGaugeVec,
pub rocksdb_total_blob_files_size: IntGaugeVec,
pub rocksdb_total_num_files: IntGaugeVec,
pub rocksdb_current_size_active_mem_tables: IntGaugeVec,
pub rocksdb_size_all_mem_tables: IntGaugeVec,
pub rocksdb_num_snapshots: IntGaugeVec,
Expand Down Expand Up @@ -116,6 +117,13 @@ impl ColumnFamilyMetrics {
registry,
)
.unwrap(),
rocksdb_total_num_files: register_int_gauge_vec_with_registry!(
"rocksdb_total_num_files",
"Total number of files used in the column family",
&["cf_name"],
registry,
)
.unwrap(),
rocksdb_current_size_active_mem_tables: register_int_gauge_vec_with_registry!(
"rocksdb_current_size_active_mem_tables",
"The current approximate size of active memtable (bytes).",
Expand Down
16 changes: 15 additions & 1 deletion crates/typed-store/src/rocks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use bincode::Options;
use collectable::TryExtend;
use itertools::Itertools;
use prometheus::{Histogram, HistogramTimer};
use rocksdb::properties::num_files_at_level;
use rocksdb::{
checkpoint::Checkpoint, BlockBasedOptions, BottommostLevelCompaction, Cache, CompactOptions,
DBPinnableSlice, LiveFile, OptimisticTransactionDB, SnapshotWithThreadMode,
Expand Down Expand Up @@ -902,7 +903,7 @@ impl<K, V> DBMap<K, V> {
fn get_int_property(
rocksdb: &RocksDB,
cf: &impl AsColumnFamilyRef,
property_name: &'static std::ffi::CStr,
property_name: &std::ffi::CStr,
) -> Result<i64, TypedStoreError> {
match rocksdb.property_int_value_cf(cf, property_name) {
Ok(Some(value)) => Ok(value.try_into().unwrap()),
Expand Down Expand Up @@ -983,6 +984,19 @@ impl<K, V> DBMap<K, V> {
Self::get_int_property(rocksdb, &cf, ROCKSDB_PROPERTY_TOTAL_BLOB_FILES_SIZE)
.unwrap_or(METRICS_ERROR),
);
// 7 is the default number of levels in RocksDB. If we ever change the number of levels using `set_num_levels`,
// we need to update here as well. Note that there isn't an API to query the DB to get the number of levels (yet).
let total_num_files: i64 = (0..=6)
.map(|level| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also query the num levels in the db or is this the max value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default value, and yes one can change it.

I didn't find a way to query db option in rust, but there is a c++ API that can do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update comment about if we every change number of layers, we need to update here as well.

Worse case, it'll just miss lower level file count.

Self::get_int_property(rocksdb, &cf, &num_files_at_level(level))
.unwrap_or(METRICS_ERROR)
})
.sum();
db_metrics
.cf_metrics
.rocksdb_total_num_files
.with_label_values(&[cf_name])
.set(total_num_files);
db_metrics
.cf_metrics
.rocksdb_current_size_active_mem_tables
Expand Down
Loading