incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/4] git commit: Adding in a tablecontext warmup timer.
Date Sat, 22 Mar 2014 21:01:02 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/apache-blur-0.2 859e37c40 -> 831d22f38


Adding in a tablecontext warmup timer.


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

Branch: refs/heads/apache-blur-0.2
Commit: eda29d7427a217509da92dcb11eca20e2f1fea63
Parents: 859e37c
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Sat Mar 22 11:30:58 2014 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Sat Mar 22 11:30:58 2014 -0400

----------------------------------------------------------------------
 .../blur/thrift/BlurControllerServer.java       | 41 +++++++++++++++++++-
 1 file changed, 39 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eda29d74/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java b/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java
index f04c5ac..06f5ea3 100644
--- a/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java
+++ b/blur-core/src/main/java/org/apache/blur/thrift/BlurControllerServer.java
@@ -29,6 +29,7 @@ import java.util.IdentityHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Random;
 import java.util.Set;
 import java.util.Timer;
 import java.util.TimerTask;
@@ -63,6 +64,7 @@ import org.apache.blur.manager.results.MergerBlurResultIterable;
 import org.apache.blur.manager.stats.MergerTableStats;
 import org.apache.blur.manager.status.MergerQueryStatusSingle;
 import org.apache.blur.server.ControllerServerContext;
+import org.apache.blur.server.TableContext;
 import org.apache.blur.thirdparty.thrift_0_9_0.TException;
 import org.apache.blur.thirdparty.thrift_0_9_0.protocol.TProtocol;
 import org.apache.blur.thirdparty.thrift_0_9_0.transport.TFramedTransport;
@@ -176,6 +178,8 @@ public class BlurControllerServer extends TableAdmin implements Iface
{
   private long _maxFetchDelay = 2000;
   private long _maxMutateDelay = 2000;
   private long _maxDefaultDelay = 2000;
+  private long _preconnectTime = TimeUnit.MINUTES.toMillis(1);
+  private long _preconnectDelay = 15000;
 
   private long _defaultParallelCallTimeout = TimeUnit.MINUTES.toMillis(1);
   private WatchChildren _watchForClusters;
@@ -185,6 +189,7 @@ public class BlurControllerServer extends TableAdmin implements Iface
{
   private ConcurrentMap<String, WatchChildren> _watchForTableLayoutChanges = new ConcurrentHashMap<String,
WatchChildren>();
   private ConcurrentMap<String, WatchChildren> _watchForOnlineShardsPerCluster = new
ConcurrentHashMap<String, WatchChildren>();
   private Timer _preconnectTimer;
+  private Timer _tableContextWarmupTimer;
 
   public void init() throws KeeperException, InterruptedException {
     setupZookeeper();
@@ -198,6 +203,34 @@ public class BlurControllerServer extends TableAdmin implements Iface
{
       updateLayout(cluster);
     }
     startPreconnectTimer();
+    startTableContextWarmupTimer();
+  }
+
+  private void startTableContextWarmupTimer() {
+    _tableContextWarmupTimer = new Timer("controller tablecontext warmup", true);
+    _tableContextWarmupTimer.schedule(new TimerTask() {
+      @Override
+      public void run() {
+        try {
+          tableContextWarmup();
+        } catch (Exception e) {
+          LOG.error("Unknown error while trying to preconnect to shard servers.", e);
+        }
+      }
+    }, getRandomDelay(_preconnectDelay, _preconnectDelay * 4), TimeUnit.MINUTES.toMillis(1));
+  }
+
+  protected void tableContextWarmup() throws BlurException, TException {
+    for (String table : tableList()) {
+      LOG.debug("Warming the tablecontext for table [{0}]", table);
+      TableDescriptor describe = describe(table);
+      TableContext.create(describe);
+    }
+  }
+
+  private long getRandomDelay(long min, long max) {
+    Random random = new Random();
+    return random.nextInt((int) (max - min)) + min;
   }
 
   private void startPreconnectTimer() {
@@ -211,7 +244,7 @@ public class BlurControllerServer extends TableAdmin implements Iface
{
           LOG.error("Unknown error while trying to preconnect to shard servers.", e);
         }
       }
-    }, TimeUnit.SECONDS.toMillis(5), TimeUnit.SECONDS.toMillis(5));
+    }, _preconnectDelay, _preconnectTime);
   }
 
   private void preconnectClients() {
@@ -389,6 +422,10 @@ public class BlurControllerServer extends TableAdmin implements Iface
{
       _closed.set(true);
       _running.set(false);
       _executor.shutdownNow();
+      _preconnectTimer.cancel();
+      _preconnectTimer.purge();
+      _tableContextWarmupTimer.cancel();
+      _tableContextWarmupTimer.purge();
       close(_watchForClusters);
       close(_watchForOnlineShardsPerCluster.values());
       close(_watchForOnlineShardsPerClusterExistance.values());
@@ -1175,7 +1212,7 @@ public class BlurControllerServer extends TableAdmin implements Iface
{
       throw new BException("Unknown error during mutation.", e);
     }
   }
-  
+
   @Override
   public void enqueueMutateBatch(List<RowMutation> mutations) throws BlurException,
TException {
     try {


Mime
View raw message