Skip to content

refactor(server): close retained graphs on shutdown - #3347

Merged
imbajin merged 2 commits into
apache:masterfrom
hugegraph:fix/shutdown-retained-cleanup
Oct 14, 2026
Merged

imbajin merged 2 commits into
apache:masterfrom
hugegraph:fix/shutdown-retained-cleanup

Conversation

@imbajin

@imbajin imbajin commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Purpose of the PR

A background task can outlive both Gremlin and REST graph-close attempts during Server shutdown. Previously, shutdown then stopped the task database worker while the graph and its transaction were still retained. This follows up on the shutdown lifecycle review and ASF #3302.

Org staging PR: hugegraph#316.

Main Changes

After task workers drain, retry retained graph closes through the existing scheduler registry before stopping task database and event workers. Treat an already terminated cron executor as a completed dispatch barrier. Each executor wait checks actual termination on explicit retry; a failed or interrupted wait stops the later shutdown stages.

A graph-close failure still attempts cleanup of other graphs and leaves the task database executor available for an explicit retry. Store-close notifications finish before the shared event executor stops.

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:
    • Reproduced the missing final close through HugeGraphServer.stop() before the fix. The regression now verifies task completion persistence, retained graph and scheduler closure, task database owner release, and store-close event delivery.
    • Added real distributed-scheduler shutdown coverage and bounded timeout/interruption retry tests for the task database, ephemeral, schema and OLAP executors.
    • Passed HugeFactoryTest, StandardTaskAdmissionTest and DistributedTaskAdmissionTest, mvn editorconfig:format, root mvn clean compile -Dmaven.javadoc.skip=true, and git diff --check.

Does this PR potentially affect the following parts?

  • Dependencies
  • Modify configurations
  • The public API
  • Other affects: Server shutdown lifecycle.
  • 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: docs/server-runtime.md.

Conceptual overview

Retained graph cleanup before task DB and event shutdown, including the remaining cancellation callback limitation

Conceptual diagram; not runtime test evidence. The remaining cancellation-callback limitation is documented in the follow-up review.

- retry retained graph closes before task DB shutdown
- preserve event delivery until cleanup completes
- cover pending tasks and explicit close retries
- treat terminated cron as a completed dispatch barrier
- preserve ordered waits on explicit shutdown retries
- cover distributed owner and interrupted timeout retries
@codecov

codecov Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 72.34043% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.21%. Comparing base (92af2f8) to head (bd1894f).
⚠️ Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
...pache/hugegraph/task/DistributedTaskScheduler.java 44.44% 10 Missing ⚠️
...in/java/org/apache/hugegraph/task/TaskManager.java 89.28% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3347      +/-   ##
============================================
+ Coverage     54.31%   57.21%   +2.90%     
+ Complexity     2250      130    -2120     
============================================
  Files           770      514     -256     
  Lines         67952    49733   -18219     
  Branches       9213     7206    -2007     
============================================
- Hits          36905    28454    -8451     
+ Misses        27470    18405    -9065     
+ Partials       3577     2874     -703     
Flag Coverage Δ
hstore 35.58% <8.51%> (?)
server_memory 51.69% <72.34%> (?)
server_rocksdb 42.23% <34.04%> (?)

☔ 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.

@imbajin imbajin changed the title fix(server): close retained graphs on shutdown refactor(server): close retained graphs on shutdown Oct 14, 2026
@imbajin
imbajin merged commit e4934c2 into apache:master Oct 14, 2026
19 checks passed
@imbajin

imbajin commented Oct 14, 2026

Copy link
Copy Markdown
Member Author

[P2] Final distributed close can lose its cancellation executor

If a busy cron operation makes both early graph-close attempts time out while a schema/OLAP task is still active, the final close still needs to cancel that task. However, TaskManager.close() has already terminated distributedSchedulerExecutor. DistributedTaskScheduler.close() passes the terminated barrier, then cancelOwned() submits cancellation back to that executor and gets RejectedExecutionException before interrupting the task. An explicit retry repeats this until the task finishes independently.

Please keep a valid path for these owned cancellation callbacks during final graph cleanup, while retaining the task DB executor until owner release. Add a delayed-cron-barrier + active interruptible schema/OLAP worker regression. A Java 17 extracted-method/latch probe reproduced two rejected retries and recovery after external task completion; this is a remaining recovery gap, not a new regression or evidence of data loss.

Score for reviewed head: 8.0/10.

@imbajin
imbajin deleted the fix/shutdown-retained-cleanup branch October 14, 2026 20:15
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