{"record":{"id":"750d23eb9843b97f","repo":"apache/pulsar","slug":"failed-to-update-to-value-s","errorCode":null,"errorMessage":"Failed to update to value:%s","messagePattern":"Failed to update to value:(.+?)","errorType":"exception","errorClass":"ConflictException","httpStatus":null,"severity":"error","filePath":"pulsar-metadata/src/main/java/org/apache/pulsar/metadata/tableview/impl/MetadataStoreTableViewImpl.java","lineNumber":418,"sourceCode":"    }\n\n    public T get(String key) {\n        return data.get(key);\n    }\n\n    public CompletableFuture<Void> put(String key, T value) {\n        String path = getPath(key);\n        return cache.readModifyUpdateOrCreate(path, (old) -> {\n            if (conflictResolver.test(old.orElse(null), value)) {\n                return value;\n            } else {\n                throw new ConflictException(\n                        String.format(\"Failed to update from old:%s to value:%s\", old, value));\n            }\n        }).thenCompose(__ -> doHandleNotification(path)) // immediately notify local tableview\n        .exceptionally(e -> {\n            if (e.getCause() instanceof MetadataStoreException.BadVersionException) {\n                throw FutureUtil.wrapToCompletionException(new ConflictException(\n                        String.format(\"Failed to update to value:%s\", value)));\n            }\n\n            throw FutureUtil.wrapToCompletionException(e.getCause());\n        });\n    }\n\n    public CompletableFuture<Void> delete(String key) {\n        String path = getPath(key);\n        return cache.delete(path)\n                .thenCompose(__ -> doHandleNotification(path)); // immediately notify local tableview\n    }\n\n    public int size() {\n        return immutableData.size();\n    }\n\n    public boolean isEmpty() {","sourceCodeStart":400,"sourceCodeEnd":436,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-metadata/src/main/java/org/apache/pulsar/metadata/tableview/impl/MetadataStoreTableViewImpl.java#L400-L436","documentation":"ConflictException thrown by MetadataStoreTableViewImpl.put when the underlying metadata-store update fails with BadVersionException, meaning another writer changed the entry between the cached read and the CAS update attempt.","triggerScenarios":"Two clients call put on the same key concurrently; the second update's expected version no longer matches the store's version, so cache.readModifyUpdateOrCreate fails with MetadataStoreException.BadVersionException and is translated into this ConflictException.","commonSituations":"Multiple brokers/producers writing the same tableview key at once, a delete racing with a put on the same key, or retry loops that hammer one hot key.","solutions":["Catch ConflictException from the put future and retry with a fresh read (the tableview re-reads before next attempt).","Use a distinct key per writer, or shard keys to avoid hot-key contention.","Enable/verify the conflictResolver design accounts for optimistic-concurrency retries.","Reduce write frequency to the same key, or serialize writes through a single owner."],"exampleFix":"// before\nreturn cache.readModifyUpdateOrCreate(path, mutator);\n// after\nreturn FutureUtil.retryFailedAsync(() -> cache.readModifyUpdateOrCreate(path, mutator), retryPolicy);","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"CompletableFuture<Void> put = tableView.put(key, value);\nput.exceptionally(ex -> {\n    if (FutureUtil.unwrapCompletionException(ex) instanceof ConflictException) {\n        // BadVersion case: retry after fresh read with backoff\n        return null;\n    }\n    throw FutureUtil.wrapToCompletionException(ex);\n});","preventionTips":["Implement bounded retry with jitter for hot keys.","Shard or namespace keys so concurrent writers don't CAS the same entry.","Minimize read-modify-write windows; compute the new value quickly.","Consider serializing writes through a single owner/leader for shared keys."],"tags":["conflict","badversion","concurrency","optimistic-locking"],"backgroundTag":"write-conflict","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}