Java Code Examples for org.apache.hadoop.hbase.client.ConnectionUtils#getPauseTime()

The following examples show how to use org.apache.hadoop.hbase.client.ConnectionUtils#getPauseTime() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThriftConnection.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
  // Don't sleep for retrying the first time
  if (executionCount > 1 && pause > 0) {
    try {
      long sleepTime = ConnectionUtils.getPauseTime(pause, executionCount - 1);
      Thread.sleep(sleepTime);
    } catch (InterruptedException ie) {
      //reset interrupt marker
      Thread.currentThread().interrupt();
    }
  }
  return super.retryRequest(exception, executionCount, context);
}
 
Example 2
Source File: MemstoreAwareObserver.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void main(String...args) throws Exception {
    long timeWaited = 0l;
    for (int i = 1; i <= 40; i++) {
        timeWaited += ConnectionUtils.getPauseTime(90, i);
    }
    System.out.printf("timeWaited: %d sec%n", timeWaited);
}
 
Example 3
Source File: HRegionServer.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public boolean reportRegionStateTransition(final RegionStateTransitionContext context) {
  if (TEST_SKIP_REPORTING_TRANSITION) {
    return skipReportingTransition(context);
  }
  final ReportRegionStateTransitionRequest request =
      createReportRegionStateTransitionRequest(context);

  // Time to pause if master says 'please hold'. Make configurable if needed.
  final long initPauseTime = 1000;
  int tries = 0;
  long pauseTime;
  // Keep looping till we get an error. We want to send reports even though server is going down.
  // Only go down if clusterConnection is null. It is set to null almost as last thing as the
  // HRegionServer does down.
  while (this.asyncClusterConnection != null && !this.asyncClusterConnection.isClosed()) {
    RegionServerStatusService.BlockingInterface rss = rssStub;
    try {
      if (rss == null) {
        createRegionServerStatusStub();
        continue;
      }
      ReportRegionStateTransitionResponse response =
        rss.reportRegionStateTransition(null, request);
      if (response.hasErrorMessage()) {
        LOG.info("TRANSITION FAILED " + request + ": " + response.getErrorMessage());
        break;
      }
      // Log if we had to retry else don't log unless TRACE. We want to
      // know if were successful after an attempt showed in logs as failed.
      if (tries > 0 || LOG.isTraceEnabled()) {
        LOG.info("TRANSITION REPORTED " + request);
      }
      // NOTE: Return mid-method!!!
      return true;
    } catch (ServiceException se) {
      IOException ioe = ProtobufUtil.getRemoteException(se);
      boolean pause =
          ioe instanceof ServerNotRunningYetException || ioe instanceof PleaseHoldException
              || ioe instanceof CallQueueTooBigException;
      if (pause) {
        // Do backoff else we flood the Master with requests.
        pauseTime = ConnectionUtils.getPauseTime(initPauseTime, tries);
      } else {
        pauseTime = initPauseTime; // Reset.
      }
      LOG.info("Failed report transition " +
        TextFormat.shortDebugString(request) + "; retry (#" + tries + ")" +
          (pause?
              " after " + pauseTime + "ms delay (Master is coming online...).":
              " immediately."),
          ioe);
      if (pause) Threads.sleep(pauseTime);
      tries++;
      if (rssStub == rss) {
        rssStub = null;
      }
    }
  }
  return false;
}