Repository: risingwavelabs/risingwave
File: src/meta/src/hummock/manager/compaction/compaction_group_schedule.rs (Rust)

Code before:
                    "failed to merge group-{} group-{}",
                    next_group.group_id,
                    group.group_id,
                );
            }
        }

        result
    }
}

#[derive(Debug, Default)]
struct GroupMergeValidator {}

impl GroupMergeValidator {
    /// Check if two sorted, non-empty table id lists have non-overlapping ranges.
    /// Returns true if `max(left) < min(right)` after ordering by first element.
    fn check_table_ids_non_overlapping(table_ids_1: &[TableId], table_ids_2: &[TableId]) -> bool {
        assert!(!table_ids_1.is_empty() && !table_ids_2.is_empty());
        let (left, right) = if table_ids_1.first().unwrap() <= table_ids_2.first().unwrap() {
            (table_ids_1, table_ids_2)
        } else {
            (table_ids_2, table_ids_1)
        };
        left.last().unwrap() < right.first().unwrap()
    }

    /// Check if the table is high write throughput with the given threshold and ratio.
    pub fn is_table_high_write_throughput(
        table_throughput: impl Iterator<Item = &TableWriteThroughputStatistic>,
        threshold: u64,
        high_write_throughput_ratio: f64,
    ) -> bool {
        let mut sample_size = 0;
        let mut high_write_throughput_count = 0;
        for statistic in table_throughput {
            sample_size += 1;
            if statistic.throughput > threshold {
                high_write_throughput_count += 1;
            }
        }

        high_write_throughput_count as f64 > sample_size as f64 * high_write_throughput_ratio
    }

    pub fn is_table_low_write_throughput(
        table_throughput: impl Iterator<Item = &TableWriteThroughputStatistic>,
        threshold: u64,
        low_write_throughput_ratio: f64,
    ) -> bool {
        let mut sample_size = 0;

Review comment (bug):
This helper relies on both slices being sorted (so `first()` is min and `last()` is max), but that requirement is only documented and not enforced. To make the helper more robust and self-contained, consider computing min/max via iterators (no sorting requirement), or add a `debug_assert!` that the inputs are sorted if that invariant is crucial. This reduces the chance of subtle misuse at new call sites.

Code after:
                    "failed to merge group-{} group-{}",
                    next_group.group_id,
                    group.group_id,
                );
            }
        }

        result
    }
}

#[derive(Debug, Default)]
struct GroupMergeValidator {}

impl GroupMergeValidator {
    /// Check if the table is high write throughput with the given threshold and ratio.
    pub fn is_table_high_write_throughput(
        table_throughput: impl Iterator<Item = &TableWriteThroughputStatistic>,
        threshold: u64,
        high_write_throughput_ratio: f64,
    ) -> bool {
        let mut sample_size = 0;
        let mut high_write_throughput_count = 0;
        for statistic in table_throughput {
            sample_size += 1;
            if statistic.throughput > threshold {
                high_write_throughput_count += 1;
            }
        }

        high_write_throughput_count as f64 > sample_size as f64 * high_write_throughput_ratio
    }

    pub fn is_table_low_write_throughput(
        table_throughput: impl Iterator<Item = &TableWriteThroughputStatistic>,
        threshold: u64,
        low_write_throughput_ratio: f64,
    ) -> bool {
        let mut sample_size = 0;
        let mut low_write_throughput_count = 0;
        for statistic in table_throughput {
            sample_size += 1;
            if statistic.throughput <= threshold {
                low_write_throughput_count += 1;
            }
        }

        low_write_throughput_count as f64 > sample_size as f64 * low_write_throughput_ratio
    }

    fn check_is_low_write_throughput_compaction_group(