incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: Fixed BLUR-146
Date Thu, 20 Jun 2013 14:53:20 GMT
Updated Branches:
  refs/heads/master 425c63ec0 -> c9c875c09


Fixed BLUR-146


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

Branch: refs/heads/master
Commit: c9c875c09e0ed651b554fa2f2ab4bfba94aee82d
Parents: 425c63e
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Thu Jun 20 10:52:24 2013 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Thu Jun 20 10:52:24 2013 -0400

----------------------------------------------------------------------
 .../clusterstatus/ZookeeperClusterStatus.java   | 95 ++++++++++----------
 .../blur/manager/indexserver/SafeMode.java      |  4 +-
 .../blur/manager/indexserver/SafeModeTest.java  |  6 +-
 .../main/java/org/apache/blur/shell/Main.java   | 45 ++++++++--
 .../blur/shell/WaitInSafemodeCommand.java       | 64 +++++++++++++
 .../blur/zookeeper/ZooKeeperLockManager.java    | 13 ++-
 distribution/src/main/scripts/bin/blur          | 12 +--
 7 files changed, 177 insertions(+), 62 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c9c875c0/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperClusterStatus.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperClusterStatus.java
b/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperClusterStatus.java
index 6354366..b6bf61a 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperClusterStatus.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperClusterStatus.java
@@ -49,6 +49,7 @@ import org.apache.blur.zookeeper.WatchChildren.OnChange;
 import org.apache.blur.zookeeper.WatchNodeData;
 import org.apache.blur.zookeeper.WatchNodeExistance;
 import org.apache.blur.zookeeper.ZkUtils;
+import org.apache.blur.zookeeper.ZooKeeperLockManager;
 import org.apache.hadoop.io.compress.CompressionCodec;
 import org.apache.hadoop.io.compress.DefaultCodec;
 import org.apache.lucene.search.similarities.Similarity;
@@ -104,7 +105,8 @@ public class ZookeeperClusterStatus extends ClusterStatus {
           _tableWatchers.put(cluster, clusterWatcher);
           String safemodePath = ZookeeperPathConstants.getSafemodePath(cluster);
           ZkUtils.waitUntilExists(_zk, safemodePath);
-          WatchNodeExistance watchNodeExistance = new WatchNodeExistance(_zk, safemodePath).watch(new
SafeExistance(cluster));
+          WatchNodeExistance watchNodeExistance = new WatchNodeExistance(_zk, safemodePath).watch(new
SafeExistance(
+              cluster));
           _safeModeWatchers.put(cluster, watchNodeExistance);
         }
       }
@@ -170,7 +172,8 @@ public class ZookeeperClusterStatus extends ClusterStatus {
       for (String table : newTables) {
         final String clusterTableKey = getClusterTableKey(cluster, table);
 
-        WatchNodeExistance readOnlyWatcher = new WatchNodeExistance(_zk, ZookeeperPathConstants.getTableReadOnlyPath(cluster,
table));
+        WatchNodeExistance readOnlyWatcher = new WatchNodeExistance(_zk, ZookeeperPathConstants.getTableReadOnlyPath(
+            cluster, table));
         readOnlyWatcher.watch(new WatchNodeExistance.OnChange() {
           @Override
           public void action(Stat stat) {
@@ -185,7 +188,8 @@ public class ZookeeperClusterStatus extends ClusterStatus {
           readOnlyWatcher.close();
         }
 
-        WatchNodeExistance enabledWatcher = new WatchNodeExistance(_zk, ZookeeperPathConstants.getTableEnabledPath(cluster,
table));
+        WatchNodeExistance enabledWatcher = new WatchNodeExistance(_zk, ZookeeperPathConstants.getTableEnabledPath(
+            cluster, table));
         enabledWatcher.watch(new WatchNodeExistance.OnChange() {
           @Override
           public void action(Stat stat) {
@@ -297,12 +301,13 @@ public class ZookeeperClusterStatus extends ClusterStatus {
   }
 
   private void watchForOnlineShardNodes(final String cluster) {
-    WatchChildren watch = new WatchChildren(_zk, ZookeeperPathConstants.getOnlineShardsPath(cluster)).watch(new
OnChange() {
-      @Override
-      public void action(List<String> children) {
-        _onlineShardsNodes.put(cluster, children);
-      }
-    });
+    WatchChildren watch = new WatchChildren(_zk, ZookeeperPathConstants.getOnlineShardsPath(cluster))
+        .watch(new OnChange() {
+          @Override
+          public void action(List<String> children) {
+            _onlineShardsNodes.put(cluster, children);
+          }
+        });
     if (_onlineShardsNodesWatchers.putIfAbsent(cluster, watch) != null) {
       // There was already a watch created. Close the extra watcher.
       watch.close();
@@ -395,19 +400,23 @@ public class ZookeeperClusterStatus extends ClusterStatus {
     try {
       checkIfOpen();
       NullPointerException npe = null;
-      LOOP:
-      for (int i = 0; i < 10; i++) {
+      LOOP: for (int i = 0; i < 10; i++) {
         npe = null;
         try {
-          tableDescriptor.shardCount = Integer.parseInt(new String(getData(ZookeeperPathConstants.getTableShardCountPath(cluster,
table))));
+          tableDescriptor.shardCount = Integer.parseInt(new String(getData(ZookeeperPathConstants
+              .getTableShardCountPath(cluster, table))));
           tableDescriptor.tableUri = new String(getData(ZookeeperPathConstants.getTableUriPath(cluster,
table)));
-          tableDescriptor.compressionClass = new String(getData(ZookeeperPathConstants.getTableCompressionCodecPath(cluster,
table)));
-          tableDescriptor.compressionBlockSize = Integer.parseInt(new String(getData(ZookeeperPathConstants.getTableCompressionBlockSizePath(cluster,
table))));
-          tableDescriptor.analyzerDefinition = fromBytes(getData(ZookeeperPathConstants.getTablePath(cluster,
table)), AnalyzerDefinition.class);
+          tableDescriptor.compressionClass = new String(getData(ZookeeperPathConstants.getTableCompressionCodecPath(
+              cluster, table)));
+          tableDescriptor.compressionBlockSize = Integer.parseInt(new String(getData(ZookeeperPathConstants
+              .getTableCompressionBlockSizePath(cluster, table))));
+          tableDescriptor.analyzerDefinition = fromBytes(getData(ZookeeperPathConstants.getTablePath(cluster,
table)),
+              AnalyzerDefinition.class);
           tableDescriptor.blockCaching = isBlockCacheEnabled(cluster, table);
           tableDescriptor.blockCachingFileTypes = getBlockCacheFileTypes(cluster, table);
           tableDescriptor.name = table;
-          tableDescriptor.columnPreCache = fromBytes(getData(ZookeeperPathConstants.getTableColumnsToPreCache(cluster,
table)), ColumnPreCache.class);
+          tableDescriptor.columnPreCache = fromBytes(
+              getData(ZookeeperPathConstants.getTableColumnsToPreCache(cluster, table)),
ColumnPreCache.class);
           byte[] data = getData(ZookeeperPathConstants.getTableSimilarityPath(cluster, table));
           if (data != null) {
             tableDescriptor.similarityClass = new String(data);
@@ -467,12 +476,12 @@ public class ZookeeperClusterStatus extends ClusterStatus {
   private byte[] getData(String path) throws KeeperException, InterruptedException {
     Stat stat = _zk.exists(path, false);
     if (stat == null) {
-      LOG.debug("Tried to fetch path [{0}] and path is missing",path);
+      LOG.debug("Tried to fetch path [{0}] and path is missing", path);
       return null;
     }
     byte[] data = _zk.getData(path, false, stat);
     if (data == null) {
-      LOG.debug("Fetched path [{0}] and data is null",path);
+      LOG.debug("Fetched path [{0}] and data is null", path);
       return null;
     }
     return data;
@@ -561,30 +570,15 @@ public class ZookeeperClusterStatus extends ClusterStatus {
 
   @Override
   public boolean isInSafeMode(boolean useCache, String cluster) {
-    if (useCache) {
-      Long safeModeTimestamp = _safeModeMap.get(cluster);
-      if (safeModeTimestamp != null && safeModeTimestamp != Long.MIN_VALUE) {
-        return safeModeTimestamp < System.currentTimeMillis() ? false : true;
-      }
-    }
     long s = System.nanoTime();
     try {
       checkIfOpen();
-      String blurSafemodePath = ZookeeperPathConstants.getSafemodePath(cluster);
-      Stat stat = _zk.exists(blurSafemodePath, false);
-      if (stat == null) {
-        return false;
-      }
-      byte[] data = _zk.getData(blurSafemodePath, false, stat);
-      if (data == null) {
+      String safemodePath = ZookeeperPathConstants.getSafemodePath(cluster);
+      ZooKeeperLockManager zooKeeperLockManager = new ZooKeeperLockManager(_zk, safemodePath);
+      if (zooKeeperLockManager.getNumberOfLockNodesPresent(cluster) == 0) {
         return false;
       }
-      long timestamp = Long.parseLong(new String(data));
-      long waitTime = timestamp - System.currentTimeMillis();
-      if (waitTime > 0) {
-        return true;
-      }
-      return false;
+      return true;
     } catch (KeeperException e) {
       throw new RuntimeException(e);
     } catch (InterruptedException e) {
@@ -704,10 +698,13 @@ public class ZookeeperClusterStatus extends ClusterStatus {
       }
       String table = BlurUtil.nullCheck(tableDescriptor.name, "tableDescriptor.name cannot
be null.");
       String cluster = BlurUtil.nullCheck(tableDescriptor.cluster, "tableDescriptor.cluster
cannot be null.");
-      BlurAnalyzer analyzer = new BlurAnalyzer(BlurUtil.nullCheck(tableDescriptor.analyzerDefinition,
"tableDescriptor.analyzerDefinition cannot be null."));
+      BlurAnalyzer analyzer = new BlurAnalyzer(BlurUtil.nullCheck(tableDescriptor.analyzerDefinition,
+          "tableDescriptor.analyzerDefinition cannot be null."));
       String uri = BlurUtil.nullCheck(tableDescriptor.tableUri, "tableDescriptor.tableUri
cannot be null.");
-      int shardCount = BlurUtil.zeroCheck(tableDescriptor.shardCount, "tableDescriptor.shardCount
cannot be less than 1");
-      CompressionCodec compressionCodec = BlurUtil.getInstance(tableDescriptor.compressionClass,
CompressionCodec.class);
+      int shardCount = BlurUtil.zeroCheck(tableDescriptor.shardCount,
+          "tableDescriptor.shardCount cannot be less than 1");
+      CompressionCodec compressionCodec = BlurUtil
+          .getInstance(tableDescriptor.compressionClass, CompressionCodec.class);
       // @TODO check block size
       int compressionBlockSize = tableDescriptor.compressionBlockSize;
       Similarity similarity = BlurUtil.getInstance(tableDescriptor.similarityClass, Similarity.class);
@@ -721,12 +718,17 @@ public class ZookeeperClusterStatus extends ClusterStatus {
       }
       BlurUtil.setupFileSystem(uri, shardCount);
       BlurUtil.createPath(_zk, blurTablePath, analyzer.toJSON().getBytes());
-      BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableColumnsToPreCache(cluster,
table), BlurUtil.read(columnPreCache));
+      BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableColumnsToPreCache(cluster,
table),
+          BlurUtil.read(columnPreCache));
       BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableUriPath(cluster, table), uri.getBytes());
-      BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableShardCountPath(cluster, table),
Integer.toString(shardCount).getBytes());
-      BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableCompressionCodecPath(cluster,
table), compressionCodec.getClass().getName().getBytes());
-      BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableCompressionBlockSizePath(cluster,
table), Integer.toString(compressionBlockSize).getBytes());
-      BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableSimilarityPath(cluster, table),
similarity.getClass().getName().getBytes());
+      BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableShardCountPath(cluster, table),
+          Integer.toString(shardCount).getBytes());
+      BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableCompressionCodecPath(cluster,
table), compressionCodec
+          .getClass().getName().getBytes());
+      BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableCompressionBlockSizePath(cluster,
table), Integer
+          .toString(compressionBlockSize).getBytes());
+      BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableSimilarityPath(cluster, table),
similarity.getClass()
+          .getName().getBytes());
       BlurUtil.createPath(_zk, ZookeeperPathConstants.getLockPath(cluster, table), null);
       BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableFieldNamesPath(cluster, table),
null);
       if (tableDescriptor.readOnly) {
@@ -735,7 +737,8 @@ public class ZookeeperClusterStatus extends ClusterStatus {
       if (blockCaching) {
         BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableBlockCachingPath(cluster,
table), null);
       }
-      BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableBlockCachingFileTypesPath(cluster,
table), toBytes(blockCachingFileTypes));
+      BlurUtil.createPath(_zk, ZookeeperPathConstants.getTableBlockCachingFileTypesPath(cluster,
table),
+          toBytes(blockCachingFileTypes));
     } catch (IOException e) {
       throw new RuntimeException(e);
     } catch (KeeperException e) {

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c9c875c0/blur-core/src/main/java/org/apache/blur/manager/indexserver/SafeMode.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/indexserver/SafeMode.java b/blur-core/src/main/java/org/apache/blur/manager/indexserver/SafeMode.java
index 9625100..6260adc 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/indexserver/SafeMode.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/indexserver/SafeMode.java
@@ -43,8 +43,8 @@ import org.apache.zookeeper.ZooKeeper;
 public class SafeMode extends ZooKeeperLockManager {
 
   private static final Log LOG = LogFactory.getLog(SafeMode.class);
-  private static final String STARTUP = "STARTUP";
-  private static final String SETUP = "SETUP";
+  public static final String STARTUP = "STARTUP";
+  public static final String SETUP = "SETUP";
 
   private final ZooKeeper zooKeeper;
   

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c9c875c0/blur-core/src/test/java/org/apache/blur/manager/indexserver/SafeModeTest.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/manager/indexserver/SafeModeTest.java
b/blur-core/src/test/java/org/apache/blur/manager/indexserver/SafeModeTest.java
index da06232..0765ce4 100644
--- a/blur-core/src/test/java/org/apache/blur/manager/indexserver/SafeModeTest.java
+++ b/blur-core/src/test/java/org/apache/blur/manager/indexserver/SafeModeTest.java
@@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.blur.MiniCluster;
+import org.apache.blur.zookeeper.ZooKeeperLockManager;
 import org.apache.zookeeper.KeeperException;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
@@ -59,7 +60,7 @@ public class SafeModeTest {
   }
 
   @Test
-  public void testBasicStartup() throws IOException, InterruptedException {
+  public void testBasicStartup() throws IOException, InterruptedException, KeeperException
{
     List<AtomicReference<Throwable>> errors = new ArrayList<AtomicReference<Throwable>>();
     List<AtomicLong> timeRegisteredLst = new ArrayList<AtomicLong>();
     List<Thread> threads = new ArrayList<Thread>();
@@ -93,6 +94,9 @@ public class SafeModeTest {
       }
     }
     assertTrue("newest [" + newest + "] oldest [" + oldest + "]", (newest - oldest) <
TimeUnit.SECONDS.toMillis(5));
+    ZooKeeperLockManager zooKeeperLockManager = new ZooKeeperLockManager(zk, "/testing/safemode");
+    Thread.sleep(5000);
+    assertEquals(0, zooKeeperLockManager.getNumberOfLockNodesPresent(SafeMode.STARTUP));
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c9c875c0/blur-shell/src/main/java/org/apache/blur/shell/Main.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/Main.java b/blur-shell/src/main/java/org/apache/blur/shell/Main.java
index cff751e..bd4ed23 100644
--- a/blur-shell/src/main/java/org/apache/blur/shell/Main.java
+++ b/blur-shell/src/main/java/org/apache/blur/shell/Main.java
@@ -58,11 +58,12 @@ public class Main {
 
   private static Map<String, Command> commands;
   static String cluster;
-  
+
   static String getCluster(Iface client) throws BlurException, TException, CommandException
{
-    return getCluster(client,"There is more than one shard cluster, use \"cluster\" command
to set the cluster that should be in use.");
+    return getCluster(client,
+        "There is more than one shard cluster, use \"cluster\" command to set the cluster
that should be in use.");
   }
-  
+
   static String getCluster(Iface client, String errorMessage) throws BlurException, TException,
CommandException {
     if (cluster != null) {
       return cluster;
@@ -121,7 +122,7 @@ public class Main {
     }
 
   }
-  
+
   private static class ClusterCommand extends Command {
 
     @Override
@@ -222,7 +223,7 @@ public class Main {
 
       out.println();
       out.println(" - Cluster commands - ");
-      String[] clusterCommands = { "controllers", "shards", "clusterlist", "cluster" };
+      String[] clusterCommands = { "controllers", "shards", "clusterlist", "cluster", "safemodewait"
};
       printCommandAndHelp(out, cmds, clusterCommands, bufferLength);
 
       out.println();
@@ -238,6 +239,10 @@ public class Main {
           out.println("  " + buffer(e.getKey(), bufferLength) + " - " + e.getValue().help());
         }
       }
+      
+      out.println();
+      out.println("  " + buffer("shell", bufferLength) + " - enters into the Blur interactive
shell");
+      out.println("  " + buffer("execute", bufferLength) + " - executes a custom class passing
all the command line args to the main method");
     }
 
     private int getMaxCommandLength(Set<String> keySet) {
@@ -292,6 +297,9 @@ public class Main {
   }
 
   public static void main(String[] args) throws Throwable {
+
+    args = removeLeadingShellFromScript(args);
+
     Builder<String, Command> builder = new ImmutableMap.Builder<String, Command>();
     builder.put("help", new HelpCommand());
     builder.put("debug", new DebugCommand());
@@ -317,6 +325,7 @@ public class Main {
     builder.put("shards", new ShardsEchoCommand());
     builder.put("truncate", new TruncateTableCommand());
     builder.put("cluster", new ClusterCommand());
+    builder.put("safemodewait", new WaitInSafemodeCommand());
     commands = builder.build();
 
     CliShellOptions cliShellOptions = getCliShellOptions(args);
@@ -350,9 +359,13 @@ public class Main {
               continue;
             }
             String[] commandArgs = line.split("\\s");
-            Command command = commands.get(commandArgs[0]);
+            String commandStr = commandArgs[0];
+            if (commandStr.equals("exit")) {
+              commandStr = "quit";
+            }
+            Command command = commands.get(commandStr);
             if (command == null) {
-              out.println("unknown command \"" + commandArgs[0] + "\"");
+              out.println("unknown command \"" + commandStr + "\"");
             } else {
               long start = System.nanoTime();
               try {
@@ -400,6 +413,17 @@ public class Main {
     }
   }
 
+  private static String[] removeLeadingShellFromScript(String[] args) {
+    if (args.length > 0) {
+      if (args[0].equals("shell")) {
+        String[] newArgs = new String[args.length - 1];
+        System.arraycopy(args, 1, newArgs, 0, newArgs.length);
+        return newArgs;
+      }
+    }
+    return args;
+  }
+
   private static CliShellOptions getCliShellOptions(String[] args) throws IOException {
     CliShellOptions cliShellOptions = new CliShellOptions();
     if (args.length == 0) {
@@ -446,6 +470,13 @@ public class Main {
           return cliShellOptions;
         }
       } else {
+        String controllerConnectionString = loadControllerConnectionString();
+        if (controllerConnectionString == null) {
+          System.err
+              .println("Could not locate controller connection string in the blu-site.properties
file and it was not passed in via command line args.");
+          return null;
+        }
+        cliShellOptions.setControllerConnectionString(controllerConnectionString);
         // command was found at arg0
         cliShellOptions.setShell(false);
         cliShellOptions.setArgs(args);

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c9c875c0/blur-shell/src/main/java/org/apache/blur/shell/WaitInSafemodeCommand.java
----------------------------------------------------------------------
diff --git a/blur-shell/src/main/java/org/apache/blur/shell/WaitInSafemodeCommand.java b/blur-shell/src/main/java/org/apache/blur/shell/WaitInSafemodeCommand.java
new file mode 100644
index 0000000..8d3fcac
--- /dev/null
+++ b/blur-shell/src/main/java/org/apache/blur/shell/WaitInSafemodeCommand.java
@@ -0,0 +1,64 @@
+package org.apache.blur.shell;
+
+/**
+ * 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.
+ */
+import java.io.PrintWriter;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.blur.thirdparty.thrift_0_9_0.TException;
+import org.apache.blur.thrift.generated.Blur;
+import org.apache.blur.thrift.generated.BlurException;
+
+public class WaitInSafemodeCommand extends Command {
+
+  @Override
+  public void doit(PrintWriter out, Blur.Iface client, String[] args) throws CommandException,
TException,
+      BlurException {
+    String cluster;
+    if (args.length != 2) {
+      cluster = Main.getCluster(client, "Invalid args: " + help());
+    } else {
+      cluster = args[1];
+    }
+    boolean inSafeMode;
+    boolean isNoLonger = false;
+    do {
+      inSafeMode = client.isInSafeMode(cluster);
+      if (!inSafeMode) {
+        if (isNoLonger) {
+          out.println("Cluster " + cluster + " is no longer in safemode.");
+        } else {
+          out.println("Cluster " + cluster + " is not in safemode.");
+        }
+        return;
+      }
+      isNoLonger = true;
+      try {
+        Thread.sleep(TimeUnit.SECONDS.toMillis(1));
+      } catch (InterruptedException e) {
+        throw new RuntimeException(e);
+      }
+    } while (inSafeMode);
+  }
+
+  @Override
+  public String help() {
+    return "wait for safe mode to exit, args; clustername";
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c9c875c0/blur-util/src/main/java/org/apache/blur/zookeeper/ZooKeeperLockManager.java
----------------------------------------------------------------------
diff --git a/blur-util/src/main/java/org/apache/blur/zookeeper/ZooKeeperLockManager.java b/blur-util/src/main/java/org/apache/blur/zookeeper/ZooKeeperLockManager.java
index 81cfde9..55ca281 100644
--- a/blur-util/src/main/java/org/apache/blur/zookeeper/ZooKeeperLockManager.java
+++ b/blur-util/src/main/java/org/apache/blur/zookeeper/ZooKeeperLockManager.java
@@ -32,7 +32,7 @@ import org.apache.zookeeper.ZooDefs.Ids;
 import org.apache.zookeeper.ZooKeeper;
 
 public class ZooKeeperLockManager {
-  
+
   private static final Log LOG = LogFactory.getLog(ZooKeeperLockManager.class);
 
   protected final Map<String, String> lockMap = new HashMap<String, String>();
@@ -53,6 +53,17 @@ public class ZooKeeperLockManager {
     this.lockPath = lockPath;
   }
 
+  public int getNumberOfLockNodesPresent(String name) throws KeeperException, InterruptedException
{
+    List<String> children = zooKeeper.getChildren(lockPath, false);
+    int count = 0;
+    for (String s : children) {
+      if (s.startsWith(name + "_")) {
+        count++;
+      }
+    }
+    return count;
+  }
+
   public void unlock(String name) throws InterruptedException, KeeperException {
     if (!lockMap.containsKey(name)) {
       throw new RuntimeException("Lock [" + name + "] has not be created.");

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c9c875c0/distribution/src/main/scripts/bin/blur
----------------------------------------------------------------------
diff --git a/distribution/src/main/scripts/bin/blur b/distribution/src/main/scripts/bin/blur
index ec4be88..efbe9a3 100755
--- a/distribution/src/main/scripts/bin/blur
+++ b/distribution/src/main/scripts/bin/blur
@@ -20,10 +20,12 @@ bin=`cd "$bin"; pwd`
 
 . "$bin"/blur-config.sh
 PROC_NAME=$1
-if [ $1 = "shell" ]; then
-  "$JAVA_HOME"/bin/java -Dblur.name=$PROC_NAME -Djava.library.path=$JAVA_LIBRARY_PATH $BLUR_COMMAND
-Dblur.logs.dir=$BLUR_LOGS -Dblur.log.file=$PROC_NAME.log -cp $BLUR_CLASSPATH org.apache.blur.shell.Main
$2
+if [ $# -eq 0 ]; then
+  "$JAVA_HOME"/bin/java -Dblur.name=$PROC_NAME -Djava.library.path=$JAVA_LIBRARY_PATH $BLUR_COMMAND
-Dblur.logs.dir=$BLUR_LOGS -Dblur.log.file=$PROC_NAME.log -cp $BLUR_CLASSPATH org.apache.blur.shell.Main
shell help
+elif [ $1 = "shell" ]; then
+  "$JAVA_HOME"/bin/java -Dblur.name=$PROC_NAME -Djava.library.path=$JAVA_LIBRARY_PATH $BLUR_COMMAND
-Dblur.logs.dir=$BLUR_LOGS -Dblur.log.file=$PROC_NAME.log -cp $BLUR_CLASSPATH org.apache.blur.shell.Main
${@:2}
+elif [ $1 = "execute" ]; then
+  "$JAVA_HOME"/bin/java -Dblur.name=$PROC_NAME -Djava.library.path=$JAVA_LIBRARY_PATH $BLUR_COMMAND
-Dblur.logs.dir=$BLUR_LOGS -Dblur.log.file=$PROC_NAME.log -cp $BLUR_CLASSPATH ${@:2}
 else
-  "$JAVA_HOME"/bin/java -Dblur.name=$PROC_NAME -Djava.library.path=$JAVA_LIBRARY_PATH $BLUR_COMMAND
-Dblur.logs.dir=$BLUR_LOGS -Dblur.log.file=$PROC_NAME.log -cp $BLUR_CLASSPATH $@
+  "$JAVA_HOME"/bin/java -Dblur.name=$PROC_NAME -Djava.library.path=$JAVA_LIBRARY_PATH $BLUR_COMMAND
-Dblur.logs.dir=$BLUR_LOGS -Dblur.log.file=$PROC_NAME.log -cp $BLUR_CLASSPATH org.apache.blur.shell.Main
shell ${@:1}
 fi
-
-


Mime
View raw message