Java 类org.apache.hadoop.hbase.util.RetryCounter 实例源码

项目:ditb    文件:HBaseTestingUtility.java   
/**
 * Tool to get the reference to the region server object that holds the
 * region of the specified user table.
 * It first searches for the meta rows that contain the region of the
 * specified table, then gets the index of that RS, and finally retrieves
 * the RS's reference.
 * @param tableName user table to lookup in hbase:meta
 * @return region server that holds it, null if the row doesn't exist
 * @throws IOException
 * @throws InterruptedException
 */
public HRegionServer getRSForFirstRegionInTable(TableName tableName)
    throws IOException, InterruptedException {
  List<byte[]> metaRows = getMetaTableRows(tableName);
  if (metaRows == null || metaRows.isEmpty()) {
    return null;
  }
  LOG.debug("Found " + metaRows.size() + " rows for table " +
    tableName);
  byte [] firstrow = metaRows.get(0);
  LOG.debug("FirstRow=" + Bytes.toString(firstrow));
  long pause = getConfiguration().getLong(HConstants.HBASE_CLIENT_PAUSE,
    HConstants.DEFAULT_HBASE_CLIENT_PAUSE);
  int numRetries = getConfiguration().getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
    HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
  RetryCounter retrier = new RetryCounter(numRetries+1, (int)pause, TimeUnit.MICROSECONDS);
  while(retrier.shouldRetry()) {
    int index = getMiniHBaseCluster().getServerWith(firstrow);
    if (index != -1) {
      return getMiniHBaseCluster().getRegionServerThreads().get(index).getRegionServer();
    }
    // Came back -1.  Region may not be online yet.  Sleep a while.
    retrier.sleepUntilNextRetry();
  }
  return null;
}
项目:ditb    文件:HBaseClusterManager.java   
private Pair<Integer, String> execWithRetries(String hostname, ServiceType service, String... cmd)
    throws IOException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return exec(hostname, service, cmd);
    } catch (IOException e) {
      retryOrThrow(retryCounter, e, hostname, cmd);
    }
    try {
      retryCounter.sleepUntilNextRetry();
    } catch (InterruptedException ex) {
      // ignore
      LOG.warn("Sleep Interrupted:" + ex);
    }
  }
}
项目:LCIndex-HBase-0.94.16    文件:RecoverableZooKeeper.java   
/**
 * exists is an idempotent operation. Retry before throwing exception
 * @return A Stat instance
 */
public Stat exists(String path, Watcher watcher)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.exists(path, watcher);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "exists");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:LCIndex-HBase-0.94.16    文件:RecoverableZooKeeper.java   
/**
 * exists is an idempotent operation. Retry before throwing exception
 * @return A Stat instance
 */
public Stat exists(String path, boolean watch)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.exists(path, watch);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "exists");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:LCIndex-HBase-0.94.16    文件:RecoverableZooKeeper.java   
/**
 * getChildren is an idempotent operation. Retry before throwing exception
 * @return List of children znodes
 */
public List<String> getChildren(String path, Watcher watcher)
  throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.getChildren(path, watcher);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getChildren");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:LCIndex-HBase-0.94.16    文件:RecoverableZooKeeper.java   
/**
 * getChildren is an idempotent operation. Retry before throwing exception
 * @return List of children znodes
 */
public List<String> getChildren(String path, boolean watch)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.getChildren(path, watch);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getChildren");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:LCIndex-HBase-0.94.16    文件:RecoverableZooKeeper.java   
/**
 * getData is an idempotent operation. Retry before throwing exception
 * @return Data
 */
public byte[] getData(String path, Watcher watcher, Stat stat)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      byte[] revData = zk.getData(path, watcher, stat);       
      return this.removeMetaData(revData);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getData");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:LCIndex-HBase-0.94.16    文件:RecoverableZooKeeper.java   
/**
 * getData is an idemnpotent operation. Retry before throwing exception
 * @return Data
 */
public byte[] getData(String path, boolean watch, Stat stat)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      byte[] revData = zk.getData(path, watch, stat);
      return this.removeMetaData(revData);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getData");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:LCIndex-HBase-0.94.16    文件:RecoverableZooKeeper.java   
/**
 * Run multiple operations in a transactional manner. Retry before throwing exception
 */
public List<OpResult> multi(Iterable<Op> ops)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  Iterable<Op> multiOps = prepareZKMulti(ops);
  while (true) {
    try {
      return zk.multi(multiOps);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "multi");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:pbase    文件:ServerManager.java   
/**
 * Check if a region server is reachable and has the expected start code
 */
public boolean isServerReachable(ServerName server) {
  if (server == null) throw new NullPointerException("Passed server is null");

  RetryCounter retryCounter = pingRetryCounterFactory.create();
  while (retryCounter.shouldRetry()) {
    try {
      AdminService.BlockingInterface admin = getRsAdmin(server);
      if (admin != null) {
        ServerInfo info = ProtobufUtil.getServerInfo(admin);
        return info != null && info.hasServerName()
          && server.getStartcode() == info.getServerName().getStartCode();
      }
    } catch (IOException ioe) {
      LOG.debug("Couldn't reach " + server + ", try=" + retryCounter.getAttemptTimes()
        + " of " + retryCounter.getMaxAttempts(), ioe);
      try {
        retryCounter.sleepUntilNextRetry();
      } catch(InterruptedException ie) {
        Thread.currentThread().interrupt();
      }
    }
  }
  return false;
}
项目:pbase    文件:HBaseTestingUtility.java   
/**
 * Tool to get the reference to the region server object that holds the
 * region of the specified user table.
 * It first searches for the meta rows that contain the region of the
 * specified table, then gets the index of that RS, and finally retrieves
 * the RS's reference.
 * @param tableName user table to lookup in hbase:meta
 * @return region server that holds it, null if the row doesn't exist
 * @throws IOException
 * @throws InterruptedException
 */
public HRegionServer getRSForFirstRegionInTable(TableName tableName)
    throws IOException, InterruptedException {
  List<byte[]> metaRows = getMetaTableRows(tableName);
  if (metaRows == null || metaRows.isEmpty()) {
    return null;
  }
  LOG.debug("Found " + metaRows.size() + " rows for table " +
    tableName);
  byte [] firstrow = metaRows.get(0);
  LOG.debug("FirstRow=" + Bytes.toString(firstrow));
  long pause = getConfiguration().getLong(HConstants.HBASE_CLIENT_PAUSE,
    HConstants.DEFAULT_HBASE_CLIENT_PAUSE);
  int numRetries = getConfiguration().getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
    HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
  RetryCounter retrier = new RetryCounter(numRetries+1, (int)pause, TimeUnit.MICROSECONDS);
  while(retrier.shouldRetry()) {
    int index = getMiniHBaseCluster().getServerWith(firstrow);
    if (index != -1) {
      return getMiniHBaseCluster().getRegionServerThreads().get(index).getRegionServer();
    }
    // Came back -1.  Region may not be online yet.  Sleep a while.
    retrier.sleepUntilNextRetry();
  }
  return null;
}
项目:HIndex    文件:HBaseTestingUtility.java   
/**
 * Tool to get the reference to the region server object that holds the
 * region of the specified user table.
 * It first searches for the meta rows that contain the region of the
 * specified table, then gets the index of that RS, and finally retrieves
 * the RS's reference.
 * @param tableName user table to lookup in hbase:meta
 * @return region server that holds it, null if the row doesn't exist
 * @throws IOException
 */
public HRegionServer getRSForFirstRegionInTable(TableName tableName)
    throws IOException, InterruptedException {
  List<byte[]> metaRows = getMetaTableRows(tableName);
  if (metaRows == null || metaRows.isEmpty()) {
    return null;
  }
  LOG.debug("Found " + metaRows.size() + " rows for table " +
    tableName);
  byte [] firstrow = metaRows.get(0);
  LOG.debug("FirstRow=" + Bytes.toString(firstrow));
  long pause = getConfiguration().getLong(HConstants.HBASE_CLIENT_PAUSE,
    HConstants.DEFAULT_HBASE_CLIENT_PAUSE);
  int numRetries = getConfiguration().getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
    HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
  RetryCounter retrier = new RetryCounter(numRetries+1, (int)pause, TimeUnit.MICROSECONDS);
  while(retrier.shouldRetry()) {
    int index = getMiniHBaseCluster().getServerWith(firstrow);
    if (index != -1) {
      return getMiniHBaseCluster().getRegionServerThreads().get(index).getRegionServer();
    }
    // Came back -1.  Region may not be online yet.  Sleep a while.
    retrier.sleepUntilNextRetry();
  }
  return null;
}
项目:HIndex    文件:HBaseClusterManager.java   
private Pair<Integer, String> execWithRetries(String hostname, String... cmd)
    throws IOException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return exec(hostname, cmd);
    } catch (IOException e) {
      retryOrThrow(retryCounter, e, hostname, cmd);
    }
    try {
      retryCounter.sleepUntilNextRetry();
    } catch (InterruptedException ex) {
      // ignore
      LOG.warn("Sleep Interrupted:" + ex);
    }
  }
}
项目:IRIndex    文件:RecoverableZooKeeper.java   
/**
 * exists is an idempotent operation. Retry before throwing exception
 * @return A Stat instance
 */
public Stat exists(String path, Watcher watcher)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.exists(path, watcher);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "exists");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:IRIndex    文件:RecoverableZooKeeper.java   
/**
 * exists is an idempotent operation. Retry before throwing exception
 * @return A Stat instance
 */
public Stat exists(String path, boolean watch)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.exists(path, watch);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "exists");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:IRIndex    文件:RecoverableZooKeeper.java   
/**
 * getChildren is an idempotent operation. Retry before throwing exception
 * @return List of children znodes
 */
public List<String> getChildren(String path, Watcher watcher)
  throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.getChildren(path, watcher);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getChildren");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:IRIndex    文件:RecoverableZooKeeper.java   
/**
 * getChildren is an idempotent operation. Retry before throwing exception
 * @return List of children znodes
 */
public List<String> getChildren(String path, boolean watch)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.getChildren(path, watch);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getChildren");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:IRIndex    文件:RecoverableZooKeeper.java   
/**
 * getData is an idempotent operation. Retry before throwing exception
 * @return Data
 */
public byte[] getData(String path, Watcher watcher, Stat stat)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      byte[] revData = zk.getData(path, watcher, stat);       
      return this.removeMetaData(revData);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getData");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:IRIndex    文件:RecoverableZooKeeper.java   
/**
 * getData is an idemnpotent operation. Retry before throwing exception
 * @return Data
 */
public byte[] getData(String path, boolean watch, Stat stat)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      byte[] revData = zk.getData(path, watch, stat);
      return this.removeMetaData(revData);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getData");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:IRIndex    文件:RecoverableZooKeeper.java   
/**
 * Run multiple operations in a transactional manner. Retry before throwing exception
 */
public List<OpResult> multi(Iterable<Op> ops)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  Iterable<Op> multiOps = prepareZKMulti(ops);
  while (true) {
    try {
      return zk.multi(multiOps);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "multi");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:hbase    文件:HBaseTestingUtility.java   
/**
 * Tool to get the reference to the region server object that holds the
 * region of the specified user table.
 * It first searches for the meta rows that contain the region of the
 * specified table, then gets the index of that RS, and finally retrieves
 * the RS's reference.
 * @param tableName user table to lookup in hbase:meta
 * @return region server that holds it, null if the row doesn't exist
 * @throws IOException
 * @throws InterruptedException
 */
public HRegionServer getRSForFirstRegionInTable(TableName tableName)
    throws IOException, InterruptedException {
  List<byte[]> metaRows = getMetaTableRows(tableName);
  if (metaRows == null || metaRows.isEmpty()) {
    return null;
  }
  LOG.debug("Found " + metaRows.size() + " rows for table " +
    tableName);
  byte [] firstrow = metaRows.get(0);
  LOG.debug("FirstRow=" + Bytes.toString(firstrow));
  long pause = getConfiguration().getLong(HConstants.HBASE_CLIENT_PAUSE,
    HConstants.DEFAULT_HBASE_CLIENT_PAUSE);
  int numRetries = getConfiguration().getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
    HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
  RetryCounter retrier = new RetryCounter(numRetries+1, (int)pause, TimeUnit.MICROSECONDS);
  while(retrier.shouldRetry()) {
    int index = getMiniHBaseCluster().getServerWith(firstrow);
    if (index != -1) {
      return getMiniHBaseCluster().getRegionServerThreads().get(index).getRegionServer();
    }
    // Came back -1.  Region may not be online yet.  Sleep a while.
    retrier.sleepUntilNextRetry();
  }
  return null;
}
项目:hbase    文件:HBaseClusterManager.java   
private Pair<Integer, String> execWithRetries(String hostname, ServiceType service, String... cmd)
    throws IOException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return exec(hostname, service, cmd);
    } catch (IOException e) {
      retryOrThrow(retryCounter, e, hostname, cmd);
    }
    try {
      retryCounter.sleepUntilNextRetry();
    } catch (InterruptedException ex) {
      // ignore
      LOG.warn("Sleep Interrupted:" + ex);
    }
  }
}
项目:hbase    文件:RecoverableZooKeeper.java   
/**
 * exists is an idempotent operation. Retry before throwing exception
 * @return A Stat instance
 */
public Stat exists(String path, Watcher watcher) throws KeeperException, InterruptedException {
  try (TraceScope scope = TraceUtil.createTrace("RecoverableZookeeper.exists")) {
    RetryCounter retryCounter = retryCounterFactory.create();
    while (true) {
      try {
        long startTime = EnvironmentEdgeManager.currentTime();
        Stat nodeStat = checkZk().exists(path, watcher);
        return nodeStat;
      } catch (KeeperException e) {
        switch (e.code()) {
          case CONNECTIONLOSS:
            retryOrThrow(retryCounter, e, "exists");
            break;
          case OPERATIONTIMEOUT:
            retryOrThrow(retryCounter, e, "exists");
            break;

          default:
            throw e;
        }
      }
      retryCounter.sleepUntilNextRetry();
    }
  }
}
项目:hbase    文件:RecoverableZooKeeper.java   
/**
 * exists is an idempotent operation. Retry before throwing exception
 * @return A Stat instance
 */
public Stat exists(String path, boolean watch) throws KeeperException, InterruptedException {
  try (TraceScope scope = TraceUtil.createTrace("RecoverableZookeeper.exists")) {
    RetryCounter retryCounter = retryCounterFactory.create();
    while (true) {
      try {
        long startTime = EnvironmentEdgeManager.currentTime();
        Stat nodeStat = checkZk().exists(path, watch);
        return nodeStat;
      } catch (KeeperException e) {
        switch (e.code()) {
          case CONNECTIONLOSS:
            retryOrThrow(retryCounter, e, "exists");
            break;
          case OPERATIONTIMEOUT:
            retryOrThrow(retryCounter, e, "exists");
            break;

          default:
            throw e;
        }
      }
      retryCounter.sleepUntilNextRetry();
    }
  }
}
项目:PyroDB    文件:HBaseTestingUtility.java   
/**
 * Tool to get the reference to the region server object that holds the
 * region of the specified user table.
 * It first searches for the meta rows that contain the region of the
 * specified table, then gets the index of that RS, and finally retrieves
 * the RS's reference.
 * @param tableName user table to lookup in hbase:meta
 * @return region server that holds it, null if the row doesn't exist
 * @throws IOException
 */
public HRegionServer getRSForFirstRegionInTable(TableName tableName)
    throws IOException, InterruptedException {
  List<byte[]> metaRows = getMetaTableRows(tableName);
  if (metaRows == null || metaRows.isEmpty()) {
    return null;
  }
  LOG.debug("Found " + metaRows.size() + " rows for table " +
    tableName);
  byte [] firstrow = metaRows.get(0);
  LOG.debug("FirstRow=" + Bytes.toString(firstrow));
  long pause = getConfiguration().getLong(HConstants.HBASE_CLIENT_PAUSE,
    HConstants.DEFAULT_HBASE_CLIENT_PAUSE);
  int numRetries = getConfiguration().getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
    HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
  RetryCounter retrier = new RetryCounter(numRetries+1, (int)pause, TimeUnit.MICROSECONDS);
  while(retrier.shouldRetry()) {
    int index = getMiniHBaseCluster().getServerWith(firstrow);
    if (index != -1) {
      return getMiniHBaseCluster().getRegionServerThreads().get(index).getRegionServer();
    }
    // Came back -1.  Region may not be online yet.  Sleep a while.
    retrier.sleepUntilNextRetry();
  }
  return null;
}
项目:PyroDB    文件:HBaseClusterManager.java   
private Pair<Integer, String> execWithRetries(String hostname, String... cmd)
    throws IOException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return exec(hostname, cmd);
    } catch (IOException e) {
      retryOrThrow(retryCounter, e, hostname, cmd);
    }
    try {
      retryCounter.sleepUntilNextRetry();
    } catch (InterruptedException ex) {
      // ignore
      LOG.warn("Sleep Interrupted:" + ex);
    }
  }
}
项目:c5    文件:HBaseTestingUtility.java   
/**
 * Tool to get the reference to the region server object that holds the
 * region of the specified user table.
 * It first searches for the meta rows that contain the region of the
 * specified table, then gets the index of that RS, and finally retrieves
 * the RS's reference.
 * @param tableName user table to lookup in hbase:meta
 * @return region server that holds it, null if the row doesn't exist
 * @throws IOException
 */
public HRegionServer getRSForFirstRegionInTable(TableName tableName)
    throws IOException, InterruptedException {
  List<byte[]> metaRows = getMetaTableRows(tableName);
  if (metaRows == null || metaRows.isEmpty()) {
    return null;
  }
  LOG.debug("Found " + metaRows.size() + " rows for table " +
    tableName);
  byte [] firstrow = metaRows.get(0);
  LOG.debug("FirstRow=" + Bytes.toString(firstrow));
  long pause = getConfiguration().getLong(HConstants.HBASE_CLIENT_PAUSE,
    HConstants.DEFAULT_HBASE_CLIENT_PAUSE);
  int numRetries = getConfiguration().getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER,
    HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
  RetryCounter retrier = new RetryCounter(numRetries+1, (int)pause, TimeUnit.MICROSECONDS);
  while(retrier.shouldRetry()) {
    int index = getMiniHBaseCluster().getServerWith(firstrow);
    if (index != -1) {
      return getMiniHBaseCluster().getRegionServerThreads().get(index).getRegionServer();
    }
    // Came back -1.  Region may not be online yet.  Sleep a while.
    retrier.sleepUntilNextRetry();
  }
  return null;
}
项目:HBase-Research    文件:RecoverableZooKeeper.java   
/**
 * exists is an idempotent operation. Retry before throwing exception
 * @return A Stat instance
 */
public Stat exists(String path, Watcher watcher)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.exists(path, watcher);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "exists");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:HBase-Research    文件:RecoverableZooKeeper.java   
/**
 * exists is an idempotent operation. Retry before throwing exception
 * @return A Stat instance
 */
public Stat exists(String path, boolean watch)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.exists(path, watch);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "exists");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:HBase-Research    文件:RecoverableZooKeeper.java   
/**
 * getChildren is an idempotent operation. Retry before throwing exception
 * @return List of children znodes
 */
public List<String> getChildren(String path, Watcher watcher)
  throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.getChildren(path, watcher);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getChildren");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:HBase-Research    文件:RecoverableZooKeeper.java   
/**
 * getChildren is an idempotent operation. Retry before throwing exception
 * @return List of children znodes
 */
public List<String> getChildren(String path, boolean watch)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.getChildren(path, watch);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getChildren");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:HBase-Research    文件:RecoverableZooKeeper.java   
/**
 * getData is an idempotent operation. Retry before throwing exception
 * @return Data
 */
public byte[] getData(String path, Watcher watcher, Stat stat)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      byte[] revData = zk.getData(path, watcher, stat);       
      return this.removeMetaData(revData);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getData");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:HBase-Research    文件:RecoverableZooKeeper.java   
/**
 * getData is an idemnpotent operation. Retry before throwing exception
 * @return Data
 */
public byte[] getData(String path, boolean watch, Stat stat)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      byte[] revData = zk.getData(path, watch, stat);
      return this.removeMetaData(revData);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getData");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:HBase-Research    文件:RecoverableZooKeeper.java   
/**
 * Run multiple operations in a transactional manner. Retry before throwing exception
 */
public List<OpResult> multi(Iterable<Op> ops)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  Iterable<Op> multiOps = prepareZKMulti(ops);
  while (true) {
    try {
      return zk.multi(multiOps);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "multi");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:hbase-0.94.8-qod    文件:RecoverableZooKeeper.java   
/**
 * exists is an idempotent operation. Retry before throwing exception
 * @return A Stat instance
 */
public Stat exists(String path, Watcher watcher)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.exists(path, watcher);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "exists");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:hbase-0.94.8-qod    文件:RecoverableZooKeeper.java   
/**
 * exists is an idempotent operation. Retry before throwing exception
 * @return A Stat instance
 */
public Stat exists(String path, boolean watch)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.exists(path, watch);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "exists");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:hbase-0.94.8-qod    文件:RecoverableZooKeeper.java   
/**
 * getChildren is an idempotent operation. Retry before throwing exception
 * @return List of children znodes
 */
public List<String> getChildren(String path, Watcher watcher)
  throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.getChildren(path, watcher);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getChildren");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:hbase-0.94.8-qod    文件:RecoverableZooKeeper.java   
/**
 * getChildren is an idempotent operation. Retry before throwing exception
 * @return List of children znodes
 */
public List<String> getChildren(String path, boolean watch)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      return zk.getChildren(path, watch);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getChildren");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:hbase-0.94.8-qod    文件:RecoverableZooKeeper.java   
/**
 * getData is an idempotent operation. Retry before throwing exception
 * @return Data
 */
public byte[] getData(String path, Watcher watcher, Stat stat)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      byte[] revData = zk.getData(path, watcher, stat);       
      return this.removeMetaData(revData);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getData");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}
项目:hbase-0.94.8-qod    文件:RecoverableZooKeeper.java   
/**
 * getData is an idemnpotent operation. Retry before throwing exception
 * @return Data
 */
public byte[] getData(String path, boolean watch, Stat stat)
throws KeeperException, InterruptedException {
  RetryCounter retryCounter = retryCounterFactory.create();
  while (true) {
    try {
      byte[] revData = zk.getData(path, watch, stat);
      return this.removeMetaData(revData);
    } catch (KeeperException e) {
      switch (e.code()) {
        case CONNECTIONLOSS:
        case SESSIONEXPIRED:
        case OPERATIONTIMEOUT:
          retryOrThrow(retryCounter, e, "getData");
          break;

        default:
          throw e;
      }
    }
    retryCounter.sleepUntilNextRetry();
    retryCounter.useRetry();
  }
}