Skip to content

fix: retry failed terminal task status writes during storage sync - #20874

Merged
maytasm merged 4 commits into
apache:masterfrom
agali-09:fix/retry-failed-metadata-updates
Nov 25, 2026
Merged

maytasm merged 4 commits into
apache:masterfrom
agali-09:fix/retry-failed-metadata-updates

Conversation

@agali-09

Copy link
Copy Markdown
Contributor

Description

When a terminal task status cannot be persisted, TaskQueue marks the task complete in memory while metadata still lists it as active. Further completion notifications are ignored, and periodic storage synchronization previously left this mismatch unresolved. This can cause task-list APIs to report finished tasks as active indefinitely.

This PR retries terminal-status writes during syncFromStorage() for tasks completed in memory but still active in metadata.

The retry uses the existing per-task synchronization and persistence checks. Completed entries remain in memory until a subsequent storage snapshot confirms completion, preventing them from being re-added for execution. Retries preserve the original terminal status, duration, error message, and worker location without repeating shutdown or completion metrics.

The persistence logic is extracted into persistTaskStatus(), shared by initial completion notifications and synchronization retries. Failed persistence attempts emit the existing alert and a new task/status/persistFailed/count metric.

Validation

Added regression tests in the existing TaskQueueTest covering failed writes and reads, recovery, lost commit acknowledgements, stale snapshots, preserved completion details and duplicate-run prevention.

Release note

Fixed an issue where completed ingestion tasks could remain listed as active after a metadata-store write failure. The Overlord now retries persisting their terminal statuses during periodic storage synchronization.


Key changed classes in this PR
  • TaskQueue
  • TaskQueueTest

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@FrankChen021 FrankChen021 left a comment

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.

⚪ Review incomplete

PR 20874 currently has a definite merge conflict with master (mergeable=CONFLICTING, mergeStateStatus=DIRTY) at head c260b616b2b4d68eb2f0e43356579b909ca9c17a. Please resolve the conflicts with master and push a new head; review is deferred until then.

Reviewed 0 changed files; no code review was performed because the PR conflicts with master.


This is an automated review by Codex GPT-5.6-Luna(max)

@FrankChen021 FrankChen021 left a comment

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.

🟡 Changes recommended

The terminal-status retry path is correctly synchronized and prevents completed tasks from being rerun. However, the new persistence-failure metric is not registered in the default metric allowlist or emitter mappings, so it is silently unavailable with common configured emitters. Add those registrations before merging.

Reviewed 3 of 3 changed files.

Validation: git diff --check passed. No build or tests were run; this was a static review.

Severity Findings
P0 0
P1 0
P2 1
P3 0
Total 1

This is an automated review by Codex GPT-5.6-Luna(max)

After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.

.emit();
final ServiceMetricEvent.Builder metricBuilder = ServiceMetricEvent.builder();
IndexTaskUtils.setTaskDimensions(metricBuilder, task);
emitter.emit(metricBuilder.setMetric("task/status/persistFailed/count", 1));

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.

[P2] Register the new metric with emitter mappings

Finding: The new task/status/persistFailed/count metric is emitted here, but it is absent from the default logging-emitter allowlist and the default Dropwizard, StatsD, Prometheus, and OpenTSDB metric mappings. With metric filtering enabled or any of those default mapping-based emitters, the event is silently dropped, so operators cannot observe the persistence failures this PR is intended to expose.

Suggestion: Add the metric to each applicable default metric configuration and cover its registration with focused emitter tests.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, done!

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.

Confirmed fixed at head 857dcd9: task/status/persistFailed/count is registered in the default logging allowlist and Dropwizard, StatsD, Prometheus, and OpenTSDB mappings, with focused tests updated. Reviewed 12 of 12 changed files; no remaining actionable issue found.

@agali-09
agali-09 force-pushed the fix/retry-failed-metadata-updates branch from 5bb6cd0 to e9f3adf Compare November 12, 2026 16:46
Resolve TaskQueueTest additions by retaining both status persistence tests and upstream task-count tests.

@FrankChen021 FrankChen021 left a comment

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.

🟢 Approval recommended

The prior P2 is fixed at the reviewed head. The persistence-failure metric is now registered in the logging allowlist and all four default emitter mappings, with focused tests updated.

Follow-up assessment

Reviewed 12 of 12 changed files. No remaining actionable issues found.

Validation: git diff --check a48de36c04ae1f0d8e9c51f87489d52faf2898ef..857dcd99ceb2250ff993f073a0f4fa938d445aaf passed. No build or tests were run; this was a static follow-up review.


This is an automated review by Codex

@FrankChen021 FrankChen021 added the Approval Recommended Used when AI completes a review and reports no findings label Nov 13, 2026

@maytasm maytasm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please see comments

final Collection<TaskInfo> removedTasks = mapDifference.entriesOnlyOnLeft().values();

// Retry failed writes of terminal task statuses for tasks still active in storage.
for (final String taskId : mapDifference.entriesDiffering().keySet()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This retries every completed entry that the snapshot still lists, including tasks whose write succeeded after getActiveTaskInfos() read the DB. For those, persistTaskStatus finds a terminal status and fires the "Ignoring notification for already-complete task" alert. Every completion during the sync window triggers it. Could TaskEntry track whether the persist failed, and retry only those entries without alerting when storage is already terminal?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for (TaskEntry e : activeTasks.values()) {
  if (e.persistFailed && newTasks.containsKey(e.getTask().getId())) {
    // compute() on that id, re-check the flag inside, then retry
  }
}

@agali-09 agali-09 Nov 24, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in the latest commit, PTAL. Retries now track only persistence failures, recheck under the per-task lock, and stop without alerting when storage is already terminal.

@FrankChen021 FrankChen021 left a comment

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.

🟡 Changes recommended

Make completion cleanup independent of persistence-failure reporting before merging. If alert or metric emission throws while reporting a persistence failure, notifyStatus exits before shutting down the runner, releasing task locks, emitting completion metrics, and requesting management. A later storage sync retries persistence but does not retry those cleanup operations.

Reviewed 12 of 12 changed files. The incremental review covered the two files changed since 857dcd99ceb2250ff993f073a0f4fa938d445aaf; the full scope also covered metric documentation, default emitter mappings, and focused tests.

Validation: git diff --check a48de36c04ae1f0d8e9c51f87489d52faf2898ef..6e612863cda7c8add001a1995c1babf00d5661e6 passed. No tests or builds were run; this was a static review.

Severity Findings
P0 0
P1 0
P2 1
P3 0
Total 1

This is an automated review by Codex GPT-5.6-Luna(max)

After addressing the findings or replying to the comments, you can request another review from me to trigger a new automated review.

.emit();
final ServiceMetricEvent.Builder metricBuilder = ServiceMetricEvent.builder();
IndexTaskUtils.setTaskDimensions(metricBuilder, task);
emitter.emit(metricBuilder.setMetric("task/status/persistFailed/count", 1));

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.

[P2] Keep completion cleanup independent of emitter failures

Finding: When persistence fails, the alert emission above or this synchronous metric emission can throw. The exception escapes before notifyStatus reaches shutdownTaskOnRunner, removeTaskLock, emitTaskCompletionLogsAndMetrics, and requestManagement. The retry flag lets a later storage sync persist and remove the completed entry, but those cleanup operations are never retried, leaving runner, lock, and completion-counter state stale.

Suggestion: Make alert and metric reporting best-effort or otherwise guarantee the normal completion cleanup runs after a persistence failure; extend the emitter-failure test to assert runner shutdown, lock release, and completion metrics.

@FrankChen021 FrankChen021 removed the Approval Recommended Used when AI completes a review and reports no findings label Nov 24, 2026
@agali-09
agali-09 requested a review from maytasm November 24, 2026 05:56
@agali-09
agali-09 force-pushed the fix/retry-failed-metadata-updates branch from 6e61286 to ae0c9ef Compare November 24, 2026 06:49

@FrankChen021 FrankChen021 left a comment

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.

🟢 Approval recommended

The prior persistence-reporting issue is fixed. Alert and metric emitter exceptions no longer prevent runner shutdown, lock release, completion accounting, management notification, or later terminal-status retries. The full retry path preserves terminal task state and prevents completed tasks from being rerun.

Reviewed 12 of 12 changed files. The incremental review covered the two files changed since the previous reviewed head; the full scope included metric documentation, emitter registrations, allowlists, and focused tests.

Validation: git diff --check a48de36c04ae1f0d8e9c51f87489d52faf2898ef..ae0c9efd080429e7f4265ce8d6e4c59f0abbf20b passed. No tests or builds were run; this was a static review.


This is an automated review by Codex GPT-5.6-Luna(max)

@FrankChen021 FrankChen021 added the Approval Recommended Used when AI completes a review and reports no findings label Nov 24, 2026

@FrankChen021 FrankChen021 left a comment

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.

🟢 Approval recommended

No actionable issues found in this review. The retry path preserves terminal task state, prevents reruns, and keeps cleanup independent of persistence-reporting failures. The new metric is documented and registered across the default emitters and logging allowlist.

Reviewed 12 of 12 changed files.

Validation: git diff --check a48de36 ae0c9ef passed. No build or tests were run; this was a static review.


This is an automated review by Codex GPT-5.6-Luna(max)

@maytasm
maytasm merged commit 5a5d28b into apache:master Nov 25, 2026
28 checks passed
@github-actions github-actions Bot added this to the 40.0.0 milestone Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants