/** * Creates the given path without placing any data in. * * @param path target path */ public void create(final String path) { Preconditions.checkNotNull(path, "path is required"); final String target = PathUtils.join(root, path); try { curator.create().withMode(mode).forPath(target); getCache().rebuildNode(target); } catch (final Exception e) { throw new DrillRuntimeException("unable to put ", e); } }
/** * Deletes the given node residing at the given path * * @param path target path to delete */ public void delete(final String path) { Preconditions.checkNotNull(path, "path is required"); final String target = PathUtils.join(root, path); try { curator.delete().forPath(target); getCache().rebuildNode(target); } catch (final Exception e) { throw new DrillRuntimeException(String.format("unable to delete node at %s", target), e); } }
/** * Puts the given byte sequence into the given path if path is does not exist. * * @param path target path * @param data data to store * @return null if path was created, else data stored for the given path */ public byte[] putIfAbsent(final String path, final byte[] data) { Preconditions.checkNotNull(path, "path is required"); Preconditions.checkNotNull(data, "data is required"); final String target = PathUtils.join(root, path); try { try { curator.create().withMode(mode).forPath(target, data); getCache().rebuildNode(target); return null; } catch (NodeExistsException e) { // do nothing } return curator.getData().forPath(target); } catch (final Exception e) { throw new DrillRuntimeException("unable to put ", e); } }
getCache().rebuildNode(target); } catch (final VersionMismatchException e) { throw e;