maedhroz commented on code in PR #2409:
URL: https://github.com/apache/cassandra/pull/2409#discussion_r1228453597


##########
src/java/org/apache/cassandra/index/sai/disk/v1/bbtree/BlockBalancedTreeRamBuffer.java:
##########
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cassandra.index.sai.disk.v1.bbtree;
+
+import java.io.IOException;
+import java.util.stream.IntStream;
+
+import com.google.common.base.Preconditions;
+
+import org.apache.lucene.util.Accountable;
+import org.apache.lucene.util.ByteBlockPool;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.Counter;
+import org.apache.lucene.util.packed.PackedInts;
+import org.apache.lucene.util.packed.PackedLongValues;
+
+/**
+ * On-heap buffer for point values that provides a sortable view of itself as 
{@link IntersectingPointValues}.
+ */
+public class BlockBalancedTreeRamBuffer implements Accountable
+{
+    private final Counter bytesUsed;
+    private final ByteBlockPool bytes;
+    private final byte[] packedValue;
+    private final PackedLongValues.Builder rowIDsBuilder;
+    private int numPoints;
+    private int numRows;
+    private int lastSegmentRowID = -1;
+    private boolean closed = false;
+
+    public BlockBalancedTreeRamBuffer(int pointNumBytes)
+    {
+        this.bytesUsed = Counter.newCounter();
+
+        this.bytes = new ByteBlockPool(new 
ByteBlockPool.DirectTrackingAllocator(bytesUsed));
+
+        packedValue = new byte[pointNumBytes];
+
+        rowIDsBuilder = 
PackedLongValues.deltaPackedBuilder(PackedInts.COMPACT);
+        bytesUsed.addAndGet(rowIDsBuilder.ramBytesUsed());
+    }
+
+    @Override
+    public long ramBytesUsed()
+    {
+        return bytesUsed.get();
+    }
+
+    public int numRows()
+    {
+        return numRows;
+    }
+
+    public long addPackedValue(int segmentRowId, BytesRef value)
+    {
+        ensureOpen();
+
+        assert value.length == packedValue.length : "The value has length=" + 
value.length + " but should be " + packedValue.length;
+
+        long startingBytesUsed = bytesUsed.get();
+        long startingRowIDsBytesUsed = rowIDsBuilder.ramBytesUsed();
+
+        rowIDsBuilder.add(segmentRowId);
+        bytes.append(value);
+
+        if (segmentRowId != lastSegmentRowID)

Review Comment:
   Is there ever a case where we would actually add values for duplicate rows, 
one after the other? If not, this becomes an assertion at most?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to