@Override public void operationComplete(int rc, List<LogSegmentMetadata> logSegmentMetadatas) { if (KeeperException.Code.OK.intValue() == rc) { LOG.debug("Updated ledgers list : {}", path, logSegmentMetadatas); } } }
/** * Wait for request completion with timeout. */ private void waitForPacketFinish(ReplyHeader r, Packet packet) throws InterruptedException { long waitStartTime = Time.currentElapsedTime(); while (!packet.finished) { packet.wait(requestTimeout); if (!packet.finished && ((Time.currentElapsedTime() - waitStartTime) >= requestTimeout)) { LOG.error("Timeout error occurred for the packet '{}'.", packet); r.setErr(Code.REQUESTTIMEOUT.intValue()); break; } } }
public void processResult(int rc, String path, Object ctx) { if (rc != KeeperException.Code.OK.intValue()) { if (bang) { failed = true; LOG.error("Delete Assert.failed for 0x" + Long.toHexString(zk.getSessionId()) + "with rc:" + rc + " path:" + path); } } } }
@Override public void processResult(int rc, String path, Object ctx, Stat stat) { if (KeeperException.Code.OK.intValue() == rc) { ZKAccessControl.this.zkVersion = stat.getVersion(); promise.setValue(ZKAccessControl.this); } else { promise.setException(KeeperException.create(KeeperException.Code.get(rc))); } } }, null);
@Override public void processResult(int rc, String path, Object ctx) { if (KeeperException.Code.OK.intValue() == rc) { promise.updateIfEmpty(new Return<Void>(null)); return; } promise.updateIfEmpty(new Throw<Void>( KeeperException.create(KeeperException.Code.get(rc)))); return; } }, null);
@Override public void processResult(int rc, String path, Object ctx) { if (Code.OK.intValue() == rc) { fetchSubNamespaces(watcher, promise); } else { promise.setException(KeeperException.create(Code.get(rc))); } } }, null);
@Override public void operationComplete(int rc, List<LogSegmentMetadata> segments) { if (KeeperException.Code.OK.intValue() == rc) { promise.setValue(segments); } else if (KeeperException.Code.NONODE.intValue() == rc) { promise.setException(new LogNotFoundException("Log " + getFullyQualifiedName() + " not found")); } else { String errMsg = "ZK Exception " + rc + " reading ledger list for " + getFullyQualifiedName(); promise.setException(new ZKException(errMsg, KeeperException.Code.get(rc))); } } });
@Override public void processResult(int rc, String path, Object ctx, Stat stat) { if (KeeperException.Code.OK.intValue() == rc) { promise.updateIfEmpty(new Return<ZkVersion>(new ZkVersion(stat.getVersion()))); return; } promise.updateIfEmpty(new Throw<ZkVersion>( KeeperException.create(KeeperException.Code.get(rc)))); return; } }, null);
@Override public void processResult(int rc, String path, Object ctx, String name) { if (KeeperException.Code.OK.intValue() == rc) { logger.info("Created zk path {} for default ACL.", zkRootPath); fetchDefaultAccessControlEntry(promise); } else { promise.setException(KeeperException.create(KeeperException.Code.get(rc))); } } }, null);
@Override public void sync(String path, VoidCallback cb, Object ctx) { executor.execute(() -> { if (getProgrammedFailStatus()) { cb.processResult(failReturnCode.intValue(), path, ctx); return; } else if (stopped) { cb.processResult(KeeperException.Code.ConnectionLoss, path, ctx); return; } cb.processResult(0, path, ctx); }); }
private void processWatchResult(CuratorEvent event) throws Exception { if (event.getResultCode() != KeeperException.Code.NONODE.intValue()) return; LOG.info("Trying to reacquire because of the NONODE event"); startCreateCurrentNode(); }
/** * Visits the subtree with root as given path and calls the passed callback with each znode * found during the search. It performs a depth-first, pre-order traversal of the tree. * <p> * <b>Important:</b> This is <i>not an atomic snapshot</i> of the tree ever, but the * state as it exists across multiple RPCs from zkClient to the ensemble. * For practical purposes, it is suggested to bring the clients to the ensemble * down (i.e. prevent writes to pathRoot) to 'simulate' a snapshot behavior. */ public static void visitSubTreeDFS(ZooKeeper zk, final String path, boolean watch, StringCallback cb) throws KeeperException, InterruptedException { PathUtils.validatePath(path); zk.getData(path, watch, null); cb.processResult(Code.OK.intValue(), path, null, path); visitSubTreeDFSHelper(zk, path, watch, cb); }
private void conLossPacket(Packet p) { if (p.replyHeader == null) { return; } switch (state) { case AUTH_FAILED: p.replyHeader.setErr(KeeperException.Code.AUTHFAILED.intValue()); break; case CLOSED: p.replyHeader.setErr(KeeperException.Code.SESSIONEXPIRED.intValue()); break; default: p.replyHeader.setErr(KeeperException.Code.CONNECTIONLOSS.intValue()); } finishPacket(p); }
/** * The asynchronous version of multi. * * @see #multi(Iterable) */ public void multi(Iterable<Op> ops, MultiCallback cb, Object ctx) { List<OpResult> results = validatePath(ops); if (results.size() > 0) { cb.processResult(KeeperException.Code.BADARGUMENTS.intValue(), null, ctx, results); return; } multiInternal(generateMultiTransaction(ops), cb, ctx); }
@Test public void testMaxTTLs() throws InterruptedException, KeeperException { RequestHeader h = new RequestHeader(1, ZooDefs.OpCode.createTTL); String path = "/bad_ttl"; CreateTTLRequest request = new CreateTTLRequest(path, new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_WITH_TTL.toFlag(), EphemeralType.TTL.maxValue()); CreateResponse response = new CreateResponse(); ReplyHeader r = zk.submitRequest(h, request, response, null); Assert.assertEquals("EphemeralType.getMaxTTL() should succeed", r.getErr(), Code.OK.intValue()); Assert.assertNotNull("Node should exist", zk.exists(path, false)); }
@Test public void testPRequest() throws Exception { pLatch = new CountDownLatch(1); processor = new PrepRequestProcessor(zks, new MyRequestProcessor()); Request foo = new Request(null, 1l, 1, OpCode.create, ByteBuffer.allocate(3), null); processor.pRequest(foo); Assert.assertEquals("Request should have marshalling error", new ErrorTxn(KeeperException.Code.MARSHALLINGERROR.intValue()), outcome.getTxn()); Assert.assertTrue("request hasn't been processed in chain", pLatch.await(5, TimeUnit.SECONDS)); }
public void verifyMulti() { List<Op> ops = Arrays.asList( Op.create("/multi", new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT), Op.delete("/multi", -1)); zk.multi(ops, this, null); latch_await(); Assert.assertEquals(this.rc, KeeperException.Code.OK.intValue()); Assert.assertTrue(this.opResults.get(0) instanceof OpResult.CreateResult); Assert.assertTrue(this.opResults.get(1) instanceof OpResult.DeleteResult); }
void queueEvent(String clientPath, int err, Set<Watcher> materializedWatchers, EventType eventType) { KeeperState sessionState = KeeperState.SyncConnected; if (KeeperException.Code.SESSIONEXPIRED.intValue() == err || KeeperException.Code.CONNECTIONLOSS.intValue() == err) { sessionState = Event.KeeperState.Disconnected; } WatchedEvent event = new WatchedEvent(eventType, sessionState, clientPath); eventThread.queueEvent(event, materializedWatchers); }
@Override protected boolean shouldAddWatch(int rc) { return rc == 0 || rc == KeeperException.Code.NONODE.intValue(); } }
public void processRequest(Request request) throws RequestProcessorException { KeeperException ke = new KeeperException.UnimplementedException(); request.setException(ke); ReplyHeader rh = new ReplyHeader(request.cxid, request.zxid, ke.code().intValue()); try { request.cnxn.sendResponse(rh, null, "response"); } catch (IOException e) { throw new RequestProcessorException("Can't send the response", e); } request.cnxn.sendCloseSession(); }