/** * Ensure Armeria's dependencies do not cause a trouble with hbase-shaded-client. * * @see <a href="https://issues.apache.org/jira/browse/HBASE-14963">HBASE-14963</a> */ @Test(expected = NotAllMetaRegionsOnlineException.class) public void testGuavaConflict() throws Exception { // Make sure Armeria is available in the class path. assertThat(Version.identify(Server.class.getClassLoader())).isNotNull(); // Make sure newer Guava is available in the class path. assertThat(Stopwatch.class.getDeclaredConstructor().getModifiers()).is(new Condition<>( value -> !Modifier.isPublic(value), "Recent Guava Stopwatch should have non-public default constructor.")); final MetaTableLocator locator = new MetaTableLocator(); final ZooKeeperWatcher zkw = mock(ZooKeeperWatcher.class); final RecoverableZooKeeper zk = mock(RecoverableZooKeeper.class); when(zkw.getRecoverableZooKeeper()).thenReturn(zk); when(zk.exists(any(), any())).thenReturn(new Stat(0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0)); locator.waitMetaRegionLocation(zkw, 100); } }
/** * Setup our cluster connection if not already initialized. * @throws IOException */ protected synchronized void setupClusterConnection() throws IOException { if (clusterConnection == null) { clusterConnection = createClusterConnection(); metaTableLocator = new MetaTableLocator(); } }
void doWaiting() throws InterruptedException { try { while (new MetaTableLocator().waitMetaRegionLocation(watcher, 10000) == null); } catch (NotAllMetaRegionsOnlineException e) { //Ignore } } }
private ServerName getMetaRegionServerName(int replicaId) throws IOException, KeeperException { ZooKeeperWatcher zkw = createZooKeeperWatcher(); ServerName sn = null; try { sn = new MetaTableLocator().getMetaRegionLocation(zkw, replicaId); } finally { zkw.close(); } return sn; }
+ new MetaTableLocator().getMetaRegionLocation(zkw)); Configuration conf = HBaseConfiguration.create(); int numMetaReplicas = conf.getInt(HConstants.META_REPLICAS_NUM, for (int i = 1; i < numMetaReplicas; i++) { sb.append("\nRegion server holding hbase:meta, replicaId " + i + " " + new MetaTableLocator().getMetaRegionLocation(zkw, i));
@Test (expected = NotAllMetaRegionsOnlineException.class) public void testTimeoutWaitForMeta() throws IOException, InterruptedException { new MetaTableLocator().waitMetaRegionLocation(watcher, 100); }
@After public void after() { try { // Clean out meta location or later tests will be confused... they presume // start fresh in zk. new MetaTableLocator().deleteMetaLocation(this.watcher); } catch (KeeperException e) { LOG.warn("Unable to delete hbase:meta location", e); } this.watcher.close(); }
@Test public void testGetRegionsFromMetaTable() throws IOException, InterruptedException { List<RegionInfo> regions = new MetaTableLocator().getMetaRegions(UTIL.getZooKeeperWatcher()); assertTrue(regions.size() >= 1); assertTrue(new MetaTableLocator().getMetaRegionsAndLocations( UTIL.getZooKeeperWatcher()).size() >= 1); }
ServerName serverName = new MetaTableLocator().getMetaRegionLocation(zkw); List<Pair<HRegionInfo, ServerName>> list = new ArrayList<Pair<HRegionInfo, ServerName>>();
LOG.trace("Looking up meta region location in ZK," + " connection=" + this); List<ServerName> servers = new MetaTableLocator().blockUntilAvailable(zkw, hci.rpcTimeout, hci.getConfiguration()); if (LOG.isTraceEnabled()) {
/** * Used by the client to identify if all regions have the schema updates * * @param tableName * @return Pair indicating the status of the alter command * @throws IOException */ public Pair<Integer, Integer> getReopenStatus(TableName tableName) throws IOException { List<HRegionInfo> hris; if (TableName.META_TABLE_NAME.equals(tableName)) { hris = new MetaTableLocator().getMetaRegions(server.getZooKeeper()); } else { hris = MetaTableAccessor.getTableRegions(server.getZooKeeper(), server.getConnection(), tableName, true); } Integer pending = 0; for (HRegionInfo hri : hris) { String name = hri.getEncodedName(); // no lock concurrent access ok: sequential consistency respected. if (regionsToReopen.containsKey(name) || regionStates.isRegionInTransition(name)) { pending++; } } return new Pair<Integer, Integer>(pending, hris.size()); }
sn, RegionState.State.OPENING); assertFalse(new MetaTableLocator().verifyMetaRegionLocation(connection, watcher, 100)); MetaTableLocator.setMetaLocation(this.watcher, sn, RegionState.State.OPEN); assertFalse(new MetaTableLocator().verifyMetaRegionLocation(connection, watcher, 100));
private void testVerifyMetaRegionLocationWithException(Exception ex) throws IOException, InterruptedException, KeeperException, ServiceException { // Mock an ClientProtocol. final ClientProtos.ClientService.BlockingInterface implementation = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); ClusterConnection connection = mockConnection(null, implementation); // If a 'get' is called on mocked interface, throw connection refused. Mockito.when(implementation.get((RpcController) Mockito.any(), (GetRequest) Mockito.any())). thenThrow(new ServiceException(ex)); long timeout = UTIL.getConfiguration(). getLong("hbase.catalog.verification.timeout", 1000); MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPENING); assertFalse(new MetaTableLocator().verifyMetaRegionLocation( connection, watcher, timeout)); MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN); assertFalse(new MetaTableLocator().verifyMetaRegionLocation( connection, watcher, timeout)); }
thenReturn(GetResponse.newBuilder().build()); final MetaTableLocator mtl = new MetaTableLocator(); ServerName meta = new MetaTableLocator().getMetaRegionLocation(this.watcher); assertNull(meta); Thread t = new Thread() {
List<HRegionInfo> regions; if (TableName.META_TABLE_NAME.equals(tableName)) { regions = new MetaTableLocator().getMetaRegions(services.getZooKeeper()); } else { regions = MetaTableAccessor.getTableRegions(services.getZooKeeper(),
@Override public List<HRegionInfo> evaluate() throws IOException { if (TableName.META_TABLE_NAME.equals(tableName)) { return new MetaTableLocator().getMetaRegions(env.getMasterServices().getZooKeeper()); } return MetaTableAccessor.getTableRegions(env.getMasterServices().getZooKeeper(), env.getMasterServices().getConnection(), tableName); } });
/** * Test waiting on meat w/ no timeout specified. * @throws IOException * @throws InterruptedException * @throws KeeperException */ @Test public void testNoTimeoutWaitForMeta() throws IOException, InterruptedException, KeeperException { final MetaTableLocator mtl = new MetaTableLocator(); ServerName hsa = mtl.getMetaRegionLocation(watcher); assertNull(hsa); // Now test waiting on meta location getting set. Thread t = new WaitOnMetaThread(); startWaitAliveThenWaitItLives(t, 1); // Set a meta location. MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN); hsa = SN; // Join the thread... should exit shortly. t.join(); // Now meta is available. assertTrue(mtl.getMetaRegionLocation(watcher).equals(hsa)); }
.getLiveRegionServerThreads().get(0).getRegionServer(); ZKWatcher zkw = hrs.getZooKeeper(); MetaTableLocator mtl = new MetaTableLocator(); ServerName sn = mtl.getMetaRegionLocation(zkw); if (sn != null && !masterAddr.equals(sn)) {
hris = new MetaTableLocator().getMetaRegions(server.getZooKeeper()); } else { hris = MetaTableAccessor.getTableRegions(server.getZooKeeper(),
/** * Test normal operations */ @Test public void testMetaLookup() throws IOException, InterruptedException, ServiceException, KeeperException { final ClientProtos.ClientService.BlockingInterface client = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class); Mockito.when(client.get((RpcController)Mockito.any(), (GetRequest)Mockito.any())). thenReturn(GetResponse.newBuilder().build()); final MetaTableLocator mtl = new MetaTableLocator(); assertNull(mtl.getMetaRegionLocation(this.watcher)); for (RegionState.State state : RegionState.State.values()) { if (state.equals(RegionState.State.OPEN)) continue; MetaTableLocator.setMetaLocation(this.watcher, SN, state); assertNull(mtl.getMetaRegionLocation(this.watcher)); assertEquals(state, MetaTableLocator.getMetaRegionState(this.watcher).getState()); } MetaTableLocator.setMetaLocation(this.watcher, SN, RegionState.State.OPEN); assertEquals(SN, mtl.getMetaRegionLocation(this.watcher)); assertEquals(RegionState.State.OPEN, MetaTableLocator.getMetaRegionState(this.watcher).getState()); mtl.deleteMetaLocation(this.watcher); assertNull(MetaTableLocator.getMetaRegionState(this.watcher).getServerName()); assertEquals(RegionState.State.OFFLINE, MetaTableLocator.getMetaRegionState(this.watcher).getState()); assertNull(mtl.getMetaRegionLocation(this.watcher)); }