Skip to content

Commit 3160b36

Browse files
rmdmattinglyRay Mattingly
authored andcommitted
HBASE-28687 BackupSystemTable#checkSystemTable should ensure system tables are enabled (#6018)
Co-authored-by: Ray Mattingly <[email protected]> Signed-off-by: Bryan Beaudreault <[email protected]> Signed-off-by: Nick Dimiduk <[email protected]>
1 parent c908bb7 commit 3160b36

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupSystemTable.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.apache.hadoop.hbase.ServerName;
4848
import org.apache.hadoop.hbase.TableExistsException;
4949
import org.apache.hadoop.hbase.TableName;
50+
import org.apache.hadoop.hbase.TableNotDisabledException;
5051
import org.apache.hadoop.hbase.backup.BackupInfo;
5152
import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
5253
import org.apache.hadoop.hbase.backup.BackupRestoreConstants;
@@ -207,10 +208,12 @@ private void checkSystemTable() throws IOException {
207208
TableDescriptor backupHTD = BackupSystemTable.getSystemTableDescriptor(conf);
208209
createSystemTable(admin, backupHTD);
209210
}
211+
ensureTableEnabled(admin, tableName);
210212
if (!admin.tableExists(bulkLoadTableName)) {
211213
TableDescriptor blHTD = BackupSystemTable.getSystemTableForBulkLoadedDataDescriptor(conf);
212214
createSystemTable(admin, blHTD);
213215
}
216+
ensureTableEnabled(admin, bulkLoadTableName);
214217
waitForSystemTable(admin, tableName);
215218
waitForSystemTable(admin, bulkLoadTableName);
216219
}
@@ -1889,4 +1892,14 @@ private static byte[] rowkey(String s, String... other) {
18891892
}
18901893
return Bytes.toBytes(sb.toString());
18911894
}
1895+
1896+
private static void ensureTableEnabled(Admin admin, TableName tableName) throws IOException {
1897+
if (!admin.isTableEnabled(tableName)) {
1898+
try {
1899+
admin.enableTable(tableName);
1900+
} catch (TableNotDisabledException ignored) {
1901+
LOG.info("Table {} is not disabled, ignoring enable request", tableName);
1902+
}
1903+
}
1904+
}
18921905
}

hbase-backup/src/test/java/org/apache/hadoop/hbase/backup/TestBackupBase.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.io.IOException;
2121
import java.util.ArrayList;
22+
import java.util.Arrays;
2223
import java.util.HashMap;
2324
import java.util.Iterator;
2425
import java.util.List;
@@ -57,6 +58,7 @@
5758
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
5859
import org.apache.hadoop.hbase.master.cleaner.LogCleaner;
5960
import org.apache.hadoop.hbase.master.cleaner.TimeToLiveLogCleaner;
61+
import org.apache.hadoop.hbase.regionserver.LogRoller;
6062
import org.apache.hadoop.hbase.security.HadoopSecurityEnabledUserProviderForTesting;
6163
import org.apache.hadoop.hbase.security.UserProvider;
6264
import org.apache.hadoop.hbase.security.access.SecureTestUtil;
@@ -67,6 +69,7 @@
6769
import org.apache.hadoop.hbase.wal.AbstractFSWALProvider;
6870
import org.apache.hadoop.hbase.wal.WALFactory;
6971
import org.junit.AfterClass;
72+
import org.junit.Before;
7073
import org.junit.BeforeClass;
7174
import org.slf4j.Logger;
7275
import org.slf4j.LoggerFactory;
@@ -115,6 +118,38 @@ public IncrementalTableBackupClientForTest(Connection conn, String backupId,
115118
super(conn, backupId, request);
116119
}
117120

121+
@Before
122+
public void ensurePreviousBackupTestsAreCleanedUp() throws Exception {
123+
// Every operation here may not be necessary for any given test,
124+
// some often being no-ops. the goal is to help ensure atomicity
125+
// of that tests that implement TestBackupBase
126+
try (BackupAdmin backupAdmin = getBackupAdmin()) {
127+
backupManager.finishBackupSession();
128+
backupAdmin.listBackupSets().forEach(backupSet -> {
129+
try {
130+
backupAdmin.deleteBackupSet(backupSet.getName());
131+
} catch (IOException ignored) {
132+
}
133+
});
134+
} catch (Exception ignored) {
135+
}
136+
Arrays.stream(TEST_UTIL.getAdmin().listTableNames())
137+
.filter(tableName -> !tableName.isSystemTable()).forEach(tableName -> {
138+
try {
139+
TEST_UTIL.truncateTable(tableName);
140+
} catch (IOException ignored) {
141+
}
142+
});
143+
TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads().forEach(rst -> {
144+
try {
145+
LogRoller walRoller = rst.getRegionServer().getWalRoller();
146+
walRoller.requestRollAll();
147+
walRoller.waitUntilWalRollFinished();
148+
} catch (Exception ignored) {
149+
}
150+
});
151+
}
152+
118153
@Override
119154
public void execute() throws IOException {
120155
// case INCREMENTAL_COPY:
@@ -468,7 +503,7 @@ private BackupInfo getBackupInfo(String backupId) throws IOException {
468503
}
469504
}
470505

471-
protected BackupAdmin getBackupAdmin() throws IOException {
506+
protected static BackupAdmin getBackupAdmin() throws IOException {
472507
return new BackupAdminImpl(TEST_UTIL.getConnection());
473508
}
474509

0 commit comments

Comments
 (0)