protected Region getRegionByEncodedName(byte[] regionName, String encodedRegionName) throws NotServingRegionException { Region region = this.onlineRegions.get(encodedRegionName); if (region == null) { MovedRegionInfo moveInfo = getMovedRegion(encodedRegionName); if (moveInfo != null) { throw new RegionMovedException(moveInfo.getServerName(), moveInfo.getSeqNum()); } Boolean isOpening = this.regionsInTransitionInRS.get(Bytes.toBytes(encodedRegionName)); String regionNameStr = regionName == null ? encodedRegionName : Bytes.toStringBinary(regionName); if (isOpening != null && isOpening.booleanValue()) { throw new RegionOpeningException( "Region " + regionNameStr + " is opening on " + this.serverName); } throw new NotServingRegionException( "Region " + regionNameStr + " is not online on " + this.serverName); } return region; }
private Throwable cleanup(final Throwable t, final String msg) { // Don't log as error if NSRE; NSRE is 'normal' operation. if (t instanceof NotServingRegionException) { LOG.debug("NotServingRegionException; " + t.getMessage()); return t; } if (msg == null) { LOG.error("", RemoteExceptionHandler.checkThrowable(t)); } else { LOG.error(msg, RemoteExceptionHandler.checkThrowable(t)); } if (!rpcServices.checkOOME(t)) { checkFileSystem(); } return t; }
@Test (timeout=300000) public void testCloseRegionIfInvalidRegionNameIsPassed() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion1"); createTableWithDefaultConf(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TableName.valueOf(TABLENAME)); List<HRegionInfo> onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()); for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaTable()) { if (regionInfo.getRegionNameAsString().contains("TestHBACloseRegion1")) { info = regionInfo; try { admin.closeRegionWithEncodedRegionName("sample", rs.getServerName() .getServerName()); } catch (NotServingRegionException nsre) { // expected, ignore it } } } } onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()); assertTrue("The region should be present in online regions list.", onlineRegions.contains(info)); }
@Test (timeout=300000) public void testCloseRegionWhenEncodedRegionNameIsNotGiven() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion4"); createTableWithDefaultConf(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TableName.valueOf(TABLENAME)); List<HRegionInfo> onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()); for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaTable()) { if (regionInfo.getRegionNameAsString().contains("TestHBACloseRegion4")) { info = regionInfo; try { admin.closeRegionWithEncodedRegionName(regionInfo .getRegionNameAsString(), rs.getServerName().getServerName()); } catch (NotServingRegionException nsre) { // expected, ignore it. } } } } onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()); assertTrue("The region should be present in online regions list.", onlineRegions.contains(info)); }
public static void checkRegionIsClosed(HBaseTestingUtility HTU, HRegionServer rs, HRegionInfo hri) throws Exception { while (!rs.getRegionsInTransitionInRS().isEmpty()) { Thread.sleep(1); } boolean exception = false; try { while ((rs.getRegion(hri.getRegionName()).isAvailable())) { Thread.sleep(10); } } catch (NotServingRegionException expected) { exception = true; // That's how it work: if the region is closed we have an exception. } assert(exception); // We don't delete the znode here, because there is not always a znode. }
private Throwable cleanup(final Throwable t, final String msg) { // Don't log as error if NSRE; NSRE is 'normal' operation. if (t instanceof NotServingRegionException) { LOG.debug("NotServingRegionException; " + t.getMessage()); return t; } if (msg == null) { LOG.error("", RemoteExceptionHandler.checkThrowable(t)); } else { LOG.error(msg, RemoteExceptionHandler.checkThrowable(t)); } if (!checkOOME(t)) { checkFileSystem(); } return t; }
@QosPriority(priority = HConstants.HIGH_QOS) protected boolean closeRegion(HRegionInfo region, final boolean zk, final int versionOfClosingNode) throws IOException { checkOpen(); // Check for permissions to close. HRegion actualRegion = this.getFromOnlineRegions(region.getEncodedName()); if (actualRegion != null && actualRegion.getCoprocessorHost() != null) { actualRegion.getCoprocessorHost().preClose(false); } LOG.info("Received close region: " + region.getRegionNameAsString() + ". Version of ZK closing node:" + versionOfClosingNode); boolean hasit = this.onlineRegions.containsKey(region.getEncodedName()); if (!hasit) { LOG.warn("Received close for region we are not serving; " + region.getEncodedName()); throw new NotServingRegionException("Received close for " + region.getRegionNameAsString() + " but we are not serving it"); } return closeRegion(region, false, zk, versionOfClosingNode); }
protected HRegion getRegionByEncodedName(byte[] regionName, String encodedRegionName) throws NotServingRegionException { HRegion region = this.onlineRegions.get(encodedRegionName); if (region == null) { MovedRegionInfo moveInfo = getMovedRegion(encodedRegionName); if (moveInfo != null) { throw new RegionMovedException(moveInfo.getServerName(), moveInfo.getSeqNum()); } Boolean isOpening = this.regionsInTransitionInRS.get(Bytes.toBytes(encodedRegionName)); String regionNameStr = regionName == null ? encodedRegionName : Bytes.toStringBinary(regionName); if (isOpening != null && isOpening.booleanValue()) { throw new RegionOpeningException("Region " + regionNameStr + " is opening on " + this.serverName); } throw new NotServingRegionException("Region " + regionNameStr + " is not online on " + this.serverName); } return region; }
@Override public void throwable(Throwable t, boolean retrying) { if (t instanceof SocketTimeoutException || t instanceof ConnectException || t instanceof RetriesExhaustedException || (location != null && getConnection().isDeadServer(location.getServerName()))) { // if thrown these exceptions, we clear all the cache entries that // map to that slow/dead server; otherwise, let cache miss and ask // hbase:meta again to find the new location if (this.location != null) getConnection().clearCaches(location.getServerName()); } else if (t instanceof RegionMovedException) { getConnection().updateCachedLocations(tableName, row, t, location); } else if (t instanceof NotServingRegionException && !retrying) { // Purge cache entries for this specific region from hbase:meta cache // since we don't call connect(true) when number of retries is 1. getConnection().deleteCachedRegionLocation(location); } }
protected HRegion getRegionByEncodedName(byte[] regionName, String encodedRegionName) throws NotServingRegionException { HRegion region = this.onlineRegions.get(encodedRegionName); if (region == null) { MovedRegionInfo moveInfo = getMovedRegion(encodedRegionName); if (moveInfo != null) { throw new RegionMovedException(moveInfo.getServerName(), moveInfo.getSeqNum()); } Boolean isOpening = this.regionsInTransitionInRS.get(Bytes.toBytes(encodedRegionName)); String regionNameStr = regionName == null? encodedRegionName: Bytes.toStringBinary(regionName); if (isOpening != null && isOpening.booleanValue()) { throw new RegionOpeningException("Region " + regionNameStr + " is opening on " + this.serverNameFromMasterPOV); } throw new NotServingRegionException("Region " + regionNameStr + " is not online on " + this.serverNameFromMasterPOV); } return region; }
protected Throwable cleanup(final Throwable t, final String msg) { // Don't log as error if NSRE; NSRE is 'normal' operation. if (t instanceof NotServingRegionException) { LOG.debug("NotServingRegionException; " + t.getMessage()); return t; } if (msg == null) { LOG.error("", RemoteExceptionHandler.checkThrowable(t)); } else { LOG.error(msg, RemoteExceptionHandler.checkThrowable(t)); } if (!checkOOME(t)) { checkFileSystem(); } return t; }
@Test (timeout=300000) public void testCloseRegionIfInvalidRegionNameIsPassed() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion1"); createTableWithDefaultConf(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); List<HRegionInfo> onlineRegions = ProtobufUtil.getOnlineRegions(rs); for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaTable()) { if (regionInfo.getRegionNameAsString().contains("TestHBACloseRegion1")) { info = regionInfo; try { admin.closeRegionWithEncodedRegionName("sample", rs.getServerName() .getServerName()); } catch (NotServingRegionException nsre) { // expected, ignore it } } } } onlineRegions = ProtobufUtil.getOnlineRegions(rs); assertTrue("The region should be present in online regions list.", onlineRegions.contains(info)); }
@Test (timeout=300000) public void testCloseRegionWhenEncodedRegionNameIsNotGiven() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion4"); createTableWithDefaultConf(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); List<HRegionInfo> onlineRegions = ProtobufUtil.getOnlineRegions(rs); for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaTable()) { if (regionInfo.getRegionNameAsString().contains("TestHBACloseRegion4")) { info = regionInfo; try { admin.closeRegionWithEncodedRegionName(regionInfo .getRegionNameAsString(), rs.getServerName().getServerName()); } catch (NotServingRegionException nsre) { // expected, ignore it. } } } } onlineRegions = ProtobufUtil.getOnlineRegions(rs); assertTrue("The region should be present in online regions list.", onlineRegions.contains(info)); }
@QosPriority(priority=HConstants.HIGH_QOS) protected boolean closeRegion(HRegionInfo region, final boolean zk, final int versionOfClosingNode) throws IOException { checkOpen(); //Check for permissions to close. HRegion actualRegion = this.getFromOnlineRegions(region.getEncodedName()); if (actualRegion != null && actualRegion.getCoprocessorHost() != null) { actualRegion.getCoprocessorHost().preClose(false); } LOG.info("Received close region: " + region.getRegionNameAsString() + ". Version of ZK closing node:" + versionOfClosingNode); boolean hasit = this.onlineRegions.containsKey(region.getEncodedName()); if (!hasit) { LOG.warn("Received close for region we are not serving; " + region.getEncodedName()); throw new NotServingRegionException("Received close for " + region.getRegionNameAsString() + " but we are not serving it"); } return closeRegion(region, false, zk, versionOfClosingNode); }
/** * This method needs to be called before any public call that reads or * modifies stores in bulk. It has to be called just before a try. * #closeBulkRegionOperation needs to be called in the try's finally block * Acquires a writelock and checks if the region is closing or closed. * @throws NotServingRegionException when the region is closing or closed * @throws RegionTooBusyException if failed to get the lock in time * @throws InterruptedIOException if interrupted while waiting for a lock */ private void startBulkRegionOperation(boolean writeLockNeeded) throws NotServingRegionException, RegionTooBusyException, InterruptedIOException { if (this.closing.get()) { throw new NotServingRegionException(regionInfo.getRegionNameAsString() + " is closing"); } if (writeLockNeeded) lock(lock.writeLock()); else lock(lock.readLock()); if (this.closed.get()) { if (writeLockNeeded) lock.writeLock().unlock(); else lock.readLock().unlock(); throw new NotServingRegionException(regionInfo.getRegionNameAsString() + " is closed"); } }
protected HRegion getRegionByEncodedName(byte[] regionName, String encodedRegionName) throws NotServingRegionException { HRegion region = this.onlineRegions.get(encodedRegionName); if (region == null) { MovedRegionInfo moveInfo = getMovedRegion(encodedRegionName); if (moveInfo != null) { throw new RegionMovedException(moveInfo.getServerName(), moveInfo.getSeqNum()); } Boolean isOpening = this.regionsInTransitionInRS.get(Bytes.toBytes(encodedRegionName)); String regionNameStr = regionName == null? encodedRegionName: Bytes.toStringBinary(regionName); if (isOpening != null && isOpening.booleanValue()) { throw new RegionOpeningException("Region " + regionNameStr + " is opening on " + this.serverName); } throw new NotServingRegionException("" + regionNameStr + " is not online on " + this.serverName); } return region; }
private Throwable cleanup(final Throwable t, final String msg) { // Don't log as error if NSRE; NSRE is 'normal' operation. if (t instanceof NotServingRegionException) { LOG.debug("NotServingRegionException; " + t.getMessage()); return t; } Throwable e = t instanceof RemoteException ? ((RemoteException) t).unwrapRemoteException() : t; if (msg == null) { LOG.error("", e); } else { LOG.error(msg, e); } if (!rpcServices.checkOOME(t)) { checkFileSystem(); } return t; }
@Override protected CloseRegionResponse execCloseRegion(ServerName server, byte[] regionName) throws IOException { switch (this.invocations++) { case 0: throw new NotServingRegionException("Fake"); case 1: throw new RegionServerAbortedException("Fake!"); case 2: throw new RegionServerStoppedException("Fake!"); case 3: throw new ServerNotRunningYetException("Fake!"); case 4: LOG.info("Return null response from serverName=" + server + "; means STUCK...TODO timeout"); executor.schedule(new Runnable() { @Override public void run() { LOG.info("Sending in CRASH of " + server); doCrash(server); } }, 1, TimeUnit.SECONDS); return null; default: return super.execCloseRegion(server, regionName); } }
@QosPriority(priority=HIGH_QOS) protected boolean closeRegion(HRegionInfo region, final boolean zk, final int versionOfClosingNode) throws IOException { checkOpen(); LOG.info("Received close region: " + region.getRegionNameAsString() + ". Version of ZK closing node:" + versionOfClosingNode); boolean hasit = this.onlineRegions.containsKey(region.getEncodedName()); if (!hasit) { LOG.warn("Received close for region we are not serving; " + region.getEncodedName()); throw new NotServingRegionException("Received close for " + region.getRegionNameAsString() + " but we are not serving it"); } checkIfRegionInTransition(region, CLOSE); return closeRegion(region, false, zk, versionOfClosingNode); }
/** * This method needs to be called before any public call that reads or * modifies stores in bulk. It has to be called just before a try. * #closeBulkRegionOperation needs to be called in the try's finally block * Acquires a writelock and checks if the region is closing or closed. * @throws NotServingRegionException when the region is closing or closed */ private void startBulkRegionOperation(boolean writeLockNeeded) throws NotServingRegionException { if (this.closing.get()) { throw new NotServingRegionException(regionInfo.getRegionNameAsString() + " is closing"); } if (writeLockNeeded) lock.writeLock().lock(); else lock.readLock().lock(); if (this.closed.get()) { if (writeLockNeeded) lock.writeLock().unlock(); else lock.readLock().unlock(); throw new NotServingRegionException(regionInfo.getRegionNameAsString() + " is closed"); } }
protected HRegion getRegionByEncodedName(byte[] regionName, String encodedRegionName) throws NotServingRegionException { HRegion region = this.onlineRegions.get(encodedRegionName); if (region == null) { MovedRegionInfo moveInfo = getMovedRegion(encodedRegionName); if (moveInfo != null) { throw new RegionMovedException(moveInfo.getServerName(), moveInfo.getSeqNum()); } Boolean isOpening = this.regionsInTransitionInRS.get(Bytes.toBytes(encodedRegionName)); String regionNameStr = regionName == null? encodedRegionName: Bytes.toStringBinary(regionName); if (isOpening != null && isOpening.booleanValue()) { throw new RegionOpeningException("Region " + regionNameStr + " is opening on " + this.serverName); } throw new NotServingRegionException("Region " + regionNameStr + " is not online on " + this.serverName); } return region; }
@Test (timeout=300000) public void testCloseRegionIfInvalidRegionNameIsPassed() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion1"); createTableWithDefaultConf(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); List<HRegionInfo> onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()); for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaTable()) { if (regionInfo.getRegionNameAsString().contains("TestHBACloseRegion1")) { info = regionInfo; try { admin.closeRegionWithEncodedRegionName("sample", rs.getServerName() .getServerName()); } catch (NotServingRegionException nsre) { // expected, ignore it } } } } onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()); assertTrue("The region should be present in online regions list.", onlineRegions.contains(info)); }
@Test (timeout=300000) public void testCloseRegionWhenEncodedRegionNameIsNotGiven() throws Exception { byte[] TABLENAME = Bytes.toBytes("TestHBACloseRegion4"); createTableWithDefaultConf(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); List<HRegionInfo> onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()); for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaTable()) { if (regionInfo.getRegionNameAsString().contains("TestHBACloseRegion4")) { info = regionInfo; try { admin.closeRegionWithEncodedRegionName(regionInfo .getRegionNameAsString(), rs.getServerName().getServerName()); } catch (NotServingRegionException nsre) { // expected, ignore it. } } } } onlineRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices()); assertTrue("The region should be present in online regions list.", onlineRegions.contains(info)); }
@Override public void throwable(Throwable t, boolean retrying) { if (t instanceof SocketTimeoutException || t instanceof ConnectException || t instanceof RetriesExhaustedException || (location != null && getConnection().isDeadServer(location.getServerName()))) { // if thrown these exceptions, we clear all the cache entries that // map to that slow/dead server; otherwise, let cache miss and ask // hbase:meta again to find the new location if (this.location != null) getConnection().clearCaches(location.getServerName()); } else if (t instanceof RegionMovedException) { getConnection().updateCachedLocations(tableName, row, t, location.getServerName()); } else if (t instanceof NotServingRegionException && !retrying) { // Purge cache entries for this specific region from hbase:meta cache // since we don't call connect(true) when number of retries is 1. getConnection().deleteCachedRegionLocation(location); } }
protected HRegion getRegionByEncodedName(byte[] regionName, String encodedRegionName) throws NotServingRegionException { HRegion region = this.onlineRegions.get(encodedRegionName); if (region == null) { MovedRegionInfo moveInfo = getMovedRegion(encodedRegionName); if (moveInfo != null) { throw new RegionMovedException(moveInfo.getServerName(), moveInfo.getSeqNum()); } Boolean isOpening = this.regionsInTransitionInRS.get(Bytes.toBytes(encodedRegionName)); String regionNameStr = regionName == null? encodedRegionName: Bytes.toStringBinary(regionName); if (isOpening != null && isOpening.booleanValue()) { throw new RegionOpeningException("Region " + regionNameStr + " is opening"); } throw new NotServingRegionException("Region " + regionNameStr + " is not online"); } return region; }