{"record":{"id":"e9b109b73d9c0a3f","repo":"weaviate/weaviate","slug":"clean-prior-replica-snapshot-for-op-q-w","errorCode":null,"errorMessage":"clean prior replica snapshot for op %q: %w","messagePattern":"clean prior replica snapshot for op %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"adapters/repos/db/replica_snapshot.go","lineNumber":58,"sourceCode":"\nfunc (i *Index) IncomingCreateReplicaSnapshot(ctx context.Context, shardName, opID string) ([]string, error) {\n\t// Target retries can land twice server-side for the same opID; without\n\t// this lock they race on the staging dir.\n\ti.replicaSnapshotOpLocks.Lock(opID)\n\tdefer i.replicaSnapshotOpLocks.Unlock(opID)\n\n\tshard, release, err := i.GetShard(ctx, shardName)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"incoming create replica snapshot get shard %s: %w\", shardName, err)\n\t}\n\tdefer release()\n\tif shard == nil {\n\t\treturn nil, fmt.Errorf(\"incoming create replica snapshot: shard %q not found\", shardName)\n\t}\n\n\t// On retry the prior snapshot may be stale relative to current shard contents.\n\tif rerr := i.releaseReplicaSnapshot(ctx, opID, shard); rerr != nil {\n\t\treturn nil, fmt.Errorf(\"clean prior replica snapshot for op %q: %w\", opID, rerr)\n\t}\n\n\tstagingRoot := replicaStagingDir(i.Config.RootPath, opID, schema.ClassName(i.Config.ClassName))\n\tif err := os.MkdirAll(stagingRoot, 0o755); err != nil {\n\t\treturn nil, fmt.Errorf(\"create replica staging dir: %w\", err)\n\t}\n\n\tif file.ProbeHardlinkSupport(i.Config.RootPath) {\n\t\tfiles, err := shard.CreateReplicaSnapshot(ctx, stagingRoot)\n\t\tif err != nil {\n\t\t\ti.cleanupFailedReplicaSnapshot(stagingRoot, opID, false, nil)\n\t\t\treturn nil, err\n\t\t}\n\t\ti.logger.WithField(\"op_id\", opID).WithField(\"shard\", shardName).\n\t\t\tDebugf(\"created replica snapshot: %d files\", len(files))\n\t\ti.recordReplicaSnapshot(opID, replicaSnapshotState{shardName: shardName, isSnapshot: true})\n\t\treturn files, nil\n\t}","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/repos/db/replica_snapshot.go#L40-L76","documentation":"Wraps a failure from releaseReplicaSnapshot when cleaning a prior snapshot for the same opID. On retries of the same opID, a stale snapshot must be released before creating a fresh one; a failure here (e.g. staging-dir removal error) leaves stale state that would race the new snapshot.","triggerScenarios":"Thrown at adapters/repos/db/replica_snapshot.go:58 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect the wrapped cause (disk permissions, staging dir in use) and clear the stale staging dir manually if needed.","Retry the operation once the prior snapshot state is cleaned; the opID lock serializes access.","If repeated, investigate leaked snapshot registrations in Index.replicaSnapshots."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"75aa4b6d11f8818305aafd4440b4e32794f7ca04","analyzedAt":"2026-09-04T14:58:20.392Z","contentChangedAt":"2026-09-04T14:58:20.392Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}