From commits-return-68528-archive-asf-public=cust-asf.ponee.io@hbase.apache.org Mon Feb 26 15:35:47 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 7535018064A for ; Mon, 26 Feb 2018 15:35:46 +0100 (CET) Received: (qmail 13111 invoked by uid 500); 26 Feb 2018 14:35:45 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 13099 invoked by uid 99); 26 Feb 2018 14:35:45 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 26 Feb 2018 14:35:45 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id CAFEAE5CE1; Mon, 26 Feb 2018 14:35:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: zhangduo@apache.org To: commits@hbase.apache.org Message-Id: <5ff04cad719d4b9ba613996c7cc33432@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-20083 Fix findbugs error for ReplicationSyncUp Date: Mon, 26 Feb 2018 14:35:44 +0000 (UTC) Repository: hbase Updated Branches: refs/heads/master 8c74d177f -> 2beda62a1 HBASE-20083 Fix findbugs error for ReplicationSyncUp Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/2beda62a Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/2beda62a Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/2beda62a Branch: refs/heads/master Commit: 2beda62a10f0828eb10cec28b0ba53246cd0b671 Parents: 8c74d17 Author: zhangduo Authored: Mon Feb 26 16:37:58 2018 +0800 Committer: zhangduo Committed: Mon Feb 26 22:13:13 2018 +0800 ---------------------------------------------------------------------- .../regionserver/ReplicationSyncUp.java | 59 ++++++-------------- .../replication/TestReplicationSyncUpTool.java | 6 +- 2 files changed, 19 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/2beda62a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSyncUp.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSyncUp.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSyncUp.java index 283eb96..c2862de 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSyncUp.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/replication/regionserver/ReplicationSyncUp.java @@ -49,35 +49,18 @@ import org.apache.hadoop.util.ToolRunner; */ public class ReplicationSyncUp extends Configured implements Tool { - private static Configuration conf; - private static final long SLEEP_TIME = 10000; - // although the tool is designed to be run on command line - // this api is provided for executing the tool through another app - public static void setConfigure(Configuration config) { - conf = config; - } - /** * Main program - * @param args - * @throws Exception */ public static void main(String[] args) throws Exception { - if (conf == null) conf = HBaseConfiguration.create(); - int ret = ToolRunner.run(conf, new ReplicationSyncUp(), args); + int ret = ToolRunner.run(HBaseConfiguration.create(), new ReplicationSyncUp(), args); System.exit(ret); } @Override public int run(String[] args) throws Exception { - Replication replication; - ReplicationSourceManager manager; - FileSystem fs; - Path oldLogDir, logDir, walRootDir; - ZKWatcher zkw; - Abortable abortable = new Abortable() { @Override public void abort(String why, Throwable e) { @@ -88,23 +71,19 @@ public class ReplicationSyncUp extends Configured implements Tool { return false; } }; - - zkw = - new ZKWatcher(conf, "syncupReplication" + System.currentTimeMillis(), abortable, - true); - - walRootDir = FSUtils.getWALRootDir(conf); - fs = FSUtils.getWALFileSystem(conf); - oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME); - logDir = new Path(walRootDir, HConstants.HREGION_LOGDIR_NAME); - - System.out.println("Start Replication Server start"); - replication = new Replication(); - replication.initialize(new DummyServer(zkw), fs, logDir, oldLogDir, null); - manager = replication.getReplicationManager(); - manager.init().get(); - - try { + Configuration conf = getConf(); + try (ZKWatcher zkw = + new ZKWatcher(conf, "syncupReplication" + System.currentTimeMillis(), abortable, true)) { + Path walRootDir = FSUtils.getWALRootDir(conf); + FileSystem fs = FSUtils.getWALFileSystem(conf); + Path oldLogDir = new Path(walRootDir, HConstants.HREGION_OLDLOGDIR_NAME); + Path logDir = new Path(walRootDir, HConstants.HREGION_LOGDIR_NAME); + + System.out.println("Start Replication Server start"); + Replication replication = new Replication(); + replication.initialize(new DummyServer(zkw), fs, logDir, oldLogDir, null); + ReplicationSourceManager manager = replication.getReplicationManager(); + manager.init().get(); while (manager.activeFailoverTaskCount() > 0) { Thread.sleep(SLEEP_TIME); } @@ -114,15 +93,12 @@ public class ReplicationSyncUp extends Configured implements Tool { manager.join(); } catch (InterruptedException e) { System.err.println("didn't wait long enough:" + e); - return (-1); - } finally { - zkw.close(); + return -1; } - return 0; } - static class DummyServer implements Server { + class DummyServer implements Server { String hostname; ZKWatcher zkw; @@ -138,7 +114,7 @@ public class ReplicationSyncUp extends Configured implements Tool { @Override public Configuration getConfiguration() { - return conf; + return getConf(); } @Override @@ -191,7 +167,6 @@ public class ReplicationSyncUp extends Configured implements Tool { @Override public ClusterConnection getClusterConnection() { - // TODO Auto-generated method stub return null; } http://git-wip-us.apache.org/repos/asf/hbase/blob/2beda62a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSyncUpTool.java ---------------------------------------------------------------------- diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSyncUpTool.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSyncUpTool.java index 19aeac1..6c487ad 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSyncUpTool.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/replication/TestReplicationSyncUpTool.java @@ -38,6 +38,7 @@ import org.apache.hadoop.hbase.replication.regionserver.ReplicationSyncUp; import org.apache.hadoop.hbase.testclassification.LargeTests; import org.apache.hadoop.hbase.testclassification.ReplicationTests; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.util.ToolRunner; import org.junit.Before; import org.junit.ClassRule; import org.junit.Test; @@ -420,9 +421,6 @@ public class TestReplicationSyncUpTool extends TestReplicationBase { } protected void syncUp(HBaseTestingUtility ut) throws Exception { - ReplicationSyncUp.setConfigure(ut.getConfiguration()); - String[] arguments = new String[] { null }; - new ReplicationSyncUp().run(arguments); + ToolRunner.run(ut.getConfiguration(), new ReplicationSyncUp(), new String[0]); } - }