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

Make ordinary indexes store their keys unsliced #659

Merged
merged 1 commit into from
Apr 1, 2025

Conversation

jeltsch
Copy link
Collaborator

@jeltsch jeltsch commented Mar 27, 2025

Previously, the keys stored in ordinary indexes and ordinary-index accumulators were of type SerialisedKey, and the append operations for ordinary-index accumulators did not truncate keys that were represented as slices of larger byte sequences to their actual payloads. This pull request changes IndexOrdinary and IndexOrdinaryAcc to use Unsliced SerialisedKey for storing keys, so that it is guaranteed that only actual key contents are stored.

Comment on lines 111 to +117
= do
#ifdef NO_IGNORE_ASSERTS
maybeLastLastKey <- Growing.readMaybeLast lastKeys
assert (all (< key) maybeLastLastKey) $ return ()
maybeLastUnslicedLastKey <- Growing.readMaybeLast unslicedLastKeys
assert (all (< key) (fromUnslicedKey <$> maybeLastUnslicedLastKey))
(return ())
#endif
Growing.append lastKeys pageCount key
Growing.append unslicedLastKeys pageCount (makeUnslicedKey key)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something along these lines would fix the compiler error with assertions disabled

    = do
          let !key' = makeUnslicedKey key
#ifdef NO_IGNORE_ASSERTS
          maybeLastUnslicedLastKey <- Growing.readMaybeLast unslicedLastKeys
          assert (all (< key') maybeLastUnslicedLastKey)
                 (return ())
#endif
          Growing.append unslicedLastKeys pageCount key'

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What compiler error do you get here? I can’t see an error in this code, and commenting out the #ifdef#endif part doesn’t cause GHC to show me an error message.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I see: When removing both assertion blocks, there is an unused import. I had a similar issue in the same module with readMaybeLast, which I solved by a conditional import. I can just move the import of fromUnslicedKey into the conditional block with the readMaybeLast import.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can just move the import of fromUnslicedKey into the conditional block with the readMaybeLast import.

Done in dd6b71c.

Comment on lines 92 to +100
= assert (firstKey <= lastKey) $
do
#ifdef NO_IGNORE_ASSERTS
maybeLastLastKey <- Growing.readMaybeLast lastKeys
assert (all (< firstKey) maybeLastLastKey) $ return ()
maybeLastUnslicedLastKey <- Growing.readMaybeLast unslicedLastKeys
assert
(all (< firstKey) (fromUnslicedKey <$> maybeLastUnslicedLastKey))
(return ())
#endif
Growing.append lastKeys 1 lastKey
Growing.append unslicedLastKeys 1 (makeUnslicedKey lastKey)
Copy link
Collaborator

Choose a reason for hiding this comment

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

See my suggestion for appendMulti

Copy link
Collaborator

@jorisdral jorisdral left a comment

Choose a reason for hiding this comment

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

Whoops, I didn't mean to approve just yet

@jorisdral
Copy link
Collaborator

Let's squash before we merge

@jeltsch jeltsch force-pushed the jeltsch/unsliced-keys-in-ordinary-indexes branch from dd6b71c to 84f5ca5 Compare April 1, 2025 19:54
@jeltsch jeltsch enabled auto-merge April 1, 2025 19:54
@jeltsch jeltsch added this pull request to the merge queue Apr 1, 2025
Merged via the queue into main with commit 441f194 Apr 1, 2025
27 checks passed
@jeltsch jeltsch deleted the jeltsch/unsliced-keys-in-ordinary-indexes branch April 1, 2025 20:48
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.

2 participants