Skip to content

Commit 6d38775

Browse files
authored
HBASE-29449 Update backup describe command for continuous backup (#7045)
Signed-off-by: Tak Lon (Stephen) Wu <[email protected]> Reviewed by: Kevin Geiszler <[email protected]>
1 parent 41b217d commit 6d38775

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

hbase-backup/src/main/java/org/apache/hadoop/hbase/backup/BackupInfo.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ public BackupProtos.BackupInfo toProtosBackupInfo() {
440440
builder.setBackupType(BackupProtos.BackupType.valueOf(getType().name()));
441441
builder.setWorkersNumber(workers);
442442
builder.setBandwidth(bandwidth);
443+
builder.setContinuousBackupEnabled(isContinuousBackupEnabled());
444+
builder.setIncrCommittedWalTs(getIncrCommittedWalTs());
443445
return builder.build();
444446
}
445447

@@ -535,6 +537,8 @@ public static BackupInfo fromProto(BackupProtos.BackupInfo proto) {
535537
context.setType(BackupType.valueOf(proto.getBackupType().name()));
536538
context.setWorkers(proto.getWorkersNumber());
537539
context.setBandwidth(proto.getBandwidth());
540+
context.setContinuousBackupEnabled(proto.getContinuousBackupEnabled());
541+
context.setIncrCommittedWalTs(proto.getIncrCommittedWalTs());
538542
return context;
539543
}
540544

@@ -578,6 +582,12 @@ public String getShortDescription() {
578582
cal.setTimeInMillis(getCompleteTs());
579583
date = cal.getTime();
580584
sb.append("End time=" + date).append(",");
585+
if (getType() == BackupType.INCREMENTAL) {
586+
cal = Calendar.getInstance();
587+
cal.setTimeInMillis(getIncrCommittedWalTs());
588+
date = cal.getTime();
589+
sb.append("Committed WAL time for incremental backup=" + date).append(",");
590+
}
581591
}
582592
sb.append("Progress=" + getProgress() + "%");
583593
sb.append("}");

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

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,27 @@
1717
*/
1818
package org.apache.hadoop.hbase.backup;
1919

20+
import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.CONF_CONTINUOUS_BACKUP_WAL_DIR;
21+
import static org.apache.hadoop.hbase.backup.BackupRestoreConstants.OPTION_ENABLE_CONTINUOUS_BACKUP;
22+
import static org.apache.hadoop.hbase.replication.regionserver.ReplicationMarkerChore.REPLICATION_MARKER_ENABLED_DEFAULT;
23+
import static org.apache.hadoop.hbase.replication.regionserver.ReplicationMarkerChore.REPLICATION_MARKER_ENABLED_KEY;
24+
import static org.junit.Assert.assertEquals;
2025
import static org.junit.Assert.assertNotEquals;
2126
import static org.junit.Assert.assertTrue;
2227

2328
import java.io.ByteArrayOutputStream;
2429
import java.io.PrintStream;
2530
import java.util.List;
31+
import org.apache.hadoop.fs.FileSystem;
32+
import org.apache.hadoop.fs.Path;
2633
import org.apache.hadoop.hbase.HBaseClassTestRule;
2734
import org.apache.hadoop.hbase.TableName;
2835
import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
2936
import org.apache.hadoop.hbase.backup.impl.BackupCommands;
3037
import org.apache.hadoop.hbase.backup.impl.BackupSystemTable;
38+
import org.apache.hadoop.hbase.client.Put;
3139
import org.apache.hadoop.hbase.testclassification.LargeTests;
40+
import org.apache.hadoop.hbase.util.Bytes;
3241
import org.apache.hadoop.util.ToolRunner;
3342
import org.junit.ClassRule;
3443
import org.junit.Test;
@@ -101,11 +110,89 @@ public void testBackupDescribeCommand() throws Exception {
101110
String response = baos.toString();
102111
assertTrue(response.indexOf(backupId) > 0);
103112
assertTrue(response.indexOf("COMPLETE") > 0);
113+
assertTrue(response.contains("IsContinuous=false"));
104114

105115
BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection());
106116
BackupInfo status = table.readBackupInfo(backupId);
107117
String desc = status.getShortDescription();
108118
table.close();
109119
assertTrue(response.indexOf(desc) >= 0);
110120
}
121+
122+
@Test
123+
public void testBackupDescribeCommandForContinuousBackup() throws Exception {
124+
LOG.info("test backup describe on a single table with data: command-line");
125+
Path root = TEST_UTIL.getDataTestDirOnTestFS();
126+
Path backupWalDir = new Path(root, "testBackupDescribeCommand");
127+
FileSystem fs = FileSystem.get(conf1);
128+
fs.mkdirs(backupWalDir);
129+
conf1.set(CONF_CONTINUOUS_BACKUP_WAL_DIR, backupWalDir.toString());
130+
conf1.setBoolean(REPLICATION_MARKER_ENABLED_KEY, true);
131+
132+
try (BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection())) {
133+
// Continuous backup
134+
String[] backupArgs = new String[] { "create", BackupType.FULL.name(), BACKUP_ROOT_DIR, "-t",
135+
table1.getNameAsString(), "-" + OPTION_ENABLE_CONTINUOUS_BACKUP };
136+
int ret = ToolRunner.run(conf1, new BackupDriver(), backupArgs);
137+
assertEquals("Backup should succeed", 0, ret);
138+
List<BackupInfo> backups = table.getBackupHistory();
139+
String backupId = backups.get(0).getBackupId();
140+
assertTrue(checkSucceeded(backupId));
141+
LOG.info("backup complete");
142+
143+
BackupInfo info = getBackupAdmin().getBackupInfo(backupId);
144+
assertTrue(info.getState() == BackupState.COMPLETE);
145+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
146+
System.setOut(new PrintStream(baos));
147+
148+
// Run backup describe
149+
String[] args = new String[] { "describe", backupId };
150+
ret = ToolRunner.run(conf1, new BackupDriver(), args);
151+
assertTrue(ret == 0);
152+
String response = baos.toString();
153+
assertTrue(response.contains(backupId));
154+
assertTrue(response.contains("COMPLETE"));
155+
assertTrue(response.contains("IsContinuous=true"));
156+
BackupInfo status = table.readBackupInfo(backupId);
157+
String desc = status.getShortDescription();
158+
assertTrue(response.contains(desc));
159+
160+
// load table
161+
Put p;
162+
for (int i = 0; i < NB_ROWS_IN_BATCH; i++) {
163+
p = new Put(Bytes.toBytes("row" + i));
164+
p.addColumn(famName, qualName, Bytes.toBytes("val" + i));
165+
TEST_UTIL.getConnection().getTable(table1).put(p);
166+
}
167+
Thread.sleep(5000);
168+
169+
// Incremental backup
170+
backupArgs = new String[] { "create", BackupType.INCREMENTAL.name(), BACKUP_ROOT_DIR, "-t",
171+
table1.getNameAsString() };
172+
ret = ToolRunner.run(conf1, new BackupDriver(), backupArgs);
173+
assertEquals("Incremental Backup should succeed", 0, ret);
174+
backups = table.getBackupHistory();
175+
String incrBackupId = backups.get(0).getBackupId();
176+
assertTrue(checkSucceeded(incrBackupId));
177+
LOG.info("Incremental backup complete");
178+
179+
// Run backup describe
180+
args = new String[] { "describe", incrBackupId };
181+
ret = ToolRunner.run(conf1, new BackupDriver(), args);
182+
assertTrue(ret == 0);
183+
response = baos.toString();
184+
assertTrue(response.contains(incrBackupId));
185+
assertTrue(response.contains("COMPLETE"));
186+
assertTrue(response.contains("Committed WAL time for incremental backup="));
187+
status = table.readBackupInfo(incrBackupId);
188+
desc = status.getShortDescription();
189+
assertTrue(response.contains(desc));
190+
} finally {
191+
if (fs.exists(backupWalDir)) {
192+
fs.delete(backupWalDir, true);
193+
}
194+
conf1.unset(CONF_CONTINUOUS_BACKUP_WAL_DIR);
195+
conf1.setBoolean(REPLICATION_MARKER_ENABLED_KEY, REPLICATION_MARKER_ENABLED_DEFAULT);
196+
}
197+
}
111198
}

hbase-protocol-shaded/src/main/protobuf/Backup.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ message BackupInfo {
9393
optional uint32 workers_number = 11;
9494
optional uint64 bandwidth = 12;
9595
map<string, RSTimestampMap> table_set_timestamp = 13;
96+
optional bool continuous_backup_enabled = 14;
97+
optional uint64 incr_committed_wal_ts = 15;
9698

9799
message RSTimestampMap {
98100
map<string, uint64> rs_timestamp = 1;

0 commit comments

Comments
 (0)