rpuch commented on code in PR #7219: URL: https://github.com/apache/ignite-3/pull/7219#discussion_r2623253220
########## 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; Review Comment: applied -> included ########## 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 out of order rows and just rows are mutually exclusive, the latter should be renamed to 'regular rows'. But it seems more useful to have just rows (including both types) and out of order rows ########## modules/partition-replicator/src/test/java/org/apache/ignite/internal/partition/replicator/raft/snapshot/outgoing/OutgoingSnapshotStatsTest.java: ########## @@ -0,0 +1,133 @@ +/* + * 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 org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.is; + +import java.util.List; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import org.apache.ignite.internal.partition.replicator.raft.snapshot.ZonePartitionKey; +import org.apache.ignite.internal.raft.RaftGroupConfiguration; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * Tests for {@link OutgoingSnapshotStats}. + */ +class OutgoingSnapshotStatsTest { + private static final long LAST_APPLIED_INDEX = 1; + + private static final long LAST_APPLIED_TERM = 2; + + private static final List<String> PEERS = List.of("node1", "node2"); + + private static final List<String> OLD_PEERS = List.of("node3", "node4"); + + private static final List<String> LEARNERS = List.of("node5", "node6"); + + private static final List<String> OLD_LEARNERS = List.of("node7", "node8"); + + private static final RaftGroupConfiguration CONFIG = new RaftGroupConfiguration( + LAST_APPLIED_INDEX, + LAST_APPLIED_TERM, + 0, + 0, + PEERS, + LEARNERS, + OLD_PEERS, + OLD_LEARNERS + ); + + private static final int CATALOG_VERSION = 10; + + private OutgoingSnapshotStats stats; + + @BeforeEach + void setUp() { + stats = new OutgoingSnapshotStats(UUID.randomUUID(), new ZonePartitionKey(0, 0)); Review Comment: Can this be just moved to the initializer of `stats`? -- 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]
