{"record":{"id":"2e288ec80ec39c9d","repo":"thanos-io/thanos","slug":"add-series","errorCode":null,"errorMessage":"add series","messagePattern":"add series","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/block/index.go","lineNumber":673,"sourceCode":"\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}\n\t\t\tvalset.set(l.Value)\n\t\t})\n\t\tpostings.Add(i, s.lset)","sourceCodeStart":655,"sourceCodeEnd":691,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/block/index.go#L655-L691","documentation":"During rewrite(), each sorted series is added to the new index writer via indexw.AddSeries. A failure wrapped as \"add series\" means the TSDB index writer rejected adding series i with its labels and chunk metas — usually a validation failure in the new index being built.","triggerScenarios":"indexw.AddSeries(i, s.lset, s.chks...) errors during rewrite/Repair: typically labels invalid (duplicate label names), series out of order relative to the writer's expectations, chunk metas invalid (e.g. empty chunks, wrong ordering), or an I/O error writing symbol/series entries.","commonSituations":"Repairing blocks that contain malformed series created by an older Prometheus version or by a buggy compaction; blocks with duplicate/out-of-order series discovered during verification and repair; corrupted index producing invalid chunk metadata that fails writer validation.","solutions":["Inspect the wrapped cause to see which series/chunk validation failed (labelset is in the rewrite log for duplicates)","Delete the corrupted block from the bucket so the Thanos compactor repairs or removes it, instead of repeatedly rewriting","Verify the source block (`thanos tools bucket verify`) and confirm the Prometheus version that produced it is supported","Retry after fixing underlying I/O/permission errors if the cause is disk-level"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"for _, s := range series {\n\tif labels.HasDuplicateLabelNames(s.lset) {\n\t\treturn errors.Errorf(\"series %s has duplicate label names, block corrupt\", s.lset)\n\t}\n\tfor _, c := range s.chks {\n\t\tif c.MaxTime <= c.MinTime { return errors.Errorf(\"invalid chunk in series %s\", s.lset) }\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := rewrite(...); err != nil {\n\tvar idxErr *index.ValidationError\n\tif goerrors.As(errors.Cause(err), &idxErr) {\n\t\t// writer rejected a series/chunk: treat block as corrupt, delete & re-sync\n\t\treturn markBlockCorrupt(ctx, bkt, id)\n\t}\n\treturn err\n}","preventionTips":["Verify the source index before repair so malformed series are caught before writing","Keep Prometheus/Thanos versions current; older bugs produced invalid series labels","If AddSeries fails repeatedly on the same block, delete the block and let compactor repair from replicas","Log the failing series labelset (rewrite already logs duplicates) to speed triage"],"tags":["thanos","tsdb","index-write","block-rewrite","corruption"],"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"}