{"record":{"id":"82ffd78b177f1552","repo":"kopia/kopia","slug":"error-optimizing-indexes","errorCode":null,"errorMessage":"error optimizing indexes","messagePattern":"error optimizing indexes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command_index_optimize.go","lineNumber":53,"sourceCode":"\n\tcontentIDs, err := toContentIDs(c.optimizeDropContents)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\topt := indexblob.CompactOptions{\n\t\tMaxSmallBlobs: c.optimizeMaxSmallBlobs,\n\t\tAllIndexes:    c.optimizeAllIndexes,\n\t\tDropContents:  contentIDs,\n\t}\n\n\tif age := c.optimizeDropDeletedOlderThan; age > 0 {\n\t\topt.DropDeletedBefore = rep.Time().Add(-age)\n\t}\n\n\t_, err = rep.ContentManager().CompactIndexes(ctx, opt)\n\n\treturn errors.Wrap(err, \"error optimizing indexes\")\n}\n","sourceCodeStart":35,"sourceCodeEnd":55,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/cli/command_index_optimize.go#L35-L55","documentation":"`kopia index optimize` failed when rep.ContentManager().CompactIndexes returned an error while compacting/merging index blobs according to the provided options (drop-deleted ages, max-concurrency, etc.). The repository's index compaction transaction failed and no useful result was produced.","triggerScenarios":"Running `kopia index optimize` (runOptimizeCommand) where CompactIndexes fails: concurrent index writers blocking compaction, storage write errors while uploading the merged index blob, deletion of source blobs failing, or invalid optimization options.","commonSituations":"Another kopia client (backup/sync) running concurrently against the same repository; read-only or quota-exceeded storage backend; very large index blobs timing out during merge; version mismatch between CLI and repository format.","solutions":["Stop other kopia clients that may be writing indexes concurrently, then re-run optimize.","Retry with reduced concurrency (e.g. --max-concurrency=1) to avoid storage contention.","Check the storage backend for write errors, quota, or permission problems and fix those first.","Upgrade kopia if repository format is newer than the CLI; run `kopia repository status` to compare versions."],"exampleFix":"// before\nkopia index optimize --max-concurrency=16\n// after\nkopia index optimize --max-concurrency=1  # avoid contention with concurrent writers","handlingStrategy":"retry","validationCode":"// refuse to optimize while other clients may be writing\nif activeWriters := checkOtherKopiaClients(); activeWriters > 0 {\n    return fmt.Errorf(\"%d kopia clients active; retry optimize later\", activeWriters)\n}","typeGuard":null,"tryCatchPattern":"_, err = rep.ContentManager().CompactIndexes(ctx, opt)\nif err != nil {\n    return errors.Wrap(err, \"error optimizing indexes\")\n}","preventionTips":["Schedule optimize when no backups or maintenance jobs are running.","Use low --max-concurrency against rate-limited storage.","Ensure the storage backend has write quota and correct permissions.","Keep kopia upgraded to match the repository format version."],"tags":["index-compaction","kopia-cli","storage","concurrency"],"backgroundTag":"index-compaction-failed","analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}