You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by te...@apache.org on 2016/12/05 18:53:30 UTC
hbase git commit: HBASE-17154 Backup progress command usage small fix
(Vladimir Rodionov)
Repository: hbase
Updated Branches:
refs/heads/HBASE-7912 89e5b5508 -> 0c59d2368
HBASE-17154 Backup progress command usage small fix (Vladimir Rodionov)
Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/0c59d236
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/0c59d236
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/0c59d236
Branch: refs/heads/HBASE-7912
Commit: 0c59d2368944ca8c0e2022400bedaaa92cb57083
Parents: 89e5b55
Author: tedyu <yu...@gmail.com>
Authored: Mon Dec 5 10:53:25 2016 -0800
Committer: tedyu <yu...@gmail.com>
Committed: Mon Dec 5 10:53:25 2016 -0800
----------------------------------------------------------------------
.../hbase/backup/impl/BackupCommands.java | 29 ++++++++++++++++----
.../hadoop/hbase/backup/TestBackupDescribe.java | 24 ++++++++--------
2 files changed, 36 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hbase/blob/0c59d236/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java
index ed9b4c9..436f419 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/backup/impl/BackupCommands.java
@@ -33,6 +33,7 @@ import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.backup.BackupInfo;
+import org.apache.hadoop.hbase.backup.BackupInfo.BackupState;
import org.apache.hadoop.hbase.backup.BackupRequest;
import org.apache.hadoop.hbase.backup.BackupRestoreConstants;
import org.apache.hadoop.hbase.backup.BackupType;
@@ -74,8 +75,10 @@ public final class BackupCommands implements BackupRestoreConstants {
public static final String PROGRESS_CMD_USAGE = "Usage: bin/hbase backup progress <backup_id>\n"
- + " backup_id Backup image id\n";
+ + " backup_id Backup image id (optional). If no id specified, the command will show\n"+
+ " progress for currently running backup session.";
public static final String NO_INFO_FOUND = "No info was found for backup id: ";
+ public static final String NO_ACTIVE_SESSION_FOUND = "No active backup sessions found.";
public static final String DESCRIBE_CMD_USAGE = "Usage: bin/hbase backup describe <backup_id>\n"
+ " backup_id Backup image id\n";
@@ -391,8 +394,8 @@ public final class BackupCommands implements BackupRestoreConstants {
if (cmdline == null || cmdline.getArgs() == null ||
cmdline.getArgs().length == 1) {
- System.err.println("No backup id was specified, "
- + "will retrieve the most recent (ongoing) sessions");
+ System.out.println("No backup id was specified, "
+ + "will retrieve the most recent (ongoing) session");
}
String[] args = cmdline == null ? null : cmdline.getArgs();
if (args != null && args.length > 2) {
@@ -405,10 +408,26 @@ public final class BackupCommands implements BackupRestoreConstants {
Configuration conf = getConf() != null? getConf(): HBaseConfiguration.create();
try(final Connection conn = ConnectionFactory.createConnection(conf);
final BackupSystemTable sysTable = new BackupSystemTable(conn);){
- BackupInfo info = sysTable.readBackupInfo(backupId);
+ BackupInfo info = null;
+
+ if (backupId != null) {
+ info = sysTable.readBackupInfo(backupId);
+ } else {
+ List<BackupInfo> infos = sysTable.getBackupContexts(BackupState.RUNNING);
+ if(infos != null && infos.size() > 0) {
+ info = infos.get(0);
+ backupId = info.getBackupId();
+ System.out.println("Found ongoing session with backupId="+ backupId);
+ } else {
+ }
+ }
int progress = info == null? -1: info.getProgress();
if(progress < 0){
- System.out.println(NO_INFO_FOUND + backupId);
+ if(backupId != null) {
+ System.out.println(NO_INFO_FOUND + backupId);
+ } else {
+ System.err.println(NO_ACTIVE_SESSION_FOUND);
+ }
} else{
System.out.println(backupId+" progress=" + progress+"%");
}
http://git-wip-us.apache.org/repos/asf/hbase/blob/0c59d236/hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDescribe.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDescribe.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDescribe.java
index b7d41e0..57548fc 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDescribe.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/backup/TestBackupDescribe.java
@@ -6,9 +6,9 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -51,24 +51,24 @@ public class TestBackupDescribe extends TestBackupBase {
public void testBackupDescribe() throws Exception {
LOG.info("test backup describe on a single table with data");
-
- String[] args = new String[]{"describe", "backup_2" };
+
+ String[] args = new String[]{"describe", "backup_2" };
int ret = ToolRunner.run(conf1, new BackupDriver(), args);
assertTrue(ret < 0);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- System.setOut(new PrintStream(baos));
+ System.setErr(new PrintStream(baos));
args = new String[]{"progress" };
ToolRunner.run(TEST_UTIL.getConfiguration(), new BackupDriver(), args);
String output = baos.toString();
LOG.info("Output from progress: " + output);
- assertTrue(output.indexOf(BackupCommands.NO_INFO_FOUND) >= 0);
+ assertTrue(output.indexOf(BackupCommands.NO_ACTIVE_SESSION_FOUND) >= 0);
}
@Test
public void testBackupSetCommandWithNonExistentTable() throws Exception {
- String[] args = new String[]{"set", "add", "some_set", "table" };
+ String[] args = new String[]{"set", "add", "some_set", "table" };
// Run backup
int ret = ToolRunner.run(conf1, new BackupDriver(), args);
assertNotEquals(ret, 0);
@@ -78,10 +78,10 @@ public class TestBackupDescribe extends TestBackupBase {
public void testBackupDescribeCommand() throws Exception {
LOG.info("test backup describe on a single table with data: command-line");
-
+
List<TableName> tableList = Lists.newArrayList(table1);
String backupId = fullTableBackup(tableList);
-
+
LOG.info("backup complete");
assertTrue(checkSucceeded(backupId));
@@ -91,7 +91,7 @@ public class TestBackupDescribe extends TestBackupBase {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
System.setOut(new PrintStream(baos));
- String[] args = new String[]{"describe", backupId };
+ String[] args = new String[]{"describe", backupId };
// Run backup
int ret = ToolRunner.run(conf1, new BackupDriver(), args);
assertTrue(ret == 0);
@@ -106,6 +106,6 @@ public class TestBackupDescribe extends TestBackupBase {
assertTrue(response.indexOf(desc) >= 0);
}
-
-
+
+
}