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


##########
src/java/org/apache/cassandra/index/sai/disk/v1/bbtree/BlockBalancedTreeWriter.java:
##########
@@ -0,0 +1,766 @@
+/*
+ * 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.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.IntFunction;
+
+import com.google.common.base.MoreObjects;
+
+import org.apache.cassandra.index.sai.disk.io.RAMIndexOutput;
+import org.apache.cassandra.index.sai.disk.v1.SAICodecUtils;
+import org.apache.lucene.store.DataOutput;
+import org.apache.lucene.store.GrowableByteArrayDataOutput;
+import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.ArrayUtil;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.FutureArrays;
+import org.apache.lucene.util.IntroSorter;
+import org.apache.lucene.util.Sorter;
+import org.apache.lucene.util.bkd.MutablePointsReaderUtils;
+
+/**
+ * This is a specialisation of the lucene BKDWriter that only writes a single 
dimension
+ * balanced tree.
+ * <p>
+ * Recursively builds a block balanced tree to assign all incoming points to 
smaller
+ * and smaller rectangles (cells) until the number of points in a given
+ * rectangle is &lt;= <code>maxPointsInLeafNode</code>.  The tree is
+ * fully balanced, which means the leaf nodes will have between 50% and 100% of
+ * the requested <code>maxPointsInLeafNode</code>.  Values that fall exactly
+ * on a cell boundary may be in either cell.
+ *
+ * <p>
+ * <b>NOTE</b>: This can write at most Integer.MAX_VALUE * 
<code>maxPointsInLeafNode</code> total points.
+ */

Review Comment:
   So to summarize my understanding of how this works, we start w/ a 
`IntersectingPointValues`. We hit `writeField()` (which I've suggested 
renaming, etc.), write a footer, pass all the points to 
`OneDimensionBKDWriter`, finalize the tree in `OneDimensionBKDWriter`, write a 
footer, and return a the footer position. While that's happening, 
`OneDimensionBKDWriter` also sends blocks postings lists through the provided 
callback, and those are later written to the actual postings file, along w/ the 
auxiliary postings. `BlockBalancedTreeWriter` really doesn't do much other than 
store some configuration parameters for the process (ex. `bytesPerValue`), and 
those inform `OneDimensionBKDWriter`, which actually does all the work.
   
   How do we actually want to document this? Right now, we have no high level 
documentation on `OneDimensionBKDWriter`, and the documentation here on 
`BlockBalancedTreeWriter` is sort of random details copied from (I'm guessing?) 
the Lucene JavaDoc. (I could be wrong there.) Here's one proposal for how we do 
this:
   
   1.) Provide a decent summary of what `writeField()` does below, see 
https://github.com/apache/cassandra/pull/2409/files#r1228830151
   
   2.) Whittle down the class level JavaDoc (especially the "smaller and 
smaller rectangles" bit) to `@see` reference `BKDWriter`, retain the bit about 
`maxPointsInLeafNode` if it still matters (although w/ `{@link 
#maxPointsInLeafNode}`), and describe the top-level format, which is just 
header, tree (written by `OneDimensionBKDWriter` or whatever we call it), and a 
footer.
   
   3.) In the class JavaDoc for `OneDimensionBKDWriter`, actually describe the 
format for the tree, with the leaf nodes, then the packed index representing 
the binary tree. The question here is whether we want to describe the leaf 
format, w/ the order index and the packed values in detail, but I think we do. 
The alternative would be pushing it down to `writeLeafBlock()`, but that feels 
too fragmented.
   
   4.) Have short summary JavaDoc for `add()` and `finish()` that roughly 
describe their processes.
   
   5.) Document everything below that level w/ inline comments where they seem 
useful.
   
   It seems like there are some TODOs (which I haven't fully wrapped my head 
around) in the tree building logic below, but even if some of that changes, 
what I've described in these 5 points doesn't seem very likely to change.
   
   WDYT?



-- 
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