Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/HClient.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/HClient.java (revision 555417) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/HClient.java (working copy) @@ -15,12 +15,9 @@ */ package org.apache.hadoop.hbase; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; import java.util.Map; import java.util.NoSuchElementException; import java.util.Random; @@ -27,7 +24,6 @@ import java.util.SortedMap; import java.util.TreeMap; import java.util.TreeSet; -import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -36,9 +32,6 @@ import org.apache.hadoop.hbase.io.KeyedData; import org.apache.hadoop.io.DataInputBuffer; import org.apache.hadoop.io.Text; -import org.apache.hadoop.io.retry.RetryPolicies; -import org.apache.hadoop.io.retry.RetryPolicy; -import org.apache.hadoop.io.retry.RetryProxy; import org.apache.hadoop.ipc.RPC; import org.apache.hadoop.ipc.RemoteException; @@ -261,8 +254,8 @@ checkMaster(); try { this.master.createTable(desc); - } catch (Exception e) { - RemoteExceptionHandler.handleRemoteException(e); + } catch (RemoteException e) { + throw RemoteExceptionHandler.decodeRemoteException(e); } } @@ -279,8 +272,8 @@ try { this.master.deleteTable(tableName); - } catch(Exception e) { - RemoteExceptionHandler.handleRemoteException(e); + } catch(RemoteException e) { + throw RemoteExceptionHandler.decodeRemoteException(e); } // Wait until first region is deleted @@ -311,9 +304,12 @@ break; } - } catch (Exception ex) { + } catch (IOException ex) { if(tries == numRetries - 1) { // no more tries left - RemoteExceptionHandler.handleRemoteException(ex); + if(ex instanceof RemoteException) { + ex = RemoteExceptionHandler.decodeRemoteException((RemoteException) ex); + } + throw ex; } } finally { @@ -349,8 +345,8 @@ try { this.master.addColumn(tableName, column); - } catch (Exception e) { - RemoteExceptionHandler.handleRemoteException(e); + } catch (RemoteException e) { + throw RemoteExceptionHandler.decodeRemoteException(e); } } @@ -368,8 +364,8 @@ try { this.master.deleteColumn(tableName, columnName); - } catch(Exception e) { - RemoteExceptionHandler.handleRemoteException(e); + } catch(RemoteException e) { + throw RemoteExceptionHandler.decodeRemoteException(e); } } @@ -387,8 +383,8 @@ try { this.master.enableTable(tableName); - } catch(Exception e) { - RemoteExceptionHandler.handleRemoteException(e); + } catch(RemoteException e) { + throw RemoteExceptionHandler.decodeRemoteException(e); } // Wait until first region is enabled @@ -429,9 +425,12 @@ break; } - } catch (Exception e) { + } catch (IOException e) { if(tries == numRetries - 1) { // no more retries - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } } finally { @@ -475,8 +474,8 @@ try { this.master.disableTable(tableName); - } catch(Exception e) { - RemoteExceptionHandler.handleRemoteException(e); + } catch(RemoteException e) { + throw RemoteExceptionHandler.decodeRemoteException(e); } // Wait until first region is disabled @@ -517,9 +516,12 @@ break; } - } catch(Exception e) { + } catch(IOException e) { if(tries == numRetries - 1) { // no more retries - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } } finally { @@ -555,8 +557,8 @@ checkMaster(); try { this.master.shutdown(); - } catch(Exception e) { - RemoteExceptionHandler.handleRemoteException(e); + } catch(RemoteException e) { + throw RemoteExceptionHandler.decodeRemoteException(e); } } @@ -737,10 +739,13 @@ try { rootRegion.getRegionInfo(HGlobals.rootRegionInfo.regionName); break; - } catch(Exception e) { + } catch(IOException e) { if(tries == numRetries - 1) { // Don't bother sleeping. We've run out of retries. - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } // Sleep and retry finding root region. @@ -864,9 +869,12 @@ servers.put(regionInfo.startKey, new RegionLocation(regionInfo, new HServerAddress(serverAddress))); } - } catch (Exception e) { + } catch (IOException e) { if(tries == numRetries - 1) { // no retries left - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } } finally { @@ -939,8 +947,8 @@ server = (HRegionInterface) RPC.waitForProxy(serverInterfaceClass, versionId, regionServer.getInetSocketAddress(), this.conf); - } catch (Exception e) { - RemoteExceptionHandler.handleRemoteException(e); + } catch (RemoteException e) { + throw RemoteExceptionHandler.decodeRemoteException(e); } this.servers.put(regionServer.toString(), server); @@ -996,8 +1004,8 @@ } } } - } catch (Exception ex) { - RemoteExceptionHandler.handleRemoteException(ex); + } catch (RemoteException ex) { + throw RemoteExceptionHandler.decodeRemoteException(ex); } finally { if(scannerId != -1L) { @@ -1065,9 +1073,12 @@ value = server.get(info.regionInfo.regionName, row, column); break; - } catch (Exception e) { + } catch (IOException e) { if (tries == numRetries - 1) { - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } findRegion(info); } @@ -1100,10 +1111,13 @@ values = server.get(info.regionInfo.regionName, row, column, numVersions); break; - } catch(Exception e) { + } catch(IOException e) { if(tries == numRetries - 1) { // No more tries - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } findRegion(info); } @@ -1146,10 +1160,13 @@ values = server.get(info.regionInfo.regionName, row, column, timestamp, numVersions); break; - } catch(Exception e) { + } catch(IOException e) { if(tries == numRetries - 1) { // No more tries - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } findRegion(info); } @@ -1188,10 +1205,13 @@ value = server.getRow(info.regionInfo.regionName, row); break; - } catch(NotServingRegionException e) { + } catch(IOException e) { if(tries == numRetries - 1) { // No more tries - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } findRegion(info); } @@ -1275,37 +1295,6 @@ return new ClientScanner(columns, startRow, timestamp, filter); } - /* - * @return General HClient RetryPolicy instance. - */ - RetryPolicy getRetryPolicy() { - Map, RetryPolicy> exceptionToPolicyMap = - new HashMap, RetryPolicy>(); - // Pass numRetries - 1 because it does less-than-equal internally rather - // than the less-than we do elsewhere where we use numRetries. - RetryPolicy rp = - RetryPolicies.retryUpToMaximumCountWithProportionalSleep(numRetries, - this.pause, TimeUnit.MILLISECONDS); - exceptionToPolicyMap.put(NotServingRegionException.class, rp); - exceptionToPolicyMap.put(WrongRegionException.class, rp); - exceptionToPolicyMap.put(RegionNotFoundException.class, rp); - return RetryPolicies.retryByRemoteException(RetryPolicies.TRY_ONCE_THEN_FAIL, - exceptionToPolicyMap); - - } - - /* - * Interface for {@link #startUpate()} used by the - * {@link org.apache.hadoop.io.retry} mechanism. - */ - private interface StartUpdateInterface { - /** - * @return row lockid for the update - * @throws IOException - */ - long startUpdate() throws IOException; - } - /** * Start an atomic row insertion/update. No changes are committed until the * call to commit() returns. A call to abort() will abandon any updates in progress. @@ -1322,44 +1311,40 @@ * @throws IOException */ public long startUpdate(final Text row) throws IOException { - // Implemention of the StartUpdate interface. - StartUpdateInterface implementation = new StartUpdateInterface() { - private RegionLocation info = null; - private int attempts = 0; - - /* - * Wrapped method. Proxy wrapper is configured to judge whether - * exception merits retry. - * @return lockid - * @throws IOException - */ - public long startUpdate() throws IOException { - this.attempts++; - if (this.info != null) { - LOG.info("Retry of startUpdate. Attempt " + this.attempts + - " for row " + row); - // If a retry. Something wrong w/ region we have. Refind. - try { - findRegion(info); - } catch (RegionNotFoundException e) { - // continue. If no longer exists, perhaps we just came through - // a split and region is now gone. Below getRegionLocation should - // recalibrate client. - } - } - this.info = getRegionLocation(row); + long lockid = -1; + for(int tries = 0; tries < numRetries; tries++) { + IOException e = null; + RegionLocation info = getRegionLocation(row); + try { currentServer = getHRegionConnection(info.serverAddress); currentRegion = info.regionInfo.regionName; clientid = rand.nextLong(); - return currentServer.startUpdate(currentRegion, clientid, row); + lockid = currentServer.startUpdate(currentRegion, clientid, row); + break; + + } catch (IOException ex) { + e = ex; } - }; - - // Get retry proxy wrapper around 'implementation'. - StartUpdateInterface retryProxy = (StartUpdateInterface)RetryProxy. - create(StartUpdateInterface.class, implementation, getRetryPolicy()); - // Run retry. - return retryProxy.startUpdate(); + if(tries < numRetries - 1) { + try { + Thread.sleep(this.pause); + + } catch (InterruptedException ex) { + } + try { + findRegion(info); + + } catch (IOException ex) { + e = ex; + } + } else { + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; + } + } + return lockid; } /** @@ -1374,7 +1359,7 @@ try { this.currentServer.put(this.currentRegion, this.clientid, lockid, column, val); - } catch(Exception e) { + } catch(IOException e) { try { this.currentServer.abort(this.currentRegion, this.clientid, lockid); } catch(IOException e2) { @@ -1382,7 +1367,10 @@ } this.currentServer = null; this.currentRegion = null; - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } } @@ -1397,7 +1385,7 @@ try { this.currentServer.delete(this.currentRegion, this.clientid, lockid, column); - } catch(Exception e) { + } catch(IOException e) { try { this.currentServer.abort(this.currentRegion, this.clientid, lockid); } catch(IOException e2) { @@ -1405,7 +1393,10 @@ } this.currentServer = null; this.currentRegion = null; - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } } @@ -1418,10 +1409,13 @@ public void abort(long lockid) throws IOException { try { this.currentServer.abort(this.currentRegion, this.clientid, lockid); - } catch(Exception e) { + } catch(IOException e) { this.currentServer = null; this.currentRegion = null; - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } } @@ -1447,10 +1441,13 @@ this.currentServer.commit(this.currentRegion, this.clientid, lockid, timestamp); - } catch (Exception e) { + } catch (IOException e) { this.currentServer = null; this.currentRegion = null; - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } } @@ -1463,7 +1460,7 @@ public void renewLease(long lockid) throws IOException { try { this.currentServer.renewLease(lockid, this.clientid); - } catch(Exception e) { + } catch(IOException e) { try { this.currentServer.abort(this.currentRegion, this.clientid, lockid); } catch(IOException e2) { @@ -1471,7 +1468,10 @@ } this.currentServer = null; this.currentRegion = null; - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } } @@ -1559,10 +1559,13 @@ break; - } catch(Exception e) { + } catch(IOException e) { if(tries == numRetries - 1) { // No more tries - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } findRegion(info); loadRegions(); @@ -1569,9 +1572,12 @@ } } - } catch(Exception e) { + } catch(IOException e) { close(); - RemoteExceptionHandler.handleRemoteException(e); + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } return true; } Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/HMaster.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/HMaster.java (revision 555417) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/HMaster.java (working copy) @@ -40,6 +40,7 @@ import org.apache.hadoop.hbase.io.KeyedData; import org.apache.hadoop.io.DataInputBuffer; import org.apache.hadoop.io.Text; +import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.ipc.RPC; import org.apache.hadoop.ipc.Server; import org.apache.hadoop.util.StringUtils; @@ -211,6 +212,9 @@ } } } catch (IOException e) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } LOG.error(e); } } @@ -309,7 +313,15 @@ } tries = 0; - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + try { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + + } catch (IOException ex) { + LOG.warn(ex); + } + } tries++; if(tries < numRetries) { LOG.warn("ROOT scanner", e); @@ -461,6 +473,9 @@ tries = 0; } catch (IOException e) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } tries++; if(tries < numRetries) { LOG.warn("META scanner", e); @@ -471,7 +486,15 @@ } } while(true); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + try { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + + } catch (IOException ex) { + LOG.warn(ex); + } + } LOG.error("META scanner", e); closed = true; } @@ -597,7 +620,10 @@ root.getLog().closeAndDelete(); meta.close(); meta.getLog().closeAndDelete(); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } LOG.error(e); } } @@ -691,7 +717,15 @@ // Start the server last so everything else is running before we start // receiving requests this.server.start(); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + try { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + + } catch (IOException ex) { + LOG.warn(ex); + } + } // Something happened during startup. Shut things down. this.closed = true; LOG.error(e); @@ -717,7 +751,16 @@ LOG.debug("Processing " + op.toString()); } op.process(); - } catch(Exception ex) { + + } catch (Exception ex) { + if (ex instanceof RemoteException) { + try { + ex = RemoteExceptionHandler.decodeRemoteException((RemoteException) ex); + + } catch (IOException e) { + LOG.warn(e); + } + } LOG.warn(ex); synchronized(msgQueue) { msgQueue.addLast(op); @@ -746,7 +789,7 @@ try { // Wait for the root scanner to finish. rootScannerThread.join(); - } catch(Exception iex) { + } catch (Exception iex) { // Print if ever there is an interrupt (Just for kicks. Remove if it // ever happens). LOG.warn(iex); @@ -1205,13 +1248,12 @@ try { values = server.next(scannerId); - } catch(Exception e) { - try { - RemoteExceptionHandler.handleRemoteException(e); + } catch (IOException e) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); - } catch(Exception ex) { - LOG.error(ex); } + LOG.error(e); break; } @@ -1283,7 +1325,10 @@ try { info.readFields(inbuf); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } LOG.error(e); break; } @@ -1331,9 +1376,11 @@ try { server.close(scannerId); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } LOG.error(e); - } } } @@ -1407,9 +1454,12 @@ scanMetaRegion(server, scannerId, HGlobals.rootRegionInfo.regionName); break; - } catch(Exception e) { - if(tries == numRetries - 1) { - RemoteExceptionHandler.handleRemoteException(e); + } catch (IOException e) { + if (tries == numRetries - 1) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } } } @@ -1439,9 +1489,12 @@ } break; - } catch(Exception e) { - if(tries == numRetries - 1) { - RemoteExceptionHandler.handleRemoteException(e); + } catch (IOException e) { + if (tries == numRetries - 1) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } } } @@ -1538,9 +1591,12 @@ break; - } catch(Exception e) { - if(tries == numRetries - 1) { - RemoteExceptionHandler.handleRemoteException(e); + } catch (IOException e) { + if (tries == numRetries - 1) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } continue; } @@ -1558,7 +1614,10 @@ try { HRegion.deleteRegion(fs, dir, regionInfo.regionName); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } LOG.error("failed to delete region " + regionInfo.regionName); LOG.error(e); throw e; @@ -1649,9 +1708,12 @@ break; - } catch(Exception e) { + } catch (IOException e) { if(tries == numRetries - 1) { - RemoteExceptionHandler.handleRemoteException(e); + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } } pendingRegions.remove(regionName); @@ -1754,9 +1816,12 @@ assignAttempts.put(regionName, Long.valueOf(0L)); break; - } catch(Exception e) { + } catch (IOException e) { if(tries == numRetries - 1) { - RemoteExceptionHandler.handleRemoteException(e); + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } } } @@ -1926,7 +1991,10 @@ try { server.close(scannerId); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } LOG.error(e); } } @@ -1943,9 +2011,12 @@ } // for(MetaRegion m:) } // synchronized(metaScannerLock) - } catch(Exception e) { + } catch (IOException e) { if(tries == numRetries - 1) { - RemoteExceptionHandler.handleRemoteException(e); + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } continue; } @@ -2030,10 +2101,12 @@ LOG.debug("updated columns in row: " + i.regionName); } - } catch(Exception e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } LOG.error("column update failed in row: " + i.regionName); LOG.error(e); - RemoteExceptionHandler.handleRemoteException(e); } finally { try { @@ -2041,7 +2114,10 @@ server.abort(m.regionName, clientId, lockid); } - } catch(IOException iex) { + } catch (IOException iex) { + if (iex instanceof RemoteException) { + iex = RemoteExceptionHandler.decodeRemoteException((RemoteException) iex); + } LOG.error(iex); } } @@ -2132,7 +2208,10 @@ // Delete the region try { HRegion.deleteRegion(fs, dir, i.regionName); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } LOG.error("failed to delete region " + i.regionName); LOG.error(e); } @@ -2182,10 +2261,12 @@ if(LOG.isDebugEnabled()) { LOG.debug("updated columns in row: " + i.regionName); } - } catch(Exception e) { + } catch (Exception e) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } LOG.error("column update failed in row: " + i.regionName); LOG.error(e); - RemoteExceptionHandler.handleRemoteException(e); } finally { if(lockid != -1L) { @@ -2192,7 +2273,10 @@ try { server.abort(regionName, clientId, lockid); - } catch(IOException iex) { + } catch (IOException iex) { + if (iex instanceof RemoteException) { + iex = RemoteExceptionHandler.decodeRemoteException((RemoteException) iex); + } LOG.error(iex); } } @@ -2222,7 +2306,10 @@ try { fs.delete(HStoreFile.getMapDir(dir, i.regionName, columnName)); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } LOG.error(e); } @@ -2229,7 +2316,10 @@ try { fs.delete(HStoreFile.getInfoDir(dir, i.regionName, columnName)); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } LOG.error(e); } Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/HRegionServer.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/HRegionServer.java (revision 555417) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/HRegionServer.java (working copy) @@ -36,7 +36,7 @@ import org.apache.hadoop.hbase.filter.RowFilterInterface; import org.apache.hadoop.hbase.io.KeyedData; import org.apache.hadoop.io.Text; -import org.apache.hadoop.io.retry.RetryProxy; +import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.ipc.RPC; import org.apache.hadoop.ipc.Server; import org.apache.hadoop.net.DNS; @@ -92,17 +92,6 @@ private final Thread splitOrCompactCheckerThread; protected final Integer splitOrCompactLock = new Integer(0); - /** - * Interface used by the {@link org.apache.hadoop.io.retry} mechanism. - */ - public interface UpdateMetaInterface { - /** - * @return True if succeeded. - * @throws IOException - */ - public boolean update() throws IOException; - } - /** Runs periodically to determine if regions need to be compacted or split */ class SplitOrCompactChecker implements Runnable, RegionUnavailableListener { HClient client = new HClient(conf); @@ -203,6 +192,7 @@ // When a region is split, the META table needs to updated if we're // splitting a 'normal' region, and the ROOT table needs to be // updated if we are splitting a META region. + final Text tableToUpdate = region.getRegionInfo().tableDesc.getName().equals(META_TABLE_NAME) ? ROOT_TABLE_NAME : META_TABLE_NAME; @@ -209,49 +199,64 @@ if(LOG.isDebugEnabled()) { LOG.debug("Updating " + tableToUpdate + " with region split info"); } + + // Remove old region from META - // Wrap the update of META region with an org.apache.hadoop.io.retry. - UpdateMetaInterface implementation = new UpdateMetaInterface() { - /* (non-Javadoc) - * @see org.apache.hadoop.hbase.HRegionServer.UpdateMetaInterface#update() - */ - public boolean update() throws IOException { + for (int tries = 0; tries < numRetries; tries++) { + try { HRegion.removeRegionFromMETA(client, tableToUpdate, - region.getRegionName()); - for (int i = 0; i < newRegions.length; i++) { - HRegion.addRegionToMETA(client, tableToUpdate, newRegions[i], - serverInfo.getServerAddress(), serverInfo.getStartCode()); - } + region.getRegionName()); - // Now tell the master about the new regions - if (LOG.isDebugEnabled()) { - LOG.debug("Reporting region split to master"); + } catch (IOException e) { + if(tries == numRetries - 1) { + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; } - reportSplit(newRegions[0].getRegionInfo(), newRegions[1]. - getRegionInfo()); - LOG.info("region split, META update, and report to master all" + - " successful. Old region=" + oldRegion + ", new regions: " + - newRegions[0].getRegionName() + ", " + - newRegions[1].getRegionName()); + } + } + + // Add new regions to META + + for (int i = 0; i < newRegions.length; i++) { + for (int tries = 0; tries < numRetries; tries ++) { + try { + HRegion.addRegionToMETA(client, tableToUpdate, newRegions[i], + serverInfo.getServerAddress(), serverInfo.getStartCode()); - // Finally, start serving the new regions - lock.writeLock().lock(); - try { - onlineRegions.put(newRegions[0].getRegionName(), newRegions[0]); - onlineRegions.put(newRegions[1].getRegionName(), newRegions[1]); - } finally { - lock.writeLock().unlock(); + } catch(IOException e) { + if(tries == numRetries - 1) { + if(e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } + throw e; + } } - return true; } - }; + } + + // Now tell the master about the new regions - // Get retry proxy wrapper around 'implementation'. - UpdateMetaInterface retryProxy = (UpdateMetaInterface)RetryProxy. - create(UpdateMetaInterface.class, implementation, - client.getRetryPolicy()); - // Run retry. - retryProxy.update(); + if (LOG.isDebugEnabled()) { + LOG.debug("Reporting region split to master"); + } + reportSplit(newRegions[0].getRegionInfo(), newRegions[1]. + getRegionInfo()); + LOG.info("region split, META update, and report to master all" + + " successful. Old region=" + oldRegion + ", new regions: " + + newRegions[0].getRegionName() + ", " + + newRegions[1].getRegionName()); + + // Finally, start serving the new regions + + lock.writeLock().lock(); + try { + onlineRegions.put(newRegions[0].getRegionName(), newRegions[0]); + onlineRegions.put(newRegions[1].getRegionName(), newRegions[1]); + } finally { + lock.writeLock().unlock(); + } } } @@ -289,7 +294,15 @@ try { cur.optionallyFlush(); - } catch(IOException iex) { + } catch (IOException iex) { + if (iex instanceof RemoteException) { + try { + iex = RemoteExceptionHandler.decodeRemoteException((RemoteException) iex); + + } catch (IOException x) { + iex = x; + } + } LOG.error(iex); } } @@ -342,8 +355,16 @@ LOG.debug("Rolling log. Number of entries is: " + nEntries); } log.rollWriter(); - } catch(IOException iex) { - // continue + } catch (IOException iex) { + if (iex instanceof RemoteException) { + try { + iex = RemoteExceptionHandler.decodeRemoteException((RemoteException) iex); + + } catch (IOException x) { + iex = x; + } + } + LOG.warn(iex); } } } @@ -466,8 +487,11 @@ HMasterRegionInterface.class, HMasterRegionInterface.versionID, new HServerAddress(conf.get(MASTER_ADDRESS)).getInetSocketAddress(), conf); - } catch(IOException e) { + } catch (IOException e) { this.stopRequested = true; + if (e instanceof RemoteException) { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + } throw e; } } @@ -554,8 +578,16 @@ this.server.start(); LOG.info("HRegionServer started at: " + serverInfo.getServerAddress().toString()); } catch(IOException e) { + stopRequested = true; + if (e instanceof RemoteException) { + try { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + + } catch (IOException ex) { + e = ex; + } + } LOG.error(e); - stopRequested = true; } while(! stopRequested) { @@ -640,7 +672,15 @@ } } - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + try { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + + } catch (IOException ex) { + e = ex; + } + } LOG.error(e); } } @@ -679,7 +719,15 @@ if (abortRequested) { try { log.rollWriter(); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + try { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + + } catch (IOException ex) { + e = ex; + } + } LOG.warn(e); } LOG.info("aborting server at: " + @@ -688,7 +736,15 @@ Vector closedRegions = closeAllRegions(); try { log.closeAndDelete(); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + try { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + + } catch (IOException ex) { + e = ex; + } + } LOG.error(e); } try { @@ -704,7 +760,15 @@ LOG.info("telling master that region server is shutting down at: " + serverInfo.getServerAddress().toString()); hbaseMaster.regionServerReport(serverInfo, exitMsg); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + try { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + + } catch (IOException ex) { + e = ex; + } + } LOG.warn(e); } LOG.info("stopping server at: " + @@ -818,7 +882,15 @@ "Impossible state during msg processing. Instruction: " + e.msg.toString()); } - } catch(IOException ie) { + } catch (IOException ie) { + if (ie instanceof RemoteException) { + try { + ie = RemoteExceptionHandler.decodeRemoteException((RemoteException) ie); + + } catch (IOException x) { + ie = x; + } + } if(e.tries < numRetries) { LOG.warn(ie); e.tries++; @@ -884,7 +956,15 @@ try { region.close(); LOG.debug("region closed " + region.getRegionName()); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + try { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + + } catch (IOException x) { + e = x; + } + } LOG.error("error closing region " + region.getRegionName(), e); } } @@ -1021,7 +1101,15 @@ public void leaseExpired() { try { localRegion.abort(localLockId); - } catch(IOException iex) { + } catch (IOException iex) { + if (iex instanceof RemoteException) { + try { + iex = RemoteExceptionHandler.decodeRemoteException((RemoteException) iex); + + } catch (IOException x) { + iex = x; + } + } LOG.error(iex); } } @@ -1172,7 +1260,15 @@ } leases.createLease(scannerId, scannerId, new ScannerListener(scannerName)); - } catch(IOException e) { + } catch (IOException e) { + if (e instanceof RemoteException) { + try { + e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e); + + } catch (IOException x) { + e = x; + } + } LOG.error(e); throw e; } Index: src/contrib/hbase/src/java/org/apache/hadoop/hbase/RemoteExceptionHandler.java =================================================================== --- src/contrib/hbase/src/java/org/apache/hadoop/hbase/RemoteExceptionHandler.java (revision 555417) +++ src/contrib/hbase/src/java/org/apache/hadoop/hbase/RemoteExceptionHandler.java (working copy) @@ -30,62 +30,46 @@ /** * Converts org.apache.hadoop.ipc.RemoteException into original exception, - * if possible. + * if possible. If the original exception is an Error or a RuntimeException, + * throws the original exception. + * + * @param re original exception + * @return decoded RemoteException if it is an instance of or a subclass of + * IOException, or the original RemoteException if it cannot be decoded. * - * @param e original exception - * @throws IOException + * @throws IOException indicating a server error ocurred if the decoded + * exception is not an IOException. The decoded exception is set as + * the cause. */ @SuppressWarnings("unchecked") - public static void handleRemoteException(final Exception e) throws IOException { - Exception ex = e; - if (e instanceof RemoteException) { - RemoteException r = (RemoteException) e; + public static IOException decodeRemoteException(final RemoteException re) + throws IOException { + IOException i = re; - Class c = null; - try { - c = Class.forName(r.getClassName()); - - } catch (ClassNotFoundException x) { - throw r; - } + try { + Class c = Class.forName(re.getClassName()); + + Class[] parameterTypes = { String.class }; + Constructor ctor = c.getConstructor(parameterTypes); - Constructor ctor = null; - try { - Class[] parameterTypes = { String.class }; - ctor = c.getConstructor(parameterTypes); - - } catch (NoSuchMethodException x) { - throw r; - } + Object[] arguments = { re.getMessage() }; + Throwable t = (Throwable) ctor.newInstance(arguments); - try { - Object[] arguments = { r.getMessage() }; + if (t instanceof IOException) { + i = (IOException) t; - ex = (Exception) ctor.newInstance(arguments); - - } catch (IllegalAccessException x) { - throw r; - - } catch (InvocationTargetException x) { - throw r; - - } catch (InstantiationException x) { - throw r; + } else { + i = new IOException("server error"); + i.initCause(t); + throw i; } - } - if (ex instanceof IOException) { - IOException io = (IOException) ex; - throw io; - - } else if (ex instanceof RuntimeException) { - RuntimeException re = (RuntimeException) ex; - throw re; - - } else { - AssertionError a = new AssertionError("unexpected exception"); - a.initCause(ex); - throw a; + } catch (ClassNotFoundException x) { + } catch (NoSuchMethodException x) { + } catch (IllegalAccessException x) { + } catch (InvocationTargetException x) { + } catch (InstantiationException x) { } + return i; } }