maedhroz commented on code in PR #2267: URL: https://github.com/apache/cassandra/pull/2267#discussion_r1183081154
########## src/java/org/apache/cassandra/io/sstable/format/bti/PartitionIterator.java: ########## @@ -0,0 +1,246 @@ +/* + * 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.io.sstable.format.bti; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.apache.cassandra.db.DecoratedKey; +import org.apache.cassandra.db.PartitionPosition; +import org.apache.cassandra.dht.IPartitioner; +import org.apache.cassandra.io.sstable.KeyReader; +import org.apache.cassandra.io.util.FileDataInput; +import org.apache.cassandra.io.util.FileHandle; +import org.apache.cassandra.utils.ByteBufferUtil; +import org.apache.cassandra.utils.Throwables; + +import static org.apache.cassandra.utils.FBUtilities.immutableListWithFilteredNulls; + +class PartitionIterator extends PartitionIndex.IndexPosIterator implements KeyReader +{ + private final PartitionIndex partitionIndex; + private final IPartitioner partitioner; + private final PartitionPosition limit; + private final int exclusiveLimit; + private final FileHandle dataFile; + private final FileHandle rowIndexFile; + + private FileDataInput dataInput; + private FileDataInput indexInput; + + private DecoratedKey currentKey; + private TrieIndexEntry currentEntry; + private DecoratedKey nextKey; + private TrieIndexEntry nextEntry; + + @SuppressWarnings({ "resource", "RedundantSuppression" }) + static PartitionIterator create(PartitionIndex partitionIndex, IPartitioner partitioner, FileHandle rowIndexFile, FileHandle dataFile, + PartitionPosition left, int inclusiveLeft, PartitionPosition right, int exclusiveRight) throws IOException + { + PartitionIterator partitionIterator = null; + PartitionIndex partitionIndexCopy = null; + FileHandle dataFileCopy = null; + FileHandle rowIndexFileCopy = null; + + try + { + partitionIndexCopy = partitionIndex.sharedCopy(); + dataFileCopy = dataFile.sharedCopy(); + rowIndexFileCopy = rowIndexFile.sharedCopy(); + + partitionIterator = new PartitionIterator(partitionIndexCopy, partitioner, rowIndexFileCopy, dataFileCopy, left, right, exclusiveRight); + + partitionIterator.readNext(); + // Because the index stores prefixes, the first value can be in any relationship with the left bound. + if (partitionIterator.nextKey != null && !(partitionIterator.nextKey.compareTo(left) > inclusiveLeft)) + { + partitionIterator.readNext(); + } + partitionIterator.advance(); Review Comment: So to make sure I understand, we `readNext()` to load the next key and index entry, then `advance()` actually assigns them to the "current" key and entry, which will be accessible via `key()` and `entry()`? -- 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]

