You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2018/03/14 07:00:48 UTC
[2/2] hbase git commit: HBASE-20181 Logging and minor logic
improvements in BackupLogCleaner
HBASE-20181 Logging and minor logic improvements in BackupLogCleaner
Signed-off-by: Apekshit Sharma <ap...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/000a84cb
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/000a84cb
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/000a84cb
Branch: refs/heads/master
Commit: 000a84cb4afce33e6d6601f65955f2de9924cf8a
Parents: 810567f
Author: BELUGA BEHR <da...@gmail.com>
Authored: Wed Mar 14 09:56:46 2018 +0530
Committer: Apekshit Sharma <ap...@apache.org>
Committed: Wed Mar 14 12:30:04 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/000a84cb/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