{"record":{"id":"072e4907f3261da8","repo":"apache/pulsar","slug":"failed-to-set-data-for-path","errorCode":null,"errorMessage":"Failed to set data for ${path}","messagePattern":"Failed to set data for (.+?)","errorType":"exception","errorClass":"MetadataStoreException","httpStatus":null,"severity":"error","filePath":"pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/BaseResources.java","lineNumber":159,"sourceCode":"    protected CompletableFuture<Optional<T>> getAsync(String path) {\n        return cache.get(path);\n    }\n\n    protected CompletableFuture<Optional<T>> refreshAndGetAsync(String path) {\n        return store.sync(path).thenCompose(___ -> {\n            cache.invalidate(path);\n            return cache.get(path);\n        });\n    }\n\n    protected void set(String path, Function<T, T> modifyFunction) throws MetadataStoreException {\n        try {\n            setAsync(path, modifyFunction).get(operationTimeoutSec, TimeUnit.SECONDS);\n        } catch (ExecutionException e) {\n            throw (e.getCause() instanceof MetadataStoreException) ? (MetadataStoreException) e.getCause()\n                    : new MetadataStoreException(e.getCause());\n        } catch (Exception e) {\n            throw new MetadataStoreException(\"Failed to set data for \" + path, e);\n        }\n    }\n\n    protected CompletableFuture<Void> setAsync(String path, Function<T, T> modifyFunction) {\n        return cache.readModifyUpdate(path, modifyFunction).thenApply(__ -> null);\n    }\n\n    protected void setWithCreate(String path, Function<Optional<T>, T> createFunction) throws MetadataStoreException {\n        try {\n            setWithCreateAsync(path, createFunction).get(operationTimeoutSec, TimeUnit.SECONDS);\n        } catch (ExecutionException e) {\n            throw (e.getCause() instanceof MetadataStoreException) ? (MetadataStoreException) e.getCause()\n                    : new MetadataStoreException(e.getCause());\n        } catch (Exception e) {\n            throw new MetadataStoreException(\"Failed to set/create \" + path, e);\n        }\n    }\n","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/BaseResources.java#L141-L177","documentation":"BaseResources.set performs a read-modify-update through the cache and blocks until completion; failures (store errors, optimistic-concurrency retries exhausted, timeout, interruption) are converted into MetadataStoreException('Failed to set data for <path>'). It means a policy/resource update could not be persisted at that path.","triggerScenarios":"Calling set(path, modifyFunction) when the readModifyUpdate fails due to store write errors, version/BadVersion conflicts after retries, operation timeout, or interruption.","commonSituations":"Concurrent admin updates racing on the same path; metadata store read-only or quorum loss; ZooKeeper BadVersionException due to simultaneous writers; timeout too small during heavy update traffic.","solutions":["Retry the update if caused by concurrent modification (the cache retries, but heavy contention can still fail)","Check metadata store write access and quorum health","Increase operationTimeoutSec for large policy documents","Serialize admin updates for the same resource to reduce version conflicts"],"exampleFix":"// before\nnsResources.set(path, policies -> { policies.auth_policies.put(...); return policies; });\n// after\ntry {\n    nsResources.set(path, policies -> { policies.auth_policies.put(...); return policies; });\n} catch (MetadataStoreException e) {\n    if (e.getCause() instanceof MetadataStoreException.BadVersionException) {\n        // retry once after re-reading current policies\n    } else { throw e; }\n}","handlingStrategy":"retry","validationCode":"if (!resources.exists(path)) throw new IllegalStateException(\"Cannot set: path missing \" + path);","typeGuard":null,"tryCatchPattern":"try { resources.set(path, modifier); }\ncatch (MetadataStoreException e) {\n    if (e.getCause() instanceof MetadataStoreException.BadVersionException) { /* re-read and retry */ }\n    else throw e;\n}","preventionTips":["Minimize concurrent admin writers per resource","Retry version-conflict failures with fresh reads","Ensure store quorum health before bulk updates"],"tags":["metadata-store","write-failure","concurrency","exception-wrapping"],"backgroundTag":"metadata-store-operation-failed","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}