Repository: risingwavelabs/risingwave
File: src/storage/src/hummock/sstable/block.rs (Rust)

Code before:
        match self.table_id {
            Some(current_table_id) => assert_eq!(current_table_id, input_table_id),
            None => self.table_id = Some(input_table_id),
        }
        #[cfg(debug_assertions)]
        self.debug_valid();

        let mut key: BytesMut = Default::default();
        full_key.encode_into_without_table_id(&mut key);

        // Call the core implementation with encoded key
        self.add_encoded_impl(&key, value);
    }

    /// Core implementation that accepts pre-encoded key.
    /// This is used by both `add` and `add_encoded` to avoid code duplication.
    fn add_encoded_impl(&mut self, key: &[u8], value: &[u8]) {
        if self.entry_count > 0 {
            debug_assert!(!key.is_empty());
            debug_assert_eq!(
                KeyComparator::compare_encoded_full_key(&self.last_key[..], key),
                Ordering::Less,
            );
        }
        // Update restart point if needed and calculate diff key.
        let k_type = LenType::new(key.len());
        let v_type = LenType::new(value.len());

        let type_mismatch = if let Some(RestartPoint {
            offset: _,
            key_len_type: last_key_len_type,
            value_len_type: last_value_len_type,
        }) = self.restart_points_type_index.last()
        {
            k_type != *last_key_len_type || v_type != *last_value_len_type
        } else {
            true
        };

        let diff_key = if self.entry_count.is_multiple_of(self.restart_count) || type_mismatch {
            let offset = utils::checked_into_u32(self.buf.len()).unwrap_or_else(|_| {
                panic!(
                    "WARN overflow can't convert buf_len {} into u32 table {:?}",
                    self.buf.len(),
                    self.table_id,
                )
            });

            self.restart_points.push(offset);

            if type_mismatch {

Review comment (bug):
The debug_assert! message was removed when simplifying the comparison. This makes debugging ordering violations much harder since developers won't know which key failed the assertion. Consider preserving the informative error message or adding a comment explaining why it was removed.
```suggestion
                Ordering::Less,
                "BlockBuilder keys must be strictly increasing: last_key={:?}, new_key={:?}, table_id={:?}",
                self.last_key,
                key,
                self.table_id,
```

Code after:
        let input_table_id = full_key.user_key.table_id;
        match self.table_id {
            Some(current_table_id) => assert_eq!(current_table_id, input_table_id),
            None => self.table_id = Some(input_table_id),
        }
        #[cfg(debug_assertions)]
        self.debug_valid();

        let mut key: BytesMut = Default::default();
        full_key.encode_into(&mut key);

        // Slice off the table_id prefix to get the key without table_id
        let encoded_key_without_table_id = &key[TABLE_PREFIX_LEN..];

        // Call the core implementation with encoded key
        self.add_encoded_impl(encoded_key_without_table_id, value);
    }

    /// Core implementation that accepts pre-encoded key.
    /// This is used by both `add` and `add_for_test` to avoid code duplication.
    fn add_encoded_impl(&mut self, key: &[u8], value: &[u8]) {
        if self.entry_count > 0 {
            debug_assert!(!key.is_empty());
            debug_assert_eq!(
                KeyComparator::compare_encoded_full_key(&self.last_key[..], key),
                Ordering::Less,
            );
        }
        // Update restart point if needed and calculate diff key.
        let k_type = LenType::new(key.len());
        let v_type = LenType::new(value.len());

        let type_mismatch = if let Some(RestartPoint {
            offset: _,
            key_len_type: last_key_len_type,
            value_len_type: last_value_len_type,
        }) = self.restart_points_type_index.last()
        {
            k_type != *last_key_len_type || v_type != *last_value_len_type
        } else {
            true
        };

        let diff_key = if self.entry_count.is_multiple_of(self.restart_count) || type_mismatch {
            let offset = utils::checked_into_u32(self.buf.len()).unwrap_or_else(|_| {
                panic!(
                    "WARN overflow can't convert buf_len {} into u32 table {:?}",
                    self.buf.len(),
                    self.table_id,
                )
            });