/** * Construct a master address listener with the specified * <code>zookeeper</code> reference. * <p> * This constructor does not trigger any actions, you must call methods * explicitly. Normally you will just want to execute {@link #start()} to * begin tracking of the master address. * * @param watcher * zk reference and watcher * @param abortable * abortable in case of fatal error */ public MasterAddressTracker(ZooKeeperWatcher watcher, Abortable abortable) { super(watcher, watcher.getMasterAddressZNode(), abortable); }
/** * @return True if cluster has an active master. */ public boolean isActiveMaster() { try { if (ZKUtil.checkExists(watcher, watcher.getMasterAddressZNode()) >= 0) { return true; } } catch (KeeperException ke) { LOG.info("Received an unexpected KeeperException when checking " + "isActiveMaster : " + ke); } return false; }
private static ArrayList<ACL> createACL(ZooKeeperWatcher zkw, String node) { if (isSecureZooKeeper(zkw.getConfiguration())) { // Certain znodes are accessed directly by the client, // so they must be readable by non-authenticated clients if ((node.equals(zkw.baseZNode) == true) || (node.equals(zkw.getMasterAddressZNode()) == true) || (node.equals(zkw.clusterIdZNode) == true) || (node.equals(zkw.fsZNode) == true) || (node.equals(zkw.backupMasterAddressesZNode) == true) || (node.startsWith(zkw.tableZNode) == true)) { return ZooKeeperWatcher.CREATOR_ALL_AND_WORLD_READABLE; } return Ids.CREATOR_ALL_ACL; } else { return Ids.OPEN_ACL_UNSAFE; } }
void handle(final String path) { if (path.equals(watcher.getMasterAddressZNode()) && !master.isStopped()) { handleMasterNodeChange(); } }
synchronized (clusterHasActiveMaster) { if (ZKUtil .watchAndCheckExists(watcher, watcher.getMasterAddressZNode())) {
/** * delete the master znode if its content is same as the parameter */ public static boolean deleteIfEquals(ZooKeeperWatcher zkw, final String content) { if (content == null) { throw new IllegalArgumentException("Content must not be null"); } try { Stat stat = new Stat(); byte[] data = ZKUtil.getDataNoWatch(zkw, zkw.getMasterAddressZNode(), stat); ServerName sn = ServerName.parseFrom(data); if (sn != null && content.equals(sn.toString())) { return (ZKUtil.deleteNode(zkw, zkw.getMasterAddressZNode(), stat.getVersion())); } } catch (KeeperException e) { LOG.warn("Can't get or delete the master znode", e); } catch (DeserializationException e) { LOG.warn("Can't get or delete the master znode", e); } return false; } }
public void stop() { try { // 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.getMasterAddressZNode()); // 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.error( this.watcher.prefix("Error deleting our own master address node"), e); } } }
/** * Get master address. Use this instead of {@link #getMasterAddress()} if you * do not have an instance of this tracker in your context. * * @param zkw * ZooKeeperWatcher to use * @return ServerName stored in the the master address znode or null if no * znode present. * @throws org.apache.zookeeper.KeeperException * @throws java.io.IOException */ public static ServerName getMasterAddress(final ZooKeeperWatcher zkw) throws KeeperException, IOException { byte[] data = ZKUtil.getData(zkw, zkw.getMasterAddressZNode()); if (data == null) { throw new IOException( "Can't get master address from ZooKeeper; znode data == null"); } try { return ServerName.parseFrom(data); } catch (DeserializationException e) { KeeperException ke = new KeeperException.DataInconsistencyException(); ke.initCause(e); throw ke; } }
this.watcher.backupMasterAddressesZNode, this.sn.toString()); if (MasterAddressTracker.setMasterAddress(this.watcher, this.watcher.getMasterAddressZNode(), this.sn)) { this.watcher.getMasterAddressZNode()); if (bytes == null) { msg = ("A master was detected, but went down before its address " this.watcher.getMasterAddressZNode());
"testActiveMasterManagerFromZK", null, true); try { ZKUtil.deleteNode(zk, zk.getMasterAddressZNode()); ZKUtil.deleteNode(zk, zk.clusterStateZNode); } catch (KeeperException.NoNodeException nne) { zk.getMasterAddressZNode()); zk.registerListener(listener); ZKUtil.deleteNode(zk, zk.getMasterAddressZNode()); ZKUtil.deleteNode(zk, zk.getMasterAddressZNode());
"testActiveMasterManagerFromZK", null, true); try { ZKUtil.deleteNode(zk, zk.getMasterAddressZNode()); ZKUtil.deleteNode(zk, zk.clusterStateZNode); } catch (KeeperException.NoNodeException nne) {