Uploaded image for project: 'Hadoop Common'
  1. Hadoop Common
  2. HADOOP-2555

Refactor the HTable#get and HTable#getRow methods to avoid repetition of retry-on-failure logic

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 0.17.0
    • None
    • None

    Description

      The following code is repeated in every one of HTable#get and HTable#getRow methods:

      HTable.java
          MapWritable value = null;
          for (int tries = 0; tries < numRetries; tries++) {
            HRegionLocation r = getRegionLocation(row);
            HRegionInterface server =
              connection.getHRegionConnection(r.getServerAddress());
            
            try {
              value = server.getRow(r.getRegionInfo().getRegionName(), row, ts);  // This is the only line of code that changes significantly between methods
              break;
              
            } catch (IOException e) {
              if (e instanceof RemoteException) {
                e = RemoteExceptionHandler.decodeRemoteException((RemoteException) e);
              }
              if (tries == numRetries - 1) {
                // No more tries
                throw e;
              }
              if (LOG.isDebugEnabled()) {
                LOG.debug("reloading table servers because: " + e.getMessage());
              }
              tableServers = connection.reloadTableServers(tableName);
            }
            try {
              Thread.sleep(this.pause);
              
            } catch (InterruptedException x) {
              // continue
            }
          }
      

      This should be factored out into a protected method that handles retry-on-failure logic to facilitate more robust testing and the development of new API methods.

      Proposed modification:

      // Execute the provided Callable against the server
      protected <T> callServerWithRetries(Callable<T> callable) throws RemoteException;

      The above code could then be reduced to:

      HTable.java
          MapWritable value = null;
          final connection;
          try {
            value = callServerWithRetries(new Callable<MapWritable>() {
                  HRegionLocation r = getRegionLocation(row);
                  HRegionInterface server =
                      connection.getHRegionConnection(r.getServerAddress());
                  server.getRow(r.getRegionInfo().getRegionName(), row, ts);
                });
          } catch (RemoteException e) {
            // handle unrecoverable remote exceptions
          }
      

      This would greatly ease the development of new API methods by reducing the amount of code needed to implement a new method and reducing the amount of logic that needs to be tested per method.

      Attachments

        1. hadoop-2555.patch
          18 kB
          Peter Dolan
        2. 2555-v3.patch
          15 kB
          Bryan Duxbury
        3. 2555-v2.patch
          15 kB
          Bryan Duxbury

        Activity

          People

            bryanduxbury Bryan Duxbury
            pdwryst Peter Dolan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: