You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "Caideyipi (via GitHub)" <gi...@apache.org> on 2025/05/27 03:09:25 UTC

[PR] Added table metric & Improved the database / view metric [iotdb]

Caideyipi opened a new pull request, #15587:
URL: https://github.com/apache/iotdb/pull/15587

   ## Description
   As the title said.
   
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error 
       conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, 
       design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design 
   (or naming) decision point and compare the alternatives with the designs that you've implemented 
   (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere 
   (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), 
   link to that discussion from this PR description and explain what have changed in your final design 
   compared to your original proposal or the consensus version in the end of the discussion. 
   If something hasn't changed since the original discussion, you can omit a detailed discussion of 
   those aspects of the design here, perhaps apart from brief mentioning for the sake of readability 
   of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   <hr>
   
   This PR has:
   - [ ] been self-reviewed.
       - [ ] concurrent read
       - [ ] concurrent write
       - [ ] concurrent read and write 
   - [ ] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. 
   - [ ] added or updated version, __license__, or notice information
   - [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious 
     for an unfamiliar reader.
   - [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold 
     for code coverage.
   - [ ] added integration tests.
   - [ ] been tested in a test IoTDB cluster.
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items 
   apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items 
   from the checklist above are strictly necessary, but it would be very helpful if you at least 
   self-review the PR. -->
   
   <hr>
   
   ##### Key changed/added classes (or packages if there are too many classes) in this PR
   


-- 
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: reviews-unsubscribe@iotdb.apache.org

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


Re: [PR] Added table metric & Improved the database / view metric & Added "count databases" for table model [iotdb]

Posted by "jt2594838 (via GitHub)" <gi...@apache.org>.
jt2594838 merged PR #15587:
URL: https://github.com/apache/iotdb/pull/15587


-- 
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: reviews-unsubscribe@iotdb.apache.org

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


Re: [PR] Added table metric & Improved the database / view metric & Added "count databases" for table model [iotdb]

Posted by "jt2594838 (via GitHub)" <gi...@apache.org>.
jt2594838 commented on code in PR #15587:
URL: https://github.com/apache/iotdb/pull/15587#discussion_r2534550439


##########
iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/persistence/schema/ConfigSchemaStatistics.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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.confignode.persistence.schema;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * The {@link ConfigSchemaStatistics} is used to:
+ *
+ * <p>1. Serve the {@link org.apache.iotdb.confignode.manager.partition.PartitionMetrics} for schema
+ * related metrics, to prevent too much scanning and lock acquisition, and to simplify the metric
+ * getter logic.
+ *
+ * <p>2. Be reserved for potential mem-control and quota functionalities expansion.
+ *
+ * <p>3. Be in consistency with SchemaRegionMemMetric in dataNode.
+ */
+public class ConfigSchemaStatistics {
+  public AtomicLong treeDatabaseNum = new AtomicLong(0);
+
+  // Add 1 for information_schema
+  public AtomicLong tableDatabaseNum = new AtomicLong(1);
+
+  public ConcurrentMap<String, Long> treeViewTableNum = new ConcurrentHashMap<>();
+  public ConcurrentMap<String, Long> baseTableNum = new ConcurrentHashMap<>();
+
+  // Getter
+
+  public long getTreeDatabaseNum() {
+    return treeDatabaseNum.get();
+  }
+
+  public long getTableDatabaseNum() {
+    return tableDatabaseNum.get();
+  }
+
+  public long getTreeViewTableNum(final String database) {
+    return treeViewTableNum.getOrDefault(database, 0L);
+  }
+
+  public long getBaseTableNum(final String database) {
+    return baseTableNum.getOrDefault(database, 0L);
+  }
+
+  // Setter
+
+  public void increaseTreeDatabaseNum() {
+    treeDatabaseNum.incrementAndGet();
+  }
+
+  public void decreaseTreeDatabaseNum() {
+    treeDatabaseNum.decrementAndGet();
+  }
+
+  public void increaseTableDatabaseNum() {
+    tableDatabaseNum.incrementAndGet();
+  }
+
+  public void decreaseTableDatabaseNum() {
+    tableDatabaseNum.decrementAndGet();
+  }
+
+  public void increaseTreeViewTableNum(final String database) {
+    treeViewTableNum.compute(database, (db, num) -> num == null ? 0 : num + 1);

Review Comment:
   Should be 1 instead of 0?



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/metric/SchemaEngineMemMetric.java:
##########
@@ -123,6 +134,8 @@ public void unbindFrom(AbstractMetricService metricService) {
         MetricType.GAUGE, Metric.SCHEMA_ENGINE.toString(), Tag.NAME.toString(), SCHEMA_CONSENSUS);
   }
 
+  public static void unbindTableMetrics() {}
+

Review Comment:
   Why is this empty?



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java:
##########
@@ -3849,6 +3849,27 @@ public SettableFuture<ConfigTaskResult> showDatabases(
     return future;
   }
 
+  @Override
+  public SettableFuture<ConfigTaskResult> countDatabases(final Predicate<String> canSeenDB) {
+    final SettableFuture<ConfigTaskResult> future = SettableFuture.create();
+    // Construct request using statement
+    final List<String> databasePathPattern = Arrays.asList(ALL_RESULT_NODES);
+    try (final ConfigNodeClient client =
+        CONFIG_NODE_CLIENT_MANAGER.borrowClient(ConfigNodeInfo.CONFIG_REGION_ID)) {
+      // Send request to some API server
+      final TGetDatabaseReq req =
+          new TGetDatabaseReq(databasePathPattern, ALL_MATCH_SCOPE.serialize())
+              .setIsTableModel(true);
+      final TShowDatabaseResp resp = client.showDatabase(req);
+      // build TSBlock
+      CountDatabaseTask.buildTSBlock(
+          (int) resp.getDatabaseInfoMap().keySet().stream().filter(canSeenDB).count() + 1, future);

Review Comment:
   Add a comment for "+ 1".



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/rescon/MemSchemaEngineStatistics.java:
##########
@@ -186,6 +194,20 @@ public void deleteDevice(long cnt) {
     totalDeviceNumber.addAndGet(-cnt);
   }
 
+  public void addTableDevice(final String table) {
+    tableDeviceNumber.compute(table, (tableName, num) -> Objects.nonNull(num) ? num + 1 : 1L);
+  }
+
+  public void decreaseTableDevice(final String table, final long decrease) {
+    tableDeviceNumber.computeIfPresent(table, (tableName, num) -> num - decrease);
+  }
+
+  // Reset table device, will alter the schema statistics as well
+  public void resetTableDevice(final String table) {
+    final long num = tableDeviceNumber.remove(table);
+    totalDeviceNumber.addAndGet(-num);
+  }

Review Comment:
   Any chance num may be null?



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/rescon/MemSchemaEngineStatistics.java:
##########
@@ -129,6 +132,11 @@ public long getTotalDevicesNumber() {
     return totalDeviceNumber.get();
   }
 
+  @Override
+  public long getTableDeviceNumber(final String tableName) {
+    return tableDeviceNumber.get(tableName);
+  }

Review Comment:
   getOrDefault?



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java:
##########
@@ -3849,6 +3849,27 @@ public SettableFuture<ConfigTaskResult> showDatabases(
     return future;
   }
 
+  @Override
+  public SettableFuture<ConfigTaskResult> countDatabases(final Predicate<String> canSeenDB) {

Review Comment:
   canSeenDB -> canSeeDB
   
   



-- 
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: reviews-unsubscribe@iotdb.apache.org

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