EdColeman commented on a change in pull request #2324: URL: https://github.com/apache/accumulo/pull/2324#discussion_r739358399
########## File path: server/base/src/main/java/org/apache/accumulo/server/conf/store/impl/ZooPropLoader.java ########## @@ -0,0 +1,163 @@ +/* + * 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.store.impl; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.Executor; + +import org.apache.accumulo.fate.zookeeper.ZooReaderWriter; +import org.apache.accumulo.server.conf.codec.VersionedPropCodec; +import org.apache.accumulo.server.conf.codec.VersionedProperties; +import org.apache.accumulo.server.conf.store.PropCacheId; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.data.Stat; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.github.benmanes.caffeine.cache.CacheLoader; + +public class ZooPropLoader implements CacheLoader<PropCacheId,VersionedProperties> { + + private static final Logger log = LoggerFactory.getLogger(ZooPropLoader.class); + + private final ZooReaderWriter zrw; + private final VersionedPropCodec propCodec; + // used to set watcher, does not react to events. + private final PropStoreWatcher propStoreWatcher; + private final PropStoreMetrics metrics; + + public ZooPropLoader(final ZooReaderWriter zrw, final VersionedPropCodec propCodec, + final PropStoreWatcher propStoreWatcher, final PropStoreMetrics metrics) { + this.zrw = zrw; + this.propCodec = propCodec; + this.propStoreWatcher = propStoreWatcher; + this.metrics = metrics; + } + + @Override + public @Nullable VersionedProperties load(PropCacheId propCacheId) { + try { + log.trace("load called for {}", propCacheId); + metrics.updateLoadCounter(); + Stat stat = new Stat(); + var vProps = propCodec.fromBytes(zrw.getData(propCacheId.getPath(), propStoreWatcher, stat)); + if (stat.getVersion() != vProps.getDataVersion()) { Review comment: While it could be achieved using just the stat version of the node, the properties would still need to hold and track that value and I felt it simplified reasoning if the VersionProperties value was "truth" and the ZkNode was used as reference. I also explored what would be necessary to provide strongly versioned properties if something other than ZooKeeper was used as the store, and carried it over from that. -- 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]
