Repository navigation
feat(gc): Implement SQLite-backed GcStorage #653
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
Changes from all commits
7dbb16c
296786a
e9f46ff
d8207ac
20935a3
b2e54d4
b1b0db6
3a21138
282c346
ff77829
f95fc6a
3ac0f5f
ee81ab4
1fe4d59
7e221a8
5a7f734
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] You could add an |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| CREATE TABLE IF NOT EXISTS garbage_collector ( | ||
| object_id TEXT NOT NULL PRIMARY KEY, | ||
| expires_at INTEGER, | ||
|
lcian marked this conversation as resolved.
Resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would likely be useful to add an index on |
||
| created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP | ||
| ); | ||
|
|
||
| CREATE INDEX idx_garbage_collector_expires_at | ||
| ON garbage_collector (expires_at); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| fn main() { | ||
| println!("cargo:rerun-if-changed=migrations"); | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build script watches wrong migrations pathMedium Severity
Reviewed by Cursor Bugbot for commit 5a7f734. Configure here. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| //! Persistence of object expiration metadata, read by the garbage collector to | ||
| //! find objects whose lifetime has elapsed. | ||
| //! | ||
| //! [`GcStorage`] is the backend-agnostic interface. Implementations record the | ||
| //! expiration of each object when it is written and hand back the expired ids | ||
| //! that the collector is allowed to delete. | ||
|
|
||
| /// [`GcStorage`] implementation backed by SQLite. | ||
| pub mod sqlite; | ||
|
|
||
| use std::fmt::Debug; | ||
|
|
||
| use objectstore_types::time::Timestamp; | ||
|
|
||
| use crate::change_stream::ChangeStreamError; | ||
| use crate::id::ObjectId; | ||
|
|
||
| /// Stores object expiration metadata for the garbage collector. | ||
| /// | ||
| /// Implementations are called on the write path (via [`upsert`](Self::upsert) | ||
| /// and [`remove`](Self::remove)) and by the collector itself (via | ||
| /// [`list_expired`](Self::list_expired)), so they must be safe to share across | ||
| /// tasks. | ||
| #[async_trait::async_trait] | ||
| pub trait GcStorage: Send + Sync + Debug { | ||
| /// Records that `id` expires at `expires_at`, replacing any previous deadline. | ||
| /// | ||
| /// A later deadline replaces an earlier one; a shorter deadline is ignored, so concurrent | ||
| /// writers cannot pull an expiration forward. `None` clears the recorded deadline and marks | ||
| /// the object as never expiring. | ||
| async fn upsert( | ||
| &self, | ||
| id: &ObjectId, | ||
| expires_at: Option<Timestamp>, | ||
| ) -> Result<(), ChangeStreamError>; | ||
|
|
||
| /// Forgets `id` entirely. | ||
| /// | ||
| /// Best-effort: failures are not reported to the caller. | ||
| async fn remove(&self, id: &ObjectId); | ||
|
|
||
| /// Returns up to `limit` ids whose expiration is at or before `now`, | ||
| /// ordered by earliest expiry first. | ||
| /// | ||
| /// Objects without an expiration are never returned. | ||
| async fn list_expired( | ||
| &self, | ||
| now: Timestamp, | ||
| limit: u64, | ||
| ) -> Result<Vec<ObjectId>, ChangeStreamError>; | ||
| } |


Uh oh!
There was an error while loading. Please reload this page.
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.
There are many changes to the Cargo.toml/.lock which should go away when you rebase the stack.
Then [nit] look also at which sqlx features we're bringing in, we might only need a subset of the default.
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.
I believe.. Jan, told me to only select the features on the package level instead of workspace level.