org.apache.hadoop.hbase.zookeeper.MasterAddressTracker Java Examples
The following examples show how to use
org.apache.hadoop.hbase.zookeeper.MasterAddressTracker.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestMasterAddressTracker.java From hbase with Apache License 2.0 | 6 votes |
/** * Unit tests that uses ZooKeeper but does not use the master-side methods * but rather acts directly on ZK. * @throws Exception */ @Test public void testMasterAddressTrackerFromZK() throws Exception { // Create the master node with a dummy address final int infoPort = 1235; final ServerName sn = ServerName.valueOf("localhost", 1234, System.currentTimeMillis()); final MasterAddressTracker addressTracker = setupMasterTracker(sn, infoPort); try { assertTrue(addressTracker.hasMaster()); ServerName pulledAddress = addressTracker.getMasterAddress(); assertTrue(pulledAddress.equals(sn)); assertEquals(infoPort, addressTracker.getMasterInfoPort()); } finally { assertTrue("Couldn't clean up master", MasterAddressTracker.deleteIfEquals(addressTracker.getWatcher(), sn.toString())); } }
Example #2
Source File: HBaseUsageExtractor.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
private String getHBaseMasterUrl() { String host = conf.get("hbase.master.info.bindAddress"); if (host.equals("0.0.0.0")) { try { host = MasterAddressTracker.getMasterAddress(new ZooKeeperWatcher(conf, null, null)).getHostname(); } catch (IOException | KeeperException io) { return null; } } String port = conf.get("hbase.master.info.port"); return "http://" + host + ":" + port + "/"; }
Example #3
Source File: HBaseUsageExtractor.java From kylin with Apache License 2.0 | 5 votes |
private String getHBaseMasterUrl() { String host = conf.get("hbase.master.info.bindAddress"); if (host.equals("0.0.0.0")) { try { host = MasterAddressTracker.getMasterAddress(new ZooKeeperWatcher(conf, null, null)).getHostname(); } catch (IOException | KeeperException io) { return null; } } String port = conf.get("hbase.master.info.port"); return "http://" + host + ":" + port + "/"; }
Example #4
Source File: ActiveMasterManager.java From hbase with Apache License 2.0 | 5 votes |
/** * Fetches the active master's ServerName from zookeeper. */ private void fetchAndSetActiveMasterServerName() { LOG.debug("Attempting to fetch active master sn from zk"); try { activeMasterServerName = MasterAddressTracker.getMasterAddress(watcher); } catch (IOException | KeeperException e) { // Log and ignore for now and re-fetch later if needed. LOG.error("Error fetching active master information", e); } }
Example #5
Source File: TestActiveMasterManager.java From hbase with Apache License 2.0 | 5 votes |
/** * Assert there is an active master and that it has the specified address. * @param zk single Zookeeper watcher * @param expectedAddress the expected address of the master * @throws KeeperException unexpected Zookeeper exception * @throws IOException if an IO problem is encountered */ private void assertMaster(ZKWatcher zk, ServerName expectedAddress) throws KeeperException, IOException { ServerName readAddress = MasterAddressTracker.getMasterAddress(zk); assertNotNull(readAddress); assertTrue(expectedAddress.equals(readAddress)); }
Example #6
Source File: TestRSStatusServlet.java From hbase with Apache License 2.0 | 5 votes |
@Before public void setupBasicMocks() throws IOException, ServiceException { rs = Mockito.mock(HRegionServer.class); rpcServices = Mockito.mock(RSRpcServices.class); rpcServer = Mockito.mock(RpcServerInterface.class); Mockito.doReturn(HBaseConfiguration.create()).when(rs).getConfiguration(); Mockito.doReturn(rpcServices).when(rs).getRSRpcServices(); Mockito.doReturn(rpcServer).when(rs).getRpcServer(); Mockito.doReturn(fakeResponse).when(rpcServices).getServerInfo(Mockito.any(), Mockito.any()); // Fake ZKW ZKWatcher zkw = Mockito.mock(ZKWatcher.class); Mockito.doReturn("fakequorum").when(zkw).getQuorum(); Mockito.doReturn(zkw).when(rs).getZooKeeper(); // Fake BlockCache LOG.warn("The " + HConstants.HFILE_BLOCK_CACHE_SIZE_KEY + " is set to 0"); Mockito.doReturn(Optional.empty()).when(rs).getBlockCache(); // Fake MasterAddressTracker MasterAddressTracker mat = Mockito.mock(MasterAddressTracker.class); Mockito.doReturn(fakeMasterAddress).when(mat).getMasterAddress(); Mockito.doReturn(mat).when(rs).getMasterAddressTracker(); MetricsRegionServer rms = Mockito.mock(MetricsRegionServer.class); Mockito.doReturn(new MetricsRegionServerWrapperStub()).when(rms).getRegionServerWrapper(); Mockito.doReturn(rms).when(rs).getMetrics(); MetricsHBaseServer ms = Mockito.mock(MetricsHBaseServer.class); Mockito.doReturn(new MetricsHBaseServerWrapperStub()).when(ms).getHBaseServerWrapper(); Mockito.doReturn(ms).when(rpcServer).getMetrics(); Mockito.doReturn(ByteBuffAllocator.HEAP).when(rpcServer).getByteBuffAllocator(); }
Example #7
Source File: TestMasterAddressTracker.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testDeleteIfEquals() throws Exception { final ServerName sn = ServerName.valueOf("localhost", 1234, System.currentTimeMillis()); final MasterAddressTracker addressTracker = setupMasterTracker(sn, 1772); try { assertFalse("shouldn't have deleted wrong master server.", MasterAddressTracker.deleteIfEquals(addressTracker.getWatcher(), "some other string.")); } finally { assertTrue("Couldn't clean up master", MasterAddressTracker.deleteIfEquals(addressTracker.getWatcher(), sn.toString())); } }
Example #8
Source File: TestMasterAddressTracker.java From hbase with Apache License 2.0 | 5 votes |
/** * create an address tracker instance * @param sn if not-null set the active master * @param infoPort if there is an active master, set its info port. */ private MasterAddressTracker setupMasterTracker(final ServerName sn, final int infoPort) throws Exception { ZKWatcher zk = new ZKWatcher(TEST_UTIL.getConfiguration(), name.getMethodName(), null); ZKUtil.createAndFailSilent(zk, zk.getZNodePaths().baseZNode); // Should not have a master yet MasterAddressTracker addressTracker = new MasterAddressTracker(zk, null); addressTracker.start(); assertFalse(addressTracker.hasMaster()); zk.registerListener(addressTracker); // Use a listener to capture when the node is actually created NodeCreationListener listener = new NodeCreationListener(zk, zk.getZNodePaths().masterAddressZNode); zk.registerListener(listener); if (sn != null) { LOG.info("Creating master node"); MasterAddressTracker.setMasterAddress(zk, zk.getZNodePaths().masterAddressZNode, sn, infoPort); // Wait for the node to be created LOG.info("Waiting for master address manager to be notified"); listener.waitForCreation(); LOG.info("Master node created"); } return addressTracker; }
Example #9
Source File: TestMasterAddressTracker.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testNoBackups() throws Exception { final ServerName sn = ServerName.valueOf("localhost", 1234, System.currentTimeMillis()); final MasterAddressTracker addressTracker = setupMasterTracker(sn, 1772); try { assertEquals("Should receive 0 for backup not found.", 0, addressTracker.getBackupMasterInfoPort( ServerName.valueOf("doesnotexist.example.com", 1234, System.currentTimeMillis()))); } finally { assertTrue("Couldn't clean up master", MasterAddressTracker.deleteIfEquals(addressTracker.getWatcher(), sn.toString())); } }
Example #10
Source File: TestMasterAddressTracker.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testNoMaster() throws Exception { final MasterAddressTracker addressTracker = setupMasterTracker(null, 1772); assertFalse(addressTracker.hasMaster()); assertNull("should get null master when none active.", addressTracker.getMasterAddress()); assertEquals("Should receive 0 for backup not found.", 0, addressTracker.getMasterInfoPort()); }
Example #11
Source File: HMaster.java From hbase with Apache License 2.0 | 4 votes |
private void startActiveMasterManager(int infoPort) throws KeeperException { String backupZNode = ZNodePaths.joinZNode( zooKeeper.getZNodePaths().backupMasterAddressesZNode, serverName.toString()); /* * Add a ZNode for ourselves in the backup master directory since we * may not become the active master. If so, we want the actual active * master to know we are backup masters, so that it won't assign * regions to us if so configured. * * If we become the active master later, ActiveMasterManager will delete * this node explicitly. If we crash before then, ZooKeeper will delete * this node for us since it is ephemeral. */ LOG.info("Adding backup master ZNode " + backupZNode); if (!MasterAddressTracker.setMasterAddress(zooKeeper, backupZNode, serverName, infoPort)) { LOG.warn("Failed create of " + backupZNode + " by " + serverName); } this.activeMasterManager.setInfoPort(infoPort); int timeout = conf.getInt(HConstants.ZK_SESSION_TIMEOUT, HConstants.DEFAULT_ZK_SESSION_TIMEOUT); // If we're a backup master, stall until a primary to write this address if (conf.getBoolean(HConstants.MASTER_TYPE_BACKUP, HConstants.DEFAULT_MASTER_TYPE_BACKUP)) { LOG.debug("HMaster started in backup mode. Stalling until master znode is written."); // This will only be a minute or so while the cluster starts up, // so don't worry about setting watches on the parent znode while (!activeMasterManager.hasActiveMaster()) { LOG.debug("Waiting for master address and cluster state znode to be written."); Threads.sleep(timeout); } } MonitoredTask status = TaskMonitor.get().createStatus("Master startup"); status.setDescription("Master startup"); try { if (activeMasterManager.blockUntilBecomingActiveMaster(timeout, status)) { finishActiveMasterInitialization(status); } } catch (Throwable t) { status.setStatus("Failed to become active: " + t.getMessage()); LOG.error(HBaseMarkers.FATAL, "Failed to become active master", t); // HBASE-5680: Likely hadoop23 vs hadoop 20.x/1.x incompatibility if (t instanceof NoClassDefFoundError && t.getMessage(). contains("org/apache/hadoop/hdfs/protocol/HdfsConstants$SafeModeAction")) { // improved error message for this special case abort("HBase is having a problem with its Hadoop jars. You may need to recompile " + "HBase against Hadoop version " + org.apache.hadoop.util.VersionInfo.getVersion() + " or change your hadoop jars to start properly", t); } else { abort("Unhandled exception. Starting shutdown.", t); } } finally { status.cleanup(); } }
Example #12
Source File: HRegionServer.java From hbase with Apache License 2.0 | 4 votes |
/** * @return Master address tracker instance. */ public MasterAddressTracker getMasterAddressTracker() { return this.masterAddressTracker; }
Example #13
Source File: TestMasterStatusServlet.java From hbase with Apache License 2.0 | 4 votes |
@Before public void setupBasicMocks() { conf = HBaseConfiguration.create(); master = Mockito.mock(HMaster.class); Mockito.doReturn(FAKE_HOST).when(master).getServerName(); Mockito.doReturn(conf).when(master).getConfiguration(); //Fake DeadServer DeadServer deadServer = Mockito.mock(DeadServer.class); // Fake serverManager ServerManager serverManager = Mockito.mock(ServerManager.class); Mockito.doReturn(1.0).when(serverManager).getAverageLoad(); Mockito.doReturn(serverManager).when(master).getServerManager(); Mockito.doReturn(deadServer).when(serverManager).getDeadServers(); // Fake AssignmentManager and RIT AssignmentManager am = Mockito.mock(AssignmentManager.class); RegionStates rs = Mockito.mock(RegionStates.class); List<RegionState> regionsInTransition = new ArrayList<>(); regionsInTransition.add(new RegionState(FAKE_HRI, RegionState.State.CLOSING, 12345L, FAKE_HOST)); Mockito.doReturn(rs).when(am).getRegionStates(); Mockito.doReturn(regionsInTransition).when(rs).getRegionsInTransition(); Mockito.doReturn(am).when(master).getAssignmentManager(); Mockito.doReturn(serverManager).when(master).getServerManager(); // Fake ZKW ZKWatcher zkw = Mockito.mock(ZKWatcher.class); Mockito.doReturn(new ZNodePaths(conf)).when(zkw).getZNodePaths(); Mockito.doReturn("fakequorum").when(zkw).getQuorum(); Mockito.doReturn(zkw).when(master).getZooKeeper(); // Fake MasterAddressTracker MasterAddressTracker tracker = Mockito.mock(MasterAddressTracker.class); Mockito.doReturn(tracker).when(master).getMasterAddressTracker(); Mockito.doReturn(FAKE_HOST).when(tracker).getMasterAddress(); MetricsRegionServer rms = Mockito.mock(MetricsRegionServer.class); Mockito.doReturn(new MetricsRegionServerWrapperStub()).when(rms).getRegionServerWrapper(); Mockito.doReturn(rms).when(master).getMetrics(); // Mock admin admin = Mockito.mock(Admin.class); }
Example #14
Source File: TestMasterAddressTracker.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testParsingNull() throws Exception { assertNull("parse on null data should return null.", MasterAddressTracker.parse(null)); }