ibessonov commented on code in PR #4859: URL: https://github.com/apache/ignite-3/pull/4859#discussion_r1877777093
########## modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/rebalance/RebalanceUtil.java: ########## @@ -203,9 +203,15 @@ public static CompletableFuture<Void> updatePendingAssignmentsKeys( put(partChangeTriggerKey, longToBytesKeepingOrder(revision)) ).yield(PLANNED_KEY_UPDATED.ordinal()), iif(value(partAssignmentsPendingKey).eq(partAssignmentsBytes), - ops(remove(partAssignmentsPlannedKey)).yield(PLANNED_KEY_REMOVED_EQUALS_PENDING.ordinal()), + ops( + remove(partAssignmentsPlannedKey), + put(partChangeTriggerKey, longToBytesKeepingOrder(revision)) Review Comment: Can we do the `longToBytesKeepingOrder(revision)` just once? ########## modules/distribution-zones/src/test/java/org/apache/ignite/internal/distributionzones/rebalance/RebalanceUtilUpdateAssignmentsTest.java: ########## @@ -521,12 +525,18 @@ private void test( KV_UPDATE_CONTEXT); } + keyValueStorage.put( + RebalanceUtil.pendingChangeTriggerKey(tablePartitionId).bytes(), + longToBytesKeepingOrder(1), + KV_UPDATE_CONTEXT); + + Review Comment: ```suggestion KV_UPDATE_CONTEXT ); ``` ########## modules/table/src/test/java/org/apache/ignite/internal/table/distributed/disaster/DisasterRecoveryMsInvokeTest.java: ########## @@ -0,0 +1,120 @@ +/* + * 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.table.distributed.disaster; + +import static java.util.stream.Collectors.toSet; +import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.pendingChangeTriggerKey; +import static org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil.pendingPartAssignmentsKey; +import static org.apache.ignite.internal.partitiondistribution.PartitionDistributionUtils.calculateAssignmentForPartition; +import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully; +import static org.apache.ignite.internal.util.ByteUtils.bytesToLongKeepingOrder; +import static org.apache.ignite.internal.util.ByteUtils.longToBytesKeepingOrder; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.stream.IntStream; +import java.util.stream.Stream; +import org.apache.ignite.internal.distributionzones.rebalance.RebalanceUtil; +import org.apache.ignite.internal.hlc.HybridClock; +import org.apache.ignite.internal.hlc.HybridClockImpl; +import org.apache.ignite.internal.manager.ComponentContext; +import org.apache.ignite.internal.metastorage.impl.MetaStorageManagerImpl; +import org.apache.ignite.internal.metastorage.impl.StandaloneMetaStorageManager; +import org.apache.ignite.internal.partitiondistribution.Assignment; +import org.apache.ignite.internal.partitiondistribution.Assignments; +import org.apache.ignite.internal.replicator.TablePartitionId; +import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +/** + * Tests for disaster recovery meta storage invoke that changes {@link RebalanceUtil#pendingChangeTriggerKey(TablePartitionId)}. + */ +public class DisasterRecoveryMsInvokeTest extends BaseIgniteAbstractTest { + private static final int partNum = 2; + private static final int replicas = 2; + + private static final Set<String> nodes1 = IntStream.of(5).mapToObj(i -> "nodes1_" + i).collect(toSet()); + private static final Set<String> nodes2 = IntStream.of(5).mapToObj(i -> "nodes2_" + i).collect(toSet()); + + private static final Set<Assignment> assignments1 = calculateAssignmentForPartition(nodes1, partNum, replicas); + private static final Set<Assignment> assignments2 = calculateAssignmentForPartition(nodes2, partNum, replicas); + + private static final TablePartitionId tablePartitionId = new TablePartitionId(1, 1); + + private static final long expectedPendingChangeTriggerKey = 10L; + + private long assignmentsTimestamp; + + private final HybridClock clock = new HybridClockImpl(); + + private MetaStorageManagerImpl metaStorageManager; + + @BeforeEach + public void setUp() throws ExecutionException, InterruptedException { + metaStorageManager = StandaloneMetaStorageManager.create(); + + assertThat(metaStorageManager.startAsync(new ComponentContext()), willCompleteSuccessfully()); + + metaStorageManager.deployWatches(); + + metaStorageManager.put(pendingChangeTriggerKey(tablePartitionId), longToBytesKeepingOrder(1)).get(); + + assignmentsTimestamp = clock.now().longValue(); + } + + @ParameterizedTest + @MethodSource("assignments") + public void testPendingChangeTriggerKey( + Set<Assignment> currentPending, + Set<Assignment> pending + ) throws Exception { + if (currentPending != null) { + metaStorageManager.put( + pendingPartAssignmentsKey(tablePartitionId), Assignments.toBytes(currentPending, assignmentsTimestamp) + ).get(); Review Comment: Usually we use `assertThat(*, willCompleteSuccessfully())`, it includes the timeout. Waiting without timeout is a bad habit. ########## modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/rebalance/ZoneRebalanceUtil.java: ########## @@ -200,9 +202,15 @@ public static CompletableFuture<Void> updatePendingAssignmentsKeys( put(partChangeTriggerKey, longToBytesKeepingOrder(revision)) ).yield(PLANNED_KEY_UPDATED.ordinal()), iif(value(partAssignmentsPendingKey).eq(partAssignmentsBytes), - ops(remove(partAssignmentsPlannedKey)).yield(PLANNED_KEY_REMOVED_EQUALS_PENDING.ordinal()), + ops( + remove(partAssignmentsPlannedKey), + put(partChangeTriggerKey, longToBytesKeepingOrder(revision)) Review Comment: Same question, basically ########## modules/distribution-zones/src/main/java/org/apache/ignite/internal/distributionzones/rebalance/RebalanceUtil.java: ########## @@ -203,9 +203,15 @@ public static CompletableFuture<Void> updatePendingAssignmentsKeys( put(partChangeTriggerKey, longToBytesKeepingOrder(revision)) ).yield(PLANNED_KEY_UPDATED.ordinal()), iif(value(partAssignmentsPendingKey).eq(partAssignmentsBytes), - ops(remove(partAssignmentsPlannedKey)).yield(PLANNED_KEY_REMOVED_EQUALS_PENDING.ordinal()), + ops( + remove(partAssignmentsPlannedKey), + put(partChangeTriggerKey, longToBytesKeepingOrder(revision)) Review Comment: Please update the comment too -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org