-
Notifications
You must be signed in to change notification settings - Fork 297
feat(sync-service): SQLite-backed metadata storage #3682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for electric-next ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3682 +/- ##
=======================================
Coverage 87.93% 87.93%
=======================================
Files 23 23
Lines 1898 1898
Branches 499 500 +1
=======================================
Hits 1669 1669
Misses 227 227
Partials 2 2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This comment has been minimized.
This comment has been minimized.
7226bf9 to
891453c
Compare
|
benchmark this |
This comment has been minimized.
This comment has been minimized.
891453c to
3653942
Compare
This comment has been minimized.
This comment has been minimized.
7ecf14d to
3fa21d8
Compare
This comment has been minimized.
This comment has been minimized.
Replace enormous ets tables holding shape lookup information with a single SQLite database. This massively reduces memory usage and removes the need to iterate the storage backend for shape information in the case of an unclean shutdown.
3fa21d8 to
6566a32
Compare
| SELECT handle FROM shapes WHERE comparable = ?1 LIMIT 1 | ||
| """, | ||
| shape_lookup: """ | ||
| SELECT shape FROM shapes WHERE handle = ?1 LIMIT 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we not make handle unique? Otherwise this returns an arbitrary shape. It would also mean you could get rid of the LIMIT 1. Currently we're only unique on the composite (comparable, handle)
| SELECT 1 FROM shapes WHERE handle = ?1 | ||
| """, | ||
| handle_lookup: """ | ||
| SELECT handle FROM shapes WHERE comparable = ?1 LIMIT 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for comparable. This should be unique too
Improves memory usage and actually greatly simplifies the ShapeStatus code as it removes the need for a "restore" path at all, let alone 2 distinct versions based on clean vs unclean shutdown.
The only metadata left in RAM is the LRU information, which is just
{handle, timestamp}.The access is via two NimblePool instances, one for reads which has a "worker" per core and a single write worker which guarantees serialized writes.
Performance locally seems reasonable, though it will be slower since - even if the data is in sqlite's page cache - we're now loading shape data from disk and deserializing using
:erlang.binary_to_term/1.My (hopefully) only controversial move is to add snapshot status information to the shape data so that we can initialize the system and remove any shapes that were left in a half-baked state without querying the storage backend.
I think this is cleaner that the current system, which AFAICT has issues if the system is terminated before a snapshot is started (since the snapshotting requires an active consumer and consumers are now lazily started, meaning that
await_snapshot_start/2will crash or hang).The implications of this are:
I've let claude review and addressed its comments, it's conclusion: