Skip to content

Import sqlite storage as separate module#3449

Open
badboy wants to merge 3 commits into
main-sqlitefrom
sqlite/initial-import
Open

Import sqlite storage as separate module#3449
badboy wants to merge 3 commits into
main-sqlitefrom
sqlite/initial-import

Conversation

@badboy
Copy link
Copy Markdown
Member

@badboy badboy commented May 6, 2026

My plan over the next few weeks is to split up #3405 into reviewable pieces and merge them piece by piece.
For that I created the main-sqlite branch, which currently is the same as main. This way any feature work/bug fixes against the current Glean can continue to go to main without issues.
Over time I can rebase/merge that branch against main to keep-up-to-date, but keep further sqlite work reviewable.


this very first part is merely adding the first pieces of code, but none of that is actually part of the compilation yet (wouldn't work because it's not fully usable yet).
The details about the sqlite setup will change in later commits. Re-arranging that into a single commit that has the perfect setup would be a lot of work of splitting and rebasing commits (and squashing and merge conflicts), so doing it this way seemed easier.

@badboy badboy requested a review from a team as a code owner May 6, 2026 13:02
@badboy badboy requested review from chutten and removed request for a team May 6, 2026 13:02
@badboy badboy force-pushed the sqlite/initial-import branch from b65fc42 to d3d4e1b Compare May 6, 2026 13:04
Comment thread glean-core/src/database/sqlite/schema.rs Outdated
Comment thread glean-core/src/database/sqlite/schema.rs
Comment thread glean-core/src/database/sqlite.rs
Comment thread glean-core/src/database/sqlite.rs
Comment thread glean-core/src/database/sqlite.rs
lifetime TEXT NOT NULL,
labels TEXT NOT NULL, -- can't be null or ON CONFLICT won't work
value BLOB,
UNIQUE(id, ping, labels)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reflects a change in semantics, doesn't it? Previously, if a metric changed lifetime we'd store both.

Also: why are labels part of the unique constraint?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a) That's true, but it's kind of ... is it a bug? Unintended side-effect? We can never sent out two values. And based on the order of lifetimes by which we fetch values (ping, app, user) we end up with the "longest" one.

b) Because that's what makes it unique?
A labeled metric cat.name will add these rows:

id ping labels value
cat.name metrics label1 1
cat.name custom label1 1
cat.name metrics label2 31
cat.name custom label2 31

We use ON CONFLICT to do an upsert and that acts on the uniqueness constraint.
If we would not put labels in the unique constraint, we would overwrite previous rows.

Is that more clear?

Comment thread glean-core/src/database/sqlite.rs
Comment thread glean-core/src/database/sqlite.rs Outdated
///
/// This function will **not** panic on database errors.
pub fn clear_ping_lifetime_storage(&self, storage_name: &str) -> Result<()> {
let clear_sql = "DELETE FROM telemetry WHERE lifetime = ?1 AND ping = ?2";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not include Lifetime::Ping.as_str() in the statement directly?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess mostly to avoid copy-n-paste errors should we ever consider renaming Ping :P (I'll inline it)

@badboy badboy requested a review from chutten May 27, 2026 14:23
badboy added 3 commits May 27, 2026 16:39
This is a modified version of the kvstore/skv implementation:
https://searchfox.org/firefox-main/rev/cced10961b53e0d29e22e635404fec37728b2644/toolkit/components/kvstore/src/skv/connection.rs
Which itself is based on application-service's sql-support.

It's stripped down to what we need in Glean:
* A file-backed database
* A schema set up on start, potentially applying migrations if we need that
* A read-write connection, which is re-used for all access.
@badboy badboy force-pushed the sqlite/initial-import branch from 09f39e8 to a643cd3 Compare May 27, 2026 14:41
@badboy
Copy link
Copy Markdown
Member Author

badboy commented May 27, 2026

Woops, I initially pushed 3 changes as 3 separate commits, but then locally already squashed them and repushed accidentally. Only the 3 changes can be seen here: d3d4e1b...09f39e8

@badboy badboy added the sqlite Any changes to the new SQLite storage backend label May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sqlite Any changes to the new SQLite storage backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants