Repository: tikv/tikv
File: components/engine_rocks/src/rocks_metrics.rs (Rust)

Code before:
                if let Some(v) = crate::util::get_cf_num_blob_files_at_level(db, handle, level) {
                    *cf_stats.levels[level]
                        .num_blob_files
                        .get_or_insert_default() += v;
                }
            }

            if let Some(info) = db.get_map_property_cf(handle, ROCKSDB_CFSTATS) {
                let stall_num = self.db_stats.stall_num.get_or_insert_default();
                for (key, val) in ROCKSDB_IOSTALL_KEY.iter().zip(stall_num) {
                    *val += info.get_property_int_value(key);
                }
            }
        }

        // For compaction and flushes.
        if let Some(v) = db.get_property_int(ROCKSDB_NUM_RUNNING_COMPACTIONS) {
            *self
                .db_stats
                .num_running_compactions
                .get_or_insert_default() += v;
        }
        if let Some(v) = db.get_property_int(ROCKSDB_NUM_RUNNING_FLUSHES) {
            *self
                .db_stats
                .num_running_compactions
                .get_or_insert_default() += v;
        }

        // For snapshot
        *self.db_stats.num_snapshots.get_or_insert_default() +=
            db.get_property_int(ROCKSDB_NUM_SNAPSHOTS).unwrap_or(0);
        let oldest_snapshot_time =
            db.get_property_int(ROCKSDB_OLDEST_SNAPSHOT_TIME)
                .map_or(0, |t| {
                    let now = time::get_time().sec as u64;
                    // RocksDB returns 0 if no snapshots.
                    if t > 0 && now > t { now - t } else { 0 }
                });
        if oldest_snapshot_time > self.db_stats.oldest_snapshot_time.unwrap_or(0) {
            *self.db_stats.oldest_snapshot_time.get_or_insert_default() = oldest_snapshot_time;
        }

        // Since block cache is shared, getting cache size from any CF/DB is fine. Here
        // we get from default CF.
        if self.db_stats.block_cache_size.is_none() {
            let handle = crate::util::get_cf_handle(db, CF_DEFAULT).unwrap();
            *self.db_stats.block_cache_size.get_or_insert_default() =
                db.get_block_cache_usage_cf(handle);
        }
        if self.db_stats.blob_cache_size.is_none() {

Review comment (suggestion):
```suggestion
                .num_running_flushes
```

Code after:
                if let Some(v) = crate::util::get_cf_num_blob_files_at_level(db, handle, level) {
                    *cf_stats.levels[level]
                        .num_blob_files
                        .get_or_insert_default() += v;
                }
            }

            if let Some(info) = db.get_map_property_cf(handle, ROCKSDB_CFSTATS) {
                let stall_num = self.db_stats.stall_num.get_or_insert_default();
                for (key, val) in ROCKSDB_IOSTALL_KEY.iter().zip(stall_num) {
                    *val += info.get_property_int_value(key);
                }
            }
        }

        // For compaction and flushes.
        if let Some(v) = db.get_property_int(ROCKSDB_NUM_RUNNING_COMPACTIONS) {
            *self
                .db_stats
                .num_running_compactions
                .get_or_insert_default() += v;
        }
        if let Some(v) = db.get_property_int(ROCKSDB_NUM_RUNNING_FLUSHES) {
            *self.db_stats.num_running_flushes.get_or_insert_default() += v;
        }

        // For snapshot
        *self.db_stats.num_snapshots.get_or_insert_default() +=
            db.get_property_int(ROCKSDB_NUM_SNAPSHOTS).unwrap_or(0);
        let oldest_snapshot_time =
            db.get_property_int(ROCKSDB_OLDEST_SNAPSHOT_TIME)
                .map_or(0, |t| {
                    let now = time::get_time().sec as u64;
                    // RocksDB returns 0 if no snapshots.
                    if t > 0 && now > t { now - t } else { 0 }
                });
        if oldest_snapshot_time > self.db_stats.oldest_snapshot_time.unwrap_or(0) {
            *self.db_stats.oldest_snapshot_time.get_or_insert_default() = oldest_snapshot_time;
        }

        // Since block cache is shared, getting cache size from any CF/DB is fine. Here
        // we get from default CF.
        if self.db_stats.block_cache_size.is_none() {
            let handle = crate::util::get_cf_handle(db, CF_DEFAULT).unwrap();
            *self.db_stats.block_cache_size.get_or_insert_default() =
                db.get_block_cache_usage_cf(handle);
        }
        if self.db_stats.blob_cache_size.is_none() {
            let handle = crate::util::get_cf_handle(db, CF_DEFAULT).unwrap();
            *self.db_stats.blob_cache_size.get_or_insert_default() =
                db.get_blob_cache_usage_cf(handle);