private void handleLeaderChange() { try { synchronized(lock) { if (ZKUtil.watchAndCheckExists(watcher, leaderZNode)) { LOG.info("Found new leader for znode: "+leaderZNode); leaderExists.set(true); } else { LOG.info("Leader change, but no new leader found"); leaderExists.set(false); lock.notifyAll(); } } } catch (KeeperException ke) { watcher.abort("ZooKeeper error checking for leader znode", ke); candidate.stop("ZooKeeper error checking for leader: "+ke.getMessage()); } }
throw (RuntimeException) new RuntimeException(e.getMessage()). initCause(e); } finally {
throw (RuntimeException) new RuntimeException(e.getMessage()). initCause(e);
private List<OpResult> validatePath(Iterable<Op> ops) { List<OpResult> results = new ArrayList<OpResult>(); boolean error = false; for (Op op : ops) { try { op.validate(); } catch (IllegalArgumentException iae) { LOG.error("IllegalArgumentException: " + iae.getMessage()); ErrorResult err = new ErrorResult( KeeperException.Code.BADARGUMENTS.intValue()); results.add(err); error = true; continue; } catch (KeeperException ke) { LOG.error("KeeperException: " + ke.getMessage()); ErrorResult err = new ErrorResult(ke.code().intValue()); results.add(err); error = true; continue; } ErrorResult err = new ErrorResult( KeeperException.Code.RUNTIMEINCONSISTENCY.intValue()); results.add(err); } if (false == error) { results.clear(); } return results; }
private void checkRoot() throws IOException, InterruptedException { ZooKeeper zk = new ZooKeeper(hostPort, 10000, this); try { zk.create(dirOnZK, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException ke) { // expected, sort of } catch (KeeperException ke) { Assert.fail("Unexpected exception code for create " + dirOnZK + ": " + ke.getMessage()); } try { zk.create(testDirOnZK, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } catch (KeeperException.NodeExistsException ke) { // expected, sort of } catch (KeeperException ke) { Assert.fail("Unexpected exception code for create " + testDirOnZK + ": " + ke.getMessage()); } zk.close(); }
sb.append("\n" + ke.getMessage());
public void stop() { try { synchronized (clusterHasActiveMaster) { // Master is already stopped, wake up the manager // thread so that it can shutdown soon. clusterHasActiveMaster.notifyAll(); } // If our address is in ZK, delete it on our way out ServerName activeMaster = null; try { activeMaster = MasterAddressTracker.getMasterAddress(this.watcher); } catch (IOException e) { LOG.warn("Failed get of master address: " + e.toString()); } if (activeMaster != null && activeMaster.equals(this.sn)) { ZKUtil.deleteNode(watcher, watcher.getZNodePaths().masterAddressZNode); // We may have failed to delete the znode at the previous step, but // we delete the file anyway: a second attempt to delete the znode is likely to fail again. ZNodeClearer.deleteMyEphemeralNodeOnDisk(); } } catch (KeeperException e) { LOG.debug(this.watcher.prefix("Failed delete of our master address node; " + e.getMessage())); } } }
/** * Removes the leader znode, if it is currently claimed by this instance. */ public void stepDownAsLeader() { try { synchronized(lock) { if (!leaderExists.get()) { return; } byte[] leaderId = ZKUtil.getData(watcher, leaderZNode); if (leaderId != null && Bytes.equals(nodeId, leaderId)) { LOG.info("Stepping down as leader"); ZKUtil.deleteNodeFailSilent(watcher, leaderZNode); leaderExists.set(false); } else { LOG.info("Not current leader, no need to step down"); } } } catch (KeeperException ke) { watcher.abort("Unhandled zookeeper exception removing leader node", ke); candidate.stop("Unhandled zookeeper exception removing leader node: " + ke.getMessage()); } catch (InterruptedException e) { watcher.abort("Unhandled zookeeper exception removing leader node", e); candidate.stop("Unhandled zookeeper exception removing leader node: " + e.getMessage()); } }
private List<OpResult> validatePath(Iterable<Op> ops) { List<OpResult> results = new ArrayList<OpResult>(); boolean error = false; for (Op op : ops) { try { op.validate(); } catch (IllegalArgumentException iae) { LOG.error("IllegalArgumentException: " + iae.getMessage()); ErrorResult err = new ErrorResult( KeeperException.Code.BADARGUMENTS.intValue()); results.add(err); error = true; continue; } catch (KeeperException ke) { LOG.error("KeeperException: " + ke.getMessage()); ErrorResult err = new ErrorResult(ke.code().intValue()); results.add(err); error = true; continue; } ErrorResult err = new ErrorResult( KeeperException.Code.RUNTIMEINCONSISTENCY.intValue()); results.add(err); } if (false == error) { results.clear(); } return results; }
candidate.stop("Unexpected error from ZK: "+ke.getMessage()); return;
} catch (KeeperException e) { LOG.warn( "Failed to create znode " + node + " due to: " + e.getMessage() + ", will retry later");
@Override public void processRequest(Request request) throws RequestProcessorException { // Check if this is a local session and we are trying to create // an ephemeral node, in which case we upgrade the session Request upgradeRequest = null; try { upgradeRequest = lzks.checkUpgradeSession(request); } catch (KeeperException ke) { if (request.getHdr() != null) { LOG.debug("Updating header"); request.getHdr().setType(OpCode.error); request.setTxn(new ErrorTxn(ke.code().intValue())); } request.setException(ke); LOG.info("Error creating upgrade request " + ke.getMessage()); } catch (IOException ie) { LOG.error("Unexpected error in upgrade", ie); } if (upgradeRequest != null) { nextProcessor.processRequest(upgradeRequest); } nextProcessor.processRequest(request); }
public void start() { try { watcher.registerListener(this); String parent = ZKUtil.getParent(leaderZNode); if (ZKUtil.checkExists(watcher, parent) < 0) { ZKUtil.createWithParents(watcher, parent); } } catch (KeeperException ke) { watcher.abort("Unhandled zk exception when starting", ke); candidate.stop("Unhandled zk exception starting up: "+ke.getMessage()); } }
private void deleteNodeIfExists(ZooKeeper zk, String nodeName) throws InterruptedException { try { zk.delete(nodeName, -1); } catch (KeeperException ke) { Code code = ke.code(); boolean valid = code == KeeperException.Code.NONODE || code == KeeperException.Code.NOTEMPTY; if (!valid) { Assert.fail("Unexpected exception code for delete: " + ke.getMessage()); } } }
zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } catch (KeeperException ke) { Assert.fail("Creating node " + parentName + ke.getMessage()); boolean valid = code == KeeperException.Code.NODEEXISTS; if (!valid) { Assert.fail("Unexpected exception code for createin: " + ke.getMessage());
@Test(timeout = 10000) public void testReconfigEnabledWithSuperUser() throws InterruptedException { try { zkAdmin.addAuthInfo("digest", "super:test".getBytes()); Assert.assertTrue(reconfigPort()); } catch (KeeperException e) { Assert.fail("Reconfig should not fail, but failed with exception : " + e.getMessage()); } }
@Test(timeout = 10000) public void testReconfigEnabledWithAuthAndACL() throws InterruptedException { resetZKAdmin(); try { zkAdmin.addAuthInfo("digest", "super:test".getBytes()); ArrayList<ACL> acls = new ArrayList<ACL>( Collections.singletonList( new ACL(ZooDefs.Perms.WRITE, new Id("digest", "user:tl+z3z0vO6PfPfEENfLF96E6pM0="/* password is test */)))); zkAdmin.setACL(ZooDefs.CONFIG_NODE, acls, -1); resetZKAdmin(); zkAdmin.addAuthInfo("digest", "user:test".getBytes()); Assert.assertTrue(reconfigPort()); } catch (KeeperException e) { Assert.fail("Reconfig should not fail, but failed with exception : " + e.getMessage()); } }
zk.create(parentName, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT); } catch (KeeperException ke) { Assert.fail("Creating node " + parentName + ke.getMessage()); || code == KeeperException.Code.NOTEMPTY; if (!valid) { Assert.fail("Unexpected exception code for delete: " + ke.getMessage()); boolean valid = code == KeeperException.Code.NODEEXISTS; if (!valid) { Assert.fail("Unexpected exception code for createin: " + ke.getMessage());
|| code == KeeperException.Code.NOTEMPTY; if (!valid) { Assert.fail("Unexpected exception code for delete: " + ke.getMessage()); boolean valid = code == KeeperException.Code.NODEEXISTS; if (!valid) { Assert.fail("Unexpected exception code for create: " + ke.getMessage()); || code == KeeperException.Code.BADVERSION; if (!valid) { Assert.fail("Unexpected exception code for delete: " + ke.getMessage());
LOG.info("Got user-level KeeperException when processing {} aborting" + " remaining multi ops. Error Path:{} Error:{}", request.toString(), e.getPath(), e.getMessage()); request.toString(), e.getPath(), e.getMessage());