mike-tr-adamson commented on code in PR #2409: URL: https://github.com/apache/cassandra/pull/2409#discussion_r1242127270
########## src/java/org/apache/cassandra/index/sai/disk/v1/bbtree/BlockBalancedTreePostingsIndex.java: ########## @@ -0,0 +1,86 @@ +/* + * 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 com.carrotsearch.hppc.IntLongHashMap; +import com.carrotsearch.hppc.IntLongMap; +import org.apache.cassandra.index.sai.disk.io.IndexInputReader; +import org.apache.cassandra.io.util.FileHandle; +import org.apache.cassandra.io.util.RandomAccessReader; + +import static com.google.common.base.Preconditions.checkArgument; +import static org.apache.cassandra.index.sai.disk.v1.SAICodecUtils.validate; + +/** + * Mapping between node ID and an offset to its auxiliary posting list (containing every row id from all leaves + * reachable from that node. See {@link BlockBalancedTreePostingsWriter}). + */ +class BlockBalancedTreePostingsIndex +{ + private final int size; + public final IntLongMap index = new IntLongHashMap(); + + BlockBalancedTreePostingsIndex(FileHandle postingsFileHandle, long filePosition) throws IOException + { + try (RandomAccessReader reader = postingsFileHandle.createReader(); + IndexInputReader input = IndexInputReader.create(reader)) + { + validate(input); + input.seek(filePosition); + + size = input.readVInt(); + + for (int x = 0; x < size; x++) + { + final int node = input.readVInt(); + final long filePointer = input.readVLong(); + + index.put(node, filePointer); + } + } + } + + /** + * Returns <tt>true</tt> if given node ID has an auxiliary posting list. + */ + boolean exists(int nodeID) + { + checkArgument(nodeID > 0); + return index.containsKey(nodeID); + } + + /** + * Returns an offset within the balanced tree postings file to the begining of the blocks summary of given node's auxiliary + * posting list. + * + * @throws IllegalArgumentException when given nodeID doesn't have an auxiliary posting list. Check first with + * {@link #exists(int)} + */ + long getPostingsFilePointer(int nodeID) + { + checkArgument(exists(nodeID)); Review Comment: Agreed. The usage shows that `getPostingsFilePointer` is always preceded by a call to `exists` so we definitely don't need to check there. Then `exists` is always preceded by a call to `getNodeID` from the traversal state. So, I have pushed the assertion up to there. It makes sense to keep it in the state in one place. -- 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]

