{"record":{"id":"2bf3a6919105bb06","repo":"ipfs/kubo","slug":"creating-delete-batch-w","errorCode":null,"errorMessage":"creating delete batch: %w","messagePattern":"creating delete batch: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/node/storage.go","lineNumber":227,"sourceCode":"\t}\n\tdefer results.Close()\n\n\tvar batch datastore.Batch\n\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)","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/ipfs/kubo/blob/329838acdfafae224582930457efe80aa217afc0/core/node/storage.go#L209-L245","documentation":"Raised by deleteStaleDHTValueRecords when ds.Batch(ctx) fails while preparing the batch used to delete stale DHT value records. The datastore does not support or cannot currently create a batch. The purge aborts with keys-deleted-so-far returned and is retried on the next daemon start.","triggerScenarios":"First stale key is found and ds.Batch fails — datastore backend lacks batching support, is closing, or is in an error state (e.g. after corruption or during shutdown).","commonSituations":"Using a datastore wrapper that doesn't implement Batching, datastore shutdown racing the migration at daemon stop, or a corrupted/failing datastore.","solutions":["Check the wrapped error; ensure the configured datastore supports batching (all built-in kubo datastores do)","Avoid shutting the daemon down during startup migration; let the purge finish","Verify datastore health and restart the daemon — the purge retries on next start","Check disk space/permissions on the repo directory"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if _, err := ds.Batch(ctx); err != nil {\n    log.Warnf(\"datastore batching unavailable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"count, err := deleteStaleDHTValueRecords(ctx, ds)\nif err != nil && strings.Contains(err.Error(), \"creating delete batch\") {\n    // check datastore health; purge retries next start\n}","preventionTips":["Use built-in kubo datastores which all support batching","Avoid stopping the daemon during startup migrations","Check datastore error state before running migrations"],"tags":["datastore","batch","migration","dht","purge"],"backgroundTag":"datastore-batch-create-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"}