/** * @param rootDir Path to the root directory where hbase files are stored * @param archiveDir Path to the hbase archive directory * @param hFileLinkPattern The path of the HFile Link. */ public final static HFileLink buildFromHFileLinkPattern(final Path rootDir, final Path archiveDir, final Path hFileLinkPattern) { Path hfilePath = getHFileLinkPatternRelativePath(hFileLinkPattern); Path tempPath = new Path(new Path(rootDir, HConstants.HBASE_TEMP_DIRECTORY), hfilePath); Path originPath = new Path(rootDir, hfilePath); Path mobPath = new Path(new Path(rootDir, MobConstants.MOB_DIR_NAME), hfilePath); Path archivePath = new Path(archiveDir, hfilePath); return new HFileLink(originPath, tempPath, mobPath, archivePath); }
@Test public void testEqualsWithLink() throws IOException { Path origin = new Path("/origin"); Path tmp = TEST_UTIL.getDataTestDir(); Path mob = new Path("/mob"); Path archive = new Path("/archive"); HFileLink link1 = new HFileLink(new Path(origin, "f1"), new Path(tmp, "f1"), new Path(mob, "f1"), new Path(archive, "f1")); HFileLink link2 = new HFileLink(new Path(origin, "f1"), new Path(tmp, "f1"), new Path(mob, "f1"), new Path(archive, "f1")); StoreFileInfo info1 = new StoreFileInfo(TEST_UTIL.getConfiguration(), TEST_UTIL.getTestFileSystem(), null, link1); StoreFileInfo info2 = new StoreFileInfo(TEST_UTIL.getConfiguration(), TEST_UTIL.getTestFileSystem(), null, link2); assertEquals(info1, info2); assertEquals(info1.hashCode(), info2.hashCode()); } }
/** * @param rootDir Path to the root directory where hbase files are stored * @param archiveDir Path to the hbase archive directory * @param hFileLinkPattern The path of the HFile Link. */ public final static HFileLink buildFromHFileLinkPattern(final Path rootDir, final Path archiveDir, final Path hFileLinkPattern) { Path hfilePath = getHFileLinkPatternRelativePath(hFileLinkPattern); Path tempPath = new Path(new Path(rootDir, HConstants.HBASE_TEMP_DIRECTORY), hfilePath); Path originPath = new Path(rootDir, hfilePath); Path archivePath = new Path(archiveDir, hfilePath); return new HFileLink(originPath, tempPath, archivePath); }
public void storeFile (final String region, final String family, final String hfile) throws IOException { Path path = new Path(family, HFileLink.createHFileLinkName(table, region, hfile)); long size = new HFileLink(conf, path).getFileStatus(fs).getLen(); files.add(new Pair<Path, Long>(path, size)); }
private FSDataInputStream openSourceFile(final Path path) { try { if (HFileLink.isHFileLink(path)) { return new HFileLink(inputRoot, inputArchive, path).open(inputFs); } else if (isHLogLinkPath(path)) { String serverName = path.getParent().getName(); String logName = path.getName(); return new HLogLink(inputRoot, serverName, logName).open(inputFs); } return inputFs.open(path); } catch (IOException e) { LOG.error("Unable to open source file=" + path, e); return null; } }
private FileStatus getFileStatus(final FileSystem fs, final Path path) { try { if (HFileLink.isHFileLink(path)) { HFileLink link = new HFileLink(inputRoot, inputArchive, path); return link.getFileStatus(fs); } else if (isHLogLinkPath(path)) { String serverName = path.getParent().getName(); String logName = path.getName(); return new HLogLink(inputRoot, serverName, logName).getFileStatus(fs); } return fs.getFileStatus(path); } catch (IOException e) { LOG.warn("Unable to get the status for file=" + path); return null; } }
public void storeFile (final String region, final String family, final String hfile) throws IOException { Path path = new Path(family, HFileLink.createHFileLinkName(table, region, hfile)); HFileLink link = new HFileLink(conf, path); boolean inArchive = false; long size = -1; try { if ((inArchive = fs.exists(link.getArchivePath()))) { size = fs.getFileStatus(link.getArchivePath()).getLen(); hfileArchiveSize.addAndGet(size); hfileArchiveCount.addAndGet(1); } else { size = link.getFileStatus(fs).getLen(); hfileSize.addAndGet(size); hfilesCount.addAndGet(1); } } catch (FileNotFoundException e) { hfilesMissing.addAndGet(1); } if (showFiles) { System.out.printf("%8s %s/%s/%s/%s %s%n", (size < 0 ? "-" : StringUtils.humanReadableInt(size)), table, region, family, hfile, (inArchive ? "(archive)" : (size < 0) ? "(NOT FOUND)" : "")); } }
InputStream in = new HFileLink(conf, linkPath).open(fs); OutputStream out = fs.create(outPath); IOUtils.copyBytes(in, out, conf);
@Test public void testEqualsWithLink() throws IOException { Path origin = new Path("/origin"); Path tmp = TEST_UTIL.getDataTestDir(); Path mob = new Path("/mob"); Path archive = new Path("/archive"); HFileLink link1 = new HFileLink(new Path(origin, "f1"), new Path(tmp, "f1"), new Path(mob, "f1"), new Path(archive, "f1")); HFileLink link2 = new HFileLink(new Path(origin, "f1"), new Path(tmp, "f1"), new Path(mob, "f1"), new Path(archive, "f1")); StoreFileInfo info1 = new StoreFileInfo(TEST_UTIL.getConfiguration(), TEST_UTIL.getTestFileSystem(), null, link1); StoreFileInfo info2 = new StoreFileInfo(TEST_UTIL.getConfiguration(), TEST_UTIL.getTestFileSystem(), null, link2); assertEquals(info1, info2); assertEquals(info1.hashCode(), info2.hashCode()); } }