Skip to content

[go, js] refresh periodic schedules after commit - #1540

Merged
bgentry merged 1 commit into
masterfrom
bg/periodic-keep-alive-after-commit
Oct 25, 2026
Merged

bgentry merged 1 commit into
masterfrom
bg/periodic-keep-alive-after-commit

Conversation

@bgentry

@bgentry bgentry commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Every ten minutes, the leader refreshes the saved rows of its durable periodic jobs. At startup, it skips a row that has expired but is not reaped yet. It computes a new next run time and writes it in a transaction. If that transaction rolls back, keep-alive still refreshes the expired row. The row keeps its old next run time but looks current. The next leader loads it and enqueues every run since that time.

This change refreshes a row only after its next run time is loaded at startup or committed. Each registration carries a flag for this. The flag clears when a job is added and when leadership starts. A commit that finishes after its job is replaced, or after leadership changes, does not set it. When no job qualifies, keep-alive still runs with an empty ID list, so expired rows are still reaped.

Go and JS get the same fix and equivalent tests. The tests cover a blocked startup, failed begin, upsert and commit, a later successful write, a restart, and a job replaced during commit. A Go test also runs a batch through a real transaction to show that a rollback leaves the job ineligible.

@bgentry
bgentry force-pushed the bg/periodic-keep-alive-after-commit branch 3 times, most recently from 25e6ad9 to a468d0f Compare October 25, 2026 05:56
Every ten minutes, the leader refreshes the saved rows of its durable
periodic jobs. Startup skips a row that has expired but is not reaped
yet. The leader computes a new next run time and writes it in a
transaction. If that transaction rolls back, keep-alive still refreshes
the expired row. The row keeps its old next run time but looks current.
The next leader loads it and enqueues every run since that time.

Refresh a row only after its next run time is loaded at startup or
committed. Track this with a flag on each registration. Clear the flag
when a job is added and when leadership starts. Ignore a commit that
finishes after its job is replaced or after leadership changes. Call
keep-alive with an empty ID list when no job qualifies, so expired rows
are still reaped.

Add tests for a blocked startup, failed transactions, a later
successful write, a restart, and a job replaced during commit. A Go
test runs a batch through a real transaction to show that a rollback
leaves the job ineligible.
@bgentry
bgentry force-pushed the bg/periodic-keep-alive-after-commit branch from 0e6410f to 91e31b3 Compare October 25, 2026 21:40
@bgentry
bgentry marked this pull request as ready for review October 25, 2026 21:45
@bgentry
bgentry merged commit 21ec5ea into master Oct 25, 2026
37 checks passed
@bgentry
bgentry deleted the bg/periodic-keep-alive-after-commit branch October 25, 2026 21:51
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