public void stepDownAsLeader() {
    try {
      synchronized (lock) {
        if (!leaderExists.get()) {
          return;
        }
        byte[] leaderId = ZKUtil.getData(watcher, leaderZNode);
        if (leaderId != null && Bytes.equals(nodeId, leaderId)) {
          LOG.info("Stepping down as leader");
          ZKUtil.deleteNodeFailSilent(watcher, leaderZNode);
          leaderExists.set(false);
        } else {
          LOG.info("Not current leader, no need to step down");
        }
      }
    } catch (KeeperException ke) {
      watcher.abort("Unhandled zookeeper exception removing leader node", ke);
      candidate.stop("Unhandled zookeeper exception removing leader node: " + ke.getMessage());
    } catch (InterruptedException e) {
      watcher.abort("Unhandled zookeeper exception removing leader node", e);
      candidate.stop("Unhandled zookeeper exception removing leader node: " + e.getMessage());
    }
  }
Removes the leader znode, if it is currently claimed by this instance.
hbase-zookeeper/src/main/java/org/apache/hadoop/hbase/zookeeper/ZKLeaderManager.java