{"record":{"id":"cffb95277851b968","repo":"apache/iceberg","slug":"failed-to-initialize-sharedcount","errorCode":null,"errorMessage":"Failed to initialize SharedCount","messagePattern":"Failed to initialize SharedCount","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/maintenance/api/ZkLockFactory.java","lineNumber":140,"sourceCode":"    client.start();\n\n    try {\n      if (!client.blockUntilConnected(connectionTimeoutMs, TimeUnit.MILLISECONDS)) {\n        throw new IllegalStateException(\"Connection to Zookeeper timed out\");\n      }\n\n      this.taskSharedCount = new SharedCount(client, getTaskSharePath(), 0);\n      this.recoverySharedCount = new SharedCount(client, getRecoverySharedPath(), 0);\n      taskSharedCount.start();\n      recoverySharedCount.start();\n      isOpen = true;\n      LOG.info(\"ZkLockFactory initialized for lockId: {}.\", lockId);\n    } catch (InterruptedException e) {\n      Thread.currentThread().interrupt();\n      throw new RuntimeException(\"Interrupted while connecting to Zookeeper\", e);\n    } catch (Exception e) {\n      closeQuietly();\n      throw new RuntimeException(\"Failed to initialize SharedCount\", e);\n    }\n  }\n\n  private String getTaskSharePath() {\n    return LOCK_BASE_PATH + lockId + \"/task\";\n  }\n\n  private String getRecoverySharedPath() {\n    return LOCK_BASE_PATH + lockId + \"/recovery\";\n  }\n\n  private void closeQuietly() {\n    try {\n      close();\n    } catch (Exception e) {\n      LOG.warn(\"Failed to close ZkLockFactory for lockId: {}\", lockId, e);\n    }\n  }","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/maintenance/api/ZkLockFactory.java#L122-L158","documentation":"Starting the Curator SharedCount instances (taskSharedCount/recoverySharedCount) after connecting failed; the factory closes resources quietly and rethrows RuntimeException('Failed to initialize SharedCount', e). The shared counters used by the trigger locks could not be created/started in ZooKeeper.","triggerScenarios":"SharedCount.start() fails: ZooKeeper session lost right after connect, node creation denied by ACL/permissions, znode parents missing and no namespace support, or the ensemble errors on setData/getData for the counter path.","commonSituations":"ZooKeeper ACLs deny writes for the configured user (e.g. SASL/Kerberos mismatch); znode path conflicts or chroot misconfiguration; session expiry during startup because the ensemble is overloaded; incompatible Curator/ZooKeeper client versions on the classpath.","solutions":["Check the wrapped cause (getCause()) for the KeeperException code (NoAuth, NodeExists, ConnectionLoss).","Fix ZooKeeper ACLs so the client user can create/write under the lock base path.","Verify chroot/lockId path configuration; ensure parents are creatable.","Confirm Curator and ZooKeeper client versions match the flink-shaded-zookeeper version of the Iceberg build.","Retry open() once the session is stable; ensure the ensemble has quorum."],"exampleFix":"// before\n// ACL denies writes -> SharedCount.start() fails\nzkCli.sh -server zk:2181 create /iceberg/lock 'x'  // created by different user\n// after\n// grant the Flink principal full access to the lock base path\nsetAcl /iceberg/lock world:anyone:cdrwa   # or sasl:flink-user:cdrwa","handlingStrategy":"try-catch","validationCode":"// preflight: verify write access to the lock base path\nzkCli.sh -server zk:2181 create /iceberg/lock/test 'x'; delete /iceberg/lock/test","typeGuard":null,"tryCatchPattern":"try {\n  factory.open();\n} catch (RuntimeException e) {\n  if (e.getMessage().contains(\"Failed to initialize SharedCount\")) {\n    LOG.error(\"SharedCount init failed\", e.getCause());\n    closeQuietly();\n  }\n}","preventionTips":["Grant create/write ACLs under the lock base path","Align Curator/ZooKeeper client versions with the Iceberg build","Verify chroot and lockId path configuration","Ensure ensemble quorum before deploying triggers"],"tags":["flink","zookeeper","sharedcount","lock","curator"],"backgroundTag":"zookeeper-session-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}