Skip to content

Commit 38aef80

Browse files
HBASE-28449 Fix backupSystemTable prefix scans (#5768)
Signed-off-by: Bryan Beaudreault <[email protected]>
1 parent f934af8 commit 38aef80

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,11 +1438,7 @@ private Put createPutForWriteRegionServerLogTimestamp(TableName table, byte[] sm
14381438
*/
14391439
private Scan createScanForReadLogTimestampMap(String backupRoot) {
14401440
Scan scan = new Scan();
1441-
byte[] startRow = rowkey(TABLE_RS_LOG_MAP_PREFIX, backupRoot);
1442-
byte[] stopRow = Arrays.copyOf(startRow, startRow.length);
1443-
stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1);
1444-
scan.withStartRow(startRow);
1445-
scan.withStopRow(stopRow);
1441+
scan.setStartStopRowForPrefixScan(rowkey(TABLE_RS_LOG_MAP_PREFIX, backupRoot, NULL));
14461442
scan.addFamily(BackupSystemTable.META_FAMILY);
14471443

14481444
return scan;
@@ -1479,11 +1475,7 @@ private Put createPutForRegionServerLastLogRollResult(String server, Long timest
14791475
*/
14801476
private Scan createScanForReadRegionServerLastLogRollResult(String backupRoot) {
14811477
Scan scan = new Scan();
1482-
byte[] startRow = rowkey(RS_LOG_TS_PREFIX, backupRoot);
1483-
byte[] stopRow = Arrays.copyOf(startRow, startRow.length);
1484-
stopRow[stopRow.length - 1] = (byte) (stopRow[stopRow.length - 1] + 1);
1485-
scan.withStartRow(startRow);
1486-
scan.withStopRow(stopRow);
1478+
scan.setStartStopRowForPrefixScan(rowkey(RS_LOG_TS_PREFIX, backupRoot, NULL));
14871479
scan.addFamily(BackupSystemTable.META_FAMILY);
14881480
scan.readVersions(1);
14891481

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,11 @@ public void testRegionServerLastLogRollResults() throws IOException {
190190
String[] servers = new String[] { "server1", "server2", "server3" };
191191
Long[] timestamps = new Long[] { 100L, 102L, 107L };
192192

193+
// validate the prefix scan in readRegionServerlastLogRollResult will get the right timestamps
194+
// when a backup root with the same prefix is present
193195
for (int i = 0; i < servers.length; i++) {
194196
table.writeRegionServerLastLogRollResult(servers[i], timestamps[i], "root");
197+
table.writeRegionServerLastLogRollResult(servers[i], timestamps[i], "root/backup");
195198
}
196199

197200
HashMap<String, Long> result = table.readRegionServerLastLogRollResult("root");
@@ -265,7 +268,10 @@ public void testRegionServerLogTimestampMap() throws IOException {
265268
rsTimestampMap.put("rs2:100", 101L);
266269
rsTimestampMap.put("rs3:100", 103L);
267270

271+
// validate the prefix scan in readLogTimestampMap will get the right timestamps
272+
// when a backup root with the same prefix is present
268273
table.writeRegionServerLogTimestamp(tables, rsTimestampMap, "root");
274+
table.writeRegionServerLogTimestamp(tables, rsTimestampMap, "root/backup");
269275

270276
Map<TableName, Map<String, Long>> result = table.readLogTimestampMap("root");
271277

@@ -291,7 +297,10 @@ public void testRegionServerLogTimestampMap() throws IOException {
291297
rsTimestampMap1.put("rs2:100", 201L);
292298
rsTimestampMap1.put("rs3:100", 203L);
293299

300+
// validate the prefix scan in readLogTimestampMap will get the right timestamps
301+
// when a backup root with the same prefix is present
294302
table.writeRegionServerLogTimestamp(tables1, rsTimestampMap1, "root");
303+
table.writeRegionServerLogTimestamp(tables1, rsTimestampMap, "root/backup");
295304

296305
result = table.readLogTimestampMap("root");
297306

0 commit comments

Comments
 (0)