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 2022/09/28 01:14:49 UTC

[GitHub] [iotdb] SpriCoder commented on a diff in pull request #7454: [IOTDB-4423] Add TsFileMetricManager to take care of the tsfile status

SpriCoder commented on code in PR #7454:
URL: https://github.com/apache/iotdb/pull/7454#discussion_r981852320


##########
server/src/main/java/org/apache/iotdb/db/engine/TsFileMetricManager.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.engine;
+
+import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * This class collect the number and size of tsfile, and send it to the {@link
+ * org.apache.iotdb.db.service.metrics.predefined.FileMetrics}
+ */
+public class TsFileMetricManager {
+  private static final TsFileMetricManager INSTANCE = new TsFileMetricManager();
+  private AtomicLong seqFileSize = new AtomicLong(0);
+  private AtomicLong unseqFileSize = new AtomicLong(0);
+  private AtomicInteger seqFileNum = new AtomicInteger(0);
+  private AtomicInteger unseqFileNum = new AtomicInteger(0);
+
+  private TsFileMetricManager() {}
+
+  public static TsFileMetricManager getInstance() {
+    return INSTANCE;
+  }
+
+  public void addFile(long size, boolean seq) {
+    if (!MetricConfigDescriptor.getInstance().getMetricConfig().getEnableMetric()) {
+      return;
+    }
+    if (seq) {
+      seqFileSize.getAndAdd(size);
+      seqFileNum.incrementAndGet();
+    } else {
+      unseqFileSize.getAndAdd(size);
+      unseqFileNum.incrementAndGet();
+    }
+  }
+
+  public void deleteFile(long size, boolean seq) {
+    if (!MetricConfigDescriptor.getInstance().getMetricConfig().getEnableMetric()) {
+      return;
+    }

Review Comment:
   No need to judge whether metric service is enable.



##########
server/src/main/java/org/apache/iotdb/db/engine/TsFileMetricManager.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.engine;
+
+import org.apache.iotdb.metrics.config.MetricConfigDescriptor;
+
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * This class collect the number and size of tsfile, and send it to the {@link
+ * org.apache.iotdb.db.service.metrics.predefined.FileMetrics}
+ */
+public class TsFileMetricManager {
+  private static final TsFileMetricManager INSTANCE = new TsFileMetricManager();
+  private AtomicLong seqFileSize = new AtomicLong(0);
+  private AtomicLong unseqFileSize = new AtomicLong(0);
+  private AtomicInteger seqFileNum = new AtomicInteger(0);
+  private AtomicInteger unseqFileNum = new AtomicInteger(0);
+
+  private TsFileMetricManager() {}
+
+  public static TsFileMetricManager getInstance() {
+    return INSTANCE;
+  }
+
+  public void addFile(long size, boolean seq) {
+    if (!MetricConfigDescriptor.getInstance().getMetricConfig().getEnableMetric()) {
+      return;
+    }

Review Comment:
   No need to judge whether metric service is enable.



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