{"record":{"id":"0d241aecf143c2f0","repo":"thanos-io/thanos","slug":"postings-entries-must-be-in-increasing-order-curr","errorCode":null,"errorMessage":"postings entries must be in increasing order, current: %d, previous: %d","messagePattern":"postings entries must be in increasing order, current: (.+?), previous: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/postings_codec.go","lineNumber":112,"sourceCode":"\tcompressedBuf := bytes.NewBuffer(make([]byte, 0, estimateSnappyStreamSize(length)))\n\tif n, err := compressedBuf.WriteString(codecHeaderStreamedSnappy); err != nil {\n\t\treturn nil, fmt.Errorf(\"writing streamed snappy header\")\n\t} else if n != len(codecHeaderStreamedSnappy) {\n\t\treturn nil, fmt.Errorf(\"short-write streamed snappy header\")\n\t}\n\n\tuvarintEncodeBuf := make([]byte, binary.MaxVarintLen64)\n\n\tsw, err := extsnappy.Compressor.Compress(compressedBuf)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"creating snappy compressor: %w\", err)\n\t}\n\n\tprev := storage.SeriesRef(0)\n\tfor p.Next() {\n\t\tv := p.At()\n\t\tif v < prev {\n\t\t\treturn nil, errors.Errorf(\"postings entries must be in increasing order, current: %d, previous: %d\", v, prev)\n\t\t}\n\n\t\tuvarintSize := binary.PutUvarint(uvarintEncodeBuf, uint64(v-prev))\n\t\tif written, err := sw.Write(uvarintEncodeBuf[:uvarintSize]); err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"writing uvarint encoded byte\")\n\t\t} else if written != uvarintSize {\n\t\t\treturn nil, errors.Wrap(err, \"short-write for uvarint encoded byte\")\n\t\t}\n\n\t\tprev = v\n\t}\n\tif p.Err() != nil {\n\t\treturn nil, p.Err()\n\t}\n\tif err := sw.Close(); err != nil {\n\t\treturn nil, errors.Wrap(err, \"closing snappy stream writer\")\n\t}\n","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/postings_codec.go#L94-L130","documentation":"The diff+varint encoding stores deltas between consecutive series refs, so postings MUST arrive in strictly increasing order. The encoder returns this error when a posting value is lower than the previous one, because a negative delta cannot be uvarint-encoded.","triggerScenarios":"encodePostingsToCache -> diffVarintSnappyStreamedEncode when p.At() returns a value < prev: an index.Postings iterator yielding out-of-order series refs.","commonSituations":"Corrupted index postings lists on disk; custom/buggy Postings implementations returning unordered refs; data race in the posting list construction.","solutions":["Fix the source of the unordered postings (usually corrupted index data)","Run tsdb recovery / delete and rebuild affected block index files","If implementing a custom Postings type, sort refs before iteration"],"exampleFix":"// before: custom Postings emitting unordered refs\nrefs := []uint64{5, 3, 9}\n// after: sort before returning\nsort.Slice(refs, func(i, j int) bool { return refs[i] < refs[j] })","handlingStrategy":"validation","validationCode":"func postingsAreSorted(p index.Postings) (bool, error) {\n    prev := storage.SeriesRef(0)\n    for p.Next() {\n        v := p.At()\n        if v < prev { return false, nil }\n        prev = v\n    }\n    return p.Err() == nil, p.Err()\n}","typeGuard":null,"tryCatchPattern":"b, err := diffVarintSnappyStreamedEncode(p, length)\nif err != nil {\n    if strings.Contains(err.Error(), \"must be in increasing order\") {\n        return nil, fmt.Errorf(\"corrupt postings list: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Always construct postings lists from sorted refs (tsdb guarantees this)","Validate custom index.Postings implementations emit strictly increasing refs","Rebuild index files when corruption is detected instead of re-encoding"],"tags":["postings","corruption","index"],"backgroundTag":"invalid-argument-value","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"}