Skip to content

Commit

Permalink
HBASE-16314 Retry on table snapshot failure during full backup (Vladi…
Browse files Browse the repository at this point in the history
…mir Rodionov)
  • Loading branch information
tedyu committed Apr 21, 2017
1 parent a3b6f4a commit e95cf47
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ public interface BackupRestoreConstants {
public final static int BACKUP_SYSTEM_TTL_DEFAULT = HConstants.FOREVER;
public final static String BACKUP_ENABLE_KEY = "hbase.backup.enable";
public final static boolean BACKUP_ENABLE_DEFAULT = false;


public static final String BACKUP_MAX_ATTEMPTS_KEY = "hbase.backup.attempts.max";
public static final int DEFAULT_BACKUP_MAX_ATTEMPTS = 10;

public static final String BACKUP_ATTEMPTS_PAUSE_MS_KEY = "hbase.backup.attempts.pause.ms";
public static final int DEFAULT_BACKUP_ATTEMPTS_PAUSE_MS = 10000;



/*
* Drivers option list
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@

package org.apache.hadoop.hbase.backup.impl;

import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.BACKUP_ATTEMPTS_PAUSE_MS_KEY;
import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.BACKUP_MAX_ATTEMPTS_KEY;
import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.DEFAULT_BACKUP_ATTEMPTS_PAUSE_MS;
import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.DEFAULT_BACKUP_MAX_ATTEMPTS;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -148,8 +153,7 @@ public void execute() throws IOException {
"snapshot_" + Long.toString(EnvironmentEdgeManager.currentTime()) + "_"
+ tableName.getNamespaceAsString() + "_" + tableName.getQualifierAsString();

admin.snapshot(snapshotName, tableName);

snapshotTable(admin, tableName, snapshotName);
backupInfo.setSnapshotName(tableName, snapshotName);
}

Expand Down Expand Up @@ -186,4 +190,32 @@ public void execute() throws IOException {

}

private void snapshotTable(Admin admin, TableName tableName, String snapshotName)
throws IOException {

int maxAttempts =
conf.getInt(BACKUP_MAX_ATTEMPTS_KEY, DEFAULT_BACKUP_MAX_ATTEMPTS);
int pause =
conf.getInt(BACKUP_ATTEMPTS_PAUSE_MS_KEY, DEFAULT_BACKUP_ATTEMPTS_PAUSE_MS);
int attempts = 0;

while (attempts++ < maxAttempts) {
try {
admin.snapshot(snapshotName, tableName);
return;
} catch (IOException ee) {
LOG.warn("Snapshot attempt " + attempts + " failed for table " + tableName
+ ", sleeping for " + pause + "ms", ee);
if (attempts < maxAttempts) {
try {
Thread.sleep(pause);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
}
}
throw new IOException("Failed to snapshot table "+ tableName);
}
}

0 comments on commit e95cf47

Please sign in to comment.