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):
`check_table_ids_non_overlapping` will panic if either table-id list is empty (due to the `assert!` + `unwrap()`s). In `validate_group_merge`, the lists are derived from `table_statistic.keys()` and could be empty for some groups, which would turn a merge-rejection into a runtime crash. Consider handling empty inputs explicitly (e.g., treat empty as non-overlapping and return `true`, or return a `Result<bool>` / bubble up a proper `Error::CompactionGroup` from the validator instead of panicking)."

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(