mcvsubbu commented on a change in pull request #4356: Emit metrics to track performance against specific Service-Level-Objectives (SLO) URL: https://github.com/apache/incubator-pinot/pull/4356#discussion_r296917708
########## File path: pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/LazyTableConfigCache.java ########## @@ -0,0 +1,105 @@ +/** + * 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.pinot.broker.requesthandler; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.util.concurrent.ListenableFuture; +import com.google.common.util.concurrent.ListenableFutureTask; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.annotation.concurrent.ThreadSafe; +import org.apache.helix.ZNRecord; +import org.apache.helix.store.zk.ZkHelixPropertyStore; +import org.apache.pinot.common.config.TableConfig; +import org.apache.pinot.common.config.TableNameBuilder; +import org.apache.pinot.common.metadata.ZKMetadataProvider; + + +/** + * A cache for table-config objects maintained by the broker. The cache is implemented as a lazy-cache: i.e., on a + * cache miss, the value is fetched asynchronously/lazily - the caller is not blocked and can expect to get null or + * a previously cached value. + * + * This cache should be used only for best-effort cases, where absence of the value does not have critical implications. + * + * The cache is unbounded as we don't expect an ever-growing or very large number of tables to be served by a single + * broker. + */ +@ThreadSafe +public class LazyTableConfigCache { + + private static final int CACHE_TIMEOUT_MINS = 60; + + private final LoadingCache<String, TableConfig> _configCache; + private final ZkHelixPropertyStore<ZNRecord> _propertyStore; + private final ExecutorService _executorService; + + public LazyTableConfigCache(ZkHelixPropertyStore<ZNRecord> propertyStore) { + _propertyStore = propertyStore; + _executorService = Executors.newCachedThreadPool(); + + _configCache = CacheBuilder.newBuilder().refreshAfterWrite(CACHE_TIMEOUT_MINS, TimeUnit.MINUTES) + .build(new CacheLoader<String, TableConfig>() { + @Override + public TableConfig load(@Nonnull String rawTableName) { + return ZKMetadataProvider.getTableConfig(_propertyStore, rawTableName); + } + + @Override + public ListenableFuture<TableConfig> reload(String tableName, TableConfig oldValue) { + ListenableFutureTask<TableConfig> task = + ListenableFutureTask.create(() -> ZKMetadataProvider.getTableConfig(_propertyStore, tableName)); Review comment: this call takes a typed table name, not raw table name. We store configs for typed table names, not on raw table name ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
