From 1e414a44133891a66c1556382ff43ae031a00d30 Mon Sep 17 00:00:00 2001 From: Jonathan Hsieh Date: Wed, 13 Feb 2013 18:55:52 +0000 Subject: [PATCH] HBASE-7547 Fix findbugs warnings in snapshot classes (Ted Yu) git-svn-id: https://svn.apache.org/repos/asf/hbase/branches/hbase-7290@1445847 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/hadoop/hbase/client/HBaseAdmin.java | 2 +- .../master/snapshot/MasterSnapshotVerifier.java | 2 +- .../hbase/master/snapshot/SnapshotFileCache.java | 2 +- .../hadoop/hbase/snapshot/ExportSnapshot.java | 2 +- .../hbase/snapshot/ReferenceServerWALsTask.java | 11 +++++++---- .../hbase/snapshot/RestoreSnapshotHelper.java | 12 +++--------- .../apache/hadoop/hbase/snapshot/SnapshotInfo.java | 14 +++++++------- .../hadoop/hbase/snapshot/TakeSnapshotUtils.java | 2 +- 8 files changed, 22 insertions(+), 25 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index 4a75813d0e1..2870e23707c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -2441,7 +2441,7 @@ public class HBaseAdmin implements Abortable, Closeable { .setName(snapshotName).setTable(tableName).build(); // actually restore the snapshot - RestoreSnapshotResponse response = internalRestoreSnapshotAsync(snapshot); + internalRestoreSnapshotAsync(snapshot); final IsRestoreSnapshotDoneRequest request = IsRestoreSnapshotDoneRequest.newBuilder() .setSnapshot(snapshot).build(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/MasterSnapshotVerifier.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/MasterSnapshotVerifier.java index 8a5f5676193..eca7ab59f9b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/MasterSnapshotVerifier.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/MasterSnapshotVerifier.java @@ -219,7 +219,7 @@ public final class MasterSnapshotVerifier { String fileName = hfile.getPath().getName(); Path file = new Path(realCfDir, fileName); Path archived = new Path(archivedCfDir, fileName); - if (!fs.exists(file) && !fs.equals(archived)) { + if (!fs.exists(file) && !file.equals(archived)) { throw new CorruptedSnapshotException("Can't find hfile: " + hfile.getPath() + " in the real (" + archivedCfDir + ") or archive (" + archivedCfDir + ") directory for the primary table.", snapshot); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotFileCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotFileCache.java index c47ab0b43b5..0c9217bbf53 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotFileCache.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/snapshot/SnapshotFileCache.java @@ -275,7 +275,7 @@ public class SnapshotFileCache implements Stoppable { /** * Information about a snapshot directory */ - public class SnapshotDirectoryInfo { + private static class SnapshotDirectoryInfo { long lastModified; Collection files; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java index bf8aa46d907..16dce6270b0 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ExportSnapshot.java @@ -650,7 +650,7 @@ public final class ExportSnapshot extends Configured implements Tool { // ExportSnapshot private void printUsageAndExit() { - System.err.printf("Usage: bin/hbase %s [options]\n", getClass().getName()); + System.err.printf("Usage: bin/hbase %s [options]%n", getClass().getName()); System.err.println(" where [options] are:"); System.err.println(" -h|-help Show this help and exit."); System.err.println(" -snapshot NAME Snapshot to restore."); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ReferenceServerWALsTask.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ReferenceServerWALsTask.java index b0bdbfa2db2..9c987ab20e0 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ReferenceServerWALsTask.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/ReferenceServerWALsTask.java @@ -76,11 +76,14 @@ public class ReferenceServerWALsTask extends SnapshotTask { // Iterate through each of the log files and add a reference to it. // assumes that all the files under the server's logs directory is a log FileStatus[] serverLogs = FSUtils.listStatus(fs, logDir, null); - if (serverLogs == null) LOG.info("No logs for server directory:" + logDir - + ", done referencing files."); + if (serverLogs == null) { + LOG.debug("No logs for server directory:" + logDir + ", done referencing files."); + return null; + } - if (LOG.isDebugEnabled()) LOG.debug("Adding references for WAL files:" - + Arrays.toString(serverLogs)); + if (LOG.isDebugEnabled()) { + LOG.debug("Adding references for WAL files:" + Arrays.toString(serverLogs)); + } for (FileStatus file : serverLogs) { this.rethrowException(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/RestoreSnapshotHelper.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/RestoreSnapshotHelper.java index be3d8bdd13b..e7bebe98335 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/RestoreSnapshotHelper.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/RestoreSnapshotHelper.java @@ -41,14 +41,12 @@ import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.backup.HFileArchiver; -import org.apache.hadoop.hbase.catalog.MetaEditor; import org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher; import org.apache.hadoop.hbase.io.HFileLink; import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription; import org.apache.hadoop.hbase.regionserver.HRegion; import org.apache.hadoop.hbase.regionserver.StoreFile; import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.hbase.util.EnvironmentEdgeManager; import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.FSVisitor; import org.apache.hadoop.hbase.util.ModifyRegionUtils; @@ -132,8 +130,6 @@ public class RestoreSnapshotHelper { * @return the set of regions touched by the restore operation */ public RestoreMetaChanges restoreHdfsRegions() throws IOException { - long startTime = EnvironmentEdgeManager.currentTimeMillis(); - LOG.debug("starting restore"); Set snapshotRegionNames = SnapshotReferenceUtil.getSnapshotRegionNames(fs, snapshotDir); if (snapshotRegionNames == null) { @@ -152,7 +148,7 @@ public class RestoreSnapshotHelper { String regionName = regionInfo.getEncodedName(); if (snapshotRegionNames.contains(regionName)) { LOG.info("region to restore: " + regionName); - snapshotRegionNames.remove(regionInfo); + snapshotRegionNames.remove(regionName); metaChanges.addRegionToRestore(regionInfo); } else { LOG.info("region to remove: " + regionName); @@ -196,7 +192,7 @@ public class RestoreSnapshotHelper { /** * Describe the set of operations needed to update META after restore. */ - public class RestoreMetaChanges { + public static class RestoreMetaChanges { private List regionsToRestore = null; private List regionsToRemove = null; private List regionsToAdd = null; @@ -325,13 +321,11 @@ public class RestoreSnapshotHelper { // Add families not present in the table for (Map.Entry> familyEntry: snapshotFiles.entrySet()) { - byte[] family = Bytes.toBytes(familyEntry.getKey()); Path familyDir = new Path(regionDir, familyEntry.getKey()); if (!fs.mkdirs(familyDir)) { throw new IOException("Unable to create familyDir=" + familyDir); } - List hfilesToAdd = new LinkedList(); for (String hfileName: familyEntry.getValue()) { LOG.trace("Adding HFileLink " + hfileName + " to table=" + tableName); restoreStoreFile(familyDir, regionInfo, hfileName); @@ -384,7 +378,7 @@ public class RestoreSnapshotHelper { } // create the regions on disk - List clonedRegions = ModifyRegionUtils.createRegions(conf, tableDir.getParent(), + ModifyRegionUtils.createRegions(conf, tableDir.getParent(), tableDesc, clonedRegionsInfo, new ModifyRegionUtils.RegionFillTask() { public void fillRegion(final HRegion region) throws IOException { cloneRegion(region, snapshotRegions.get(region.getRegionInfo().getEncodedName())); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java index 571a9beabb7..d0256e2ccdc 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/SnapshotInfo.java @@ -210,7 +210,7 @@ public final class SnapshotInfo extends Configured implements Tool { } if (showFiles) { - System.out.printf("%8s %s/%s/%s/%s %s\n", + 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)" : "")); @@ -225,7 +225,7 @@ public final class SnapshotInfo extends Configured implements Tool { logsCount.addAndGet(1); if (showFiles) { - System.out.printf("%8s recovered.edits %s on region %s\n", + System.out.printf("%8s recovered.edits %s on region %s%n", StringUtils.humanReadableInt(size), logfile, region); } } @@ -243,7 +243,7 @@ public final class SnapshotInfo extends Configured implements Tool { } if (showFiles) { - System.out.printf("%8s log %s on server %s %s\n", + System.out.printf("%8s log %s on server %s %s%n", (size < 0 ? "-" : StringUtils.humanReadableInt(size)), logfile, server, (size < 0 ? "(NOT FOUND)" : "")); @@ -255,24 +255,24 @@ public final class SnapshotInfo extends Configured implements Tool { System.out.println(); if (hfilesMissing.get() > 0 || logsMissing.get() > 0) { System.out.println("**************************************************************"); - System.out.printf("BAD SNAPSHOT: %d hfile(s) and %d log(s) missing.\n", + System.out.printf("BAD SNAPSHOT: %d hfile(s) and %d log(s) missing.%n", hfilesMissing.get(), logsMissing.get()); System.out.println("**************************************************************"); } - System.out.printf("%d HFiles (%d in archive), total size %s (%.2f%% %s shared with the source table)\n", + System.out.printf("%d HFiles (%d in archive), total size %s (%.2f%% %s shared with the source table)%n", hfilesCount.get() + hfileArchiveCount.get(), hfileArchiveCount.get(), StringUtils.humanReadableInt(hfileSize.get() + hfileArchiveSize.get()), ((float)hfileSize.get() / (hfileSize.get() + hfileArchiveSize.get())) * 100, StringUtils.humanReadableInt(hfileSize.get()) ); - System.out.printf("%d Logs, total size %s\n", + System.out.printf("%d Logs, total size %s%n", logsCount.get(), StringUtils.humanReadableInt(logSize.get())); System.out.println(); } private void printUsageAndExit() { - System.err.printf("Usage: bin/hbase %s [options]\n", getClass().getName()); + System.err.printf("Usage: bin/hbase %s [options]%n", getClass().getName()); System.err.println(" where [options] are:"); System.err.println(" -h|-help Show this help and exit."); System.err.println(" -snapshot NAME Snapshot to examine."); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/TakeSnapshotUtils.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/TakeSnapshotUtils.java index c3bad50bf90..0eaad2eaf33 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/TakeSnapshotUtils.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/snapshot/TakeSnapshotUtils.java @@ -138,7 +138,7 @@ public class TakeSnapshotUtils { Multimap realLogs = getMapOfServersAndLogs(fs, logsDir, serverNames); if (realLogs != null) { assertNotNull(snapshot, "No server logs added to snapshot", snapshotLogs); - } else if (realLogs == null) { + } else { assertNull(snapshot, "Snapshotted server logs that don't exist", snapshotLogs); }