org.apache.hadoop.hbase.client.RegionInfo Java Examples

The following examples show how to use org.apache.hadoop.hbase.client.RegionInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RegionStateNode.java    From hbase with Apache License 2.0 6 votes vote down vote up
public void checkOnline() throws DoNotRetryRegionException {
  RegionInfo ri = getRegionInfo();
  State s = state;
  if (s != State.OPEN) {
    throw new DoNotRetryRegionException(ri.getEncodedName() + " is not OPEN; state=" + s);
  }
  if (ri.isSplitParent()) {
    throw new DoNotRetryRegionException(
      ri.getEncodedName() + " is not online (splitParent=true)");
  }
  if (ri.isSplit()) {
    throw new DoNotRetryRegionException(ri.getEncodedName() + " has split=true");
  }
  if (ri.isOffline()) {
    // RegionOfflineException is not instance of DNRIOE so wrap it.
    throw new DoNotRetryRegionException(new RegionOfflineException(ri.getEncodedName()));
  }
}
 
Example #2
Source File: RestoreSnapshotProcedure.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Add regions to in-memory states
 * @param regionInfos regions to add
 * @param env MasterProcedureEnv
 * @param regionReplication the number of region replications
 */
private void addRegionsToInMemoryStates(List<RegionInfo> regionInfos, MasterProcedureEnv env,
    int regionReplication) {
  AssignmentManager am = env.getAssignmentManager();
  for (RegionInfo regionInfo : regionInfos) {
    if (regionInfo.isSplit()) {
      am.getRegionStates().updateRegionState(regionInfo, RegionState.State.SPLIT);
    } else {
      am.getRegionStates().updateRegionState(regionInfo, RegionState.State.CLOSED);

      // For region replicas
      for (int i = 1; i < regionReplication; i++) {
        RegionInfo regionInfoForReplica =
            RegionReplicaUtil.getRegionInfoForReplica(regionInfo, i);
        am.getRegionStates().updateRegionState(regionInfoForReplica, RegionState.State.CLOSED);
      }
    }
  }
}
 
Example #3
Source File: BaseTestHBaseFsck.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Get region info from local cluster.
 */
Map<ServerName, List<String>> getDeployedHRIs(final Admin admin) throws IOException {
  ClusterMetrics status = admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS));
  Collection<ServerName> regionServers = status.getLiveServerMetrics().keySet();
  Map<ServerName, List<String>> mm = new HashMap<>();
  for (ServerName hsi : regionServers) {
    // list all online regions from this region server
    List<RegionInfo> regions = admin.getRegions(hsi);
    List<String> regionNames = new ArrayList<>(regions.size());
    for (RegionInfo hri : regions) {
      regionNames.add(hri.getRegionNameAsString());
    }
    mm.put(hsi, regionNames);
  }
  return mm;
}
 
Example #4
Source File: TestWALMonotonicallyIncreasingSeqId.java    From hbase with Apache License 2.0 6 votes vote down vote up
private HRegion initHRegion(TableDescriptor htd, byte[] startKey, byte[] stopKey, int replicaId)
    throws IOException {
  Configuration conf = TEST_UTIL.getConfiguration();
  conf.set("hbase.wal.provider", walProvider);
  conf.setBoolean("hbase.hregion.mvcc.preassign", false);
  Path tableDir = CommonFSUtils.getTableDir(testDir, htd.getTableName());

  RegionInfo info = RegionInfoBuilder.newBuilder(htd.getTableName()).setStartKey(startKey)
      .setEndKey(stopKey).setReplicaId(replicaId).setRegionId(0).build();
  fileSystem = tableDir.getFileSystem(conf);
  final Configuration walConf = new Configuration(conf);
  CommonFSUtils.setRootDir(walConf, tableDir);
  this.walConf = walConf;
  wals = new WALFactory(walConf, "log_" + replicaId);
  ChunkCreator.initialize(MemStoreLABImpl.CHUNK_SIZE_DEFAULT, false, 0, 0, 0, null);
  HRegion region = HRegion.createHRegion(info, TEST_UTIL.getDefaultRootDirPath(), conf, htd,
    wals.getWAL(info));
  return region;
}
 
Example #5
Source File: TestRSGroupBasedLoadBalancer.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Test the cluster startup bulk assignment which attempts to retain assignment info.
 */
@Test
public void testRetainAssignment() throws Exception {
  // Test simple case where all same servers are there
  Map<ServerName, List<RegionInfo>> currentAssignments = mockClusterServers();
  Map<RegionInfo, ServerName> inputForTest = new HashMap<>();
  for (ServerName sn : currentAssignments.keySet()) {
    for (RegionInfo region : currentAssignments.get(sn)) {
      inputForTest.put(region, sn);
    }
  }
  //verify region->null server assignment is handled
  inputForTest.put(randomRegions(1).get(0), null);
  Map<ServerName, List<RegionInfo>> newAssignment = loadBalancer
      .retainAssignment(inputForTest, servers);
  assertRetainedAssignment(inputForTest, servers, newAssignment);
}
 
Example #6
Source File: RegionsMerger.java    From hbase-operator-tools with Apache License 2.0 6 votes vote down vote up
private List<RegionInfo> getOpenRegions(Connection connection, TableName table) throws Exception {
  List<RegionInfo> regions = new ArrayList<>();
  Table metaTbl = connection.getTable(META_TABLE_NAME);
  String tblName = table.getNameAsString();
  RowFilter rowFilter = new RowFilter(CompareOperator.EQUAL,
    new SubstringComparator(tblName+","));
  SingleColumnValueFilter colFilter = new SingleColumnValueFilter(CATALOG_FAMILY,
    STATE_QUALIFIER, CompareOperator.EQUAL, Bytes.toBytes("OPEN"));
  Scan scan = new Scan();
  FilterList filter = new FilterList(FilterList.Operator.MUST_PASS_ALL);
  filter.addFilter(rowFilter);
  filter.addFilter(colFilter);
  scan.setFilter(filter);
  try(ResultScanner rs = metaTbl.getScanner(scan)){
    Result r;
    while ((r = rs.next()) != null) {
      RegionInfo region = RegionInfo.parseFrom(r.getValue(CATALOG_FAMILY, REGIONINFO_QUALIFIER));
      regions.add(region);
    }
  }
  return regions;
}
 
Example #7
Source File: TestSequenceIdMonotonicallyIncreasing.java    From hbase with Apache License 2.0 6 votes vote down vote up
private long getMaxSeqId(HRegionServer rs, RegionInfo region) throws IOException {
  Path walFile = ((AbstractFSWAL<?>) rs.getWAL(null)).getCurrentFileName();
  long maxSeqId = -1L;
  try (WAL.Reader reader =
    WALFactory.createReader(UTIL.getTestFileSystem(), walFile, UTIL.getConfiguration())) {
    for (;;) {
      WAL.Entry entry = reader.next();
      if (entry == null) {
        break;
      }
      if (Bytes.equals(region.getEncodedNameAsBytes(), entry.getKey().getEncodedRegionName())) {
        maxSeqId = Math.max(maxSeqId, entry.getKey().getSequenceId());
      }
    }
  }
  return maxSeqId;
}
 
Example #8
Source File: HMaster.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public long createSystemTable(final TableDescriptor tableDescriptor) throws IOException {
  if (isStopped()) {
    throw new MasterNotRunningException();
  }

  TableName tableName = tableDescriptor.getTableName();
  if (!(tableName.isSystemTable())) {
    throw new IllegalArgumentException(
      "Only system table creation can use this createSystemTable API");
  }

  RegionInfo[] newRegions = ModifyRegionUtils.createRegionInfos(tableDescriptor, null);

  LOG.info(getClientIdAuditPrefix() + " create " + tableDescriptor);

  // This special create table is called locally to master.  Therefore, no RPC means no need
  // to use nonce to detect duplicated RPC call.
  long procId = this.procedureExecutor.submitProcedure(
    new CreateTableProcedure(procedureExecutor.getEnvironment(), tableDescriptor, newRegions));

  return procId;
}
 
Example #9
Source File: NamespaceQuotaSnapshotStore.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public SpaceQuotaSnapshot getTargetState(
    String subject, SpaceQuota spaceQuota) throws IOException {
  rlock.lock();
  try {
    final long sizeLimitInBytes = spaceQuota.getSoftLimit();
    long sum = 0L;
    for (Entry<RegionInfo,Long> entry : filterBySubject(subject)) {
      sum += entry.getValue();
    }
    // Add in the size for any snapshots against this table
    sum += QuotaTableUtil.getNamespaceSnapshotSize(conn, subject);
    // Observance is defined as the size of the table being less than the limit
    SpaceQuotaStatus status = sum <= sizeLimitInBytes ? SpaceQuotaStatus.notInViolation()
        : new SpaceQuotaStatus(ProtobufUtil.toViolationPolicy(spaceQuota.getViolationPolicy()));
    return new SpaceQuotaSnapshot(status, sum, sizeLimitInBytes);
  } finally {
    rlock.unlock();
  }
}
 
Example #10
Source File: RSGroupableBalancerTestBase.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Generate a list of regions evenly distributed between the tables.
 *
 * @param numRegions The number of regions to be generated.
 * @return List of RegionInfo.
 */
protected List<RegionInfo> randomRegions(int numRegions) {
  List<RegionInfo> regions = new ArrayList<>(numRegions);
  byte[] start = new byte[16];
  byte[] end = new byte[16];
  rand.nextBytes(start);
  rand.nextBytes(end);
  int regionIdx = rand.nextInt(tables.length);
  for (int i = 0; i < numRegions; i++) {
    Bytes.putInt(start, 0, numRegions << 1);
    Bytes.putInt(end, 0, (numRegions << 1) + 1);
    int tableIndex = (i + regionIdx) % tables.length;
    regions.add(RegionInfoBuilder.newBuilder(tables[tableIndex])
        .setStartKey(start)
        .setEndKey(end)
        .setSplit(false)
        .setRegionId(regionId++)
        .build());
  }
  return regions;
}
 
Example #11
Source File: MetaTableAccessor.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a hbase:meta row for each of the specified new regions. Initial state for new regions is
 * CLOSED.
 * @param connection connection we're using
 * @param regionInfos region information list
 * @param ts desired timestamp
 * @throws IOException if problem connecting or updating meta
 */
private static void addRegionsToMeta(Connection connection, List<RegionInfo> regionInfos,
  int regionReplication, long ts) throws IOException {
  List<Put> puts = new ArrayList<>();
  for (RegionInfo regionInfo : regionInfos) {
    if (RegionReplicaUtil.isDefaultReplica(regionInfo)) {
      Put put = makePutFromRegionInfo(regionInfo, ts);
      // New regions are added with initial state of CLOSED.
      addRegionStateToPut(put, RegionState.State.CLOSED);
      // Add empty locations for region replicas so that number of replicas can be cached
      // whenever the primary region is looked up from meta
      for (int i = 1; i < regionReplication; i++) {
        addEmptyLocation(put, i);
      }
      puts.add(put);
    }
  }
  putsToMetaTable(connection, puts);
  LOG.info("Added {} regions to meta.", puts.size());
}
 
Example #12
Source File: TestHBCK2.java    From hbase-operator-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetRegionState() throws IOException {
  TEST_UTIL.createTable(REGION_STATES_TABLE_NAME, Bytes.toBytes("family1"));
  try (Admin admin = TEST_UTIL.getConnection().getAdmin()) {
    List<RegionInfo> regions = admin.getRegions(REGION_STATES_TABLE_NAME);
    RegionInfo info = regions.get(0);
    assertEquals(RegionState.State.OPEN, getCurrentRegionState(info));
    String region = info.getEncodedName();
    try (ClusterConnection connection = this.hbck2.connect()) {
      this.hbck2.setRegionState(connection, region, RegionState.State.CLOSING);
    }
    assertEquals(RegionState.State.CLOSING, getCurrentRegionState(info));
  } finally {
    TEST_UTIL.deleteTable(REGION_STATES_TABLE_NAME);
  }
}
 
Example #13
Source File: TestMergeTableRegionsProcedure.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testRecoveryAndDoubleExecution() throws Exception {
  final TableName tableName = TableName.valueOf("testRecoveryAndDoubleExecution");
  final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

  List<RegionInfo> tableRegions = createTable(tableName);

  ProcedureTestingUtility.waitNoProcedureRunning(procExec);
  ProcedureTestingUtility.setKillIfHasParent(procExec, false);
  ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);

  RegionInfo[] regionsToMerge = new RegionInfo[2];
  regionsToMerge[0] = tableRegions.get(0);
  regionsToMerge[1] = tableRegions.get(1);

  long procId = procExec.submitProcedure(
    new MergeTableRegionsProcedure(procExec.getEnvironment(), regionsToMerge, true));

  // Restart the executor and execute the step twice
  MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId);
  ProcedureTestingUtility.assertProcNotFailed(procExec, procId);

  assertRegionCount(tableName, initialRegionCount - 1);
}
 
Example #14
Source File: RequestConverter.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Create a protocol buffer UpdateFavoredNodesRequest to update a list of favorednode mappings
 * @param updateRegionInfos a list of favored node mappings
 * @return a protocol buffer UpdateFavoredNodesRequest
 */
public static UpdateFavoredNodesRequest buildUpdateFavoredNodesRequest(
    final List<Pair<RegionInfo, List<ServerName>>> updateRegionInfos) {
  UpdateFavoredNodesRequest.Builder ubuilder = UpdateFavoredNodesRequest.newBuilder();
  if (updateRegionInfos != null && !updateRegionInfos.isEmpty()) {
    RegionUpdateInfo.Builder builder = RegionUpdateInfo.newBuilder();
    for (Pair<RegionInfo, List<ServerName>> pair : updateRegionInfos) {
      builder.setRegion(ProtobufUtil.toRegionInfo(pair.getFirst()));
      for (ServerName server : pair.getSecond()) {
        builder.addFavoredNodes(ProtobufUtil.toServerName(server));
      }
      ubuilder.addUpdateInfo(builder.build());
      builder.clear();
    }
  }
  return ubuilder.build();
}
 
Example #15
Source File: TestCompactedHFilesDischarger.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
  TableName tableName = TableName.valueOf(getClass().getSimpleName());
  TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor =
    new TableDescriptorBuilder.ModifyableTableDescriptor(tableName);
  tableDescriptor.setColumnFamily(
    new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(fam));
  RegionInfo info = RegionInfoBuilder.newBuilder(tableName).build();
  Path path = testUtil.getDataTestDir(getClass().getSimpleName());
  region = HBaseTestingUtility.createRegionAndWAL(info, path,
    testUtil.getConfiguration(), tableDescriptor);
  rss = mock(RegionServerServices.class);
  List<HRegion> regions = new ArrayList<>(1);
  regions.add(region);
  Mockito.doReturn(regions).when(rss).getRegions();
}
 
Example #16
Source File: CatalogJanitor.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public boolean visit(Result r) {
  if (r == null || r.isEmpty()) {
    return true;
  }
  this.report.count++;
  RegionInfo regionInfo = null;
  try {
    regionInfo = metaTableConsistencyCheck(r);
  } catch(Throwable t) {
    LOG.warn("Failed consistency check on {}", Bytes.toStringBinary(r.getRow()), t);
  }
  if (regionInfo != null) {
    LOG.trace(regionInfo.toString());
    if (regionInfo.isSplitParent()) { // splitParent means split and offline.
      this.report.splitParents.put(regionInfo, r);
    }
    if (MetaTableAccessor.hasMergeRegions(r.rawCells())) {
      this.report.mergedRegions.put(regionInfo, r);
    }
  }
  // Returning true means "keep scanning"
  return true;
}
 
Example #17
Source File: TestCreateTableProcedure.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateWithoutColumnFamily() throws Exception {
  final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
  final TableName tableName = TableName.valueOf(name.getMethodName());
  // create table with 0 families will fail
  final TableDescriptorBuilder builder =
    TableDescriptorBuilder.newBuilder(MasterProcedureTestingUtility.createHTD(tableName));

  // disable sanity check
  builder.setValue(TableDescriptorChecker.TABLE_SANITY_CHECKS, Boolean.FALSE.toString());
  TableDescriptor htd = builder.build();
  final RegionInfo[] regions = ModifyRegionUtils.createRegionInfos(htd, null);

  long procId =
      ProcedureTestingUtility.submitAndWait(procExec,
          new CreateTableProcedure(procExec.getEnvironment(), htd, regions));
  final Procedure<?> result = procExec.getResult(procId);
  assertEquals(true, result.isFailed());
  Throwable cause = ProcedureTestingUtility.getExceptionCause(result);
  assertTrue("expected DoNotRetryIOException, got " + cause,
      cause instanceof DoNotRetryIOException);
}
 
Example #18
Source File: RegionMover.java    From hbase with Apache License 2.0 6 votes vote down vote up
private List<RegionInfo> readRegionsFromFile(String filename) throws IOException {
  List<RegionInfo> regions = new ArrayList<>();
  File f = new File(filename);
  if (!f.exists()) {
    return regions;
  }
  try (DataInputStream dis = new DataInputStream(
      new BufferedInputStream(new FileInputStream(f)))) {
    int numRegions = dis.readInt();
    int index = 0;
    while (index < numRegions) {
      regions.add(RegionInfo.parseFromOrNull(Bytes.readByteArray(dis)));
      index++;
    }
  } catch (IOException e) {
    LOG.error("Error while reading regions from file:" + filename, e);
    throw e;
  }
  return regions;
}
 
Example #19
Source File: TestHStoreFile.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testStoreFileReference() throws Exception {
  final RegionInfo hri =
    RegionInfoBuilder.newBuilder(TableName.valueOf("testStoreFileReference")).build();
  HRegionFileSystem regionFs = HRegionFileSystem.createRegionOnFileSystem(conf, fs,
    new Path(testDir, hri.getTable().getNameAsString()), hri);
  HFileContext meta = new HFileContextBuilder().withBlockSize(8 * 1024).build();

  // Make a store file and write data to it.
  StoreFileWriter writer = new StoreFileWriter.Builder(conf, cacheConf, this.fs)
    .withFilePath(regionFs.createTempName()).withFileContext(meta).build();
  writeStoreFile(writer);
  Path hsfPath = regionFs.commitStoreFile(TEST_FAMILY, writer.getPath());
  writer.close();

  HStoreFile file = new HStoreFile(this.fs, hsfPath, conf, cacheConf, BloomType.NONE, true);
  file.initReader();
  StoreFileReader r = file.getReader();
  assertNotNull(r);
  StoreFileScanner scanner =
    new StoreFileScanner(r, mock(HFileScanner.class), false, false, 0, 0, false);

  // Verify after instantiating scanner refCount is increased
  assertTrue("Verify file is being referenced", file.isReferencedInReads());
  scanner.close();
  // Verify after closing scanner refCount is decreased
  assertFalse("Verify file is not being referenced", file.isReferencedInReads());
}
 
Example #20
Source File: TestQuotaObserverChore.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testNumRegionsForTable() {
  TableName tn1 = TableName.valueOf("t1");
  TableName tn2 = TableName.valueOf("t2");
  TableName tn3 = TableName.valueOf("t3");

  final int numTable1Regions = 10;
  final int numTable2Regions = 15;
  final int numTable3Regions = 8;
  Map<RegionInfo,Long> regionReports = new HashMap<>();
  for (int i = 0; i < numTable1Regions; i++) {
    regionReports.put(RegionInfoBuilder.newBuilder(tn1)
        .setStartKey(Bytes.toBytes(i))
        .setEndKey(Bytes.toBytes(i + 1))
        .build(), 0L);
  }

  for (int i = 0; i < numTable2Regions; i++) {
    regionReports.put(RegionInfoBuilder.newBuilder(tn2)
        .setStartKey(Bytes.toBytes(i))
        .setEndKey(Bytes.toBytes(i + 1))
        .build(), 0L);
  }

  for (int i = 0; i < numTable3Regions; i++) {
    regionReports.put(RegionInfoBuilder.newBuilder(tn3)
        .setStartKey(Bytes.toBytes(i))
        .setEndKey(Bytes.toBytes(i + 1))
        .build(), 0L);
  }

  TableQuotaSnapshotStore store = new TableQuotaSnapshotStore(conn, chore, regionReports);
  when(chore.getTableSnapshotStore()).thenReturn(store);

  assertEquals(numTable1Regions, Iterables.size(store.filterBySubject(tn1)));
  assertEquals(numTable2Regions, Iterables.size(store.filterBySubject(tn2)));
  assertEquals(numTable3Regions, Iterables.size(store.filterBySubject(tn3)));
}
 
Example #21
Source File: RegionsMerger.java    From hbase-operator-tools with Apache License 2.0 5 votes vote down vote up
private boolean canMerge(Path path, RegionInfo region1, RegionInfo region2,
    Collection<Pair<RegionInfo, RegionInfo>> alreadyMerging) throws IOException {
  if(alreadyMerging.stream().anyMatch(regionPair ->
      region1.equals(regionPair.getFirst()) ||
      region2.equals(regionPair.getFirst()) ||
      region1.equals(regionPair.getSecond()) ||
      region2.equals(regionPair.getSecond()))){
    return false;
  }
  if (RegionInfo.areAdjacent(region1, region2)) {
    long size1 = sumSizeInFS(new Path(path, region1.getEncodedName()));
    long size2 = sumSizeInFS(new Path(path, region2.getEncodedName()));
    boolean mergeable = (resultSizeThreshold > (size1 + size2));
    if (!mergeable) {
      LOG.warn("Not merging regions {} and {} because resulting region size would get close to " +
          "the {} limit. {} total size: {}; {} total size:{}", region1.getEncodedName(),
        region2.getEncodedName(), resultSizeThreshold, region1.getEncodedName(), size1,
        region2.getEncodedName(), size2);
    }
    return mergeable;
  } else {
    LOG.warn(
      "WARNING: Can't merge regions {} and {} because those are not adjacent.",
      region1.getEncodedName(),
      region2.getEncodedName());
    return false;
  }
}
 
Example #22
Source File: RegionCoprocessorHost.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Supports Coprocessor 'bypass'.
 * @return true if default behavior should be bypassed, false otherwise
 * @deprecated Since hbase-2.0.0. No replacement. To be removed in hbase-3.0.0 and replaced
 * with something that doesn't expose IntefaceAudience.Private classes.
 */
@Deprecated
public boolean preWALRestore(final RegionInfo info, final WALKey logKey, final WALEdit logEdit)
    throws IOException {
  return execOperation(coprocEnvironments.isEmpty()? null:
      new RegionObserverOperationWithoutResult(true) {
    @Override
    public void call(RegionObserver observer) throws IOException {
      observer.preWALRestore(this, info, logKey, logEdit);
    }
  });
}
 
Example #23
Source File: BackupUtils.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Write the .regioninfo file on-disk.
 */
public static void writeRegioninfoOnFilesystem(final Configuration conf, final FileSystem fs,
    final Path regionInfoDir, RegionInfo regionInfo) throws IOException {
  final byte[] content = RegionInfo.toDelimitedByteArray(regionInfo);
  Path regionInfoFile = new Path(regionInfoDir, "." + HConstants.REGIONINFO_QUALIFIER_STR);
  // First check to get the permissions
  FsPermission perms = CommonFSUtils.getFilePermissions(fs, conf, HConstants.DATA_FILE_UMASK_KEY);
  // Write the RegionInfo file content
  FSDataOutputStream out = FSUtils.create(conf, fs, regionInfoFile, perms, null);
  try {
    out.write(content);
  } finally {
    out.close();
  }
}
 
Example #24
Source File: AssignmentManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Delete the region states. This is called by "DeleteTable"
 */
public void deleteTable(final TableName tableName) throws IOException {
  final ArrayList<RegionInfo> regions = regionStates.getTableRegionsInfo(tableName);
  regionStateStore.deleteRegions(regions);
  for (int i = 0; i < regions.size(); ++i) {
    final RegionInfo regionInfo = regions.get(i);
    // we expect the region to be offline
    regionStates.removeFromOfflineRegions(regionInfo);
    regionStates.deleteRegion(regionInfo);
  }
}
 
Example #25
Source File: CatalogJanitor.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the specified region has merge qualifiers, if so, try to clean them.
 * @return true if no info:merge* columns; i.e. the specified region doesn't have
 *   any merge qualifiers.
 */
public boolean cleanMergeQualifier(final RegionInfo region) throws IOException {
  // Get merge regions if it is a merged region and already has merge qualifier
  List<RegionInfo> parents = MetaTableAccessor.getMergeRegions(this.services.getConnection(),
      region.getRegionName());
  if (parents == null || parents.isEmpty()) {
    // It doesn't have merge qualifier, no need to clean
    return true;
  }

  // If a parent region is a merged child region and GC has not kicked in/finish its work yet,
  // return false in this case to avoid kicking in a merge, trying later.
  cleanMergeRegion(region, parents);
  return false;
}
 
Example #26
Source File: MetaTableAccessor.java    From hbase with Apache License 2.0 5 votes vote down vote up
public static Put addRegionInfo(final Put p, final RegionInfo hri) throws IOException {
  p.add(CellBuilderFactory.create(CellBuilderType.SHALLOW_COPY).setRow(p.getRow())
    .setFamily(HConstants.CATALOG_FAMILY).setQualifier(HConstants.REGIONINFO_QUALIFIER)
    .setTimestamp(p.getTimestamp()).setType(Type.Put)
    // Serialize the Default Replica HRI otherwise scan of hbase:meta
    // shows an info:regioninfo value with encoded name and region
    // name that differs from that of the hbase;meta row.
    .setValue(RegionInfo.toByteArray(RegionReplicaUtil.getRegionInfoForDefaultReplica(hri)))
    .build());
  return p;
}
 
Example #27
Source File: ExampleMasterObserverWithMetrics.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public void preCreateTable(ObserverContext<MasterCoprocessorEnvironment> ctx,
                           TableDescriptor desc, RegionInfo[] regions) throws IOException {
  // we rely on the fact that there is only 1 instance of our MasterObserver. We keep track of
  // when the operation starts before the operation is executing.
  this.createTableStartTime = System.currentTimeMillis();
}
 
Example #28
Source File: MultiTableSnapshotInputFormatImpl.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Return the list of splits extracted from the scans/snapshots pushed to conf by
 * {@link
 * #setInput(org.apache.hadoop.conf.Configuration, java.util.Map, org.apache.hadoop.fs.Path)}
 *
 * @param conf Configuration to determine splits from
 * @return Return the list of splits extracted from the scans/snapshots pushed to conf
 * @throws IOException
 */
public List<TableSnapshotInputFormatImpl.InputSplit> getSplits(Configuration conf)
    throws IOException {
  Path rootDir = CommonFSUtils.getRootDir(conf);
  FileSystem fs = rootDir.getFileSystem(conf);

  List<TableSnapshotInputFormatImpl.InputSplit> rtn = Lists.newArrayList();

  Map<String, Collection<Scan>> snapshotsToScans = getSnapshotsToScans(conf);
  Map<String, Path> snapshotsToRestoreDirs = getSnapshotDirs(conf);
  for (Map.Entry<String, Collection<Scan>> entry : snapshotsToScans.entrySet()) {
    String snapshotName = entry.getKey();

    Path restoreDir = snapshotsToRestoreDirs.get(snapshotName);

    SnapshotManifest manifest =
        TableSnapshotInputFormatImpl.getSnapshotManifest(conf, snapshotName, rootDir, fs);
    List<RegionInfo> regionInfos =
        TableSnapshotInputFormatImpl.getRegionInfosFromManifest(manifest);

    for (Scan scan : entry.getValue()) {
      List<TableSnapshotInputFormatImpl.InputSplit> splits =
          TableSnapshotInputFormatImpl.getSplits(scan, manifest, regionInfos, restoreDir, conf);
      rtn.addAll(splits);
    }
  }
  return rtn;
}
 
Example #29
Source File: TestWALObserver.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Coprocessors shouldn't get notice of empty waledits.
 */
@Test
public void testEmptyWALEditAreNotSeen() throws Exception {
  RegionInfo hri = createBasicHRegionInfo(Bytes.toString(TEST_TABLE));
  TableDescriptor htd = createBasic3FamilyHTD(Bytes.toString(TEST_TABLE));
  MultiVersionConcurrencyControl mvcc = new MultiVersionConcurrencyControl();
  NavigableMap<byte[], Integer> scopes = new TreeMap<>(Bytes.BYTES_COMPARATOR);
  for(byte[] fam : htd.getColumnFamilyNames()) {
    scopes.put(fam, 0);
  }
  WAL log = wals.getWAL(null);
  try {
    SampleRegionWALCoprocessor cp = getCoprocessor(log, SampleRegionWALCoprocessor.class);

    cp.setTestValues(TEST_TABLE, null, null, null, null, null, null, null);

    assertFalse(cp.isPreWALWriteCalled());
    assertFalse(cp.isPostWALWriteCalled());

    final long now = EnvironmentEdgeManager.currentTime();
    long txid = log.appendData(hri,
      new WALKeyImpl(hri.getEncodedNameAsBytes(), hri.getTable(), now, mvcc, scopes),
      new WALEdit());
    log.sync(txid);

    assertFalse("Empty WALEdit should skip coprocessor evaluation.", cp.isPreWALWriteCalled());
    assertFalse("Empty WALEdit should skip coprocessor evaluation.", cp.isPostWALWriteCalled());
  } finally {
    log.close();
  }
}
 
Example #30
Source File: TestModifyTableProcedure.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testRollbackAndDoubleExecutionOffline() throws Exception {
  final TableName tableName = TableName.valueOf(name.getMethodName());
  final String familyName = "cf2";
  final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();

  // create the table
  RegionInfo[] regions = MasterProcedureTestingUtility.createTable(
    procExec, tableName, null, "cf1");
  UTIL.getAdmin().disableTable(tableName);

  ProcedureTestingUtility.waitNoProcedureRunning(procExec);
  ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);

  TableDescriptor td = UTIL.getAdmin().getDescriptor(tableName);
  TableDescriptor newTd =
    TableDescriptorBuilder.newBuilder(td).setCompactionEnabled(!td.isCompactionEnabled())
      .setColumnFamily(ColumnFamilyDescriptorBuilder.of(familyName)).setRegionReplication(3)
      .build();

  // Start the Modify procedure && kill the executor
  long procId = procExec.submitProcedure(
    new ModifyTableProcedure(procExec.getEnvironment(), newTd));

  // Restart the executor and rollback the step twice
  int lastStep = 3; // failing before MODIFY_TABLE_UPDATE_TABLE_DESCRIPTOR
  MasterProcedureTestingUtility.testRollbackAndDoubleExecution(procExec, procId, lastStep);

  // cf2 should not be present
  MasterProcedureTestingUtility.validateTableCreation(UTIL.getHBaseCluster().getMaster(),
    tableName, regions, "cf1");
}