keith-turner commented on code in PR #2569: URL: https://github.com/apache/accumulo/pull/2569#discussion_r855531387
########## server/base/src/main/java/org/apache/accumulo/server/conf/util/PropSnapshot.java: ########## @@ -0,0 +1,106 @@ +/* + * 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.util; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import org.apache.accumulo.server.conf.codec.VersionedProperties; +import org.apache.accumulo.server.conf.store.PropCacheKey; +import org.apache.accumulo.server.conf.store.PropStore; +import org.apache.accumulo.server.conf.store.PropStoreException; +import org.checkerframework.checker.nullness.qual.NonNull; + +/** + * This class provides a secondary, local cache of properties and is intended to be used to optimize + * constructing a configuration hierarchy from the underlying properties stored in ZooKeeper. + * <p> + * Configurations and especially the derivers use an updateCount to detect configuration changes. + * The updateCount is checked frequently and the configuration hierarchy rebuilt when a change is + * detected. + */ +public class PropSnapshot { + + private final Lock updateLock = new ReentrantLock(); + private final AtomicBoolean needsUpdate = new AtomicBoolean(true); + private final AtomicReference<VersionedProperties> vPropRef = new AtomicReference<>(); + private final PropCacheKey propCacheKey; + private final PropStore propStore; + + public PropSnapshot(final PropCacheKey propCacheKey, final PropStore propStore) { + this.propCacheKey = propCacheKey; + this.propStore = propStore; + + updateSnapshot(); + } + + /** + * Get the current snapshot - updating if necessary. + * + * @return the current property snapshot. + */ + public @NonNull VersionedProperties get() { + if (needsUpdate.get()) { + updateSnapshot(); + } Review Comment: The `updateSnapshot()` function checks needsUpdate, so its redundant to check here. ```suggestion updateSnapshot(); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
