{"record":{"id":"a6c1c69a722122c7","repo":"apache/pulsar","slug":"failed-to-check-exist-policies-readonly-flag-pat","errorCode":null,"errorMessage":"Failed to check exist ${POLICIES_READONLY_FLAG_PATH}","messagePattern":"Failed to check exist (.+?)","errorType":"exception","errorClass":"MetadataStoreException","httpStatus":null,"severity":"error","filePath":"pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/NamespaceResources.java","lineNumber":83,"sourceCode":"        partitionedTopicResources = new PartitionedTopicResources(configurationStore, operationTimeoutSec, executor);\n    }\n\n    public CompletableFuture<List<String>> listNamespacesAsync(String tenant) {\n        return getChildrenRecursiveAsync(joinPath(BASE_POLICIES_PATH, tenant));\n    }\n\n    public CompletableFuture<Boolean> getPoliciesReadOnlyAsync() {\n        return super.existsAsync(POLICIES_READONLY_FLAG_PATH);\n    }\n\n    public boolean getPoliciesReadOnly() throws MetadataStoreException {\n        try {\n            return getPoliciesReadOnlyAsync().get(getOperationTimeoutSec(), 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 check exist \" + POLICIES_READONLY_FLAG_PATH, e);\n        }\n    }\n\n    public void createPolicies(NamespaceName ns, Policies policies) throws MetadataStoreException{\n        create(joinPath(BASE_POLICIES_PATH, ns.toString()), policies);\n    }\n\n    public CompletableFuture<Void> createPoliciesAsync(NamespaceName ns, Policies policies) {\n        return createAsync(joinPath(BASE_POLICIES_PATH, ns.toString()), policies);\n    }\n\n    public boolean namespaceExists(NamespaceName ns) throws MetadataStoreException {\n        String path = joinPath(BASE_POLICIES_PATH, ns.toString());\n        return super.exists(path) && super.getChildren(path).isEmpty();\n    }\n\n    public CompletableFuture<Boolean> namespaceExistsAsync(NamespaceName ns) {\n        String path = joinPath(BASE_POLICIES_PATH, ns.toString());","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker-common/src/main/java/org/apache/pulsar/broker/resources/NamespaceResources.java#L65-L101","documentation":"MetadataStoreException thrown by NamespaceResources.getPoliciesReadOnly() when the synchronous check for the read-only flag node (/admin/flags/policies-readonly) in the metadata store fails. The async existence check is awaited with .get(timeout); any non-ExecutionException failure — most commonly a TimeoutException from the .get() call, or InterruptedException — is wrapped with this message. It indicates the broker could not determine whether namespace policies are read-only, typically due to metadata store (ZooKeeper/etcd) connectivity or latency problems.","triggerScenarios":"Calling getPoliciesReadOnly() when the metadata store is unreachable/slow so getPoliciesReadOnlyAsync().get() times out (getOperationTimeoutSec exceeded), the calling thread is interrupted, or the metadata store session expires mid-operation.","commonSituations":"Broker startup or admin operations against a ZooKeeper quorum that is overloaded, partitioned, or down; network latency between broker and metadata store exceeding the operation timeout; thread interrupted during broker shutdown while policies are being read.","solutions":["Check metadata store (ZooKeeper/etcd) health and broker connectivity to it","Increase operationTimeoutSec if the store is merely slow","Inspect the wrapped cause (getCause()) — TimeoutException vs session-expired — and remediate accordingly","Prefer the async getPoliciesReadOnlyAsync() API on non-blocking threads and handle its CompletableFuture failure directly"],"exampleFix":"// before\nboolean ro = namespaceResources.getPoliciesReadOnly();\n// after\nboolean ro;\ntry {\n    ro = namespaceResources.getPoliciesReadOnly();\n} catch (MetadataStoreException e) {\n    log.error(\"Cannot read policies read-only flag (cause: {}), failing over/retrying\", e.getCause(), e);\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"// Pre-check reachability (conceptual)\nif (!metadataStoreAdminAvailable(namespaceResources, opTimeoutSec)) {\n    throw new IllegalStateException(\"Metadata store unreachable; cannot read policies read-only flag\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    boolean ro = nsResources.getPoliciesReadOnly();\n} catch (MetadataStoreException e) {\n    if (e.getCause() instanceof TimeoutException) {\n        // retry or fail over to another metadata store node\n    } else {\n        throw e;\n    }\n}","preventionTips":["Monitor ZooKeeper/etcd latency and session health from brokers","Size operationTimeoutSec to observed store latency with headroom","Prefer the async getPoliciesReadOnlyAsync() on event-loop threads","Alert on broker-to-metadata-store network partitions"],"tags":["metadata-store","zookeeper","timeout","broker-startup"],"backgroundTag":"metadata-store-unavailable","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"}