incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [3/4] git commit: Adding trace logic to the thrift cache.
Date Wed, 04 Mar 2015 13:54:31 GMT
Adding trace logic to the thrift cache.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/cd4d44de
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/cd4d44de
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/cd4d44de

Branch: refs/heads/master
Commit: cd4d44de8fdf70fe0471835a8a8b5b929ee0320c
Parents: 3175976
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Wed Mar 4 08:52:14 2015 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Wed Mar 4 08:52:14 2015 -0500

----------------------------------------------------------------------
 .../org/apache/blur/server/cache/ClassObj.java  |  5 ++
 .../apache/blur/server/cache/ThriftCache.java   | 71 ++++++++++++++------
 2 files changed, 54 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/cd4d44de/blur-core/src/main/java/org/apache/blur/server/cache/ClassObj.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/server/cache/ClassObj.java b/blur-core/src/main/java/org/apache/blur/server/cache/ClassObj.java
index eabcc7b..9d595f6 100644
--- a/blur-core/src/main/java/org/apache/blur/server/cache/ClassObj.java
+++ b/blur-core/src/main/java/org/apache/blur/server/cache/ClassObj.java
@@ -48,4 +48,9 @@ public class ClassObj<T> {
     return _clazz == other._clazz;
   }
 
+  @Override
+  public String toString() {
+    return "ClassObj [_clazz=" + _clazz + "]";
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/cd4d44de/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java b/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java
index bf6237b..3050d1e 100644
--- a/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java
+++ b/blur-core/src/main/java/org/apache/blur/server/cache/ThriftCache.java
@@ -30,6 +30,8 @@ import org.apache.blur.log.Log;
 import org.apache.blur.log.LogFactory;
 import org.apache.blur.thirdparty.thrift_0_9_0.TBase;
 import org.apache.blur.thrift.generated.BlurException;
+import org.apache.blur.trace.Trace;
+import org.apache.blur.trace.Tracer;
 import org.apache.blur.user.User;
 import org.apache.blur.user.UserContext;
 
@@ -43,6 +45,15 @@ import com.yammer.metrics.core.MetricName;
 
 public class ThriftCache {
 
+  private static final String KEY = "key";
+  private static final String CLASS = "class";
+  private static final String T_KEY = "tKey";
+  private static final String SHARDS = "shards";
+  private static final String TABLE = "table";
+  private static final String THRIFT_CACHE_PUT = "ThriftCache - put";
+  private static final String THRIFT_CACHE_GET = "ThriftCache - get";
+  private static final String THRIFT_CACHE_GET_KEY = "ThriftCache - getKey";
+
   private static final Log LOG = LogFactory.getLog(ThriftCache.class);
 
   private final ConcurrentLinkedHashMap<ThriftCacheKey<?>, ThriftCacheValue<?>>
_cacheMap;
@@ -83,40 +94,56 @@ public class ThriftCache {
   }
 
   public <K extends TBase<?, ?>, V extends TBase<?, ?>> V put(ThriftCacheKey<K>
key, V t) throws BlurException {
-    synchronized (_lastModTimestamps) {
-      Long lastModTimestamp = _lastModTimestamps.get(key.getTable());
-      if (lastModTimestamp != null && key.getTimestamp() < lastModTimestamp) {
-        // This means that the key was created before the index was modified. So
-        // do not cache the value because it's already out of date with the
-        // index.
-        return t;
+    Tracer trace = Trace.trace(THRIFT_CACHE_PUT, Trace.param(KEY, key));
+    try {
+      synchronized (_lastModTimestamps) {
+        Long lastModTimestamp = _lastModTimestamps.get(key.getTable());
+        if (lastModTimestamp != null && key.getTimestamp() < lastModTimestamp)
{
+          // This means that the key was created before the index was modified.
+          // So do not cache the value because it's already out of date with the
+          // index.
+          return t;
+        }
       }
+      LOG.debug("Inserting into cache [{0}] with key [{1}]", t, key);
+      _cacheMap.put(key, new ThriftCacheValue<V>(t));
+      return t;
+    } finally {
+      trace.done();
     }
-    LOG.debug("Inserting into cache [{0}] with key [{1}]", t, key);
-    _cacheMap.put(key, new ThriftCacheValue<V>(t));
-    return t;
   }
 
   @SuppressWarnings("unchecked")
   public <K extends TBase<?, ?>, V extends TBase<?, ?>> V get(ThriftCacheKey<K>
key, Class<V> clazz)
       throws BlurException {
-    ThriftCacheValue<V> value = (ThriftCacheValue<V>) _cacheMap.get(key);
-    if (value == null) {
-      LOG.debug("Cache Miss for [{0}]", key);
-      _misses.mark();
-      _missesAtomicLong.incrementAndGet();
-      return null;
+    Tracer trace = Trace.trace(THRIFT_CACHE_GET, Trace.param(KEY, key));
+    try {
+      ThriftCacheValue<V> value = (ThriftCacheValue<V>) _cacheMap.get(key);
+      if (value == null) {
+        LOG.debug("Cache Miss for [{0}]", key);
+        _misses.mark();
+        _missesAtomicLong.incrementAndGet();
+        return null;
+      }
+      LOG.debug("Cache Hit for [{0}]", key);
+      _hits.mark();
+      _hitsAtomicLong.incrementAndGet();
+      return value.getValue(clazz);
+    } finally {
+      trace.done();
     }
-    LOG.debug("Cache Hit for [{0}]", key);
-    _hits.mark();
-    _hitsAtomicLong.incrementAndGet();
-    return value.getValue(clazz);
   }
 
   public <K extends TBase<?, ?>> ThriftCacheKey<K> getKey(String table,
int[] shards, K tkey, Class<K> clazz)
       throws BlurException {
-    User user = UserContext.getUser();
-    return new ThriftCacheKey<K>(user, table, shards, tkey, clazz);
+    Tracer trace = Trace.trace(THRIFT_CACHE_GET_KEY, Trace.param(TABLE, table), Trace.param(SHARDS,
shards),
+        Trace.param(T_KEY, tkey), Trace.param(CLASS, clazz));
+    try {
+      User user = UserContext.getUser();
+      return new ThriftCacheKey<K>(user, table, shards, tkey, clazz);
+    } finally {
+      trace.done();
+    }
   }
 
   public void clearTable(String table) {


Mime
View raw message