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

Ranges cache: add ownership check #6004

Merged
merged 2 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/graveler/committed/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ func getBytes(b *[]byte) ([]byte, error) {
if l < 0 {
return nil, fmt.Errorf("impossible negative length %d: %w", l, ErrBadValueBytes)
}
ret := make([]byte, l)
copy(ret, (*b)[:l])
ret := (*b)[:l]
*b = (*b)[l:]
return ret, nil
}
Expand Down
16 changes: 14 additions & 2 deletions pkg/graveler/sstable/range_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ func (m *RangeManager) GetValueGE(ctx context.Context, ns committed.Namespace, i
}
return nil, ErrKeyNotFound
}
vBytes, _, err := value.Value(nil)
vBytes, owned, err := value.Value(nil)
if !owned {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, great catch!

Is there any way for us to change this bad ownership status? IIUC when !owned, iterator it shares underlying state with some other iterator. I would expect this state to persist, and now very many calls (including future getValue()s) will keep on copying every value. It might be considerably more efficient if we could convince Pebble to unshare the iterator -- say by creating future iterators on a new iterator hierarchy. (It goes without saying that this is no reason to delay this PR!)

b := vBytes
vBytes = make([]byte, len(b))
copy(vBytes, b)
}

if err != nil {
return nil, fmt.Errorf("extract value from sstable id %s (key %s): %w", id, key, err)
}
Expand Down Expand Up @@ -132,7 +138,13 @@ func (m *RangeManager) GetValue(ctx context.Context, ns committed.Namespace, id
// lookup path in range but key not found
return nil, ErrKeyNotFound
}
vBytes, _, err := value.Value(nil)
vBytes, owned, err := value.Value(nil)
if !owned {
b := vBytes
vBytes = make([]byte, len(b))
copy(vBytes, b)
}

if err != nil {
return nil, fmt.Errorf("extract value from sstable id %s (key %s): %w", id, key, err)
}
Expand Down