You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ea...@apache.org on 2019/05/16 12:00:18 UTC

[incubator-iotdb] branch cluster updated: implement Status of NodeTool

This is an automated email from the ASF dual-hosted git repository.

east pushed a commit to branch cluster
in repository https://gitbox.apache.org/repos/asf/incubator-iotdb.git


The following commit(s) were added to refs/heads/cluster by this push:
     new 2a02dbe  implement Status of NodeTool
2a02dbe is described below

commit 2a02dbe02a2f82dac927beeba470afe34f41b08c
Author: mdf369 <95...@qq.com>
AuthorDate: Thu May 16 19:59:55 2019 +0800

    implement Status of NodeTool
---
 .../org/apache/iotdb/cluster/entity/Server.java    |  2 +
 .../querymetric/QueryStatusAsyncProcessor.java     | 44 +++++++++++++++++++++
 .../request/querymetric/QueryStatusRequest.java    | 31 +++++++++++++++
 .../response/querymetric/QueryStatusResponse.java  | 46 ++++++++++++++++++++++
 .../iotdb/cluster/service/ClusterMonitor.java      |  5 +++
 .../iotdb/cluster/service/ClusterMonitorMBean.java |  7 ++++
 .../iotdb/cluster/service/nodetool/NodeTool.java   |  3 +-
 .../iotdb/cluster/service/nodetool/Status.java     | 35 ++++++++++++++++
 .../org/apache/iotdb/cluster/utils/RaftUtils.java  | 43 +++++++++++++++++++-
 .../UserGuideV0.7.0/7-Tools-NodeTool.md            | 36 ++++++++++++++++-
 10 files changed, 249 insertions(+), 3 deletions(-)

diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/entity/Server.java b/cluster/src/main/java/org/apache/iotdb/cluster/entity/Server.java
index 5a1fa3b..1567bcd 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/entity/Server.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/entity/Server.java
@@ -45,6 +45,7 @@ import org.apache.iotdb.cluster.rpc.raft.processor.querymetadata.QueryMetadataIn
 import org.apache.iotdb.cluster.rpc.raft.processor.querymetadata.QueryPathsAsyncProcessor;
 import org.apache.iotdb.cluster.rpc.raft.processor.querymetadata.QuerySeriesTypeAsyncProcessor;
 import org.apache.iotdb.cluster.rpc.raft.processor.querymetadata.QueryTimeSeriesAsyncProcessor;
+import org.apache.iotdb.cluster.rpc.raft.processor.querymetric.QueryStatusAsyncProcessor;
 import org.apache.iotdb.cluster.utils.RaftUtils;
 import org.apache.iotdb.cluster.utils.hash.PhysicalNode;
 import org.apache.iotdb.cluster.utils.hash.Router;
@@ -165,6 +166,7 @@ public class Server {
   private void registerQueryMetricProcessor(RpcServer rpcServer) {
     rpcServer.registerUserProcessor(new QueryMetricAsyncProcessor());
     rpcServer.registerUserProcessor(new QueryJobNumAsyncProcessor());
+    rpcServer.registerUserProcessor(new QueryStatusAsyncProcessor());
   }
 
   public void stop() throws ProcessorException, InterruptedException {
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querymetric/QueryStatusAsyncProcessor.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querymetric/QueryStatusAsyncProcessor.java
new file mode 100644
index 0000000..615eaf6
--- /dev/null
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/processor/querymetric/QueryStatusAsyncProcessor.java
@@ -0,0 +1,44 @@
+/**
+ * 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.iotdb.cluster.rpc.raft.processor.querymetric;
+
+import com.alipay.remoting.AsyncContext;
+import com.alipay.remoting.BizContext;
+import org.apache.iotdb.cluster.rpc.raft.processor.BasicAsyncUserProcessor;
+import org.apache.iotdb.cluster.rpc.raft.request.querymetric.QueryStatusRequest;
+import org.apache.iotdb.cluster.rpc.raft.response.querymetric.QueryStatusResponse;
+
+public class QueryStatusAsyncProcessor extends BasicAsyncUserProcessor<QueryStatusRequest> {
+
+  @Override
+  public void handleRequest(BizContext bizContext, AsyncContext asyncContext,
+      QueryStatusRequest request) {
+    String groupId = request.getGroupID();
+
+    QueryStatusResponse response = QueryStatusResponse.createSuccessResponse(groupId,
+        true);
+    response.addResult(true);
+    asyncContext.sendResponse(response);
+  }
+
+  @Override
+  public String interest() {
+    return QueryStatusRequest.class.getName();
+  }
+}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querymetric/QueryStatusRequest.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querymetric/QueryStatusRequest.java
new file mode 100644
index 0000000..b88b08e
--- /dev/null
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/request/querymetric/QueryStatusRequest.java
@@ -0,0 +1,31 @@
+/**
+ * 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.iotdb.cluster.rpc.raft.request.querymetric;
+
+import java.io.Serializable;
+import org.apache.iotdb.cluster.rpc.raft.request.BasicRequest;
+
+public class QueryStatusRequest extends BasicRequest implements Serializable {
+
+  private static final long serialVersionUID = 8434915883943829829L;
+
+  public QueryStatusRequest(String groupID) {
+    super(groupID);
+  }
+}
\ No newline at end of file
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/response/querymetric/QueryStatusResponse.java b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/response/querymetric/QueryStatusResponse.java
new file mode 100644
index 0000000..2044f5e
--- /dev/null
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/rpc/raft/response/querymetric/QueryStatusResponse.java
@@ -0,0 +1,46 @@
+/**
+ * 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.iotdb.cluster.rpc.raft.response.querymetric;
+
+import org.apache.iotdb.cluster.rpc.raft.response.BasicResponse;
+
+public class QueryStatusResponse extends BasicResponse {
+
+  private boolean status;
+
+  private QueryStatusResponse(String groupId, boolean redirected, String leaderStr,
+      String errorMsg) {
+    super(groupId, redirected, leaderStr, errorMsg);
+  }
+
+  public static QueryStatusResponse createSuccessResponse(String groupId, boolean status) {
+    QueryStatusResponse response = new QueryStatusResponse(groupId, false, null,
+        null);
+    response.status = status;
+    return response;
+  }
+
+  public static QueryStatusResponse createErrorResponse(String groupId, String errorMsg) {
+    return new QueryStatusResponse(groupId, false, null, errorMsg);
+  }
+
+  public boolean getStatus() {
+    return status;
+  }
+}
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitor.java b/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitor.java
index 916ea1d..c997971 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitor.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitor.java
@@ -110,4 +110,9 @@ public class ClusterMonitor implements ClusterMonitorMBean, IService {
   public Map<String, Map<String, Integer>> getQueryJobNumMap() {
     return RaftUtils.getQueryJobNumMapForCluster();
   }
+
+  @Override
+  public Map<String, Boolean> getStatusMap() {
+    return RaftUtils.getStatusMapForCluster();
+  }
 }
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitorMBean.java b/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitorMBean.java
index 02b0207..7144e1c 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitorMBean.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/service/ClusterMonitorMBean.java
@@ -76,4 +76,11 @@ public interface ClusterMonitorMBean {
    * @return outer key: ip, inner key: groupId, value: number of query jobs
    */
   Map<String, Map<String, Integer>> getQueryJobNumMap();
+
+  /**
+   * Get status of all nodes
+   *
+   * @return key: node ip, value: live or not
+   */
+  Map<String, Boolean> getStatusMap();
 }
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/NodeTool.java b/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/NodeTool.java
index 64bb52b..9d464b3 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/NodeTool.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/NodeTool.java
@@ -54,7 +54,8 @@ public class NodeTool {
         StorageGroup.class,
         Host.class,
         Lag.class,
-        Query.class
+        Query.class,
+        Status.class
     );
 
     Cli.CliBuilder<Runnable> builder = Cli.builder("nodetool");
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Status.java b/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Status.java
new file mode 100644
index 0000000..302a1c7
--- /dev/null
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/service/nodetool/Status.java
@@ -0,0 +1,35 @@
+/**
+ * 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.iotdb.cluster.service.nodetool;
+
+import io.airlift.airline.Command;
+import java.util.Map;
+import org.apache.iotdb.cluster.service.nodetool.NodeTool.NodeToolCmd;
+import org.apache.iotdb.cluster.service.ClusterMonitorMBean;
+
+@Command(name = "status", description = "Print status of all hosts")
+public class Status extends NodeToolCmd {
+
+  @Override
+  public void execute(ClusterMonitorMBean proxy)
+  {
+    Map<String, Boolean> statusMap = proxy.getStatusMap();
+    statusMap.forEach((ip, status) -> System.out.println(ip + "\t->\t" + (status ? "on" : "off")));
+  }
+}
\ No newline at end of file
diff --git a/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java b/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
index fe9fb8f..f1cb1fa 100644
--- a/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
+++ b/cluster/src/main/java/org/apache/iotdb/cluster/utils/RaftUtils.java
@@ -62,11 +62,13 @@ import org.apache.iotdb.cluster.rpc.raft.request.BasicNonQueryRequest;
 import org.apache.iotdb.cluster.rpc.raft.request.BasicRequest;
 import org.apache.iotdb.cluster.rpc.raft.request.querymetric.QueryJobNumRequest;
 import org.apache.iotdb.cluster.rpc.raft.request.querymetric.QueryMetricRequest;
+import org.apache.iotdb.cluster.rpc.raft.request.querymetric.QueryStatusRequest;
 import org.apache.iotdb.cluster.rpc.raft.response.BasicResponse;
 import org.apache.iotdb.cluster.rpc.raft.response.querymetric.QueryJobNumResponse;
 import org.apache.iotdb.cluster.rpc.raft.response.querymetric.QueryMetricResponse;
 import org.apache.iotdb.cluster.rpc.raft.response.nonquery.DataGroupNonQueryResponse;
 import org.apache.iotdb.cluster.rpc.raft.response.nonquery.MetaGroupNonQueryResponse;
+import org.apache.iotdb.cluster.rpc.raft.response.querymetric.QueryStatusResponse;
 import org.apache.iotdb.cluster.utils.hash.PhysicalNode;
 import org.apache.iotdb.cluster.utils.hash.Router;
 import org.apache.iotdb.cluster.utils.hash.VirtualNode;
@@ -591,7 +593,7 @@ public class RaftUtils {
   /**
    * Get query job number running on each data partition for all nodes
    *
-   * @return key: data partition ID, value: query job number
+   * @return outer key: ip, inner key: groupId, value: number of query jobs
    */
   public static Map<String, Map<String, Integer>> getQueryJobNumMapForCluster() {
     PeerId[] peerIds = RaftUtils.convertStringArrayToPeerIdArray(config.getNodes());
@@ -632,6 +634,45 @@ public class RaftUtils {
   }
 
   /**
+   * Get status of each node in cluster
+   *
+   * @return key: node ip, value: live or not
+   */
+  public static Map<String, Boolean> getStatusMapForCluster() {
+    PeerId[] peerIds = RaftUtils.convertStringArrayToPeerIdArray(config.getNodes());
+    Map<String, Boolean> res = new HashMap<>();
+    for (int i = 0; i < peerIds.length; i++) {
+      PeerId peerId = peerIds[i];
+      res.put(peerId.getIp(), getStatusOfNode(peerId));
+    }
+
+    return res;
+  }
+
+  private static boolean getStatusOfNode(PeerId peerId) {
+    QueryStatusRequest request = new QueryStatusRequest("");
+    SingleQPTask task = new SingleQPTask(false, request);
+
+    LOGGER.debug("Execute get status for node {}.", peerId);
+    try {
+      NodeAsClient client = RaftNodeAsClientManager.getInstance().getRaftNodeAsClient();
+      /** Call async method **/
+      client.asyncHandleRequest(task.getRequest(), peerId, task);
+
+      task.await();
+      boolean status = false;
+      if (task.getTaskState() == TaskState.FINISH) {
+        BasicResponse response = task.getResponse();
+        status = response == null ? null : ((QueryStatusResponse) response).getStatus();
+      }
+      return status;
+    } catch (RaftConnectionException | InterruptedException e) {
+      LOGGER.error("Fail to get status from remote node {} because of {}.", peerId, e);
+      return false;
+    }
+  }
+
+  /**
    * try to get raft rpc client
    */
   public static NodeAsClient getRaftNodeAsClient() throws RaftConnectionException {
diff --git a/docs/Documentation/UserGuideV0.7.0/7-Tools-NodeTool.md b/docs/Documentation/UserGuideV0.7.0/7-Tools-NodeTool.md
index 938c68d..a442bf5 100644
--- a/docs/Documentation/UserGuideV0.7.0/7-Tools-NodeTool.md
+++ b/docs/Documentation/UserGuideV0.7.0/7-Tools-NodeTool.md
@@ -295,6 +295,40 @@ After using the command, the successful output will be as follows:
   data-group-0  ->   0
   data-group-2  ->   1
 Total  ->   7
+```
+The above output indicates that 7 query tasks are running on cluster. Moreover, node 192.168.130.14 contains 2 data partitions and 4 query tasks are running on it, wherein 1 query task is running on data partition data-group-0, and 3 query tasks are running on data partition data-group-1; node 192.168.130.16 contains 2 data partitions and 2 query tasks are running on it, wherein 2 query tasks is running on data partition data-group-2, and no query task is running on data partition data-g [...]
+
+### Query Status of Nodes in Cluster (status)
+
+IoTDB Cluster contains multiple nodes. For any node, there is a possibility that the service cannot be provided normally due to problems of network and hardware. With this command, users are able to know the current status of all nodes in the cluster.
+
+#### Input
+
+The command to query status of nodes is `status`, no additional parameters are needed.
+
+#### Output
+
+The output is multiple string lines, each line represents a key-value pair, where the key is node IP and the value is status of this node (`on` represents normal and `off` represents abnormal. The format of each line is `key -> value`.
+
+#### Example
+
+Assume that the IoTDB Cluster is running on 3 nodes: 192.168.130.14, 192.168.130.16 and 192.168.130.18, and number of replicas is 2.
 
+The Linux and MacOS system startup commands are as follows:
+```
+  Shell > ./bin/nodetool.sh -h 192.168.130.14 status
+```
+  
+The Windows system startup commands are as follows:
+```
+  Shell > \bin\nodetool.bat -h 192.168.130.14 status
+```
+  
+After using the command, the successful output will be as follows: 
+	
+```
+192.168.130.14  ->  on
+192.168.130.16  ->  on
+192.168.130.18  ->  off
 ```
-The above output indicates that 7 query tasks are running on cluster. Moreover, node 192.168.130.14 contains 2 data partitions and 4 query tasks are running on it, wherein 1 query task is running on data partition data-group-0, and 3 query tasks are running on data partition data-group-1; node 192.168.130.16 contains 2 data partitions and 2 query tasks are running on it, wherein 2 query tasks is running on data partition data-group-2, and no query task is running on data partition data-g [...]
\ No newline at end of file
+The above output indicates that node 192.168.130.14 and node 192.168.130.16 are in normal state, and node 192.168.130.18 cannot provide services.