From c2a366f842f2e8d86a661442e6686863a29f4b2f Mon Sep 17 00:00:00 2001 From: Keith Turner Date: Fri, 2 Feb 2018 16:19:19 -0500 Subject: [PATCH] ACCUMULO-4797 improved namespace config performance --- .../accumulo/core/client/impl/Tables.java | 5 ++- .../server/conf/NamespaceConfiguration.java | 4 +- .../conf/ServerConfigurationFactory.java | 10 ++++- .../server/conf/TableParentConfiguration.java | 45 ------------------- .../conf/NamespaceConfigurationTest.java | 8 ++-- 5 files changed, 19 insertions(+), 53 deletions(-) delete mode 100644 server/base/src/main/java/org/apache/accumulo/server/conf/TableParentConfiguration.java diff --git a/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java b/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java index a93347c2162..423d81f5410 100644 --- a/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java +++ b/core/src/main/java/org/apache/accumulo/core/client/impl/Tables.java @@ -60,14 +60,15 @@ private static ZooCache getZooCache(final Instance instance) { if (sm != null) { sm.checkPermission(TABLES_PERMISSION); } - final String zks = instance.getZooKeepers(); - final int timeOut = instance.getZooKeepersSessionTimeOut(); + final String uuid = instance.getInstanceID(); try { return instanceToZooCache.get(uuid, new Callable() { @Override public ZooCache call() { + final String zks = instance.getZooKeepers(); + final int timeOut = instance.getZooKeepersSessionTimeOut(); return new ZooCacheFactory().getZooCache(zks, timeOut, new Watcher() { @Override public void process(WatchedEvent watchedEvent) { diff --git a/server/base/src/main/java/org/apache/accumulo/server/conf/NamespaceConfiguration.java b/server/base/src/main/java/org/apache/accumulo/server/conf/NamespaceConfiguration.java index 1ca083e30b6..099f9e05275 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/conf/NamespaceConfiguration.java +++ b/server/base/src/main/java/org/apache/accumulo/server/conf/NamespaceConfiguration.java @@ -45,6 +45,7 @@ public class NamespaceConfiguration extends ObservableConfiguration { protected String namespaceId = null; protected Instance inst = null; private ZooCacheFactory zcf = new ZooCacheFactory(); + private final String path; public NamespaceConfiguration(String namespaceId, AccumuloConfiguration parent) { this(namespaceId, HdfsZooInstance.getInstance(), parent); @@ -54,6 +55,7 @@ public NamespaceConfiguration(String namespaceId, Instance inst, AccumuloConfigu this.inst = inst; this.parent = parent; this.namespaceId = namespaceId; + this.path = ZooUtil.getRoot(inst.getInstanceID()) + Constants.ZNAMESPACES + "/" + namespaceId + Constants.ZNAMESPACE_CONF; } /** @@ -85,7 +87,7 @@ private synchronized ZooCachePropertyAccessor getPropCacheAccessor() { } private String getPath() { - return ZooUtil.getRoot(inst.getInstanceID()) + Constants.ZNAMESPACES + "/" + getNamespaceId() + Constants.ZNAMESPACE_CONF; + return path; } @Override diff --git a/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfigurationFactory.java b/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfigurationFactory.java index f79f707c98a..666c5eb1b9d 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfigurationFactory.java +++ b/server/base/src/main/java/org/apache/accumulo/server/conf/ServerConfigurationFactory.java @@ -21,6 +21,7 @@ import java.util.Map; import org.apache.accumulo.core.client.Instance; +import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.client.impl.Tables; import org.apache.accumulo.core.conf.AccumuloConfiguration; import org.apache.accumulo.core.conf.ConfigSanityCheck; @@ -189,8 +190,13 @@ public NamespaceConfiguration getNamespaceConfigurationForTable(String tableId) // can't hold the lock during the construction and validation of the config, // which may result in creating multiple objects for the same id, but that's ok. if (conf == null) { - // changed - include instance in constructor call - conf = new TableParentConfiguration(tableId, instance, getConfiguration()); + String namespaceId; + try { + namespaceId = Tables.getNamespaceId(instance, tableId); + } catch (TableNotFoundException e) { + throw new RuntimeException(e); + } + conf = new NamespaceConfiguration(namespaceId, instance, getConfiguration()); ConfigSanityCheck.validate(conf); synchronized (tableParentConfigs) { tableParentConfigs.get(instanceID).put(tableId, conf); diff --git a/server/base/src/main/java/org/apache/accumulo/server/conf/TableParentConfiguration.java b/server/base/src/main/java/org/apache/accumulo/server/conf/TableParentConfiguration.java deleted file mode 100644 index 70649be8af7..00000000000 --- a/server/base/src/main/java/org/apache/accumulo/server/conf/TableParentConfiguration.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file 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. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.accumulo.server.conf; - -import org.apache.accumulo.core.client.Instance; -import org.apache.accumulo.core.client.TableNotFoundException; -import org.apache.accumulo.core.client.impl.Tables; -import org.apache.accumulo.core.conf.AccumuloConfiguration; - -/** - * Used by TableConfiguration to dynamically get the NamespaceConfiguration if the namespace changes - */ -public class TableParentConfiguration extends NamespaceConfiguration { - - private String tableId; - - public TableParentConfiguration(String tableId, Instance inst, AccumuloConfiguration parent) { - super(null, inst, parent); - this.tableId = tableId; - this.namespaceId = getNamespaceId(); - } - - @Override - protected String getNamespaceId() { - try { - return Tables.getNamespaceId(inst, tableId); - } catch (TableNotFoundException e) { - throw new RuntimeException(e); - } - } -} diff --git a/server/base/src/test/java/org/apache/accumulo/server/conf/NamespaceConfigurationTest.java b/server/base/src/test/java/org/apache/accumulo/server/conf/NamespaceConfigurationTest.java index 071e9c04028..1030546d592 100644 --- a/server/base/src/test/java/org/apache/accumulo/server/conf/NamespaceConfigurationTest.java +++ b/server/base/src/test/java/org/apache/accumulo/server/conf/NamespaceConfigurationTest.java @@ -65,15 +65,17 @@ public void setUp() { iid = UUID.randomUUID().toString(); instance = createMock(Instance.class); parent = createMock(AccumuloConfiguration.class); - c = new NamespaceConfiguration(NSID, instance, parent); - zcf = createMock(ZooCacheFactory.class); - c.setZooCacheFactory(zcf); expect(instance.getInstanceID()).andReturn(iid); expectLastCall().anyTimes(); expect(instance.getZooKeepers()).andReturn(ZOOKEEPERS); expect(instance.getZooKeepersSessionTimeOut()).andReturn(ZK_SESSION_TIMEOUT); replay(instance); + + c = new NamespaceConfiguration(NSID, instance, parent); + zcf = createMock(ZooCacheFactory.class); + c.setZooCacheFactory(zcf); + zc = createMock(ZooCache.class); expect(zcf.getZooCache(eq(ZOOKEEPERS), eq(ZK_SESSION_TIMEOUT), anyObject(NamespaceConfWatcher.class))).andReturn(zc); replay(zcf);