Skip to content

Start Pipe tasks downstream-first (1.3 backport) - #19483

Open
Caideyipi wants to merge 5 commits into
apache:dev/1.3from
Caideyipi:cp-19455-dev-1.3
Open

Caideyipi wants to merge 5 commits into
apache:dev/1.3from
Caideyipi:cp-19455-dev-1.3

Conversation

@Caideyipi

Copy link
Copy Markdown
Collaborator

Summary

Cherry-pick of Apache IoTDB commit be57cd48a511413a55be9f6d5831e062090a4223 onto dev/1.3, with compatibility adaptations for this branch.

Pipe tasks now start downstream-first: the sink starts before the processor, and the source starts last. If a stage fails during startup, previously started stages are stopped in reverse order.

For a Source -> Processor -> Sink pipeline, the sink and processor are ready before the source can emit data. If processor startup throws after the sink starts, the sink is stopped and the original startup exception is propagated.

Compatibility adaptations

  • Added the localized message constants to the existing UtilMessages classes for both English and Chinese.
  • Adapted the startup rollback regression test to the 1.3 test structure and APIs.
  • Used the Guava executor types available in this branch.

Validation

  • Spotless formatting passed for node-commons and datanode.
  • The focused Maven test run stopped before compilation: Maven could not resolve org.apache.tsfile:tsfile:1.1.5-SNAPSHOT from JitPack (HTTP 403), so no tests ran.

* Fix Pipe startup sequencing

* Fix Pipe subtask test imports

(cherry picked from commit be57cd4)
# Conflicts:
#	iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/PipeDataNodeTask.java
@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review follow-up (reviewed head 05a632785522df3f02585f7197204c7efbf84bb0; final head 847e0598dcbcc607933b262b7a8f7d41e07509cb): the earlier getDisplayTaskID() compatibility issue is fixed in 1302c946. Addressed the worker-starvation finding: first-execution timeouts now log a warning and continue startup rather than dropping queued subtasks; interruptions and actual startup failures still roll back. Validation passed: English and Chinese full-reactor test-compile, PipeSubtaskTest (3 tests), and focused DataNode startup tests (13 tests). The local and remote PR heads both match 847e0598dcbcc607933b262b7a8f7d41e07509cb.

if (e instanceof Error error) {
throw error;
}
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

major iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/agent/task/PipeTaskAgent.java:1070 — startPipeTask swallows start failures so the ConfigNode never learns the task was dropped

When pipeTask.start() throws during a meta push, the new catch drops the region's task and returns, so no TPushPipeMetaRespExceptionMessage is produced (push replies SUCCESS). The CN records no critical exception and keeps the pipe RUNNING while that region's task is gone; PipeHeartbeatParser skips task metas missing on the DN, so replication silently stalls. Previously the exception propagated and the CN stopped the pipe.

Fix: Surface the failure to the ConfigNode: rethrow it (or record the exception in the task meta) instead of returning after the drop, so the CN stops and reports the pipe.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0aeecc1: startPipeTask now rethrows startup failures after rolling back the failed task. Meta-sync handling converts the propagated failure into a TPushPipeMetaRespExceptionMessage, so the ConfigNode receives the failure instead of a success response. Added regression coverage for the returned error. Focused tests passed (16 tests).

// Trigger start() method for each pipe task by parallel stream
final long startTime = System.currentTimeMillis();
runPipeTasks(pipeTasks.values(), PipeTask::start);
runPipeTasks(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/agent/task/PipeTaskAgent.java:746 — First-execution waits now run while the pipe agent write lock is held

startPipe now waits for the sink and processor first executions (up to min(1 min, dn_connection_timeout/6) = 10 s each) and handlePipeMetaChanges runs it under the global pipe write lock. With busy subtask workers these per-region waits serialize over pipe_task_thread_count (5) threads, so meta sync, collectPipeMetaList and STOP/DROP requests hit their lock timeouts.

Fix: Perform the first-execution wait outside the locked meta-change section (or cap the aggregate wait per push) so a starved worker cannot block pipe meta sync and other pipe operations.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0aeecc1: batch and single-pipe meta-sync now start subtasks while holding the metadata write lock, release the lock, and then wait for first execution. Wait failures are returned to the ConfigNode, and the current task is rolled back if it is still registered. First-execution timeouts remain non-fatal. Added regression tests for lock availability and failure reporting; all 16 focused tests passed.

@Caideyipi

Copy link
Copy Markdown
Collaborator Author

Review follow-up for head 847e0598dcbcc607933b262b7a8f7d41e07509cb (updated to 0aeecc1b65fedd93c40fa63ab855de5a317c6d51): addressed the startup-failure and write-lock findings. Startup failures now propagate through meta sync as error responses. First-execution waits run after releasing the metadata write lock; task rollback is guarded against a concurrent replacement. Added regression coverage for failure propagation and lock availability. Validation: Spotless passed; focused PipeTaskAgentTest and PipeDataNodeTaskTest passed (16 tests, 0 failures/errors).

pipeTasksToAwaitFirstExecution = null;
releaseWriteLock();
}
return awaitFirstExecutionAfterMetaChanges(startedPipeTasks, exceptionMessages);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

major iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/agent/task/PipeTaskAgent.java:453 — First-execution waits inside pushPipeMeta can exceed the ConfigNode 2 s sync timeout and stop every pipe

pushPipeMeta now blocks in awaitFirstExecutionAfterMetaChanges (up to 10 s per sink and processor latch) before replying. PipeMetaSyncProcedure's best-effort push waits only 2 s (getRuntimeMetaPushTimeoutInMs); on timeout ConfigNodeProcedureEnv.fillMissingPipePushMetaResponses builds a PIPE_PUSH_META_ERROR without exceptionMessages, so PipeTaskInfo.recordDataNodePushPipeMetaExceptions(respMap, null) marks every pipe STOPPED/isStoppedByRuntimeException and auto-restart repeats the cycle.

Fix: Do not block the push-meta response on first execution: await asynchronously, or bound the aggregate wait well below getRuntimeMetaPushTimeoutInMs() so a slow pipe start cannot time out the periodic meta sync.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in PR #19523, commit 5773071825296d76f432ff4e48b6dc7f1121d7c0. The first-execution wait now uses one shared deadline capped by one-sixth of the metadata-collection heartbeat interval (and the existing first-execution timeout). The ConfigNode meta-push timeout is two-thirds of the same interval, so the aggregate wait stays within one quarter of that timeout. The wait is outside the metadata write lock and deadline expiry remains non-fatal. Added regression coverage; the final focused run passed 124 tests.


private boolean rollbackPipeTaskAfterMetaChange(
final StartedPipeTask startedPipeTask, final Throwable failure) {
acquireWriteLock();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

major iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/agent/task/PipeTaskAgent.java:1155 — Blocking acquireWriteLock() from a pipeExecutor task can deadlock with the write-lock holder waiting on the same executor

rollbackPipeTaskAfterMetaChange runs on a PipeDataNodeTaskAgent.runPipeTasks worker (pipe_task_thread_count threads + bounded queue) and blocks in acquireWriteLock(). A concurrent meta change holds that write lock inside startPipe/stopPipe and blocks in runPipeTasks on future.get(); once all pool threads wait for the lock, the queued start tasks never run and neither side can progress.

Fix: Never take the write lock from pipeExecutor work: queue rollback requests for the meta-change thread, or use tryWriteLock and skip/defer the rollback when the lock is unavailable.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in PR #19523, commit 5773071825296d76f432ff4e48b6dc7f1121d7c0. Executor workers now collect startup-wait failures without acquiring the metadata write lock. The metadata-change thread performs rollback only after the executor tasks complete, avoiding the lock-owner/waiting-worker deadlock. Added regression coverage for the rollback thread and lock behavior.


@Override
public void awaitFirstExecution() {
PipeSinkSubtaskManager.instance().awaitFirstExecution(pipeName, creationTime, sinkSubtaskId);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/stage/PipeTaskSinkStage.java:79 — SubscriptionTaskSinkStage inherits awaitFirstExecution that queries the wrong subtask manager

SubscriptionTaskSinkStage overrides start/stop/deregister to SubscriptionSinkSubtaskManager but not awaitFirstExecution, so the inherited PipeTaskSinkStage.awaitFirstExecution looks sinkSubtaskId up in PipeSinkSubtaskManager and throws PipeException("No such subtask"). PipeDataNodeTask.awaitFirstExecution then stops all stages and PipeTaskAgent drops the task, failing the pipe start. Latent while SubscriptionConfig.getSubscriptionEnabled() returns false in dev/1.3.

Fix: Override awaitFirstExecution in SubscriptionTaskSinkStage (adding the matching await to SubscriptionSinkSubtaskManager), or route the base method through an overridable subtask-manager accessor.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in PR #19523, commit 5773071825296d76f432ff4e48b6dc7f1121d7c0. SubscriptionTaskSinkStage now routes awaitFirstExecution through SubscriptionSinkSubtaskManager, and the manager waits without holding its monitor. Added a regression test verifying the subscription stage waits on its registered lifecycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants