Java Code Examples for org.apache.hadoop.hbase.io.Reference#createTopReference()

The following examples show how to use org.apache.hadoop.hbase.io.Reference#createTopReference() . These examples are extracted from open source projects. 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 Project: phoenix   File: IndexSplitTransaction.java    License: Apache License 2.0 6 votes vote down vote up
private Path splitStoreFile(HRegionInfo hri, String familyName, StoreFile f, byte[] splitRow,
        boolean top, HRegionFileSystem fs) throws IOException {
    f.closeReader(true);
    Path splitDir =
            new Path(fs.getSplitsDir(hri), familyName);
    // A reference to the bottom half of the hsf store file.
    Reference r =
            top ? Reference.createTopReference(splitRow) : Reference
                    .createBottomReference(splitRow);
    // 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 parentRegionName = this.parent.getRegionInfo().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(splitDir, f.getPath().getName() + "." + parentRegionName);
    return r.write(fs.getFileSystem(), p);
}
 
Example 2
Source Project: hbase   File: HRegionFileSystem.java    License: 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 Project: hbase   File: BulkLoadHFilesTool.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Split a storefile into a top and bottom half, maintaining the metadata, recreating bloom
 * filters, etc.
 */
@VisibleForTesting
static void splitStoreFile(Configuration conf, Path inFile, ColumnFamilyDescriptor familyDesc,
    byte[] splitKey, Path bottomOut, Path topOut) throws IOException {
  // Open reader with no block cache, and not in-memory
  Reference topReference = Reference.createTopReference(splitKey);
  Reference bottomReference = Reference.createBottomReference(splitKey);

  copyHFileHalf(conf, inFile, topOut, topReference, familyDesc);
  copyHFileHalf(conf, inFile, bottomOut, bottomReference, familyDesc);
}
 
Example 4
Source Project: hbase   File: TestCatalogJanitor.java    License: 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 5
Source Project: hbase   File: TestCatalogJanitor.java    License: Apache License 2.0 5 votes vote down vote up
private Path createReferences(final MasterServices services, final TableDescriptor td,
  final RegionInfo parent, final RegionInfo daughter, final byte[] midkey, final boolean top)
  throws IOException {
  Path rootdir = services.getMasterFileSystem().getRootDir();
  Path tabledir = CommonFSUtils.getTableDir(rootdir, parent.getTable());
  Path storedir = HStore.getStoreHomedir(tabledir, daughter, td.getColumnFamilies()[0].getName());
  Reference ref =
    top ? Reference.createTopReference(midkey) : Reference.createBottomReference(midkey);
  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 = services.getMasterFileSystem().getFileSystem();
  ref.write(fs, p);
  return p;
}