Skip to content

feat(storage): record which lock owner may write a subscription's progress - #29

Merged
yordis merged 5 commits into
yordis/fix-subscription-stale-lock-noticefrom
yordis/feat-subscription-lock-generation
Oct 23, 2026
Merged

yordis merged 5 commits into
yordis/fix-subscription-stale-lock-noticefrom
yordis/feat-subscription-lock-generation

Conversation

@yordis

@yordis yordis commented Oct 21, 2026 •

Copy link
Copy Markdown
Member
  • The advisory lock decides who runs a subscription, but nothing in the database records who may write its progress, so a node that lost the lock without knowing yet can still overwrite the position of the node that took over.
  • Recording a lock generation on the subscription row when the lock is acquired gives every progress write something to be checked against, and returns the committed position under the same lock so the new owner resumes from where the last owner actually got to rather than from a value read before the lock was held.
  • The database must be migrated before nodes running this version start, as described in the upgrade guide.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@cursor

cursor Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

PR Summary

High Risk
Changes subscription ownership and progress semantics with a required DB migration; incorrect rollout or fencing integration could corrupt subscription positions in multi-node deployments.

Overview
Adds subscription lock claiming so acquiring a subscription advisory lock also bumps lock_generation on the subscription row and returns a lease (FencingToken, committed last_seen, session) for fencing progress writes.

try_subscription_lock/3 on EventStore.AdvisoryLocks wraps storage claim_subscription_lock with the same monitor/release semantics as generic advisory locks. New types: FencingToken, Storage.Lock.Lease, and AdvisoryLocks.Lease.

Schema 1.5.0 adds subscriptions.lock_generation (default 0) via migration and fresh installs; operators must migrate before rolling out this version. A compatibility test confirms pre-1.5 nodes still ack and lock against the new column.

Reviewed by Cursor Bugbot for commit e86d30e. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0db78949-1f61-4459-b3e0-33a052d576df

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@yordis
yordis added this pull request to stack #32 October 21, 2026 00:25
@yordis
yordis force-pushed the yordis/feat-subscription-lock-generation branch from be51aff to b739ba1 Compare October 21, 2026 00:45

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b739ba1. Configure here.

Comment thread lib/event_store/storage/lock.ex
@yordis
yordis force-pushed the yordis/feat-subscription-lock-generation branch from 65dbd78 to fe09d3d Compare October 21, 2026 09:06
@yordis
yordis force-pushed the yordis/feat-subscription-lock-generation branch from fe09d3d to e86d30e Compare October 22, 2026 15:12
@yordis
yordis force-pushed the yordis/feat-subscription-lock-generation branch 2 times, most recently from 1bb32ab to 915c3fe Compare October 23, 2026 07:36
@yordis
yordis force-pushed the yordis/feat-subscription-lock-generation branch from 915c3fe to 86cd193 Compare October 23, 2026 09:58
…y write their progress

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…gress

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…t the migrated schema

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…eaves the subscription unclaimable

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
…ng it

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis
yordis force-pushed the yordis/feat-subscription-lock-generation branch from 86cd193 to 8485fad Compare October 23, 2026 20:11
@yordis
yordis merged commit c72996b into yordis/fix-advisory-lock-checkout-hang Oct 23, 2026
11 checks passed
@yordis
yordis deleted the yordis/feat-subscription-lock-generation branch October 23, 2026 20:41
yordis added a commit that referenced this pull request Oct 24, 2026
…gress (#29)

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
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