Updated Branches: refs/heads/master 54e95fd07 -> 2bf8cb446
Adding a shutdown switch that pervents the layouts of tables to change once a shutdown begins. Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/2bf8cb44 Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/2bf8cb44 Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/2bf8cb44 Branch: refs/heads/master Commit: 2bf8cb4463546f22886bfc1d18858030c920236f Parents: b5180c6 Author: Aaron McCurry <[email protected]> Authored: Wed Dec 11 13:43:12 2013 -0500 Committer: Aaron McCurry <[email protected]> Committed: Wed Dec 11 13:45:56 2013 -0500 ---------------------------------------------------------------------- .../clusterstatus/ZookeeperPathConstants.java | 4 ++ .../indexserver/DistributedIndexServer.java | 26 +++++++- .../java/org/apache/blur/thrift/Shutdown.java | 67 ++++++++++++++++++++ .../src/main/scripts/bin/stop-shards.sh | 5 +- 4 files changed, 99 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2bf8cb44/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperPathConstants.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperPathConstants.java b/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperPathConstants.java index 5278aca..6c15f17 100644 --- a/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperPathConstants.java +++ b/blur-core/src/main/java/org/apache/blur/manager/clusterstatus/ZookeeperPathConstants.java @@ -66,6 +66,10 @@ public class ZookeeperPathConstants { public static String getSafemodePath(String cluster) { return getClusterPath(cluster) + "/safemode"; } + + public static String getShutdownPath(String cluster) { + return getClusterPath(cluster) + "/shutdown"; + } public static String getRegisteredShardsPath(String cluster) { return getClusterPath(cluster) + "/registered-nodes"; http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2bf8cb44/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java b/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java index 09019ad..f4a69ac 100644 --- a/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java +++ b/blur-core/src/main/java/org/apache/blur/manager/indexserver/DistributedIndexServer.java @@ -69,6 +69,7 @@ import org.apache.zookeeper.CreateMode; import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.ZooDefs.Ids; import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; import com.google.common.io.Closer; @@ -77,6 +78,7 @@ public class DistributedIndexServer extends AbstractDistributedIndexServer { private static final Log LOG = LogFactory.getLog(DistributedIndexServer.class); private static final long _delay = TimeUnit.SECONDS.toMillis(10); private static final AtomicLong _pauseWarmup = new AtomicLong(); + private static final Set<String> EMPTY = new HashSet<String>(); static class LayoutEntry { @@ -250,7 +252,7 @@ public class DistributedIndexServer extends AbstractDistributedIndexServer { } private WatchChildren watchForShardServerChanges() { - + WatchChildren watchOnlineShards = new WatchChildren(_zookeeper, ZookeeperPathConstants.getOnlineShardsPath(_cluster)).watch(new OnChange() { private List<String> _prevOnlineShards = new ArrayList<String>(); @@ -570,7 +572,7 @@ public class DistributedIndexServer extends AbstractDistributedIndexServer { private Set<String> getShardsToServe(String table) { if (!isEnabled(table)) { - return new HashSet<String>(); + return EMPTY; } LayoutEntry layoutEntry = _layout.get(table); if (layoutEntry == null) { @@ -589,6 +591,12 @@ public class DistributedIndexServer extends AbstractDistributedIndexServer { List<String> offlineShardServers = new ArrayList<String>(_clusterStatus.getOfflineShardServers(false, cluster)); List<String> shardList = getShardList(table); + String shutdownPath = ZookeeperPathConstants.getShutdownPath(cluster); + if (isShuttingDown(shutdownPath)) { + LOG.info("Cluster shutting down, return empty layout."); + return EMPTY; + } + DistributedLayout layoutManager = _distributedLayoutFactory.createDistributedLayout(table, shardList, shardServerList, offlineShardServers, false); @@ -603,4 +611,18 @@ public class DistributedIndexServer extends AbstractDistributedIndexServer { _layout.put(table, new LayoutEntry(layoutManager, shardsToServeCache)); return shardsToServeCache; } + + private boolean isShuttingDown(String shutdownPath) { + try { + Stat stat = _zookeeper.exists(shutdownPath, false); + if (stat == null) { + return false; + } + return true; + } catch (KeeperException e) { + throw new RuntimeException(e); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } } http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2bf8cb44/blur-core/src/main/java/org/apache/blur/thrift/Shutdown.java ---------------------------------------------------------------------- diff --git a/blur-core/src/main/java/org/apache/blur/thrift/Shutdown.java b/blur-core/src/main/java/org/apache/blur/thrift/Shutdown.java new file mode 100644 index 0000000..5f082e0 --- /dev/null +++ b/blur-core/src/main/java/org/apache/blur/thrift/Shutdown.java @@ -0,0 +1,67 @@ +/** + * 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. + */ +package org.apache.blur.thrift; + +import static org.apache.blur.utils.BlurConstants.BLUR_CLUSTER; +import static org.apache.blur.utils.BlurConstants.BLUR_CLUSTER_NAME; +import static org.apache.blur.utils.BlurConstants.BLUR_ZOOKEEPER_CONNECTION; +import static org.apache.blur.utils.BlurConstants.BLUR_ZOOKEEPER_TIMEOUT; +import static org.apache.blur.utils.BlurConstants.BLUR_ZOOKEEPER_TIMEOUT_DEFAULT; + +import java.io.IOException; + +import org.apache.blur.BlurConfiguration; +import org.apache.blur.manager.clusterstatus.ZookeeperPathConstants; +import org.apache.blur.zookeeper.ZkUtils; +import org.apache.zookeeper.CreateMode; +import org.apache.zookeeper.KeeperException; +import org.apache.zookeeper.ZooDefs.Ids; +import org.apache.zookeeper.ZooKeeper; + +public class Shutdown { + + public static void main(String[] args) throws IOException, KeeperException, InterruptedException { + BlurConfiguration configuration = new BlurConfiguration(); + String zkConnectionStr = ThriftServer.isEmpty(configuration.get(BLUR_ZOOKEEPER_CONNECTION), + BLUR_ZOOKEEPER_CONNECTION); + int sessionTimeout = configuration.getInt(BLUR_ZOOKEEPER_TIMEOUT, BLUR_ZOOKEEPER_TIMEOUT_DEFAULT); + final ZooKeeper zooKeeper = ZkUtils.newZooKeeper(zkConnectionStr, sessionTimeout); + String cluster = configuration.get(BLUR_CLUSTER_NAME, BLUR_CLUSTER); + String shutdownPath = ZookeeperPathConstants.getShutdownPath(cluster); + zooKeeper.create(shutdownPath, null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL); + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + @Override + public void run() { + try { + zooKeeper.close(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + })); + + while (true) { + System.out.println("Waiting for shutdown."); + try { + Thread.sleep(60000); + } catch (InterruptedException e) { + return; + } + } + } + +} http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/2bf8cb44/distribution/src/main/scripts/bin/stop-shards.sh ---------------------------------------------------------------------- diff --git a/distribution/src/main/scripts/bin/stop-shards.sh b/distribution/src/main/scripts/bin/stop-shards.sh index 5e1342d..8f16076 100755 --- a/distribution/src/main/scripts/bin/stop-shards.sh +++ b/distribution/src/main/scripts/bin/stop-shards.sh @@ -19,6 +19,9 @@ bin=`dirname "$0"` bin=`cd "$bin"; pwd` . "$bin"/blur-config.sh - +PROC_NAME="Shutdown" +nohup "$JAVA_HOME"/bin/java -Dblur.name=SHUTDOWN_PROC -Djava.library.path=$JAVA_LIBRARY_PATH -Dblur.logs.dir=$BLUR_LOGS -Dblur.log.file=blur-$USER-$PROC_NAME -cp $BLUR_CLASSPATH org.apache.blur.thrift.Shutdown > "$BLUR_LOGS/blur-$USER-$PROC_NAME.out" 2>&1 < /dev/null & +SHUTDOWN_PID=$! $BLUR_HOME/bin/shards.sh $BLUR_HOME/bin/stop-shard-server.sh +kill -15 $SHUTDOWN_PID
