{"record":{"id":"2831b681225d6f44","repo":"thanos-io/thanos","slug":"write-chunks","errorCode":null,"errorMessage":"write chunks","messagePattern":"write chunks","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/index.go","lineNumber":670,"sourceCode":"\n\tlastSet := labels.Labels{}\n\t// Build a new TSDB block.\n\tfor _, s := range series {\n\t\t// The TSDB library will throw an error if we add a series with\n\t\t// identical labels as the last series. This means that we have\n\t\t// discovered a duplicate time series in the old block. We drop\n\t\t// all duplicate series preserving the first one.\n\t\t// TODO: Add metric to count dropped series if repair becomes a daemon\n\t\t// rather than a batch job.\n\t\tif labels.Compare(lastSet, s.lset) == 0 {\n\t\t\tlevel.Warn(logger).Log(\"msg\",\n\t\t\t\t\"dropping duplicate series in tsdb block found\",\n\t\t\t\t\"labelset\", s.lset.String(),\n\t\t\t)\n\t\t\tcontinue\n\t\t}\n\t\tif err := chunkw.WriteChunks(s.chks...); err != nil {\n\t\t\treturn errors.Wrap(err, \"write chunks\")\n\t\t}\n\t\tif err := indexw.AddSeries(i, s.lset, s.chks...); err != nil {\n\t\t\treturn errors.Wrap(err, \"add series\")\n\t\t}\n\n\t\tmeta.Stats.NumChunks += uint64(len(s.chks))\n\t\tmeta.Stats.NumSeries++\n\n\t\tfor _, chk := range s.chks {\n\t\t\tmeta.Stats.NumSamples += uint64(chk.Chunk.NumSamples())\n\t\t}\n\n\t\ts.lset.Range(func(l labels.Label) {\n\t\t\tvalset, ok := values[l.Name]\n\t\t\tif !ok {\n\t\t\t\tvalset = stringset{}\n\t\t\t\tvalues[l.Name] = valset\n\t\t\t}","sourceCodeStart":652,"sourceCodeEnd":688,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/index.go#L652-L688","documentation":"During rewrite(), after collecting and sorting series, each series' chunks are written to the new index file with indexw.WriteChunks. Failure here is wrapped with \"write chunks\". This means writing chunk metadata (chunk metas, offsets, CRCs) into the new TSDB index failed.","triggerScenarios":"chunkw.WriteChunks(s.chks...) returns an error during rewrite/Repair — typically because the underlying index writer hit an I/O error (disk full, permission denied on tmp dir), or a chunk is malformed/overlapping so the TSDB index writer rejects it.","commonSituations":"Disk full on the volume holding the repair tmp directory when running compactor repair; corrupted chunk metadata carried over from a damaged source index causing writer validation failures; filesystem permission problems in the block directory.","solutions":["Check the wrapped cause: if it is a disk/space or permission error, free space or fix permissions on the tmp repair directory and rerun the repair","Verify the source block for corruption (`thanos tools bucket verify`); if chunks themselves are corrupt, delete the block so compactor repairs or re-syncs it","Re-download the block from object storage to get an intact copy before rewriting","Retry the repair operation after transient I/O failures"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"func ensureDiskSpace(dir string, minBytes uint64) error {\n\tvar st syscall.Statfs_t\n\tif err := syscall.Statfs(dir, &st); err != nil { return err }\n\tif uint64(st.Bavail)*uint64(st.Bsize) < minBytes {\n\t\treturn errors.Errorf(\"insufficient space in %s\", dir)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if err := rewrite(...); err != nil {\n\tif errors.Is(errors.Cause(err), syscall.ENOSPC) {\n\t\t// free space / use another volume, then retry\n\t} else if isPermErr(errors.Cause(err)) {\n\t\t// fix tmp dir permissions\n\t}\n\treturn err\n}","preventionTips":["Keep enough free space on the tmp/repair volume (index rewrite roughly doubles index size temporarily)","Run the compactor/repair process with write access to the block cache dir","Verify blocks before rewriting to avoid carrying corrupt chunk metas into the new index","Watch filesystem error metrics; retry transient I/O failures once"],"tags":["thanos","tsdb","index-write","disk-io","block-rewrite"],"backgroundTag":"database-write-failed","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}