-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HBASE-28562 Correct backup ancestor calculation #5868
Merged
ndimiduk
merged 5 commits into
apache:master
from
DieterDP-ng:Hbase-28562_Backup_ancestor_location
Jun 6, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7256354
HBASE-28562 Correct backup ancestor calculation
DieterDP-ng adc75b3
HBASE-28562 Correct backup ancestor calculation
DieterDP-ng 89d764d
Run spotless:apply
DieterDP-ng 3e8f2e9
Move BackupManager#getAncestors
DieterDP-ng cac1257
Process review comments.
DieterDP-ng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,12 @@ | |
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.FileStatus; | ||
import org.apache.hadoop.fs.FileSystem; | ||
|
@@ -271,8 +275,8 @@ public static void cleanupAndRestoreBackupSystem(Connection conn, BackupInfo bac | |
* @param backupInfo The current backup info | ||
* @throws IOException exception | ||
*/ | ||
protected void addManifest(BackupInfo backupInfo, BackupManager backupManager, BackupType type, | ||
Configuration conf) throws IOException { | ||
protected void addManifest(BackupInfo backupInfo, BackupType type, Configuration conf) | ||
throws IOException { | ||
// set the overall backup phase : store manifest | ||
backupInfo.setPhase(BackupPhase.STORE_MANIFEST); | ||
|
||
|
@@ -281,13 +285,65 @@ protected void addManifest(BackupInfo backupInfo, BackupManager backupManager, B | |
// set the table region server start and end timestamps for incremental backup | ||
manifest.setIncrTimestampMap(backupInfo.getIncrTimestampMap()); | ||
} | ||
ArrayList<BackupImage> ancestors = backupManager.getAncestors(backupInfo); | ||
List<BackupImage> ancestors = getAncestors(backupInfo); | ||
for (BackupImage image : ancestors) { | ||
manifest.addDependentImage(image); | ||
} | ||
manifest.store(conf); | ||
} | ||
|
||
/** | ||
* Gets the direct ancestors of the currently being created backup. | ||
* @param backupInfo The backup info for the backup being created | ||
*/ | ||
protected List<BackupImage> getAncestors(BackupInfo backupInfo) throws IOException { | ||
LOG.debug("Getting the direct ancestors of the current backup {}", backupInfo.getBackupId()); | ||
|
||
// Full backups do not have ancestors | ||
if (backupInfo.getType() == BackupType.FULL) { | ||
LOG.debug("Current backup is a full backup, no direct ancestor for it."); | ||
return Collections.emptyList(); | ||
} | ||
|
||
List<BackupImage> ancestors = new ArrayList<>(); | ||
Set<TableName> tablesToCover = new HashSet<>(backupInfo.getTables()); | ||
|
||
// Go over the backup history list from newest to oldest | ||
List<BackupInfo> allHistoryList = backupManager.getBackupHistory(true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this |
||
for (BackupInfo backup : allHistoryList) { | ||
// If the image has a different rootDir, it cannot be an ancestor. | ||
if (!Objects.equals(backup.getBackupRootDir(), backupInfo.getBackupRootDir())) { | ||
continue; | ||
} | ||
|
||
BackupImage.Builder builder = BackupImage.newBuilder(); | ||
BackupImage image = builder.withBackupId(backup.getBackupId()).withType(backup.getType()) | ||
.withRootDir(backup.getBackupRootDir()).withTableList(backup.getTableNames()) | ||
.withStartTime(backup.getStartTs()).withCompleteTime(backup.getCompleteTs()).build(); | ||
|
||
// The ancestors consist of the most recent FULL backups that cover the list of tables | ||
// required in the new backup and all INCREMENTAL backups that came after one of those FULL | ||
// backups. | ||
if (backup.getType().equals(BackupType.INCREMENTAL)) { | ||
ancestors.add(image); | ||
LOG.debug("Dependent incremental backup image: {BackupID={}}", image.getBackupId()); | ||
} else { | ||
if (tablesToCover.removeAll(new HashSet<>(image.getTableNames()))) { | ||
ancestors.add(image); | ||
LOG.debug("Dependent full backup image: {BackupID={}}", image.getBackupId()); | ||
|
||
if (tablesToCover.isEmpty()) { | ||
LOG.debug("Got {} ancestors for the current backup.", ancestors.size()); | ||
return Collections.unmodifiableList(ancestors); | ||
} | ||
} | ||
} | ||
} | ||
|
||
throw new IllegalStateException( | ||
"Unable to find full backup that contains tables: " + tablesToCover); | ||
} | ||
|
||
/** | ||
* Get backup request meta data dir as string. | ||
* @param backupInfo backup info | ||
|
@@ -312,15 +368,15 @@ protected String obtainBackupMetaDataStr(BackupInfo backupInfo) { | |
* @param backupInfo backup info | ||
* @throws IOException exception | ||
*/ | ||
protected void completeBackup(final Connection conn, BackupInfo backupInfo, | ||
BackupManager backupManager, BackupType type, Configuration conf) throws IOException { | ||
protected void completeBackup(final Connection conn, BackupInfo backupInfo, BackupType type, | ||
Configuration conf) throws IOException { | ||
// set the complete timestamp of the overall backup | ||
backupInfo.setCompleteTs(EnvironmentEdgeManager.currentTime()); | ||
// set overall backup status: complete | ||
backupInfo.setState(BackupState.COMPLETE); | ||
backupInfo.setProgress(100); | ||
// add and store the manifest for the backup | ||
addManifest(backupInfo, backupManager, type, conf); | ||
addManifest(backupInfo, type, conf); | ||
|
||
// compose the backup complete data | ||
String backupCompleteData = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the ancestors be a
Set
so that we don't end up with multiple entries for the same ancestor?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a need for it. Since we're iterating over a list of unique possible ancestors, we can't end up with duplicates.