<NME> NamespaceConfiguration.java
<BEF> /*
 * 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
 *
 *   https://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 java.util.Map;
import java.util.function.Predicate;

import org.apache.accumulo.core.clientImpl.Namespace;
import org.apache.accumulo.core.conf.AccumuloConfiguration;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.data.NamespaceId;
import org.apache.accumulo.server.ServerContext;
import org.apache.accumulo.server.conf.store.NamespacePropKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NamespaceConfiguration extends ZooBasedConfiguration {

  private static final Logger log = LoggerFactory.getLogger(NamespaceConfiguration.class);
  protected ServerContext context;

  private static final Logger log = Logger.getLogger(NamespaceConfiguration.class);

  private final AccumuloConfiguration parent;
  private static ZooCache propCache = null;
  protected String namespaceId = null;
  protected Instance inst = null;
  private Set<ConfigurationObserver> observers;

  public NamespaceConfiguration(String namespaceId, AccumuloConfiguration parent) {
    inst = HdfsZooInstance.getInstance();
    this.parent = parent;
    this.namespaceId = namespaceId;
    this.observers = Collections.synchronizedSet(new HashSet<ConfigurationObserver>());
    String value = theseProps.get(key);

    if (value != null) {
      return value;
    }

    return getParent().get(property);
  }

  /**
   * exclude system iterators/constraints from the system namespace so that they don't affect the
   * metadata or root tables.
   */
  @Override
  public void getProperties(Map<String,String> props, Predicate<String> filter) {
    Predicate<String> parentFilter = filter;
    // exclude system iterators/constraints from the system namespace
    // so they don't affect the metadata or root tables.
    if (getNamespaceId().equals(Namespace.ACCUMULO.id()))
      parentFilter = key -> !isIteratorOrConstraint(key) && filter.test(key);

    getParent().getProperties(props, parentFilter);

    getSnapshot().entrySet().stream().filter(e -> filter.test(e.getKey()) && e.getValue() != null)
    return value;
  }

  private synchronized static ZooCache getPropCache() {
    Instance inst = HdfsZooInstance.getInstance();
    if (propCache == null)
	propCache = new ZooCache(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), new NamespaceConfWatcher(inst));
    return propCache;
  }


<MSG> ACCUMULO-2515 ACCUMULO-2489 Apply same fixes from TableConfiguration to
NamespaceConfiguration

Also switch over TableConfigurationUpdateIT to use SimpleMacIT instead
of doing it itself.

<DFF> @@ -38,13 +38,18 @@ public class NamespaceConfiguration extends AccumuloConfiguration {
   private static final Logger log = Logger.getLogger(NamespaceConfiguration.class);
 
   private final AccumuloConfiguration parent;
-  private static ZooCache propCache = null;
+  private static volatile ZooCache propCache = null;
+  private static final Object lock = new Object();
   protected String namespaceId = null;
   protected Instance inst = null;
   private Set<ConfigurationObserver> observers;
 
   public NamespaceConfiguration(String namespaceId, AccumuloConfiguration parent) {
-    inst = HdfsZooInstance.getInstance();
+    this(namespaceId, HdfsZooInstance.getInstance(), parent);
+  }
+
+  public NamespaceConfiguration(String namespaceId, Instance inst, AccumuloConfiguration parent) {
+    this.inst = inst;
     this.parent = parent;
     this.namespaceId = namespaceId;
     this.observers = Collections.synchronizedSet(new HashSet<ConfigurationObserver>());
@@ -75,10 +80,17 @@ public class NamespaceConfiguration extends AccumuloConfiguration {
     return value;
   }
 
-  private synchronized static ZooCache getPropCache() {
-    Instance inst = HdfsZooInstance.getInstance();
-    if (propCache == null)
-	propCache = new ZooCache(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), new NamespaceConfWatcher(inst));
+  private void initializePropCache() {
+    synchronized (lock) {
+      if (propCache == null)
+        propCache = new ZooCache(inst.getZooKeepers(), inst.getZooKeepersSessionTimeOut(), new NamespaceConfWatcher(inst));
+    }
+  }
+
+  private ZooCache getPropCache() {
+    if (null == propCache) {
+      initializePropCache();
+    }
     return propCache;
   }
 

{'addition_count': 18, 'commit_subject': 'ACCUMULO-2515 ACCUMULO-2489 Apply same fixes from TableConfiguration to NamespaceConfiguration', 'deletion_count': 6, 'file_extension': '.java', 'lang': 'java', 'license': 'apache-2.0', 'repo_name': 'apache/accumulo'}