/** * Gets the meta region location, if available, and waits for up to the specified timeout if not * immediately available. Given the zookeeper notification could be delayed, we will try to get * the latest data. * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation * @param timeout maximum time to wait, in millis * @return server name for server hosting meta region formatted as per {@link ServerName}, or null * if none available * @throws InterruptedException if interrupted while waiting * @throws NotAllMetaRegionsOnlineException if a meta or root region is not online */ public static ServerName waitMetaRegionLocation(ZKWatcher zkw, long timeout) throws InterruptedException, NotAllMetaRegionsOnlineException { return waitMetaRegionLocation(zkw, RegionInfo.DEFAULT_REPLICA_ID, timeout); }
void doWaiting() throws InterruptedException { try { for (;;) { if (MetaTableLocator.waitMetaRegionLocation(watcher, 10000) != null) { break; } } } catch (NotAllMetaRegionsOnlineException e) { // Ignore } } }
protected static void waitMetaRegions(final MasterProcedureEnv env) throws IOException { int timeout = env.getMasterConfiguration().getInt("hbase.client.catalog.timeout", 10000); try { if (MetaTableLocator.waitMetaRegionLocation(env.getMasterServices().getZooKeeper(), timeout) == null) { throw new NotAllMetaRegionsOnlineException(); } } catch (InterruptedException e) { throw (InterruptedIOException) new InterruptedIOException().initCause(e); } }
@Test(expected = NotAllMetaRegionsOnlineException.class) public void testTimeoutWaitForMeta() throws IOException, InterruptedException { MetaTableLocator.waitMetaRegionLocation(watcher, 100); }
/** * 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); } }
RegionInfo meta = RegionReplicaUtil.getRegionInfoForReplica( RegionInfoBuilder.FIRST_META_REGIONINFO, j); ServerName metaLocation = MetaTableLocator.waitMetaRegionLocation(master.getZooKeeper(), j, 1); for (int i = 0; i < 1; i++) { String hostAndPort = "";
/** * Gets the meta region location, if available, and waits for up to the * specified timeout if not immediately available. * Given the zookeeper notification could be delayed, we will try to * get the latest data. * @param zkw * @param timeout maximum time to wait, in millis * @return server name for server hosting meta region formatted as per * {@link ServerName}, or null if none available * @throws InterruptedException if interrupted while waiting * @throws NotAllMetaRegionsOnlineException */ public ServerName waitMetaRegionLocation(ZooKeeperWatcher zkw, long timeout) throws InterruptedException, NotAllMetaRegionsOnlineException { return waitMetaRegionLocation(zkw, HRegionInfo.DEFAULT_REPLICA_ID, timeout); }
/** * Gets the meta region location, if available, and waits for up to the * specified timeout if not immediately available. * Given the zookeeper notification could be delayed, we will try to * get the latest data. * * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation * @param timeout maximum time to wait, in millis * @return server name for server hosting meta region formatted as per * {@link ServerName}, or null if none available * @throws InterruptedException if interrupted while waiting * @throws NotAllMetaRegionsOnlineException if a meta or root region is not online */ public ServerName waitMetaRegionLocation(ZKWatcher zkw, long timeout) throws InterruptedException, NotAllMetaRegionsOnlineException { return waitMetaRegionLocation(zkw, RegionInfo.DEFAULT_REPLICA_ID, timeout); }
/** * Gets a connection to the server hosting meta, as reported by ZooKeeper, waiting up to the * specified timeout for availability. * * <p>WARNING: Does not retry. Use an {@link org.apache.hadoop.hbase.client.HTable} instead. * * @param connection the connection to use * @param zkw reference to the {@link ZKWatcher} which also contains configuration and operation * @param timeout How long to wait on meta location * @param replicaId the ID of the replica * @return connection to server hosting meta * @throws InterruptedException if waiting for the socket operation fails * @throws IOException if the number of retries for getting the connection is exceeded */ private AdminService.BlockingInterface getMetaServerConnection(ClusterConnection connection, ZKWatcher zkw, long timeout, int replicaId) throws InterruptedException, IOException { return getCachedConnection(connection, waitMetaRegionLocation(zkw, replicaId, timeout)); }
/** * Gets a connection to the server hosting meta, as reported by ZooKeeper, * waiting up to the specified timeout for availability. * <p>WARNING: Does not retry. Use an {@link org.apache.hadoop.hbase.client.HTable} instead. * @param hConnection * @param zkw * @param timeout How long to wait on meta location * @param replicaId * @return connection to server hosting meta * @throws InterruptedException * @throws NotAllMetaRegionsOnlineException if timed out waiting * @throws IOException */ private AdminService.BlockingInterface getMetaServerConnection(HConnection hConnection, ZooKeeperWatcher zkw, long timeout, int replicaId) throws InterruptedException, NotAllMetaRegionsOnlineException, IOException { return getCachedConnection(hConnection, waitMetaRegionLocation(zkw, replicaId, timeout)); }
@Override public void run() { try { mtl.waitMetaRegionLocation(watcher); } catch (InterruptedException e) { throw new RuntimeException("Interrupted", e); } } };
/** * Waits indefinitely for availability of <code>hbase:meta</code>. Used during * cluster startup. Does not verify meta, just that something has been * set up in zk. * @see #waitMetaRegionLocation(ZKWatcher, long) * @throws InterruptedException if interrupted while waiting */ public void waitMetaRegionLocation(ZKWatcher zkw) throws InterruptedException { long startTime = System.currentTimeMillis(); while (!stopped) { try { if (waitMetaRegionLocation(zkw, 100) != null) { break; } long sleepTime = System.currentTimeMillis() - startTime; // +1 in case sleepTime=0 if ((sleepTime + 1) % 10000 == 0) { LOG.warn("Have been waiting for meta to be assigned for " + sleepTime + "ms"); } } catch (NotAllMetaRegionsOnlineException e) { if (LOG.isTraceEnabled()) { LOG.trace("hbase:meta still not available, sleeping and retrying." + " Reason: " + e.getMessage()); } } } }
void doWaiting() throws InterruptedException { try { while (new MetaTableLocator().waitMetaRegionLocation(watcher, 10000) == null); } catch (NotAllMetaRegionsOnlineException e) { //Ignore } } }
protected static void waitMetaRegions(final MasterProcedureEnv env) throws IOException { int timeout = env.getMasterConfiguration().getInt("hbase.client.catalog.timeout", 10000); try { if (env.getMasterServices().getMetaTableLocator().waitMetaRegionLocation( env.getMasterServices().getZooKeeper(), timeout) == null) { throw new NotAllMetaRegionsOnlineException(); } } catch (InterruptedException e) { throw (InterruptedIOException)new InterruptedIOException().initCause(e); } }
@Test (expected = NotAllMetaRegionsOnlineException.class) public void testTimeoutWaitForMeta() throws IOException, InterruptedException { new MetaTableLocator().waitMetaRegionLocation(watcher, 100); }
private void enableCrashedServerProcessing(final boolean waitForMeta) throws IOException, InterruptedException { // If crashed server processing is disabled, we enable it and expire those dead but not expired // servers. This is required so that if meta is assigning to a server which dies after // assignMeta starts assignment, ServerCrashProcedure can re-assign it. Otherwise, we will be // stuck here waiting forever if waitForMeta is specified. if (!isServerCrashProcessingEnabled()) { setServerCrashProcessingEnabled(true); this.serverManager.processQueuedDeadServers(); } if (waitForMeta) { metaTableLocator.waitMetaRegionLocation(this.getZooKeeper()); // Above check waits for general meta availability but this does not // guarantee that the transition has completed this.assignmentManager.waitForAssignment(HRegionInfo.FIRST_META_REGIONINFO); } }
/** * Waits indefinitely for availability of <code>hbase:meta</code>. Used during * cluster startup. Does not verify meta, just that something has been * set up in zk. * @see #waitMetaRegionLocation(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher, long) * @throws InterruptedException if interrupted while waiting */ public void waitMetaRegionLocation(ZooKeeperWatcher zkw) throws InterruptedException { Stopwatch stopwatch = new Stopwatch().start(); while (!stopped) { try { if (waitMetaRegionLocation(zkw, 100) != null) break; long sleepTime = stopwatch.elapsedMillis(); // +1 in case sleepTime=0 if ((sleepTime + 1) % 10000 == 0) { LOG.warn("Have been waiting for meta to be assigned for " + sleepTime + "ms"); } } catch (NotAllMetaRegionsOnlineException e) { if (LOG.isTraceEnabled()) { LOG.trace("hbase:meta still not available, sleeping and retrying." + " Reason: " + e.getMessage()); } } } }
if (server.getMetaTableLocator().waitMetaRegionLocation( server.getZooKeeper(), timeout) == null) { throw new NotAllMetaRegionsOnlineException();
@SuppressWarnings("deprecation") protected boolean wasRegionOnDeadServerByMeta( final HRegionInfo region, final ServerName sn) { try { if (region.isMetaRegion()) { ServerName server = this.server.getMetaTableLocator(). getMetaRegionLocation(this.server.getZooKeeper()); return regionStates.isServerDeadAndNotProcessed(server); } while (!server.isStopped()) { try { this.server.getMetaTableLocator().waitMetaRegionLocation(server.getZooKeeper()); Result r = MetaTableAccessor.getRegionResult(server.getConnection(), region.getRegionName()); if (r == null || r.isEmpty()) return false; ServerName server = HRegionInfo.getServerName(r); return regionStates.isServerDeadAndNotProcessed(server); } catch (IOException ioe) { LOG.info("Received exception accessing hbase:meta during force assign " + region.getRegionNameAsString() + ", retrying", ioe); } } } catch (InterruptedException e) { Thread.currentThread().interrupt(); LOG.info("Interrupted accessing hbase:meta", e); } // Call is interrupted or server is stopped. return regionStates.isServerDeadAndNotProcessed(sn); }
HRegionInfo meta = RegionReplicaUtil.getRegionInfoForReplica( HRegionInfo.FIRST_META_REGIONINFO, j); ServerName metaLocation = metaTableLocator.waitMetaRegionLocation(master.getZooKeeper(), j, 1); for (int i = 0; i < 1; i++) { String url = "//" + metaLocation.getHostname() + ":" +