A ZooKeeper node that "failed" usually means one of three different things, and the fix depends on which one you're facing. If it's a single server in an ensemble, the fastest path is to inspect its log for the exact shutdown reason, confirm its data directory is intact, restart it, and let leader election or sync catch it up. If it's a znode that's stuck or inconsistent, you need to restore the data path rather than the process. And if you've lost quorum, no restart will help until a majority can talk to each other again. Start by classifying the failure, because restarting blindly can make a split-brain worse.

The distinction matters more than any single command. ZooKeeper has no "repair this znode" switch; recovery happens either by bringing an ensemble member back into sync or by rewriting the offending node through a client. This article walks the ordered sequence for each case, with the checks that tell you whether the fix worked and the point at which you should stop improvising.

Classify the failure before touching anything

Write down three facts first: how many servers are in the ensemble, how many are currently responding, and whether the problem is a process, a data node, or the whole cluster's availability. An ensemble of 3 or 5 tolerates the loss of 1 or 2 members respectively, so a single down server is a degraded-but-serving state, not an outage. That changes the urgency and the risk of your next move.

A process-level failure shows up as a server that won't start, exits during startup, or dies repeatedly. A znode-level failure usually surfaces as a client exception, a KeeperException with a specific code, or a watcher that never fires. A quorum-level failure means clients get connection-loss errors and no server can win an election. Each has a different first action, and mixing them up is how routine maintenance turns into data loss.

Confirm the symptom and its blast radius

Before restarting, verify what clients actually see. Run the four-letter admin commands against a live server, typically echo ruok | nc 2181 for a liveness check and echo stat | nc 2181 for role, mode, and connection counts. mntr gives a broader metrics dump. These are plaintext commands on the client port; treat the port as trusted-network only or use the newer admin server on port 8080 where enabled.

Cross-check from a client. A zkCli.sh session allows stat /path to inspect a specific znode's version, epoch, and child count, and ls /path to confirm structure. If the CLI connects fine and only one path errors, your problem is data-level. If the CLI hangs or reports connection loss across several hosts, the ensemble itself is in trouble and you should stop restarting members until you've read the logs of every one.

Reading the logs for the actual shutdown reason

The server log is the only reliable source for why a member stopped. Look for the moment the process began shutting down, not just the first error, because ZooKeeper logs a lot of harmless warnings. Common distinct causes include:

java.io.IOException: No space left on device during a snapshot or transaction-log write. An out-of-memory kill, which shows as an abrupt end to logging with no shutdown sequence at all. Packet len ... is out of range or CRC errors on transaction log replay, indicating disk or corruption problems. Cannot open channel to ... repeated across members, which points at networking or firewall rules rather than local data. Election loops with LOOKING repeated many times, which usually means members can't reach each other or disagree on configuration.

Match the log line to a cause rather than to a fix. Disk-full and OOM conditions require freeing resources before restart; a restart without that headroom will fail again within minutes. Replay errors require deciding whether the local data directory is trustworthy at all.

Ordered recovery for a single failed ensemble member

This is the common case and the one to handle first. Prerequisites: you know the ensemble size and configuration, you can reach the host, and the other members are healthy enough to form a quorum.

1: Stop the failed process cleanly if it's still half-alive. A zombie process holding the data directory lock will block a clean start, so confirm no java process is bound to the client and election ports. 2: Check free disk space and file-descriptor limits on the host. ZooKeeper needs room for snapshots and transaction logs, and a full disk is the most common cause of a node that died once and will die again. 3: Inspect the data directory. You should see a myid file containing this server's numeric ID, a version-2 subdirectory with snapshots and logs, and nothing that suggests truncation. Confirm myid matches the server.N entry in the ensemble's shared configuration, because a mismatched ID is rejected at startup. 4: If the data directory looks suspect, move it aside rather than deleting it. Starting with an empty directory lets the server re-sync from the leader in most configurations, at the cost of a longer catch-up. Keep the old directory until you've confirmed the new state is healthy. 5: Start the service and watch the log through startup. Success looks like a transition to FOLLOWING (or LEADING if elections reshuffle) and then stable connection handling. A member that logs LOOKING indefinitely is failing to sync, not failing to start. 6: Verify catch-up. stat on the recovered server should show Mode: follower and a zxid close to the leader's. Compare srvr output across members to confirm they agree on the current epoch.

Success check: a client that creates a test znode and reads it back from a different server sees the same value within a moment. Failure check: the restarted member logs repeated snapshot or log replay errors, or repeatedly loses its session to the leader, which means its data directory or network path is still broken. At that point, stop restarting and either rebuild the member from a fresh sync or escalate to whoever owns the cluster's storage.

When the znode itself is the problem

A znode-level fault looks different. Clients get NODEEXISTS, NONODE, BADVERSION, or NOTEMPTY errors, or stat shows a version or cversion that contradicts what your application expects. ZooKeeper doesn't expose an in-place repair; the supported recovery is to correct the data through a client, then verify watchers and children behave as expected.

For a node with wrong data, use set on the CLI or your client library with the current version to make the write conditional; a version mismatch will fail loudly instead of clobbering a concurrent change. For a node that should exist but doesn't, recreate it with the intended data and ACL. For an unexpected node, delete it with deleteall only after confirming no live watcher or ephemeral owner depends on it, since deleting a parent takes children with it.

Ephemeral nodes deserve a specific mention. They belong to the session that created them, and a failed member drops its sessions, so its ephemeral nodes vanish. If clients are waiting on those paths, they see NONODE; recreating the path manually is a workaround, not a fix, because the original owner's session is gone. The real remedy is on the application side: re-register the ephemeral node when the session reconnects, which well-written clients already do.

If the znode corruption is widespread rather than a single path, suspect the ensemble rather than the node. ZooKeeper's writes are ordered and replicated, so selective corruption across many paths usually indicates a client-side bug or an external actor, not the storage layer.

Quorum loss and split-brain symptoms

When no server can win an election, the ensemble stops accepting writes. This is by design: a minority partition refuses writes to prevent divergence, and clients should see connection loss rather than stale data. The fix is to restore enough connectivity or members to reach a majority, not to force a leader.

The dangerous scenario is a split-brain look-alike: two partitions each large enough to elect a leader. ZooKeeper's quorum rules prevent this in a correct configuration, so if you observe two leaders, suspect misconfiguration such as mismatched server.N lists, duplicate myid values, or members pointed at different configuration files. Verify every member's configuration checksum matches and that myid values are unique before restarting anything. A wrong ID will happily join the wrong cluster.

Once a majority can communicate, the ensemble re-elects and the remaining members resync. Expect a burst of client session expirations and watcher re-registrations; that's normal recovery behavior, not a second failure.

Configuration and environment problems that masquerade as data failures

Several non-obvious issues present as "the node failed" when the node is fine:

Clock skew beyond the tick and session timeout tolerances causes spurious election churn. Check that NTP is healthy on every host. A full transaction log directory, separate from the data directory, is a distinct disk-full path that's easy to miss. Firewall rules that block only the election port block quorum while leaving client connections working, which looks like a partial outage. JVM heap that's too small for the snapshot size causes long pauses and failed syncs under load rather than a clean crash.

Each of these has a corresponding check in stat, mntr, or the log, and each is reversible. This is where I'd spend time before touching data directories: environment faults are common, cheap to rule out, and fixing them avoids an unnecessary resync.

Verifying the fix and preventing the next failure

Confirm recovery from two angles. First, the ensemble: stat on each member should show a leader and consistent follower modes, and mntr should show a stable zk_avg_latency and zero or near-zero zk_outstanding_requests. Second, the application: a test client should connect, create and delete a znode, and observe a watcher fire. If either check fails, the process is up but the cluster isn't useful yet.

For prevention, the highest-value changes are disk headroom monitoring with alerts well before full, log rotation and snapshot purge thresholds sized to your write rate, JVM heap and GC settings matched to snapshot size, and a documented check that every member's myid and configuration agree. Most "failed" nodes I'd expect an operator to encounter trace back to disk, memory, or configuration drift, in roughly that order of frequency for typical deployments. None of these require guessing at current values; they require reading your own logs and metrics.

One limit worth stating plainly: ZooKeeper's own documentation is the authority for version-specific behavior, and options like the admin server, four-letter command availability, and snapshot handling have changed across releases. Check the docs for your installed version rather than relying on a general procedure, and treat any recovery step that deletes data as a last resort with a backup first.