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

sstable: audit and clean up instances of improper key comparisons in the presence of synthetic prefixes/suffixes #4136

Closed
itsbilal opened this issue Nov 5, 2024 · 3 comments
Assignees
Labels
A-storage C-bug Something isn't working O-testcluster Issues found as part of DRT testing P-3 Issues/test failures with no fix SLA T-storage

Comments

@itsbilal
Copy link
Member

itsbilal commented Nov 5, 2024

Currently, a lot of the code around synthetic prefixes assumes that the comparer holds the property of Compare(x+a, x+b) == Compare(a, b) for any prefix x and arbitrary bytes a,b. This is true for the metamorphic test's comparer, but not for the Cockroach comparer where if the bytes immediately after x denote a local or range-local key, they'll sort before all other keys and break this property.

Here's an example of CopySpan being called with the prefix trimmed away:

start.UserKey = syntheticPrefix.Invert(start.UserKey)

And here we call the comparer with the trimmed key, which is invalid:

if r.Compare(end.UserKey, entry.sep) <= 0 {

In the rowblk (and probably also colblk) iterator code, we also do a similar trimming of synthetic prefixes from seek keys before calling the comparer on the remainder, which is invalid:

searchKey = key[len(syntheticPrefix):]

For this reason, in the presence of synthetic prefixes and prefixless sstables, we should materialize the full key before calling the comparer anywhere.

Cockroach companion issue: cockroachdb/cockroach#134168

Jira issue: PEBBLE-296

@itsbilal itsbilal added C-bug Something isn't working P-3 Issues/test failures with no fix SLA O-testcluster Issues found as part of DRT testing labels Nov 5, 2024
@github-project-automation github-project-automation bot moved this to Incoming in Storage Nov 5, 2024
@jbowens
Copy link
Collaborator

jbowens commented Nov 5, 2024

Note that we do require that MVCC prefixes (base.Split.Prefix(k)) be comparable with bytes.Compare now and that should hold for the Cockroach comparator as well:

// Compare(a, b) = bytes.Compare(prefix(a), prefix(b)) if not 0,
// otherwise ComparePointSuffixes(suffix(a), suffix(b))

Is the issue that we're not split-ing the key in some places before performing the comparison?

@itsbilal
Copy link
Member Author

itsbilal commented Nov 5, 2024

@jbowens We call the Comparer on the remainder of the key after the synthetic prefix, and the synthetic prefix is actually not the same as the prefix returned by Split - it's much shorter than that. But upon closer inspection I realized that should be okay - the normalization we do in the Cockroach comparer is all about the suffix, not the prefix, so I should better scrutinize the synthetic suffix logic instead of the synthetic prefix logic.

@itsbilal itsbilal self-assigned this Nov 5, 2024
@itsbilal
Copy link
Member Author

I'll close this issue for now as it's a non-issue the way it's currently spelled out. However, the parent issue cockroachdb/cockroach#134168 still stands until we've investigated this properly and gotten a new reproduction + figured out a root cause.

@github-project-automation github-project-automation bot moved this from Investigations to Done in Storage Nov 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-storage C-bug Something isn't working O-testcluster Issues found as part of DRT testing P-3 Issues/test failures with no fix SLA T-storage
Projects
Status: Done
Development

No branches or pull requests

2 participants