HBASE-7604 Remove duplicated code from HFileLink (Matteo Bertozzi)
git-svn-id: https://svn.apache.org/repos/asf/hbase/branches/hbase-7290@1445854 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f70ed5ab6d
commit
bc37ac1553
|
@ -142,50 +142,6 @@ public class HFileLink extends FileLink {
|
||||||
return m.groupCount() > 2 && m.group(3) != null && m.group(2) != null && m.group(1) != null;
|
return m.groupCount() > 2 && m.group(3) != null && m.group(2) != null && m.group(1) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The returned path can be the "original" file path like: /hbase/table/region/cf/hfile
|
|
||||||
* or a path to the archived file like: /hbase/.archive/table/region/cf/hfile
|
|
||||||
*
|
|
||||||
* @param fs {@link FileSystem} on which to check the HFileLink
|
|
||||||
* @param conf {@link Configuration} from which to extract specific archive locations
|
|
||||||
* @param path HFileLink path
|
|
||||||
* @return Referenced path (original path or archived path)
|
|
||||||
* @throws IOException on unexpected error.
|
|
||||||
*/
|
|
||||||
public static Path getReferencedPath(final Configuration conf, final FileSystem fs,
|
|
||||||
final Path path) throws IOException {
|
|
||||||
return getReferencedPath(fs, FSUtils.getRootDir(conf),
|
|
||||||
HFileArchiveUtil.getArchivePath(conf), path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The returned path can be the "original" file path like: /hbase/table/region/cf/hfile
|
|
||||||
* or a path to the archived file like: /hbase/.archive/table/region/cf/hfile
|
|
||||||
*
|
|
||||||
* @param fs {@link FileSystem} on which to check the HFileLink
|
|
||||||
* @param rootDir root hbase directory
|
|
||||||
* @param archiveDir Path to the hbase archive directory
|
|
||||||
* @param path HFileLink path
|
|
||||||
* @return Referenced path (original path or archived path)
|
|
||||||
* @throws IOException on unexpected error.
|
|
||||||
*/
|
|
||||||
public static Path getReferencedPath(final FileSystem fs, final Path rootDir,
|
|
||||||
final Path archiveDir, final Path path) throws IOException {
|
|
||||||
Path hfilePath = getRelativeTablePath(path);
|
|
||||||
|
|
||||||
Path originPath = new Path(rootDir, hfilePath);
|
|
||||||
if (fs.exists(originPath)) {
|
|
||||||
return originPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
Path archivePath = new Path(archiveDir, hfilePath);
|
|
||||||
if (fs.exists(archivePath)) {
|
|
||||||
return archivePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Path(new Path(rootDir, HConstants.HBASE_TEMP_DIRECTORY), hfilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a HFileLink path to a table relative path.
|
* Convert a HFileLink path to a table relative path.
|
||||||
* e.g. the link: /hbase/test/0123/cf/testtb=4567-abcd
|
* e.g. the link: /hbase/test/0123/cf/testtb=4567-abcd
|
||||||
|
|
|
@ -304,8 +304,8 @@ public final class ExportSnapshot extends Configured implements Tool {
|
||||||
private FileStatus getFileStatus(final FileSystem fs, final Path path) {
|
private FileStatus getFileStatus(final FileSystem fs, final Path path) {
|
||||||
try {
|
try {
|
||||||
if (HFileLink.isHFileLink(path)) {
|
if (HFileLink.isHFileLink(path)) {
|
||||||
Path refPath = HFileLink.getReferencedPath(fs, inputRoot, inputArchive, path);
|
HFileLink link = new HFileLink(inputRoot, inputArchive, path);
|
||||||
return fs.getFileStatus(refPath);
|
return link.getFileStatus(fs);
|
||||||
} else if (isHLogLinkPath(path)) {
|
} else if (isHLogLinkPath(path)) {
|
||||||
String serverName = path.getParent().getName();
|
String serverName = path.getParent().getName();
|
||||||
String logName = path.getName();
|
String logName = path.getName();
|
||||||
|
@ -375,7 +375,7 @@ public final class ExportSnapshot extends Configured implements Tool {
|
||||||
public void storeFile (final String region, final String family, final String hfile)
|
public void storeFile (final String region, final String family, final String hfile)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Path path = new Path(family, HFileLink.createHFileLinkName(table, region, hfile));
|
Path path = new Path(family, HFileLink.createHFileLinkName(table, region, hfile));
|
||||||
long size = fs.getFileStatus(HFileLink.getReferencedPath(conf, fs, path)).getLen();
|
long size = new HFileLink(conf, path).getFileStatus(fs).getLen();
|
||||||
files.add(new Pair<Path, Long>(path, size));
|
files.add(new Pair<Path, Long>(path, size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue