ACCUMULO-802 finished adding constraints to namespaces, works correctly.
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/3163db2f Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/3163db2f Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/3163db2f Branch: refs/heads/ACCUMULO-802 Commit: 3163db2f8284cb0b7b21407355c8080bcc611990 Parents: c9250dd Author: Sean Hickey <[email protected]> Authored: Fri Jul 26 15:28:22 2013 -0400 Committer: Christopher Tubbs <[email protected]> Committed: Thu Oct 31 21:26:02 2013 -0400 ---------------------------------------------------------------------- .../accumulo/server/conf/TableConfWatcher.java | 1 + .../server/conf/TableConfiguration.java | 8 +++-- .../conf/TableNamespaceConfiguration.java | 34 +------------------- .../org/apache/accumulo/tserver/Tablet.java | 10 ++++-- .../accumulo/test/TableNamespacesTest.java | 12 ++----- 5 files changed, 18 insertions(+), 47 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/3163db2f/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfWatcher.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfWatcher.java b/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfWatcher.java index c407309..b0abe3b 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfWatcher.java +++ b/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfWatcher.java @@ -44,6 +44,7 @@ class TableConfWatcher implements Watcher { log.trace("WatchEvent : " + path + " " + event.getState() + " " + event.getType()); String tablesPrefix = ZooUtil.getRoot(instance) + Constants.ZTABLES + "/"; + String namespacesPrefix = ZooUtil.getRoot(instance) + Constants.ZNAMESPACES + "/"; String tableId = null; String key = null; http://git-wip-us.apache.org/repos/asf/accumulo/blob/3163db2f/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfiguration.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfiguration.java b/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfiguration.java index 4c58153..fe3c30f 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfiguration.java +++ b/server/base/src/main/java/org/apache/accumulo/server/conf/TableConfiguration.java @@ -40,12 +40,12 @@ public class TableConfiguration extends AccumuloConfiguration { private static ZooCache tablePropCache = null; private final String instanceId; - private final AccumuloConfiguration parent; + private final TableNamespaceConfiguration parent; private String table = null; private Set<ConfigurationObserver> observers; - public TableConfiguration(String instanceId, String table, AccumuloConfiguration parent) { + public TableConfiguration(String instanceId, String table, TableNamespaceConfiguration parent) { this.instanceId = instanceId; this.table = table; this.parent = parent; @@ -144,4 +144,8 @@ public class TableConfiguration extends AccumuloConfiguration { public String getTableId() { return table; } + + public TableNamespaceConfiguration getNamespaceConfiguration() { + return parent; + } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/3163db2f/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java ---------------------------------------------------------------------- diff --git a/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java b/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java index bf3c0bb..e3c58f3 100644 --- a/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java +++ b/server/base/src/main/java/org/apache/accumulo/server/conf/TableNamespaceConfiguration.java @@ -19,12 +19,11 @@ package org.apache.accumulo.server.conf; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; +import java.util.Set; import java.util.TreeMap; import org.apache.accumulo.core.Constants; import org.apache.accumulo.core.client.Instance; -import org.apache.accumulo.core.client.TableNamespaceNotFoundException; -import org.apache.accumulo.core.client.impl.TableNamespaces; import org.apache.accumulo.core.conf.AccumuloConfiguration; import org.apache.accumulo.core.conf.Property; import org.apache.accumulo.core.zookeeper.ZooUtil; @@ -43,19 +42,12 @@ public class TableNamespaceConfiguration extends AccumuloConfiguration { public TableNamespaceConfiguration(String namespaceId, AccumuloConfiguration parent) { inst = HdfsZooInstance.getInstance(); - propCache = new ZooCache(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut()); this.parent = parent; this.namespaceId = namespaceId; this.observers = Collections.synchronizedSet(new HashSet<ConfigurationObserver>()); } @Override - public void invalidateCache() { - if (propCache != null) - propCache.clear(); - } - - @Override public String get(Property property) { String key = property.getKey(); String value = get(key); @@ -135,41 +127,17 @@ public class TableNamespaceConfiguration extends AccumuloConfiguration { Collection<ConfigurationObserver> copy = Collections.unmodifiableCollection(observers); for (ConfigurationObserver co : copy) co.sessionExpired(); - - try { - for (String t : TableNamespaces.getTableIds(inst, namespaceId)) { - ServerConfiguration.getTableConfiguration(inst, t).expireAllObservers(); - } - } catch (TableNamespaceNotFoundException e) { - throw new IllegalStateException("The namespace (" + namespaceId + ") for this configuration no longer exists"); - } } public void propertyChanged(String key) { Collection<ConfigurationObserver> copy = Collections.unmodifiableCollection(observers); for (ConfigurationObserver co : copy) co.propertyChanged(key); - - try { - for (String t : TableNamespaces.getTableIds(inst, namespaceId)) { - ServerConfiguration.getTableConfiguration(inst, t).propertyChanged(key); - } - } catch (TableNamespaceNotFoundException e) { - throw new IllegalStateException("The namespace (" + namespaceId + ") for this configuration no longer exists"); - } } public void propertiesChanged(String key) { Collection<ConfigurationObserver> copy = Collections.unmodifiableCollection(observers); for (ConfigurationObserver co : copy) co.propertiesChanged(); - - try { - for (String t : TableNamespaces.getTableIds(inst, namespaceId)) { - ServerConfiguration.getTableConfiguration(inst, t).propertiesChanged(key); - } - } catch (TableNamespaceNotFoundException e) { - throw new IllegalStateException("The namespace (" + namespaceId + ") for this configuration no longer exists"); - } } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/3163db2f/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java ---------------------------------------------------------------------- diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java index 0ef6c6b..58acc52 100644 --- a/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java +++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/Tablet.java @@ -1316,7 +1316,7 @@ public class Tablet { acuTableConf.addObserver(configObserver = new ConfigurationObserver() { private void reloadConstraints() { - constraintChecker.set(new ConstraintChecker(getTableConfiguration())); + constraintChecker.set(new ConstraintChecker(acuTableConf)); } @Override @@ -1351,6 +1351,9 @@ public class Tablet { } }); + + acuTableConf.getNamespaceConfiguration().addObserver(configObserver); + // Force a load of any per-table properties configObserver.propertiesChanged(); @@ -2494,7 +2497,7 @@ public class Tablet { ConstraintChecker cc = constraintChecker.get(); if (cc.classLoaderChanged()) { - ConstraintChecker ncc = new ConstraintChecker(getTableConfiguration()); + ConstraintChecker ncc = new ConstraintChecker(acuTableConf); constraintChecker.compareAndSet(cc, ncc); } } @@ -2752,6 +2755,7 @@ public class Tablet { log.log(TLevel.TABLET_HIST, extent + " closed"); + acuTableConf.getNamespaceConfiguration().removeObserver(configObserver); acuTableConf.removeObserver(configObserver); closeComplete = completeClose; @@ -3865,6 +3869,6 @@ public class Tablet { } public TableConfiguration getTableConfiguration() { - return tabletServer.getTableConfiguration(extent); + return acuTableConf; } } http://git-wip-us.apache.org/repos/asf/accumulo/blob/3163db2f/test/src/test/java/org/apache/accumulo/test/TableNamespacesTest.java ---------------------------------------------------------------------- diff --git a/test/src/test/java/org/apache/accumulo/test/TableNamespacesTest.java b/test/src/test/java/org/apache/accumulo/test/TableNamespacesTest.java index ceca3be..ae1a005 100644 --- a/test/src/test/java/org/apache/accumulo/test/TableNamespacesTest.java +++ b/test/src/test/java/org/apache/accumulo/test/TableNamespacesTest.java @@ -49,7 +49,6 @@ import org.apache.accumulo.core.iterators.Filter; import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope; import org.apache.accumulo.core.security.Authorizations; import org.apache.accumulo.core.util.UtilWaitThread; -import org.apache.accumulo.examples.simple.constraints.AlphaNumKeyConstraint; import org.apache.accumulo.examples.simple.constraints.NumericValueConstraint; import org.apache.accumulo.minicluster.MiniAccumuloCluster; import org.junit.AfterClass; @@ -67,7 +66,6 @@ public class TableNamespacesTest { @BeforeClass static public void setUp() throws Exception { folder.create(); - System.out.println(folder.getRoot()); accumulo = new MiniAccumuloCluster(folder.getRoot(), secret); accumulo.start(); } @@ -75,7 +73,7 @@ public class TableNamespacesTest { @AfterClass static public void tearDown() throws Exception { accumulo.stop(); - // folder.delete(); + folder.delete(); } /** @@ -390,12 +388,8 @@ public class TableNamespacesTest { c.tableNamespaceOperations().removeIterator(namespace, iter, EnumSet.copyOf(scope)); c.tableNamespaceOperations().addConstraint(namespace, NumericValueConstraint.class.getName()); - //c.tableOperations().addConstraint(tableName, AlphaNumKeyConstraint.class.getName()); - - /*for (Entry<String,Integer> e : c.tableOperations().listConstraints(tableName).entrySet()) { - System.out.println(e.toString()); - }*/ - //UtilWaitThread.sleep(10000); + // doesn't take effect immediately, needs time to propagate + UtilWaitThread.sleep(250); m = new Mutation("rowy"); m.put("a", "b", new Value("abcde".getBytes(Constants.UTF8)));
