keith-turner commented on a change in pull request #2324: URL: https://github.com/apache/accumulo/pull/2324#discussion_r747850728
########## File path: server/base/src/main/java/org/apache/accumulo/server/conf/store/impl/ZooPropLoader.java ########## @@ -0,0 +1,169 @@ +/* + * 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 java.util.concurrent.TimeUnit; + +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); + Stat stat = new Stat(); + long startNanos = System.nanoTime(); + + var vProps = propCodec.fromBytes(zrw.getData(propCacheId.getPath(), propStoreWatcher, stat)); + + metrics.addLoadTime( + TimeUnit.MILLISECONDS.convert(System.nanoTime() - startNanos, TimeUnit.NANOSECONDS)); + + if (stat.getVersion() != vProps.getDataVersion()) { + log.warn("data versions between decoded value {} and zk value {} do not match", + vProps.getDataVersion(), stat.getVersion()); + return null; + } + return vProps; + } catch (Exception ex) { + metrics.incrZkError(); + log.warn("Failed to load: {} from ZooKeeper, returning null", propCacheId, ex); + propStoreWatcher.signalZkChangeEvent(propCacheId); + return null; + } + } + + @Override + public CompletableFuture<? extends VersionedProperties> asyncLoad(PropCacheId propCacheId, + Executor executor) { + log.trace("asyncLoad called for key: {}", propCacheId); + return CacheLoader.super.asyncLoad(propCacheId, executor); + } + + @Override + public CompletableFuture<? extends VersionedProperties> asyncReload(PropCacheId propCacheId, + VersionedProperties oldValue, Executor executor) throws Exception { + log.trace("asyncReload called for key: {}", propCacheId); + metrics.incrRefresh(); + + return CompletableFuture.supplyAsync(() -> loadIfDifferentVersion(propCacheId, oldValue)); Review comment: > There is a thread pool specified there and I think Caffeine will use that pool and not the general JVM pool. CompletableFuture.supplyAsync() is a java function that has no awareness of any caffeine thread pools. Looking at the [javadoc](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/CompletableFuture.html#supplyAsync(java.util.function.Supplier)) it says. > Returns a new CompletableFuture that is asynchronously completed by a task running in the ForkJoinPool.commonPool() with the value obtained by calling the given Supplier. That ForkJoinPool.commonPool() is static JVM wide thread pool. There is another version of [supply async that takes a thread pool](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/concurrent/CompletableFuture.html#supplyAsync(java.util.function.Supplier,java.util.concurrent.Executor)). -- 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]
