{"record":{"id":"9b19e91646867472","repo":"apache/dolphinscheduler","slug":"zookeeper-check-key-is-existed-error","errorCode":null,"errorMessage":"zookeeper check key is existed error","messagePattern":"zookeeper check key is existed error","errorType":"exception","errorClass":"RegistryException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistry.java","lineNumber":167,"sourceCode":"            throw new RegistryException(\"Failed to subscribe listener for key: \" + path, e);\n        }\n    }\n\n    @Override\n    public String get(String key) {\n        try {\n            return new String(client.getData().forPath(key), StandardCharsets.UTF_8);\n        } catch (Exception e) {\n            throw new RegistryException(\"zookeeper get data error\", e);\n        }\n    }\n\n    @Override\n    public boolean exists(String key) {\n        try {\n            return null != client.checkExists().forPath(key);\n        } catch (Exception e) {\n            throw new RegistryException(\"zookeeper check key is existed error\", e);\n        }\n    }\n\n    @Override\n    public void put(String key, String value, boolean deleteOnDisconnect) {\n        final CreateMode mode = deleteOnDisconnect ? CreateMode.EPHEMERAL : CreateMode.PERSISTENT;\n\n        try {\n            client.create()\n                    .orSetData()\n                    .creatingParentsIfNeeded()\n                    .withMode(mode)\n                    .forPath(key, value.getBytes(StandardCharsets.UTF_8));\n        } catch (Exception e) {\n            throw new RegistryException(\"Failed to put registry key: \" + key, e);\n        }\n    }\n","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-registry/dolphinscheduler-registry-plugins/dolphinscheduler-registry-zookeeper/src/main/java/org/apache/dolphinscheduler/plugin/registry/zookeeper/ZookeeperRegistry.java#L149-L185","documentation":"ZookeeperRegistry.exists() calls Curator's client.checkExists().forPath(key) and wraps any exception in a RegistryException with message 'zookeeper check key is existed error'. Unlike get(), a missing node is not an error here (null Stat is returned as false); the wrapper fires only on infrastructure or argument failures.","triggerScenarios":"Calling exists(key) while the ZooKeeper session is expired or the ensemble is unreachable (CONNECTIONLOSS), when the key is a malformed path (empty string, not starting with '/', contains null byte — BADARGUMENTS), or when ACLs deny the checkExists stat call.","commonSituations":"ZooKeeper cluster down or network partition during startup health checks; building keys from user-supplied IDs that produce invalid paths; misconfigured chroot or connect string so all paths resolve outside the allowed tree.","solutions":["Check the wrapped cause: KeeperException.Code CONNECTIONLOSS/SESSIONEXPIRED → verify ensemble health and wait for Curator session recovery, then retry","Validate the key is an absolute, well-formed ZNode path before calling","Verify registry.zookeeper.connect-string, chroot, and auth configuration in the DolphinScheduler common properties","Check ZooKeeper server logs and ACLs if AUTHFAILED/NOAUTH appears"],"exampleFix":"// before\nString key = \"/ds/\" + id;\nboolean ok = registry.exists(key);\n// after\nif (id == null || id.isEmpty()) { throw new IllegalArgumentException(\"id required\"); }\nboolean ok = registry.exists(\"/ds/\" + id);","handlingStrategy":"try-catch","validationCode":"if (key == null || !key.startsWith(\"/\")) {\n    throw new IllegalArgumentException(\"registry key must be an absolute znode path\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    return registry.exists(key);\n} catch (RegistryException e) {\n    Throwable cause = e.getCause();\n    if (cause instanceof KeeperException.ConnectionLossException || cause instanceof KeeperException.SessionExpiredException) {\n        return retryExists(key); // retry after session recovery\n    }\n    throw e;\n}","preventionTips":["Validate path format before any registry call","Check ZooKeeper availability during health checks so infra failures are detected early","Watch the cause exception, not just the RegistryException wrapper","Keep chroot and path-prefix config aligned across components"],"tags":["zookeeper","curator","registry","existence-check"],"backgroundTag":"connection-refused","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}