PHOENIX-5010 Don't build client guidepost cache when 
phoenix.stats.collection.enabled is disabled


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/21c3a7c2
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/21c3a7c2
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/21c3a7c2

Branch: refs/heads/4.x-cdh5.15
Commit: 21c3a7c2e9cd4d4f59623dd987c6602304ac9335
Parents: a0e9859
Author: Ankit Singhal <ankitsingha...@gmail.com>
Authored: Tue Nov 13 19:36:26 2018 +0000
Committer: Pedro Boado <pbo...@apache.org>
Committed: Tue Nov 27 15:11:41 2018 +0000

----------------------------------------------------------------------
 .../org/apache/phoenix/query/GuidePostsCache.java | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/21c3a7c2/phoenix-core/src/main/java/org/apache/phoenix/query/GuidePostsCache.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/query/GuidePostsCache.java 
b/phoenix-core/src/main/java/org/apache/phoenix/query/GuidePostsCache.java
index d27be1b..1d9fa36 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/GuidePostsCache.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/GuidePostsCache.java
@@ -16,6 +16,10 @@
  */
 package org.apache.phoenix.query;
 
+import static org.apache.phoenix.query.QueryServices.STATS_COLLECTION_ENABLED;
+import static org.apache.phoenix.query.QueryServices.STATS_ENABLED_ATTRIB;
+import static 
org.apache.phoenix.query.QueryServicesOptions.DEFAULT_STATS_COLLECTION_ENABLED;
+
 import java.io.IOException;
 import java.util.List;
 import java.util.Objects;
@@ -66,6 +70,8 @@ public class GuidePostsCache {
         final long maxTableStatsCacheSize = config.getLong(
                 QueryServices.STATS_MAX_CACHE_SIZE,
                 QueryServicesOptions.DEFAULT_STATS_MAX_CACHE_SIZE);
+               final boolean isStatsEnabled = 
config.getBoolean(STATS_COLLECTION_ENABLED, DEFAULT_STATS_COLLECTION_ENABLED)
+                               && config.getBoolean(STATS_ENABLED_ATTRIB, 
true);
         cache = CacheBuilder.newBuilder()
                 // Expire entries a given amount of time after they were 
written
                 .expireAfterWrite(statsUpdateFrequency, TimeUnit.MILLISECONDS)
@@ -80,7 +86,7 @@ public class GuidePostsCache {
                 // Log removals at TRACE for debugging
                 .removalListener(new PhoenixStatsCacheRemovalListener())
                 // Automatically load the cache when entries are missing
-                .build(new StatsLoader());
+                .build(isStatsEnabled ? new StatsLoader() : new 
EmptyStatsLoader());
     }
 
     /**
@@ -129,6 +135,16 @@ public class GuidePostsCache {
     }
 
     /**
+     * Empty stats loader if stats are disabled
+     */
+       protected class EmptyStatsLoader extends CacheLoader<GuidePostsKey, 
GuidePostsInfo> {
+               @Override
+               public GuidePostsInfo load(GuidePostsKey statsKey) throws 
Exception {
+                       return GuidePostsInfo.NO_GUIDEPOST;
+               }
+       }
+
+    /**
      * Returns the underlying cache. Try to use the provided methods instead 
of accessing the cache
      * directly.
      */

Reply via email to