You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by GitBox <gi...@apache.org> on 2019/11/21 20:24:46 UTC

[GitHub] [incubator-pinot] jihaozh commented on a change in pull request #4842: [TE] add detection health for the alerts list

jihaozh commented on a change in pull request #4842: [TE] add detection health for the alerts list
URL: https://github.com/apache/incubator-pinot/pull/4842#discussion_r349300642
 
 

 ##########
 File path: thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/datasource/cache/metadata/MetaDataCollectionCache.java
 ##########
 @@ -0,0 +1,83 @@
+/*
+ *  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.thirdeye.datasource.cache.metadata;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * The cache for a meta-data collection.
+ * This cache will hold a collection of meta-data and periodically reloads it using the cache loader.
+ *
+ * It's designed to cache the original or derived meta-data collection for ThirdEye Dashboard server, for example, a
+ * list of all applications, subscription groups, and detection configs. Loading a collection of metadata has been
+ * a pain point for ThirdEye. It requires data base to scan the index table and then do a look up for each config in the
+ * generic json table, which is slow. This cache makes such loading asynchronous and returns user the cached result
+ * when opening page.
+ *
+ * @param <T> the type of the value to be cached.
+ */
+public class MetaDataCollectionCache<T> {
+  private static final String META_DATA_KEY = "metaData";
+  protected static final Logger LOG = LoggerFactory.getLogger(MetaDataCollectionCache.class);
+  private final LoadingCache<String, T> loadingCache;
+
+  /**
+   * Create a Metadata collection cache
+   * @param cacheLoader the cache loader for the meta data collection
+   * @param reloadPeriod the period of the reloading frequency
+   * @param reloadUnit the unit for the reload period
+   */
+  public MetaDataCollectionCache(MetadataCacheLoader<T> cacheLoader, int reloadPeriod, TimeUnit reloadUnit) {
+    this.loadingCache = CacheBuilder.newBuilder()
+        .expireAfterWrite(10, TimeUnit.MINUTES)
 
 Review comment:
   Good point. Yes, it should. It will trigger a cache refresh whenever the user changes the config.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org