sanpwc commented on code in PR #5159:
URL: https://github.com/apache/ignite-3/pull/5159#discussion_r1942966517


##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ZoneResourcesManager.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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 org.apache.ignite.internal.util.IgniteUtils.inBusyLock;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.internal.catalog.descriptors.CatalogZoneDescriptor;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import 
org.apache.ignite.internal.tx.storage.state.ThreadAssertingTxStateStorage;
+import org.apache.ignite.internal.tx.storage.state.TxStatePartitionStorage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import 
org.apache.ignite.internal.tx.storage.state.rocksdb.TxStateRocksDbSharedStorage;
+import 
org.apache.ignite.internal.tx.storage.state.rocksdb.TxStateRocksDbStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.worker.ThreadAssertions;
+
+class ZoneResourcesManager implements ManuallyCloseable {

Review Comment:
   Could you please add a javadoc explaining what ZoneResourcesManager is?



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/PartitionReplicaLifecycleManager.java:
##########
@@ -485,6 +494,12 @@ private CompletableFuture<Void> 
createZonePartitionReplicationNode(
                                 stablePeersAndLearners,
                                 raftGroupListener,
                                 raftGroupEventsListener,
+                                // TODO: IGNITE-24371 - pass real isVolatile 
flag
+                                false,
+                                () -> 
zoneResourcesManager.getOrCreatePartitionStorage(
+                                        zoneDescriptorAt(zoneId, 
stableAssignments.timestamp()),

Review Comment:
   How it's guaranteed that catalog is up-to-date to the requested timestamp?
   Please check
   
   >      Note: the given timestamp must respect schema-synchronization timeout 
and it's up to user to wait for actual node metadata. See 
SchemaSyncService#waitForMetadataCompleteness(long) method for details.
   
   in `CatalogService#activeCatalog`



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/PartitionReplicaLifecycleManager.java:
##########
@@ -1185,6 +1210,12 @@ public CompletableFuture<Void> 
stopAsync(ComponentContext componentContext) {
             return nullCompletedFuture();
         }
 
+        try {
+            IgniteUtils.closeAllManually(zoneResourcesManager);

Review Comment:
   busy lock?



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/PartitionReplicaLifecycleManager.java:
##########
@@ -485,6 +494,12 @@ private CompletableFuture<Void> 
createZonePartitionReplicationNode(
                                 stablePeersAndLearners,
                                 raftGroupListener,
                                 raftGroupEventsListener,
+                                // TODO: IGNITE-24371 - pass real isVolatile 
flag
+                                false,
+                                () -> 
zoneResourcesManager.getOrCreatePartitionStorage(

Review Comment:
   Since now we do create and close resources on zone create and node stop 
let's also destroy them on zone drop.



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/PartitionReplicaLifecycleManager.java:
##########
@@ -485,6 +494,12 @@ private CompletableFuture<Void> 
createZonePartitionReplicationNode(
                                 stablePeersAndLearners,
                                 raftGroupListener,
                                 raftGroupEventsListener,
+                                // TODO: IGNITE-24371 - pass real isVolatile 
flag
+                                false,
+                                () -> 
zoneResourcesManager.getOrCreatePartitionStorage(
+                                        zoneDescriptorAt(zoneId, 
stableAssignments.timestamp()),

Review Comment:
   Why do we use timestamp from stable assignments?
   It's fragile:
   ZoneCreated -> zoneDescriptor(t1) -> stable(t1)
   ZoneAltered -> zoneDescriptor(t2) -> stable(t1)
   
   Event if currently stable assignments timestamp always matches proper zone 
descriptor it might not be true in case of using 
createZonePartitionReplicationNode within handling pending assignments event. I 
didn't check whether we do it know.
   



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ZoneResourcesManager.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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 org.apache.ignite.internal.util.IgniteUtils.inBusyLock;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.internal.catalog.descriptors.CatalogZoneDescriptor;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import 
org.apache.ignite.internal.tx.storage.state.ThreadAssertingTxStateStorage;
+import org.apache.ignite.internal.tx.storage.state.TxStatePartitionStorage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import 
org.apache.ignite.internal.tx.storage.state.rocksdb.TxStateRocksDbSharedStorage;
+import 
org.apache.ignite.internal.tx.storage.state.rocksdb.TxStateRocksDbStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.worker.ThreadAssertions;
+
+class ZoneResourcesManager implements ManuallyCloseable {
+    private final TxStateRocksDbSharedStorage sharedTxStateStorage;
+
+    private final Map<Integer, ZoneResources> zoneResourcesMap = new 
ConcurrentHashMap<>();
+
+    private final IgniteSpinBusyLock busyLock = new IgniteSpinBusyLock();
+
+    ZoneResourcesManager(TxStateRocksDbSharedStorage sharedTxStateStorage) {
+        this.sharedTxStateStorage = sharedTxStateStorage;
+    }
+
+    /**
+     * Gets or creates a transaction state storage for a zone partition.
+     *
+     * @param zoneDescriptor Zone descriptor.
+     * @param partitionId Partition ID.
+     */
+    TxStatePartitionStorage getOrCreatePartitionStorage(CatalogZoneDescriptor 
zoneDescriptor, int partitionId) {

Review Comment:
   PartitionStorage -> TxStateStorage ?



##########
modules/partition-replicator/src/test/java/org/apache/ignite/internal/partition/replicator/ZoneResourcesManagerTest.java:
##########
@@ -0,0 +1,94 @@
+/*
+ * 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 
org.apache.ignite.internal.testframework.IgniteTestUtils.bypassingThreadAssertions;
+import static 
org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.Mockito.when;
+
+import java.nio.file.Path;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ScheduledExecutorService;
+import org.apache.ignite.internal.catalog.descriptors.CatalogZoneDescriptor;
+import org.apache.ignite.internal.components.LogSyncer;
+import org.apache.ignite.internal.manager.ComponentContext;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.apache.ignite.internal.testframework.ExecutorServiceExtension;
+import org.apache.ignite.internal.testframework.InjectExecutorService;
+import org.apache.ignite.internal.testframework.WorkDirectory;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.apache.ignite.internal.tx.storage.state.TxStatePartitionStorage;
+import 
org.apache.ignite.internal.tx.storage.state.rocksdb.TxStateRocksDbSharedStorage;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+@ExtendWith(WorkDirectoryExtension.class)
+@ExtendWith(ExecutorServiceExtension.class)
+class ZoneResourcesManagerTest extends BaseIgniteAbstractTest {
+    private TxStateRocksDbSharedStorage sharedStorage;
+
+    @Mock
+    private CatalogZoneDescriptor zoneDescriptor;
+
+    @Mock
+    private LogSyncer logSyncer;
+
+    private ZoneResourcesManager manager;
+
+    @WorkDirectory
+    private Path workDir;
+
+    @InjectExecutorService
+    private ScheduledExecutorService scheduler;
+
+    @InjectExecutorService
+    private ExecutorService executor;
+
+    @BeforeEach
+    void init() {
+        sharedStorage = new TxStateRocksDbSharedStorage(workDir, scheduler, 
executor, logSyncer, () -> 0);
+
+        manager = new ZoneResourcesManager(sharedStorage);
+
+        when(zoneDescriptor.partitions()).thenReturn(10);
+
+        assertThat(sharedStorage.startAsync(new ComponentContext()), 
willCompleteSuccessfully());
+    }
+
+    @AfterEach
+    void cleanup() {
+        assertThat(sharedStorage.stopAsync(), willCompleteSuccessfully());
+    }
+
+    @Test
+    void createsTxStatePartitionStorage() {
+        TxStatePartitionStorage txStatePartitionStorage = 
bypassingThreadAssertions(
+                () -> manager.getOrCreatePartitionStorage(zoneDescriptor, 1)
+        );
+
+        assertThat(txStatePartitionStorage, is(notNullValue()));
+    }

Review Comment:
   I'd also add a test for ZoneResourcesManager#close that will ensure that all 
storages for several zones that were created will be closed. Similar to what 
you've added in ZonePartitionReplicaImplTest.



##########
modules/partition-replicator/src/main/java/org/apache/ignite/internal/partition/replicator/ZoneResourcesManager.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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 org.apache.ignite.internal.util.IgniteUtils.inBusyLock;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.ignite.internal.catalog.descriptors.CatalogZoneDescriptor;
+import org.apache.ignite.internal.close.ManuallyCloseable;
+import 
org.apache.ignite.internal.tx.storage.state.ThreadAssertingTxStateStorage;
+import org.apache.ignite.internal.tx.storage.state.TxStatePartitionStorage;
+import org.apache.ignite.internal.tx.storage.state.TxStateStorage;
+import 
org.apache.ignite.internal.tx.storage.state.rocksdb.TxStateRocksDbSharedStorage;
+import 
org.apache.ignite.internal.tx.storage.state.rocksdb.TxStateRocksDbStorage;
+import org.apache.ignite.internal.util.IgniteSpinBusyLock;
+import org.apache.ignite.internal.worker.ThreadAssertions;
+
+class ZoneResourcesManager implements ManuallyCloseable {
+    private final TxStateRocksDbSharedStorage sharedTxStateStorage;
+
+    private final Map<Integer, ZoneResources> zoneResourcesMap = new 
ConcurrentHashMap<>();

Review Comment:
   Please add a comment explaining that it's zoneId -> zoneResource and 
probably rename it to zone**s**...



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