rpuch commented on code in PR #7219:
URL: https://github.com/apache/ignite-3/pull/7219#discussion_r2625812851


##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/snapshot/outgoing/OutgoingSnapshotStats.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.ignite.internal.partition.replicator.raft.snapshot.outgoing;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.metrics.StopWatchTimer;
+import 
org.apache.ignite.internal.partition.replicator.raft.snapshot.PartitionKey;
+import 
org.apache.ignite.internal.partition.replicator.raft.snapshot.incoming.IncomingSnapshotCopier;
+import org.apache.ignite.internal.raft.RaftGroupConfiguration;
+
+/**
+ * Tracks important metrics for the outgoing snapshot.
+ *
+ * <p>Note: not thread safe. Thread safety guaranteed by operation's order in 
{@link IncomingSnapshotCopier}.
+ */
+class OutgoingSnapshotStats {
+    private static final IgniteLogger LOG = 
Loggers.forClass(OutgoingSnapshotStats.class);
+
+    long rowsSent;
+
+    long rowVersionsSent;
+
+    long totalBytesSent;
+
+    long outOfOrderRowsSent;
+
+    long outOfOrderVersionsSent;
+
+    long outOfOrderTotalBytesSent;
+
+    int totalBatches;
+
+    private final StopWatchTimer currentBatchTimer = new StopWatchTimer();
+
+    long combinedBatchDuration;
+
+    long minBatchDuration;
+
+    long maxBatchDuration;
+
+    final StopWatchTimer totalSnapshotTimer = new StopWatchTimer();
+
+    long lastAppliedIndex;
+
+    long lastAppliedTerm;
+
+    final List<String> peers = new ArrayList<>();
+
+    final List<String> oldPeers = new ArrayList<>();
+
+    final List<String> learners = new ArrayList<>();
+
+    final List<String> oldLearners = new ArrayList<>();
+
+    int catalogVersion;
+
+    private final UUID snapshotId;
+
+    private final PartitionKey partitionKey;
+
+    /** Constructor. */
+    OutgoingSnapshotStats(UUID snapshotId, PartitionKey partitionKey) {
+        this.snapshotId = snapshotId;
+        this.partitionKey = partitionKey;
+    }
+
+    void onSnapshotStart() {
+        totalSnapshotTimer.start();
+    }
+
+    void onSnapshotEnd() {
+        totalSnapshotTimer.end();
+    }
+
+    void setSnapshotMeta(long lastAppliedIndex, long lastAppliedTerm, 
RaftGroupConfiguration config, int catalogVersion) {
+        this.lastAppliedIndex = lastAppliedIndex;
+        this.lastAppliedTerm = lastAppliedTerm;
+        this.catalogVersion = catalogVersion;
+
+        peers.addAll(config.peers());
+
+        List<String> oldPeers = config.oldPeers();
+        if (oldPeers != null) {
+            this.oldPeers.addAll(oldPeers);
+        }
+
+        learners.addAll(config.learners());
+
+        List<String> oldLearners = config.oldLearners();
+        if (oldLearners != null) {
+            this.oldLearners.addAll(oldLearners);
+        }
+    }
+
+    void onStartMvDataBatchProcessing() {
+        this.currentBatchTimer.start();
+    }
+
+    void onEndMvDataBatchProcessing() {
+        this.currentBatchTimer.end();
+
+        totalBatches++;
+
+        long batchDuration = currentBatchTimer.duration(MILLISECONDS);
+
+        minBatchDuration = totalBatches == 1
+                ? batchDuration
+                : Math.min(minBatchDuration, batchDuration);
+
+        maxBatchDuration = Math.max(maxBatchDuration, batchDuration);
+
+        combinedBatchDuration += batchDuration;
+    }
+
+    void onProcessOutOfOrderRow(long rowVersions, long totalBytes) {
+        outOfOrderRowsSent++;
+
+        outOfOrderVersionsSent += rowVersions;
+        outOfOrderTotalBytesSent += totalBytes;
+    }
+
+    void onProcessRow(long rowVersions, long totalBytes) {
+        rowsSent++;
+
+        rowVersionsSent += rowVersions;
+        totalBytesSent += totalBytes;
+    }

Review Comment:
   If we track them separately, then 'non-out-of-order rows' need to be named 
in a specific name, like 'regular rows'. Otherwise, it's not clear whether 
out-of-order rows are included in just 'rows' or not



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/raft/snapshot/outgoing/OutgoingSnapshotStats.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.ignite.internal.partition.replicator.raft.snapshot.outgoing;
+
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.metrics.StopWatchTimer;
+import 
org.apache.ignite.internal.partition.replicator.raft.snapshot.PartitionKey;
+import 
org.apache.ignite.internal.partition.replicator.raft.snapshot.incoming.IncomingSnapshotCopier;
+import org.apache.ignite.internal.raft.RaftGroupConfiguration;
+
+/**
+ * Tracks important metrics for the outgoing snapshot.
+ *
+ * <p>Note: not thread safe. Thread safety guaranteed by operation's order in 
{@link IncomingSnapshotCopier}.
+ */
+class OutgoingSnapshotStats {
+    private static final IgniteLogger LOG = 
Loggers.forClass(OutgoingSnapshotStats.class);
+
+    long rowsSent;
+
+    long rowVersionsSent;
+
+    long totalBytesSent;
+
+    long outOfOrderRowsSent;
+
+    long outOfOrderVersionsSent;
+
+    long outOfOrderTotalBytesSent;
+
+    int totalBatches;
+
+    private final StopWatchTimer currentBatchTimer = new StopWatchTimer();
+
+    long combinedBatchDuration;
+
+    long minBatchDuration;
+
+    long maxBatchDuration;
+
+    final StopWatchTimer totalSnapshotTimer = new StopWatchTimer();
+
+    long lastAppliedIndex;
+
+    long lastAppliedTerm;
+
+    final List<String> peers = new ArrayList<>();
+
+    final List<String> oldPeers = new ArrayList<>();
+
+    final List<String> learners = new ArrayList<>();
+
+    final List<String> oldLearners = new ArrayList<>();
+
+    int catalogVersion;
+
+    private final UUID snapshotId;
+
+    private final PartitionKey partitionKey;
+
+    /** Constructor. */
+    OutgoingSnapshotStats(UUID snapshotId, PartitionKey partitionKey) {
+        this.snapshotId = snapshotId;
+        this.partitionKey = partitionKey;
+    }
+
+    void onSnapshotStart() {
+        totalSnapshotTimer.start();
+    }
+
+    void onSnapshotEnd() {
+        totalSnapshotTimer.end();
+    }
+
+    void setSnapshotMeta(long lastAppliedIndex, long lastAppliedTerm, 
RaftGroupConfiguration config, int catalogVersion) {
+        this.lastAppliedIndex = lastAppliedIndex;
+        this.lastAppliedTerm = lastAppliedTerm;
+        this.catalogVersion = catalogVersion;
+
+        peers.addAll(config.peers());
+
+        List<String> oldPeers = config.oldPeers();
+        if (oldPeers != null) {
+            this.oldPeers.addAll(oldPeers);
+        }
+
+        learners.addAll(config.learners());
+
+        List<String> oldLearners = config.oldLearners();
+        if (oldLearners != null) {
+            this.oldLearners.addAll(oldLearners);
+        }
+    }
+
+    void onStartMvDataBatchProcessing() {
+        this.currentBatchTimer.start();
+    }
+
+    void onEndMvDataBatchProcessing() {
+        this.currentBatchTimer.end();
+
+        totalBatches++;
+
+        long batchDuration = currentBatchTimer.duration(MILLISECONDS);
+
+        minBatchDuration = totalBatches == 1
+                ? batchDuration
+                : Math.min(minBatchDuration, batchDuration);
+
+        maxBatchDuration = Math.max(maxBatchDuration, batchDuration);
+
+        combinedBatchDuration += batchDuration;
+    }
+
+    void onProcessOutOfOrderRow(long rowVersions, long totalBytes) {
+        outOfOrderRowsSent++;
+
+        outOfOrderVersionsSent += rowVersions;
+        outOfOrderTotalBytesSent += totalBytes;
+    }
+
+    void onProcessRow(long rowVersions, long totalBytes) {
+        rowsSent++;
+
+        rowVersionsSent += rowVersions;
+        totalBytesSent += totalBytes;
+    }

Review Comment:
   If we track them separately, then 'non-out-of-order rows' need to be named 
in a specific name, like 'regular rows'. Otherwise, it's not clear to the user 
whether out-of-order rows are included in just 'rows' or not



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