当前位置: 首页>>代码示例>>Java>>正文


Java RegionLocations.getRegionLocation方法代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.RegionLocations.getRegionLocation方法的典型用法代码示例。如果您正苦于以下问题:Java RegionLocations.getRegionLocation方法的具体用法?Java RegionLocations.getRegionLocation怎么用?Java RegionLocations.getRegionLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.hbase.RegionLocations的用法示例。

在下文中一共展示了RegionLocations.getRegionLocation方法的34个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getRegionServer

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * Returns the {@link ServerName} from catalog table {@link Result}
 * where the region is transitioning. It should be the same as
 * {@link HRegionInfo#getServerName(Result)} if the server is at OPEN state.
 * @param r Result to pull the transitioning server name from
 * @return A ServerName instance or {@link HRegionInfo#getServerName(Result)}
 * if necessary fields not found or empty.
 */
static ServerName getRegionServer(final Result r, int replicaId) {
  Cell cell = r.getColumnLatestCell(HConstants.CATALOG_FAMILY, getServerNameColumn(replicaId));
  if (cell == null || cell.getValueLength() == 0) {
    RegionLocations locations = MetaTableAccessor.getRegionLocations(r);
    if (locations != null) {
      HRegionLocation location = locations.getRegionLocation(replicaId);
      if (location != null) {
        return location.getServerName();
      }
    }
    return null;
  }
  return ServerName.parseServerName(Bytes.toString(cell.getValueArray(),
    cell.getValueOffset(), cell.getValueLength()));
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:24,代码来源:RegionStateStore.java


示例2: replicateUsingCallable

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
private void replicateUsingCallable(ClusterConnection connection, Queue<Entry> entries)
    throws IOException, RuntimeException {
  Entry entry;
  while ((entry = entries.poll()) != null) {
    byte[] row = entry.getEdit().getCells().get(0).getRow();
    RegionLocations locations = connection.locateRegion(tableName, row, true, true);
    RegionReplicaReplayCallable callable = new RegionReplicaReplayCallable(connection,
      RpcControllerFactory.instantiate(connection.getConfiguration()),
      table.getName(), locations.getRegionLocation(1),
      locations.getRegionLocation(1).getRegionInfo(), row, Lists.newArrayList(entry),
      new AtomicLong());

    RpcRetryingCallerFactory factory = RpcRetryingCallerFactory.instantiate(
      connection.getConfiguration());
    factory.<ReplicateWALEntryResponse> newCaller().callWithRetries(callable, 10000);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:18,代码来源:TestRegionReplicaReplicationEndpointNoMaster.java


示例3: testShutdownOfReplicaHolder

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
@Test
public void testShutdownOfReplicaHolder() throws Exception {
  // checks that the when the server holding meta replica is shut down, the meta replica
  // can be recovered
  RegionLocations rl = ConnectionManager.getConnectionInternal(TEST_UTIL.getConfiguration()).
      locateRegion(TableName.META_TABLE_NAME, Bytes.toBytes(""), false, true);
  HRegionLocation hrl = rl.getRegionLocation(1);
  ServerName oldServer = hrl.getServerName();
  TEST_UTIL.getHBaseClusterInterface().killRegionServer(oldServer);
  int i = 0;
  do {
    LOG.debug("Waiting for the replica " + hrl.getRegionInfo() + " to come up");
    Thread.sleep(30000); //wait for the detection/recovery
    rl = ConnectionManager.getConnectionInternal(TEST_UTIL.getConfiguration()).
        locateRegion(TableName.META_TABLE_NAME, Bytes.toBytes(""), false, true);
    hrl = rl.getRegionLocation(1);
    i++;
  } while ((hrl == null || hrl.getServerName().equals(oldServer)) && i < 3);
  assertTrue(i != 3);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:21,代码来源:TestMetaWithReplicas.java


示例4: prepare

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * Two responsibilities
 * - if the call is already completed (by another replica) stops the retries.
 * - set the location to the right region, depending on the replica.
 */
@Override
public void prepare(final boolean reload) throws IOException {
  if (controller.isCanceled()) return;

  if (Thread.interrupted()) {
    throw new InterruptedIOException();
  }

  if (reload || location == null) {
    RegionLocations rl = getRegionLocations(false, id, cConnection, tableName, get.getRow());
    location = id < rl.size() ? rl.getRegionLocation(id) : null;
  }

  if (location == null || location.getServerName() == null) {
    // With this exception, there will be a retry. The location can be null for a replica
    //  when the table is created or after a split.
    throw new HBaseIOException("There is no location for replica id #" + id);
  }

  ServerName dest = location.getServerName();

  setStub(cConnection.getClient(dest));
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:29,代码来源:RpcRetryingCallerWithReadReplicas.java


示例5: clearCache

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * Delete a cached location, no matter what it is. Called when we were told to not use cache.
 * @param tableName tableName
 * @param row
 */
public void clearCache(final TableName tableName, final byte [] row, int replicaId) {
  ConcurrentMap<byte[], RegionLocations> tableLocations = getTableLocations(tableName);

  boolean removed = false;
  RegionLocations regionLocations = getCachedLocation(tableName, row);
  if (regionLocations != null) {
    HRegionLocation toBeRemoved = regionLocations.getRegionLocation(replicaId);
    RegionLocations updatedLocations = regionLocations.remove(replicaId);
    if (updatedLocations != regionLocations) {
      byte[] startKey = regionLocations.getRegionLocation().getRegionInfo().getStartKey();
      if (updatedLocations.isEmpty()) {
        removed = tableLocations.remove(startKey, regionLocations);
      } else {
        removed = tableLocations.replace(startKey, regionLocations, updatedLocations);
      }
    }

    if (removed && LOG.isTraceEnabled() && toBeRemoved != null) {
      LOG.trace("Removed " + toBeRemoved + " from cache");
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:28,代码来源:MetaCache.java


示例6: getReplicaLocationOrFail

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
private HRegionLocation getReplicaLocationOrFail(Action<Row> action) {
  // We are going to try get location once again. For each action, we'll do it once
  // from cache, because the previous calls in the loop might populate it.
  int replicaId = action.getReplicaId();
  RegionLocations locs = findAllLocationsOrFail(action, true);
  if (locs == null) return null; // manageError already called
  HRegionLocation loc = locs.getRegionLocation(replicaId);
  if (loc == null || loc.getServerName() == null) {
    locs = findAllLocationsOrFail(action, false);
    if (locs == null) return null; // manageError already called
    loc = locs.getRegionLocation(replicaId);
  }
  if (loc == null || loc.getServerName() == null) {
    manageLocationError(action, null);
    return null;
  }
  return loc;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:19,代码来源:AsyncProcess.java


示例7: getRegionServer

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * Returns the {@link ServerName} from catalog table {@link Result}
 * where the region is transitioning. It should be the same as
 * {@link MetaTableAccessor#getServerName(Result,int)} if the server is at OPEN state.
 * @param r Result to pull the transitioning server name from
 * @return A ServerName instance or {@link MetaTableAccessor#getServerName(Result,int)}
 * if necessary fields not found or empty.
 */
static ServerName getRegionServer(final Result r, int replicaId) {
  final Cell cell = r.getColumnLatestCell(HConstants.CATALOG_FAMILY,
      getServerNameColumn(replicaId));
  if (cell == null || cell.getValueLength() == 0) {
    RegionLocations locations = MetaTableAccessor.getRegionLocations(r);
    if (locations != null) {
      HRegionLocation location = locations.getRegionLocation(replicaId);
      if (location != null) {
        return location.getServerName();
      }
    }
    return null;
  }
  return ServerName.parseServerName(Bytes.toString(cell.getValueArray(),
    cell.getValueOffset(), cell.getValueLength()));
}
 
开发者ID:apache,项目名称:hbase,代码行数:25,代码来源:RegionStateStore.java


示例8: replicateUsingCallable

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
private void replicateUsingCallable(ClusterConnection connection, Queue<Entry> entries)
    throws IOException, RuntimeException {
  Entry entry;
  while ((entry = entries.poll()) != null) {
    byte[] row = CellUtil.cloneRow(entry.getEdit().getCells().get(0));
    RegionLocations locations = connection.locateRegion(tableName, row, true, true);
    RegionReplicaReplayCallable callable = new RegionReplicaReplayCallable(connection,
      RpcControllerFactory.instantiate(connection.getConfiguration()),
      table.getName(), locations.getRegionLocation(1),
      locations.getRegionLocation(1).getRegionInfo(), row, Lists.newArrayList(entry),
      new AtomicLong());

    RpcRetryingCallerFactory factory = RpcRetryingCallerFactory.instantiate(
      connection.getConfiguration());
    factory.<ReplicateWALEntryResponse> newCaller().callWithRetries(callable, 10000);
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:18,代码来源:TestRegionReplicaReplicationEndpointNoMaster.java


示例9: testShutdownOfReplicaHolder

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
@Test
public void testShutdownOfReplicaHolder() throws Exception {
  // checks that the when the server holding meta replica is shut down, the meta replica
  // can be recovered
  try (ClusterConnection conn = (ClusterConnection)
      ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())) {
    RegionLocations rl = conn.
        locateRegion(TableName.META_TABLE_NAME, Bytes.toBytes(""), false, true);
    HRegionLocation hrl = rl.getRegionLocation(1);
    ServerName oldServer = hrl.getServerName();
    TEST_UTIL.getHBaseClusterInterface().killRegionServer(oldServer);
    int i = 0;
    do {
      LOG.debug("Waiting for the replica " + hrl.getRegionInfo() + " to come up");
      Thread.sleep(10000); //wait for the detection/recovery
      rl = conn.locateRegion(TableName.META_TABLE_NAME, Bytes.toBytes(""), false, true);
      hrl = rl.getRegionLocation(1);
      i++;
    } while ((hrl == null || hrl.getServerName().equals(oldServer)) && i < 3);
    assertTrue(i != 3);
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:23,代码来源:TestMetaWithReplicas.java


示例10: prepare

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * Two responsibilities
 * - if the call is already completed (by another replica) stops the retries.
 * - set the location to the right region, depending on the replica.
 */
@Override
// TODO: Very like the super class implemenation. Can we shrink this down?
public void prepare(final boolean reload) throws IOException {
  if (getRpcController().isCanceled()) return;
  if (Thread.interrupted()) {
    throw new InterruptedIOException();
  }
  if (reload || location == null) {
    RegionLocations rl = getRegionLocations(false, id, cConnection, tableName, get.getRow());
    location = id < rl.size() ? rl.getRegionLocation(id) : null;
  }

  if (location == null || location.getServerName() == null) {
    // With this exception, there will be a retry. The location can be null for a replica
    //  when the table is created or after a split.
    throw new HBaseIOException("There is no location for replica id #" + id);
  }

  setStubByServiceName(this.location.getServerName());
}
 
开发者ID:apache,项目名称:hbase,代码行数:26,代码来源:RpcRetryingCallerWithReadReplicas.java


示例11: clearCache

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * Deletes the cached location of the region if necessary, based on some error from source.
 * @param hri The region in question.
 */
public void clearCache(RegionInfo hri) {
  ConcurrentMap<byte[], RegionLocations> tableLocations = getTableLocations(hri.getTable());
  RegionLocations regionLocations = tableLocations.get(hri.getStartKey());
  if (regionLocations != null) {
    HRegionLocation oldLocation = regionLocations.getRegionLocation(hri.getReplicaId());
    if (oldLocation == null) return;
    RegionLocations updatedLocations = regionLocations.remove(oldLocation);
    boolean removed;
    if (updatedLocations != regionLocations) {
      if (updatedLocations.isEmpty()) {
        removed = tableLocations.remove(hri.getStartKey(), regionLocations);
      } else {
        removed = tableLocations.replace(hri.getStartKey(), regionLocations, updatedLocations);
      }
      if (removed) {
        if (metrics != null) {
          metrics.incrMetaCacheNumClearRegion();
        }
        if (LOG.isTraceEnabled()) {
          LOG.trace("Removed " + oldLocation + " from cache");
        }
      }
    }
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:30,代码来源:MetaCache.java


示例12: prepare

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * @param reload force reload of server location
 * @throws IOException
 */
@Override
public void prepare(boolean reload) throws IOException {
  if (Thread.interrupted()) {
    throw new InterruptedIOException();
  }
  RegionLocations rl = RpcRetryingCallerWithReadReplicas.getRegionLocations(!reload,
      id, getConnection(), getTableName(), getRow());
  location = id < rl.size() ? rl.getRegionLocation(id) : null;
  if (location == null || location.getServerName() == null) {
    // With this exception, there will be a retry. The location can be null for a replica
    //  when the table is created or after a split.
    throw new HBaseIOException("There is no location for replica id #" + id);
  }
  ServerName dest = location.getServerName();
  setStub(super.getConnection().getClient(dest));
  if (!instantiated || reload) {
    checkIfRegionServerIsRemote();
    instantiated = true;
  }
  cursor = null;
  // check how often we retry.
  if (reload) {
    incRPCRetriesMetrics(scanMetrics, isRegionServerRemote);
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:30,代码来源:ScannerCallable.java


示例13: getReplicaLocationOrFail

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
private HRegionLocation getReplicaLocationOrFail(Action action) {
  // We are going to try get location once again. For each action, we'll do it once
  // from cache, because the previous calls in the loop might populate it.
  int replicaId = action.getReplicaId();
  RegionLocations locs = findAllLocationsOrFail(action, true);
  if (locs == null) return null; // manageError already called
  HRegionLocation loc = locs.getRegionLocation(replicaId);
  if (loc == null || loc.getServerName() == null) {
    locs = findAllLocationsOrFail(action, false);
    if (locs == null) return null; // manageError already called
    loc = locs.getRegionLocation(replicaId);
  }
  if (loc == null || loc.getServerName() == null) {
    manageLocationError(action, null);
    return null;
  }
  return loc;
}
 
开发者ID:apache,项目名称:hbase,代码行数:19,代码来源:AsyncRequestFutureImpl.java


示例14: countMetaRegions

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
private static int countMetaRegions(final HMaster master, final TableName tableName)
    throws IOException {
  final AtomicInteger actualRegCount = new AtomicInteger(0);
  final MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result rowResult) throws IOException {
      RegionLocations list = MetaTableAccessor.getRegionLocations(rowResult);
      if (list == null) {
        LOG.warn("No serialized HRegionInfo in " + rowResult);
        return true;
      }
      HRegionLocation l = list.getRegionLocation();
      if (l == null) {
        return true;
      }
      if (!l.getRegionInfo().getTable().equals(tableName)) {
        return false;
      }
      if (l.getRegionInfo().isOffline() || l.getRegionInfo().isSplit()) return true;
      HRegionLocation[] locations = list.getRegionLocations();
      for (HRegionLocation location : locations) {
        if (location == null) continue;
        ServerName serverName = location.getServerName();
        // Make sure that regions are assigned to server
        if (serverName != null && serverName.getHostAndPort() != null) {
          actualRegCount.incrementAndGet();
        }
      }
      return true;
    }
  };
  MetaScanner.metaScan(master.getConnection(), visitor, tableName);
  return actualRegCount.get();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:35,代码来源:MasterProcedureTestingUtility.java


示例15: addCallsForReplica

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * Creates the calls and submit them
 *
 * @param cs  - the completion service to use for submitting
 * @param rl  - the region locations
 * @param min - the id of the first replica, inclusive
 * @param max - the id of the last replica, inclusive.
 */
private void addCallsForReplica(ResultBoundedCompletionService<Result> cs,
                               RegionLocations rl, int min, int max) {
  for (int id = min; id <= max; id++) {
    HRegionLocation hrl = rl.getRegionLocation(id);
    ReplicaRegionServerCallable callOnReplica = new ReplicaRegionServerCallable(id, hrl);
    cs.submit(callOnReplica, callTimeout, id);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:RpcRetryingCallerWithReadReplicas.java


示例16: prepare

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * @param reload force reload of server location
 * @throws IOException
 */
@Override
public void prepare(boolean reload) throws IOException {
  if (Thread.interrupted()) {
    throw new InterruptedIOException();
  }
  RegionLocations rl = RpcRetryingCallerWithReadReplicas.getRegionLocations(!reload,
      id, getConnection(), getTableName(), getRow());
  location = id < rl.size() ? rl.getRegionLocation(id) : null;
  if (location == null || location.getServerName() == null) {
    // With this exception, there will be a retry. The location can be null for a replica
    //  when the table is created or after a split.
    throw new HBaseIOException("There is no location for replica id #" + id);
  }
  ServerName dest = location.getServerName();
  setStub(super.getConnection().getClient(dest));
  if (!instantiated || reload) {
    checkIfRegionServerIsRemote();
    instantiated = true;
  }

  // check how often we retry.
  // HConnectionManager will call instantiateServer with reload==true
  // if and only if for retries.
  if (reload && this.scanMetrics != null) {
    this.scanMetrics.countOfRPCRetries.incrementAndGet();
    if (isRegionServerRemote) {
      this.scanMetrics.countOfRemoteRPCRetries.incrementAndGet();
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:35,代码来源:ScannerCallable.java


示例17: relocateRegion

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
@Override
public HRegionLocation relocateRegion(final TableName tableName,
    final byte [] row) throws IOException{
  RegionLocations locations =  relocateRegion(tableName, row,
    RegionReplicaUtil.DEFAULT_REPLICA_ID);
  return locations == null ? null :
    locations.getRegionLocation(RegionReplicaUtil.DEFAULT_REPLICA_ID);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:9,代码来源:ConnectionManager.java


示例18: locateMeta

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
private RegionLocations locateMeta(final TableName tableName,
    boolean useCache, int replicaId) throws IOException {
  // HBASE-10785: We cache the location of the META itself, so that we are not overloading
  // zookeeper with one request for every region lookup. We cache the META with empty row
  // key in MetaCache.
  byte[] metaCacheKey = HConstants.EMPTY_START_ROW; // use byte[0] as the row for meta
  RegionLocations locations = null;
  if (useCache) {
    locations = getCachedLocation(tableName, metaCacheKey);
    if (locations != null && locations.getRegionLocation(replicaId) != null) {
      return locations;
    }
  }

  // only one thread should do the lookup.
  synchronized (metaRegionLock) {
    // Check the cache again for a hit in case some other thread made the
    // same query while we were waiting on the lock.
    if (useCache) {
      locations = getCachedLocation(tableName, metaCacheKey);
      if (locations != null && locations.getRegionLocation(replicaId) != null) {
        return locations;
      }
    }

    // Look up from zookeeper
    locations = this.registry.getMetaRegionLocation();
    if (locations != null) {
      cacheLocation(tableName, locations);
    }
  }
  return locations;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:34,代码来源:ConnectionManager.java


示例19: locateRegionsInRange

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * Get the corresponding regions for an arbitrary range of keys.
 * @param startKey Starting row in range, inclusive
 * @param endKey Ending row in range, exclusive
 * @param reload force reload of server location
 * @return A list of HRegionLocation corresponding to the regions that contain
 *         the specified range
 * @throws IOException
 */
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value="NP_NULL_ON_SOME_PATH",
    justification="I thought I'd fixed it but FB still complains; see below")
private List<HRegionLocation> locateRegionsInRange(byte[] startKey,
    byte[] endKey, boolean reload) throws IOException {
  final boolean endKeyIsEndOfTable = Bytes.equals(endKey,
      HConstants.EMPTY_END_ROW);
  if ((Bytes.compareTo(startKey, endKey) > 0) && !endKeyIsEndOfTable) {
    throw new IllegalArgumentException("Invalid range: "
        + Bytes.toStringBinary(startKey) + " > "
        + Bytes.toStringBinary(endKey));
  }
  List<HRegionLocation> regionList = new ArrayList<HRegionLocation>();
  byte[] currentKey = startKey;
  do {
    RegionLocations rl = RpcRetryingCallerWithReadReplicas.getRegionLocations(reload, id,
        getConnection(), tableName, currentKey);
    HRegionLocation regionLocation = id < rl.size() ? rl.getRegionLocation(id) : null;
    if (regionLocation != null && regionLocation.getRegionInfo().containsRow(currentKey)) {
      regionList.add(regionLocation);
    } else {
      // FindBugs: NP_NULL_ON_SOME_PATH Complaining about regionLocation
      throw new DoNotRetryIOException("Does hbase:meta exist hole? Locating row "
          + Bytes.toStringBinary(currentKey) + " returns incorrect region "
          + (regionLocation != null? regionLocation.getRegionInfo(): null));
    }
    currentKey = regionLocation.getRegionInfo().getEndKey();
  } while (!Bytes.equals(currentKey, HConstants.EMPTY_END_ROW)
      && (endKeyIsEndOfTable || Bytes.compareTo(currentKey, endKey) < 0));
  return regionList;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:40,代码来源:ReversedScannerCallable.java


示例20: getLocation

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
public HRegionLocation getLocation(boolean useCache) throws IOException {
  RegionLocations rl = getRegionLocations(connection, tableName, row, useCache, replicaId);
  if (rl == null) {
    throw new HBaseIOException(getExceptionMessage());
  }
  HRegionLocation location = rl.getRegionLocation(replicaId);
  if (location == null) {
    throw new HBaseIOException(getExceptionMessage());
  }

  return location;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:13,代码来源:RegionAdminServiceCallable.java


示例21: addCallsForReplica

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * Creates the calls and submit them
 *
 * @param cs  - the completion service to use for submitting
 * @param rl  - the region locations
 * @param min - the id of the first replica, inclusive
 * @param max - the id of the last replica, inclusive.
 */
private void addCallsForReplica(ResultBoundedCompletionService cs,
                               RegionLocations rl, int min, int max) {
  for (int id = min; id <= max; id++) {
    HRegionLocation hrl = rl.getRegionLocation(id);
    ReplicaRegionServerCallable callOnReplica = new ReplicaRegionServerCallable(id, hrl);
    cs.submit(callOnReplica, callTimeout);
  }
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:17,代码来源:RpcRetryingCallerWithReadReplicas.java


示例22: relocateRegion

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
@Override
public HRegionLocation relocateRegion(final TableName tableName,
                                      final byte[] row) throws IOException {
    RegionLocations locations = relocateRegion(tableName, row,
            RegionReplicaUtil.DEFAULT_REPLICA_ID);
    return locations == null ? null :
            locations.getRegionLocation(RegionReplicaUtil.DEFAULT_REPLICA_ID);
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:9,代码来源:ConnectionManager.java


示例23: locateRegionsInRange

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * Get the corresponding regions for an arbitrary range of keys.
 * @param startKey Starting row in range, inclusive
 * @param endKey Ending row in range, exclusive
 * @param reload force reload of server location
 * @return A list of HRegionLocation corresponding to the regions that contain
 *         the specified range
 * @throws IOException
 */
private List<HRegionLocation> locateRegionsInRange(byte[] startKey,
    byte[] endKey, boolean reload) throws IOException {
  final boolean endKeyIsEndOfTable = Bytes.equals(endKey,
      HConstants.EMPTY_END_ROW);
  if ((Bytes.compareTo(startKey, endKey) > 0) && !endKeyIsEndOfTable) {
    throw new IllegalArgumentException("Invalid range: "
        + Bytes.toStringBinary(startKey) + " > "
        + Bytes.toStringBinary(endKey));
  }
  List<HRegionLocation> regionList = new ArrayList<HRegionLocation>();
  byte[] currentKey = startKey;
  do {
    RegionLocations rl = RpcRetryingCallerWithReadReplicas.getRegionLocations(reload, id,
        getConnection(), tableName, currentKey);
    HRegionLocation regionLocation = id < rl.size() ? rl.getRegionLocation(id) : null;
    if (regionLocation != null && regionLocation.getRegionInfo().containsRow(currentKey)) {
      regionList.add(regionLocation);
    } else {
      throw new DoNotRetryIOException("Does hbase:meta exist hole? Locating row "
          + Bytes.toStringBinary(currentKey) + " returns incorrect region "
          + regionLocation.getRegionInfo());
    }
    currentKey = regionLocation.getRegionInfo().getEndKey();
  } while (!Bytes.equals(currentKey, HConstants.EMPTY_END_ROW)
      && (endKeyIsEndOfTable || Bytes.compareTo(currentKey, endKey) < 0));
  return regionList;
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:37,代码来源:ReversedScannerCallable.java


示例24: countMetaRegions

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
private static int countMetaRegions(final HMaster master, final TableName tableName)
    throws IOException {
  final AtomicInteger actualRegCount = new AtomicInteger(0);
  final MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() {
    @Override
    public boolean visit(Result rowResult) throws IOException {
      RegionLocations list = MetaTableAccessor.getRegionLocations(rowResult);
      if (list == null) {
        LOG.warn("No serialized RegionInfo in " + rowResult);
        return true;
      }
      HRegionLocation l = list.getRegionLocation();
      if (l == null) {
        return true;
      }
      if (!l.getRegionInfo().getTable().equals(tableName)) {
        return false;
      }
      if (l.getRegionInfo().isOffline() || l.getRegionInfo().isSplit()) return true;
      HRegionLocation[] locations = list.getRegionLocations();
      for (HRegionLocation location : locations) {
        if (location == null) continue;
        ServerName serverName = location.getServerName();
        // Make sure that regions are assigned to server
        if (serverName != null && serverName.getHostAndPort() != null) {
          actualRegCount.incrementAndGet();
        }
      }
      return true;
    }
  };
  MetaTableAccessor.scanMetaForTableRegions(master.getConnection(), visitor, tableName);
  return actualRegCount.get();
}
 
开发者ID:apache,项目名称:hbase,代码行数:35,代码来源:MasterProcedureTestingUtility.java


示例25: locateMeta

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
private RegionLocations locateMeta(final TableName tableName,
    boolean useCache, int replicaId) throws IOException {
  // HBASE-10785: We cache the location of the META itself, so that we are not overloading
  // zookeeper with one request for every region lookup. We cache the META with empty row
  // key in MetaCache.
  byte[] metaCacheKey = HConstants.EMPTY_START_ROW; // use byte[0] as the row for meta
  RegionLocations locations = null;
  if (useCache) {
    locations = getCachedLocation(tableName, metaCacheKey);
    if (locations != null && locations.getRegionLocation(replicaId) != null) {
      return locations;
    }
  }

  // only one thread should do the lookup.
  synchronized (metaRegionLock) {
    // Check the cache again for a hit in case some other thread made the
    // same query while we were waiting on the lock.
    if (useCache) {
      locations = getCachedLocation(tableName, metaCacheKey);
      if (locations != null && locations.getRegionLocation(replicaId) != null) {
        return locations;
      }
    }

    // Look up from zookeeper
    locations = get(this.registry.getMetaRegionLocation());
    if (locations != null) {
      cacheLocation(tableName, locations);
    }
  }
  return locations;
}
 
开发者ID:apache,项目名称:hbase,代码行数:34,代码来源:ConnectionImplementation.java


示例26: addCallsForReplica

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * Creates the calls and submit them
 *
 * @param cs  - the completion service to use for submitting
 * @param rl  - the region locations
 * @param min - the id of the first replica, inclusive
 * @param max - the id of the last replica, inclusive.
 */
private void addCallsForReplica(ResultBoundedCompletionService<Result> cs,
                               RegionLocations rl, int min, int max) {
  for (int id = min; id <= max; id++) {
    HRegionLocation hrl = rl.getRegionLocation(id);
    ReplicaRegionServerCallable callOnReplica = new ReplicaRegionServerCallable(id, hrl);
    cs.submit(callOnReplica, operationTimeout, id);
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:17,代码来源:RpcRetryingCallerWithReadReplicas.java


示例27: locateRegionsInRange

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * Get the corresponding regions for an arbitrary range of keys.
 * @param startKey Starting row in range, inclusive
 * @param endKey Ending row in range, exclusive
 * @param reload force reload of server location
 * @return A list of HRegionLocation corresponding to the regions that contain
 *         the specified range
 * @throws IOException
 */
private List<HRegionLocation> locateRegionsInRange(byte[] startKey,
    byte[] endKey, boolean reload) throws IOException {
  final boolean endKeyIsEndOfTable = Bytes.equals(endKey,
      HConstants.EMPTY_END_ROW);
  if ((Bytes.compareTo(startKey, endKey) > 0) && !endKeyIsEndOfTable) {
    throw new IllegalArgumentException("Invalid range: "
        + Bytes.toStringBinary(startKey) + " > "
        + Bytes.toStringBinary(endKey));
  }
  List<HRegionLocation> regionList = new ArrayList<>();
  byte[] currentKey = startKey;
  do {
    RegionLocations rl = RpcRetryingCallerWithReadReplicas.getRegionLocations(!reload, id,
        getConnection(), getTableName(), currentKey);
    HRegionLocation regionLocation = id < rl.size() ? rl.getRegionLocation(id) : null;
    if (regionLocation != null && regionLocation.getRegionInfo().containsRow(currentKey)) {
      regionList.add(regionLocation);
    } else {
      throw new DoNotRetryIOException("Does hbase:meta exist hole? Locating row "
          + Bytes.toStringBinary(currentKey) + " returns incorrect region "
          + (regionLocation == null ? null : regionLocation.getRegionInfo()));
    }
    currentKey = regionLocation.getRegionInfo().getEndKey();
  } while (!Bytes.equals(currentKey, HConstants.EMPTY_END_ROW)
      && (endKeyIsEndOfTable || Bytes.compareTo(currentKey, endKey) < 0));
  return regionList;
}
 
开发者ID:apache,项目名称:hbase,代码行数:37,代码来源:ReversedScannerCallable.java


示例28: waitForAllRegionsOnline

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
private void waitForAllRegionsOnline(final long deadlineTs)
    throws IOException, TimeoutException {
  final AtomicInteger actualRegCount = new AtomicInteger(0);
  final MetaScannerVisitor visitor = new MetaScannerVisitorBase() {
    @Override
    public boolean processRow(Result rowResult) throws IOException {
      RegionLocations list = MetaTableAccessor.getRegionLocations(rowResult);
      if (list == null) {
        LOG.warn("No serialized HRegionInfo in " + rowResult);
        return true;
      }
      HRegionLocation l = list.getRegionLocation();
      if (l == null) {
        return true;
      }
      if (!l.getRegionInfo().getTable().equals(desc.getTableName())) {
        return false;
      }
      if (l.getRegionInfo().isOffline() || l.getRegionInfo().isSplit()) return true;
      HRegionLocation[] locations = list.getRegionLocations();
      for (HRegionLocation location : locations) {
        if (location == null) continue;
        ServerName serverName = location.getServerName();
        // Make sure that regions are assigned to server
        if (serverName != null && serverName.getHostAndPort() != null) {
          actualRegCount.incrementAndGet();
        }
      }
      return true;
    }
  };

  int tries = 0;
  IOException serverEx = null;
  int numRegs = (splitKeys == null ? 1 : splitKeys.length + 1) * desc.getRegionReplication();
  while (EnvironmentEdgeManager.currentTime() < deadlineTs) {
    actualRegCount.set(0);
    MetaScanner.metaScan(getAdmin().getConnection(), visitor, desc.getTableName());
    if (actualRegCount.get() == numRegs) {
      // all the regions are online
      return;
    }

    try {
      Thread.sleep(getAdmin().getPauseTime(tries++));
    } catch (InterruptedException e) {
      throw new InterruptedIOException("Interrupted when opening" +
        " regions; " + actualRegCount.get() + " of " + numRegs +
        " regions processed so far");
    }
  }
  throw new TimeoutException("Only " + actualRegCount.get() +
          " of " + numRegs + " regions are online; retries exhausted.");
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:55,代码来源:HBaseAdmin.java


示例29: locateRegion

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
@Override
public HRegionLocation locateRegion(final byte[] regionName) throws IOException {
  RegionLocations locations = locateRegion(HRegionInfo.getTable(regionName),
    HRegionInfo.getStartKey(regionName), false, true);
  return locations == null ? null : locations.getRegionLocation();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:7,代码来源:ConnectionManager.java


示例30: prepare

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * @param reload force reload of server location
 * @throws IOException
 */
@Override
public void prepare(boolean reload) throws IOException {
  if (Thread.interrupted()) {
    throw new InterruptedIOException();
  }
  if (!instantiated || reload) {
    if (locateStartRow == null) {
      // Just locate the region with the row
      RegionLocations rl = RpcRetryingCallerWithReadReplicas.getRegionLocations(reload, id,
          getConnection(), tableName, row);
      this.location = id < rl.size() ? rl.getRegionLocation(id) : null;
      if (this.location == null) {
        throw new IOException("Failed to find location, tableName="
            + tableName + ", row=" + Bytes.toStringBinary(row) + ", reload="
            + reload);
      }
    } else {
      // Need to locate the regions with the range, and the target location is
      // the last one which is the previous region of last region scanner
      List<HRegionLocation> locatedRegions = locateRegionsInRange(
          locateStartRow, row, reload);
      if (locatedRegions.isEmpty()) {
        throw new DoNotRetryIOException(
            "Does hbase:meta exist hole? Couldn't get regions for the range from "
                + Bytes.toStringBinary(locateStartRow) + " to "
                + Bytes.toStringBinary(row));
      }
      this.location = locatedRegions.get(locatedRegions.size() - 1);
    }
    setStub(getConnection().getClient(getLocation().getServerName()));
    checkIfRegionServerIsRemote();
    instantiated = true;
  }

  // check how often we retry.
  // HConnectionManager will call instantiateServer with reload==true
  // if and only if for retries.
  if (reload && this.scanMetrics != null) {
    this.scanMetrics.countOfRPCRetries.incrementAndGet();
    if (isRegionServerRemote) {
      this.scanMetrics.countOfRemoteRPCRetries.incrementAndGet();
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:49,代码来源:ReversedScannerCallable.java


示例31: locateRegion

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
@Override
public HRegionLocation locateRegion(final byte[] regionName) throws IOException {
    RegionLocations locations = locateRegion(HRegionInfo.getTable(regionName),
            HRegionInfo.getStartKey(regionName), false, true);
    return locations == null ? null : locations.getRegionLocation();
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:7,代码来源:ConnectionManager.java


示例32: locateRegion

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
@Override
public HRegionLocation locateRegion(final byte[] regionName) throws IOException {
  RegionLocations locations = locateRegion(RegionInfo.getTable(regionName),
    RegionInfo.getStartKey(regionName), false, true);
  return locations == null ? null : locations.getRegionLocation();
}
 
开发者ID:apache,项目名称:hbase,代码行数:7,代码来源:ConnectionImplementation.java


示例33: waitForAllRegionsOnline

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
protected void waitForAllRegionsOnline(final long deadlineTs, final byte[][] splitKeys)
    throws IOException, TimeoutException {
  final TableDescriptor desc = getTableDescriptor();
  final AtomicInteger actualRegCount = new AtomicInteger(0);
  final MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() {
    @Override
    public boolean visit(Result rowResult) throws IOException {
      RegionLocations list = MetaTableAccessor.getRegionLocations(rowResult);
      if (list == null) {
        LOG.warn("No serialized HRegionInfo in " + rowResult);
        return true;
      }
      HRegionLocation l = list.getRegionLocation();
      if (l == null) {
        return true;
      }
      if (!l.getRegionInfo().getTable().equals(desc.getTableName())) {
        return false;
      }
      if (l.getRegionInfo().isOffline() || l.getRegionInfo().isSplit()) return true;
      HRegionLocation[] locations = list.getRegionLocations();
      for (HRegionLocation location : locations) {
        if (location == null) continue;
        ServerName serverName = location.getServerName();
        // Make sure that regions are assigned to server
        if (serverName != null && serverName.getHostAndPort() != null) {
          actualRegCount.incrementAndGet();
        }
      }
      return true;
    }
  };

  int tries = 0;
  int numRegs = (splitKeys == null ? 1 : splitKeys.length + 1) * desc.getRegionReplication();
  while (EnvironmentEdgeManager.currentTime() < deadlineTs) {
    actualRegCount.set(0);
    MetaTableAccessor.scanMetaForTableRegions(getAdmin().getConnection(), visitor,
      desc.getTableName());
    if (actualRegCount.get() == numRegs) {
      // all the regions are online
      return;
    }

    try {
      Thread.sleep(getAdmin().getPauseTime(tries++));
    } catch (InterruptedException e) {
      throw new InterruptedIOException("Interrupted when opening" + " regions; "
          + actualRegCount.get() + " of " + numRegs + " regions processed so far");
    }
  }
  throw new TimeoutException("Only " + actualRegCount.get() + " of " + numRegs
      + " regions are online; retries exhausted.");
}
 
开发者ID:apache,项目名称:hbase,代码行数:55,代码来源:HBaseAdmin.java


示例34: prepare

import org.apache.hadoop.hbase.RegionLocations; //导入方法依赖的package包/类
/**
 * @param reload force reload of server location
 * @throws IOException
 */
@Override
public void prepare(boolean reload) throws IOException {
  if (Thread.interrupted()) {
    throw new InterruptedIOException();
  }
  if (!instantiated || reload) {
    // we should use range locate if
    // 1. we do not want the start row
    // 2. the start row is empty which means we need to locate to the last region.
    if (scan.includeStartRow() && !isEmptyStartRow(getRow())) {
      // Just locate the region with the row
      RegionLocations rl = RpcRetryingCallerWithReadReplicas.getRegionLocations(!reload, id,
          getConnection(), getTableName(), getRow());
      this.location = id < rl.size() ? rl.getRegionLocation(id) : null;
      if (location == null || location.getServerName() == null) {
        throw new IOException("Failed to find location, tableName="
            + getTableName() + ", row=" + Bytes.toStringBinary(getRow()) + ", reload="
            + reload);
      }
    } else {
      // Need to locate the regions with the range, and the target location is
      // the last one which is the previous region of last region scanner
      byte[] locateStartRow = createCloseRowBefore(getRow());
      List<HRegionLocation> locatedRegions = locateRegionsInRange(
          locateStartRow, getRow(), reload);
      if (locatedRegions.isEmpty()) {
        throw new DoNotRetryIOException(
            "Does hbase:meta exist hole? Couldn't get regions for the range from "
                + Bytes.toStringBinary(locateStartRow) + " to "
                + Bytes.toStringBinary(getRow()));
      }
      this.location = locatedRegions.get(locatedRegions.size() - 1);
    }
    setStub(getConnection().getClient(getLocation().getServerName()));
    checkIfRegionServerIsRemote();
    instantiated = true;
  }

  // check how often we retry.
  if (reload) {
    incRPCRetriesMetrics(scanMetrics, isRegionServerRemote);
  }
}
 
开发者ID:apache,项目名称:hbase,代码行数:48,代码来源:ReversedScannerCallable.java



注:本文中的org.apache.hadoop.hbase.RegionLocations.getRegionLocation方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。