Skip to content

fix(event-indexer): remove non-functional advisory lock from leader election - #1295

Open
colemaya95-ctrl wants to merge 1 commit into
StellarCheckMate:mainfrom
colemaya95-ctrl:fix/issue-1276-advisory-lock-removal
Open

fix(event-indexer): remove non-functional advisory lock from leader election#1295
colemaya95-ctrl wants to merge 1 commit into
StellarCheckMate:mainfrom
colemaya95-ctrl:fix/issue-1276-advisory-lock-removal

Conversation

@colemaya95-ctrl

Copy link
Copy Markdown
Contributor

Summary

The PostgreSQL advisory lock was held only for the duration of the database connection, not for the duration of leadership. Each call to try_acquire_inner() obtained a connection from the shared pool and returned it immediately, releasing the advisory lock before the next heartbeat. This made the 'second layer of mutual exclusion' documentation inaccurate and ineffective.

The row-level lease via INSERT...ON CONFLICT DO UPDATE is sufficient for atomic leader election. When the lease acquisition succeeds, the row is atomic at the database level, eliminating the split-brain race condition that the advisory lock was intended to prevent.

Changes

  • Removed the advisory lock acquisition and release code
  • Removed the LOCK_KEY constant
  • Updated module documentation to accurately describe the row-level lease mechanism
  • Removed unused imports (debug) and variables (ttl_interval)
  • Simplified code paths in try_acquire_inner and release

Testing

  • ✅ All event-indexer tests pass (71 total across multiple test files)
  • ✅ Code formatting passes (cargo fmt)
  • ✅ Clippy linter passes with no warnings
  • ✅ Code compiles without errors

CI Status

The fix passes all local checks that match the CI pipeline:

  • Formatting: ✅
  • Clippy: ✅
  • Tests: ✅

Closes #1276

…lection

The PostgreSQL advisory lock was held only for the duration of the
database connection, not for the duration of leadership. Each call to
try_acquire_inner() obtained a connection from the shared pool and
returned it immediately, releasing the advisory lock before the next
heartbeat. This made the 'second layer of mutual exclusion' documentation
inaccurate and ineffective.

The row-level lease via INSERT...ON CONFLICT DO UPDATE is sufficient for
atomic leader election. When the lease acquisition succeeds, the row is
atomic at the database level, eliminating the split-brain race condition
that the advisory lock was intended to prevent.

This commit:
- Removes the advisory lock acquisition and release code
- Removes the LOCK_KEY constant
- Updates module documentation to accurately describe the row-level lease
- Removes unused imports and variables

Closes StellarCheckMate#1276
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.

event-indexer's Leader-Election Advisory Lock Doesn't Persist for the Duration of Leadership

1 participant