You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2021/02/08 02:57:18 UTC

[GitHub] [iotdb] jt2594838 commented on a change in pull request #2619: [IOTDB-1144]support the show devices plan in distributed version

jt2594838 commented on a change in pull request #2619:
URL: https://github.com/apache/iotdb/pull/2619#discussion_r571751733



##########
File path: cluster/src/main/java/org/apache/iotdb/cluster/client/sync/SyncClientAdaptor.java
##########
@@ -349,6 +351,26 @@ public static Integer getPathCount(AsyncDataClient client, Node header, List<Str
     return handler.getResult(RaftServer.getReadOperationTimeoutMS());
   }
 
+  public static Set<String> getDevices(AsyncDataClient client, Node header, ShowDevicesPlan plan)
+      throws InterruptedException, TException, IOException {
+    GetDevicesHandler handler = new GetDevicesHandler();
+    AtomicReference<Set<String>> response = new AtomicReference<>(null);
+    handler.setResponse(response);
+    handler.setContact(client.getNode());
+    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+    DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
+    plan.serialize(dataOutputStream);
+
+    client.getDevices(header, ByteBuffer.wrap(byteArrayOutputStream.toByteArray()),
+        handler);
+    synchronized (response) {

Review comment:
       I think `GetDevicesHandler` has the answer.

##########
File path: cluster/src/main/java/org/apache/iotdb/cluster/metadata/CMManager.java
##########
@@ -1298,6 +1299,49 @@ protected MeasurementMNode getMeasurementMNode(MNode deviceMNode, String measure
     return super.showTimeseries(plan, context);
   }
 
+  public Set<PartialPath> getLocalDevices(ShowDevicesPlan plan) throws MetadataException {
+    return super.getDevices(plan);
+  }
+
+  @Override
+  public Set<PartialPath> getDevices(ShowDevicesPlan plan) throws MetadataException {
+    ConcurrentSkipListSet<PartialPath> resultSet = new ConcurrentSkipListSet<>();
+    ExecutorService pool = new ThreadPoolExecutor(THREAD_POOL_SIZE, THREAD_POOL_SIZE, 0,
+        TimeUnit.SECONDS, new LinkedBlockingDeque<>());
+    List<PartitionGroup> globalGroups = metaGroupMember.getPartitionTable().getGlobalGroups();
+
+    int limit = plan.getLimit() == 0 ? Integer.MAX_VALUE : plan.getLimit();
+    int offset = plan.getOffset();
+    // do not use limit and offset in sub-queries unless offset is 0, otherwise the results are
+    // not combinable

Review comment:
       It should be checked in plan generation, instead of execution.

##########
File path: cluster/src/main/java/org/apache/iotdb/cluster/server/handlers/caller/GetDevicesHandler.java
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.server.handlers.caller;
+
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.iotdb.cluster.rpc.thrift.Node;
+import org.apache.thrift.async.AsyncMethodCallback;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@SuppressWarnings("common-java:DuplicatedBlocks")
+public class GetDevicesHandler implements AsyncMethodCallback<Set<String>> {
+
+  private static final Logger logger = LoggerFactory.getLogger(GetDevicesHandler.class);
+
+  private Node contact;
+  private AtomicReference<Set<String>> result;
+
+  @Override
+  public void onComplete(Set<String> resp) {
+    logger.info("Received devices schema from {}", contact);

Review comment:
       Maybe `info` is too high for this




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org