Skip to content

Commit 90080e7

Browse files
authored
CNDB-141284: use ByteBuffer.remaining instead of limit to asset size (#1755)
The data inserted into the trie in `TrieMemoryIndex` is `encodedTerm`, which is built from `term` and only on the "available" bytes (between `term.position()` and `term.limit()`). But the check that decides to use the (more efficient) recursive path or not uses `term.limit()` to assess the size of `encodedTerm`. If `term.position()` is not 0, this is incorrect, and can lead to using the less optimal pass completely unecessarily. This has been shown to happen when investigating riptano/cndb#14153: the non-recursive path was taken even for boolean values (because the nodes were using `offheap_buffers`; with `offheap_objects`, the buffers getting to `TriMemoryIndex` are 0-positioned). See riptano/cndb#14184.
1 parent c5300ae commit 90080e7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/java/org/apache/cassandra/index/sai/memory/TrieMemoryIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private void applyTransformer(PrimaryKey primaryKey,
252252

253253
try
254254
{
255-
data.putSingleton(encodedTerm, primaryKey, transformer, term.limit() <= MAX_RECURSIVE_KEY_LENGTH);
255+
data.putSingleton(encodedTerm, primaryKey, transformer, term.remaining() <= MAX_RECURSIVE_KEY_LENGTH);
256256
}
257257
catch (TrieSpaceExhaustedException e)
258258
{

0 commit comments

Comments
 (0)