You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "rpuch (via GitHub)" <gi...@apache.org> on 2023/12/19 13:32:48 UTC
[PR] IGNITE-21079 PartitionReplicaListener should not interact with storages in the messaging thread [ignite-3]
rpuch opened a new pull request, #2978:
URL: https://github.com/apache/ignite-3/pull/2978
https://issues.apache.org/jira/browse/IGNITE-21079
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-21079 PartitionReplicaListener should not interact with storages in the messaging thread [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #2978:
URL: https://github.com/apache/ignite-3/pull/2978#discussion_r1431487158
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java:
##########
@@ -438,6 +443,14 @@ public TableManager(
int cpus = Runtime.getRuntime().availableProcessors();
+ partitionOperationsExecutor = new StripedThreadPoolExecutor(
+ Math.min(cpus * 3, 25),
+ NamedThreadFactory.threadPrefix(nodeName, "storage-operations"),
Review Comment:
Why it's "storage-operations?, it's rather a "partition-operations" one. It's not about the naming, it's about whether we need to move only storage related logic to the new thread or whole replicaRequest processing. I believe that latter is better.
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -3640,7 +3668,7 @@ private void failIfSchemaChangedSinceTxStart(UUID txId, HybridTimestamp operatio
}
private CompletableFuture<Integer> reliableCatalogVersionFor(HybridTimestamp ts) {
- return schemaSyncService.waitForMetadataCompleteness(ts)
+ return waitForMetadataCompleteness(ts)
.thenApply(unused -> catalogService.activeCatalogVersion(ts.longValue()));
}
Review Comment:
Switch from raft to replica is missing. I'm also mentioned it in the comment above within the context of decorated raft client.
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -338,7 +345,12 @@ public PartitionReplicaListener(
cursors = new ConcurrentSkipListMap<>(IgniteUuid.globalOrderComparator());
- schemaCompatValidator = new SchemaCompatibilityValidator(validationSchemasSource, catalogService, schemaSyncService);
+ schemaCompatValidator = new SchemaCompatibilityValidator(
Review Comment:
As you can see from the comments above I don't like an idea of mixing business logic inside PartitionReplicaListener with tread switching one. I'd say that we should propagate decorated schemaSyncService, raft client that will switch tread on replica enter.
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -468,6 +481,10 @@ public CompletableFuture<ReplicaResult> invoke(ReplicaRequest request, String se
});
}
+ private CompletableFuture<Void> switchToRequestOperationsThread() {
+ return runAsync(NO_OP, requestOperationsExecutor);
Review Comment:
Wondering whether it's an enough efficient why to switch the thread. Any thoughts?
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/TableManager.java:
##########
@@ -438,6 +443,14 @@ public TableManager(
int cpus = Runtime.getRuntime().availableProcessors();
+ partitionOperationsExecutor = new StripedThreadPoolExecutor(
Review Comment:
I'd rather move it to ReplicaManager. By the way, by doing this you will eliminate the necessity of adding new parameter to PartitionReplicaListener, instead it should be possible to change the thread somewhere near the `replica.processRequest. It might be fine to have such parameter in Replica.java though.
--
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-21079 PartitionReplicaListener should not interact with storages in the messaging thread [ignite-3]
Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #2978:
URL: https://github.com/apache/ignite-3/pull/2978#discussion_r1435562428
##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -213,6 +213,8 @@ public class IgniteImpl implements Ignite {
/** Lifecycle manager. */
private final LifecycleManager lifecycleManager;
+ private final ThreadPools threadPools;
Review Comment:
After thinking a bit more, I renamed the class, thanks for the suggestion.
--
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-21079 PartitionReplicaListener should not interact with storages in the messaging thread [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc merged PR #2978:
URL: https://github.com/apache/ignite-3/pull/2978
--
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-21079 PartitionReplicaListener should not interact with storages in the messaging thread [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #2978:
URL: https://github.com/apache/ignite-3/pull/2978#discussion_r1432465562
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -3640,7 +3668,7 @@ private void failIfSchemaChangedSinceTxStart(UUID txId, HybridTimestamp operatio
}
private CompletableFuture<Integer> reliableCatalogVersionFor(HybridTimestamp ts) {
- return schemaSyncService.waitForMetadataCompleteness(ts)
+ return waitForMetadataCompleteness(ts)
.thenApply(unused -> catalogService.activeCatalogVersion(ts.longValue()));
}
Review Comment:
I mean that raft response will be returned in messaging thread and we also won't to switch response processing to partition one.
--
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-21079 PartitionReplicaListener should not interact with storages in the messaging thread [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on PR #2978:
URL: https://github.com/apache/ignite-3/pull/2978#issuecomment-1868254696
Looks good to me. Thank you!
--
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-21079 PartitionReplicaListener should not interact with storages in the messaging thread [ignite-3]
Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #2978:
URL: https://github.com/apache/ignite-3/pull/2978#discussion_r1432305278
##########
modules/table/src/main/java/org/apache/ignite/internal/table/distributed/replicator/PartitionReplicaListener.java:
##########
@@ -3640,7 +3668,7 @@ private void failIfSchemaChangedSinceTxStart(UUID txId, HybridTimestamp operatio
}
private CompletableFuture<Integer> reliableCatalogVersionFor(HybridTimestamp ts) {
- return schemaSyncService.waitForMetadataCompleteness(ts)
+ return waitForMetadataCompleteness(ts)
.thenApply(unused -> catalogService.activeCatalogVersion(ts.longValue()));
}
Review Comment:
I don't get this one. `waitForMetadataCompleteness()` method guarantees to return a future which dependents will be executed in the partition-operations thread. How does it relate to a Raft client?
--
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-21079 PartitionReplicaListener should not interact with storages in the messaging thread [ignite-3]
Posted by "sanpwc (via GitHub)" <gi...@apache.org>.
sanpwc commented on code in PR #2978:
URL: https://github.com/apache/ignite-3/pull/2978#discussion_r1435541018
##########
modules/raft-api/src/main/java/org/apache/ignite/internal/raft/service/RaftCommandRunner.java:
##########
@@ -0,0 +1,39 @@
+/*
+ * 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.raft.service;
+
+import java.util.concurrent.CompletableFuture;
+import org.apache.ignite.internal.raft.Command;
+
+/**
+ * Raft client that is only able to run commands on a Raft group. For a more potent interface, take a look at {@link RaftGroupService}.
+ *
+ * @see RaftGroupService
+ */
+public interface RaftCommandRunner {
Review Comment:
It's fine for now, however in future we will also need to decorate other raft client methods like refreshLeader(), addPeer() and others that sends messages.
##########
modules/runner/src/main/java/org/apache/ignite/internal/app/ThreadPools.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.app;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.internal.thread.LogUncaughtExceptionHandler;
+import org.apache.ignite.internal.thread.NamedThreadFactory;
+import org.apache.ignite.internal.thread.StripedThreadPoolExecutor;
+import org.apache.ignite.internal.util.IgniteUtils;
+
+/**
+ * Component that hosts thread pools which do not belong to a certain component and which are global to an Ignite instance.
+ */
+public class ThreadPools implements IgniteComponent {
+ private static final IgniteLogger LOG = Loggers.forClass(ThreadPools.class);
+
+ private final StripedThreadPoolExecutor partitionOperationsExecutor;
+
+ /**
+ * Constructor.
+ */
+ public ThreadPools(String nodeName) {
+ partitionOperationsExecutor = new StripedThreadPoolExecutor(
+ Math.min(Runtime.getRuntime().availableProcessors() * 3, 25),
+ NamedThreadFactory.threadPrefix(nodeName, "partition-operations"),
+ new LogUncaughtExceptionHandler(LOG),
+ false,
+ 0
+ );
+ }
+
+ @Override
+ public void start() {
+ // No-op.
+ }
+
+ @Override
+ public void stop() throws Exception {
+ IgniteUtils.shutdownAndAwaitTermination(partitionOperationsExecutor, 10, TimeUnit.SECONDS);
+ }
+
+ public StripedThreadPoolExecutor partitionOperationsExecutor() {
Review Comment:
Same as above. It's a public method of an IgniteComponent, thus from my point of view it deserves the javadoc that will clarify the guarantees.
##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -213,6 +213,8 @@ public class IgniteImpl implements Ignite {
/** Lifecycle manager. */
private final LifecycleManager lifecycleManager;
+ private final ThreadPools threadPools;
Review Comment:
I'd preserve (almost)common naming patter here, meaning that I'd use Manager postfix.
##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -821,6 +827,7 @@ public CompletableFuture<Ignite> start(Path configPath) {
// Start all other components after the join request has completed and the node has been validated.
try {
lifecycleManager.startComponents(
+ threadPools,
Review Comment:
True for now, but when we will expand thread switching logic to cover meta storage it'll be necessary to move it to the "first" components group.
##########
modules/table/src/test/java/org/apache/ignite/internal/table/distributed/schema/ExecutorInclinedSchemaSyncServiceTest.java:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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.schema;
+
+import static java.util.concurrent.CompletableFuture.completedFuture;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureCompletedMatcher.completedFuture;
+import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.either;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.not;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.ignite.internal.hlc.HybridTimestamp;
+import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
+import org.apache.ignite.internal.util.IgniteUtils;
+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)
+class ExecutorInclinedSchemaSyncServiceTest extends BaseIgniteAbstractTest {
Review Comment:
I agree that such duplication it's better than test generification for raftCommandRunner and scemaSyncService.
##########
modules/replicator/src/main/java/org/apache/ignite/internal/replicator/ReplicaManager.java:
##########
@@ -129,6 +130,8 @@ public class ReplicaManager extends AbstractEventProducer<LocalReplicaEvent, Loc
/** A hybrid logical clock. */
private final HybridClock clock;
+ private final StripedThreadPoolExecutor requestsExecutor;
Review Comment:
Well, I'd add javadoc that will clarify what guarantees we have.
##########
modules/runner/src/main/java/org/apache/ignite/internal/app/ThreadPools.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.app;
+
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.internal.logger.IgniteLogger;
+import org.apache.ignite.internal.logger.Loggers;
+import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.internal.thread.LogUncaughtExceptionHandler;
+import org.apache.ignite.internal.thread.NamedThreadFactory;
+import org.apache.ignite.internal.thread.StripedThreadPoolExecutor;
+import org.apache.ignite.internal.util.IgniteUtils;
+
+/**
+ * Component that hosts thread pools which do not belong to a certain component and which are global to an Ignite instance.
+ */
+public class ThreadPools implements IgniteComponent {
+ private static final IgniteLogger LOG = Loggers.forClass(ThreadPools.class);
+
+ private final StripedThreadPoolExecutor partitionOperationsExecutor;
+
+ /**
+ * Constructor.
+ */
+ public ThreadPools(String nodeName) {
+ partitionOperationsExecutor = new StripedThreadPoolExecutor(
+ Math.min(Runtime.getRuntime().availableProcessors() * 3, 25),
Review Comment:
Almost sure, that someday we will add some configuration possibilities here, but for now it's fine.
--
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-21079 PartitionReplicaListener should not interact with storages in the messaging thread [ignite-3]
Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #2978:
URL: https://github.com/apache/ignite-3/pull/2978#discussion_r1435559947
##########
modules/runner/src/main/java/org/apache/ignite/internal/app/IgniteImpl.java:
##########
@@ -213,6 +213,8 @@ public class IgniteImpl implements Ignite {
/** Lifecycle manager. */
private final LifecycleManager lifecycleManager;
+ private final ThreadPools threadPools;
Review Comment:
I'm not sure it makes a lot of sense naming it a manager as it's just a collection of pools, so it would be a stretch
--
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