Skip to content

overlap: use overlapcache - #3639

Closed
RaduBerinde wants to merge 2 commits into
cockroachdb:masterfrom
RaduBerinde:overlap-cache-wire-up
Closed

overlap: use overlapcache#3639
RaduBerinde wants to merge 2 commits into
cockroachdb:masterfrom
RaduBerinde:overlap-cache-wire-up

Conversation

@RaduBerinde

Copy link
Copy Markdown
Member

overlap: add overlapcache subpackage

This commit implements a new overlap cache data structure which will
be embedded into FileMetadata.

The cache works by remembering a handful of data regions and whether
the spaces in-between are known to be empty. The goal is to make
repeated overlap checks in the same area of a file much cheaper. This
will make it feasible to have an optimistic overlap check that can be
repeated on a slightly changed version without redoing most of the
work.

overlap: use overlapcache

We embed an overlap cache in FileMetadata and use it with the
overlap checker.

When we have to open a table, we now try to find a maximal empty
region and the two surrounding data regions so that we can populate
the cache with this information.

The cache will be very useful for optimistic overlap checks which
happen without blocking compactions, and might need to be retried.

This commit implements a new overlap cache data structure which will
be embedded into `FileMetadata`.

The cache works by remembering a handful of data regions and whether
the spaces in-between are known to be empty. The goal is to make
repeated overlap checks in the same area of a file much cheaper. This
will make it feasible to have an optimistic overlap check that can be
repeated on a slightly changed version without redoing most of the
work.
@RaduBerinde
RaduBerinde requested a review from a team as a code owner May 30, 2024 18:20
@cockroach-teamcity

Copy link
Copy Markdown
Member

This change is Reviewable

We embed an overlap cache in `FileMetadata` and use it with the
overlap checker.

When we have to open a table, we now try to find a maximal empty
region and the two surrounding data regions so that we can populate
the cache with this information.

The cache will be very useful for optimistic overlap checks which
happen without blocking compactions, and might need to be retried.
@RaduBerinde

Copy link
Copy Markdown
Member Author

Friendly ping.

@jbowens jbowens 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.

Is the memory overhead of maintaining per-FileMetadata cache sustainable? It's not uncommon to have ~500k-1m sstables in a LSM version

Reviewable status: 0 of 8 files reviewed, all discussions resolved (waiting on @itsbilal and @sumeerbhola)

@RaduBerinde RaduBerinde left a comment

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.

Is the memory overhead of maintaining per-FileMetadata cache sustainable? It's not uncommon to have ~500k-1m sstables in a LSM version

In the common case of mostly points, we will have at most 6 keys per FileMetadata. I assumed that's not a huge problem given that we have ~4 keys already for the smallest/largest point/range keys. I can reduce the cache to 4 and it should still be very beneficial.

Or maybe I should at moving towards a separate LRU cache for a limited number of tables?

Reviewable status: 0 of 8 files reviewed, all discussions resolved (waiting on @itsbilal and @sumeerbhola)

@RaduBerinde

Copy link
Copy Markdown
Member Author

We can also greatly reduce the maxKeySize so we have a hard bound (probably even something like 128 covers a ton of common cases).

@RaduBerinde

Copy link
Copy Markdown
Member Author

Some higher level thoughts from a discussion with @sumeerbhola - I might hold off on this and get more data to establish how effective/necessary this cache is.

@RaduBerinde
RaduBerinde marked this pull request as draft April 11, 2025 15:37
@RaduBerinde RaduBerinde closed this by deleting the head repository Jun 2, 2026
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