Skip to content

More effective views cleanup.#5503

Open
Shubham8287 wants to merge 8 commits into
masterfrom
shub/views-cleanup
Open

More effective views cleanup.#5503
Shubham8287 wants to merge 8 commits into
masterfrom
shub/views-cleanup

Conversation

@Shubham8287

@Shubham8287 Shubham8287 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Description of Changes

Existing View cleanup code is naive and doesn't anticipate large number of view subscribers, which could easily happen if clients are connecting via http sql call.

As a result I saw this log line:

[c2008d0c308db28e93c1d8785d6aa26cafdc78940da42414310a8a1cdc195fb0] DATABASE: cleared 0 expired views (585700 remaining)

We already have a due ticket to make it configuratable at database level: #3717 but I think that requires some ux decisions to make and little bit more work (I could be wrong).

This patch tries to mitigate it by doing two things:

  1. When a cleanup run leaves expired views behind, nowthe loop runs more frequently until the backlog is drained, then returns to the normal interval.

  2. (More important) It changes expired view query paths to use iterators and clears expired materialized views in bounded batches, avoiding collection of the full expired-view set before deletion.

API and ABI breaking changes

NA though there could be some noticeable latency sometimes as we are now clearing views more aggresively.

How complicated do you think these changes are? Grade on a scale from 1 to 5,

1.5

Testing

No functional change, existing test should cover.

@Shubham8287 Shubham8287 requested review from gefjon and jsdt July 9, 2026 12:10

@gefjon gefjon left a comment

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 all looks like an improvement, though I still think this code needs a major overhaul. Do you have a sense of what it means that the cleanup cleared 0 expired views with nearly 600k remaining in the previous version? Does that mean that our entire time budget was spent collecting the expired_items vec at line 2910 in the previous code, and didn't get to actually delete any of them?

Comment thread crates/datastore/src/locking_tx_datastore/mut_tx.rs
Comment thread crates/datastore/src/locking_tx_datastore/mut_tx.rs
Comment thread crates/datastore/src/locking_tx_datastore/mut_tx.rs
@Shubham8287

Copy link
Copy Markdown
Contributor Author

Does that mean that our entire time budget was spent collecting the expired_items vec at line 2910 in the previous code, and didn't get to actually delete any of them?

Yes.

Shubham8287 and others added 3 commits July 9, 2026 21:25
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
Signed-off-by: Shubham Mishra <shivam828787@gmail.com>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
Signed-off-by: Shubham Mishra <shivam828787@gmail.com>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
Signed-off-by: Shubham Mishra <shivam828787@gmail.com>
@Shubham8287 Shubham8287 requested a review from gefjon July 9, 2026 16:16

@gefjon gefjon left a comment

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.

Thank you!

@Shubham8287 Shubham8287 enabled auto-merge July 9, 2026 16:33
@joshua-spacetime

Copy link
Copy Markdown
Contributor

I can't review these changes and won't block them, but I will just comment that making cleanup run more frequently and even making algorithmic improvements to it won't actually clean up 585700 rows if they're not already being cleaned up (which is the actual issue).

@Shubham8287

Copy link
Copy Markdown
Contributor Author

it won't actually clean up 585700 rows if they're not already being cleaned up (which is the actual issue).

Why? All those are expired views.

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.

3 participants