You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "petrov-mg (via GitHub)" <gi...@apache.org> on 2026/05/18 22:24:14 UTC
[PR] IGNITE-28681 Operation Context integrated in Ignite internal async structures [ignite]
petrov-mg opened a new pull request, #13148:
URL: https://github.com/apache/ignite/pull/13148
Thank you for submitting the pull request to the Apache Ignite.
In order to streamline the review of the contribution
we ask you to ensure the following steps have been taken:
### The Contribution Checklist
- [ ] 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 pull request body describes changes that have been made.
The description explains _WHAT_ and _WHY_ was made instead of _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.
- [ ] A reviewer has been mentioned through the JIRA comments
(see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers))
- [ ] The pull request has been checked by the Teamcity Bot and
the `green visa` attached to the JIRA ticket (see tab `PR Check` at [TC.Bot - Instance 1](https://tcbot2.sbt-ignite-dev.ru/prs.html) or [TC.Bot - Instance 2](https://mtcga.gridgain.com/prs.html))
### Notes
- [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
- [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
- [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
- [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "petrov-mg (via GitHub)" <gi...@apache.org>.
petrov-mg merged PR #13148:
URL: https://github.com/apache/ignite/pull/13148
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #13148:
URL: https://github.com/apache/ignite/pull/13148#issuecomment-4522895563
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) **Quality Gate failed**
Failed conditions
 [24 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) (required ≤ 1)
<!-- sqra:qg_revision=646c88985f8ffb947246379aebc620d6a443686216fc4ecf4317faf804713d6f -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #13148:
URL: https://github.com/apache/ignite/pull/13148#issuecomment-4482822255
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) **Quality Gate failed**
Failed conditions
 [6 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) (required ≤ 1)
<!-- sqra:qg_revision=af0f1848494a3e8b75232f670b51010f6bf14ed26be1934cbd73b992529abf95 -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #13148:
URL: https://github.com/apache/ignite/pull/13148#issuecomment-4496457705
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) **Quality Gate failed**
Failed conditions
 [4 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) (required ≤ 1)
<!-- sqra:qg_revision=e206e686bf91e5584af03460677b882d272e6c614f492ab510a7ff7043b9f0f5 -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #13148:
URL: https://github.com/apache/ignite/pull/13148#issuecomment-4521907898
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) **Quality Gate failed**
Failed conditions
 [24 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) (required ≤ 1)
<!-- sqra:qg_revision=646c88985f8ffb947246379aebc620d6a443686216fc4ecf4317faf804713d6f -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "petrov-mg (via GitHub)" <gi...@apache.org>.
petrov-mg commented on code in PR #13148:
URL: https://github.com/apache/ignite/pull/13148#discussion_r3304528383
##########
modules/core/src/main/java/org/apache/ignite/internal/util/worker/queue/AsyncQueueHandler.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.util.worker.queue;
+
+import java.util.Iterator;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.managers.communication.GridIoPolicy;
+import org.apache.ignite.internal.thread.context.OperationContext;
+import org.apache.ignite.internal.thread.context.OperationContextSnapshot;
+import org.apache.ignite.internal.thread.context.function.OperationContextAwareWrapper;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.worker.GridWorker;
+import org.apache.ignite.internal.worker.WorkersRegistry;
+import org.apache.ignite.thread.IgniteThread;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.thread.IgniteThread.GRP_IDX_UNASSIGNED;
+
+/**
+ * Represents a single-threaded, asynchronous queue elements handler. It automatically captures the {@link OperationContext}
+ * attached to the thread that submitted the item for handling and restores it before handling actually begins in the
+ * worker thread.
+ *
+ * @param <T> Type of items to be processed.
+ * @param <W> Type of wrapper over processing item that are stored in the underlying queue.
+ */
+abstract class AsyncQueueHandler<T, W extends OperationContextAwareWrapper<T>> extends GridWorker {
+ /** */
+ private final BlockingQueue<W> workerQueue;
+
+ /** */
+ private Thread workerThread;
+
+ /** */
+ protected AsyncQueueHandler(
+ @Nullable String igniteInstanceName,
+ String workerThreadName,
+ IgniteLogger log,
+ @Nullable WorkersRegistry workerReg,
+ BlockingQueue<W> workerQueue
+ ) {
+ super(igniteInstanceName, workerThreadName, log, workerReg);
+
+ this.workerQueue = workerQueue;
+ }
+
+ /** */
+ protected abstract W wrapQueueElement(T delegate, OperationContextSnapshot snapshot);
+
+ /** */
+ protected Thread.UncaughtExceptionHandler uncaughtExceptionHandler() {
+ return null;
+ }
+
+ /** */
+ protected IgniteThread createWorkerThread(GridWorker worker) {
+ return new IgniteThread(igniteInstanceName(), name(), worker, GRP_IDX_UNASSIGNED, -1, GridIoPolicy.UNDEFINED);
+ }
+
+ /** */
+ @Nullable protected OperationContextAwareWrapper<T> takeQueuedElement() throws InterruptedException {
+ blockingSectionBegin();
+
+ try {
+ return workerQueue.take();
+ }
+ finally {
+ blockingSectionEnd();
+ }
+ }
+
+ /** */
+ @Nullable protected OperationContextAwareWrapper<T> pollQueuedElement(
+ long timeout,
+ @NotNull TimeUnit unit
+ ) throws InterruptedException {
+ blockingSectionBegin();
+
+ try {
+ return workerQueue.poll(timeout, unit);
+ }
+ finally {
+ blockingSectionEnd();
+ }
+ }
+
+ /** */
+ public void start() {
+ synchronized (this) {
+ if (workerThread != null)
+ return;
+
+ workerThread = createWorkerThread(this);
+
+ Thread.UncaughtExceptionHandler errHnd = uncaughtExceptionHandler();
+
+ if (errHnd != null)
+ workerThread.setUncaughtExceptionHandler(errHnd);
+
+ workerThread.start();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void cleanup() {
Review Comment:
The `start` method creates and starts a worker thread. Once the worker thread completes execution of its body, it invokes the `cleanup` method (see GridWorker#run). Since `cleanup` is declared as protected, it can only be invoked by the worker thread itself.
Therefore, invocation of start always happens-before invocation of cleanup.
Currently, `AsyncQueueHandler` supports restarting, so the following scenario is expected:
1. A worker thread is started.
2. The worker is cancelled.
3. The worker body completes execution.
4. Resources are cleaned up.
5. The worker thread terminates.
6. A new worker thread is started.
We expect that code that uses AsyncQueueHandler must prevent unintended worker restarts.
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #13148:
URL: https://github.com/apache/ignite/pull/13148#issuecomment-4520263691
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) **Quality Gate failed**
Failed conditions
 [24 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) (required ≤ 1)
<!-- sqra:qg_revision=646c88985f8ffb947246379aebc620d6a443686216fc4ecf4317faf804713d6f -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "petrov-mg (via GitHub)" <gi...@apache.org>.
petrov-mg commented on code in PR #13148:
URL: https://github.com/apache/ignite/pull/13148#discussion_r3304563604
##########
modules/core/src/main/java/org/apache/ignite/internal/util/worker/queue/AsyncQueueHandler.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.util.worker.queue;
+
+import java.util.Iterator;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.managers.communication.GridIoPolicy;
+import org.apache.ignite.internal.thread.context.OperationContext;
+import org.apache.ignite.internal.thread.context.OperationContextSnapshot;
+import org.apache.ignite.internal.thread.context.function.OperationContextAwareWrapper;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.worker.GridWorker;
+import org.apache.ignite.internal.worker.WorkersRegistry;
+import org.apache.ignite.thread.IgniteThread;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.thread.IgniteThread.GRP_IDX_UNASSIGNED;
+
+/**
+ * Represents a single-threaded, asynchronous queue elements handler. It automatically captures the {@link OperationContext}
+ * attached to the thread that submitted the item for handling and restores it before handling actually begins in the
+ * worker thread.
+ *
+ * @param <T> Type of items to be processed.
+ * @param <W> Type of wrapper over processing item that are stored in the underlying queue.
+ */
+abstract class AsyncQueueHandler<T, W extends OperationContextAwareWrapper<T>> extends GridWorker {
+ /** */
+ private final BlockingQueue<W> workerQueue;
+
+ /** */
+ private Thread workerThread;
+
+ /** */
+ protected AsyncQueueHandler(
+ @Nullable String igniteInstanceName,
+ String workerThreadName,
+ IgniteLogger log,
+ @Nullable WorkersRegistry workerReg,
+ BlockingQueue<W> workerQueue
+ ) {
+ super(igniteInstanceName, workerThreadName, log, workerReg);
+
+ this.workerQueue = workerQueue;
+ }
+
+ /** */
+ protected abstract W wrapQueueElement(T delegate, OperationContextSnapshot snapshot);
+
+ /** */
+ protected Thread.UncaughtExceptionHandler uncaughtExceptionHandler() {
+ return null;
+ }
+
+ /** */
+ protected IgniteThread createWorkerThread(GridWorker worker) {
+ return new IgniteThread(igniteInstanceName(), name(), worker, GRP_IDX_UNASSIGNED, -1, GridIoPolicy.UNDEFINED);
Review Comment:
Done.
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "sergey-chugunov-1985 (via GitHub)" <gi...@apache.org>.
sergey-chugunov-1985 commented on code in PR #13148:
URL: https://github.com/apache/ignite/pull/13148#discussion_r3302950279
##########
modules/core/src/main/java/org/apache/ignite/internal/util/worker/queue/AsyncQueueHandler.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.util.worker.queue;
+
+import java.util.Iterator;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.managers.communication.GridIoPolicy;
+import org.apache.ignite.internal.thread.context.OperationContext;
+import org.apache.ignite.internal.thread.context.OperationContextSnapshot;
+import org.apache.ignite.internal.thread.context.function.OperationContextAwareWrapper;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.worker.GridWorker;
+import org.apache.ignite.internal.worker.WorkersRegistry;
+import org.apache.ignite.thread.IgniteThread;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.thread.IgniteThread.GRP_IDX_UNASSIGNED;
+
+/**
+ * Represents a single-threaded, asynchronous queue elements handler. It automatically captures the {@link OperationContext}
+ * attached to the thread that submitted the item for handling and restores it before handling actually begins in the
+ * worker thread.
+ *
+ * @param <T> Type of items to be processed.
+ * @param <W> Type of wrapper over processing item that are stored in the underlying queue.
+ */
+abstract class AsyncQueueHandler<T, W extends OperationContextAwareWrapper<T>> extends GridWorker {
+ /** */
+ private final BlockingQueue<W> workerQueue;
+
+ /** */
+ private Thread workerThread;
+
+ /** */
+ protected AsyncQueueHandler(
+ @Nullable String igniteInstanceName,
+ String workerThreadName,
+ IgniteLogger log,
+ @Nullable WorkersRegistry workerReg,
+ BlockingQueue<W> workerQueue
+ ) {
+ super(igniteInstanceName, workerThreadName, log, workerReg);
+
+ this.workerQueue = workerQueue;
+ }
+
+ /** */
+ protected abstract W wrapQueueElement(T delegate, OperationContextSnapshot snapshot);
+
+ /** */
+ protected Thread.UncaughtExceptionHandler uncaughtExceptionHandler() {
+ return null;
+ }
+
+ /** */
+ protected IgniteThread createWorkerThread(GridWorker worker) {
+ return new IgniteThread(igniteInstanceName(), name(), worker, GRP_IDX_UNASSIGNED, -1, GridIoPolicy.UNDEFINED);
Review Comment:
We could use another IgniteThread constructor with only three arguments. grpIdx, stripe and plc parameters are always the same.
##########
modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java:
##########
@@ -2837,68 +2818,50 @@ public DiscoveryMessageNotifierThread(GridWorker worker) {
}
}
- /**
- *
- */
- private class DiscoveryMessageNotifierWorker extends GridWorker {
- /** Queue. */
- private final BlockingQueue<T2<GridFutureAdapter, Runnable>> queue = new LinkedBlockingQueue<>();
-
- /**
- * Default constructor.
- */
- protected DiscoveryMessageNotifierWorker() {
+ /** */
+ private class DiscoveryMessageNotifier extends IgniteAsyncObjectHandler<T2<GridFutureAdapter<?>, Runnable>> {
+ /** Default constructor. */
+ protected DiscoveryMessageNotifier() {
super(ctx.igniteInstanceName(), "disco-notifier-worker", GridDiscoveryManager.this.log, ctx.workersRegistry());
}
- /**
- *
- */
+ /** {@inheritDoc} */
+ @Override public IgniteThread createWorkerThread(GridWorker worker) {
+ return new DiscoveryMessageNotifierThread(worker);
+ }
+
+ /** */
private void body0() throws InterruptedException {
- T2<GridFutureAdapter, Runnable> notification;
+ OperationContextAwareWrapper<T2<GridFutureAdapter<?>, Runnable>> contextualNotification = takeQueuedElement();
- blockingSectionBegin();
+ try (Scope ignored = OperationContext.restoreSnapshot(contextualNotification.contextSnapshot())) {
+ T2<GridFutureAdapter<?>, Runnable> notification = contextualNotification.delegate();
- try {
- notification = queue.take();
- }
- finally {
- blockingSectionEnd();
- }
-
- try {
- notification.get2().run();
- }
- finally {
- notification.get1().onDone();
+ try {
+ notification.get2().run();
+ }
+ finally {
+ notification.get1().onDone();
+ }
}
}
- /**
- * @param cmd Command.
- */
- public synchronized void submit(GridFutureAdapter notificationFut, Runnable cmd) {
+ /** @param cmd Command. */
+ public synchronized void submit(GridFutureAdapter<?> notificationFut, Runnable cmd) {
if (isCancelled()) {
notificationFut.onDone();
return;
}
- queue.add(new T2<>(notificationFut, cmd));
+ addToQueue(new T2<>(notificationFut, cmd));
}
- /**
- * Cancel thread execution and completes all notification futures.
- */
+ /** Cancel thread execution and completes all notification futures. */
Review Comment:
```suggestion
/** Cancels thread execution and completes all notification futures. */
```
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessor.java:
##########
@@ -190,6 +164,16 @@ public DataStreamerImpl<K, V> dataStreamer(@Nullable String cacheName) {
}
}
+ /** */
+ public void scheduleAutoFlush(DataStreamerImpl<?, ?> dataStreamer) {
Review Comment:
Why two methods exposed through GridKernalContext instead of passing flusher to DataStreamerImpl? Both approaches are not ideal but the last one is less invasive from my point of view.
##########
modules/core/src/main/java/org/apache/ignite/internal/util/worker/queue/AsyncQueueHandler.java:
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.util.worker.queue;
+
+import java.util.Iterator;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.internal.managers.communication.GridIoPolicy;
+import org.apache.ignite.internal.thread.context.OperationContext;
+import org.apache.ignite.internal.thread.context.OperationContextSnapshot;
+import org.apache.ignite.internal.thread.context.function.OperationContextAwareWrapper;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.worker.GridWorker;
+import org.apache.ignite.internal.worker.WorkersRegistry;
+import org.apache.ignite.thread.IgniteThread;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.thread.IgniteThread.GRP_IDX_UNASSIGNED;
+
+/**
+ * Represents a single-threaded, asynchronous queue elements handler. It automatically captures the {@link OperationContext}
+ * attached to the thread that submitted the item for handling and restores it before handling actually begins in the
+ * worker thread.
+ *
+ * @param <T> Type of items to be processed.
+ * @param <W> Type of wrapper over processing item that are stored in the underlying queue.
+ */
+abstract class AsyncQueueHandler<T, W extends OperationContextAwareWrapper<T>> extends GridWorker {
+ /** */
+ private final BlockingQueue<W> workerQueue;
+
+ /** */
+ private Thread workerThread;
+
+ /** */
+ protected AsyncQueueHandler(
+ @Nullable String igniteInstanceName,
+ String workerThreadName,
+ IgniteLogger log,
+ @Nullable WorkersRegistry workerReg,
+ BlockingQueue<W> workerQueue
+ ) {
+ super(igniteInstanceName, workerThreadName, log, workerReg);
+
+ this.workerQueue = workerQueue;
+ }
+
+ /** */
+ protected abstract W wrapQueueElement(T delegate, OperationContextSnapshot snapshot);
+
+ /** */
+ protected Thread.UncaughtExceptionHandler uncaughtExceptionHandler() {
+ return null;
+ }
+
+ /** */
+ protected IgniteThread createWorkerThread(GridWorker worker) {
+ return new IgniteThread(igniteInstanceName(), name(), worker, GRP_IDX_UNASSIGNED, -1, GridIoPolicy.UNDEFINED);
+ }
+
+ /** */
+ @Nullable protected OperationContextAwareWrapper<T> takeQueuedElement() throws InterruptedException {
+ blockingSectionBegin();
+
+ try {
+ return workerQueue.take();
+ }
+ finally {
+ blockingSectionEnd();
+ }
+ }
+
+ /** */
+ @Nullable protected OperationContextAwareWrapper<T> pollQueuedElement(
+ long timeout,
+ @NotNull TimeUnit unit
+ ) throws InterruptedException {
+ blockingSectionBegin();
+
+ try {
+ return workerQueue.poll(timeout, unit);
+ }
+ finally {
+ blockingSectionEnd();
+ }
+ }
+
+ /** */
+ public void start() {
+ synchronized (this) {
+ if (workerThread != null)
+ return;
+
+ workerThread = createWorkerThread(this);
+
+ Thread.UncaughtExceptionHandler errHnd = uncaughtExceptionHandler();
+
+ if (errHnd != null)
+ workerThread.setUncaughtExceptionHandler(errHnd);
+
+ workerThread.start();
+ }
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void cleanup() {
Review Comment:
I guess cleanup method is called as part of node's stop procedure and race with start method is not possible?
By race I mean a situation when the first thread calls start method, the second on calls cleanup and then the third calls start again and reverts the work of the second thread.
If this situation is not possible it is fine to ignore this comment.
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #13148:
URL: https://github.com/apache/ignite/pull/13148#issuecomment-4505467598
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) **Quality Gate failed**
Failed conditions
 [5 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) (required ≤ 1)
<!-- sqra:qg_revision=07dae25ccd767f76ed0ba9bd02ce66f4928d0bc219b779ac2345a92aa64ed66b -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #13148:
URL: https://github.com/apache/ignite/pull/13148#issuecomment-4488021680
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) **Quality Gate failed**
Failed conditions
 [4 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) (required ≤ 1)
<!-- sqra:qg_revision=e206e686bf91e5584af03460677b882d272e6c614f492ab510a7ff7043b9f0f5 -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #13148:
URL: https://github.com/apache/ignite/pull/13148#issuecomment-4505932171
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) **Quality Gate failed**
Failed conditions
 [5 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) (required ≤ 1)
<!-- sqra:qg_revision=07dae25ccd767f76ed0ba9bd02ce66f4928d0bc219b779ac2345a92aa64ed66b -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "petrov-mg (via GitHub)" <gi...@apache.org>.
petrov-mg commented on code in PR #13148:
URL: https://github.com/apache/ignite/pull/13148#discussion_r3304562247
##########
modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java:
##########
@@ -2837,68 +2818,50 @@ public DiscoveryMessageNotifierThread(GridWorker worker) {
}
}
- /**
- *
- */
- private class DiscoveryMessageNotifierWorker extends GridWorker {
- /** Queue. */
- private final BlockingQueue<T2<GridFutureAdapter, Runnable>> queue = new LinkedBlockingQueue<>();
-
- /**
- * Default constructor.
- */
- protected DiscoveryMessageNotifierWorker() {
+ /** */
+ private class DiscoveryMessageNotifier extends IgniteAsyncObjectHandler<T2<GridFutureAdapter<?>, Runnable>> {
+ /** Default constructor. */
+ protected DiscoveryMessageNotifier() {
super(ctx.igniteInstanceName(), "disco-notifier-worker", GridDiscoveryManager.this.log, ctx.workersRegistry());
}
- /**
- *
- */
+ /** {@inheritDoc} */
+ @Override public IgniteThread createWorkerThread(GridWorker worker) {
+ return new DiscoveryMessageNotifierThread(worker);
+ }
+
+ /** */
private void body0() throws InterruptedException {
- T2<GridFutureAdapter, Runnable> notification;
+ OperationContextAwareWrapper<T2<GridFutureAdapter<?>, Runnable>> contextualNotification = takeQueuedElement();
- blockingSectionBegin();
+ try (Scope ignored = OperationContext.restoreSnapshot(contextualNotification.contextSnapshot())) {
+ T2<GridFutureAdapter<?>, Runnable> notification = contextualNotification.delegate();
- try {
- notification = queue.take();
- }
- finally {
- blockingSectionEnd();
- }
-
- try {
- notification.get2().run();
- }
- finally {
- notification.get1().onDone();
+ try {
+ notification.get2().run();
+ }
+ finally {
+ notification.get1().onDone();
+ }
}
}
- /**
- * @param cmd Command.
- */
- public synchronized void submit(GridFutureAdapter notificationFut, Runnable cmd) {
+ /** @param cmd Command. */
+ public synchronized void submit(GridFutureAdapter<?> notificationFut, Runnable cmd) {
if (isCancelled()) {
notificationFut.onDone();
return;
}
- queue.add(new T2<>(notificationFut, cmd));
+ addToQueue(new T2<>(notificationFut, cmd));
}
- /**
- * Cancel thread execution and completes all notification futures.
- */
+ /** Cancel thread execution and completes all notification futures. */
Review Comment:
Done.
##########
modules/core/src/main/java/org/apache/ignite/internal/processors/datastreamer/DataStreamProcessor.java:
##########
@@ -190,6 +164,16 @@ public DataStreamerImpl<K, V> dataStreamer(@Nullable String cacheName) {
}
}
+ /** */
+ public void scheduleAutoFlush(DataStreamerImpl<?, ?> dataStreamer) {
Review Comment:
Done.
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #13148:
URL: https://github.com/apache/ignite/pull/13148#issuecomment-4503072679
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) **Quality Gate failed**
Failed conditions
 [5 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) (required ≤ 1)
<!-- sqra:qg_revision=07dae25ccd767f76ed0ba9bd02ce66f4928d0bc219b779ac2345a92aa64ed66b -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #13148:
URL: https://github.com/apache/ignite/pull/13148#issuecomment-4515392808
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) **Quality Gate failed**
Failed conditions
 [5 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) (required ≤ 1)
<!-- sqra:qg_revision=07dae25ccd767f76ed0ba9bd02ce66f4928d0bc219b779ac2345a92aa64ed66b -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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-28681 Operation Context integrated in Ignite internal async structures [ignite]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #13148:
URL: https://github.com/apache/ignite/pull/13148#issuecomment-4545339596
## [](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) **Quality Gate failed**
Failed conditions
 [24 New Code Smells](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148) (required ≤ 1)
<!-- sqra:qg_revision=646c88985f8ffb947246379aebc620d6a443686216fc4ecf4317faf804713d6f -->
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_ignite&pullRequest=13148)
##
 Catch issues before they fail your Quality Gate with our IDE extension  [SonarQube for IDE](https://www.sonarsource.com/products/sonarlint/features/connected-mode/?referrer=pull-request)
--
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