{"record":{"id":"e3d35802e4bb0107","repo":"thanos-io/thanos","slug":"flush","errorCode":null,"errorMessage":"flush","messagePattern":"flush","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/tools_bucket.go","lineNumber":1313,"sourceCode":"\t\t\t\t\tcomp = compactv2.NewDryRun(tbc.tmpDir, logger, changeLog, chunkPool)\n\t\t\t\t} else {\n\t\t\t\t\tcomp = compactv2.New(tbc.tmpDir, logger, changeLog, chunkPool)\n\t\t\t\t}\n\n\t\t\t\tlevel.Info(logger).Log(\"msg\", \"starting rewrite for block\", \"source\", id, \"new\", newID, \"toDelete\", string(deletionsYaml), \"toRelabel\", string(relabelYaml))\n\t\t\t\tif err := comp.WriteSeries(ctx, []block.Reader{b}, d, p, modifiers...); err != nil {\n\t\t\t\t\treturn errors.Wrapf(err, \"writing series from %v to %v\", id, newID)\n\t\t\t\t}\n\n\t\t\t\tif tbc.dryRun {\n\t\t\t\t\tlevel.Info(logger).Log(\"msg\", \"dry run finished. Changes should be printed to stderr\", \"Block ID\", id)\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\tlevel.Info(logger).Log(\"msg\", \"wrote new block after modifications; flushing\", \"source\", id, \"new\", newID)\n\t\t\t\tmeta.Stats, err = d.Flush()\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn errors.Wrap(err, \"flush\")\n\t\t\t\t}\n\t\t\t\tif err := meta.WriteToDir(logger, filepath.Join(tbc.tmpDir, newID.String())); err != nil {\n\t\t\t\t\treturn err\n\t\t\t\t}\n\n\t\t\t\tlevel.Info(logger).Log(\"msg\", \"uploading new block\", \"source\", id, \"new\", newID)\n\t\t\t\tif tbc.promBlocks {\n\t\t\t\t\tif err := block.UploadPromBlock(ctx, logger, insBkt, filepath.Join(tbc.tmpDir, newID.String()), metadata.HashFunc(*hashFunc)); err != nil {\n\t\t\t\t\t\treturn errors.Wrap(err, \"upload\")\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif err := block.Upload(ctx, logger, insBkt, filepath.Join(tbc.tmpDir, newID.String()), metadata.HashFunc(*hashFunc)); err != nil {\n\t\t\t\t\t\treturn errors.Wrap(err, \"upload\")\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlevel.Info(logger).Log(\"msg\", \"uploaded\", \"source\", id, \"new\", newID)\n\n\t\t\t\tif !tbc.dryRun && tbc.deleteBlocks {","sourceCodeStart":1295,"sourceCodeEnd":1331,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/tools_bucket.go#L1295-L1331","documentation":"Wraps the destination writer d.Flush() failing after series were written during rewrite. Flush finalizes the new block's index and chunk files and computes stats; failures indicate local disk problems (no space, I/O error) or an internal error building the index for the newly written data.","triggerScenarios":"tmpDir disk full while flushing the new block; underlying file I/O error; writing a large number of rewritten series exhausting resources; flush failing to build index segments from written chunks.","commonSituations":"Small ephemeral /tmp volume on Kubernetes nodes during a rewrite of large blocks; concurrent processes filling the same volume; memory pressure on large flush operations.","solutions":["Point --tmp.dir to a volume with enough free space for the rewritten block (approx. source block size).","Check wrapped cause for ENOSPC/EIO and fix the disk condition, then clean up partial new-ID dirs in tmpDir and retry.","Rewrite blocks in smaller batches to reduce peak disk usage."],"exampleFix":"// before\nthanos tools bucket rewrite --tmp.dir=/tmp ID\n// after\nthanos tools bucket rewrite --tmp.dir=/mnt/big-volume/thanos-rewrite ID","handlingStrategy":"try-catch","validationCode":"if free, _ := diskFree(tmpDir); free < requiredBytes {\n    return fmt.Errorf(\"insufficient disk in %s\", tmpDir)\n}","typeGuard":null,"tryCatchPattern":"meta.Stats, err = d.Flush()\nif err != nil {\n    return errors.Wrap(err, \"flush: check tmp dir disk space and I/O errors\")\n}","preventionTips":["Point --tmp.dir to a large persistent volume, not ephemeral /tmp","Monitor disk usage during rewrites","Clean up partial new-block dirs in tmpDir before retrying"],"tags":["thanos","compaction","disk","flush"],"backgroundTag":"file-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"}