You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by "MarcosZyk (via GitHub)" <gi...@apache.org> on 2023/02/22 09:31:01 UTC

[GitHub] [iotdb] MarcosZyk commented on a diff in pull request #9109: [IOTDB-5524] Add Metrics for Schema Module

MarcosZyk commented on code in PR #9109:
URL: https://github.com/apache/iotdb/pull/9109#discussion_r1114055617


##########
server/src/main/java/org/apache/iotdb/db/metadata/mtree/store/disk/cache/CacheManager.java:
##########
@@ -555,6 +560,14 @@ void forEachNode(Consumer<IMNode> action) {
       }
     }
 
+    long getBufferNodeNum() {
+      long res = updatedStorageGroupMNode == null ? 0 : 1;
+      for (int i = 0; i < MAP_NUM; i++) {
+        res += maps[i].size();

Review Comment:
   The node in buffer map is the root node of a subtree need flush.



##########
server/src/main/java/org/apache/iotdb/db/metadata/metric/SchemaEngineCachedMetric.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.metadata.metric;
+
+import org.apache.iotdb.commons.service.metric.MetricService;
+import org.apache.iotdb.commons.service.metric.enums.Metric;
+import org.apache.iotdb.commons.service.metric.enums.Tag;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.metadata.mtree.store.disk.cache.CacheMemoryManager;
+import org.apache.iotdb.db.metadata.mtree.store.disk.memcontrol.ReleaseFlushStrategySizeBasedImpl;
+import org.apache.iotdb.db.metadata.rescon.CachedSchemaEngineStatistics;
+import org.apache.iotdb.metrics.AbstractMetricService;
+import org.apache.iotdb.metrics.utils.MetricLevel;
+import org.apache.iotdb.metrics.utils.MetricType;
+
+import java.util.concurrent.TimeUnit;
+
+public class SchemaEngineCachedMetric implements ISchemaEngineMetric {
+
+  private static final String RELEASE_THRESHOLD = "schema_file_release_threshold";
+  private static final String FLUSH_THRESHOLD = "schema_file_flush_threshold";
+  private static final String PINNED_NUM = "schema_file_pinned_num";
+  private static final String UNPINNED_NUM = "schema_file_unpinned_num";
+  private static final String PINNED_MEM = "schema_file_pinned_mem";
+  private static final String UNPINNED_MEM = "schema_file_unpinned_mem";
+  private static final String RELEASE_TIMER = "schema_file_release_timer";
+  private static final String FLUSH_TIMER = "schema_file_flush_timer";
+  private static final String RELEASE_THREAD_NUM = "schema_file_release_thread_num";
+  private static final String FLUSH_THREAD_NUM = "schema_file_flush_thread_num";
+
+  private final CachedSchemaEngineStatistics engineStatistics;
+
+  private final SchemaEngineMemMetric schemaEngineMemMetric;
+
+  public SchemaEngineCachedMetric(CachedSchemaEngineStatistics engineStatistics) {
+    this.engineStatistics = engineStatistics;
+    this.schemaEngineMemMetric = new SchemaEngineMemMetric(engineStatistics);
+  }
+
+  @Override
+  public void bindTo(AbstractMetricService metricService) {
+    schemaEngineMemMetric.bindTo(metricService);
+    metricService.gauge(
+        (long)
+            (IoTDBDescriptor.getInstance().getConfig().getAllocateMemoryForSchemaRegion()
+                * ReleaseFlushStrategySizeBasedImpl.RELEASE_THRESHOLD_RATIO),
+        Metric.SCHEMA_ENGINE.toString(),
+        MetricLevel.IMPORTANT,
+        Tag.NAME.toString(),
+        RELEASE_THRESHOLD);
+    metricService.gauge(
+        (long)
+            (IoTDBDescriptor.getInstance().getConfig().getAllocateMemoryForSchemaRegion()
+                * ReleaseFlushStrategySizeBasedImpl.FLUSH_THRESHOLD_RATION),
+        Metric.SCHEMA_ENGINE.toString(),
+        MetricLevel.IMPORTANT,
+        Tag.NAME.toString(),
+        FLUSH_THRESHOLD);
+    metricService.createAutoGauge(
+        Metric.SCHEMA_ENGINE.toString(),
+        MetricLevel.IMPORTANT,
+        engineStatistics,
+        CachedSchemaEngineStatistics::getPinnedMNodeNum,
+        Tag.NAME.toString(),
+        PINNED_NUM);
+    metricService.createAutoGauge(
+        Metric.SCHEMA_ENGINE.toString(),
+        MetricLevel.IMPORTANT,
+        engineStatistics,
+        CachedSchemaEngineStatistics::getUnpinnedMNodeNum,
+        Tag.NAME.toString(),
+        UNPINNED_NUM);
+    metricService.createAutoGauge(
+        Metric.SCHEMA_ENGINE.toString(),
+        MetricLevel.IMPORTANT,
+        engineStatistics,
+        CachedSchemaEngineStatistics::getPinnedMemorySize,
+        Tag.NAME.toString(),
+        PINNED_MEM);
+    metricService.createAutoGauge(
+        Metric.SCHEMA_ENGINE.toString(),
+        MetricLevel.IMPORTANT,
+        engineStatistics,
+        CachedSchemaEngineStatistics::getUnpinnedMemorySize,
+        Tag.NAME.toString(),
+        UNPINNED_MEM);

Review Comment:
   Should these two pairs diff?



##########
server/src/main/java/org/apache/iotdb/db/metadata/rescon/MemSchemaEngineStatistics.java:
##########
@@ -37,6 +38,8 @@ public class MemSchemaEngineStatistics implements ISchemaEngineStatistics {
 
   private final AtomicLong totalSeriesNumber = new AtomicLong(0);
 
+  private final AtomicInteger schemaRegionNumber = new AtomicInteger(0);

Review Comment:
   There's a map storing all SchemaRegion in SchemaEngine. Can we use it to achieve such statistics.



##########
server/src/main/java/org/apache/iotdb/db/metadata/schemaregion/SchemaRegionMemoryImpl.java:
##########
@@ -389,10 +397,14 @@ public synchronized void deleteSchemaRegion() throws MetadataException {
     }
 
     // clear all the components and release all the file handlers
+    regionStatistics.deleteSchemaRegion();
     clear();
 
     // delete all the schema region files
     SchemaRegionUtils.deleteSchemaRegionFolder(schemaRegionDirPath, logger);
+
+    // delete metric
+    SchemaMetricManager.getInstance().deleteSchemaRegionMetric(schemaRegionId.getId());

Review Comment:
   Should this logic transferred to SchemaEngine?



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