Conversation
Use advisory locks mechanism provided by ENSDb to ensure that any pending ENSNode Schema migrations are executed exactly once, even if multiple ENSIndexer instances attempt running migrations conurrently.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 6b8c334 The changes in this PR will be included in the next version bump. This PR includes changesets to release 23 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 26 minutes and 43 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Pull request overview
This PR aims to make ENSNode schema migrations execute exactly once when multiple ENSIndexer instances start concurrently, by introducing a PostgreSQL advisory-lock based synchronization mechanism in the ENSDb writer layer.
Changes:
- Added
advisoryLockId()helper to derive a stablebigintadvisory lock ID from a string name. - Added unit tests for
advisoryLockId()determinism and bigint-range behavior. - Updated
EnsDbWriter.migrateEnsNodeSchema()to acquire/release a Postgres advisory lock around Drizzle migrations.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/ensdb-sdk/src/lib/advisory-lock-id.ts | Adds stable hashing helper to produce a Postgres advisory lock key. |
| packages/ensdb-sdk/src/lib/advisory-lock-id.test.ts | Adds deterministic/unit-range tests for the lock key derivation. |
| packages/ensdb-sdk/src/client/ensdb-writer.ts | Wraps ENSNode schema migrations with advisory lock acquisition/release. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Greptile SummaryThis PR fixes a race condition in Confidence Score: 5/5Safe to merge — both previous P1 findings are fully addressed and the implementation is correct The PR correctly uses No files require special attention Important Files Changed
Sequence DiagramsequenceDiagram
participant I1 as ENSIndexer Instance 1
participant I2 as ENSIndexer Instance 2
participant PG as PostgreSQL
I1->>PG: BEGIN TRANSACTION
I1->>PG: SELECT pg_advisory_xact_lock(lockId)
note right of PG: Lock acquired by I1
I2->>PG: BEGIN TRANSACTION
I2->>PG: SELECT pg_advisory_xact_lock(lockId)
note right of PG: I2 blocks — waiting for lock
I1->>PG: migrate(tx, {migrationsSchema: 'ensnode'})
PG-->>I1: migrations applied
I1->>PG: COMMIT (lock auto-released)
note right of PG: I2 unblocks, acquires lock
I2->>PG: migrate(tx, {migrationsSchema: 'ensnode'})
note right of PG: No-op — migrations already applied
I2->>PG: COMMIT (lock auto-released)
Reviews (3): Last reviewed commit: "Apply AI PR feedback" | Re-trigger Greptile |
3586177 to
7358cc0
Compare
|
@greptile review |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use advisory locks mechanism provided by ENSDb to ensure that any pending ENSNode Schema migrations are executed exactly once, even if multiple ENSIndexer instances attempt running migrations conurrently.
Lite PR
Tip: Review docs on the ENSNode PR process
Summary
migrateEnsNodeSchemamethod inEnsDbWriterclass is now race-condition-safe.Why
I noticed that the ENSDb instance in one of hosted ENSNode environments has five records in

ensnode.__drizzle_migrationstable with the samehashcolumn value. It means that each of the five ENSIndexer instances in this ENSNode environment has executed the same pending migration file on the same ENSNode Schema.To prevent any issues with running ENSNode Schema migrations by multiple ENSIndexer instances, we need to apply a locking mechanism so that only one ENSIndexer instance can attempt executing the pending migrations for the ENSNode Schema at a time.
Testing
ensnode.__drizzle_migrationstable for one pending migration file. The lock works 👍Notes for Reviewer (Optional)
Pre-Review Checklist (Blocking)