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

HubSpot Backport: HBASE-28687 BackupSystemTable#checkSystemTable should ensure system tables are enabled (#6018) #103

Merged
merged 1 commit into from
Jul 8, 2024
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 @@ -47,6 +47,7 @@
import org.apache.hadoop.hbase.ServerName;
import org.apache.hadoop.hbase.TableExistsException;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.TableNotDisabledException;
import org.apache.hadoop.hbase.backup.BackupInfo;
import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
import org.apache.hadoop.hbase.backup.BackupRestoreConstants;
Expand Down Expand Up @@ -206,10 +207,12 @@ private void checkSystemTable() throws IOException {
TableDescriptor backupHTD = BackupSystemTable.getSystemTableDescriptor(conf);
createSystemTable(admin, backupHTD);
}
ensureTableEnabled(admin, tableName);
if (!admin.tableExists(bulkLoadTableName)) {
TableDescriptor blHTD = BackupSystemTable.getSystemTableForBulkLoadedDataDescriptor(conf);
createSystemTable(admin, blHTD);
}
ensureTableEnabled(admin, bulkLoadTableName);
waitForSystemTable(admin, tableName);
waitForSystemTable(admin, bulkLoadTableName);
}
Expand Down Expand Up @@ -1886,4 +1889,14 @@ private static byte[] rowkey(String s, String... other) {
}
return Bytes.toBytes(sb.toString());
}

private static void ensureTableEnabled(Admin admin, TableName tableName) throws IOException {
if (!admin.isTableEnabled(tableName)) {
try {
admin.enableTable(tableName);
} catch (TableNotDisabledException ignored) {
LOG.info("Table {} is not disabled, ignoring enable request", tableName);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -57,6 +58,7 @@
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.master.cleaner.LogCleaner;
import org.apache.hadoop.hbase.master.cleaner.TimeToLiveLogCleaner;
import org.apache.hadoop.hbase.regionserver.LogRoller;
import org.apache.hadoop.hbase.security.HadoopSecurityEnabledUserProviderForTesting;
import org.apache.hadoop.hbase.security.UserProvider;
import org.apache.hadoop.hbase.security.access.SecureTestUtil;
Expand All @@ -67,6 +69,7 @@
import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;
import org.apache.hadoop.hbase.wal.WALFactory;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -115,6 +118,38 @@ public IncrementalTableBackupClientForTest(Connection conn, String backupId,
super(conn, backupId, request);
}

@Before
public void ensurePreviousBackupTestsAreCleanedUp() throws Exception {
// Every operation here may not be necessary for any given test,
// some often being no-ops. the goal is to help ensure atomicity
// of that tests that implement TestBackupBase
try (BackupAdmin backupAdmin = getBackupAdmin()) {
backupManager.finishBackupSession();
backupAdmin.listBackupSets().forEach(backupSet -> {
try {
backupAdmin.deleteBackupSet(backupSet.getName());
} catch (IOException ignored) {
}
});
} catch (Exception ignored) {
}
Arrays.stream(TEST_UTIL.getAdmin().listTableNames())
.filter(tableName -> !tableName.isSystemTable()).forEach(tableName -> {
try {
TEST_UTIL.truncateTable(tableName);
} catch (IOException ignored) {
}
});
TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().forEach(rst -> {
try {
LogRoller walRoller = rst.getRegionServer().getWalRoller();
walRoller.requestRollAll();
walRoller.waitUntilWalRollFinished();
} catch (Exception ignored) {
}
});
}

@Override
public void execute() throws IOException {
// case INCREMENTAL_COPY:
Expand Down Expand Up @@ -468,7 +503,7 @@ private BackupInfo getBackupInfo(String backupId) throws IOException {
}
}

protected BackupAdmin getBackupAdmin() throws IOException {
protected static BackupAdmin getBackupAdmin() throws IOException {
return new BackupAdminImpl(TEST_UTIL.getConnection());
}

Expand Down