Package org.apache.hadoop.hbase.master

Examples of org.apache.hadoop.hbase.master.AssignmentManager$CreateUnassignedAsyncCallback


    if (cpHost != null) {
      cpHost.preSnapshot(snapshot, desc);
    }

    // if the table is enabled, then have the RS run actually the snapshot work
    AssignmentManager assignmentMgr = master.getAssignmentManager();
    if (assignmentMgr.getZKTable().isEnabledTable(snapshot.getTable())) {
      LOG.debug("Table enabled, starting distributed snapshot.");
      snapshotEnabledTable(snapshot);
      LOG.debug("Started snapshot: " + SnapshotDescriptionUtils.toString(snapshot));
    }
    // For disabled table, snapshot is created by the master
    else if (assignmentMgr.getZKTable().isDisabledTable(snapshot.getTable())) {
      LOG.debug("Table is disabled, running snapshot entirely on master.");
      snapshotDisabledTable(snapshot);
      LOG.debug("Started snapshot: " + SnapshotDescriptionUtils.toString(snapshot));
    } else {
      LOG.error("Can't snapshot table '" + snapshot.getTable()
View Full Code Here


    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    HBaseAdmin localAdmin = createTable(tableName);
    List<HRegionInfo> tableRegions = localAdmin.getTableRegions(tableName);
    HRegionInfo hri = tableRegions.get(0);
    AssignmentManager am = master.getAssignmentManager();
    assertTrue("Region " + hri.getRegionNameAsString()
      + " should be assigned properly", am.waitForAssignment(hri));
    ServerName server = am.getRegionStates().getRegionServerOfRegion(hri);
    localAdmin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(server.getServerName()));
    assertEquals("Current region server and region server before move should be same.", server,
      am.getRegionStates().getRegionServerOfRegion(hri));
  }
View Full Code Here

    }
  }

  private void waitForRITtoBeZero(HMaster master) throws IOException {
    // wait for assignments to finish
    AssignmentManager mgr = master.getAssignmentManager();
    Collection<AssignmentManager.RegionState> transRegions =
        mgr.getRegionsInTransition().values();
    for (AssignmentManager.RegionState state : transRegions) {
      mgr.waitOnRegionToClearRegionsInTransition(state.getRegion());
    }
  }
View Full Code Here

    MasterCoprocessorHost cpHost = ((HMaster) this.server).getCoprocessorHost();
    if (cpHost != null) {
      cpHost.preDeleteTableHandler(this.tableName);
    }
    // 1. Wait because of region in transition
    AssignmentManager am = this.masterServices.getAssignmentManager();
    long waitTime = server.getConfiguration().
      getLong("hbase.master.wait.on.region", 5 * 60 * 1000);
    for (HRegionInfo region : regions) {
      long done = System.currentTimeMillis() + waitTime;
      while (System.currentTimeMillis() < done) {
        AssignmentManager.RegionState rs = am.isRegionInTransition(region);
        if (rs == null) break;
        Threads.sleep(waitingTimeForEvents);
        LOG.debug("Waiting on  region to clear regions in transition; " + rs);
      }
      if (am.isRegionInTransition(region) != null) {
        throw new IOException("Waited hbase.master.wait.on.region (" +
          waitTime + "ms) for region to leave region " +
          region.getRegionNameAsString() + " in transitions");
      }
    }

    // 2. Remove regions from META
    LOG.debug("Deleting regions from META");
    MetaEditor.deleteRegions(this.server.getCatalogTracker(), regions);

    // 3. Move the table in /hbase/.tmp
    LOG.debug("Moving table directory to a temp directory");
    MasterFileSystem mfs = this.masterServices.getMasterFileSystem();
    Path tempTableDir = mfs.moveTableToTemp(tableName);

    try {
      // 4. Delete regions from FS (temp directory)
      FileSystem fs = mfs.getFileSystem();
      for (HRegionInfo hri: regions) {
        LOG.debug("Archiving region " + hri.getRegionNameAsString() + " from FS");
        HFileArchiver.archiveRegion(fs, mfs.getRootDir(),
            tempTableDir, new Path(tempTableDir, hri.getEncodedName()));
      }

      // 5. Delete table from FS (temp directory)
      if (!HBaseFileSystem.deleteDirFromFileSystem(fs, tempTableDir)) {
        LOG.error("Couldn't delete " + tempTableDir);
      }
    } finally {
      // 6. Update table descriptor cache
      this.masterServices.getTableDescriptors().remove(Bytes.toString(tableName));

      // 7. If entry for this table in zk, and up in AssignmentManager, remove it.
      am.getZKTable().setDeletedTable(Bytes.toString(tableName));
      if (cpHost != null) {
        cpHost.postDeleteTableHandler(this.tableName);
      }
    }
  }
View Full Code Here

      throws IOException {
    LOG.info("Entering into postAssign of region " + regionInfo.getRegionNameAsString() + '.');

    if (false == regionInfo.getTableNameAsString().endsWith(Constants.INDEX_TABLE_SUFFIX)) {
      MasterServices master = ctx.getEnvironment().getMasterServices();
      AssignmentManager am = master.getAssignmentManager();
      // waiting until user region is removed from transition.
      long timeout =
          master.getConfiguration()
              .getLong("hbase.bulk.assignment.waiton.empty.rit", 5 * 60 * 1000);
      Set<HRegionInfo> regionSet = new HashSet<HRegionInfo>(1);
      regionSet.add(regionInfo);
      try {
        am.waitUntilNoRegionsInTransition(timeout, regionSet);
        am.waitForAssignment(regionInfo, timeout);
      } catch (InterruptedException e) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Interrupted while region in assignment.");
        }
      }
      ServerName sn = am.getRegionServerOfRegion(regionInfo);
      String indexTableName = IndexUtils.getIndexTableName(regionInfo.getTableNameAsString());
      List<HRegionInfo> tableRegions = am.getRegionsOfTable(Bytes.toBytes(indexTableName));
      for (HRegionInfo hRegionInfo : tableRegions) {
        if (0 == Bytes.compareTo(hRegionInfo.getStartKey(), regionInfo.getStartKey())) {
          am.addPlan(hRegionInfo.getEncodedName(), new RegionPlan(hRegionInfo, null, sn));
          LOG.info("Assigning region " + hRegionInfo.getRegionNameAsString() + " to server " + sn
              + '.');
          am.assign(hRegionInfo, true, false, false);
        }
      }
    }
    LOG.info("Exiting from postAssign " + regionInfo.getRegionNameAsString() + '.');
  }
View Full Code Here

  // Because the RIT map that is taken here is the copy of original RIT map and there is
  // no sync mechanism also.
  private boolean checkRegionInTransition(ObserverContext<MasterCoprocessorEnvironment> ctx,
      HRegionInfo hri) {
    MasterServices master = ctx.getEnvironment().getMasterServices();
    AssignmentManager am = master.getAssignmentManager();
    boolean isRegionInTransition = false;
    String tableName = hri.getTableNameAsString();
    if (false == IndexUtils.isIndexTable(tableName)) {
      NavigableMap<String, RegionState> regionsInTransition = am.getRegionsInTransition();
      RegionState regionState = regionsInTransition.get(hri.getEncodedName());
      if (regionState != null) {
        isRegionInTransition = true;
      } else {
        String indexTableName = IndexUtils.getIndexTableName(tableName);
View Full Code Here

  public void postMove(ObserverContext<MasterCoprocessorEnvironment> ctx, HRegionInfo regionInfo,
      ServerName srcServer, ServerName destServer) throws IOException {
    LOG.info("Entering into postMove " + regionInfo.getRegionNameAsString() + '.');
    if (false == regionInfo.getTableNameAsString().endsWith(Constants.INDEX_TABLE_SUFFIX)) {
      MasterServices master = ctx.getEnvironment().getMasterServices();
      AssignmentManager am = master.getAssignmentManager();
      // waiting until user region is removed from transition.
      long timeout =
          master.getConfiguration()
              .getLong("hbase.bulk.assignment.waiton.empty.rit", 5 * 60 * 1000);
      Set<HRegionInfo> regionSet = new HashSet<HRegionInfo>(1);
      regionSet.add(regionInfo);
      try {
        am.waitUntilNoRegionsInTransition(timeout, regionSet);
        am.waitForAssignment(regionInfo, timeout);
        destServer = am.getRegionServerOfRegion(regionInfo);
        am.putRegionPlan(regionInfo, destServer);
      } catch (InterruptedException e) {
        if (LOG.isDebugEnabled()) {
          LOG.debug("Interrupted while region in assignment.");
        }
      }
      String indexTableName = IndexUtils.getIndexTableName(regionInfo.getTableNameAsString());
      List<HRegionInfo> tableRegions = am.getRegionsOfTable(Bytes.toBytes(indexTableName));
      for (HRegionInfo indexRegionInfo : tableRegions) {
        if (0 == Bytes.compareTo(indexRegionInfo.getStartKey(), regionInfo.getStartKey())) {
          LOG.info("Assigning region " + indexRegionInfo.getRegionNameAsString() + "from "
              + srcServer + " to server " + destServer + '.');
          am.putRegionPlan(indexRegionInfo, destServer);
          am.addPlan(indexRegionInfo.getEncodedName(), new RegionPlan(indexRegionInfo, null,
              destServer));
          am.unassign(indexRegionInfo);
          /*
           * ((HMaster) master).move(indexRegionInfo.getEncodedNameAsBytes(),
           * Bytes.toBytes(destServer.getServerName()));
           */
        }
View Full Code Here

  @Override
  public void postDisableTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
      byte[] tableName) throws IOException {
    LOG.info("Entered into postDisableTableHandler of table " + Bytes.toString(tableName));
    MasterServices master = ctx.getEnvironment().getMasterServices();
    AssignmentManager am = master.getAssignmentManager();
    try {
      if (false == IndexUtils.isIndexTable(Bytes.toString(tableName))) {
        String indexTableName = IndexUtils.getIndexTableName(tableName);
        // Index table may not present following three cases.
        // 1) Index details are not specified during table creation then index table wont be
        // created.
        // 2) Even we specify index details if master restarted in the middle of user table creation
        // corresponding index table wont be created. But without creating index table user table
        // wont
        // be disabled. No need to call disable for index table at that time.
        // 3) Index table may be deleted but this wont happen without deleting user table.
        if (true == am.getZKTable().isTablePresent(indexTableName)) {
          long timeout =
              master.getConfiguration().getLong("hbase.bulk.assignment.waiton.empty.rit",
                5 * 60 * 1000);
          // Both user table and index table should not be in enabling/disabling state at a time.
          // If disable is progress for user table then index table should be in ENABLED state.
          // If enable is progress for index table wait until table enabled.
          waitUntilTableEnabled(timeout, indexTableName, am.getZKTable());
          if (waitUntilTableEnabled(timeout, indexTableName, am.getZKTable())) {
            new DisableTableHandler(master, Bytes.toBytes(indexTableName),
                master.getCatalogTracker(), am, false).process();
          } else {
            if (LOG.isDebugEnabled()) {
              LOG.debug("Table " + indexTableName + " not in ENABLED state to disable.");
View Full Code Here

  public void postEnableTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
      byte[] tableName) throws IOException {
    LOG.info("Entered into postEnableTableHandler of table " + Bytes.toString(tableName));
    if (false == IndexUtils.isIndexTable(Bytes.toString(tableName))) {
      MasterServices master = ctx.getEnvironment().getMasterServices();
      AssignmentManager am = master.getAssignmentManager();
      String indexTableName = IndexUtils.getIndexTableName(tableName);
      // Index table may not present in three cases
      // 1) Index details are not specified during table creation then index table wont be created.
      // 2) Even we specify index details if master restarted in the middle of user table creation
      // corresponding index table wont be created. Then no need to call enable for index table
      // because it will be created as part of preMasterInitialization and enable.
      // 3) Index table may be deleted but this wont happen without deleting user table.
      if (true == am.getZKTable().isTablePresent(indexTableName)) {
        long timeout =
            master.getConfiguration().getLong("hbase.bulk.assignment.waiton.empty.rit",
              5 * 60 * 1000);
        // Both user table and index table should not be in enabling/disabling state at a time.
        // If enable is progress for user table then index table should be in disabled state.
        // If disable is progress for index table wait until table disabled.
        if (waitUntilTableDisabled(timeout, indexTableName, am.getZKTable())) {
          new EnableTableHandler(master, Bytes.toBytes(indexTableName), master.getCatalogTracker(),
              am, false).process();
        } else {
          if (LOG.isDebugEnabled()) {
            LOG.debug("Table " + indexTableName + " not in DISABLED state to enable.");
View Full Code Here

  @Override
  public void preMasterInitialization(ObserverContext<MasterCoprocessorEnvironment> ctx)
      throws IOException {
    LOG.info("Entering into preMasterInitialization.");
    MasterServices master = ctx.getEnvironment().getMasterServices();
    AssignmentManager am = master.getAssignmentManager();
    ZKTable zkTable = am.getZKTable();
    long timeout =
        master.getConfiguration().getLong("hbase.bulk.assignment.waiton.empty.rit", 5 * 60 * 1000);
    try {
      am.waitUntilNoRegionsInTransition(timeout);
    } catch (InterruptedException e) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("Interrupted while waiting for the regions in transition to complete.", e);
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.master.AssignmentManager$CreateUnassignedAsyncCallback

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.