private void processCreateResult(CuratorFramework client, CuratorEvent event) throws Exception {
    boolean doesExist = event.getResultCode() == KeeperException.Code.NODEEXISTS.intValue();
    if (!doesExist && event.getResultCode() != KeeperException.Code.OK.intValue()) {
      LOG.info("Trying to reacquire due to create error: " + event);
      startCreateCurrentNode(); // TODO: a pattern from Curator. Better error handling?
      return;
    }
    State localState = state.get();
    switch (localState) {
    case CLOSED:
    case LATENT:
      return;
    case INITIAL_SELECTION:
      if (doesExist) {
        LOG.info("Slot " + currentSlot + " was occupied");
        chooseSlotToTake(); // Try another slot.
        startCreateCurrentNode();
      } else {
        handleCreatedNode(event.getName());
      }
      break;
    case AFTER_SELECTION:
      if (doesExist) {
        processExistsFromCreate(client, event.getPath());
      } else {
        handleCreatedNode(event.getName());
      }
      break;
    default:
      throw new AssertionError("Unknown state " + localState);
    }
  }
We would have used the curator ephemeral node with some extra logic but it doesn't handle
the EXISTS condition, which is crucial here; so we c/p parts of Curator and add our logic.
llap-client/src/java/org/apache/hadoop/hive/llap/registry/impl/SlotZnode.java