From commits-return-23021-archive-asf-public=cust-asf.ponee.io@accumulo.apache.org Fri Jun 14 18:06:57 2019 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 [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id 5FEFA18067E for ; Fri, 14 Jun 2019 20:06:57 +0200 (CEST) Received: (qmail 735 invoked by uid 500); 14 Jun 2019 18:06:56 -0000 Mailing-List: contact commits-help@accumulo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@accumulo.apache.org Delivered-To: mailing list commits@accumulo.apache.org Received: (qmail 726 invoked by uid 99); 14 Jun 2019 18:06:56 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Jun 2019 18:06:56 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 8F0FD87AD7; Fri, 14 Jun 2019 18:06:52 +0000 (UTC) Date: Fri, 14 Jun 2019 18:06:52 +0000 To: "commits@accumulo.apache.org" Subject: [accumulo] branch master updated: De-dupe some code (#1211) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <156053561247.5900.3777420497801856427@gitbox.apache.org> From: mmiller@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: accumulo X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 27315b28197d2c018d6c2aca3962ea0a4c1eae32 X-Git-Newrev: 417de4e6da1f03c18e3717f2c359828f500197b2 X-Git-Rev: 417de4e6da1f03c18e3717f2c359828f500197b2 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated This is an automated email from the ASF dual-hosted git repository. mmiller pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/accumulo.git The following commit(s) were added to refs/heads/master by this push: new 417de4e De-dupe some code (#1211) 417de4e is described below commit 417de4e6da1f03c18e3717f2c359828f500197b2 Author: Mike Miller AuthorDate: Fri Jun 14 14:06:48 2019 -0400 De-dupe some code (#1211) * Create static methods in ZooUtil for ZooKeeperInstance and ClientContext to share --- .../accumulo/core/client/ZooKeeperInstance.java | 46 +--------------------- .../accumulo/core/clientImpl/ClientContext.java | 46 +--------------------- .../core/clientImpl/InstanceOperationsImpl.java | 1 - .../apache/accumulo/fate/zookeeper/ZooUtil.java | 46 ++++++++++++++++++++++ 4 files changed, 50 insertions(+), 89 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java b/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java index 9b3bd24..b61e4f2 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java +++ b/core/src/main/java/org/apache/accumulo/core/client/ZooKeeperInstance.java @@ -17,15 +17,12 @@ package org.apache.accumulo.core.client; import static com.google.common.base.Preconditions.checkArgument; -import static java.nio.charset.StandardCharsets.UTF_8; -import java.util.Collections; import java.util.List; import java.util.Properties; import java.util.UUID; import java.util.concurrent.TimeUnit; -import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.security.tokens.AuthenticationToken; import org.apache.accumulo.core.clientImpl.ClientConfConverter; import org.apache.accumulo.core.clientImpl.ClientContext; @@ -125,53 +122,14 @@ public class ZooKeeperInstance implements Instance { @Override public String getInstanceID() { if (instanceId == null) { - // want the instance id to be stable for the life of this instance object, - // so only get it once - String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + instanceName; - byte[] iidb = zooCache.get(instanceNamePath); - if (iidb == null) { - throw new RuntimeException( - "Instance name " + instanceName + " does not exist in zookeeper. " - + "Run \"accumulo org.apache.accumulo.server.util.ListInstances\" to see a list."); - } - instanceId = new String(iidb, UTF_8); + instanceId = ZooUtil.getInstanceID(zooCache, instanceName); } - - if (zooCache.get(Constants.ZROOT + "/" + instanceId) == null) { - if (instanceName == null) - throw new RuntimeException("Instance id " + instanceId + " does not exist in zookeeper"); - throw new RuntimeException("Instance id " + instanceId + " pointed to by the name " - + instanceName + " does not exist in zookeeper"); - } - return instanceId; } @Override public List getMasterLocations() { - String masterLocPath = ZooUtil.getRoot(getInstanceID()) + Constants.ZMASTER_LOCK; - - OpTimer timer = null; - - if (log.isTraceEnabled()) { - log.trace("tid={} Looking up master location in zookeeper.", Thread.currentThread().getId()); - timer = new OpTimer().start(); - } - - byte[] loc = ZooUtil.getLockData(zooCache, masterLocPath); - - if (timer != null) { - timer.stop(); - log.trace("tid={} Found master at {} in {}", Thread.currentThread().getId(), - (loc == null ? "null" : new String(loc, UTF_8)), - String.format("%.3f secs", timer.scale(TimeUnit.SECONDS))); - } - - if (loc == null) { - return Collections.emptyList(); - } - - return Collections.singletonList(new String(loc, UTF_8)); + return ZooUtil.getMasterLocations(zooCache, getInstanceID()); } @Override diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java index fa8b73e..0737aa2 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/ClientContext.java @@ -17,11 +17,9 @@ package org.apache.accumulo.core.clientImpl; import static com.google.common.base.Preconditions.checkArgument; -import static java.nio.charset.StandardCharsets.UTF_8; import static org.apache.accumulo.core.metadata.schema.TabletMetadata.ColumnType.LOCATION; import java.nio.file.Path; -import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Properties; @@ -29,7 +27,6 @@ import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.function.Supplier; -import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.AccumuloClient; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; @@ -366,29 +363,7 @@ public class ClientContext implements AccumuloClient { */ public List getMasterLocations() { ensureOpen(); - String masterLocPath = getZooKeeperRoot() + Constants.ZMASTER_LOCK; - - OpTimer timer = null; - - if (log.isTraceEnabled()) { - log.trace("tid={} Looking up master location in zookeeper.", Thread.currentThread().getId()); - timer = new OpTimer().start(); - } - - byte[] loc = ZooUtil.getLockData(zooCache, masterLocPath); - - if (timer != null) { - timer.stop(); - log.trace("tid={} Found master at {} in {}", Thread.currentThread().getId(), - (loc == null ? "null" : new String(loc, UTF_8)), - String.format("%.3f secs", timer.scale(TimeUnit.SECONDS))); - } - - if (loc == null) { - return Collections.emptyList(); - } - - return Collections.singletonList(new String(loc, UTF_8)); + return ZooUtil.getMasterLocations(zooCache, instanceId); } /** @@ -400,25 +375,8 @@ public class ClientContext implements AccumuloClient { ensureOpen(); final String instanceName = info.getInstanceName(); if (instanceId == null) { - // want the instance id to be stable for the life of this instance object, - // so only get it once - String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + instanceName; - byte[] iidb = zooCache.get(instanceNamePath); - if (iidb == null) { - throw new RuntimeException( - "Instance name " + instanceName + " does not exist in zookeeper. " - + "Run \"accumulo org.apache.accumulo.server.util.ListInstances\" to see a list."); - } - instanceId = new String(iidb, UTF_8); - } - - if (zooCache.get(Constants.ZROOT + "/" + instanceId) == null) { - if (instanceName == null) - throw new RuntimeException("Instance id " + instanceId + " does not exist in zookeeper"); - throw new RuntimeException("Instance id " + instanceId + " pointed to by the name " - + instanceName + " does not exist in zookeeper"); + instanceId = ZooUtil.getInstanceID(zooCache, instanceName); } - return instanceId; } diff --git a/core/src/main/java/org/apache/accumulo/core/clientImpl/InstanceOperationsImpl.java b/core/src/main/java/org/apache/accumulo/core/clientImpl/InstanceOperationsImpl.java index a452ce4..79411cb 100644 --- a/core/src/main/java/org/apache/accumulo/core/clientImpl/InstanceOperationsImpl.java +++ b/core/src/main/java/org/apache/accumulo/core/clientImpl/InstanceOperationsImpl.java @@ -235,7 +235,6 @@ public class InstanceOperationsImpl implements InstanceOperations { @Override public String getInstanceID() { - return context.getInstanceID(); } } diff --git a/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java b/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java index 6573614..fc92ac8 100644 --- a/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java +++ b/core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooUtil.java @@ -16,6 +16,7 @@ */ package org.apache.accumulo.fate.zookeeper; +import static java.nio.charset.StandardCharsets.UTF_8; import static java.util.Objects.requireNonNull; import static java.util.concurrent.TimeUnit.MILLISECONDS; @@ -31,6 +32,7 @@ import java.util.concurrent.TimeUnit; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.conf.AccumuloConfiguration; +import org.apache.accumulo.core.util.OpTimer; import org.apache.accumulo.core.volume.VolumeConfiguration; import org.apache.accumulo.fate.util.Retry; import org.apache.accumulo.fate.util.Retry.RetryFactory; @@ -614,4 +616,48 @@ public class ZooUtil { } } + public static String getInstanceID(ZooCache zooCache, String instanceName) { + String instanceId; + String instanceNamePath = Constants.ZROOT + Constants.ZINSTANCES + "/" + instanceName; + byte[] data = zooCache.get(instanceNamePath); + if (data == null) { + throw new RuntimeException("Instance name " + instanceName + " does not exist in zookeeper. " + + "Run \"accumulo org.apache.accumulo.server.util.ListInstances\" to see a list."); + } + instanceId = new String(data, UTF_8); + + if (zooCache.get(Constants.ZROOT + "/" + instanceId) == null) { + if (instanceName == null) + throw new RuntimeException("Instance id " + instanceId + " does not exist in zookeeper"); + throw new RuntimeException("Instance id " + instanceId + " pointed to by the name " + + instanceName + " does not exist in zookeeper"); + } + return instanceId; + } + + public static List getMasterLocations(ZooCache zooCache, String instanceId) { + String masterLocPath = ZooUtil.getRoot(instanceId) + Constants.ZMASTER_LOCK; + + OpTimer timer = null; + + if (log.isTraceEnabled()) { + log.trace("tid={} Looking up master location in zookeeper.", Thread.currentThread().getId()); + timer = new OpTimer().start(); + } + + byte[] loc = ZooUtil.getLockData(zooCache, masterLocPath); + + if (timer != null) { + timer.stop(); + log.trace("tid={} Found master at {} in {}", Thread.currentThread().getId(), + (loc == null ? "null" : new String(loc, UTF_8)), + String.format("%.3f secs", timer.scale(TimeUnit.SECONDS))); + } + + if (loc == null) { + return Collections.emptyList(); + } + + return Collections.singletonList(new String(loc, UTF_8)); + } }