.../apache/hadoop/hbase/backup/HFileArchiver.java | 86 ++++++++++------------ 1 file changed, 40 insertions(+), 46 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/HFileArchiver.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/HFileArchiver.java index 4da1235..c27f860 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/HFileArchiver.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/HFileArchiver.java @@ -25,8 +25,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; @@ -41,7 +39,8 @@ import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.HFileArchiveUtil; import org.apache.hadoop.io.MultipleIOException; import org.apache.yetus.audience.InterfaceAudience; - +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.apache.hadoop.hbase.shaded.com.google.common.base.Function; import org.apache.hadoop.hbase.shaded.com.google.common.base.Preconditions; import org.apache.hadoop.hbase.shaded.com.google.common.collect.Collections2; @@ -54,7 +53,7 @@ import org.apache.hadoop.hbase.shaded.com.google.common.collect.Lists; */ @InterfaceAudience.Private public class HFileArchiver { - private static final Log LOG = LogFactory.getLog(HFileArchiver.class); + private static final Logger LOG = LoggerFactory.getLogger(HFileArchiver.class); private static final String SEPARATOR = "."; /** Number of retries in case of fs operation failure */ @@ -110,15 +109,13 @@ public class HFileArchiver { */ public static boolean archiveRegion(FileSystem fs, Path rootdir, Path tableDir, Path regionDir) throws IOException { - if (LOG.isDebugEnabled()) { - LOG.debug("ARCHIVING " + regionDir.toString()); - } + LOG.debug("ARCHIVING {}", regionDir); // otherwise, we archive the files // make sure we can archive if (tableDir == null || regionDir == null) { - LOG.error("No archive directory could be found because tabledir (" + tableDir - + ") or regiondir (" + regionDir + "was null. Deleting files instead."); + LOG.error("No archive directory could be found because tabledir ({}) or " + + "regiondir ({}) was null. Deleting files instead.", tableDir, regionDir); deleteRegionWithoutArchiving(fs, regionDir); // we should have archived, but failed to. Doesn't matter if we deleted // the archived files correctly or not. @@ -146,13 +143,13 @@ public class HFileArchiver { FileStatus[] storeDirs = FSUtils.listStatus(fs, regionDir, nonHidden); // if there no files, we can just delete the directory and return; if (storeDirs == null) { - LOG.debug("Region directory " + regionDir + " empty."); + LOG.debug("Region directory {} empty.", regionDir); return deleteRegionWithoutArchiving(fs, regionDir); } // convert the files in the region to a File toArchive.addAll(Lists.transform(Arrays.asList(storeDirs), getAsFile)); - LOG.debug("Archiving " + toArchive); + LOG.debug("Archiving {}", toArchive); List failedArchive = resolveAndArchive(fs, regionArchiveDir, toArchive, EnvironmentEdgeManager.currentTime()); if (!failedArchive.isEmpty()) { @@ -195,8 +192,10 @@ public class HFileArchiver { RegionInfo parent, Path familyDir, byte[] family) throws IOException { FileStatus[] storeFiles = FSUtils.listStatus(fs, familyDir); if (storeFiles == null) { - LOG.debug("No store files to dispose for region=" + parent.getRegionNameAsString() + - ", family=" + Bytes.toString(family)); + if (LOG.isDebugEnabled()) { + LOG.debug("No store files to dispose for region={}, family={}", + parent.getRegionNameAsString(), Bytes.toString(family)); + } return; } @@ -231,8 +230,9 @@ public class HFileArchiver { // sometimes in testing, we don't have rss, so we need to check for that if (fs == null) { - LOG.warn("Passed filesystem is null, so just deleting the files without archiving for region:" - + Bytes.toString(regionInfo.getRegionName()) + ", family:" + Bytes.toString(family)); + LOG.warn("Passed filesystem is null, so just deleting the files without archiving for " + + "region: {}, family: {}", Bytes.toString(regionInfo.getRegionName()), + Bytes.toString(family)); deleteStoreFilesWithoutArchiving(compactedFiles); return; } @@ -256,7 +256,7 @@ public class HFileArchiver { } // otherwise we attempt to archive the store files - if (LOG.isDebugEnabled()) LOG.debug("Archiving compacted store files."); + LOG.debug("Archiving compacted store files."); // Wrap the storefile into a File StoreToFile getStorePath = new StoreToFile(fs); @@ -322,7 +322,7 @@ public class HFileArchiver { // short circuit if no files to move if (toArchive.isEmpty()) return Collections.emptyList(); - if (LOG.isTraceEnabled()) LOG.trace("moving files to the archive directory: " + baseArchiveDir); + LOG.trace("moving files to the archive directory: {}", baseArchiveDir); // make sure the archive directory exists if (!fs.exists(baseArchiveDir)) { @@ -330,7 +330,7 @@ public class HFileArchiver { throw new IOException("Failed to create the archive directory:" + baseArchiveDir + ", quitting archive attempt."); } - if (LOG.isTraceEnabled()) LOG.trace("Created archive directory:" + baseArchiveDir); + LOG.trace("Created archive directory: {}", baseArchiveDir); } List failures = new ArrayList<>(); @@ -338,16 +338,16 @@ public class HFileArchiver { for (File file : toArchive) { // if its a file archive it try { - if (LOG.isTraceEnabled()) LOG.trace("Archiving: " + file); + LOG.trace("Archiving: {}", file); if (file.isFile()) { // attempt to archive the file if (!resolveAndArchiveFile(baseArchiveDir, file, startTime)) { - LOG.warn("Couldn't archive " + file + " into backup directory: " + baseArchiveDir); + LOG.warn("Couldn't archive {} into backup directory: {}", file, baseArchiveDir); failures.add(file); } } else { // otherwise its a directory and we need to archive all files - if (LOG.isTraceEnabled()) LOG.trace(file + " is a directory, archiving children files"); + LOG.trace("{} is a directory, archiving children files", file); // so we add the directory name to the one base archive Path parentArchiveDir = new Path(baseArchiveDir, file.getName()); // and then get all the files from that directory and attempt to @@ -356,7 +356,7 @@ public class HFileArchiver { failures.addAll(resolveAndArchive(fs, parentArchiveDir, children, start)); } } catch (IOException e) { - LOG.warn("Failed to archive " + file, e); + LOG.warn("Failed to archive {}", file, e); failures.add(file); } } @@ -386,16 +386,14 @@ public class HFileArchiver { // really, really unlikely situtation, where we get the same name for the existing file, but // is included just for that 1 in trillion chance. if (fs.exists(archiveFile)) { - if (LOG.isDebugEnabled()) { - LOG.debug("File:" + archiveFile + " already exists in archive, moving to " - + "timestamped backup and overwriting current."); - } + LOG.debug("File: {} already exists in archive, moving to " + + "timestamped backup and overwriting current.", archiveFile); // move the archive file to the stamped backup Path backedupArchiveFile = new Path(archiveDir, filename + SEPARATOR + archiveStartTime); if (!fs.rename(archiveFile, backedupArchiveFile)) { - LOG.error("Could not rename archive file to backup: " + backedupArchiveFile - + ", deleting existing file in favor of newer."); + LOG.error("Could not rename archive file to backup: {}, " + + "deleting existing file in favor of newer.", backedupArchiveFile); // try to delete the exisiting file, if we can't rename it if (!fs.delete(archiveFile, false)) { throw new IOException("Couldn't delete existing archive file (" + archiveFile @@ -403,13 +401,11 @@ public class HFileArchiver { + ") to make room for similarly named file."); } } - LOG.debug("Backed up archive file from " + archiveFile); + LOG.debug("Backed up archive file from {}", archiveFile); } - if (LOG.isTraceEnabled()) { - LOG.trace("No existing file in archive for: " + archiveFile + - ", free to archive original file."); - } + LOG.trace("No existing file in archive for: {}, free to archive original file.", + archiveFile); // at this point, we should have a free spot for the archive file boolean success = false; @@ -422,34 +418,32 @@ public class HFileArchiver { try { if (!fs.exists(archiveDir)) { if (fs.mkdirs(archiveDir)) { - LOG.debug("Created archive directory:" + archiveDir); + LOG.debug("Created archive directory: {}", archiveDir); } } } catch (IOException e) { - LOG.warn("Failed to create directory: " + archiveDir, e); + LOG.warn("Failed to create directory: {}", archiveDir, e); } } try { success = currentFile.moveAndClose(archiveFile); } catch (FileNotFoundException fnfe) { - LOG.warn("Failed to archive " + currentFile + - " because it does not exist! Skipping and continuing on.", fnfe); + LOG.warn("Failed to archive {} because it does not exist! Skipping and continuing on.", + currentFile, fnfe); success = true; } catch (IOException e) { - LOG.warn("Failed to archive " + currentFile + " on try #" + i, e); + LOG.warn("Failed to archive {} on try #{}", currentFile, i, e); success = false; } } if (!success) { - LOG.error("Failed to archive " + currentFile); + LOG.error("Failed to archive {}", currentFile); return false; } - if (LOG.isDebugEnabled()) { - LOG.debug("Finished archiving from " + currentFile + ", to " + archiveFile); - } + LOG.debug("Finished archiving from {} to {}", currentFile, archiveFile); return true; } @@ -463,10 +457,10 @@ public class HFileArchiver { private static boolean deleteRegionWithoutArchiving(FileSystem fs, Path regionDir) throws IOException { if (fs.delete(regionDir, true)) { - LOG.debug("Deleted " + regionDir); + LOG.debug("Deleted {}", regionDir); return true; } - LOG.debug("Failed to delete region directory:" + regionDir); + LOG.debug("Failed to delete region directory: {}", regionDir); return false; } @@ -487,11 +481,11 @@ public class HFileArchiver { try { hsf.deleteStoreFile(); } catch (IOException e) { - LOG.error("Failed to delete store file:" + hsf.getPath()); + LOG.error("Failed to delete store file: {}", hsf.getPath()); errors.add(e); } } - if (errors.size() > 0) { + if (!errors.isEmpty()) { throw MultipleIOException.createIOException(errors); } }