Skip to content
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-28996: Implement Custom ReplicationEndpoint to Enable WAL Backup to External Storage #6518

Draft
wants to merge 5 commits into
base: HBASE-28957
Choose a base branch
from

Conversation

vinayakphegde
Copy link
Contributor

This PR implements a custom ReplicationEndpoint for HBase to enable WAL backup to external storage. It introduces several components including ContinuousBackupReplicationEndpoint, ContinuousBackupManager, and StagedBulkloadFileRegistry, among others, to handle the backup process efficiently.

@Apache-HBase

This comment has been minimized.

@Apache-HBase

This comment has been minimized.

@anmolnar
Copy link
Contributor

anmolnar commented Dec 4, 2024

@vinayakphegde You need to add ASF license header to all new files.
You also need to run mvn spotless:apply to fix code style issues.

@Apache-HBase

This comment has been minimized.

@Apache-HBase

This comment has been minimized.

@Apache-HBase
Copy link

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 41s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+0 🆗 buf 0m 0s buf was not available.
+0 🆗 buf 0m 0s buf was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 hbaseanti 0m 0s Patch does not have any anti-patterns.
_ HBASE-28957 Compile Tests _
+0 🆗 mvndep 0m 43s Maven dependency ordering for branch
+1 💚 mvninstall 3m 31s HBASE-28957 passed
+1 💚 compile 1m 5s HBASE-28957 passed
+1 💚 checkstyle 0m 17s HBASE-28957 passed
+1 💚 spotbugs 2m 51s HBASE-28957 passed
+1 💚 spotless 0m 46s branch has no errors when running spotless:check.
_ Patch Compile Tests _
+0 🆗 mvndep 0m 11s Maven dependency ordering for patch
+1 💚 mvninstall 3m 5s the patch passed
+1 💚 compile 1m 19s the patch passed
+1 💚 cc 1m 19s the patch passed
-0 ⚠️ javac 0m 30s /results-compile-javac-hbase-backup.txt hbase-backup generated 2 new + 102 unchanged - 0 fixed = 104 total (was 102)
+1 💚 blanks 0m 0s The patch has no blanks issues.
-0 ⚠️ checkstyle 0m 9s /results-checkstyle-hbase-backup.txt hbase-backup: The patch generated 3 new + 0 unchanged - 0 fixed = 3 total (was 0)
+1 💚 spotbugs 3m 17s the patch passed
+1 💚 hadoopcheck 11m 52s Patch does not cause any errors with Hadoop 3.3.6 3.4.0.
+1 💚 hbaseprotoc 1m 5s the patch passed
+1 💚 spotless 0m 44s patch has no errors when running spotless:check.
_ Other Tests _
+1 💚 asflicense 0m 17s The patch does not generate ASF License warnings.
39m 27s
Subsystem Report/Notes
Docker ClientAPI=1.43 ServerAPI=1.43 base: https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6518/3/artifact/yetus-general-check/output/Dockerfile
GITHUB PR #6518
JIRA Issue HBASE-28996
Optional Tests dupname asflicense javac spotbugs checkstyle codespell detsecrets compile hadoopcheck hbaseanti spotless cc buflint bufcompat hbaseprotoc
uname Linux 96564ffaa421 5.4.0-1103-aws #111~18.04.1-Ubuntu SMP Tue May 23 20:04:10 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/hbase-personality.sh
git revision HBASE-28957 / 9f581d5
Default Java Eclipse Adoptium-17.0.11+9
Max. process+thread count 86 (vs. ulimit of 30000)
modules C: hbase-protocol-shaded hbase-backup U: .
Console output https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6518/3/console
versions git=2.34.1 maven=3.9.8 spotbugs=4.7.3
Powered by Apache Yetus 0.15.0 https://yetus.apache.org

This message was automatically generated.

@Apache-HBase
Copy link

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 52s Docker mode activated.
-0 ⚠️ yetus 0m 4s Unprocessed flag(s): --brief-report-file --spotbugs-strict-precheck --author-ignore-list --blanks-eol-ignore-file --blanks-tabs-ignore-file --quick-hadoopcheck
_ Prechecks _
_ HBASE-28957 Compile Tests _
+0 🆗 mvndep 0m 12s Maven dependency ordering for branch
+1 💚 mvninstall 4m 15s HBASE-28957 passed
+1 💚 compile 1m 11s HBASE-28957 passed
+1 💚 javadoc 0m 39s HBASE-28957 passed
+1 💚 shadedjars 7m 20s branch has no errors when building our shaded downstream artifacts.
_ Patch Compile Tests _
+0 🆗 mvndep 0m 14s Maven dependency ordering for patch
+1 💚 mvninstall 3m 40s the patch passed
+1 💚 compile 1m 25s the patch passed
+1 💚 javac 1m 25s the patch passed
+1 💚 javadoc 0m 32s the patch passed
+1 💚 shadedjars 6m 46s patch has no errors when building our shaded downstream artifacts.
_ Other Tests _
+1 💚 unit 0m 34s hbase-protocol-shaded in the patch passed.
-1 ❌ unit 20m 37s /patch-unit-hbase-backup.txt hbase-backup in the patch failed.
49m 39s
Subsystem Report/Notes
Docker ClientAPI=1.47 ServerAPI=1.47 base: https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6518/3/artifact/yetus-jdk17-hadoop3-check/output/Dockerfile
GITHUB PR #6518
JIRA Issue HBASE-28996
Optional Tests javac javadoc unit compile shadedjars
uname Linux 70b0ec1b100c 5.4.0-200-generic #220-Ubuntu SMP Fri Sep 27 13:19:16 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/hbase-personality.sh
git revision HBASE-28957 / 9f581d5
Default Java Eclipse Adoptium-17.0.11+9
Test Results https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6518/3/testReport/
Max. process+thread count 3603 (vs. ulimit of 30000)
modules C: hbase-protocol-shaded hbase-backup U: .
Console output https://ci-hbase.apache.org/job/HBase-PreCommit-GitHub-PR/job/PR-6518/3/console
versions git=2.34.1 maven=3.9.8
Powered by Apache Yetus 0.15.0 https://yetus.apache.org

This message was automatically generated.

Copy link
Contributor

@anmolnar anmolnar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments.

Comment on lines +63 to +68
if (backupFs.exists(dirPath)) {
LOG.info("{} Directory already exists: {}", Utils.logPeerId(peerId), dirPath);
} else {
backupFs.mkdirs(dirPath);
LOG.info("{} Successfully created directory: {}", Utils.logPeerId(peerId), dirPath);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How many HBase instances are running this code? Isn't there a race condition here?
Is this run by master only?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will run on region servers. I believe we can simplify the logic by directly using backupFs.mkdirs(dirPath). It will create the directory if it doesn't exist, and simply return true if the directory already exists.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be better.

@InterfaceAudience.Private
public class ContinuousBackupManager {
private static final Logger LOG = LoggerFactory.getLogger(ContinuousBackupManager.class);
public static final String CONF_BACKUP_ROOT_DIR = "hbase.backup.root.dir";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this root dir configured?
New full backup command will get a fully qualified backup path:

hbase backup create full s3a://my-hbase-bucket/backups/backup_0001 --continous

Is this for the staging area?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is for the wal backup location. We'll have the WAL backup location, which is passed to the ReplicationEndpoint via the Configuration. Essentially, this serves as the argument for the ReplicationEndpoint to determine where to back up the data.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the common WAL backup location that we talked about earlier, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

Comment on lines +211 to +214
continuousBackupWalWriter.write(walEntries, bulkLoadFiles);

// prevent bulk-loaded files from deleting HFileCleaner thread
stagedBulkloadFileRegistry.addStagedFiles(bulkLoadFiles);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might have a race here:

  1. bulkLoadFiles are written by WalWriter
  2. bulkLoadFiles gets added to the exception list for HFileCleaner

If HFileCleaner runs between these 2 events, it will delete files which recently have been staged. I'm not sure yet how to do this properly.

Copy link
Contributor Author

@vinayakphegde vinayakphegde Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, that scenario doesn't occur. The replication framework prevents the deletion of files using ReplicationHFileCleaner. Files are only deleted once the WALs and bulkload files are successfully replicated, as indicated by a success return from the replicate() method.
So, it the replicate() method is complete, it won't delete the file.

However, in our case, the bulkloaded files are still in the staging area and haven’t been copied yet. Therefore, we had to implement an additional cleaner for this purpose.


@Override
public boolean isFileDeletable(FileStatus fStat) {
// The actual deletion decision is made in getDeletableFiles, so returning true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?
Check if the file available for deletion here. Connection to HBase can be kept open.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single GET op to HBase checking if filename is present in the table should be quick.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach would be slightly faster, right? In getDeletableFiles, we could run the query once and process all the results together, instead of executing multiple queries.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about that. Currently you run a scanner while with my approach, you'll run multiple GETs. Generally speaking PUTs and GETs are the most performant operations in key-value stores, therefore they're preferred over scanners. But. The table is small, cached, etc.

Personally I don't like scanning the same table over and over again. It's like a Hashtable.

Comment on lines +90 to +92
// Fetch staged files from HBase
Set<String> stagedFiles = StagedBulkloadFileRegistry.listAllBulkloadFiles(connection);
LOG.debug("Fetched {} staged files from HBase.", stagedFiles.size());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to maintain the list of staged files in an HBase table?
Why not just return false (do not delete) if the file is in the staging area?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use special file name prefix while staging:

bulkload1.hfile
dontdelete_bulkload2.hfile
dontdelete_bulkload3.hfile

bulkload1.hfile can be deleted from staging area others should be kept. Rename operation is atomic in HDFS afaik.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the bulkload files, we are not moving them anywhere. They remain in the data directory or archive directory. We are simply maintaining a reference to them in the HBase table.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested another way (file renaming) to avoid accidentally deleting them. This way we could avoid maintaining an HBase table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants