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; }
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; }
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 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; }
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; }
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; }
public static List<Throwable> metaCachePreservingExceptions() { return new ArrayList<Throwable>() {{ add(new RegionOpeningException(" ")); add(new RegionTooBusyException()); add(new ThrottlingException(" ")); add(new MultiActionResultTooLarge(" ")); add(new RetryImmediatelyException(" ")); add(new CallQueueTooBigException()); }}; }
/** * Look for an exception we know in the remote exception: * - hadoop.ipc wrapped exceptions * - nested exceptions * <p/> * Looks for: RegionMovedException / RegionOpeningException / RegionTooBusyException * * @return null if we didn't find the exception, the exception otherwise. */ public static Throwable findException(Object exception) { if (exception == null || !(exception instanceof Throwable)) { return null; } Throwable cur = (Throwable) exception; while (cur != null) { if (cur instanceof RegionMovedException || cur instanceof RegionOpeningException || cur instanceof RegionTooBusyException) { return cur; } if (cur instanceof RemoteException) { RemoteException re = (RemoteException) cur; cur = re.unwrapRemoteException( RegionOpeningException.class, RegionMovedException.class, RegionTooBusyException.class); if (cur == null) { cur = re.unwrapRemoteException(); } // unwrapRemoteException can return the exception given as a parameter when it cannot // unwrap it. In this case, there is no need to look further // noinspection ObjectEquality if (cur == re) { return null; } } else { cur = cur.getCause(); } } return null; }
/** * Look for an exception we know in the remote exception: * - hadoop.ipc wrapped exceptions * - nested exceptions * * Looks for: RegionMovedException / RegionOpeningException / RegionTooBusyException * @return null if we didn't find the exception, the exception otherwise. */ public static Throwable findException(Object exception) { if (exception == null || !(exception instanceof Throwable)) { return null; } Throwable cur = (Throwable) exception; while (cur != null) { if (cur instanceof RegionMovedException || cur instanceof RegionOpeningException || cur instanceof RegionTooBusyException) { return cur; } if (cur instanceof RemoteException) { RemoteException re = (RemoteException) cur; cur = re.unwrapRemoteException( RegionOpeningException.class, RegionMovedException.class, RegionTooBusyException.class); if (cur == null) { cur = re.unwrapRemoteException(); } // unwrapRemoteException can return the exception given as a parameter when it cannot // unwrap it. In this case, there is no need to look further // noinspection ObjectEquality if (cur == re) { return null; } } else { cur = cur.getCause(); } } return null; }
public static List<Throwable> metaCachePreservingExceptions() { return new ArrayList<Throwable>() {{ add(new RegionOpeningException(" ")); add(new RegionTooBusyException("Some old message")); add(new ThrottlingException(" ")); add(new MultiActionResultTooLarge(" ")); add(new RetryImmediatelyException(" ")); add(new CallQueueTooBigException()); }}; }
/** * Update the location with the new value (if the exception is a RegionMovedException) * or delete it from the cache. Does nothing if we can be sure from the exception that * the location is still accurate, or if the cache has already been updated. * * @param exception an object (to simplify user code) on which we will try to find a nested * or wrapped or both RegionMovedException * @param source server that is the source of the location update. */ @Override public void updateCachedLocations(final TableName tableName, byte[] regionName, byte[] rowkey, final Object exception, final ServerName source) { if (rowkey == null || tableName == null) { LOG.warn("Coding error, see method javadoc. row=" + (rowkey == null ? "null" : rowkey) + ", tableName=" + (tableName == null ? "null" : tableName)); return; } if (source == null) { // This should not happen, but let's secure ourselves. return; } if (regionName == null) { // we do not know which region, so just remove the cache entry for the row and server metaCache.clearCache(tableName, rowkey, source); return; } // Is it something we have already updated? final RegionLocations oldLocations = getCachedLocation(tableName, rowkey); HRegionLocation oldLocation = null; if (oldLocations != null) { oldLocation = oldLocations.getRegionLocationByRegionName(regionName); } if (oldLocation == null || !source.equals(oldLocation.getServerName())) { // There is no such location in the cache (it's been removed already) or // the cache has already been refreshed with a different location. => nothing to do return; } HRegionInfo regionInfo = oldLocation.getRegionInfo(); Throwable cause = findException(exception); if (cause != null) { if (cause instanceof RegionTooBusyException || cause instanceof RegionOpeningException) { // We know that the region is still on this region server return; } if (cause instanceof RegionMovedException) { RegionMovedException rme = (RegionMovedException) cause; if (LOG.isTraceEnabled()) { LOG.trace("Region " + regionInfo.getRegionNameAsString() + " moved to " + rme.getHostname() + ":" + rme.getPort() + " according to " + source.getHostAndPort()); } // We know that the region is not anymore on this region server, but we know // the new location. updateCachedLocation( regionInfo, source, rme.getServerName(), rme.getLocationSeqNum()); return; } } // If we're here, it means that can cannot be sure about the location, so we remove it from // the cache. Do not send the source because source can be a new server in the same host:port metaCache.clearCache(regionInfo); }
/** * Update the location with the new value (if the exception is a RegionMovedException) * or delete it from the cache. Does nothing if we can be sure from the exception that * the location is still accurate, or if the cache has already been updated. * @param exception an object (to simplify user code) on which we will try to find a nested * or wrapped or both RegionMovedException * @param source server that is the source of the location update. */ @Override public void updateCachedLocations(final TableName tableName, byte[] rowkey, final Object exception, final HRegionLocation source) { if (rowkey == null || tableName == null) { LOG.warn("Coding error, see method javadoc. row=" + (rowkey == null ? "null" : rowkey) + ", tableName=" + (tableName == null ? "null" : tableName)); return; } if (source == null || source.getServerName() == null){ // This should not happen, but let's secure ourselves. return; } // Is it something we have already updated? final HRegionLocation oldLocation = getCachedLocation(tableName, rowkey); if (oldLocation == null || !source.getServerName().equals(oldLocation.getServerName())) { // There is no such location in the cache (it's been removed already) or // the cache has already been refreshed with a different location. => nothing to do return; } HRegionInfo regionInfo = oldLocation.getRegionInfo(); Throwable cause = findException(exception); if (cause != null) { if (cause instanceof RegionTooBusyException || cause instanceof RegionOpeningException) { // We know that the region is still on this region server return; } if (cause instanceof RegionMovedException) { RegionMovedException rme = (RegionMovedException) cause; if (LOG.isTraceEnabled()) { LOG.trace("Region " + regionInfo.getRegionNameAsString() + " moved to " + rme.getHostname() + ":" + rme.getPort() + " according to " + source.getHostnamePort()); } // We know that the region is not anymore on this region server, but we know // the new location. updateCachedLocation( regionInfo, source, rme.getServerName(), rme.getLocationSeqNum()); return; } } // If we're here, it means that can cannot be sure about the location, so we remove it from // the cache. deleteCachedLocation(regionInfo, source); }
/** * Update the location with the new value (if the exception is a RegionMovedException) * or delete it from the cache. Does nothing if we can be sure from the exception that * the location is still accurate, or if the cache has already been updated. * @param exception an object (to simplify user code) on which we will try to find a nested * or wrapped or both RegionMovedException * @param source server that is the source of the location update. */ @Override public void updateCachedLocations(final TableName tableName, byte[] rowkey, final Object exception, final ServerName source) { if (rowkey == null || tableName == null) { LOG.warn("Coding error, see method javadoc. row=" + (rowkey == null ? "null" : rowkey) + ", tableName=" + (tableName == null ? "null" : tableName)); return; } if (source == null) { // This should not happen, but let's secure ourselves. return; } // Is it something we have already updated? final HRegionLocation oldLocation = getCachedLocation(tableName, rowkey); if (oldLocation == null || !source.equals(oldLocation.getServerName())) { // There is no such location in the cache (it's been removed already) or // the cache has already been refreshed with a different location. => nothing to do return; } HRegionInfo regionInfo = oldLocation.getRegionInfo(); Throwable cause = findException(exception); if (cause != null) { if (cause instanceof RegionTooBusyException || cause instanceof RegionOpeningException) { // We know that the region is still on this region server return; } if (cause instanceof RegionMovedException) { RegionMovedException rme = (RegionMovedException) cause; if (LOG.isTraceEnabled()) { LOG.trace("Region " + regionInfo.getRegionNameAsString() + " moved to " + rme.getHostname() + ":" + rme.getPort() + " according to " + source.getHostAndPort()); } // We know that the region is not anymore on this region server, but we know // the new location. updateCachedLocation( regionInfo, source, rme.getServerName(), rme.getLocationSeqNum()); return; } } // If we're here, it means that can cannot be sure about the location, so we remove it from // the cache. deleteCachedLocation(regionInfo, source); }