{"record":{"id":"59cb7561bfde6fc4","repo":"t8y2/dbx","slug":"etcd-compacted","errorCode":"ETCD_COMPACTED","errorMessage":"ETCD_COMPACTED: requested history was compacted at revision ","messagePattern":"ETCD_COMPACTED: requested history was compacted at revision ","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/etcd-go/history.go","lineNumber":67,"sourceCode":"\tif limit < 1 {\n\t\tlimit = 1\n\t}\n\tif limit > historyLimitMax {\n\t\tlimit = historyLimitMax\n\t}\n\trequestedEnd := longOrNull(params, \"endRevision\")\n\n\tctx, cancel := context.WithTimeout(context.Background(), rpcTimeoutSeconds*time.Second)\n\tlatestOptions := []clientv3.OpOption{}\n\tif requestedEnd != nil && *requestedEnd > 0 {\n\t\tlatestOptions = append(latestOptions, clientv3.WithRev(*requestedEnd))\n\t}\n\tlatest, err := client.Get(ctx, key, latestOptions...)\n\tcancel()\n\tif err != nil {\n\t\tif errors.Is(err, rpctypes.ErrCompacted) {\n\t\t\tif revision, ok := compactedRevisionOf(client, key); ok {\n\t\t\t\treturn nil, errors.New(\"ETCD_COMPACTED: requested history was compacted at revision \" + longString(revision))\n\t\t\t}\n\t\t\treturn nil, errors.New(\"ETCD_COMPACTED: requested history was compacted\")\n\t\t}\n\t\treturn nil, err\n\t}\n\tvar endRevision int64\n\tif requestedEnd != nil {\n\t\tendRevision = *requestedEnd\n\t} else {\n\t\tendRevision = latest.Header.Revision\n\t}\n\tvar targetKeyRevision int64\n\tif len(latest.Kvs) == 0 {\n\t\ttargetKeyRevision = endRevision\n\t} else {\n\t\ttargetKeyRevision = latest.Kvs[0].ModRevision\n\t}\n\trequestedStart := longOrNull(params, \"startRevision\")","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/etcd-go/history.go#L49-L85","documentation":"The initial Get that anchors the history query (WithRev at endRevision) failed with etcd's ErrCompacted, meaning the requested revision precedes the cluster's compaction boundary and its MVCC history has been discarded. The library then probes the compaction revision with a rev-1 watch and reports it in the message; if the probe fails it falls back to the generic ETCD_COMPACTED message (error 335).","triggerScenarios":"Calling history with endRevision older than the cluster's current compact revision, or with a very old default window (10000 revisions) on a cluster that compacts aggressively; the Get at that revision returns rpctypes.ErrCompacted.","commonSituations":"Replaying an old snapshot/audit query after the etcd server auto-compacted; long-lived clients with stale revision bookmarks; clusters with short --auto-compaction-retention and infrequent history queries.","solutions":["Re-run history without endRevision (or with a recent one) so the query anchors at the current revision.","Increase etcd's --auto-compaction-retention to retain more history.","Clamp startRevision to the compact revision reported; never query below it.","Persist and use the revision reported in the error message as the new lower bound for future queries."],"exampleFix":"// before\nresult, err := session.history(map[string]json.RawMessage{\"endRevision\": json.RawMessage(\"50\")}) // compacted\n// after\n// omit stale endRevision, or use the reported compact revision + 1\nresult, err := session.history(map[string]json.RawMessage{})","handlingStrategy":"fallback","validationCode":"compactRev := lastKnownCompactRevision() // track from prior ETCD_COMPACTED errors\nif endRevision != nil && *endRevision <= compactRev {\n\tendRevision = nil // anchor at latest instead of a compacted revision\n}","typeGuard":null,"tryCatchPattern":"result, err := session.history(params)\nif err != nil {\n\tif strings.HasPrefix(err.Error(), \"ETCD_COMPACTED\") {\n\t\tparams = dropEndRevision(params) // fall back to latest-revision anchor\n\t\tresult, err = session.history(params)\n\t}\n\tif err != nil { return nil, err }\n}","preventionTips":["Track the last known compact revision and clamp endRevision/startRevision above it.","Increase etcd --auto-compaction-retention to retain queried history windows.","Avoid caching old revision bookmarks across long periods.","Handle the ETCD_COMPACTED prefix explicitly and retry anchored at the latest revision."],"tags":["etcd","compaction","mvcc","history"],"backgroundTag":"etcd-mvcc-compacted","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}