HBASE-29846 Fix backup history ordering#7662
Conversation
| * @param n number of entries to return | ||
| */ | ||
| public List<BackupInfo> getBackupInfos(int n, BackupInfo.Filter... toInclude) throws IOException { | ||
| public List<BackupInfo> getBackupHistory(boolean newToOld, int n, BackupInfo.Filter... toInclude) |
There was a problem hiding this comment.
Strictly speaking, because the BackupInfos are stored using BackupIds as key, the ordering promised in this method will break over 261 years, when the epoch 9999999999 becomes 10000000000. This is a side effect of backupIds not being 0-padded when stored.
I.e., the scan would return out-of-order results:
backup_10000000000backup_9999999998backup_9999999999
But I guess that's acceptable.
|
@ndimiduk @hgromer, since you reviewed HBASE-29808, you're well suited for this PR too. |
|
🎊 +1 overall
This message was automatically generated. |
|
🎊 +1 overall
This message was automatically generated. |
| * @param n number of entries to return | ||
| */ | ||
| public List<BackupInfo> getBackupInfos(int n, BackupInfo.Filter... toInclude) throws IOException { | ||
| public List<BackupInfo> getBackupHistory(boolean newToOld, int n, BackupInfo.Filter... toInclude) |
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java
Outdated
Show resolved
Hide resolved
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java
Outdated
Show resolved
Hide resolved
| return Long.parseLong(Iterators.get(Splitter.on('_').split(backupId).iterator(), 1)); | ||
| } | ||
| }); | ||
| infos.sort(Comparator.comparing(BackupInfo::getBackupId).reversed()); |
There was a problem hiding this comment.
This is now a String sort, not a timestamp sort? Why not rely on the exiting Comparable<BackupInfo> implementation -- BackupInfo#compareTo() already does timestamp extraction and ordering. infos.sort(Comparator.reversed()) should do the trick.
There was a problem hiding this comment.
Not sure why I choose string sorting here. Possibly because it matches the sorting done in the HBASE scan, or simply because I hadn't noticed BackupInfo is Comparable out of the box.
Saw no disadvantage to using BackupInfo's sorting, so changed.
hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java
Outdated
Show resolved
Hide resolved
Restores the ordering of BackupAdmin#getHistory that was accidentally reversed in HBASE-29808. Extends & refactors TestBackupShowHistory to verify correct behavior. Fixes a possible FileNotFoundException in BackupUtils#getHistory. Merges BackupSystemTable#getBackupHistory with BackupSystemTable#getBackupInfos, to further simplify backup info retrieval. Optimized various usages of history retrieval. Clarified some javadoc regarding backup history retrieval.
c0bb414 to
ed04e2e
Compare
Restores the ordering of BackupAdmin#getHistory that was accidentally reversed in HBASE-29808. Extends & refactors TestBackupShowHistory to verify correct behavior.
Fixes a possible FileNotFoundException in BackupUtils#getHistory.
Merges BackupSystemTable#getBackupHistory with
BackupSystemTable#getBackupInfos, to further simplify backup info retrieval. Optimized various usages of history retrieval.
Clarified some javadoc regarding backup history retrieval.