Skip to content

Commit

Permalink
HBASE-4272. Add -metaonly flag to hbck feature to only inspect and tr…
Browse files Browse the repository at this point in the history
…y to repair META and ROOT.

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1169996 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
toddlipcon committed Sep 13, 2011
1 parent bcd4846 commit 340a3c4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@ Release 0.90.5 - Unreleased
for a region (todd)
HBASE-4313 Refactor TestHBaseFsck to make adding individual hbck tests
easier (Jonathan Hsieh)
HBASE-4272. Add -metaonly flag to hbck feature to only inspect and try
to repair META and ROOT. (todd)

Release 0.90.4 - August 10, 2011

Expand Down
82 changes: 58 additions & 24 deletions src/main/java/org/apache/hadoop/hbase/util/HBaseFsck.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public class HBaseFsck {
private boolean fix = false; // do we want to try fixing the errors?
private boolean rerun = false; // if we tried to fix something rerun hbck
private static boolean summary = false; // if we want to print less output
private boolean checkMetaOnly = false;

// Empty regioninfo qualifiers in .META.
private Set<Result> emptyRegionInfoQualifiers = new HashSet<Result>();
private int numThreads = MAX_NUM_THREADS;
Expand Down Expand Up @@ -145,6 +147,7 @@ int doWork() throws IOException, KeeperException, InterruptedException {
errors.reportError("Encountered fatal error. Exiting...");
return -1;
}

getMetaEntries();

// Check if .META. is found only once and in the right place
Expand All @@ -155,28 +158,28 @@ int doWork() throws IOException, KeeperException, InterruptedException {
}

// get a list of all tables that have not changed recently.
AtomicInteger numSkipped = new AtomicInteger(0);
HTableDescriptor[] allTables = getTables(numSkipped);
errors.print("Number of Tables: " +
(allTables == null ? 0 : allTables.length));
if (details) {
if (numSkipped.get() > 0) {
errors.detail("Number of Tables in flux: " + numSkipped.get());
}
if (allTables != null && allTables.length > 0) {
for (HTableDescriptor td : allTables) {
String tableName = td.getNameAsString();
errors.detail(" Table: " + tableName + "\t" +
(td.isReadOnly() ? "ro" : "rw") + "\t" +
(td.isRootRegion() ? "ROOT" :
(td.isMetaRegion() ? "META" : " ")) + "\t" +
" families: " + td.getFamilies().size());
if (!checkMetaOnly) {
AtomicInteger numSkipped = new AtomicInteger(0);
HTableDescriptor[] allTables = getTables(numSkipped);
errors.print("Number of Tables: " +
(allTables == null ? 0 : allTables.length));
if (details) {
if (numSkipped.get() > 0) {
errors.detail("Number of Tables in flux: " + numSkipped.get());
}
if (allTables != null && allTables.length > 0) {
for (HTableDescriptor td : allTables) {
String tableName = td.getNameAsString();
errors.detail(" Table: " + tableName + "\t" +
(td.isReadOnly() ? "ro" : "rw") + "\t" +
(td.isRootRegion() ? "ROOT" :
(td.isMetaRegion() ? "META" : " ")) + "\t" +
" families: " + td.getFamilies().size());
}
}

}

}

// From the master, get a list of all known live region servers
Collection<ServerName> regionServers = status.getServers();
errors.print("Number of live region servers: " +
Expand Down Expand Up @@ -278,10 +281,15 @@ void checkHdfs() throws IOException, InterruptedException {
boolean foundVersionFile = false;
FileStatus[] files = fs.listStatus(rootDir);
for (FileStatus file : files) {
if (file.getPath().getName().equals(HConstants.VERSION_FILE_NAME)) {
String dirName = file.getPath().getName();
if (dirName.equals(HConstants.VERSION_FILE_NAME)) {
foundVersionFile = true;
} else {
tableDirs.add(file);
if (!checkMetaOnly ||
dirName.equals("-ROOT-") ||
dirName.equals(".META.")) {
tableDirs.add(file);
}
}
}

Expand Down Expand Up @@ -814,8 +822,11 @@ public boolean processRow(Result result) throws IOException {
MetaScanner.metaScan(conf, visitor, null, null,
Integer.MAX_VALUE, HConstants.ROOT_TABLE_NAME);

// Scan .META. to pick up user regions
MetaScanner.metaScan(conf, visitor);
if (!checkMetaOnly) {
// Scan .META. to pick up user regions
MetaScanner.metaScan(conf, visitor);
}

errors.print("");
}

Expand Down Expand Up @@ -1050,6 +1061,9 @@ public synchronized void run() {

// list all online regions from this region server
List<HRegionInfo> regions = server.getOnlineRegions();
if (hbck.checkMetaOnly) {
regions = filterOnlyMetaRegions(regions);
}
if (details) {
errors.detail("RegionServer: " + rsinfo.getServerName() +
" number of regions: " + regions.size());
Expand All @@ -1075,6 +1089,16 @@ public synchronized void run() {
notifyAll(); // wakeup anybody waiting for this item to be done
}
}

private List<HRegionInfo> filterOnlyMetaRegions(List<HRegionInfo> regions) {
List<HRegionInfo> ret = Lists.newArrayList();
for (HRegionInfo hri : regions) {
if (hri.isMetaRegion() || hri.isRootRegion()) {
ret.add(hri);
}
}
return ret;
}
}

/**
Expand Down Expand Up @@ -1164,6 +1188,14 @@ void setSummary() {
summary = true;
}

/**
* Set META check mode.
* Print only info about META table deployment/state
*/
void setCheckMetaOnly() {
checkMetaOnly = true;
}

/**
* Check if we should rerun fsck again. This checks if we've tried to
* fix something and we should rerun fsck tool again.
Expand Down Expand Up @@ -1210,7 +1242,7 @@ protected static void printUsageAndExit() {
System.err.println(" -sleepBeforeRerun {timeInSeconds} Sleep this many seconds" +
" before checking if the fix worked if run with -fix");
System.err.println(" -summary Print only summary of the tables and status.");

System.err.println(" -metaonly Only check the state of ROOT and META tables.");
Runtime.getRuntime().exit(-2);
}

Expand Down Expand Up @@ -1261,6 +1293,8 @@ public static void main(String [] args) throws Exception {
fsck.setFixErrors(true);
} else if (cmd.equals("-summary")) {
fsck.setSummary();
} else if (cmd.equals("-metaonly")) {
fsck.setCheckMetaOnly();
} else {
String str = "Unknown command line option : " + cmd;
LOG.info(str);
Expand Down

0 comments on commit 340a3c4

Please sign in to comment.