{"record":{"id":"82ed4d0a2ef291b9","repo":"tikv/tikv","slug":"record-b-isn-t-a-valid-write","errorCode":null,"errorMessage":"record b isn't a valid write","messagePattern":"record b isn't a valid write","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"components/compact-log-backup/src/compaction/exec.rs","lineNumber":157,"sourceCode":"    /// In any case out of knowledge.\n    fn resolve(c: &Subcompaction, a: &mut Record, b: &mut Record) {\n        if a == b {\n            return;\n        }\n\n        let cid = rand::random::<u64>();\n        use util::redact;\n        warn!(\"encountering two different values: try to resolve them.\"; \"key\" => redact(&a.key), \n            \"value_a\" => redact(&a.value), \"value_b\" => redact(&b.value), \"conflict_id\" => cid);\n\n        if c.cf != CF_WRITE {\n            panic!(\n                \"encountering two different values but they are not in write CF, it is {}; cid = {}.\",\n                c.cf, cid\n            );\n        }\n        let wa = WriteRef::parse(&a.value).expect(\"record a isn't a valid write\");\n        let wb = WriteRef::parse(&b.value).expect(\"record b isn't a valid write\");\n\n        let sanity_check = |wa: &WriteRef<'_>, wb: &WriteRef<'_>| {\n            if wa.write_type == wb.write_type {\n                assert_eq!(wa.start_ts, wb.start_ts);\n            }\n            // This cannot be applied to `Rollback` because `protected` was encoded to\n            // `short_value`.\n            if wa.write_type == WriteType::Put && wb.write_type == WriteType::Put {\n                assert_eq!(wa.short_value, wb.short_value);\n            }\n        };\n        // partial ordering of two conflicting records.\n        let partial_cmp = |wa: &WriteRef<'_>, wb: &WriteRef<'_>| {\n            use WriteType::*;\n            match (wa.write_type, wb.write_type) {\n                // Rollback -> Collapsed with Put happens.\n                // Should keep the Put.\n                (Put, Rollback | Put) if wa.has_overlapped_rollback => Some(Ordering::Greater),","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/tikv/tikv/blob/78aedc1c81ef3f7d8bacc6e9d09f56460f134937/components/compact-log-backup/src/compaction/exec.rs#L139-L175","documentation":"Same resolve() collision path as the 'record a' panic, but for the second colliding value: WriteRef::parse failed to decode record b as a write-CF entry. Resolution needs both writes' write_type/start_ts to pick a winner, so a malformed record b is fatal.","triggerScenarios":"resolve() on two values for the same key where record b in CF_WRITE is truncated, has an invalid write-type byte, or was written by incompatible code.","commonSituations":"Damaged log-backup artifacts, import tools writing bad values into CF_WRITE, or version drift between data writers and the compactor.","solutions":["Dump the colliding pair and verify record b against the WriteRef encoding.","Drop or regenerate the affected backup segment and re-run the subcompaction.","Audit the producer (import/backup tool version) for format mismatches.","Repair or skip the bad record only after confirming no other consumers depend on it."],"exampleFix":"// before\nlet wb = WriteRef::parse(&b.value).expect(\"record b isn't a valid write\");\n// after\nlet wb = WriteRef::parse(&b.value)\n    .unwrap_or_else(|e| panic!(\"record b at key {:?} is not a valid write: {:?}\", b.key, e));","handlingStrategy":"validation","validationCode":"// pre-validate both sides of a collision before resolve()\nassert!(WriteRef::parse(&a.value).is_ok(), \"record a invalid\");\nassert!(WriteRef::parse(&b.value).is_ok(), \"record b invalid\");","typeGuard":"fn valid_write_ref(v: &[u8]) -> Option<WriteRef<'_>> {\n    WriteRef::parse(v).ok()\n}","tryCatchPattern":null,"preventionTips":["Keep CF_WRITE populated only with WriteRef-encoded values.","Regenerate damaged log-backup segments instead of compacting them.","Verify checksums on backup data before compaction.","Sync writer tool versions with the compactor's expected format."],"tags":["rust","corruption","compaction","log-backup"],"backgroundTag":"corrupt-write-record","analyzedSha":"78aedc1c81ef3f7d8bacc6e9d09f56460f134937","analyzedAt":"2026-09-03T23:31:32.398Z","contentChangedAt":"2026-09-03T23:31:32.398Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}