Java Code Examples for org.apache.hadoop.hbase.client.RegionInfo#getEncodedName()

The following examples show how to use org.apache.hadoop.hbase.client.RegionInfo#getEncodedName() . 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: TestFsRegionsMetaRecoverer.java    From hbase-operator-tools with Apache License 2.0 6 votes vote down vote up
@Test
public void testPutRegionInfoFromHdfsInMeta() throws Exception {
  RegionInfo info = this.createRegionInfo("test-tbl");
  Path regionPath = new Path("/hbase/data/default/test-tbl/" + info.getEncodedName());
  FSDataInputStream fis = new FSDataInputStream(new TestInputStreamSeekable(info));
  when(this.mockedFileSystem.open(new Path(regionPath, ".regioninfo")))
    .thenReturn(fis);
  fixer.putRegionInfoFromHdfsInMeta(regionPath);
  Mockito.verify(this.mockedConnection).getTable(TableName.META_TABLE_NAME);
  ArgumentCaptor<Put> captor = ArgumentCaptor.forClass(Put.class);
  Mockito.verify(this.mockedTable).put(captor.capture());
  Put capturedPut = captor.getValue();
  List<Cell> cells = capturedPut.get(HConstants.CATALOG_FAMILY,
    HConstants.STATE_QUALIFIER);
  assertEquals(1, cells.size());
  String state = Bytes.toString(cells.get(0).getValueArray(),
    cells.get(0).getValueOffset(), cells.get(0).getValueLength());
  assertEquals(RegionState.State.valueOf(state), RegionState.State.CLOSED);
  cells = capturedPut.get(HConstants.CATALOG_FAMILY,
    HConstants.REGIONINFO_QUALIFIER);
  byte[] returnedInfo = Bytes.copy(cells.get(0).getValueArray(),
    cells.get(0).getValueOffset(), cells.get(0).getValueLength());
  assertEquals(info, RegionInfo.parseFrom(returnedInfo));
}
 
Example 2
Source File: HRegionFileSystem.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Write out a merge reference under the given merges directory. Package local
 * so it doesnt leak out of regionserver.
 * @param mergedRegion {@link RegionInfo} of the merged region
 * @param familyName Column Family Name
 * @param f File to create reference.
 * @param mergedDir
 * @return Path to created reference.
 * @throws IOException
 */
public Path mergeStoreFile(RegionInfo mergedRegion, String familyName, HStoreFile f,
    Path mergedDir) throws IOException {
  Path referenceDir = new Path(new Path(mergedDir,
      mergedRegion.getEncodedName()), familyName);
  // A whole reference to the store file.
  Reference r = Reference.createTopReference(regionInfoForFs.getStartKey());
  // Add the referred-to regions name as a dot separated suffix.
  // See REF_NAME_REGEX regex above. The referred-to regions name is
  // up in the path of the passed in <code>f</code> -- parentdir is family,
  // then the directory above is the region name.
  String mergingRegionName = regionInfoForFs.getEncodedName();
  // Write reference with same file id only with the other region name as
  // suffix and into the new region location (under same family).
  Path p = new Path(referenceDir, f.getPath().getName() + "."
      + mergingRegionName);
  return r.write(fs, p);
}
 
Example 3
Source File: HRegionFileSystem.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Commit a daughter region, moving it from the split temporary directory
 * to the proper location in the filesystem.
 *
 * @param regionInfo daughter {@link org.apache.hadoop.hbase.client.RegionInfo}
 * @throws IOException
 */
public Path commitDaughterRegion(final RegionInfo regionInfo)
    throws IOException {
  Path regionDir = new Path(this.tableDir, regionInfo.getEncodedName());
  Path daughterTmpDir = this.getSplitsDir(regionInfo);

  if (fs.exists(daughterTmpDir)) {

    // Write HRI to a file in case we need to recover hbase:meta
    Path regionInfoFile = new Path(daughterTmpDir, REGION_INFO_FILE);
    byte[] regionInfoContent = getRegionInfoFileContent(regionInfo);
    writeRegionInfoFileContent(conf, fs, regionInfoFile, regionInfoContent);

    // Move the daughter temp dir to the table dir
    if (!rename(daughterTmpDir, regionDir)) {
      throw new IOException("Unable to rename " + daughterTmpDir + " to " + regionDir);
    }
  }

  return regionDir;
}
 
Example 4
Source File: CheckTableIT.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
public static void deleteFirstIndexRegion(SpliceWatcher spliceWatcher, Connection connection, String schemaName, String tableName, String indexName) throws Exception {
    SConfiguration config = HConfiguration.getConfiguration();
    HBaseTestingUtility testingUtility = new HBaseTestingUtility((Configuration) config.getConfigSource().unwrapDelegate());
    Admin admin = testingUtility.getAdmin();

    // Delete 2nd region of index
    long   conglomerateId = TableSplit.getConglomerateId(connection, schemaName, tableName, indexName);
    TableName iName = TableName.valueOf(config.getNamespace(),Long.toString(conglomerateId));
    List<RegionInfo> partitions = admin.getRegions(iName);
    for (RegionInfo partition : partitions) {
        byte[] startKey = partition.getStartKey();
        if (startKey.length == 0) {
            String encodedRegionName = partition.getEncodedName();
            spliceWatcher.execute(String.format("call syscs_util.delete_region('%s', '%s', '%s', '%s', false)",
                    schemaName, tableName, indexName, encodedRegionName));
            break;
        }
    }
}
 
Example 5
Source File: SimpleRegionNormalizer.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Determine if a {@link RegionInfo} should be considered for a merge operation.
 */
private boolean skipForMerge(final RegionStates regionStates, final RegionInfo regionInfo) {
  final RegionState state = regionStates.getRegionState(regionInfo);
  final String name = regionInfo.getEncodedName();
  return
    logTraceReason(
      () -> state == null,
      "skipping merge of region {} because no state information is available.", name)
      || logTraceReason(
        () -> !Objects.equals(state.getState(), RegionState.State.OPEN),
        "skipping merge of region {} because it is not open.", name)
      || logTraceReason(
        () -> !isOldEnoughForMerge(regionInfo),
        "skipping merge of region {} because it is not old enough.", name)
      || logTraceReason(
        () -> !isLargeEnoughForMerge(regionInfo),
        "skipping merge region {} because it is not large enough.", name);
}
 
Example 6
Source File: MasterFileSystem.java    From hbase with Apache License 2.0 6 votes vote down vote up
public void deleteFamilyFromFS(Path rootDir, RegionInfo region, byte[] familyName)
    throws IOException {
  // archive family store files
  Path tableDir = CommonFSUtils.getTableDir(rootDir, region.getTable());
  HFileArchiver.archiveFamily(fs, conf, region, tableDir, familyName);

  // delete the family folder
  Path familyDir = new Path(tableDir,
    new Path(region.getEncodedName(), Bytes.toString(familyName)));
  if (fs.delete(familyDir, true) == false) {
    if (fs.exists(familyDir)) {
      throw new IOException("Could not delete family "
          + Bytes.toString(familyName) + " from FileSystem for region "
          + region.getRegionNameAsString() + "(" + region.getEncodedName()
          + ")");
    }
  }
}
 
Example 7
Source File: AssignmentManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
public TransitRegionStateProcedure createMoveRegionProcedure(RegionInfo regionInfo,
    ServerName targetServer) throws HBaseIOException {
  RegionStateNode regionNode = this.regionStates.getRegionStateNode(regionInfo);
  if (regionNode == null) {
    throw new UnknownRegionException("No RegionStateNode found for " +
        regionInfo.getEncodedName() + "(Closed/Deleted?)");
  }
  TransitRegionStateProcedure proc;
  regionNode.lock();
  try {
    preTransitCheck(regionNode, STATES_EXPECTED_ON_UNASSIGN_OR_MOVE);
    regionNode.checkOnline();
    proc = TransitRegionStateProcedure.move(getProcedureEnvironment(), regionInfo, targetServer);
    regionNode.setProcedure(proc);
  } finally {
    regionNode.unlock();
  }
  return proc;
}
 
Example 8
Source File: AssignmentManager.java    From hbase with Apache License 2.0 6 votes vote down vote up
public long unassign(RegionInfo regionInfo) throws IOException {
  RegionStateNode regionNode = regionStates.getRegionStateNode(regionInfo);
  if (regionNode == null) {
    throw new UnknownRegionException("No RegionState found for " + regionInfo.getEncodedName());
  }
  TransitRegionStateProcedure proc;
  regionNode.lock();
  try {
    preTransitCheck(regionNode, STATES_EXPECTED_ON_UNASSIGN_OR_MOVE);
    proc = TransitRegionStateProcedure.unassign(getProcedureEnvironment(), regionInfo);
    regionNode.setProcedure(proc);
  } finally {
    regionNode.unlock();
  }
  ProcedureSyncWait.submitAndWaitProcedure(master.getMasterProcedureExecutor(), proc);
  return proc.getProcId();
}
 
Example 9
Source File: HRegionFileSystem.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Remove daughter region
 * @param regionInfo daughter {@link RegionInfo}
 * @throws IOException
 */
void cleanupDaughterRegion(final RegionInfo regionInfo) throws IOException {
  Path regionDir = new Path(this.tableDir, regionInfo.getEncodedName());
  if (this.fs.exists(regionDir) && !deleteDir(regionDir)) {
    throw new IOException("Failed delete of " + regionDir);
  }
}
 
Example 10
Source File: TestCatalogJanitor.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Test clearing a split parent.
 */
@Test
public void testCleanParent() throws IOException, InterruptedException {
  TableDescriptor td = createTableDescriptorForCurrentMethod();
  // Create regions.
  RegionInfo parent =
    createRegionInfo(td.getTableName(), Bytes.toBytes("aaa"), Bytes.toBytes("eee"));
  RegionInfo splita =
    createRegionInfo(td.getTableName(), Bytes.toBytes("aaa"), Bytes.toBytes("ccc"));
  RegionInfo splitb =
    createRegionInfo(td.getTableName(), Bytes.toBytes("ccc"), Bytes.toBytes("eee"));
  // Test that when both daughter regions are in place, that we do not remove the parent.
  Result r = createResult(parent, splita, splitb);
  // Add a reference under splitA directory so we don't clear out the parent.
  Path rootdir = this.masterServices.getMasterFileSystem().getRootDir();
  Path tabledir = CommonFSUtils.getTableDir(rootdir, td.getTableName());
  Path parentdir = new Path(tabledir, parent.getEncodedName());
  Path storedir = HStore.getStoreHomedir(tabledir, splita, td.getColumnFamilies()[0].getName());
  Reference ref = Reference.createTopReference(Bytes.toBytes("ccc"));
  long now = System.currentTimeMillis();
  // Reference name has this format: StoreFile#REF_NAME_PARSER
  Path p = new Path(storedir, Long.toString(now) + "." + parent.getEncodedName());
  FileSystem fs = this.masterServices.getMasterFileSystem().getFileSystem();
  Path path = ref.write(fs, p);
  assertTrue(fs.exists(path));
  LOG.info("Created reference " + path);
  // Add a parentdir for kicks so can check it gets removed by the catalogjanitor.
  fs.mkdirs(parentdir);
  assertFalse(this.janitor.cleanParent(parent, r));
  ProcedureTestingUtility.waitAllProcedures(masterServices.getMasterProcedureExecutor());
  assertTrue(fs.exists(parentdir));
  // Remove the reference file and try again.
  assertTrue(fs.delete(p, true));
  assertTrue(this.janitor.cleanParent(parent, r));
  // Parent cleanup is run async as a procedure. Make sure parentdir is removed.
  ProcedureTestingUtility.waitAllProcedures(masterServices.getMasterProcedureExecutor());
  assertTrue(!fs.exists(parentdir));
}
 
Example 11
Source File: RestoreSnapshotHelper.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Clone specified regions. For each region create a new region
 * and create a HFileLink for each hfile.
 */
private RegionInfo[] cloneHdfsRegions(final ThreadPoolExecutor exec,
    final Map<String, SnapshotRegionManifest> regionManifests,
    final List<RegionInfo> regions) throws IOException {
  if (regions == null || regions.isEmpty()) return null;

  final Map<String, RegionInfo> snapshotRegions = new HashMap<>(regions.size());
  final String snapshotName = snapshotDesc.getName();

  // clone region info (change embedded tableName with the new one)
  RegionInfo[] clonedRegionsInfo = new RegionInfo[regions.size()];
  for (int i = 0; i < clonedRegionsInfo.length; ++i) {
    // clone the region info from the snapshot region info
    RegionInfo snapshotRegionInfo = regions.get(i);
    clonedRegionsInfo[i] = cloneRegionInfo(snapshotRegionInfo);

    // add the region name mapping between snapshot and cloned
    String snapshotRegionName = snapshotRegionInfo.getEncodedName();
    String clonedRegionName = clonedRegionsInfo[i].getEncodedName();
    regionsMap.put(Bytes.toBytes(snapshotRegionName), Bytes.toBytes(clonedRegionName));
    LOG.info("clone region=" + snapshotRegionName + " as " + clonedRegionName +
            " in snapshot " + snapshotName);

    // Add mapping between cloned region name and snapshot region info
    snapshotRegions.put(clonedRegionName, snapshotRegionInfo);
  }

  // create the regions on disk
  ModifyRegionUtils.createRegions(exec, conf, rootDir,
    tableDesc, clonedRegionsInfo, new ModifyRegionUtils.RegionFillTask() {
      @Override
      public void fillRegion(final HRegion region) throws IOException {
        RegionInfo snapshotHri = snapshotRegions.get(region.getRegionInfo().getEncodedName());
        cloneRegion(region, snapshotHri, regionManifests.get(snapshotHri.getEncodedName()));
      }
    });

  return clonedRegionsInfo;
}
 
Example 12
Source File: TestSnapshotHFileCleaner.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindsSnapshotFilesWhenCleaning() throws IOException {
  CommonFSUtils.setRootDir(conf, TEST_UTIL.getDataTestDir());
  Path rootDir = CommonFSUtils.getRootDir(conf);
  Path archivedHfileDir = new Path(TEST_UTIL.getDataTestDir(), HConstants.HFILE_ARCHIVE_DIRECTORY);

  FileSystem fs = FileSystem.get(conf);
  SnapshotHFileCleaner cleaner = new SnapshotHFileCleaner();
  cleaner.setConf(conf);

  // write an hfile to the snapshot directory
  String snapshotName = "snapshot";
  final TableName tableName = TableName.valueOf(name.getMethodName());
  Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir);
  RegionInfo mockRegion = RegionInfoBuilder.newBuilder(tableName).build();
  Path regionSnapshotDir = new Path(snapshotDir, mockRegion.getEncodedName());
  Path familyDir = new Path(regionSnapshotDir, "family");
  // create a reference to a supposedly valid hfile
  String hfile = "fd1e73e8a96c486090c5cec07b4894c4";
  Path refFile = new Path(familyDir, hfile);

  // make sure the reference file exists
  fs.create(refFile);

  // create the hfile in the archive
  fs.mkdirs(archivedHfileDir);
  fs.createNewFile(new Path(archivedHfileDir, hfile));

  // make sure that the file isn't deletable
  assertFalse(cleaner.isFileDeletable(fs.getFileStatus(refFile)));
}
 
Example 13
Source File: NamespaceAuditor.java    From hbase with Apache License 2.0 5 votes vote down vote up
public void updateQuotaForRegionMerge(RegionInfo mergedRegion) throws IOException {
  if (!stateManager.isInitialized()) {
    throw new IOException(
        "Merge operation is being performed even before namespace auditor is initialized.");
  } else if (!stateManager.checkAndUpdateNamespaceRegionCount(mergedRegion.getTable(),
      mergedRegion.getRegionName(), -1)) {
    throw new QuotaExceededException("Region merge not possible for :" +
      mergedRegion.getEncodedName() + " as quota limits are exceeded ");
  }
}
 
Example 14
Source File: TestRegionServerMetrics.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void assertRegionMetrics(String metric, long expectedValue) throws Exception {
  try (RegionLocator locator = connection.getRegionLocator(tableName)) {
    for ( HRegionLocation location: locator.getAllRegionLocations()) {
      RegionInfo hri = location.getRegion();
      MetricsRegionAggregateSource agg =
          rs.getRegion(hri.getRegionName()).getMetrics().getSource().getAggregateSource();
      String prefix = "namespace_" + NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR +
          "_table_" + tableName.getNameAsString() +
          "_region_" + hri.getEncodedName()+
          "_metric_";
      metricsHelper.assertCounter(prefix + metric, expectedValue, agg);
    }
  }
}
 
Example 15
Source File: SimpleRegionNormalizer.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Determine if a region in {@link RegionState} should be considered for a split operation.
 */
private static boolean skipForSplit(final RegionState state, final RegionInfo regionInfo) {
  final String name = regionInfo.getEncodedName();
  return
    logTraceReason(
      () -> state == null,
      "skipping split of region {} because no state information is available.", name)
      || logTraceReason(
        () -> !Objects.equals(state.getState(), RegionState.State.OPEN),
        "skipping merge of region {} because it is not open.", name);
}
 
Example 16
Source File: LocalIndexIT.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void copyLocalIndexHFiles(Configuration conf, RegionInfo fromRegion, RegionInfo toRegion, boolean move)
        throws IOException {
    Path root = FSUtils.getRootDir(conf);

    Path seondRegion = new Path(FSUtils.getTableDir(root, fromRegion.getTable()) + Path.SEPARATOR
            + fromRegion.getEncodedName() + Path.SEPARATOR + "L#0/");
    Path hfilePath = FSUtils.getCurrentFileSystem(conf).listFiles(seondRegion, true).next().getPath();
    Path firstRegionPath = new Path(FSUtils.getTableDir(root, toRegion.getTable()) + Path.SEPARATOR
            + toRegion.getEncodedName() + Path.SEPARATOR + "L#0/");
    FileSystem currentFileSystem = FSUtils.getCurrentFileSystem(conf);
    assertTrue(FileUtil.copy(currentFileSystem, hfilePath, currentFileSystem, firstRegionPath, move, conf));
}
 
Example 17
Source File: TestHBCK2.java    From hbase-operator-tools with Apache License 2.0 5 votes vote down vote up
@Test (expected = IllegalArgumentException.class)
public void testSetRegionStateInvalidState() 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, null);
    }
  } finally {
    TEST_UTIL.deleteTable(REGION_STATES_TABLE_NAME);
  }
}
 
Example 18
Source File: TestCatalogJanitor.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testArchiveOldRegion() throws Exception {
  // Create regions.
  TableDescriptor td = createTableDescriptorForCurrentMethod();
  RegionInfo parent =
    createRegionInfo(td.getTableName(), Bytes.toBytes("aaa"), Bytes.toBytes("eee"));
  RegionInfo splita =
    createRegionInfo(td.getTableName(), Bytes.toBytes("aaa"), Bytes.toBytes("ccc"));
  RegionInfo splitb =
    createRegionInfo(td.getTableName(), Bytes.toBytes("ccc"), Bytes.toBytes("eee"));

  // Test that when both daughter regions are in place, that we do not
  // remove the parent.
  Result parentMetaRow = createResult(parent, splita, splitb);
  FileSystem fs = FileSystem.get(HTU.getConfiguration());
  Path rootdir = this.masterServices.getMasterFileSystem().getRootDir();
  // have to set the root directory since we use it in HFileDisposer to figure out to get to the
  // archive directory. Otherwise, it just seems to pick the first root directory it can find (so
  // the single test passes, but when the full suite is run, things get borked).
  CommonFSUtils.setRootDir(fs.getConf(), rootdir);
  Path tabledir = CommonFSUtils.getTableDir(rootdir, td.getTableName());
  Path storedir = HStore.getStoreHomedir(tabledir, parent, td.getColumnFamilies()[0].getName());
  Path storeArchive = HFileArchiveUtil.getStoreArchivePath(this.masterServices.getConfiguration(),
    parent, tabledir, td.getColumnFamilies()[0].getName());
  LOG.debug("Table dir:" + tabledir);
  LOG.debug("Store dir:" + storedir);
  LOG.debug("Store archive dir:" + storeArchive);

  // add a couple of store files that we can check for
  FileStatus[] mockFiles = addMockStoreFiles(2, this.masterServices, storedir);
  // get the current store files for comparison
  FileStatus[] storeFiles = fs.listStatus(storedir);
  int index = 0;
  for (FileStatus file : storeFiles) {
    LOG.debug("Have store file:" + file.getPath());
    assertEquals("Got unexpected store file", mockFiles[index].getPath(),
      storeFiles[index].getPath());
    index++;
  }

  // do the cleaning of the parent
  assertTrue(janitor.cleanParent(parent, parentMetaRow));
  Path parentDir = new Path(tabledir, parent.getEncodedName());
  // Cleanup procedure runs async. Wait till it done.
  ProcedureTestingUtility.waitAllProcedures(masterServices.getMasterProcedureExecutor());
  assertTrue(!fs.exists(parentDir));
  LOG.debug("Finished cleanup of parent region");

  // and now check to make sure that the files have actually been archived
  FileStatus[] archivedStoreFiles = fs.listStatus(storeArchive);
  logFiles("archived files", storeFiles);
  logFiles("archived files", archivedStoreFiles);

  assertArchiveEqualToOriginal(storeFiles, archivedStoreFiles, fs);

  // cleanup
  CommonFSUtils.delete(fs, rootdir, true);
}
 
Example 19
Source File: TestRecoveredEdits.java    From hbase with Apache License 2.0 4 votes vote down vote up
private void testReplayWorksWithMemoryCompactionPolicy(MemoryCompactionPolicy policy) throws
  IOException {
  Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
  // Set it so we flush every 1M or so.  Thats a lot.
  conf.setInt(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, 1024*1024);
  conf.set(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY, String.valueOf(policy).toLowerCase());
  // The file of recovered edits has a column family of 'meta'.
  final String columnFamily = "meta";
  byte[][] columnFamilyAsByteArray = new byte[][] { Bytes.toBytes(columnFamily) };
  TableDescriptor tableDescriptor = TableDescriptorBuilder
    .newBuilder(TableName.valueOf(testName.getMethodName())).setColumnFamily(
      ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(columnFamily)).build())
    .build();
  RegionInfo hri = RegionInfoBuilder.newBuilder(tableDescriptor.getTableName()).build();
  final String encodedRegionName = hri.getEncodedName();
  Path hbaseRootDir = TEST_UTIL.getDataTestDir();
  FileSystem fs = FileSystem.get(TEST_UTIL.getConfiguration());
  Path tableDir = CommonFSUtils.getTableDir(hbaseRootDir, tableDescriptor.getTableName());
  HRegionFileSystem hrfs =
      new HRegionFileSystem(TEST_UTIL.getConfiguration(), fs, tableDir, hri);
  if (fs.exists(hrfs.getRegionDir())) {
    LOG.info("Region directory already exists. Deleting.");
    fs.delete(hrfs.getRegionDir(), true);
  }
  HRegion region = HBaseTestingUtility
      .createRegionAndWAL(hri, hbaseRootDir, conf, tableDescriptor, blockCache);
  assertEquals(encodedRegionName, region.getRegionInfo().getEncodedName());
  List<String> storeFiles = region.getStoreFileList(columnFamilyAsByteArray);
  // There should be no store files.
  assertTrue(storeFiles.isEmpty());
  region.close();
  Path regionDir = FSUtils.getRegionDirFromRootDir(hbaseRootDir, hri);
  Path recoveredEditsDir = WALSplitUtil.getRegionDirRecoveredEditsDir(regionDir);
  // This is a little fragile getting this path to a file of 10M of edits.
  Path recoveredEditsFile = new Path(
    System.getProperty("test.build.classes", "target/test-classes"),
      "0000000000000016310");
  // Copy this file under the region's recovered.edits dir so it is replayed on reopen.
  Path destination = new Path(recoveredEditsDir, recoveredEditsFile.getName());
  fs.copyToLocalFile(recoveredEditsFile, destination);
  assertTrue(fs.exists(destination));
  // Now the file 0000000000000016310 is under recovered.edits, reopen the region to replay.
  region = HRegion.openHRegion(region, null);
  assertEquals(encodedRegionName, region.getRegionInfo().getEncodedName());
  storeFiles = region.getStoreFileList(columnFamilyAsByteArray);
  // Our 0000000000000016310 is 10MB. Most of the edits are for one region. Lets assume that if
  // we flush at 1MB, that there are at least 3 flushed files that are there because of the
  // replay of edits.
  if(policy == MemoryCompactionPolicy.EAGER || policy == MemoryCompactionPolicy.ADAPTIVE) {
    assertTrue("Files count=" + storeFiles.size(), storeFiles.size() >= 1);
  } else {
    assertTrue("Files count=" + storeFiles.size(), storeFiles.size() > 10);
  }
  // Now verify all edits made it into the region.
  int count = verifyAllEditsMadeItIn(fs, conf, recoveredEditsFile, region);
  LOG.info("Checked " + count + " edits made it in");
}
 
Example 20
Source File: HFileArchiver.java    From hbase with Apache License 2.0 2 votes vote down vote up
/**
 * Remove from the specified region the store files of the specified column family,
 * either by archiving them or outright deletion
 * @param fs the filesystem where the store files live
 * @param conf {@link Configuration} to examine to determine the archive directory
 * @param parent Parent region hosting the store files
 * @param tableDir {@link Path} to where the table is being stored (for building the archive path)
 * @param family the family hosting the store files
 * @throws IOException if the files could not be correctly disposed.
 */
public static void archiveFamily(FileSystem fs, Configuration conf,
    RegionInfo parent, Path tableDir, byte[] family) throws IOException {
  Path familyDir = new Path(tableDir, new Path(parent.getEncodedName(), Bytes.toString(family)));
  archiveFamilyByFamilyDir(fs, conf, parent, familyDir, family);
}