Caideyipi commented on code in PR #12723:
URL: https://github.com/apache/iotdb/pull/12723#discussion_r1637516562


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/consensus/PipeConsensusConnectorMetrics.java:
##########
@@ -0,0 +1,290 @@
+/*
+ * 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.pipe.consensus;
+
+import org.apache.iotdb.commons.service.metric.enums.Metric;
+import org.apache.iotdb.commons.service.metric.enums.Tag;
+import 
org.apache.iotdb.db.pipe.connector.protocol.pipeconsensus.PipeConsensusAsyncConnector;
+import org.apache.iotdb.metrics.AbstractMetricService;
+import org.apache.iotdb.metrics.impl.DoNothingMetricManager;
+import org.apache.iotdb.metrics.metricsets.IMetricSet;
+import org.apache.iotdb.metrics.type.Counter;
+import org.apache.iotdb.metrics.type.Timer;
+import org.apache.iotdb.metrics.utils.MetricLevel;
+import org.apache.iotdb.metrics.utils.MetricType;
+
+public class PipeConsensusConnectorMetrics implements IMetricSet {
+  private final PipeConsensusAsyncConnector pipeConsensusAsyncConnector;
+
+  private Timer connectorEnqueueTimer = 
DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer connectorWALTransferTimer = 
DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer connectorTsFileTransferTimer = 
DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer connectorTsFilePieceTransferTimer = 
DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer retryWALTransferTimer = 
DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Timer retryTsFileTransferTimer = 
DoNothingMetricManager.DO_NOTHING_TIMER;
+  private Counter retryCounter = DoNothingMetricManager.DO_NOTHING_COUNTER;
+
+  private static final String CONNECTOR = "pipeConsensusAsyncConnector";
+
+  public PipeConsensusConnectorMetrics(PipeConsensusAsyncConnector 
pipeConsensusAsyncConnector) {
+    this.pipeConsensusAsyncConnector = pipeConsensusAsyncConnector;
+  }
+
+  public void recordConnectorEnqueueTimer(long costTimeInNanos) {
+    connectorEnqueueTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordConnectorWalTransferTimer(long costTimeInNanos) {
+    connectorWALTransferTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordConnectorTsFileTransferTimer(long costTimeInNanos) {
+    connectorTsFileTransferTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordConnectorTsFilePieceTransferTimer(long costTimeInNanos) {
+    connectorTsFilePieceTransferTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordRetryWALTransferTimer(long costTimeInNanos) {
+    retryWALTransferTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordRetryTsFileTransferTimer(long costTimeInNanos) {
+    retryTsFileTransferTimer.updateNanos(costTimeInNanos);
+  }
+
+  public void recordRetryCounter() {
+    retryCounter.inc();
+  }
+
+  @Override
+  public void bindTo(AbstractMetricService metricService) {
+    bindCounter(metricService);
+    bindAutoGauge(metricService);
+    bindTimer(metricService);
+  }
+
+  @Override
+  public void unbindFrom(AbstractMetricService metricService) {
+    unbindCounter(metricService);
+    unbindAutoGauge(metricService);
+    unbindTimer(metricService);
+  }
+
+  private void bindCounter(AbstractMetricService metricService) {
+    metricService.getOrCreateCounter(
+        Metric.PIPE_RETRY_SEND_EVENT.toString(),
+        MetricLevel.IMPORTANT,
+        Tag.NAME.toString(),
+        CONNECTOR,
+        Tag.REGION.toString(),
+        pipeConsensusAsyncConnector.getConsensusGroupIdStr(),
+        Tag.TYPE.toString(),
+        "pipeConsensusRetryCount");
+  }
+
+  private void bindAutoGauge(AbstractMetricService metricService) {
+    metricService.createAutoGauge(
+        Metric.PIPE_SEND_EVENT.toString(),
+        MetricLevel.IMPORTANT,
+        pipeConsensusAsyncConnector,
+        PipeConsensusAsyncConnector::getTransferBufferSize,
+        Tag.NAME.toString(),
+        CONNECTOR,
+        Tag.REGION.toString(),
+        pipeConsensusAsyncConnector.getConsensusGroupIdStr(),
+        Tag.TYPE.toString(),
+        "transferBufferSize");
+    metricService.createAutoGauge(
+        Metric.PIPE_SEND_EVENT.toString(),
+        MetricLevel.IMPORTANT,
+        pipeConsensusAsyncConnector,
+        PipeConsensusAsyncConnector::getRetryBufferSize,
+        Tag.NAME.toString(),
+        CONNECTOR,
+        Tag.REGION.toString(),
+        pipeConsensusAsyncConnector.getConsensusGroupIdStr(),
+        Tag.TYPE.toString(),
+        "retryBufferSize");
+  }
+
+  private void bindTimer(AbstractMetricService metricService) {
+    connectorEnqueueTimer =
+        metricService.getOrCreateTimer(
+            Metric.PIPE_SEND_EVENT.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            CONNECTOR,
+            Tag.TYPE.toString(),
+            "connectorEnqueueTimer",
+            Tag.REGION.toString(),
+            pipeConsensusAsyncConnector.getConsensusGroupIdStr());
+    connectorTsFilePieceTransferTimer =
+        metricService.getOrCreateTimer(
+            Metric.PIPE_SEND_EVENT.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            CONNECTOR,
+            Tag.TYPE.toString(),
+            "connectorTsFilePieceTransferTimer",
+            Tag.REGION.toString(),
+            pipeConsensusAsyncConnector.getConsensusGroupIdStr());
+    connectorTsFileTransferTimer =
+        metricService.getOrCreateTimer(
+            Metric.PIPE_SEND_EVENT.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            CONNECTOR,
+            Tag.TYPE.toString(),
+            "connectorTsFileTransferTimer",
+            Tag.REGION.toString(),
+            pipeConsensusAsyncConnector.getConsensusGroupIdStr());
+    connectorWALTransferTimer =
+        metricService.getOrCreateTimer(
+            Metric.PIPE_SEND_EVENT.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            CONNECTOR,
+            Tag.TYPE.toString(),
+            "connectorWALTransferTimer",
+            Tag.REGION.toString(),
+            pipeConsensusAsyncConnector.getConsensusGroupIdStr());
+    retryWALTransferTimer =
+        metricService.getOrCreateTimer(
+            Metric.PIPE_RETRY_SEND_EVENT.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            CONNECTOR,
+            Tag.TYPE.toString(),
+            "retryWALTransferTimer",
+            Tag.REGION.toString(),
+            pipeConsensusAsyncConnector.getConsensusGroupIdStr());
+    retryTsFileTransferTimer =
+        metricService.getOrCreateTimer(
+            Metric.PIPE_RETRY_SEND_EVENT.toString(),
+            MetricLevel.IMPORTANT,
+            Tag.NAME.toString(),
+            CONNECTOR,
+            Tag.TYPE.toString(),
+            "retryTsFileTransferTimer",
+            Tag.REGION.toString(),
+            pipeConsensusAsyncConnector.getConsensusGroupIdStr());
+  }
+
+  private void unbindCounter(AbstractMetricService metricService) {
+    retryCounter = DoNothingMetricManager.DO_NOTHING_COUNTER;
+
+    metricService.remove(
+        MetricType.COUNTER,
+        Metric.PIPE_RETRY_SEND_EVENT.toString(),
+        Tag.NAME.toString(),
+        CONNECTOR,
+        Tag.REGION.toString(),
+        pipeConsensusAsyncConnector.getConsensusGroupIdStr(),
+        Tag.TYPE.toString(),
+        "pipeConsensusRetryCount");
+  }
+
+  private void unbindAutoGauge(AbstractMetricService metricService) {
+    metricService.remove(
+        MetricType.AUTO_GAUGE,
+        Metric.PIPE_SEND_EVENT.toString(),
+        Tag.NAME.toString(),
+        CONNECTOR,
+        Tag.REGION.toString(),
+        pipeConsensusAsyncConnector.getConsensusGroupIdStr(),
+        Tag.TYPE.toString(),
+        "transferBufferSize");
+    metricService.remove(
+        MetricType.AUTO_GAUGE,
+        Metric.PIPE_SEND_EVENT.toString(),
+        Tag.NAME.toString(),
+        CONNECTOR,
+        Tag.REGION.toString(),
+        pipeConsensusAsyncConnector.getConsensusGroupIdStr(),
+        Tag.TYPE.toString(),
+        "retryBufferSize");
+  }
+
+  private void unbindTimer(AbstractMetricService metricService) {
+    connectorEnqueueTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
+    connectorWALTransferTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
+    connectorTsFileTransferTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
+    connectorTsFilePieceTransferTimer = 
DoNothingMetricManager.DO_NOTHING_TIMER;
+    retryWALTransferTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
+    retryTsFileTransferTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
+
+    metricService.remove(
+        MetricType.TIMER,
+        Metric.PIPE_SEND_EVENT.toString(),
+        Tag.NAME.toString(),
+        CONNECTOR,
+        Tag.TYPE.toString(),
+        "connectorTsFileTransferTimer",
+        Tag.REGION.toString(),
+        pipeConsensusAsyncConnector.getConsensusGroupIdStr());
+    metricService.remove(
+        MetricType.TIMER,
+        Metric.PIPE_SEND_EVENT.toString(),
+        Tag.NAME.toString(),
+        CONNECTOR,
+        Tag.TYPE.toString(),
+        "connectorTsFilePieceTransferTimer",
+        Tag.REGION.toString(),
+        pipeConsensusAsyncConnector.getConsensusGroupIdStr());
+    metricService.remove(
+        MetricType.TIMER,
+        Metric.PIPE_SEND_EVENT.toString(),
+        Tag.NAME.toString(),
+        CONNECTOR,
+        Tag.TYPE.toString(),
+        "connectorTsFileTransferTimer",
+        Tag.REGION.toString(),
+        pipeConsensusAsyncConnector.getConsensusGroupIdStr());
+    metricService.remove(
+        MetricType.TIMER,
+        Metric.PIPE_SEND_EVENT.toString(),
+        Tag.NAME.toString(),
+        CONNECTOR,
+        Tag.TYPE.toString(),
+        "connectorWALTransferTimer",
+        Tag.REGION.toString(),
+        pipeConsensusAsyncConnector.getConsensusGroupIdStr());
+    metricService.remove(
+        MetricType.TIMER,
+        Metric.PIPE_RETRY_SEND_EVENT.toString(),
+        Tag.NAME.toString(),
+        CONNECTOR,
+        Tag.TYPE.toString(),
+        "retryWALTransferTimer",

Review Comment:
   Better choose one of "Wal" and "WAL"



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/pipeconsensus/PipeConsensusReceiver.java:
##########
@@ -1196,12 +1273,15 @@ private TPipeConsensusTransferResp onRequest(
               if (timeout
                   && reqExecutionOrderBuffer.size() < 
IOTDB_CONFIG.getPipeConsensusPipelineSize()
                   && reqExecutionOrderBuffer.first() != null
-                  && reqExecutionOrderBuffer.first().equals(tCommitId)) {
+                  && reqExecutionOrderBuffer.first().equals(requestMeta)) {
+                long startApplyNanos = System.nanoTime();
+                metric.recordDispatchWaitingTimer(startApplyNanos - 
startDispatchNanos);
+                requestMeta.setStartApplyNanos(startApplyNanos);
                 TPipeConsensusTransferResp resp = loadEvent(req);
 
                 if (resp != null
                     && resp.getStatus().getCode() == 
TSStatusCode.SUCCESS_STATUS.getStatusCode()) {

Review Comment:
   What about redirection....



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/pipeconsensus/PipeConsensusReceiver.java:
##########
@@ -1241,4 +1321,63 @@ private void resetWithNewestRebootTime(int 
connectorRebootTimes) {
       this.connectorRebootTimes = connectorRebootTimes;
     }
   }
+
+  private static class RequestMeta {
+    private final TCommitId commitId;
+    private long startApplyNanos = 0;
+
+    public RequestMeta(TCommitId commitId) {
+      this.commitId = commitId;
+    }
+
+    public int getRebootTimes() {
+      return commitId.getRebootTimes();
+    }
+
+    public long getCommitIndex() {
+      return commitId.getCommitIndex();
+    }
+
+    public void setStartApplyNanos(long startApplyNanos) {
+      // Notice that a tsFileInsertionEvent will enter RequestExecutor 
multiple times, we only need
+      // to record the time of the first apply
+      if (startApplyNanos == 0) {
+        this.startApplyNanos = startApplyNanos;
+      }
+    }
+
+    public long getStartApplyNanos() {
+      return startApplyNanos;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+      if (this == o) {
+        return true;
+      }
+      if (o == null || getClass() != o.getClass()) {
+        return false;
+      }
+      RequestMeta that = (RequestMeta) o;
+      return commitId.equals(that.commitId);

Review Comment:
   Also override the "hashcode()"



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/connector/protocol/pipeconsensus/PipeConsensusAsyncConnector.java:
##########
@@ -466,6 +501,7 @@ public void addFailureEventToRetryQueue(final Event event) {
   public void addFailureEventsToRetryQueue(final Iterable<Event> events) {
     for (final Event event : events) {
       addFailureEventToRetryQueue(event);
+      pipeConsensusConnectorMetrics.recordRetryCounter();

Review Comment:
   Add it to "batchHandler" instead.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/receiver/protocol/pipeconsensus/PipeConsensusReceiver.java:
##########
@@ -1134,16 +1195,26 @@ private TPipeConsensusTransferResp onRequest(
         if (tCommitId.getRebootTimes() > connectorRebootTimes) {
           resetWithNewestRebootTime(tCommitId.getRebootTimes());
         }
-        reqExecutionOrderBuffer.add(tCommitId);
+        reqExecutionOrderBuffer.add(requestMeta);
+        // update metric
+        if (isTransferTsFilePiece) {
+          tsFileEventCount++;

Review Comment:
   It seems that a tsfile may cause multiple "++"s and only one "--".....



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