Skip to content
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

Persist txn data listen next simplify #27134

Conversation

jkosh44
Copy link
Contributor

@jkosh44 jkosh44 commented May 16, 2024

Motivation

Tips for reviewer

Checklist

The `TxnsCache` and `TxnsCacheState` structs are in-memory caches of
the persist txn shard. It allows callers to ask questions about
specific shards at a specific timestamp. It also allows callers to
compact the cache up to some timestamp.

Previously, the compaction could compact the cache past unapplied
writes. Then, when a caller would ask certain questions, such as "what
was the most recent previous unapplied write at ts?", the cache might
incorrectly return that there were no unapplied writes since any
information of them was compacted away. Specifically, this was
happening in the `latest_write` and `empty_to` return values of the
`data_snapshot` method.

This commit fixes the issue by removing the user facing API for
compacting the cache. Instead, the cache is self compacting such that
it maintains the following invariants:

  - All unapplied writes, registers, and forgets are included in the
    cache.
  - The latest write and registration are always kept in the cache.

While we're changing `data_snapshot`, we remove the assumption that
forgets apply all previous writes. `TxnsCacheState` has no way of
enforcing this invariant and relies on callers to enforce it. It also
has no way of validating the invariant. This makes it potentially scary
for `TxnsCacheState` to rely on this assumption and easy to
accidentally break code that relies on the assumption. If callers want
the cache to take advantage of forgets applying previous writes, then
they should (and do) update the cache state to reflect this. Then the
`TxnsCacheState` can look only at its current state to learn about
applied vs unapplied writes without making any assumptions. A
consequence of this is that the cache must wait for a write to be
applied **and tidied** before learning that it's applied. This is maybe
a slight performance regression in some specific cases, but should
hopefully save some head scratching. If we need to in the future, we
can have callers remove writes from the cache after applying them but
before tidying them.

Fixes MaterializeInc#26893
@jkosh44 jkosh44 closed this May 24, 2024
@jkosh44 jkosh44 deleted the persist-txn-data-listen-next-simplify branch May 24, 2024 14:32
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.

None yet

1 participant