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


Java AssignmentManager.replicaRegionsNotRecordedInMeta方法代码示例

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


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

示例1: handleEnableTable

import org.apache.hadoop.hbase.master.AssignmentManager; //导入方法依赖的package包/类
private void handleEnableTable() throws IOException, CoordinatedStateException,
    InterruptedException {
  // I could check table is disabling and if so, not enable but require
  // that user first finish disabling but that might be obnoxious.

  // Set table enabling flag up in zk.
  this.assignmentManager.getTableStateManager().setTableState(this.tableName,
    ZooKeeperProtos.Table.State.ENABLING);
  boolean done = false;
  ServerManager serverManager = ((HMaster)this.server).getServerManager();
  // Get the regions of this table. We're done when all listed
  // tables are onlined.
  List<Pair<HRegionInfo, ServerName>> tableRegionsAndLocations;
  if (TableName.META_TABLE_NAME.equals(tableName)) {
    tableRegionsAndLocations = new MetaTableLocator().getMetaRegionsAndLocations(
      server.getZooKeeper());
  } else {
    tableRegionsAndLocations = MetaTableAccessor.getTableRegionsAndLocations(
      server.getZooKeeper(), server.getConnection(), tableName, true);
  }

  int countOfRegionsInTable = tableRegionsAndLocations.size();
  Map<HRegionInfo, ServerName> regionsToAssign =
      regionsToAssignWithServerName(tableRegionsAndLocations);
  if (services != null) {
    // need to potentially create some regions for the replicas
    List<HRegionInfo> unrecordedReplicas = AssignmentManager.replicaRegionsNotRecordedInMeta(
        new HashSet<HRegionInfo>(regionsToAssign.keySet()), services);
    Map<ServerName, List<HRegionInfo>> srvToUnassignedRegs =
          this.assignmentManager.getBalancer().roundRobinAssignment(unrecordedReplicas,
              serverManager.getOnlineServersList());
    if (srvToUnassignedRegs != null) {
      for (Map.Entry<ServerName, List<HRegionInfo>> entry : srvToUnassignedRegs.entrySet()) {
        for (HRegionInfo h : entry.getValue()) {
          regionsToAssign.put(h, entry.getKey());
        }
      }
    }
  }
  int regionsCount = regionsToAssign.size();
  if (regionsCount == 0) {
    done = true;
  }
  LOG.info("Table '" + this.tableName + "' has " + countOfRegionsInTable
    + " regions, of which " + regionsCount + " are offline.");
  List<ServerName> onlineServers = serverManager.createDestinationServersList();
  Map<ServerName, List<HRegionInfo>> bulkPlan =
      this.assignmentManager.getBalancer().retainAssignment(regionsToAssign, onlineServers);
  if (bulkPlan != null) {
    LOG.info("Bulk assigning " + regionsCount + " region(s) across " + bulkPlan.size()
        + " server(s), retainAssignment=true");

    BulkAssigner ba =
        new GeneralBulkAssigner(this.server, bulkPlan, this.assignmentManager, true);
    try {
      if (ba.bulkAssign()) {
        done = true;
      }
    } catch (InterruptedException e) {
      LOG.warn("Enable operation was interrupted when enabling table '"
          + this.tableName + "'");
      // Preserve the interrupt.
      Thread.currentThread().interrupt();
    }
  } else {
    done = true;
    LOG.info("Balancer was unable to find suitable servers for table " + tableName
        + ", leaving unassigned");
  }
  if (done) {
    // Flip the table to enabled.
    this.assignmentManager.getTableStateManager().setTableState(
      this.tableName, ZooKeeperProtos.Table.State.ENABLED);
    LOG.info("Table '" + this.tableName
    + "' was successfully enabled. Status: done=" + done);
  } else {
    LOG.warn("Table '" + this.tableName
    + "' wasn't successfully enabled. Status: done=" + done);
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:81,代码来源:EnableTableHandler.java

示例2: markRegionsOnline

import org.apache.hadoop.hbase.master.AssignmentManager; //导入方法依赖的package包/类
/**
 * Mark offline regions of the table online
 * @param env MasterProcedureEnv
 * @param tableName the target table
 * @return whether the operation is fully completed or being interrupted.
 * @throws IOException
 */
private static boolean markRegionsOnline(final MasterProcedureEnv env, final TableName tableName)
    throws IOException {
  final AssignmentManager assignmentManager = env.getMasterServices().getAssignmentManager();
  final MasterServices masterServices = env.getMasterServices();
  final ServerManager serverManager = masterServices.getServerManager();
  boolean done = false;
  // Get the regions of this table. We're done when all listed
  // tables are onlined.
  List<Pair<HRegionInfo, ServerName>> tableRegionsAndLocations;

  if (TableName.META_TABLE_NAME.equals(tableName)) {
    tableRegionsAndLocations =
        new MetaTableLocator().getMetaRegionsAndLocations(masterServices.getZooKeeper());
  } else {
    tableRegionsAndLocations =
        MetaTableAccessor.getTableRegionsAndLocations(
          masterServices.getZooKeeper(), masterServices.getConnection(), tableName, true);
  }

  int countOfRegionsInTable = tableRegionsAndLocations.size();
  Map<HRegionInfo, ServerName> regionsToAssign =
      regionsToAssignWithServerName(env, tableRegionsAndLocations);

  // need to potentially create some regions for the replicas
  List<HRegionInfo> unrecordedReplicas =
      AssignmentManager.replicaRegionsNotRecordedInMeta(new HashSet<HRegionInfo>(
          regionsToAssign.keySet()), masterServices);
  Map<ServerName, List<HRegionInfo>> srvToUnassignedRegs =
      assignmentManager.getBalancer().roundRobinAssignment(unrecordedReplicas,
        serverManager.getOnlineServersList());
  if (srvToUnassignedRegs != null) {
    for (Map.Entry<ServerName, List<HRegionInfo>> entry : srvToUnassignedRegs.entrySet()) {
      for (HRegionInfo h : entry.getValue()) {
        regionsToAssign.put(h, entry.getKey());
      }
    }
  }

  int offlineRegionsCount = regionsToAssign.size();

  LOG.info("Table '" + tableName + "' has " + countOfRegionsInTable + " regions, of which "
      + offlineRegionsCount + " are offline.");
  if (offlineRegionsCount == 0) {
    return true;
  }

  List<ServerName> onlineServers = serverManager.createDestinationServersList();
  Map<ServerName, List<HRegionInfo>> bulkPlan =
      env.getMasterServices().getAssignmentManager().getBalancer()
          .retainAssignment(regionsToAssign, onlineServers);
  if (bulkPlan != null) {
    LOG.info("Bulk assigning " + offlineRegionsCount + " region(s) across " + bulkPlan.size()
        + " server(s), retainAssignment=true");

    BulkAssigner ba = new GeneralBulkAssigner(masterServices, bulkPlan, assignmentManager, true);
    try {
      if (ba.bulkAssign()) {
        done = true;
      }
    } catch (InterruptedException e) {
      LOG.warn("Enable operation was interrupted when enabling table '" + tableName + "'");
      // Preserve the interrupt.
      Thread.currentThread().interrupt();
    }
  } else {
    LOG.info("Balancer was unable to find suitable servers for table " + tableName
        + ", leaving unassigned");
  }
  return done;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:78,代码来源:EnableTableProcedure.java


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