You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "sashapolo (via GitHub)" <gi...@apache.org> on 2025/02/13 12:17:24 UTC

[PR] IGNITE-24491 Fix zone replica stop order [ignite-3]

sashapolo opened a new pull request, #5226:
URL: https://github.com/apache/ignite-3/pull/5226

   https://issues.apache.org/jira/browse/IGNITE-24491
   
   Thank you for submitting the pull request.
   
   To streamline the review process of the patch and ensure better code quality
   we ask both an author and a reviewer to verify the following:
   
   ### The Review Checklist
   - [ ] **Formal criteria:** TC status, codestyle, mandatory documentation. Also make sure to complete the following:  
   \- There is a single JIRA ticket related to the pull request.  
   \- The web-link to the pull request is attached to the JIRA ticket.  
   \- The JIRA ticket has the Patch Available state.  
   \- The description of the JIRA ticket explains WHAT was made, WHY and HOW.  
   \- The pull request title is treated as the final commit message. The following pattern must be used: IGNITE-XXXX Change summary where XXXX - number of JIRA issue.
   - [ ] **Design:** new code conforms with the design principles of the components it is added to.
   - [ ] **Patch quality:** patch cannot be split into smaller pieces, its size must be reasonable.
   - [ ] **Code quality:** code is clean and readable, necessary developer documentation is added if needed.
   - [ ] **Tests code quality:** test set covers positive/negative scenarios, happy/edge cases. Tests are effective in terms of execution time and resources.
   
   ### Notes
   - [Apache Ignite Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Java+Code+Style+Guide)


-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24491 Fix zone replica stop order [ignite-3]

Posted by "JAkutenshi (via GitHub)" <gi...@apache.org>.
JAkutenshi commented on code in PR #5226:
URL: https://github.com/apache/ignite-3/pull/5226#discussion_r1955365928


##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/PartitionReplicaLifecycleManager.java:
##########
@@ -285,6 +287,45 @@ public PartitionReplicaLifecycleManager(
             TxStateRocksDbSharedStorage sharedTxStateStorage,
             TxManager txManager,
             SchemaManager schemaManager
+    ) {
+        this(
+                catalogService,
+                replicaMgr,
+                distributionZoneMgr,
+                metaStorageMgr,
+                topologyService,
+                lowWatermark,
+                ioExecutor,
+                rebalanceScheduler,
+                partitionOperationsExecutor,
+                clockService,
+                placementDriver,
+                schemaSyncService,
+                systemDistributedConfiguration,
+                txManager,
+                schemaManager,
+                new ZoneResourcesManager(sharedTxStateStorage)
+        );
+    }
+
+    @VisibleForTesting

Review Comment:
   `@TestOnly` is already imported, why not it?



##########
modules/partition-replicator/src/test/java/org/apache/ignite/internal/partition/replicator/PartitionReplicaLifecycleManagerTest.java:
##########
@@ -0,0 +1,231 @@
+/*
+ * 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;
+
+import static java.util.UUID.randomUUID;
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static org.apache.ignite.internal.distributionzones.rebalance.ZoneRebalanceUtil.STABLE_ASSIGNMENTS_PREFIX;
+import static org.apache.ignite.internal.lang.IgniteSystemProperties.COLOCATION_FEATURE_FLAG;
+import static org.apache.ignite.internal.lang.IgniteSystemProperties.THREAD_ASSERTIONS_ENABLED;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.util.CompletableFutures.emptySetCompletedFuture;
+import static org.apache.ignite.internal.util.CompletableFutures.nullCompletedFuture;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.inOrder;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import org.apache.ignite.internal.catalog.CatalogManager;
+import org.apache.ignite.internal.catalog.CatalogManagerImpl;
+import org.apache.ignite.internal.catalog.storage.UpdateLogImpl;
+import org.apache.ignite.internal.cluster.management.ClusterManagementGroupManager;
+import org.apache.ignite.internal.configuration.SystemDistributedConfiguration;
+import org.apache.ignite.internal.configuration.testframework.ConfigurationExtension;
+import org.apache.ignite.internal.configuration.testframework.InjectConfiguration;
+import org.apache.ignite.internal.distributionzones.DistributionZoneManager;
+import org.apache.ignite.internal.failure.FailureManager;
+import org.apache.ignite.internal.hlc.ClockService;
+import org.apache.ignite.internal.lang.ByteArray;
+import org.apache.ignite.internal.lang.NodeStoppingException;
+import org.apache.ignite.internal.lowwatermark.LowWatermark;
+import org.apache.ignite.internal.manager.ComponentContext;
+import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.internal.metastorage.MetaStorageManager;
+import org.apache.ignite.internal.metastorage.impl.StandaloneMetaStorageManager;
+import org.apache.ignite.internal.network.ClusterNodeImpl;
+import org.apache.ignite.internal.network.ClusterService;
+import org.apache.ignite.internal.partitiondistribution.Assignments;
+import org.apache.ignite.internal.placementdriver.PlacementDriver;
+import org.apache.ignite.internal.raft.Loza;
+import org.apache.ignite.internal.raft.RaftGroupOptionsConfigurer;
+import org.apache.ignite.internal.raft.client.TopologyAwareRaftGroupServiceFactory;
+import org.apache.ignite.internal.raft.storage.impl.LogStorageFactoryCreator;
+import org.apache.ignite.internal.replicator.ReplicaManager;
+import org.apache.ignite.internal.replicator.ZonePartitionId;
+import org.apache.ignite.internal.schema.SchemaManager;
+import org.apache.ignite.internal.schema.SchemaSyncService;
+import org.apache.ignite.internal.testframework.ExecutorServiceExtension;
+import org.apache.ignite.internal.testframework.IgniteAbstractTest;
+import org.apache.ignite.internal.testframework.InjectExecutorService;
+import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.tx.TxManager;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.network.NetworkAddress;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestInfo;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Answers;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+@ExtendWith(ExecutorServiceExtension.class)
+@ExtendWith(ConfigurationExtension.class)
+@WithSystemProperty(key = COLOCATION_FEATURE_FLAG, value = "true")
+@WithSystemProperty(key = THREAD_ASSERTIONS_ENABLED, value = "false")
+class PartitionReplicaLifecycleManagerTest extends IgniteAbstractTest {
+    private MetaStorageManager metaStorageManager;
+
+    private CatalogManager catalogManager;
+
+    private ReplicaManager replicaManager;
+
+    private PartitionReplicaLifecycleManager partitionReplicaLifecycleManager;
+
+    @Mock
+    private Loza raftManager;
+
+    @Mock
+    private ZoneResourcesManager zoneResourcesManager;
+
+    @InjectExecutorService
+    private ExecutorService executorService;
+
+    @InjectExecutorService
+    private ScheduledExecutorService scheduledExecutorService;
+
+    @InjectConfiguration
+    private SystemDistributedConfiguration systemDistributedConfiguration;
+
+    @BeforeEach
+    void setUp(
+            TestInfo testInfo,
+            @Mock(answer = Answers.RETURNS_DEEP_STUBS) ClusterService clusterService,
+            @Mock DistributionZoneManager distributionZoneManager,
+            @Mock LowWatermark lowWatermark,
+            @Mock ClockService clockService,
+            @Mock PlacementDriver placementDriver,
+            @Mock SchemaSyncService schemaSyncService,
+            @Mock TxManager txManager,
+            @Mock SchemaManager schemaManager,
+            @Mock ClusterManagementGroupManager cmgManager,
+            @Mock FailureManager failureManager,
+            @Mock TopologyAwareRaftGroupServiceFactory topologyAwareRaftGroupServiceFactory,
+            @Mock LogStorageFactoryCreator logStorageFactoryCreator
+    ) {
+        String nodeName = testNodeName(testInfo, 0);
+
+        when(clusterService.topologyService().localMember())
+                .thenReturn(new ClusterNodeImpl(randomUUID(), nodeName, new NetworkAddress("localhost", 0)));
+
+        when(placementDriver.getPrimaryReplica(any(), any())).thenReturn(nullCompletedFuture());
+
+        when(cmgManager.metaStorageNodes()).thenReturn(emptySetCompletedFuture());
+
+        when(distributionZoneManager.dataNodes(anyLong(), anyInt(), anyInt())).thenReturn(completedFuture(Set.of(nodeName)));
+
+        metaStorageManager = StandaloneMetaStorageManager.create();
+
+        catalogManager = new CatalogManagerImpl(new UpdateLogImpl(metaStorageManager), clockService);
+
+        replicaManager = new ReplicaManager(
+                nodeName,
+                clusterService,
+                cmgManager,
+                clockService,
+                Set.of(),
+                placementDriver,
+                executorService,
+                () -> Long.MAX_VALUE,
+                failureManager,
+                null,
+                topologyAwareRaftGroupServiceFactory,
+                raftManager,
+                RaftGroupOptionsConfigurer.EMPTY,
+                logStorageFactoryCreator,
+                executorService,
+                groupId -> nullCompletedFuture()
+        );
+
+        partitionReplicaLifecycleManager = new PartitionReplicaLifecycleManager(
+                catalogManager,
+                replicaManager,
+                distributionZoneManager,
+                metaStorageManager,
+                clusterService.topologyService(),
+                lowWatermark,
+                executorService,
+                scheduledExecutorService,
+                executorService,
+                clockService,
+                placementDriver,
+                schemaSyncService,
+                systemDistributedConfiguration,
+                txManager,
+                schemaManager,
+                zoneResourcesManager
+        );
+
+        var componentContext = new ComponentContext();
+
+        assertThat(metaStorageManager.startAsync(componentContext), willCompleteSuccessfully());
+        assertThat(metaStorageManager.recoveryFinishedFuture(), willCompleteSuccessfully());
+
+        assertThat(catalogManager.startAsync(componentContext), willCompleteSuccessfully());
+        assertThat(replicaManager.startAsync(componentContext), willCompleteSuccessfully());
+        assertThat(partitionReplicaLifecycleManager.startAsync(componentContext), willCompleteSuccessfully());
+
+        assertThat(metaStorageManager.deployWatches(), willCompleteSuccessfully());
+        assertThat(catalogManager.catalogInitializationFuture(), willCompleteSuccessfully());
+    }
+
+    @AfterEach
+    void tearDown() {
+        List<IgniteComponent> components = List.of(partitionReplicaLifecycleManager, replicaManager, catalogManager, metaStorageManager);
+
+        components.forEach(IgniteComponent::beforeNodeStop);
+
+        IgniteUtils.stopAsync(new ComponentContext(), components);
+    }
+
+    /**
+     * Tests that resources of {@link PartitionReplicaLifecycleManager} are stopped in a correct order.
+     */
+    @Test
+    void testStopOrder() throws NodeStoppingException {
+        int zoneId = catalogManager.catalog(catalogManager.latestCatalogVersion()).defaultZone().id();
+
+        var zonePartitionId = new ZonePartitionId(zoneId, 0);
+
+        var stableAssignmentsKey = new ByteArray(STABLE_ASSIGNMENTS_PREFIX + zonePartitionId);

Review Comment:
   `ZoneRebalanceUtil.stablePartAssignmentsKey(zonePartitionId)`



##########
modules/replicator/src/main/java/org/apache/ignite/internal/replicator/ZonePartitionReplicaImpl.java:
##########
@@ -42,26 +39,21 @@ public class ZonePartitionReplicaImpl implements Replica {
 
     private final TopologyAwareRaftGroupService raftClient;
 
-    private final ManuallyCloseable partitionResources;

Review Comment:
   We remove the field because it doesn't use at least for now?



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ZoneResourcesManager.java:
##########
@@ -98,13 +109,14 @@ private ZoneResources(TxStateStorage txStateStorage) {
     }
 
     @TestOnly
+    @Nullable
     public TxStatePartitionStorage txStatePartitionStorage(int zoneId, int partitionId) {
         ZoneResources resources = resourcesByZoneId.get(zoneId);
-        assert resources != null : "No resources yet for zone " + zoneId;
 
-        TxStatePartitionStorage partitionStorage = resources.txStateStorage.getPartitionStorage(partitionId);
-        assert partitionStorage != null : "No partition storage for zone " + zoneId + " and partition " + partitionId;
+        if (resources == null) {

Review Comment:
   I couldn't understand why did you change the method in this way?



##########
modules/transactions/src/main/java/org/apache/ignite/internal/tx/storage/state/rocksdb/TxStateRocksDbStorage.java:
##########
@@ -166,9 +166,4 @@ public void destroy() {
             throw new IgniteInternalException("Failed to destroy the transaction state storage of the table: " + id, e);
         }
     }
-
-    @Override
-    public void close() {
-        stop();

Review Comment:
   A funny (no) code. Thanks for removing



-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24491 Fix zone replica stop order [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo merged PR #5226:
URL: https://github.com/apache/ignite-3/pull/5226


-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24491 Fix zone replica stop order [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #5226:
URL: https://github.com/apache/ignite-3/pull/5226#discussion_r1955649870


##########
modules/replicator/src/main/java/org/apache/ignite/internal/replicator/ZonePartitionReplicaImpl.java:
##########
@@ -42,26 +39,21 @@ public class ZonePartitionReplicaImpl implements Replica {
 
     private final TopologyAwareRaftGroupService raftClient;
 
-    private final ManuallyCloseable partitionResources;

Review Comment:
   yes, it's no longer needed



-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24491 Fix zone replica stop order [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #5226:
URL: https://github.com/apache/ignite-3/pull/5226#discussion_r1955649697


##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/PartitionReplicaLifecycleManager.java:
##########
@@ -285,6 +287,45 @@ public PartitionReplicaLifecycleManager(
             TxStateRocksDbSharedStorage sharedTxStateStorage,
             TxManager txManager,
             SchemaManager schemaManager
+    ) {
+        this(
+                catalogService,
+                replicaMgr,
+                distributionZoneMgr,
+                metaStorageMgr,
+                topologyService,
+                lowWatermark,
+                ioExecutor,
+                rebalanceScheduler,
+                partitionOperationsExecutor,
+                clockService,
+                placementDriver,
+                schemaSyncService,
+                systemDistributedConfiguration,
+                txManager,
+                schemaManager,
+                new ZoneResourcesManager(sharedTxStateStorage)
+        );
+    }
+
+    @VisibleForTesting

Review Comment:
   Because this is not a test-only code, it's called by the other constructor. But it is made visible (not private) specifically for tests



-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] IGNITE-24491 Fix zone replica stop order [ignite-3]

Posted by "sashapolo (via GitHub)" <gi...@apache.org>.
sashapolo commented on code in PR #5226:
URL: https://github.com/apache/ignite-3/pull/5226#discussion_r1955682753


##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ZoneResourcesManager.java:
##########
@@ -98,13 +109,14 @@ private ZoneResources(TxStateStorage txStateStorage) {
     }
 
     @TestOnly
+    @Nullable
     public TxStatePartitionStorage txStatePartitionStorage(int zoneId, int partitionId) {
         ZoneResources resources = resourcesByZoneId.get(zoneId);
-        assert resources != null : "No resources yet for zone " + zoneId;
 
-        TxStatePartitionStorage partitionStorage = resources.txStateStorage.getPartitionStorage(partitionId);
-        assert partitionStorage != null : "No partition storage for zone " + zoneId + " and partition " + partitionId;
+        if (resources == null) {

Review Comment:
   This is test-only method. Previously it threw an assertion if resources didn't exist. In order to write a unit test, I need it to return `null` instead.



-- 
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-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org