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

Code before:
        //   - max_bytes_for_level_base
        //   - max_bytes_for_level_multiplier
        //   - max_compaction_bytes
        //   - sub_level_max_compaction_bytes
        // If any of these fields differ, the groups may have incompatible scheduling.
        if group.compaction_group_config.compaction_config
            != next_group.compaction_group_config.compaction_config
        {
            return Err(Error::CompactionGroup(format!(
                "Cannot merge group {} and next_group {} with different compaction configs",
                group.group_id, next_group.group_id
            )));
        }

        // do not merge the compaction group which is creating
        if Self::check_is_creating_compaction_group(group, created_tables) {
            return Err(Error::CompactionGroup(format!(
                "Cannot merge creating group {} next_group {}",
                group.group_id, next_group.group_id
            )));
        }

        // do not merge high throughput group
        if !Self::check_is_low_write_throughput_compaction_group(
            table_write_throughput_statistic_manager,
            group,
            opts,
        ) {
            return Err(Error::CompactionGroup(format!(
                "Cannot merge high throughput group {} next_group {}",
                group.group_id, next_group.group_id
            )));
        }

        let size_limit = (group.compaction_group_config.max_estimated_group_size() as f64
            * opts.split_group_size_ratio) as u64;

        if (group.group_size + next_group.group_size) > size_limit {
            return Err(Error::CompactionGroup(format!(
                "Cannot merge huge group {} group_size {} next_group {} next_group_size {} size_limit {}",
                group.group_id,
                group.group_size,
                next_group.group_id,
                next_group.group_size,
                size_limit
            )));
        }

        if Self::check_is_creating_compaction_group(next_group, created_tables) {
            return Err(Error::CompactionGroup(format!(
                "Cannot merge creating group {} next group {}",

Review comment (performance):
Direct comparison of entire `compaction_config` structures may be inefficient. Consider comparing only the specific fields that affect `max_estimated_group_size` (`max_bytes_for_level_base`, `max_bytes_for_level_multiplier`, `max_compaction_bytes`, `sub_level_max_compaction_bytes`) as documented in the comment above, to make the check more explicit and potentially more performant.
```suggestion
        {
            let config_a = &group.compaction_group_config.compaction_config;
            let config_b = &next_group.compaction_group_config.compaction_config;
            if config_a.max_bytes_for_level_base != config_b.max_bytes_for_level_base
                || config_a.max_bytes_for_level_multiplier != config_b.max_bytes_for_level_multiplier
                || config_a.max_compaction_bytes != config_b.max_compaction_bytes
                || config_a.sub_level_max_compaction_bytes != config_b.sub_level_max_compaction_bytes
            {
                return Err(Error::CompactionGroup(format!(
                    "Cannot merge group {} and next_group {} with different compaction configs (max_estimated_group_size fields differ)",
                    group.group_id, next_group.group_id
                )));
            }
```

Code after:
        //   - max_bytes_for_level_base
        //   - max_bytes_for_level_multiplier
        //   - max_compaction_bytes
        //   - sub_level_max_compaction_bytes
        // If any of these fields differ, the groups may have incompatible scheduling.
        if group.compaction_group_config.compaction_config
            != next_group.compaction_group_config.compaction_config
        {
            let left_config = group.compaction_group_config.compaction_config.as_ref();
            let right_config = next_group
                .compaction_group_config
                .compaction_config
                .as_ref();

            tracing::warn!(
                group_id = group.group_id,
                next_group_id = next_group.group_id,
                left_config = ?left_config,
                right_config = ?right_config,
                "compaction config mismatch detected while merging compaction groups"
            );

            return Err(Error::CompactionGroup(format!(
                "Cannot merge group {} and next_group {} with different compaction configs. left_config: {:?}, right_config: {:?}",
                group.group_id, next_group.group_id, left_config, right_config
            )));
        }

        // do not merge the compaction group which is creating
        if Self::check_is_creating_compaction_group(group, created_tables) {
            return Err(Error::CompactionGroup(format!(
                "Cannot merge creating group {} next_group {}",
                group.group_id, next_group.group_id
            )));
        }

        // do not merge high throughput group
        if !Self::check_is_low_write_throughput_compaction_group(
            table_write_throughput_statistic_manager,
            group,
            opts,
        ) {
            return Err(Error::CompactionGroup(format!(
                "Cannot merge high throughput group {} next_group {}",
                group.group_id, next_group.group_id
            )));
        }

        let size_limit = (group.compaction_group_config.max_estimated_group_size() as f64
            * opts.split_group_size_ratio) as u64;