42
42
43
43
import java .io .IOException ;
44
44
import java .net .URI ;
45
+ import java .util .Arrays ;
45
46
import java .util .List ;
46
47
import org .apache .commons .lang3 .StringUtils ;
47
48
import org .apache .hadoop .conf .Configuration ;
@@ -258,7 +259,7 @@ public static class CreateCommand extends Command {
258
259
259
260
@ Override
260
261
protected boolean requiresNoActiveSession () {
261
- return true ;
262
+ return false ;
262
263
}
263
264
264
265
@ Override
@@ -335,12 +336,12 @@ public void execute() throws IOException {
335
336
System .setProperty ("mapreduce.job.queuename" , queueName );
336
337
}
337
338
339
+ List <TableName > tablesList = Lists .newArrayList (BackupUtils .parseTableNames (tables ));
340
+
338
341
try (BackupAdminImpl admin = new BackupAdminImpl (conn )) {
339
342
BackupRequest .Builder builder = new BackupRequest .Builder ();
340
343
BackupRequest request = builder .withBackupType (BackupType .valueOf (args [1 ].toUpperCase ()))
341
- .withTableList (
342
- tables != null ? Lists .newArrayList (BackupUtils .parseTableNames (tables )) : null )
343
- .withTargetRootDir (targetBackupDir ).withTotalTasks (workers )
344
+ .withTableList (tablesList ).withTargetRootDir (targetBackupDir ).withTotalTasks (workers )
344
345
.withBandwidthPerTasks (bandwidth ).withBackupSetName (setName ).build ();
345
346
String backupId = admin .backupTables (request );
346
347
System .out .println ("Backup session " + backupId + " finished. Status: SUCCESS" );
@@ -672,35 +673,35 @@ public void execute() throws IOException {
672
673
try (final Connection conn = ConnectionFactory .createConnection (conf );
673
674
final BackupSystemTable sysTable = new BackupSystemTable (conn )) {
674
675
// Failed backup
675
- BackupInfo backupInfo ;
676
- List <BackupInfo > list = sysTable .getBackupInfos (BackupState .RUNNING );
677
- if (list .size () == 0 ) {
676
+ List <BackupInfo > backupInfos = sysTable .getBackupInfos (BackupState .RUNNING );
677
+ if (backupInfos .size () == 0 ) {
678
678
// No failed sessions found
679
679
System .out .println ("REPAIR status: no failed sessions found."
680
680
+ " Checking failed delete backup operation ..." );
681
681
repairFailedBackupDeletionIfAny (conn , sysTable );
682
682
repairFailedBackupMergeIfAny (conn , sysTable );
683
683
return ;
684
684
}
685
- backupInfo = list .get (0 );
686
- // If this is a cancel exception, then we've already cleaned.
687
- // set the failure timestamp of the overall backup
688
- backupInfo .setCompleteTs (EnvironmentEdgeManager .currentTime ());
689
- // set failure message
690
- backupInfo .setFailedMsg ("REPAIR status: repaired after failure:\n " + backupInfo );
691
- // set overall backup status: failed
692
- backupInfo .setState (BackupState .FAILED );
693
- // compose the backup failed data
694
- String backupFailedData = "BackupId=" + backupInfo .getBackupId () + ",startts="
695
- + backupInfo .getStartTs () + ",failedts=" + backupInfo .getCompleteTs () + ",failedphase="
696
- + backupInfo .getPhase () + ",failedmessage=" + backupInfo .getFailedMsg ();
697
- System .out .println (backupFailedData );
698
- TableBackupClient .cleanupAndRestoreBackupSystem (conn , backupInfo , conf );
699
- // If backup session is updated to FAILED state - means we
700
- // processed recovery already.
701
- sysTable .updateBackupInfo (backupInfo );
702
- sysTable .finishBackupExclusiveOperation ();
703
- System .out .println ("REPAIR status: finished repair failed session:\n " + backupInfo );
685
+ for (BackupInfo backupInfo : backupInfos ) {
686
+ // If this is a cancel exception, then we've already cleaned.
687
+ // set the failure timestamp of the overall backup
688
+ backupInfo .setCompleteTs (EnvironmentEdgeManager .currentTime ());
689
+ // set failure message
690
+ backupInfo .setFailedMsg ("REPAIR status: repaired after failure:\n " + backupInfo );
691
+ // set overall backup status: failed
692
+ backupInfo .setState (BackupState .FAILED );
693
+ // compose the backup failed data
694
+ String backupFailedData = "BackupId=" + backupInfo .getBackupId () + ",startts="
695
+ + backupInfo .getStartTs () + ",failedts=" + backupInfo .getCompleteTs () + ",failedphase="
696
+ + backupInfo .getPhase () + ",failedmessage=" + backupInfo .getFailedMsg ();
697
+ System .out .println (backupFailedData );
698
+ TableBackupClient .cleanupAndRestoreBackupSystem (conn , backupInfo , conf );
699
+ // If backup session is updated to FAILED state - means we
700
+ // processed recovery already.
701
+ sysTable .updateBackupInfo (backupInfo );
702
+ sysTable .finishBackupExclusiveOperation (Arrays .asList (backupInfo .getBackupId ()));
703
+ System .out .println ("REPAIR status: finished repair failed session:\n " + backupInfo );
704
+ }
704
705
}
705
706
}
706
707
@@ -709,16 +710,12 @@ private void repairFailedBackupDeletionIfAny(Connection conn, BackupSystemTable
709
710
String [] backupIds = sysTable .getListOfBackupIdsFromDeleteOperation ();
710
711
if (backupIds == null || backupIds .length == 0 ) {
711
712
System .out .println ("No failed backup DELETE operation found" );
712
- // Delete backup table snapshot if exists
713
- BackupSystemTable .deleteSnapshot (conn );
714
713
return ;
715
714
}
716
715
System .out .println ("Found failed DELETE operation for: " + StringUtils .join (backupIds ));
717
716
System .out .println ("Running DELETE again ..." );
718
- // Restore table from snapshot
719
- BackupSystemTable .restoreFromSnapshot (conn );
720
717
// Finish previous failed session
721
- sysTable .finishBackupExclusiveOperation ();
718
+ sysTable .finishBackupExclusiveOperation (Arrays . asList ( backupIds ) );
722
719
try (BackupAdmin admin = new BackupAdminImpl (conn )) {
723
720
admin .deleteBackups (backupIds );
724
721
}
@@ -731,8 +728,6 @@ public static void repairFailedBackupMergeIfAny(Connection conn, BackupSystemTab
731
728
String [] backupIds = sysTable .getListOfBackupIdsFromMergeOperation ();
732
729
if (backupIds == null || backupIds .length == 0 ) {
733
730
System .out .println ("No failed backup MERGE operation found" );
734
- // Delete backup table snapshot if exists
735
- BackupSystemTable .deleteSnapshot (conn );
736
731
return ;
737
732
}
738
733
System .out .println ("Found failed MERGE operation for: " + StringUtils .join (backupIds ));
@@ -758,10 +753,8 @@ public static void repairFailedBackupMergeIfAny(Connection conn, BackupSystemTab
758
753
} else {
759
754
checkRemoveBackupImages (fs , backupRoot , backupIds );
760
755
}
761
- // Restore table from snapshot
762
- BackupSystemTable .restoreFromSnapshot (conn );
763
756
// Unlock backup system
764
- sysTable .finishBackupExclusiveOperation ();
757
+ sysTable .finishBackupExclusiveOperation (Arrays . asList ( backupIds ) );
765
758
// Finish previous failed session
766
759
sysTable .finishMergeOperation ();
767
760
0 commit comments