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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
