apache/iceberg · error · RuntimeException

Failed to initialize SharedCount

Error message

Failed to initialize SharedCount

What it means

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.

Source

Thrown at flink/v1.20/flink/src/main/java/org/apache/iceberg/flink/maintenance/api/ZkLockFactory.java:140

    client.start();

    try {
      if (!client.blockUntilConnected(connectionTimeoutMs, TimeUnit.MILLISECONDS)) {
        throw new IllegalStateException("Connection to Zookeeper timed out");
      }

      this.taskSharedCount = new SharedCount(client, getTaskSharePath(), 0);
      this.recoverySharedCount = new SharedCount(client, getRecoverySharedPath(), 0);
      taskSharedCount.start();
      recoverySharedCount.start();
      isOpen = true;
      LOG.info("ZkLockFactory initialized for lockId: {}.", lockId);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
      throw new RuntimeException("Interrupted while connecting to Zookeeper", e);
    } catch (Exception e) {
      closeQuietly();
      throw new RuntimeException("Failed to initialize SharedCount", e);
    }
  }

  private String getTaskSharePath() {
    return LOCK_BASE_PATH + lockId + "/task";
  }

  private String getRecoverySharedPath() {
    return LOCK_BASE_PATH + lockId + "/recovery";
  }

  private void closeQuietly() {
    try {
      close();
    } catch (Exception e) {
      LOG.warn("Failed to close ZkLockFactory for lockId: {}", lockId, e);
    }
  }

View on GitHub (pinned to 86d9c8fc54)

Solutions

  1. Check the wrapped cause (getCause()) for the KeeperException code (NoAuth, NodeExists, ConnectionLoss).
  2. Fix ZooKeeper ACLs so the client user can create/write under the lock base path.
  3. Verify chroot/lockId path configuration; ensure parents are creatable.
  4. Confirm Curator and ZooKeeper client versions match the flink-shaded-zookeeper version of the Iceberg build.
  5. Retry open() once the session is stable; ensure the ensemble has quorum.

Example fix

// before
// ACL denies writes -> SharedCount.start() fails
zkCli.sh -server zk:2181 create /iceberg/lock 'x'  // created by different user
// after
// grant the Flink principal full access to the lock base path
setAcl /iceberg/lock world:anyone:cdrwa   # or sasl:flink-user:cdrwa
Defensive patterns

Strategy: try-catch

Validate before calling

// preflight: verify write access to the lock base path
zkCli.sh -server zk:2181 create /iceberg/lock/test 'x'; delete /iceberg/lock/test

Try / catch

try {
  factory.open();
} catch (RuntimeException e) {
  if (e.getMessage().contains("Failed to initialize SharedCount")) {
    LOG.error("SharedCount init failed", e.getCause());
    closeQuietly();
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/iceberg@86d9c8fc54 (2026-09-12). Data as JSON: /api/errors/cffb95277851b968. Report an issue: GitHub.