Repository: tikv/tikv
File: components/compact-log-backup/src/compaction/exec.rs (Rust)

Code before:
        }
        let wa = WriteRef::parse(&a.value).expect("record a isn't a valid write");
        let wb = WriteRef::parse(&b.value).expect("record b isn't a valid write");

        let sanity_check = |wa: &WriteRef<'_>, wb: &WriteRef<'_>| {
            if wa.write_type == wb.write_type {
                assert_eq!(wa.start_ts, wb.start_ts);
            }
            // This cannot be applied to `Rollback` because `protected` was encoded to
            // `short_value`.
            if wa.write_type == WriteType::Put && wb.write_type == WriteType::Put {
                assert_eq!(wa.short_value, wb.short_value);
            }
        };
        // partial ordering of two conflicting records.
        let partial_cmp = |wa: &WriteRef<'_>, wb: &WriteRef<'_>| {
            use WriteType::*;
            match (wa.write_type, wb.write_type) {
                // Rollback -> Collapsed with Put happens.
                // Should keep the Put.
                (Put, Rollback | Put) if wa.has_overlapped_rollback => Some(Ordering::Greater),
                (Rollback | Put, Put) if wb.has_overlapped_rollback => Some(Ordering::Less),

                // Rollback -> Protected Rollback.
                // Keep the protected one.
                // This was observered in some versions and shouldn't happen in normally.
                (Rollback, Rollback) if wa.is_protected() => Some(Ordering::Greater),
                (Rollback, Rollback) if wb.is_protected() => Some(Ordering::Less),

                // No comparing rule here.
                _ => None,
            }
        };

        sanity_check(&wa, &wb);
        let maybe_ord = partial_cmp(&wa, &wb);
        info!("resolve conflict result."; "conflict_id" => cid, "order" => ?maybe_ord);
        match maybe_ord {
            Some(Ordering::Greater) => std::mem::swap(a, b),
            None => panic!("cannot resolve the conflict {}", cid),

            Some(_) => {}
        }
    }

    fn update_checksum_diff(
        c: &Subcompaction,
        a: &mut Record,
        b: &mut Record,
        diff: &mut ChecksumDiff,
    ) {

Review comment (suggestion):
There's a grammatical error in the comment. The phrase "shouldn't happen in normally" should be "shouldn't happen normally" (remove "in").
```suggestion
                // This was observed in some versions and shouldn't happen normally.
```

Code after:
        }
        let wa = WriteRef::parse(&a.value).expect("record a isn't a valid write");
        let wb = WriteRef::parse(&b.value).expect("record b isn't a valid write");

        let sanity_check = |wa: &WriteRef<'_>, wb: &WriteRef<'_>| {
            if wa.write_type == wb.write_type {
                assert_eq!(wa.start_ts, wb.start_ts);
            }
            // This cannot be applied to `Rollback` because `protected` was encoded to
            // `short_value`.
            if wa.write_type == WriteType::Put && wb.write_type == WriteType::Put {
                assert_eq!(wa.short_value, wb.short_value);
            }
        };
        // partial ordering of two conflicting records.
        let partial_cmp = |wa: &WriteRef<'_>, wb: &WriteRef<'_>| {
            use WriteType::*;
            match (wa.write_type, wb.write_type) {
                // Rollback -> Collapsed with Put happens.
                // Should keep the Put.
                (Put, Rollback | Put) if wa.has_overlapped_rollback => Some(Ordering::Greater),
                (Rollback | Put, Put) if wb.has_overlapped_rollback => Some(Ordering::Less),

                // Rollback -> Protected Rollback.
                // Keep the protected one.
                // This was observed in some versions and shouldn't happen normally.
                (Rollback, Rollback) if wa.is_protected() => Some(Ordering::Greater),
                (Rollback, Rollback) if wb.is_protected() => Some(Ordering::Less),

                // No comparing rule here.
                _ => None,
            }
        };

        sanity_check(&wa, &wb);
        let maybe_ord = partial_cmp(&wa, &wb);
        info!("resolve conflict result."; "conflict_id" => cid, "order" => ?maybe_ord);
        match maybe_ord {
            Some(Ordering::Greater) => std::mem::swap(a, b),
            None => panic!(
                "cannot resolve the conflict {} for key {}",
                cid,
                redact(&a.key)
            ),

            Some(_) => {}
        }
    }

    fn update_checksum_diff(
        c: &Subcompaction,