You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by jy...@apache.org on 2013/03/06 19:24:52 UTC
svn commit: r1453465 - in
/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase:
snapshot/SnapshotDescriptionUtils.java util/FSUtils.java
Author: jyates
Date: Wed Mar 6 18:24:51 2013
New Revision: 1453465
URL: http://svn.apache.org/r1453465
Log:
HBASE-8008: Fix DirFilter usage to be consistent
Modified:
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotDescriptionUtils.java
hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotDescriptionUtils.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotDescriptionUtils.java?rev=1453465&r1=1453464&r2=1453465&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotDescriptionUtils.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotDescriptionUtils.java Wed Mar 6 18:24:51 2013
@@ -18,6 +18,7 @@
package org.apache.hadoop.hbase.snapshot;
import java.io.IOException;
+import java.util.Collections;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -75,24 +76,14 @@ public class SnapshotDescriptionUtils {
/**
* Filter that only accepts completed snapshot directories
*/
- public static class CompletedSnaphotDirectoriesFilter extends FSUtils.DirFilter {
+ public static class CompletedSnaphotDirectoriesFilter extends FSUtils.BlackListDirFilter {
/**
* @param fs
*/
public CompletedSnaphotDirectoriesFilter(FileSystem fs) {
- super(fs);
+ super(fs, Collections.singletonList(SNAPSHOT_TMP_DIR_NAME));
}
-
- @Override
- public boolean accept(Path path) {
- // only accept directories that aren't the tmp directory
- if (super.accept(path)) {
- return !path.getName().equals(SNAPSHOT_TMP_DIR_NAME);
- }
- return false;
- }
-
}
private static final Log LOG = LogFactory.getLog(SnapshotDescriptionUtils.class);
Modified: hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java?rev=1453465&r1=1453464&r2=1453465&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java (original)
+++ hbase/trunk/hbase-server/src/main/java/org/apache/hadoop/hbase/util/FSUtils.java Wed Mar 6 18:24:51 2013
@@ -28,6 +28,7 @@ import java.lang.reflect.Method;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -986,33 +987,65 @@ public abstract class FSUtils {
}
/**
- * A {@link PathFilter} that returns directories.
+ * Directory filter that doesn't include any of the directories in the specified blacklist
*/
- public static class DirFilter implements PathFilter {
+ public static class BlackListDirFilter implements PathFilter {
private final FileSystem fs;
+ private List<String> blacklist;
- public DirFilter(final FileSystem fs) {
+ /**
+ * Create a filter on the give filesystem with the specified blacklist
+ * @param fs filesystem to filter
+ * @param directoryNameBlackList list of the names of the directories to filter. If
+ * <tt>null</tt>, all directories are returned
+ */
+ @SuppressWarnings("unchecked")
+ public BlackListDirFilter(final FileSystem fs, final List<String> directoryNameBlackList) {
this.fs = fs;
+ blacklist =
+ (List<String>) (directoryNameBlackList == null ? Collections.emptyList()
+ : directoryNameBlackList);
}
@Override
public boolean accept(Path p) {
boolean isValid = false;
try {
- if (HConstants.HBASE_NON_USER_TABLE_DIRS.contains(p.toString())) {
+ if (blacklist.contains(p.getName().toString())) {
isValid = false;
} else {
isValid = fs.getFileStatus(p).isDir();
}
} catch (IOException e) {
- LOG.warn("An error occurred while verifying if [" + p.toString() +
- "] is a valid directory. Returning 'not valid' and continuing.", e);
+ LOG.warn("An error occurred while verifying if [" + p.toString()
+ + "] is a valid directory. Returning 'not valid' and continuing.", e);
}
return isValid;
}
}
/**
+ * A {@link PathFilter} that only allows directories.
+ */
+ public static class DirFilter extends BlackListDirFilter {
+
+ public DirFilter(FileSystem fs) {
+ super(fs, null);
+ }
+ }
+
+ /**
+ * A {@link PathFilter} that returns usertable directories. To get all directories use the
+ * {@link BlackListDirFilter} with a <tt>null</tt> blacklist
+ */
+ public static class UserTableDirFilter extends BlackListDirFilter {
+
+ public UserTableDirFilter(FileSystem fs) {
+ super(fs, HConstants.HBASE_NON_USER_TABLE_DIRS);
+ }
+ }
+
+ /**
* Heuristic to determine whether is safe or not to open a file for append
* Looks both for dfs.support.append and use reflection to search
* for SequenceFile.Writer.syncFs() or FSDataOutputStream.hflush()
@@ -1077,14 +1110,10 @@ public abstract class FSUtils {
public static List<Path> getTableDirs(final FileSystem fs, final Path rootdir)
throws IOException {
// presumes any directory under hbase.rootdir is a table
- FileStatus [] dirs = fs.listStatus(rootdir, new DirFilter(fs));
+ FileStatus[] dirs = fs.listStatus(rootdir, new UserTableDirFilter(fs));
List<Path> tabledirs = new ArrayList<Path>(dirs.length);
for (FileStatus dir: dirs) {
- Path p = dir.getPath();
- String tableName = p.getName();
- if (!HConstants.HBASE_NON_USER_TABLE_DIRS.contains(tableName)) {
- tabledirs.add(p);
- }
+ tabledirs.add(dir.getPath());
}
return tabledirs;
}
@@ -1255,18 +1284,13 @@ public abstract class FSUtils {
// if this method looks similar to 'getTableFragmentation' that is because
// it was borrowed from it.
- DirFilter df = new DirFilter(fs);
- // presumes any directory under hbase.rootdir is a table
+ // only include the directory paths to tables
+ PathFilter df = new BlackListDirFilter(fs, HConstants.HBASE_NON_TABLE_DIRS);
FileStatus [] tableDirs = fs.listStatus(hbaseRootDir, df);
for (FileStatus tableDir : tableDirs) {
- // Skip the .log and other non-table directories. All others should be tables.
// Inside a table, there are compaction.dir directories to skip. Otherwise, all else
// should be regions.
- Path d = tableDir.getPath();
- if (HConstants.HBASE_NON_TABLE_DIRS.contains(d.getName())) {
- continue;
- }
- FileStatus[] regionDirs = fs.listStatus(d, df);
+ FileStatus[] regionDirs = fs.listStatus(tableDir.getPath(), df);
for (FileStatus regionDir : regionDirs) {
Path dd = regionDir.getPath();
if (dd.getName().equals(HConstants.HREGION_COMPACTIONDIR_NAME)) {