code: public static void createOrSet(
        CuratorFramework curatorFramework,
        String path,
        CreateMode mode,
        byte[] rawBytes,
        int maxZnodeBytes
    ) throws Exception
    {
      verifySize(path, rawBytes, maxZnodeBytes);
  
      boolean created = false;
      if (curatorFramework.checkExists().forPath(path) == null) {
        try {
          curatorFramework.create()
                          .creatingParentsIfNeeded()
                          .withMode(mode)
                          .forPath(path, rawBytes);
  
          created = true;
        }
        catch (KeeperException.NodeExistsException e) {
          log.debug("Path [%s] created while we were running, will setData instead.", path);
        }
      }
  
      if (!created) {
        try {
          curatorFramework.setData()
                          .forPath(path, rawBytes);
        }
        catch (KeeperException.NoNodeException e) {
          log.warn("Someone deleted path[%s] while we were trying to set it. Leaving it deleted.", path);
        }
      }
    }
docs: Create znode if it does not already exist. If it does already exist, update the payload (but not the create mode).
  If someone deletes the znode while we're trying to set it, just let it stay deleted.
  
  @param curatorFramework curator
  @param path             path
  @param mode             create mode
  @param rawBytes         payload
  @param maxZnodeBytes    maximum payload size
  
  @throws IllegalArgumentException if rawBytes.length > maxZnodeBytes
  @throws Exception                if Curator throws an Exception