Repository: tikv/tikv
File: components/raftstore/src/store/worker/pd.rs (Rust)

Code before:
                    store_id, min_resolved_ts
                )
            }
            Task::ReportBuckets(ref buckets) => {
                write!(f, "report buckets: {:?}", buckets)
            }
            Task::ControlGrpcServer(ref event) => {
                write!(f, "control grpc server: {:?}", event)
            }
            Task::InspectLatency { factor } => {
                write!(f, "inspect raftstore latency: {:?}", factor)
            }
        }
    }
}

const DEFAULT_LOAD_BASE_SPLIT_CHECK_INTERVAL: Duration = Duration::from_secs(1);
const DEFAULT_COLLECT_TICK_INTERVAL: Duration = Duration::from_secs(1);
/// The default interval for inspecting latency ticks.
///
/// This constant defines the minimum time interval between inspection
/// operations. The actual interval should not be less than 100 microsecs
/// since that is the minimum delay required for a single I/O operation. Setting
/// an interval smaller than this threshold could lead to inefficient resource
/// usage and potential performance degradation.
const DEFAULT_INSPECT_LATENCY_TICK_INTERVAL: Duration = Duration::from_micros(100);

fn default_collect_tick_interval() -> Duration {
    fail_point!("mock_collect_tick_interval", |_| {
        Duration::from_millis(1)
    });
    DEFAULT_COLLECT_TICK_INTERVAL
}

#[inline]
fn convert_record_pairs(m: HashMap<String, u64>) -> RecordPairVec {
    m.into_iter()
        .map(|(k, v)| {
            let mut pair = pdpb::RecordPair::default();
            pair.set_key(k);
            pair.set_value(v);
            pair
        })
        .collect()
}

#[derive(Clone)]
pub struct WrappedScheduler<EK: KvEngine>(Scheduler<Task<EK>>);

impl<EK> Collector for WrappedScheduler<EK>
where

Review comment (performance):
Should we set the minimum limit on `inspect_latency_interval/inspect_kvdb_latency_interval` instead of setting it on `collect_tick_interval`?

If `inspect_kvdb_latency_interval` is smaller than `collect_tick_interval`, then `update_kvdisk_latency_stats_interval` will be 0, which is invalid and should be disallowed.

Also, is 100µs too low? Realistically, the inspect interval should never be that short—probably no less than 10ms.

Code after:
                    store_id, min_resolved_ts
                )
            }
            Task::ReportBuckets(ref buckets) => {
                write!(f, "report buckets: {:?}", buckets)
            }
            Task::ControlGrpcServer(ref event) => {
                write!(f, "control grpc server: {:?}", event)
            }
            Task::InspectLatency { factor } => {
                write!(f, "inspect raftstore latency: {:?}", factor)
            }
        }
    }
}

const DEFAULT_LOAD_BASE_SPLIT_CHECK_INTERVAL: Duration = Duration::from_secs(1);
const DEFAULT_COLLECT_TICK_INTERVAL: Duration = Duration::from_secs(1);

fn default_collect_tick_interval() -> Duration {
    fail_point!("mock_collect_tick_interval", |_| {
        Duration::from_millis(1)
    });
    DEFAULT_COLLECT_TICK_INTERVAL
}

/// Determines the minimal interval for latency inspection ticks based on raft
/// and kvdb inspection intervals.
///
/// This function handles different scenarios for latency inspection:
/// 1. Both intervals are zero: Inspection is disabled, returns a large interval
///    (1 hour)
/// 2. Only raft interval is zero: Uses kvdb interval (raft inspection disabled)
/// 3. Only kvdb interval is zero: Uses raft interval (kvdb inspection disabled)
/// 4. Both intervals non-zero: Uses the smaller of the two intervals
///
/// # Arguments
///
/// * `inspect_latency_interval` - Interval for raft latency inspection
/// * `inspect_kvdb_latency_interval` - Interval for kvdb latency inspection
///
/// # Returns
///
/// The minimal interval that should be used for latency inspection ticks
fn get_minimal_inspect_tick_interval(
    inspect_latency_interval: Duration,
    inspect_kvdb_latency_interval: Duration,
) -> Duration {
    match (
        inspect_latency_interval.is_zero(),
        inspect_kvdb_latency_interval.is_zero(),