Re: [PR] [Pipe] Fix processor worker starvation on pipe stop [iotdb]
jt2594838 merged PR #18396: URL: https://github.com/apache/iotdb/pull/18396 -- 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]
Re: [PR] [Pipe] Fix processor worker starvation on pipe stop [iotdb]
Caideyipi commented on code in PR #18396:
URL: https://github.com/apache/iotdb/pull/18396#discussion_r3734811379
##
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/PipeTsFileInsertionEvent.java:
##
@@ -868,6 +902,24 @@ private void consumeParsedTabletInsertionEventWithRetry(
}
}
+ private void sleepForParserRetry(
+ final long sleepTimeInMs, final PipeProcessorSubtaskExecutionGuard
processorExecutionGuard)
+ throws InterruptedException {
+if (!processorExecutionGuard.isEnabled()) {
+ Thread.sleep(sleepTimeInMs);
+ return;
+}
+
+final long deadlineInMs = System.currentTimeMillis() + sleepTimeInMs;
+long remainingTimeInMs = sleepTimeInMs;
+while (remainingTimeInMs > 0) {
+ processorExecutionGuard.check();
+ Thread.sleep(Math.min(remainingTimeInMs, 100));
+ processorExecutionGuard.check();
+ remainingTimeInMs = deadlineInMs - System.currentTimeMillis();
+}
Review Comment:
The guard currently has no registered-thread facility; its 100 ms polling
interval bounds stop latency while keeping the guard usable across the existing
worker and parser call paths. Registering and interrupting sleeping threads
would require a broader guard lifecycle change, so I am leaving that as a
separate optimization.
--
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]
Re: [PR] [Pipe] Fix processor worker starvation on pipe stop [iotdb]
Caideyipi commented on code in PR #18396:
URL: https://github.com/apache/iotdb/pull/18396#discussion_r3734760725
##
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/subtask/processor/PipeProcessorSubtaskYieldException.java:
##
@@ -0,0 +1,53 @@
+/*
+ * 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.iotdb.db.pipe.agent.task.subtask.processor;
+
+/** Internal control-flow exception that immediately yields the current
processor worker. */
+public final class PipeProcessorSubtaskYieldException extends RuntimeException
{
+
+ private static final PipeProcessorSubtaskYieldException
PAUSE_REQUESTED_INSTANCE =
+ new PipeProcessorSubtaskYieldException(Reason.PAUSE_REQUESTED);
+ private static final PipeProcessorSubtaskYieldException
PARSER_NOT_ADMITTED_INSTANCE =
+ new PipeProcessorSubtaskYieldException(Reason.PARSER_NOT_ADMITTED);
Review Comment:
Yes, the static instances are intentional control-flow sentinels. They
disable stack-trace creation because these exceptions are expected pause/yield
signals rather than failures; the Reason enum identifies the requested action.
A per-throw stack would add allocation cost without diagnostic value.
##
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/subtask/processor/PipeProcessorSubtask.java:
##
@@ -241,13 +263,20 @@ protected boolean executeOnce() throws Exception {
.enrichWithCommitterKeyAndCommitId((EnrichedEvent) event,
creationTime, regionId);
}
decreaseReferenceCountAndReleaseLastEvent(event, shouldReport);
+} catch (final PipeProcessorSubtaskYieldException e) {
+ isResumingFromYield.set(true);
+ throw e;
} catch (final PipeRuntimeOutOfMemoryCriticalException e) {
PipeLogger.log(
LOGGER::info,
DataNodePipeMessages.TEMPORARILY_OUT_OF_MEMORY_IN_PIPE_EVENT_PROCESSING,
e.getMessage());
return false;
} catch (final Exception e) {
+ if (ExceptionUtils.getRootCause(e) instanceof
PipeProcessorSubtaskYieldException) {
+isResumingFromYield.set(true);
+throw (PipeProcessorSubtaskYieldException)
ExceptionUtils.getRootCause(e);
+ }
if (ExceptionUtils.getRootCause(e) instanceof
PipeRuntimeOutOfMemoryCriticalException) {
Review Comment:
Addressed in 29513e2595a: the exception root cause is now computed once and
reused for both control-flow checks, avoiding repeated traversal.
--
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]
Re: [PR] [Pipe] Fix processor worker starvation on pipe stop [iotdb]
jt2594838 commented on code in PR #18396:
URL: https://github.com/apache/iotdb/pull/18396#discussion_r3717697666
##
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/subtask/processor/PipeProcessorSubtaskYieldException.java:
##
@@ -0,0 +1,53 @@
+/*
+ * 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.iotdb.db.pipe.agent.task.subtask.processor;
+
+/** Internal control-flow exception that immediately yields the current
processor worker. */
+public final class PipeProcessorSubtaskYieldException extends RuntimeException
{
+
+ private static final PipeProcessorSubtaskYieldException
PAUSE_REQUESTED_INSTANCE =
+ new PipeProcessorSubtaskYieldException(Reason.PAUSE_REQUESTED);
+ private static final PipeProcessorSubtaskYieldException
PARSER_NOT_ADMITTED_INSTANCE =
+ new PipeProcessorSubtaskYieldException(Reason.PARSER_NOT_ADMITTED);
Review Comment:
Creating a static exception instance may miss the actual stack traces.
Is it expected?
##
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/event/common/tsfile/PipeTsFileInsertionEvent.java:
##
@@ -868,6 +902,24 @@ private void consumeParsedTabletInsertionEventWithRetry(
}
}
+ private void sleepForParserRetry(
+ final long sleepTimeInMs, final PipeProcessorSubtaskExecutionGuard
processorExecutionGuard)
+ throws InterruptedException {
+if (!processorExecutionGuard.isEnabled()) {
+ Thread.sleep(sleepTimeInMs);
+ return;
+}
+
+final long deadlineInMs = System.currentTimeMillis() + sleepTimeInMs;
+long remainingTimeInMs = sleepTimeInMs;
+while (remainingTimeInMs > 0) {
+ processorExecutionGuard.check();
+ Thread.sleep(Math.min(remainingTimeInMs, 100));
+ processorExecutionGuard.check();
+ remainingTimeInMs = deadlineInMs - System.currentTimeMillis();
+}
Review Comment:
Is it possible to register this thread with the guard and let it interrupt
registered threads when the epoch changes?
Frequent sleep-and-wake may reduce performance.
##
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/subtask/processor/PipeProcessorSubtask.java:
##
@@ -241,13 +263,20 @@ protected boolean executeOnce() throws Exception {
.enrichWithCommitterKeyAndCommitId((EnrichedEvent) event,
creationTime, regionId);
}
decreaseReferenceCountAndReleaseLastEvent(event, shouldReport);
+} catch (final PipeProcessorSubtaskYieldException e) {
+ isResumingFromYield.set(true);
+ throw e;
} catch (final PipeRuntimeOutOfMemoryCriticalException e) {
PipeLogger.log(
LOGGER::info,
DataNodePipeMessages.TEMPORARILY_OUT_OF_MEMORY_IN_PIPE_EVENT_PROCESSING,
e.getMessage());
return false;
} catch (final Exception e) {
+ if (ExceptionUtils.getRootCause(e) instanceof
PipeProcessorSubtaskYieldException) {
+isResumingFromYield.set(true);
+throw (PipeProcessorSubtaskYieldException)
ExceptionUtils.getRootCause(e);
+ }
if (ExceptionUtils.getRootCause(e) instanceof
PipeRuntimeOutOfMemoryCriticalException) {
Review Comment:
No need to call getRootCause multiple times.
--
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]
