JackieTien97 commented on code in PR #16441:
URL: https://github.com/apache/iotdb/pull/16441#discussion_r2422603868


##########
iotdb-client/session/src/main/java/org/apache/iotdb/session/NodesSupplier.java:
##########
@@ -228,28 +229,37 @@ public Optional<TEndPoint> getQueryEndPoint() {
 
   private boolean updateDataNodeList() {
     try (SessionDataSet sessionDataSet =
-        client.executeQueryStatement(SHOW_DATA_NODES_COMMAND, TIMEOUT_IN_MS, 
FETCH_SIZE)) {
-      SessionDataSet.DataIterator iterator = sessionDataSet.iterator();
-      List<TEndPoint> res = new ArrayList<>();
-      while (iterator.next()) {
-        String ip = iterator.getString(IP_COLUMN_NAME);
-        // ignore 0.0.0.0 and removing DN
-        if (!REMOVING_STATUS.equals(iterator.getString(STATUS_COLUMN_NAME))
-            && !"0.0.0.0".equals(ip)) {
-          String port = iterator.getString(PORT_COLUMN_NAME);
-          if (ip != null && port != null) {
-            res.add(new TEndPoint(ip, Integer.parseInt(port)));
-          }
-        }
+        client.executeQueryStatement(SHOW_AVAILABLE_URLS_COMMAND, 
TIMEOUT_IN_MS, FETCH_SIZE)) {
+      updateAvailableNodes(sessionDataSet);
+    } catch (Exception e1) {
+      try (SessionDataSet sessionDataSet =
+          client.executeQueryStatement(SHOW_DATA_NODES_COMMAND, TIMEOUT_IN_MS, 
FETCH_SIZE)) {
+        updateAvailableNodes(sessionDataSet);
+      } catch (Exception e2) {
+        LOGGER.warn("Failed to fetch data node list from {}.", 
client.endPoint);
+        return false;
       }
-      // replace the older ones.
-      if (!res.isEmpty()) {
-        availableNodes = res;
+    }
+    return true;
+  }
+
+  private void updateAvailableNodes(SessionDataSet sessionDataSet) throws 
Exception {
+    SessionDataSet.DataIterator iterator = sessionDataSet.iterator();
+    List<TEndPoint> res = new ArrayList<>();
+    while (iterator.next()) {
+      String ip = iterator.getString(IP_COLUMN_NAME);
+      // ignore 0.0.0.0 and removing DN
+      if (!REMOVING_STATUS.equals(iterator.getString(STATUS_COLUMN_NAME))

Review Comment:
   filter removing DN in server implement



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/security/TreeAccessCheckVisitor.java:
##########
@@ -1171,6 +1172,12 @@ public TSStatus visitShowCluster(ShowClusterStatement 
statement, TreeAccessCheck
     return checkGlobalAuth(context.userName, PrivilegeType.MAINTAIN);
   }
 
+  @Override
+  public TSStatus visitShowAvailableUrls(
+      ShowAvailableUrlsStatement showAvailableUrlsStatement, 
TreeAccessCheckContext context) {
+    return SUCCEED;

Review Comment:
   better to add recordObjectAuthenticationAuditLog for these operation even if 
they require no privilege. Auth in audit log for such operations can be null.



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/schema/column/ColumnHeaderConstant.java:
##########
@@ -461,6 +461,13 @@ private ColumnHeaderConstant() {
           new ColumnHeader(DATA_REGION_NUM, TSDataType.INT32),
           new ColumnHeader(SCHEMA_REGION_NUM, TSDataType.INT32));
 
+  public static final List<ColumnHeader> showAvailableUrlsColumnHeaders =
+      ImmutableList.of(
+          new ColumnHeader(NODE_ID, TSDataType.INT32),
+          new ColumnHeader(STATUS, TSDataType.TEXT),

Review Comment:
   no need to expose these two columns to users, they only need to know ip and 
port is enough.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/metadata/ShowAvailableUrlsTask.java:
##########
@@ -0,0 +1,75 @@
+/*
+ * 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.db.queryengine.plan.execution.config.metadata;
+
+import org.apache.iotdb.commons.schema.column.ColumnHeader;
+import org.apache.iotdb.commons.schema.column.ColumnHeaderConstant;
+import org.apache.iotdb.confignode.rpc.thrift.TDataNodeInfo;
+import org.apache.iotdb.confignode.rpc.thrift.TShowDataNodesResp;
+import org.apache.iotdb.db.queryengine.common.header.DatasetHeader;
+import org.apache.iotdb.db.queryengine.common.header.DatasetHeaderFactory;
+import org.apache.iotdb.db.queryengine.plan.execution.config.ConfigTaskResult;
+import org.apache.iotdb.db.queryengine.plan.execution.config.IConfigTask;
+import 
org.apache.iotdb.db.queryengine.plan.execution.config.executor.IConfigTaskExecutor;
+import org.apache.iotdb.rpc.TSStatusCode;
+
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.SettableFuture;
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.block.TsBlockBuilder;
+import org.apache.tsfile.utils.BytesUtils;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class ShowAvailableUrlsTask implements IConfigTask {
+
+  @Override
+  public ListenableFuture<ConfigTaskResult> execute(IConfigTaskExecutor 
configTaskExecutor)
+      throws InterruptedException {
+    return configTaskExecutor.showAvailableUrls();
+  }
+
+  public static void buildTsBlock(
+      TShowDataNodesResp showDataNodesResp, SettableFuture<ConfigTaskResult> 
future) {
+    List<TSDataType> outputDataTypes =
+        ColumnHeaderConstant.showAvailableUrlsColumnHeaders.stream()
+            .map(ColumnHeader::getColumnType)
+            .collect(Collectors.toList());
+    TsBlockBuilder builder = new TsBlockBuilder(outputDataTypes);
+    if (showDataNodesResp.getDataNodesInfoList() != null) {
+      for (TDataNodeInfo dataNodeInfo : 
showDataNodesResp.getDataNodesInfoList()) {

Review Comment:
   filter removing DN here



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to