fluo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject [fluo] branch master updated: fixes #938 made tx info cache configurable (#941)
Date Thu, 19 Oct 2017 00:53:01 GMT
This is an automated email from the ASF dual-hosted git repository.

kturner pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/fluo.git


The following commit(s) were added to refs/heads/master by this push:
     new 650f044  fixes #938 made tx info cache configurable (#941)
650f044 is described below

commit 650f044b7db16e732cfbf32f484f05ec34837df8
Author: Kenneth <kennethpmcfarland@gmail.com>
AuthorDate: Thu Oct 12 16:04:22 2017 -0700

    fixes #938 made tx info cache configurable (#941)
---
 .../fluo/core/impl/FluoConfigurationImpl.java      | 42 ++++++++++++++++++++++
 .../org/apache/fluo/core/impl/TxInfoCache.java     | 10 ++++--
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/fluo/core/impl/FluoConfigurationImpl.java
b/modules/core/src/main/java/org/apache/fluo/core/impl/FluoConfigurationImpl.java
index 3e5ee85..febb318 100644
--- a/modules/core/src/main/java/org/apache/fluo/core/impl/FluoConfigurationImpl.java
+++ b/modules/core/src/main/java/org/apache/fluo/core/impl/FluoConfigurationImpl.java
@@ -15,6 +15,8 @@
 
 package org.apache.fluo.core.impl;
 
+import java.util.concurrent.TimeUnit;
+
 import org.apache.fluo.api.config.FluoConfiguration;
 
 /**
@@ -102,6 +104,46 @@ public class FluoConfigurationImpl {
     return m;
   }
 
+  public static final String TX_INFO_CACHE_SIZE = FLUO_IMPL_PREFIX + ".tx.failed.cache.size.mb";
+  public static final long TX_INFO_CACHE_SIZE_DEFAULT = 10000000;
+
+  /** 
+   * Gets the cache size
+   * 
+   * @param conf The FluoConfiguration
+   * @return The size of the cache value from the property value {@value #TX_INFO_CACHE_SIZE}
+   *     if it is set, else the value of the default value {@value #TX_INFO_CACHE_SIZE_DEFAULT}
+   */
+
+  public static long getTxInfoCacheSize(FluoConfiguration conf) {
+    long size = conf.getLong(TX_INFO_CACHE_SIZE, TX_INFO_CACHE_SIZE_DEFAULT);
+    if (size <= 0) {
+      throw new IllegalArgumentException("Cache size must be positive for " + TX_INFO_CACHE_SIZE);
+    }
+    return size;
+  }
+
+  public static final String TX_INFO_CACHE_TIMEOUT =
+      FLUO_IMPL_PREFIX + ".tx.failed.cache.expireTime.ms";
+  public static final long TX_INFO_CACHE_TIMEOUT_DEFAULT = 24 * 60 * 1000;
+
+  /**
+   * Gets the time before stale entries in the cache are evicted based on age.
+   * This method returns a long representing the time converted from the
+   * TimeUnit passed in.
+   * 
+   * @param conf The FluoConfiguration
+   * @param tu   The TimeUnit desired to represent the cache timeout
+   */
+
+  public static long getTxIfoCacheTimeout(FluoConfiguration conf, TimeUnit tu) {
+    long millis = conf.getLong(TX_INFO_CACHE_TIMEOUT, TX_INFO_CACHE_TIMEOUT_DEFAULT);
+    if (millis <= 0) {
+      throw new IllegalArgumentException("Timeout must positive for " + TX_INFO_CACHE_TIMEOUT);
+    }
+    return tu.convert(millis, TimeUnit.MILLISECONDS);
+  }
+
   public static final String ASYNC_CW_THREADS = FLUO_IMPL_PREFIX + ".async.cw.threads";
   public static final int ASYNC_CW_THREADS_DEFAULT = 8;
   public static final String ASYNC_CW_LIMIT = FLUO_IMPL_PREFIX + ".async.cw.limit";
diff --git a/modules/core/src/main/java/org/apache/fluo/core/impl/TxInfoCache.java b/modules/core/src/main/java/org/apache/fluo/core/impl/TxInfoCache.java
index ed43be2..ddd4900 100644
--- a/modules/core/src/main/java/org/apache/fluo/core/impl/TxInfoCache.java
+++ b/modules/core/src/main/java/org/apache/fluo/core/impl/TxInfoCache.java
@@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit;
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.Weigher;
+import org.apache.fluo.api.config.FluoConfiguration;
 import org.apache.fluo.api.data.Bytes;
 import org.apache.fluo.api.data.Column;
 
@@ -38,8 +39,12 @@ public class TxInfoCache {
   private final Environment env;
 
   TxInfoCache(Environment env) {
-    cache = CacheBuilder.newBuilder().expireAfterAccess(CACHE_TIMEOUT_MIN, TimeUnit.MINUTES)
-        .maximumWeight(10000000).weigher(new TxStatusWeigher()).concurrencyLevel(10).build();
+    final FluoConfiguration conf = env.getConfiguration();
+    cache = CacheBuilder.newBuilder()
+        .expireAfterAccess(FluoConfigurationImpl.getTxIfoCacheTimeout(conf, TimeUnit.MILLISECONDS),
+            TimeUnit.MILLISECONDS)
+        .maximumWeight(FluoConfigurationImpl.getTxInfoCacheSize(conf))
+        .weigher(new TxStatusWeigher()).concurrencyLevel(10).build();
     this.env = env;
   }
 
@@ -58,7 +63,6 @@ public class TxInfoCache {
         cache.put(key, txInfo);
       }
     }
-
     return txInfo;
   }
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@fluo.apache.org" <commits@fluo.apache.org>'].

Mime
View raw message