Package org.apache.hadoop.hbase.master

Examples of org.apache.hadoop.hbase.master.MasterServices


  @Override
  public void postModifyTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
      byte[] tableName, HTableDescriptor htd) throws IOException {
    String table = Bytes.toString(tableName);
    MasterServices master = ctx.getEnvironment().getMasterServices();
    List<Pair<HRegionInfo, ServerName>> tableRegionsAndLocations = null;
    LOG.info("Entering postModifyTable for the table " + table);
    if (htd instanceof IndexedHTableDescriptor) {
      TableDescriptors tableDescriptors = master.getTableDescriptors();
      Map<String, HTableDescriptor> allTableDesc = tableDescriptors.getAll();
      String indexTableName = IndexUtils.getIndexTableName(tableName);
      if (allTableDesc.containsKey(indexTableName)) {
        // Do table modification
        List<IndexSpecification> indices = ((IndexedHTableDescriptor) htd).getIndices();
        if (indices.isEmpty()) {
          LOG.error("Empty indices are passed to modify the table " + Bytes.toString(tableName));
          return;
        }
        IndexManager idxManager = IndexManager.getInstance();
        idxManager.removeIndices(table);
        idxManager.addIndexForTable(table, indices);
        LOG.info("Successfully updated the indexes for the table  " + table + " to " + indices);
      } else {
        try {
          tableRegionsAndLocations =
              MetaReader.getTableRegionsAndLocations(master.getCatalogTracker(), tableName, true);
        } catch (InterruptedException e) {
          LOG.error("Exception while trying to create index table for the existing table " + table);
          return;
        }
        if (tableRegionsAndLocations != null) {
View Full Code Here


  @Override
  public void postCreateTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
      HTableDescriptor desc, HRegionInfo[] regions) throws IOException {
    LOG.info("Entered into postCreateTableHandler of table " + desc.getNameAsString() + '.');
    if (desc instanceof IndexedHTableDescriptor) {
      MasterServices master = ctx.getEnvironment().getMasterServices();
      byte[][] splitKeys = IndexUtils.getSplitKeys(regions);
      // In case of post call for the index table creation, it wont be
      // IndexedHTableDescriptor
      IndexedHTableDescriptor iDesc = (IndexedHTableDescriptor) desc;
      createSecondaryIndexTable(iDesc, splitKeys, master, false);
View Full Code Here

  public void postAssign(ObserverContext<MasterCoprocessorEnvironment> ctx, HRegionInfo regionInfo)
      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);
View Full Code Here

  // will not be picked up.
  // 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());
View Full Code Here

  @Override
  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);
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

  @Override
  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 postDeleteTableHandler(ObserverContext<MasterCoprocessorEnvironment> ctx,
      byte[] tableName) throws IOException {
    LOG.info("Entered into postDeleteTableHandler of table " + Bytes.toString(tableName) + '.');
    MasterServices master = ctx.getEnvironment().getMasterServices();
    String indexTableName = IndexUtils.getIndexTableName(tableName);
    boolean indexTablePresent =
        master.getAssignmentManager().getZKTable().isTablePresent(indexTableName);
    // Not checking for disabled state because before deleting user table both user and index table
    // should be disabled.
    if ((false == IndexUtils.isIndexTable(Bytes.toString(tableName))) && indexTablePresent) {
      new DeleteTableHandler(Bytes.toBytes(indexTableName), master, master).process();
    }
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);
      }
    }

    TableDescriptors tableDescriptors = master.getTableDescriptors();
    Map<String, HTableDescriptor> descMap = tableDescriptors.getAll();
    Collection<HTableDescriptor> htds = descMap.values();
    IndexedHTableDescriptor iHtd = null;
    Configuration conf = master.getConfiguration();
    FileSystem fs = FSUtils.getCurrentFileSystem(conf);
    Path rootPath = FSUtils.getRootDir(conf);
    for (HTableDescriptor htd : htds) {
      if (false == htd.getNameAsString().endsWith(Constants.INDEX_TABLE_SUFFIX)) {
        FSDataInputStream fsDataInputStream = null;
        try {
          Path path = FSUtils.getTablePath(rootPath, htd.getName());
          FileStatus status = getTableInfoPath(fs, path);
          if (null == status) {
            return;
          }
          fsDataInputStream = fs.open(status.getPath());
          iHtd = new IndexedHTableDescriptor();
          iHtd.readFields(fsDataInputStream);
        } catch (EOFException e) {
          if (LOG.isDebugEnabled()) {
            LOG.debug(iHtd.getNameAsString() + " is normal table and not an indexed table.", e);
          }
        } catch (IOException i) {
          throw i;
        } finally {
          if (null != fsDataInputStream) {
            fsDataInputStream.close();
          }
        }
        if (false == iHtd.getIndices().isEmpty()) {
          String tableName = iHtd.getNameAsString();
          String indexTableName = IndexUtils.getIndexTableName(tableName);
          boolean tableExists = MetaReader.tableExists(master.getCatalogTracker(), tableName);
          boolean indexTableExists =
              MetaReader.tableExists(master.getCatalogTracker(), indexTableName);
          if ((true == tableExists) && (false == indexTableExists)) {
            LOG.info("Table has index specification details but " + "no corresponding index table.");
            List<HRegionInfo> regions =
                MetaReader.getTableRegions(master.getCatalogTracker(), iHtd.getName());
            HRegionInfo[] regionsArray = new HRegionInfo[regions.size()];
            byte[][] splitKeys = IndexUtils.getSplitKeys(regions.toArray(regionsArray));
            createSecondaryIndexTable(iHtd, splitKeys, master, false);
          } else if (true == tableExists && true == indexTableExists) {
            // If both tables are present both should be in same state in zookeeper. If tables are
            // partially enabled or disabled they will be processed as part of recovery
            // enabling/disabling tables.
            // if user table is in ENABLED state and index table is in DISABLED state means master
            // restarted as soon as user table enabled. So here we need to enable index table.
            if (zkTable.isEnabledTable(tableName) && zkTable.isDisabledTable(indexTableName)) {
              new EnableTableHandler(master, Bytes.toBytes(indexTableName),
                  master.getCatalogTracker(), am, false).process();
            } else if (zkTable.isDisabledTable(tableName) && zkTable.isEnabledTable(indexTableName)) {
              // If user table is in DISABLED state and index table is in ENABLED state means master
              // restarted as soon as user table disabled. So here we need to disable index table.
              new DisableTableHandler(master, Bytes.toBytes(indexTableName),
                  master.getCatalogTracker(), am, false).process();
              // clear index table region plans in secondary index load balancer.
              clearRegionPlans((HMaster) master, indexTableName);

            }
          }
        }
      }
    }
    if (LOG.isDebugEnabled()) {
      LOG.debug("Balancing after master initialization.");
    }

    try {
      master.getAssignmentManager().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

   * @param htd
   * @throws IOException
   */
  private void modifyTable(final byte [] tableName, final HTableDescriptor htd)
  throws IOException {
    MasterServices services = TEST_UTIL.getMiniHBaseCluster().getMaster();
    ExecutorService executor = services.getExecutorService();
    AtomicBoolean done = new AtomicBoolean(false);
    executor.registerListener(EventType.C_M_MODIFY_TABLE, new DoneListener(done));
    this.admin.modifyTable(tableName, htd);
    while (!done.get()) {
      synchronized (done) {
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hbase.master.MasterServices

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.