{"record":{"id":"2ab771257be8958e","repo":"geektutu/7days-golang","slug":"invalid-checksum-2ab771","errorCode":null,"errorMessage":"invalid checksum","messagePattern":"invalid checksum","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gee-bolt/day3-tree/meta.go","lineNumber":30,"sourceCode":"type meta struct {\n\tmagic    uint32\n\tpageSize uint32\n\tpgid     uint64\n\tchecksum uint64\n}\n\nfunc (m *meta) sum64() uint64 {\n\tvar h = fnv.New64a()\n\t_, _ = h.Write((*[unsafe.Offsetof(meta{}.checksum)]byte)(unsafe.Pointer(m))[:])\n\treturn h.Sum64()\n}\n\nfunc (m *meta) validate() error {\n\tif m.magic != magic {\n\t\treturn errors.New(\"invalid magic number\")\n\t}\n\tif m.checksum != m.sum64() {\n\t\treturn errors.New(\"invalid checksum\")\n\t}\n\treturn nil\n}\n","sourceCodeStart":12,"sourceCodeEnd":34,"githubUrl":"https://github.com/geektutu/7days-golang/blob/cf3644382101dc13e7fd92e8f5c66cabc51bcd3b/gee-bolt/day3-tree/meta.go#L12-L34","documentation":"The day3-tree meta page passes the magic check but its checksum field does not match the recomputed hash of the meta struct, indicating the metadata page was corrupted or written without updating the checksum.","triggerScenarios":"Torn write during a crash, checksum not recomputed after mutating meta fields, external edits to the file, or reading a partially flushed page.","commonSituations":"Kill -9/power loss between meta update and checksum write; running day3 code against a file mutated by day1 tooling; concurrent writers without locking.","solutions":["Restore from a known-good backup or fall back to the secondary meta page","Re-create the database and reload data","Ensure every meta mutation recomputes m.checksum = m.sum64() before flush","Add fsync-before-rename style write discipline to avoid torn pages"],"exampleFix":"// before\nm.freelist = newPage\n_ = m.writeTo(page) // stale checksum -> invalid checksum\n// after\nm.freelist = newPage\nm.checksum = m.sum64()\n_ = m.writeTo(page)","handlingStrategy":"validation","validationCode":"func metaIsConsistent(m *meta) bool { return m.checksum == m.sum64() }","typeGuard":"func hasValidChecksum(m *meta) bool { return m != nil && m.checksum == m.sum64() }","tryCatchPattern":null,"preventionTips":["Update checksum as part of every meta write transaction","Enable clean shutdown handling (SIGTERM handling) before writes","Maintain backups and test restore procedures","Avoid concurrent uncoordinated writers to the same file"],"tags":["database","corruption","checksum"],"backgroundTag":"checksum-mismatch","analyzedSha":"cf3644382101dc13e7fd92e8f5c66cabc51bcd3b","analyzedAt":"2026-09-03T18:31:24.087Z","contentChangedAt":"2026-09-03T18:31:24.087Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}