Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.CONF_CONTINUOUS_BACKUP_WAL_DIR;
import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.DEFAULT_CONTINUOUS_BACKUP_PITR_WINDOW_DAYS;
import static org.apache.hadoop.hbase.backup.replication.BackupFileSystemManager.WALS_DIR;
import static org.apache.hadoop.hbase.backup.replication.ContinuousBackupReplicationEndpoint.DATE_FORMAT;
import static org.apache.hadoop.hbase.backup.replication.ContinuousBackupReplicationEndpoint.ONE_DAY_IN_MILLISECONDS;
import static org.apache.hadoop.hbase.backup.util.BackupUtils.DATE_FORMAT;
import static org.apache.hadoop.hbase.mapreduce.WALPlayer.IGNORE_EMPTY_FILES;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_WORKERS_DESC;
import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_YARN_QUEUE_NAME;
import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_YARN_QUEUE_NAME_DESC;
import static org.apache.hadoop.hbase.backup.replication.ContinuousBackupReplicationEndpoint.DATE_FORMAT;
import static org.apache.hadoop.hbase.backup.replication.ContinuousBackupReplicationEndpoint.ONE_DAY_IN_MILLISECONDS;
import static org.apache.hadoop.hbase.backup.util.BackupUtils.DATE_FORMAT;

import java.io.IOException;
import java.net.URI;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@

import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.CONF_CONTINUOUS_BACKUP_WAL_DIR;
import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.JOB_NAME_CONF_KEY;
import static org.apache.hadoop.hbase.backup.replication.BackupFileSystemManager.BULKLOAD_FILES_DIR;
import static org.apache.hadoop.hbase.backup.replication.BackupFileSystemManager.WALS_DIR;
import static org.apache.hadoop.hbase.backup.replication.ContinuousBackupReplicationEndpoint.DATE_FORMAT;
import static org.apache.hadoop.hbase.backup.replication.ContinuousBackupReplicationEndpoint.ONE_DAY_IN_MILLISECONDS;
import static org.apache.hadoop.hbase.backup.util.BackupUtils.DATE_FORMAT;

import java.io.IOException;
import java.net.URI;
Expand Down Expand Up @@ -166,6 +167,26 @@ protected List<BulkLoad> handleBulkLoad(List<TableName> tablesToBackup) throws I
Path tblDir = CommonFSUtils.getTableDir(rootdir, srcTable);
Path p = new Path(tblDir, regionName + Path.SEPARATOR + fam + Path.SEPARATOR + filename);

// For continuous backup: bulkload files are copied from backup directory defined by
// CONF_CONTINUOUS_BACKUP_WAL_DIR instead of source cluster.
String backupRootDir = conf.get(CONF_CONTINUOUS_BACKUP_WAL_DIR);
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] somehow, hbase.backup.continuous.wal.dir is become the root now for both WALs and Bulkloads, shouldn't we call it as hbase.backup.continuous.dir/hbase.backup.continuous.root.dir

Copy link
Author

Choose a reason for hiding this comment

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

Yes, makes sense. I will create a new JIRA to update this config from everywhere it is referenced

if (backupInfo.isContinuousBackupEnabled() && !Strings.isNullOrEmpty(backupRootDir)) {
String dayDirectoryName = BackupUtils.formatToDateString(bulkLoad.getTimestamp());
Path bulkLoadBackupPath =
new Path(backupRootDir, BULKLOAD_FILES_DIR + Path.SEPARATOR + dayDirectoryName);
Path bulkLoadDir = new Path(bulkLoadBackupPath,
srcTable.getNamespaceAsString() + Path.SEPARATOR + srcTable.getNameAsString());
FileSystem backupFs = FileSystem.get(bulkLoadDir.toUri(), conf);
Path fullBulkLoadBackupPath =
new Path(bulkLoadDir, regionName + Path.SEPARATOR + fam + Path.SEPARATOR + filename);
if (backupFs.exists(fullBulkLoadBackupPath)) {
LOG.debug("Backup bulkload file found {}", fullBulkLoadBackupPath);
p = fullBulkLoadBackupPath;
} else {
LOG.warn("Backup bulkload file not found {}", fullBulkLoadBackupPath);
Copy link
Contributor

Choose a reason for hiding this comment

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

I assumed we're hitting the following
1/ it does not have any bulkload previously,
2/ something is wrong?

so, should we ask user to check if this is expected in the warning message?

Copy link
Author

Choose a reason for hiding this comment

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

In non-continuous incremental backup approach, bulkload files are copied directly from the source cluster to the backup location.

In continuous backup approach, these files are instead copied from the bulkload backup location. I’ve added a warning here because if the required bulkload backup files are missing, they would be copied from the source cluster (as a fallback mechanism).

Source cluster files are only deleted after a successful full or incremental backup (in both non-continuous and continuous)

Ideally, with continuous backups, once a bulkload file has been backed up by the replication endpoint, it could be safely deleted from the source cluster. However, doing so would significantly complicate the checkpoint logic, since it would then depend on both WAL flushes and bulkload backups.

Copy link
Contributor

@taklwu taklwu Sep 8, 2025

Choose a reason for hiding this comment

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

In continuous backup approach, these files are instead copied from the bulkload backup location. I’ve added a warning here because if the required bulkload backup files are missing, they would be copied from the source cluster (as a fallback mechanism).

[nit] right, my concerns are the action after the WARN message, and current message does not clearly tell what the user should do when he see this, do you think we should add some suggestion in this message ?

we can improve it as a follow up JIRA or in the documentation, if user see this message , should they care about it? if so, what manual operation should they perform to get rid of it ?

}
}

String srcTableQualifier = srcTable.getQualifierAsString();
String srcTableNs = srcTable.getNamespaceAsString();
Path tgtFam = new Path(tgtRoot, srcTableNs + Path.SEPARATOR + srcTableQualifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
Expand All @@ -41,6 +38,7 @@
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
import org.apache.hadoop.hbase.backup.util.BackupUtils;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.io.asyncfs.monitor.StreamSlowMonitor;
Expand Down Expand Up @@ -94,7 +92,6 @@ public class ContinuousBackupReplicationEndpoint extends BaseReplicationEndpoint

public static final long ONE_DAY_IN_MILLISECONDS = TimeUnit.DAYS.toMillis(1);
public static final String WAL_FILE_PREFIX = "wal_file.";
public static final String DATE_FORMAT = "yyyy-MM-dd";

@Override
public void init(Context context) throws IOException {
Expand Down Expand Up @@ -330,7 +327,7 @@ private void backupWalEntries(long day, List<WAL.Entry> walEntries) throws IOExc
}

private FSHLogProvider.Writer createWalWriter(long dayInMillis) {
String dayDirectoryName = formatToDateString(dayInMillis);
String dayDirectoryName = BackupUtils.formatToDateString(dayInMillis);

FileSystem fs = backupFileSystemManager.getBackupFs();
Path walsDir = backupFileSystemManager.getWalsDir();
Expand Down Expand Up @@ -408,7 +405,7 @@ void uploadBulkLoadFiles(long dayInMillis, List<Path> bulkLoadFiles)
LOG.trace("{} Bulk load files to upload: {}", Utils.logPeerId(peerId),
bulkLoadFiles.stream().map(Path::toString).collect(Collectors.joining(", ")));
}
String dayDirectoryName = formatToDateString(dayInMillis);
String dayDirectoryName = BackupUtils.formatToDateString(dayInMillis);
Path bulkloadDir = new Path(backupFileSystemManager.getBulkLoadFilesDir(), dayDirectoryName);
try {
backupFileSystemManager.getBackupFs().mkdirs(bulkloadDir);
Expand Down Expand Up @@ -446,7 +443,7 @@ void uploadBulkLoadFiles(long dayInMillis, List<Path> bulkLoadFiles)
} catch (IOException e) {
throw new BulkLoadUploadException(
String.format("%s Failed to copy bulk load file %s to %s on day %s",
Utils.logPeerId(peerId), file, destPath, formatToDateString(dayInMillis)),
Utils.logPeerId(peerId), file, destPath, BackupUtils.formatToDateString(dayInMillis)),
e);
}
}
Expand Down Expand Up @@ -495,19 +492,6 @@ static void copyWithCleanup(FileSystem srcFS, Path src, FileSystem dstFS, Path d
}
}

/**
* Convert dayInMillis to "yyyy-MM-dd" format
*/
@RestrictedApi(
explanation = "Package-private for test visibility only. Do not use outside tests.",
link = "",
allowedOnPath = "(.*/src/test/.*|.*/org/apache/hadoop/hbase/backup/replication/ContinuousBackupReplicationEndpoint.java)")
String formatToDateString(long dayInMillis) {
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat.format(new Date(dayInMillis));
}

private Path getBulkLoadFileStagingPath(Path relativePathFromNamespace) throws IOException {
FileSystem rootFs = CommonFSUtils.getRootDirFileSystem(conf);
Path rootDir = CommonFSUtils.getRootDir(conf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TimeZone;
import java.util.TreeMap;
import java.util.TreeSet;
import org.apache.hadoop.conf.Configuration;
Expand Down Expand Up @@ -86,6 +89,7 @@ public final class BackupUtils {
private static final Logger LOG = LoggerFactory.getLogger(BackupUtils.class);
public static final String LOGNAME_SEPARATOR = ".";
public static final int MILLISEC_IN_HOUR = 3600000;
public static final String DATE_FORMAT = "yyyy-MM-dd";

private BackupUtils() {
throw new AssertionError("Instantiating utility class...");
Expand Down Expand Up @@ -932,4 +936,13 @@ private static boolean continuousBackupReplicationPeerExists(Admin admin) throws
return admin.listReplicationPeers().stream()
.anyMatch(peer -> peer.getPeerId().equals(CONTINUOUS_BACKUP_REPLICATION_PEER));
}

/**
* Convert dayInMillis to "yyyy-MM-dd" format
*/
public static String formatToDateString(long dayInMillis) {
SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return dateFormat.format(new Date(dayInMillis));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
*/
package org.apache.hadoop.hbase.backup;

import static org.apache.hadoop.hbase.HConstants.REPLICATION_BULKLOAD_ENABLE_KEY;
import static org.apache.hadoop.hbase.HConstants.REPLICATION_CLUSTER_ID;
import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.CONTINUOUS_BACKUP_REPLICATION_PEER;
import static org.apache.hadoop.hbase.backup.replication.ContinuousBackupReplicationEndpoint.CONF_BACKUP_MAX_WAL_SIZE;
import static org.apache.hadoop.hbase.backup.replication.ContinuousBackupReplicationEndpoint.CONF_STAGED_WAL_FLUSH_INITIAL_DELAY;
import static org.apache.hadoop.hbase.backup.replication.ContinuousBackupReplicationEndpoint.CONF_STAGED_WAL_FLUSH_INTERVAL;
import static org.apache.hadoop.hbase.mapreduce.WALPlayer.IGNORE_EMPTY_FILES;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -46,6 +49,7 @@
import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
import org.apache.hadoop.hbase.backup.impl.BackupAdminImpl;
import org.apache.hadoop.hbase.backup.impl.BackupManager;
import org.apache.hadoop.hbase.backup.impl.BackupManifest;
import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
import org.apache.hadoop.hbase.backup.impl.FullTableBackupClient;
import org.apache.hadoop.hbase.backup.impl.IncrementalBackupManager;
Expand Down Expand Up @@ -304,6 +308,9 @@ public static void setUpHelper() throws Exception {
conf1.set(CONF_BACKUP_MAX_WAL_SIZE, "10240");
conf1.set(CONF_STAGED_WAL_FLUSH_INITIAL_DELAY, "10");
conf1.set(CONF_STAGED_WAL_FLUSH_INTERVAL, "10");
conf1.setBoolean(REPLICATION_BULKLOAD_ENABLE_KEY, true);
conf1.set(REPLICATION_CLUSTER_ID, "clusterId1");
conf1.setBoolean(IGNORE_EMPTY_FILES, true);

if (secure) {
// set the always on security provider
Expand Down Expand Up @@ -571,6 +578,12 @@ protected void dumpBackupDir() throws IOException {
}
}

BackupManifest getLatestBackupManifest(List<BackupInfo> backups) throws IOException {
BackupInfo newestBackup = backups.get(0);
return HBackupFileSystem.getManifest(conf1, new Path(BACKUP_ROOT_DIR),
newestBackup.getBackupId());
}

void deleteContinuousBackupReplicationPeerIfExists(Admin admin) throws IOException {
if (
admin.listReplicationPeers().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.CONTINUOUS_BACKUP_REPLICATION_PEER;
import static org.apache.hadoop.hbase.backup.replication.BackupFileSystemManager.BULKLOAD_FILES_DIR;
import static org.apache.hadoop.hbase.backup.replication.BackupFileSystemManager.WALS_DIR;
import static org.apache.hadoop.hbase.backup.replication.ContinuousBackupReplicationEndpoint.DATE_FORMAT;
import static org.apache.hadoop.hbase.backup.replication.ContinuousBackupReplicationEndpoint.ONE_DAY_IN_MILLISECONDS;
import static org.apache.hadoop.hbase.backup.util.BackupUtils.DATE_FORMAT;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,6 @@ String[] buildBackupArgs(String backupType, TableName[] tables, boolean continuo
}
}

BackupManifest getLatestBackupManifest(List<BackupInfo> backups) throws IOException {
BackupInfo newestBackup = backups.get(0);
return HBackupFileSystem.getManifest(conf1, new Path(BACKUP_ROOT_DIR),
newestBackup.getBackupId());
}

private void verifyTableInBackupSystemTable(TableName table) throws IOException {
try (BackupSystemTable backupTable = new BackupSystemTable(TEST_UTIL.getConnection())) {
Map<TableName, Long> tableBackupMap = backupTable.getContinuousBackupTableSet();
Expand Down
Loading