|
17 | 17 | */ |
18 | 18 | package org.apache.hadoop.hbase.backup; |
19 | 19 |
|
| 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; |
20 | 25 | import static org.junit.Assert.assertNotEquals; |
21 | 26 | import static org.junit.Assert.assertTrue; |
22 | 27 |
|
23 | 28 | import java.io.ByteArrayOutputStream; |
24 | 29 | import java.io.PrintStream; |
25 | 30 | import java.util.List; |
| 31 | +import org.apache.hadoop.fs.FileSystem; |
| 32 | +import org.apache.hadoop.fs.Path; |
26 | 33 | import org.apache.hadoop.hbase.HBaseClassTestRule; |
27 | 34 | import org.apache.hadoop.hbase.TableName; |
28 | 35 | import org.apache.hadoop.hbase.backup.BackupInfo.BackupState; |
29 | 36 | import org.apache.hadoop.hbase.backup.impl.BackupCommands; |
30 | 37 | import org.apache.hadoop.hbase.backup.impl.BackupSystemTable; |
| 38 | +import org.apache.hadoop.hbase.client.Put; |
31 | 39 | import org.apache.hadoop.hbase.testclassification.LargeTests; |
| 40 | +import org.apache.hadoop.hbase.util.Bytes; |
32 | 41 | import org.apache.hadoop.util.ToolRunner; |
33 | 42 | import org.junit.ClassRule; |
34 | 43 | import org.junit.Test; |
@@ -101,11 +110,89 @@ public void testBackupDescribeCommand() throws Exception { |
101 | 110 | String response = baos.toString(); |
102 | 111 | assertTrue(response.indexOf(backupId) > 0); |
103 | 112 | assertTrue(response.indexOf("COMPLETE") > 0); |
| 113 | + assertTrue(response.contains("IsContinuous=false")); |
104 | 114 |
|
105 | 115 | BackupSystemTable table = new BackupSystemTable(TEST_UTIL.getConnection()); |
106 | 116 | BackupInfo status = table.readBackupInfo(backupId); |
107 | 117 | String desc = status.getShortDescription(); |
108 | 118 | table.close(); |
109 | 119 | assertTrue(response.indexOf(desc) >= 0); |
110 | 120 | } |
| 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 | + } |
111 | 198 | } |
0 commit comments