Java 类org.apache.hadoop.hbase.master.MasterCoprocessorHost 实例源码

项目:ditb    文件:ModifyColumnFamilyProcedure.java   
/**
 * Coprocessor Action.
 * @param env MasterProcedureEnv
 * @param state the procedure state
 * @throws IOException
 * @throws InterruptedException
 */
private void runCoprocessorAction(final MasterProcedureEnv env,
    final ModifyColumnFamilyState state) throws IOException, InterruptedException {
  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    user.doAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        switch (state) {
        case MODIFY_COLUMN_FAMILY_PRE_OPERATION:
          cpHost.preModifyColumnHandler(tableName, cfDescriptor);
          break;
        case MODIFY_COLUMN_FAMILY_POST_OPERATION:
          cpHost.postModifyColumnHandler(tableName, cfDescriptor);
          break;
        default:
          throw new UnsupportedOperationException(this + " unhandled state=" + state);
        }
        return null;
      }
    });
  }
}
项目:ditb    文件:CreateTableProcedure.java   
private void preCreate(final MasterProcedureEnv env)
    throws IOException, InterruptedException {
  if (!getTableName().isSystemTable()) {
    ProcedureSyncWait.getMasterQuotaManager(env)
      .checkNamespaceTableAndRegionQuota(getTableName(), newRegions.size());
  }

  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    final HRegionInfo[] regions = newRegions == null ? null :
      newRegions.toArray(new HRegionInfo[newRegions.size()]);
    user.doAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        cpHost.preCreateTableHandler(hTableDescriptor, regions);
        return null;
      }
    });
  }
}
项目:ditb    文件:DisableTableProcedure.java   
/**
 * Coprocessor Action.
 * @param env MasterProcedureEnv
 * @param state the procedure state
 * @throws IOException
 * @throws InterruptedException
 */
private void runCoprocessorAction(final MasterProcedureEnv env, final DisableTableState state)
    throws IOException, InterruptedException {
  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    user.doAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        switch (state) {
        case DISABLE_TABLE_PRE_OPERATION:
          cpHost.preDisableTableHandler(tableName);
          break;
        case DISABLE_TABLE_POST_OPERATION:
          cpHost.postDisableTableHandler(tableName);
          break;
        default:
          throw new UnsupportedOperationException(this + " unhandled state=" + state);
        }
        return null;
      }
    });
  }
}
项目:ditb    文件:AddColumnFamilyProcedure.java   
/**
 * Coprocessor Action.
 * @param env MasterProcedureEnv
 * @param state the procedure state
 * @throws IOException
 * @throws InterruptedException
 */
private void runCoprocessorAction(final MasterProcedureEnv env, final AddColumnFamilyState state)
    throws IOException, InterruptedException {
  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    user.doAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        switch (state) {
        case ADD_COLUMN_FAMILY_PRE_OPERATION:
          cpHost.preAddColumnHandler(tableName, cfDescriptor);
          break;
        case ADD_COLUMN_FAMILY_POST_OPERATION:
          cpHost.postAddColumnHandler(tableName, cfDescriptor);
          break;
        default:
          throw new UnsupportedOperationException(this + " unhandled state=" + state);
        }
        return null;
      }
    });
  }
}
项目:ditb    文件:EnableTableProcedure.java   
/**
 * Coprocessor Action.
 * @param env MasterProcedureEnv
 * @param state the procedure state
 * @throws IOException
 * @throws InterruptedException
 */
private void runCoprocessorAction(final MasterProcedureEnv env, final EnableTableState state)
    throws IOException, InterruptedException {
  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    user.doAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        switch (state) {
        case ENABLE_TABLE_PRE_OPERATION:
          cpHost.preEnableTableHandler(getTableName());
          break;
        case ENABLE_TABLE_POST_OPERATION:
          cpHost.postEnableTableHandler(getTableName());
          break;
        default:
          throw new UnsupportedOperationException(this + " unhandled state=" + state);
        }
        return null;
      }
    });
  }
}
项目:ditb    文件:DeleteColumnFamilyProcedure.java   
/**
 * Coprocessor Action.
 * @param env MasterProcedureEnv
 * @param state the procedure state
 * @throws IOException
 * @throws InterruptedException
 */
private void runCoprocessorAction(final MasterProcedureEnv env,
    final DeleteColumnFamilyState state) throws IOException, InterruptedException {
  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    user.doAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        switch (state) {
        case DELETE_COLUMN_FAMILY_PRE_OPERATION:
          cpHost.preDeleteColumnHandler(tableName, familyName);
          break;
        case DELETE_COLUMN_FAMILY_POST_OPERATION:
          cpHost.postDeleteColumnHandler(tableName, familyName);
          break;
        default:
          throw new UnsupportedOperationException(this + " unhandled state=" + state);
        }
        return null;
      }
    });
  }
}
项目:ditb    文件:ModifyTableProcedure.java   
/**
 * Coprocessor Action.
 * @param env MasterProcedureEnv
 * @param state the procedure state
 * @throws IOException
 * @throws InterruptedException
 */
private void runCoprocessorAction(final MasterProcedureEnv env, final ModifyTableState state)
    throws IOException, InterruptedException {
  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    user.doAs(new PrivilegedExceptionAction<Void>() {
      @Override
      public Void run() throws Exception {
        switch (state) {
        case MODIFY_TABLE_PRE_OPERATION:
          cpHost.preModifyTableHandler(getTableName(), modifiedHTableDescriptor);
          break;
        case MODIFY_TABLE_POST_OPERATION:
          cpHost.postModifyTableHandler(getTableName(), modifiedHTableDescriptor);
          break;
        default:
          throw new UnsupportedOperationException(this + " unhandled state=" + state);
        }
        return null;
      }
    });
  }
}
项目:ditb    文件:TestMasterObserver.java   
@Test (timeout=180000)
public void testStarted() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  assertTrue("Master should be active", master.isActiveMaster());
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  assertNotNull("CoprocessorHost should not be null", host);
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp);

  // check basic lifecycle
  assertTrue("MasterObserver should have been started", cp.wasStarted());
  assertTrue("preMasterInitialization() hook should have been called",
      cp.wasMasterInitializationCalled());
  assertTrue("postStartMaster() hook should have been called",
      cp.wasStartMasterCalled());
}
项目:ditb    文件:TestMasterObserver.java   
@Test (timeout=180000)
public void testTableDescriptorsEnumeration() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  cp.resetStates();

  GetTableDescriptorsRequest req =
      RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null);
  master.getMasterRpcServices().getTableDescriptors(null, req);

  assertTrue("Coprocessor should be called on table descriptors request",
    cp.wasGetTableDescriptorsCalled());
}
项目:LCIndex-HBase-0.94.16    文件:TestMasterObserver.java   
@Test
public void testStarted() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  assertTrue("Master should be active", master.isActiveMaster());
  MasterCoprocessorHost host = master.getCoprocessorHost();
  assertNotNull("CoprocessorHost should not be null", host);
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp);

  // check basic lifecycle
  assertTrue("MasterObserver should have been started", cp.wasStarted());
  assertTrue("postStartMaster() hook should have been called",
      cp.wasStartMasterCalled());
}
项目:pbase    文件:ModifyTableHandler.java   
@Override
protected void handleTableOperation(List<HRegionInfo> hris)
throws IOException {
  MasterCoprocessorHost cpHost = ((HMaster) this.server).getMasterCoprocessorHost();
  if (cpHost != null) {
    cpHost.preModifyTableHandler(this.tableName, this.htd);
  }
  // Update descriptor
  HTableDescriptor oldHtd = getTableDescriptor();
  this.masterServices.getTableDescriptors().add(this.htd);
  deleteFamilyFromFS(hris, oldHtd.getFamiliesKeys());
  removeReplicaColumnsIfNeeded(this.htd.getRegionReplication(), oldHtd.getRegionReplication(),
      htd.getTableName());
  if (cpHost != null) {
    cpHost.postModifyTableHandler(this.tableName, this.htd);
  }
}
项目:pbase    文件:TableDeleteFamilyHandler.java   
@Override
protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
  MasterCoprocessorHost cpHost = ((HMaster) this.server)
      .getMasterCoprocessorHost();
  if (cpHost != null) {
    cpHost.preDeleteColumnHandler(this.tableName, this.familyName);
  }
  // Update table descriptor
  this.masterServices.getMasterFileSystem().deleteColumn(tableName, familyName);
  // Remove the column family from the file system
  MasterFileSystem mfs = this.masterServices.getMasterFileSystem();
  for (HRegionInfo hri : hris) {
    // Delete the family directory in FS for all the regions one by one
    mfs.deleteFamilyFromFS(hri, familyName);
  }
  if (cpHost != null) {
    cpHost.postDeleteColumnHandler(this.tableName, this.familyName);
  }
}
项目:pbase    文件:TruncateTableHandler.java   
@Override
protected void handleTableOperation(List<HRegionInfo> regions)
    throws IOException, CoordinatedStateException {
  MasterCoprocessorHost cpHost = ((HMaster) this.server).getMasterCoprocessorHost();
  if (cpHost != null) {
    cpHost.preTruncateTableHandler(this.tableName);
  }

  // 1. Wait because of region in transition
  waitRegionInTransition(regions);

  // 2. Remove table from hbase:meta and HDFS
  removeTableData(regions);

  // -----------------------------------------------------------------------
  // PONR: At this point the table is deleted.
  //       If the recreate fails, the user can only re-create the table.
  // -----------------------------------------------------------------------

  // 3. Recreate the regions
  recreateTable(regions);

  if (cpHost != null) {
    cpHost.postTruncateTableHandler(this.tableName);
  }
}
项目:pbase    文件:CreateTableHandler.java   
@Override
public void process() {
  TableName tableName = this.hTableDescriptor.getTableName();
  LOG.info("Create table " + tableName);

  try {
    final MasterCoprocessorHost cpHost = ((HMaster) this.server).getMasterCoprocessorHost();
    if (cpHost != null) {
      cpHost.preCreateTableHandler(this.hTableDescriptor, this.newRegions);
    }
    handleCreateTable(tableName);
    completed(null);
    if (cpHost != null) {
      this.activeUser.runAs(new PrivilegedExceptionAction<Void>() {
        @Override
        public Void run() throws Exception {
          cpHost.postCreateTableHandler(hTableDescriptor, newRegions);
          return null;
        }
      });
    }
  } catch (Throwable e) {
    LOG.error("Error trying to create the table " + tableName, e);
    completed(e);
  }
}
项目:pbase    文件:TestMasterObserver.java   
@Test
public void testStarted() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  assertTrue("Master should be active", master.isActiveMaster());
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  assertNotNull("CoprocessorHost should not be null", host);
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp);

  // check basic lifecycle
  assertTrue("MasterObserver should have been started", cp.wasStarted());
  assertTrue("preMasterInitialization() hook should have been called",
      cp.wasMasterInitializationCalled());
  assertTrue("postStartMaster() hook should have been called",
      cp.wasStartMasterCalled());
}
项目:pbase    文件:TestMasterObserver.java   
@Test
public void testTableDescriptorsEnumeration() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  cp.resetStates();

  GetTableDescriptorsRequest req =
      RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null);
  master.getMasterRpcServices().getTableDescriptors(null, req);

  assertTrue("Coprocessor should be called on table descriptors request",
    cp.wasGetTableDescriptorsCalled());
}
项目:HIndex    文件:TableDeleteFamilyHandler.java   
@Override
protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
  MasterCoprocessorHost cpHost = ((HMaster) this.server)
      .getCoprocessorHost();
  if (cpHost != null) {
    cpHost.preDeleteColumnHandler(this.tableName, this.familyName);
  }
  // Update table descriptor
  this.masterServices.getMasterFileSystem().deleteColumn(tableName, familyName);
  // Remove the column family from the file system
  MasterFileSystem mfs = this.masterServices.getMasterFileSystem();
  for (HRegionInfo hri : hris) {
    // Delete the family directory in FS for all the regions one by one
    mfs.deleteFamilyFromFS(hri, familyName);
  }
  if (cpHost != null) {
    cpHost.postDeleteColumnHandler(this.tableName, this.familyName);
  }
}
项目:HIndex    文件:CreateTableHandler.java   
@Override
public void process() {
  TableName tableName = this.hTableDescriptor.getTableName();
  LOG.info("Create table " + tableName);

  try {
    MasterCoprocessorHost cpHost = ((HMaster) this.server).getCoprocessorHost();
    if (cpHost != null) {
      cpHost.preCreateTableHandler(this.hTableDescriptor, this.newRegions);
    }
    handleCreateTable(tableName);
    completed(null);
    if (cpHost != null) {
      cpHost.postCreateTableHandler(this.hTableDescriptor, this.newRegions);
    }
  } catch (Throwable e) {
    LOG.error("Error trying to create the table " + tableName, e);
    completed(e);
  }
}
项目:HIndex    文件:TestMasterObserver.java   
@Test
public void testStarted() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  assertTrue("Master should be active", master.isActiveMaster());
  MasterCoprocessorHost host = master.getCoprocessorHost();
  assertNotNull("CoprocessorHost should not be null", host);
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp);

  // check basic lifecycle
  assertTrue("MasterObserver should have been started", cp.wasStarted());
  assertTrue("preMasterInitialization() hook should have been called",
      cp.wasMasterInitializationCalled());
  assertTrue("postStartMaster() hook should have been called",
      cp.wasStartMasterCalled());
}
项目:HIndex    文件:TestMasterObserver.java   
@Test
public void testTableDescriptorsEnumeration() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  MasterCoprocessorHost host = master.getCoprocessorHost();
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  cp.resetStates();

  GetTableDescriptorsRequest req =
      RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null);
  master.getTableDescriptors(null, req);

  assertTrue("Coprocessor should be called on table descriptors request",
    cp.wasGetTableDescriptorsCalled());
}
项目:IRIndex    文件:TestMasterObserver.java   
@Test
public void testStarted() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  assertTrue("Master should be active", master.isActiveMaster());
  MasterCoprocessorHost host = master.getCoprocessorHost();
  assertNotNull("CoprocessorHost should not be null", host);
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp);

  // check basic lifecycle
  assertTrue("MasterObserver should have been started", cp.wasStarted());
  assertTrue("postStartMaster() hook should have been called",
      cp.wasStartMasterCalled());
}
项目:hbase    文件:MergeTableRegionsProcedure.java   
/**
 * Post merge region action
 * @param env MasterProcedureEnv
 **/
private void preMergeRegionsCommit(final MasterProcedureEnv env) throws IOException {
  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    @MetaMutationAnnotation
    final List<Mutation> metaEntries = new ArrayList<Mutation>();
    cpHost.preMergeRegionsCommit(regionsToMerge, metaEntries, getUser());
    try {
      for (Mutation p : metaEntries) {
        RegionInfo.parseRegionName(p.getRow());
      }
    } catch (IOException e) {
      LOG.error("Row key of mutation from coprocessor is not parsable as region name."
        + "Mutations from coprocessor should only be for hbase:meta table.", e);
      throw e;
    }
  }
}
项目:hbase    文件:SplitTableRegionProcedure.java   
/**
 * Action before splitting region in a table.
 * @param env MasterProcedureEnv
 * @throws IOException
 * @throws InterruptedException
 */
private void preSplitRegion(final MasterProcedureEnv env)
    throws IOException, InterruptedException {
  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    cpHost.preSplitRegionAction(getTableName(), getSplitRow(), getUser());
  }

  // TODO: Clean up split and merge. Currently all over the place.
  // Notify QuotaManager and RegionNormalizer
  try {
    env.getMasterServices().getMasterQuotaManager().onRegionSplit(this.getParentRegion());
  } catch (QuotaExceededException e) {
    env.getAssignmentManager().getRegionNormalizer().planSkipped(this.getParentRegion(),
        NormalizationPlan.PlanType.SPLIT);
    throw e;
  }
}
项目:hbase    文件:SplitTableRegionProcedure.java   
/**
 * Post split region actions before the Point-of-No-Return step
 * @param env MasterProcedureEnv
 **/
private void preSplitRegionBeforeMETA(final MasterProcedureEnv env)
    throws IOException, InterruptedException {
  final List<Mutation> metaEntries = new ArrayList<Mutation>();
  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    cpHost.preSplitBeforeMETAAction(getSplitRow(), metaEntries, getUser());
    try {
      for (Mutation p : metaEntries) {
        RegionInfo.parseRegionName(p.getRow());
      }
    } catch (IOException e) {
      LOG.error("pid=" + getProcId() + " row key of mutation from coprocessor not parsable as "
          + "region name."
          + "Mutations from coprocessor should only for hbase:meta table.");
      throw e;
    }
  }
}
项目:hbase    文件:DisableTableProcedure.java   
/**
 * Coprocessor Action.
 * @param env MasterProcedureEnv
 * @param state the procedure state
 * @throws IOException
 * @throws InterruptedException
 */
private void runCoprocessorAction(final MasterProcedureEnv env, final DisableTableState state)
    throws IOException, InterruptedException {
  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    switch (state) {
      case DISABLE_TABLE_PRE_OPERATION:
        cpHost.preDisableTableAction(tableName, getUser());
        break;
      case DISABLE_TABLE_POST_OPERATION:
        cpHost.postCompletedDisableTableAction(tableName, getUser());
        break;
      default:
        throw new UnsupportedOperationException(this + " unhandled state=" + state);
    }
  }
}
项目:hbase    文件:CloneSnapshotProcedure.java   
/**
 * Action before cloning from snapshot.
 * @param env MasterProcedureEnv
 * @throws IOException
 * @throws InterruptedException
 */
private void preCloneSnapshot(final MasterProcedureEnv env)
    throws IOException, InterruptedException {
  if (!getTableName().isSystemTable()) {
    // Check and update namespace quota
    final MasterFileSystem mfs = env.getMasterServices().getMasterFileSystem();

    SnapshotManifest manifest = SnapshotManifest.open(
      env.getMasterConfiguration(),
      mfs.getFileSystem(),
      SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshot, mfs.getRootDir()),
      snapshot);

    ProcedureSyncWait.getMasterQuotaManager(env)
      .checkNamespaceTableAndRegionQuota(getTableName(), manifest.getRegionManifestsMap().size());
  }

  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    cpHost.preCreateTableAction(tableDescriptor, null, getUser());
  }
}
项目:hbase    文件:EnableTableProcedure.java   
/**
 * Coprocessor Action.
 * @param env MasterProcedureEnv
 * @param state the procedure state
 * @throws IOException
 * @throws InterruptedException
 */
private void runCoprocessorAction(final MasterProcedureEnv env, final EnableTableState state)
    throws IOException, InterruptedException {
  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    switch (state) {
      case ENABLE_TABLE_PRE_OPERATION:
        cpHost.preEnableTableAction(getTableName(), getUser());
        break;
      case ENABLE_TABLE_POST_OPERATION:
        cpHost.postCompletedEnableTableAction(getTableName(), getUser());
        break;
      default:
        throw new UnsupportedOperationException(this + " unhandled state=" + state);
    }
  }
}
项目:hbase    文件:ModifyTableProcedure.java   
/**
 * Coprocessor Action.
 * @param env MasterProcedureEnv
 * @param state the procedure state
 * @throws IOException
 * @throws InterruptedException
 */
private void runCoprocessorAction(final MasterProcedureEnv env, final ModifyTableState state)
    throws IOException, InterruptedException {
  final MasterCoprocessorHost cpHost = env.getMasterCoprocessorHost();
  if (cpHost != null) {
    switch (state) {
      case MODIFY_TABLE_PRE_OPERATION:
        cpHost.preModifyTableAction(getTableName(), modifiedTableDescriptor, getUser());
        break;
      case MODIFY_TABLE_POST_OPERATION:
        cpHost.postCompletedModifyTableAction(getTableName(), modifiedTableDescriptor,getUser());
        break;
      default:
        throw new UnsupportedOperationException(this + " unhandled state=" + state);
    }
  }
}
项目:hbase    文件:SnapshotManager.java   
/**
 * Clone the specified snapshot.
 * The clone will fail if the destination table has a snapshot or restore in progress.
 *
 * @param reqSnapshot Snapshot Descriptor from request
 * @param tableName table to clone
 * @param snapshot Snapshot Descriptor
 * @param snapshotTableDesc Table Descriptor
 * @param nonceKey unique identifier to prevent duplicated RPC
 * @return procId the ID of the clone snapshot procedure
 * @throws IOException
 */
private long cloneSnapshot(final SnapshotDescription reqSnapshot, final TableName tableName,
    final SnapshotDescription snapshot, final TableDescriptor snapshotTableDesc,
    final NonceKey nonceKey, final boolean restoreAcl) throws IOException {
  MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost();
  TableDescriptor htd = TableDescriptorBuilder.copy(tableName, snapshotTableDesc);
  org.apache.hadoop.hbase.client.SnapshotDescription snapshotPOJO = null;
  if (cpHost != null) {
    snapshotPOJO = ProtobufUtil.createSnapshotDesc(reqSnapshot);
    cpHost.preCloneSnapshot(snapshotPOJO, htd);
  }
  long procId;
  try {
    procId = cloneSnapshot(snapshot, htd, nonceKey, restoreAcl);
  } catch (IOException e) {
    LOG.error("Exception occurred while cloning the snapshot " + snapshot.getName()
      + " as table " + tableName.getNameAsString(), e);
    throw e;
  }
  LOG.info("Clone snapshot=" + snapshot.getName() + " as table=" + tableName);

  if (cpHost != null) {
    cpHost.postCloneSnapshot(snapshotPOJO, htd);
  }
  return procId;
}
项目:hbase    文件:TestSnapshotWithAcl.java   
@BeforeClass
public static void setupBeforeClass() throws Exception {
  conf = TEST_UTIL.getConfiguration();
  // Enable security
  enableSecurity(conf);
  conf.set(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, AccessController.class.getName());
  // Verify enableSecurity sets up what we require
  verifyConfiguration(conf);
  // Enable EXEC permission checking
  conf.setBoolean(AccessControlConstants.EXEC_PERMISSION_CHECKS_KEY, true);
  TEST_UTIL.startMiniCluster();
  TEST_UTIL.waitUntilAllRegionsAssigned(AccessControlLists.ACL_TABLE_NAME);
  MasterCoprocessorHost cpHost =
      TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterCoprocessorHost();
  cpHost.load(AccessController.class, Coprocessor.PRIORITY_HIGHEST, conf);

  USER_OWNER = User.createUserForTesting(conf, "owner", new String[0]);
  USER_RW = User.createUserForTesting(conf, "rwuser", new String[0]);
  USER_RO = User.createUserForTesting(conf, "rouser", new String[0]);
  USER_NONE = User.createUserForTesting(conf, "usernone", new String[0]);
}
项目:hbase    文件:TestMasterObserver.java   
@Test (timeout=180000)
public void testStarted() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  assertTrue("Master should be active", master.isActiveMaster());
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  assertNotNull("CoprocessorHost should not be null", host);
  CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
  assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp);

  // check basic lifecycle
  assertTrue("MasterObserver should have been started", cp.wasStarted());
  assertTrue("preMasterInitialization() hook should have been called",
      cp.wasMasterInitializationCalled());
  assertTrue("postStartMaster() hook should have been called",
      cp.wasStartMasterCalled());
}
项目:hbase    文件:TestMasterObserver.java   
@Test (timeout=180000)
public void testNamespaceOperations() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();
  String testNamespace = "observed_ns";
  HMaster master = cluster.getMaster();
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);

  // create a table
  Admin admin = UTIL.getAdmin();
  admin.createNamespace(NamespaceDescriptor.create(testNamespace).build());
  assertTrue("Test namespace should be created", cp.wasCreateNamespaceCalled());

  assertNotNull(admin.getNamespaceDescriptor(testNamespace));
  assertTrue("Test namespace descriptor should have been called",
      cp.wasGetNamespaceDescriptorCalled());
  // This test used to do a bunch w/ bypass but bypass of these table and namespace stuff has
  // been removed so the testing code was removed.
}
项目:hbase    文件:TestMasterObserver.java   
@Test (timeout=180000)
public void testTableDescriptorsEnumeration() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class);
  cp.resetStates();

  GetTableDescriptorsRequest req =
      RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null);
  master.getMasterRpcServices().getTableDescriptors(null, req);

  assertTrue("Coprocessor should be called on table descriptors request",
    cp.wasGetTableDescriptorsCalled());
}
项目:PyroDB    文件:TableDeleteFamilyHandler.java   
@Override
protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
  MasterCoprocessorHost cpHost = ((HMaster) this.server)
      .getMasterCoprocessorHost();
  if (cpHost != null) {
    cpHost.preDeleteColumnHandler(this.tableName, this.familyName);
  }
  // Update table descriptor
  this.masterServices.getMasterFileSystem().deleteColumn(tableName, familyName);
  // Remove the column family from the file system
  MasterFileSystem mfs = this.masterServices.getMasterFileSystem();
  for (HRegionInfo hri : hris) {
    // Delete the family directory in FS for all the regions one by one
    mfs.deleteFamilyFromFS(hri, familyName);
  }
  if (cpHost != null) {
    cpHost.postDeleteColumnHandler(this.tableName, this.familyName);
  }
}
项目:PyroDB    文件:TruncateTableHandler.java   
@Override
protected void handleTableOperation(List<HRegionInfo> regions)
    throws IOException, CoordinatedStateException {
  MasterCoprocessorHost cpHost = ((HMaster) this.server).getMasterCoprocessorHost();
  if (cpHost != null) {
    cpHost.preTruncateTableHandler(this.tableName);
  }

  // 1. Wait because of region in transition
  waitRegionInTransition(regions);

  // 2. Remove table from .META. and HDFS
  removeTableData(regions);

  // -----------------------------------------------------------------------
  // PONR: At this point the table is deleted.
  //       If the recreate fails, the user can only re-create the table.
  // -----------------------------------------------------------------------

  // 3. Recreate the regions
  recreateTable(regions);

  if (cpHost != null) {
    cpHost.postTruncateTableHandler(this.tableName);
  }
}
项目:PyroDB    文件:CreateTableHandler.java   
@Override
public void process() {
  TableName tableName = this.hTableDescriptor.getTableName();
  LOG.info("Create table " + tableName);

  try {
    MasterCoprocessorHost cpHost = ((HMaster) this.server).getMasterCoprocessorHost();
    if (cpHost != null) {
      cpHost.preCreateTableHandler(this.hTableDescriptor, this.newRegions);
    }
    handleCreateTable(tableName);
    completed(null);
    if (cpHost != null) {
      cpHost.postCreateTableHandler(this.hTableDescriptor, this.newRegions);
    }
  } catch (Throwable e) {
    LOG.error("Error trying to create the table " + tableName, e);
    completed(e);
  }
}
项目:PyroDB    文件:TestMasterObserver.java   
@Test
public void testStarted() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  assertTrue("Master should be active", master.isActiveMaster());
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  assertNotNull("CoprocessorHost should not be null", host);
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp);

  // check basic lifecycle
  assertTrue("MasterObserver should have been started", cp.wasStarted());
  assertTrue("preMasterInitialization() hook should have been called",
      cp.wasMasterInitializationCalled());
  assertTrue("postStartMaster() hook should have been called",
      cp.wasStartMasterCalled());
}
项目:PyroDB    文件:TestMasterObserver.java   
@Test
public void testTableDescriptorsEnumeration() throws Exception {
  MiniHBaseCluster cluster = UTIL.getHBaseCluster();

  HMaster master = cluster.getMaster();
  MasterCoprocessorHost host = master.getMasterCoprocessorHost();
  CPMasterObserver cp = (CPMasterObserver)host.findCoprocessor(
      CPMasterObserver.class.getName());
  cp.resetStates();

  GetTableDescriptorsRequest req =
      RequestConverter.buildGetTableDescriptorsRequest((List<TableName>)null);
  master.getMasterRpcServices().getTableDescriptors(null, req);

  assertTrue("Coprocessor should be called on table descriptors request",
    cp.wasGetTableDescriptorsCalled());
}
项目:c5    文件:TableDeleteFamilyHandler.java   
@Override
protected void handleTableOperation(List<HRegionInfo> hris) throws IOException {
  MasterCoprocessorHost cpHost = ((HMaster) this.server)
      .getCoprocessorHost();
  if (cpHost != null) {
    cpHost.preDeleteColumnHandler(this.tableName, this.familyName);
  }
  // Update table descriptor
  this.masterServices.getMasterFileSystem().deleteColumn(tableName, familyName);
  // Remove the column family from the file system
  MasterFileSystem mfs = this.masterServices.getMasterFileSystem();
  for (HRegionInfo hri : hris) {
    // Delete the family directory in FS for all the regions one by one
    mfs.deleteFamilyFromFS(hri, familyName);
  }
  if (cpHost != null) {
    cpHost.postDeleteColumnHandler(this.tableName, this.familyName);
  }
}
项目:c5    文件:CreateTableHandler.java   
@Override
public void process() {
  TableName tableName = this.hTableDescriptor.getTableName();
  LOG.info("Create table " + tableName);

  try {
    MasterCoprocessorHost cpHost = ((HMaster) this.server).getCoprocessorHost();
    if (cpHost != null) {
      cpHost.preCreateTableHandler(this.hTableDescriptor, this.newRegions);
    }
    handleCreateTable(tableName);
    completed(null);
    if (cpHost != null) {
      cpHost.postCreateTableHandler(this.hTableDescriptor, this.newRegions);
    }
  } catch (Throwable e) {
    LOG.error("Error trying to create the table " + tableName, e);
    completed(e);
  }
}