-
Notifications
You must be signed in to change notification settings - Fork 4.1k
21460 cursor bti #5154
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
base: cassandra-6.0
Are you sure you want to change the base?
21460 cursor bti #5154
Changes from all commits
b83001f
9a1c4ac
bc9dd57
964a277
880086e
b7a33c3
5c8eaf1
da7702b
612fb5b
277efcb
2c3d780
2e3fd5f
d92249e
226941e
a86e2e9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,8 +19,10 @@ | |
| package org.apache.cassandra.dht; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
| import java.util.Arrays; | ||
|
|
||
| import org.apache.cassandra.db.BufferDecoratedKey; | ||
| import org.apache.cassandra.db.DecoratedKey; | ||
| import org.apache.cassandra.utils.ByteBufferUtil; | ||
|
|
||
| public abstract class ReusableDecoratedKey extends BufferDecoratedKey | ||
|
|
@@ -46,6 +48,25 @@ public void copyKey(ByteBuffer newKey) | |
| recalculateToken(); | ||
| } | ||
|
|
||
| public void copyKey(byte[] newKey, int length) | ||
| { | ||
| maybeResizeKey(length); | ||
| System.arraycopy(newKey, 0, keyBytes, 0, length); | ||
| keyLength = length; | ||
| key.limit(length); | ||
| recalculateToken(); | ||
| } | ||
|
|
||
| /** | ||
| * Always a copy, token included: the next copyKey overwrites the bytes and moves the token, so | ||
| * this key is never safe to retain as it is. | ||
| */ | ||
| @Override | ||
| public DecoratedKey retainable() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if I got correctly we invoke it for every partition key, in worst case even two times (when we write to index summary + when we write it to cachedKeys), so we are actually loosing the benefit of partition key reusing and allocate similar amount or more..
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC, there's two cases I found that could eliminate a copy, but it would mean changing some of the BTI internals. I have one of them up as a separate patch. I'm open to changing this, but if memory serves, the non-copied version might be mutated... I'll go back and check. I really wish we had Rust's borrow checker for this kind of thing, it makes these questions easy.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, without a compiler check - such re-usable objects are a kind of straight razor.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am all for adding more static analysis. I don't have an approach here that I think can safely avoid the extra copy, do you? |
||
| { | ||
| return getToken().getPartitioner().decorateKey(ByteBuffer.wrap(Arrays.copyOf(keyBytes, keyLength))); | ||
| } | ||
|
|
||
| /** WARNING: retains ref to external buffer */ | ||
| public void shadowKey(ByteBuffer newKey, byte[] newKeyBytes, int newKeyLength) | ||
| { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.