{"record":{"id":"4dbdf7989addf8e3","repo":"thanos-io/thanos","slug":"add-series-4dbdf7","errorCode":null,"errorMessage":"add series","messagePattern":"add series","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compact/downsample/streamed_block_writer.go","lineNumber":127,"sourceCode":"// labelsValues sets and memPostings to be written on the finalize state in the end of downsampling process.\nfunc (w *streamedBlockWriter) WriteSeries(lset labels.Labels, chunks []chunks.Meta) error {\n\tif w.finalized || w.ignoreFinalize {\n\t\treturn errors.New(\"series can't be added, writers has been closed or internal error happened\")\n\t}\n\n\tif len(chunks) == 0 {\n\t\tlevel.Warn(w.logger).Log(\"msg\", \"empty chunks happened, skip series\", \"series\", strings.ReplaceAll(lset.String(), \"\\\"\", \"'\"))\n\t\treturn nil\n\t}\n\n\tif err := w.chunkWriter.WriteChunks(chunks...); err != nil {\n\t\tw.ignoreFinalize = true\n\t\treturn errors.Wrap(err, \"add chunks\")\n\t}\n\n\tif err := w.indexWriter.AddSeries(w.seriesRefs, lset, chunks...); err != nil {\n\t\tw.ignoreFinalize = true\n\t\treturn errors.Wrap(err, \"add series\")\n\t}\n\n\tw.seriesRefs++\n\n\tw.totalChunks += uint64(len(chunks))\n\tfor i := range chunks {\n\t\tw.totalSamples += uint64(chunks[i].Chunk.NumSamples())\n\t}\n\n\treturn nil\n}\n\n// Close calls finalizer to complete index and meta files and closes all io.CLoser writers.\n// Idempotent.\nfunc (w *streamedBlockWriter) Close() error {\n\tif w.finalized {\n\t\treturn nil\n\t}","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/compact/downsample/streamed_block_writer.go#L109-L145","documentation":"WriteSeries rejects the series because the streamedBlockWriter has already been finalized (Close called) or an earlier error set ignoreFinalize, so the block directory is closed for writes. It fires when Downsample keeps feeding series after the writer's lifecycle has ended.","triggerScenarios":"Thrown at pkg/compact/downsample/streamed_block_writer.go:127 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure all WriteSeries calls happen before Close and stop writing once finalize started.","Check the earlier error that set ignoreFinalize instead of retrying writes.","Return the error to the caller (Downsample) and abort the current block."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}