{"record":{"id":"e736077b39bd62d0","repo":"ipfs/kubo","slug":"batch-deleting-stale-key-s-w","errorCode":null,"errorMessage":"batch deleting stale key %s: %w","messagePattern":"batch deleting stale key (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/node/storage.go","lineNumber":231,"sourceCode":"\tvar count, pending int\n\tfor result := range results.Next() {\n\t\tif ctx.Err() != nil {\n\t\t\treturn count, ctx.Err()\n\t\t}\n\t\tif result.Error != nil {\n\t\t\treturn count, fmt.Errorf(\"iterating datastore keys: %w\", result.Error)\n\t\t}\n\t\tif !isStaleDHTValueRecordKey(result.Key) {\n\t\t\tcontinue\n\t\t}\n\t\tif batch == nil {\n\t\t\tbatch, err = ds.Batch(ctx)\n\t\t\tif err != nil {\n\t\t\t\treturn count, fmt.Errorf(\"creating delete batch: %w\", err)\n\t\t\t}\n\t\t}\n\t\tif err := batch.Delete(ctx, datastore.NewKey(result.Key)); err != nil {\n\t\t\treturn count, fmt.Errorf(\"batch deleting stale key %s: %w\", result.Key, err)\n\t\t}\n\t\tcount++\n\t\tpending++\n\t\tif pending >= purgeBatchSize {\n\t\t\tif err := batch.Commit(ctx); err != nil {\n\t\t\t\treturn count, fmt.Errorf(\"committing delete batch: %w\", err)\n\t\t\t}\n\t\t\tbatch = nil\n\t\t\tpending = 0\n\t\t}\n\t}\n\tif pending > 0 {\n\t\tif err := batch.Commit(ctx); err != nil {\n\t\t\treturn count, fmt.Errorf(\"committing delete batch: %w\", err)\n\t\t}\n\t}\n\tif count > 0 {\n\t\tif err := ds.Sync(ctx, datastore.NewKey(\"/\")); err != nil {","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/node/storage.go#L213-L249","documentation":"Raised by deleteStaleDHTValueRecords when batch.Delete(ctx, key) fails for a specific stale DHT value record key. The wrapped message includes the offending key, pinpointing which datastore entry could not be deleted. The purge stops; already-deleted keys are counted and the operation retries on the next daemon start.","triggerScenarios":"During the purge, a batch Delete on a matched stale key fails — typically an underlying datastore write error (disk full, I/O error, key locked by backend constraints, context cancelled).","commonSituations":"Disk full on the node, failing storage device, badger write errors after crash recovery, or daemon shutdown cancelling the context mid-purge.","solutions":["Free disk space / fix I/O problems indicated by the wrapped error","Note the failing key from the log message and inspect datastore health around it","Restart the daemon to resume the purge (it retries from scratch, skipping already-deleted keys)","Ensure the node isn't shut down mid-migration"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// ensure disk has space before deletion-heavy migrations\nif freeSpace(repoPath) < minFreeBytes {\n    return fmt.Errorf(\"insufficient space to run datastore purge\")\n}","typeGuard":null,"tryCatchPattern":"count, err := deleteStaleDHTValueRecords(ctx, ds)\nif err != nil {\n    // error message includes the failing key: log it for triage\n    log.Warnw(\"stale DHT purge failed\", \"error\", err)\n}","preventionTips":["Keep free disk headroom","Fix failing storage devices promptly","Do not interrupt the daemon during the startup purge"],"tags":["datastore","batch","delete","migration","dht"],"backgroundTag":"datastore-delete-failed","analyzedSha":"329838acdfafae224582930457efe80aa217afc0","analyzedAt":"2026-09-03T18:30:52.135Z","contentChangedAt":"2026-09-03T18:30:52.135Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}