HBASE-20181 Logging and minor logic improvements in BackupLogCleaner
This commit is contained in:
parent
b7308ee01c
commit
5bfc5745ab
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue