@Override public void execute(byte[] data) throws Exception { zk.setData(path, data, -1); } });
@Override public void start() { String value = "3"; LOG.info("before sending snapshot, set {} to {}", nodePath, value); try { leaderZk.setData(nodePath, value.getBytes(), -1); LOG.info("successfully set {} to {}", nodePath, value); } catch (Exception e) { LOG.error("error when set {} to {}, {}", nodePath, value, e); } } });
void doPopulate() { iteration++; byte v[] = ("" + iteration).getBytes(); for (int i = 0; i < count; i++) { String cpath = path + "/" + i; zk.setData(cpath, v, -1, this, v); incOutstanding(); } }
public void setData() { zk.setData(path, data, version, this, toString()); }
@Override public Stat setData(String path, byte[] data, int version) throws KeeperException, InterruptedException { Stat stat = super.setData(path, data, version); checkThrowKeeperException(); return stat; } }
@Override public void setData(String path, Object data) { byte[] bytes = serializer.serialize(data); try { zk.setData(path, bytes, -1); } catch (KeeperException e) { throw new ZkException(e); } catch (InterruptedException e) { throw new ZkInterruptedException(e); } }
@Override public void setData(String path, Object data) { byte[] bytes = serializer.serialize(data); try { zk.setData(path, bytes, -1); } catch (KeeperException e) { throw new ZkException(e); } catch (InterruptedException e) { throw new ZkInterruptedException(e); } }
public void preAuth() throws Exception { ZooKeeper zk = createClient(); zk.addAuthInfo("key", "25".getBytes()); try { createNodePrintAcl(zk, "/pre", "testPreAuth"); zk.setACL("/", Ids.CREATOR_ALL_ACL, -1); zk.getChildren("/", false); zk.create("/abc", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); zk.setData("/abc", "testData1".getBytes(), -1); zk.create("/key", null, Ids.CREATOR_ALL_ACL, CreateMode.PERSISTENT); zk.setData("/key", "5".getBytes(), -1); Thread.sleep(1000); } catch (KeeperException e) { Assert.fail("test failed :" + e); } finally { zk.close(); } }
public void verifySetDataFailure_NoNode() { rc = KeeperException.Code.NONODE; stat = null; zk.setData(path, data, version, this, toString()); verify(); }
private void setExpireBefore(long time) throws KeeperException, InterruptedException, IOException { ZooKeeper zk = UTIL.getZooKeeperWatcher().getRecoverableZooKeeper().getZooKeeper(); if (zk.exists(ZooKeeperScanPolicyObserver.NODE, false) == null) { zk.create(ZooKeeperScanPolicyObserver.NODE, Bytes.toBytes(time), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } else { zk.setData(ZooKeeperScanPolicyObserver.NODE, Bytes.toBytes(time), -1); } }
public void validAuth() throws Exception { ZooKeeper zk = createClient(); // any multiple of 5 will do... zk.addAuthInfo("key", "25".getBytes()); try { createNodePrintAcl(zk, "/valid", "testValidAuth"); zk.getData("/abc", false, null); zk.setData("/abc", "testData3".getBytes(), -1); } catch (KeeperException.AuthFailedException e) { Assert.fail("test failed :" + e); } finally { zk.close(); } }
public void missingAuth() throws Exception { ZooKeeper zk = createClient(); try { zk.getData("/abc", false, null); Assert.fail("Should not be able to get data"); } catch (KeeperException correct) { // correct } try { zk.setData("/abc", "testData2".getBytes(), -1); Assert.fail("Should not be able to set data"); } catch (KeeperException correct) { // correct } finally { zk.close(); } }
public void validAuth2() throws Exception { ZooKeeper zk = createClient(); // any multiple of 5 will do... zk.addAuthInfo("key", "125".getBytes()); try { createNodePrintAcl(zk, "/valid2", "testValidAuth2"); zk.getData("/abc", false, null); zk.setData("/abc", "testData3".getBytes(), -1); } catch (KeeperException.AuthFailedException e) { Assert.fail("test failed :" + e); } finally { zk.close(); } }
@Test public void testStartup() throws Exception { final String path = "/test_node"; zk.create(path, new byte[TEST_MAXBUFFER - 60], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); zk.setData(path, new byte[TEST_MAXBUFFER - 50], -1); stopServer(); startServer(); }
@Override public int update(final HmilyTransaction hmilyTransaction) throws HmilyRuntimeException { try { hmilyTransaction.setLastTime(new Date()); hmilyTransaction.setVersion(hmilyTransaction.getVersion() + 1); zooKeeper.setData(buildRootPath(hmilyTransaction.getTransId()), RepositoryConvertUtils.convert(hmilyTransaction, objectSerializer), -1); return ROWS; } catch (Exception e) { throw new HmilyRuntimeException(e); } }
public static void updateSegmentMetadata(ZooKeeperClient zkc, LogSegmentMetadata segment) throws Exception { byte[] finalisedData = segment.getFinalisedData().getBytes(UTF_8); zkc.get().setData(segment.getZkPath(), finalisedData, -1); }
@Test public void testNodeDataChanged() throws Exception { String path = "/test-changed"; zk1.create(path, new byte[1], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); Stat stat1 = zk1.exists(path, watcher); qu.shutdown(1); zk2.setData(path, new byte[2], stat1.getVersion()); qu.start(1); watcher.waitForConnected(TIMEOUT); watcher.assertEvent(TIMEOUT, EventType.NodeDataChanged); }
private static void updateMaxLogSegmentSequenceNo(ZooKeeperClient zkc, URI uri, String streamName, DistributedLogConfiguration conf, byte[] data) throws Exception { String logSegmentsPath = ZKLogMetadata.getLogSegmentsPath( uri, streamName, conf.getUnpartitionedStreamName()); zkc.get().setData(logSegmentsPath, data, -1); }
public void verifySetDataFailure_BadVersion() { new StringCB(zk).verifyCreate(); rc = Code.BADVERSION; stat = null; zk.setData(path, data, version + 1, this, toString()); verify(); }
@Override protected int doUpdate(Transaction transaction) { try { transaction.updateTime(); transaction.updateVersion(); Stat stat = getZk().setData(getTxidPath(transaction.getXid()), TransactionSerializer.serialize(serializer, transaction), (int) transaction.getVersion() - 2); return 1; } catch (Exception e) { throw new TransactionIOException(e); } }