/** * Get the address of the current master if one is available. Returns null if * no current master. * * @return Server name or null if timed out. */ public ServerName getMasterAddress() { return getMasterAddress(false); }
private synchronized void ensureZookeeperTrackers() throws ZooKeeperConnectionException { // initialize zookeeper and master address manager if (zooKeeper == null) { zooKeeper = getZooKeeperWatcher(); } if (clusterId == null) { clusterId = new ClusterId(); } if (masterAddressTracker == null) { masterAddressTracker = new MasterAddressTracker(zooKeeper, this); masterAddressTracker.start(); } }
private synchronized void resetZooKeeperTrackers() { if (masterAddressTracker != null) { masterAddressTracker.stop(); masterAddressTracker = null; } clusterId = null; if (zooKeeper != null) { zooKeeper.close(); zooKeeper = null; } }
/** * Set master address into the <code>master</code> znode or into the backup * subdirectory of backup masters; switch off the passed in <code>znode</code> * path. * * @param zkw * The ZooKeeperWatcher to use. * @param znode * Where to create the znode; could be at the top level or it could * be under backup masters * @param master * ServerName of the current master * @return true if node created, false if not; a watch is set in both cases * @throws org.apache.zookeeper.KeeperException */ public static boolean setMasterAddress(final ZooKeeperWatcher zkw, final String znode, final ServerName master) throws KeeperException { return ZKUtil.createEphemeralNodeAndWatch(zkw, znode, toByteArray(master)); }
return MasterAddressTracker.deleteIfEquals(zkw, znodeFileContent);
String backupZNode = ZKUtil.joinZNode( this.watcher.backupMasterAddressesZNode, this.sn.toString()); if (MasterAddressTracker.setMasterAddress(this.watcher, this.watcher.getMasterAddressZNode(), this.sn)) { MasterAddressTracker.setMasterAddress(this.watcher, backupZNode, this.sn);
sb.append("\nActive master address: "); try { sb.append(MasterAddressTracker.getMasterAddress(zkw)); } catch (IOException e) { sb.append("<<FAILED LOOKUP: " + e.getMessage() + ">>");
this.masterAddressManager = new MasterAddressTracker(this.zooKeeper, this); this.masterAddressManager.start(); blockAndCheckIfStopped(this.masterAddressManager);
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); } } }
FServerStatusProtocol master = null; while (keepLooping() && master == null) { masterServerName = this.masterAddressManager.getMasterAddress(); if (masterServerName == null) { if (!keepLooping()) { + this.masterAddressManager.getMasterAddress()); try {
/** * Assert there is an active master and that it has the specified address. * @param zk * @param thisMasterAddress * @throws org.apache.zookeeper.KeeperException * @throws java.io.IOException */ private void assertMaster(ZooKeeperWatcher zk, ServerName expectedAddress) throws KeeperException, IOException { ServerName readAddress = MasterAddressTracker.getMasterAddress(zk); assertNotNull(readAddress); assertTrue(expectedAddress.equals(readAddress)); }
ServerName sn = MasterAddressTracker.getMasterAddress(zkw); if (sn == null) { String msg = "ZooKeeper available but no active master location found";