{"record":{"id":"2725263146cb5957","repo":"apache/pulsar","slug":"failed-to-set-create-path","errorCode":null,"errorMessage":"Failed to set/create ${path}","messagePattern":"Failed to set/create (.+?)","errorType":"exception","errorClass":"MetadataStoreException","httpStatus":null,"severity":"error","filePath":"pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/BaseResources.java","lineNumber":174,"sourceCode":"            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\n    protected CompletableFuture<Void> setWithCreateAsync(String path, Function<Optional<T>, T> createFunction) {\n        return cache.readModifyUpdateOrCreate(path, createFunction).thenApply(__ -> null);\n    }\n\n    protected void create(String path, T data) throws MetadataStoreException {\n        try {\n            createAsync(path, data).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 create \" + path, e);\n        }\n    }\n","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/BaseResources.java#L156-L192","documentation":"BaseResources.setWithCreate uses cache.readModifyUpdateOrCreate to update existing data or create it if missing; any failure (store error, timeout, interruption, unexpected cause) surfaces as MetadataStoreException('Failed to set/create <path>'). It means the create-or-update of the resource could not complete.","triggerScenarios":"Calling setWithCreate(path, createFunction) when the metadata store update or initial create fails, exceeds operationTimeoutSec, or hits a create conflict because the node appeared concurrently.","commonSituations":"Two admin clients creating the same resource concurrently; store unavailable; config store in read-only state so create fails; interrupted admin thread.","solutions":["Retry; if the node now exists, fall back to set (update) semantics","Check metadata store write permissions/health","Increase operationTimeoutSec","Avoid concurrent first-time creation of the same path from multiple clients"],"exampleFix":"// before\nresources.setWithCreate(path, opt -> new Policies());\n// after\ntry {\n    resources.setWithCreate(path, opt -> new Policies());\n} catch (MetadataStoreException e) {\n    if (e.getCause() != null && e.getCause().getMessage().contains(\"already exists\")) {\n        resources.set(path, p -> p); // node created concurrently\n    } else { throw e; }\n}","handlingStrategy":"try-catch","validationCode":"boolean exists = resources.exists(path);\n// choose set vs setWithCreate based on existence to reduce create conflicts","typeGuard":null,"tryCatchPattern":"try { resources.setWithCreate(path, creator); }\ncatch (MetadataStoreException e) {\n    if (causeIndicatesAlreadyExists(e.getCause())) { resources.set(path, Function.identity()); }\n    else throw e;\n}","preventionTips":["Avoid racing initial creation of the same path","Prefer setWithCreate over create to tolerate existing nodes","Confirm store is writable before admin mutations"],"tags":["metadata-store","create-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-14T00:17:10.932Z"}