Skip to content

fix(task): preserve caller tx on cancel - #3340

Open
imbajin wants to merge 1 commit into
apache:masterfrom
hugegraph:fix/task-caller-transaction
Open

imbajin wants to merge 1 commit into
apache:masterfrom
hugegraph:fix/task-caller-transaction

Conversation

@imbajin

@imbajin imbajin commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Purpose of the PR

Cancelling a task can close the caller thread's existing graph transaction and discard unrelated, uncommitted graph changes. The default completion callback can do the same when cancellation invokes it on the caller thread.

This independently fixes the caller transaction issue tracked in the loading-mode review.

Main Changes

Preserve an existing caller transaction during Standard and Distributed scheduler cancellation, and let cancelled tasks leave worker cleanup to their execution path. Keep normal worker completion and task ownership fencing in place.

Before: write uncommitted data → cancel another task → that data is rolled back.
After: write uncommitted data → cancel another task → the caller can still commit or roll back its own data.

Document transaction ownership in docs/server-runtime.md. Update the missing-retry test fixture to provide the transaction interface that cancellation now inspects.

Verifying these changes

  • Trivial rework / code cleanup without any test coverage. (No Need)
  • Already covered by existing tests.
  • Need tests and can be verified as follows:
    • Real graph transactions reproduce the loss with the original code and preserve caller data after queued, running, completed, direct and failed cancellation. Separate worker controls verify cleanup and owner fencing.
    • Relevant tests, formatting and root compilation passed. The full unit suite passed with the canonical snapshot test fixture from #3339; production classes were unchanged by that test-only overlay, and existing environment assumptions remain.
    • Three independent reviewers checked the final change. Current org/ASF CI will be verified on the submitted head.

Does this PR potentially affect the following parts?

  • Dependencies (add/update license info)
  • Modify configurations
  • The public API
  • Other affects: task cancellation and thread-local transaction ownership
  • Nope

Documentation Status

  • Doc - TODO: required documentation is pending; complete it before merging.
  • Doc - Done: documentation is included here or linked below.
  • Doc - No Need: no user-visible documentation is affected.

Documentation files in this PR or paired hugegraph-doc PR: docs/server-runtime.md.

Paired source PR: hugegraph#311

Preserve caller transactions during cancellation.
Keep worker cleanup in its execution path.
Cover direct and failed cancellation with real tests.
Document transaction ownership and fix the fixture.
@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.01%. Comparing base (92af2f8) to head (0bff7ee).

Files with missing lines Patch % Lines
...pache/hugegraph/task/DistributedTaskScheduler.java 70.00% 3 Missing ⚠️
...n/java/org/apache/hugegraph/task/TaskCallable.java 50.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3340      +/-   ##
============================================
+ Coverage     54.31%   57.01%   +2.70%     
+ Complexity     2250      499    -1751     
============================================
  Files           770      514     -256     
  Lines         67952    49740   -18212     
  Branches       9213     7206    -2007     
============================================
- Hits          36905    28360    -8545     
+ Misses        27470    18480    -8990     
+ Partials       3577     2900     -677     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant