{"record":{"id":"568f9d313103be87","repo":"dgraph-io/badger","slug":"errchecksummismatch","errorCode":"ErrChecksumMismatch","errorMessage":"checksum mismatch","messagePattern":"checksum mismatch","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"y/checksum.go","lineNumber":18,"sourceCode":"/*\n * SPDX-FileCopyrightText: © 2017-2025 Istari Digital, Inc.\n * SPDX-License-Identifier: Apache-2.0\n */\n\npackage y\n\nimport (\n\tstderrors \"errors\"\n\t\"hash/crc32\"\n\n\t\"github.com/cespare/xxhash/v2\"\n\n\t\"github.com/dgraph-io/badger/v4/pb\"\n)\n\n// ErrChecksumMismatch is returned at checksum mismatch.\nvar ErrChecksumMismatch = stderrors.New(\"checksum mismatch\")\n\n// CalculateChecksum calculates checksum for data using ct checksum type.\nfunc CalculateChecksum(data []byte, ct pb.Checksum_Algorithm) uint64 {\n\tswitch ct {\n\tcase pb.Checksum_CRC32C:\n\t\treturn uint64(crc32.Checksum(data, CastagnoliCrcTable))\n\tcase pb.Checksum_XXHash64:\n\t\treturn xxhash.Sum64(data)\n\tdefault:\n\t\tpanic(\"checksum type not supported\")\n\t}\n}\n\n// VerifyChecksum validates the checksum for the data against the given expected checksum.\nfunc VerifyChecksum(data []byte, expected *pb.Checksum) error {\n\tactual := CalculateChecksum(data, expected.Algo)\n\tif actual != expected.Sum {\n\t\treturn Wrapf(ErrChecksumMismatch, \"actual: %d, expected: %d\", actual, expected.Sum)","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/y/checksum.go#L1-L36","documentation":"ErrChecksumMismatch is a package-level sentinel in y meaning stored data did not match its recorded checksum. It is never returned bare: callers wrap it with context — key_registry.go wraps it when the DATAKEY file's CRC32C over the key-registry payload fails, and value.go wraps it when a value-log entry's checksum over key+value fails during a read of a value pointer. In both cases the underlying bytes on disk are corrupt (bit rot, torn write, wrong encryption key), and the wrap message names which structure failed.","triggerScenarios":"Thrown at y/checksum.go:18 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped message to identify the corrupted structure (DATAKEY registry vs. an individual value-log entry)","For a DATAKEY mismatch: verify you opened the database with the same encryption key; a wrong key almost always produces this error","For value corruption, run value-log GC and rely on Badger's truncation/recovery options to drop the damaged entry or file tail","Restore from backup if the affected data is critical, and check the disk for hardware errors"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2a001d466f6b71a917319a1db41f99860e16e269","analyzedAt":"2026-09-05T13:00:02.264Z","contentChangedAt":"2026-09-05T13:00:02.264Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}