diff --git hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSVisitor.java hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSVisitor.java index fdc9f29..75729b6 100644 --- hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSVisitor.java +++ hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSVisitor.java @@ -29,11 +29,7 @@ import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.PathFilter; import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.HRegionInfo; -import org.apache.hadoop.hbase.io.Reference; -import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.wal.HLogUtil; -import org.apache.hadoop.hbase.util.FSUtils; /** * Utility methods for interacting with the hbase.root file system. @@ -42,6 +38,10 @@ import org.apache.hadoop.hbase.util.FSUtils; public final class FSVisitor { private static final Log LOG = LogFactory.getLog(FSVisitor.class); + public interface RegionVisitor { + void region(final String region) throws IOException; + } + public interface StoreFileVisitor { void storeFile(final String region, final String family, final String hfileName) throws IOException; @@ -69,6 +69,27 @@ public final class FSVisitor { * @param visitor callback object to get the store files * @throws IOException if an error occurred while scanning the directory */ + public static void visitRegions(final FileSystem fs, final Path tableDir, + final RegionVisitor visitor) throws IOException { + FileStatus[] regions = FSUtils.listStatus(fs, tableDir, new FSUtils.RegionDirFilter(fs)); + if (regions == null) { + LOG.info("No regions under directory:" + tableDir); + return; + } + + for (FileStatus region: regions) { + visitor.region(region.getPath().getName()); + } + } + + /** + * Iterate over the table store files + * + * @param fs {@link FileSystem} + * @param tableDir {@link Path} to the table directory + * @param visitor callback object to get the store files + * @throws IOException if an error occurred while scanning the directory + */ public static void visitTableStoreFiles(final FileSystem fs, final Path tableDir, final StoreFileVisitor visitor) throws IOException { FileStatus[] regions = FSUtils.listStatus(fs, tableDir, new FSUtils.RegionDirFilter(fs)); diff --git hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java index 6101b16..ba50aea 100644 --- hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java +++ hbase-server/src/test/java/org/apache/hadoop/hbase/snapshot/SnapshotTestingUtils.java @@ -23,19 +23,15 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; +import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.HashSet; import java.util.TreeSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.fs.PathFilter; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; @@ -58,7 +54,6 @@ import org.apache.hadoop.hbase.regionserver.HRegionFileSystem; import org.apache.hadoop.hbase.regionserver.HRegionServer; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.FSTableDescriptors; -import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.FSVisitor; import org.apache.hadoop.hbase.util.MD5Hash; import org.junit.Assert; @@ -207,10 +202,17 @@ public class SnapshotTestingUtils { // Extract regions and families with store files final Set snapshotRegions = new HashSet(); final Set snapshotFamilies = new TreeSet(Bytes.BYTES_COMPARATOR); + FSVisitor.visitRegions(fs, snapshotDir, new FSVisitor.RegionVisitor() { + @Override + public void region(String region) throws IOException { + snapshotRegions.add(region); + } + }); + FSVisitor.visitTableStoreFiles(fs, snapshotDir, new FSVisitor.StoreFileVisitor() { + @Override public void storeFile(final String region, final String family, final String hfileName) throws IOException { - snapshotRegions.add(region); snapshotFamilies.add(Bytes.toBytes(family)); } }); @@ -346,6 +348,7 @@ public class SnapshotTestingUtils { throws IOException { final ArrayList hfiles = new ArrayList(); FSVisitor.visitTableStoreFiles(fs, tableDir, new FSVisitor.StoreFileVisitor() { + @Override public void storeFile(final String region, final String family, final String hfileName) throws IOException { hfiles.add(new Path(tableDir, new Path(region, new Path(family, hfileName))));