Skip to content

fix(storage): Keep TTL's run state across restarts and failovers - #5073

Merged
colinbarry merged 12 commits into
masterfrom
fix/ttl-intent-across-restart
Nov 19, 2026
Merged

colinbarry merged 12 commits into
masterfrom
fix/ttl-intent-across-restart

Conversation

@colinbarry

Copy link
Copy Markdown
Contributor

A TTL that was running came back paused after a restart that recovered from the exit snapshot, and stayed paused until it was enabled again. Shutdown stops the TTL job before the exit snapshot records whether TTL runs, so the snapshot always recorded it as stopped. Promotion to MAIN had the opposite problem: it resumed every TTL, undoing STOP TTL on failover.

TTL now keeps whether it was asked to run separately from the state of its background job. ENABLE TTL and STOP TTL set it, the snapshot records it, demotion pauses the job without changing it, and promotion resumes only the TTLs that should run.

@colinbarry colinbarry added bug bug CI -build=release -test=core Run release build and core tests on push CI -build=release -test=e2e Run release build and e2e tests on push CI -build=release -test=unit labels Oct 9, 2026
@colinbarry colinbarry self-assigned this Oct 9, 2026
@colinbarry

colinbarry commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Tracking

Standard development

  • Update unit/E2E tests
  • Compare the benchmarking results between the master branch this branch
    • Not applicable: TTL run state only; no query path changes.

CI Testing Labels

  • Select the appropriate CI test labels (CI -build=build-name -test=test-suite)

Kubernetes operator / Helm charts

Does this change affect how Memgraph is deployed or configured on Kubernetes? It likely does if it adds, removes or renames a flag; changes run-time or startup settings; touches the license, AWS settings, coordinators, replication, TLS, monitoring or another enterprise feature.

  • No, the operator and Helm charts are unaffected
  • Yes, and I opened the matching PRs:
    • [ Operator PR link memgraph/kubernetes-operator#XXXX ]
    • [ Helm charts PR link memgraph/helm-charts#XXXX ]

Documentation checklist

  • Add the documentation label
  • Add the bug / feature label
  • Add the milestone for which this feature is intended
    • If not known, set for a later milestone
  • Write a release note, including added/changed clauses
    • TTL now keeps its running or stopped state across restarts and failovers; BREAKING: after upgrading, run ENABLE TTL on MAIN for each database where TTL should run. #5073
  • [ Documentation PR link fix(storage): Keep TTL's run state across restarts and failovers documentation#1908 ]
    • Is back linked to this development PR

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

This PR has potential conflicts with the following other open pull requests which modify the same files:

@sonarqubecloud

sonarqubecloud Bot commented Oct 9, 2026

Copy link
Copy Markdown

@colinbarry colinbarry added this to the mg-v3.15.0 milestone Oct 9, 2026
@colinbarry
colinbarry force-pushed the fix/ttl-intent-across-restart branch 2 times, most recently from 4a80474 to e0c1926 Compare November 10, 2026 12:39
@colinbarry colinbarry added the Docs needed Docs needed label Nov 10, 2026
@github-actions

github-actions Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Release note advisory resolved

Release note: TTL now keeps its running or stopped state across restarts and failovers; **BREAKING**: after upgrading, run `ENABLE TTL` on MAIN for each database where TTL should run. [#5073](https://github.com/memgraph/memgraph/pull/5073)

@internal-review-service-bot internal-review-service-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated review by the Memgraph review service

Verdict: APPROVE WITH NON-BLOCKING
Findings: 0 blocker, 2 non-blocking, 3 nit (3 inline)

Findings outside the diff

  • src/storage/v2/disk/storage.hpp:459-463

    [Nit] Disk StartTtl ignores repl_args

    Always calls Resume() regardless of role. Safe (the user_check_ gate prevents replica writes) but diverges from the documented contract.

  • src/storage/v2/durability/snapshot.cpp:8081

    [Nit] Snapshot load un-pauses the worker on replica recovery

    (and 6 other load blocks). ttl->Resume() runs during recovery even when the instance is a replica. Functionally inert (deny-default user_check_ is installed before recovery), but the scheduler ticks uselessly.

Comment thread src/storage/v2/durability/snapshot.cpp Resolved
Comment thread src/storage/v2/ttl.hpp Resolved
Comment thread src/storage/v2/ttl.hpp Resolved
@colinbarry

Copy link
Copy Markdown
Contributor Author

Re the two findings outside the diff:

  • Disk StartTtl ignoring repl_args: the only caller that passes is_main = false is the in-memory replication handler, so disk storage never sees a replica call. Unchanged by this PR.
  • Snapshot load resuming the scheduler on a replica: inert, because the deny-all user check is installed before recovery and the MAIN-only check after it. Keeping it paused would mean recovery records intent only and startup resumes TTL on MAIN, which is a wider change than this PR needs. No change.

A TTL that was running came back paused after a restart from the exit
snapshot, because shutdown stops the TTL job before the snapshot records
whether it runs. Promotion to MAIN also resumed every TTL, undoing STOP
TTL. TTL now keeps whether it was asked to run apart from its job's
state: the snapshot records that, demotion pauses the job without
changing it, and promotion resumes only the TTLs that should run.
Promotion read whether TTL should run and then resumed it, so a STOP TTL in between was undone. Pause, Resume, and ResumeIfWanted now hold one mutex, so each reads or sets the flag and pauses or resumes TTL as one step.
@colinbarry colinbarry added CI -build=community -test=core Run community build and core tests on push CI -build=coverage -test=core Run coverage build and core tests on push labels Nov 19, 2026
@colinbarry colinbarry added CI -build=coverage -test=clang_tidy CI -build=debug -test=core Run debug build and core tests on push CI -build=debug -test=integration Run debug build and integration tests on push labels Nov 19, 2026
@colinbarry
colinbarry force-pushed the fix/ttl-intent-across-restart branch from a7c18e7 to 5dbd5d7 Compare November 19, 2026 09:56
@colinbarry
colinbarry marked this pull request as ready for review November 19, 2026 10:01

@andrejtonev andrejtonev 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.

LGTM — wanted flag verified across restart, failover, replicated ENABLE/STOP and the STOP-vs-promotion race; mutation-tested the new e2e tests, all three catch a regression.

Test gap: nothing covers a replicated STOP TTL or DISABLE TTL followed by promotion.

Comment thread src/storage/v2/durability/snapshot.cpp Resolved
…pshot

A replica keeps its TTL scheduler alive while paused, so loading a snapshot from MAIN called Configure on a running scheduler and threw "TTL already running!". The replica was left without data and MAIN retried forever. The snapshot loaders now configure TTL only when it isn't running, as WAL recovery already does.
@colinbarry
colinbarry enabled auto-merge November 19, 2026 16:21
@colinbarry
colinbarry added this pull request to the merge queue Nov 19, 2026
Merged via the queue into master with commit 85b7331 Nov 19, 2026
35 checks passed
@colinbarry
colinbarry deleted the fix/ttl-intent-across-restart branch November 19, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking bug bug CI -build=community -test=core Run community build and core tests on push CI -build=coverage -test=clang_tidy CI -build=coverage -test=core Run coverage build and core tests on push CI -build=debug -test=core Run debug build and core tests on push CI -build=debug -test=integration Run debug build and integration tests on push CI -build=release -test=core Run release build and core tests on push CI -build=release -test=e2e Run release build and e2e tests on push CI -build=release -test=unit Docs needed Docs needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants