Repository: hbase
Updated Branches:
  refs/heads/master b7308ee01 -> 5bfc5745a


HBASE-20181 Logging and minor logic improvements in BackupLogCleaner


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/5bfc5745
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/5bfc5745
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/5bfc5745

Branch: refs/heads/master
Commit: 5bfc5745ab8e94d09851980dce2e243620f412ff
Parents: b7308ee
Author: Apekshit Sharma <a...@apache.org>
Authored: Wed Mar 14 09:56:46 2018 +0530
Committer: Apekshit Sharma <a...@apache.org>
Committed: Wed Mar 14 09:56:46 2018 +0530

----------------------------------------------------------------------
 .../hbase/backup/master/BackupLogCleaner.java   | 35 +++++++++-----------
 1 file changed, 16 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/5bfc5745/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/master/BackupLogCleaner.java
----------------------------------------------------------------------
diff --git 
a/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/master/BackupLogCleaner.java
 
b/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/master/BackupLogCleaner.java
index bd13d6e..093ef76 100644
--- 
a/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/master/BackupLogCleaner.java
+++ 
b/hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/master/BackupLogCleaner.java
@@ -20,9 +20,11 @@ package org.apache.hadoop.hbase.backup.master;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.commons.collections.MapUtils;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.hbase.HBaseInterfaceAudience;
@@ -36,6 +38,7 @@ import org.apache.hadoop.hbase.master.HMaster;
 import org.apache.hadoop.hbase.master.MasterServices;
 import org.apache.hadoop.hbase.master.cleaner.BaseLogCleanerDelegate;
 import org.apache.yetus.audience.InterfaceAudience;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -55,8 +58,9 @@ public class BackupLogCleaner extends BaseLogCleanerDelegate {
 
   @Override
   public void init(Map<String, Object> params) {
-    if (params != null && params.containsKey(HMaster.MASTER)) {
-      MasterServices master = (MasterServices) params.get(HMaster.MASTER);
+    MasterServices master = (MasterServices) MapUtils.getObject(params,
+      HMaster.MASTER);
+    if (master != null) {
       conn = master.getConnection();
       if (getConf() == null) {
         super.setConf(conn.getConfiguration());
@@ -76,14 +80,11 @@ public class BackupLogCleaner extends 
BaseLogCleanerDelegate {
     // all members of this class are null if backup is disabled,
     // so we cannot filter the files
     if (this.getConf() == null || !BackupManager.isBackupEnabled(getConf())) {
-      if (LOG.isDebugEnabled()) {
-        LOG.debug("Backup is not enabled. Check your "
-            + BackupRestoreConstants.BACKUP_ENABLE_KEY + " setting");
-      }
+      LOG.debug("Backup is not enabled. Check your {} setting",
+          BackupRestoreConstants.BACKUP_ENABLE_KEY);
       return files;
     }
 
-    List<FileStatus> list = new ArrayList<>();
     try (final BackupSystemTable table = new BackupSystemTable(conn)) {
       // If we do not have recorded backup sessions
       try {
@@ -92,31 +93,28 @@ public class BackupLogCleaner extends 
BaseLogCleanerDelegate {
           return files;
         }
       } catch (TableNotFoundException tnfe) {
-        LOG.warn("backup system table is not available" + tnfe.getMessage());
+        LOG.warn("Backup system table is not available: {}", 
tnfe.getMessage());
         return files;
       }
 
+      List<FileStatus> list = new ArrayList<>();
       Map<FileStatus, Boolean> walFilesDeletableMap = 
table.areWALFilesDeletable(files);
       for (Map.Entry<FileStatus, Boolean> entry: 
walFilesDeletableMap.entrySet()) {
         FileStatus file = entry.getKey();
         String wal = file.getPath().toString();
         boolean deletable = entry.getValue();
         if (deletable) {
-          if (LOG.isDebugEnabled()) {
-            LOG.debug("Found log file in backup system table, deleting: " + 
wal);
-          }
+          LOG.debug("Found log file in backup system table, deleting: {}", 
wal);
           list.add(file);
         } else {
-          if (LOG.isDebugEnabled()) {
-            LOG.debug("Didn't find this log in backup system table, keeping: " 
+ wal);
-          }
+          LOG.debug("Did not find this log in backup system table, keeping: 
{}", wal);
         }
       }
       return list;
     } catch (IOException e) {
       LOG.error("Failed to get backup system table table, therefore will keep 
all files", e);
       // nothing to delete
-      return new ArrayList<>();
+      return Collections.emptyList();
     }
   }
 
@@ -132,11 +130,10 @@ public class BackupLogCleaner extends 
BaseLogCleanerDelegate {
 
   @Override
   public void stop(String why) {
-    if (this.stopped) {
-      return;
+    if (!this.stopped) {
+      this.stopped = true;
+      LOG.info("Stopping BackupLogCleaner");
     }
-    this.stopped = true;
-    LOG.info("Stopping BackupLogCleaner");
   }
 
   @Override

Reply via email to