use of org.apache.cassandra.io.sstable.IndexInfo in project cassandra by apache.
the class RowIndexEntryTest method testIndexFor.
@Test
public void testIndexFor() throws IOException {
DeletionTime deletionInfo = new DeletionTime(FBUtilities.timestampMicros(), FBUtilities.nowInSeconds());
List<IndexInfo> indexes = new ArrayList<>();
indexes.add(new IndexInfo(cn(0L), cn(5L), 0, 0, deletionInfo));
indexes.add(new IndexInfo(cn(10L), cn(15L), 0, 0, deletionInfo));
indexes.add(new IndexInfo(cn(20L), cn(25L), 0, 0, deletionInfo));
RowIndexEntry rie = new RowIndexEntry(0L) {
public IndexInfoRetriever openWithIndex(FileHandle indexFile) {
return new IndexInfoRetriever() {
public IndexInfo columnsIndex(int index) {
return indexes.get(index);
}
public void close() {
}
};
}
public int columnsIndexCount() {
return indexes.size();
}
};
AbstractSSTableIterator.IndexState indexState = new AbstractSSTableIterator.IndexState(null, comp, rie, false, null);
assertEquals(0, indexState.indexFor(cn(-1L), -1));
assertEquals(0, indexState.indexFor(cn(5L), -1));
assertEquals(1, indexState.indexFor(cn(12L), -1));
assertEquals(2, indexState.indexFor(cn(17L), -1));
assertEquals(3, indexState.indexFor(cn(100L), -1));
assertEquals(3, indexState.indexFor(cn(100L), 0));
assertEquals(3, indexState.indexFor(cn(100L), 1));
assertEquals(3, indexState.indexFor(cn(100L), 2));
assertEquals(3, indexState.indexFor(cn(100L), 3));
indexState = new AbstractSSTableIterator.IndexState(null, comp, rie, true, null);
assertEquals(-1, indexState.indexFor(cn(-1L), -1));
assertEquals(0, indexState.indexFor(cn(5L), 3));
assertEquals(0, indexState.indexFor(cn(5L), 2));
assertEquals(1, indexState.indexFor(cn(17L), 3));
assertEquals(2, indexState.indexFor(cn(100L), 3));
assertEquals(2, indexState.indexFor(cn(100L), 4));
assertEquals(1, indexState.indexFor(cn(12L), 3));
assertEquals(1, indexState.indexFor(cn(12L), 2));
assertEquals(1, indexState.indexFor(cn(100L), 1));
assertEquals(2, indexState.indexFor(cn(100L), 2));
}
use of org.apache.cassandra.io.sstable.IndexInfo in project cassandra by apache.
the class RowIndexEntryTest method serializationCheck.
private static void serializationCheck(Pre_C_11206_RowIndexEntry withIndex, IndexInfo.Serializer indexSerializer, ByteBuffer bb, DataInputBuffer input) throws IOException {
Assert.assertEquals(0xdeadbeef, input.readUnsignedVInt());
Assert.assertEquals(withIndex.promotedSize(indexSerializer), input.readUnsignedVInt());
Assert.assertEquals(withIndex.headerLength(), input.readUnsignedVInt());
Assert.assertEquals(withIndex.deletionTime(), DeletionTime.serializer.deserialize(input));
Assert.assertEquals(withIndex.columnsIndex().size(), input.readUnsignedVInt());
int offset = bb.position();
int[] offsets = new int[withIndex.columnsIndex().size()];
for (int i = 0; i < withIndex.columnsIndex().size(); i++) {
int pos = bb.position();
offsets[i] = pos - offset;
IndexInfo info = indexSerializer.deserialize(input);
int end = bb.position();
Assert.assertEquals(indexSerializer.serializedSize(info), end - pos);
Assert.assertEquals(withIndex.columnsIndex().get(i).offset, info.offset);
Assert.assertEquals(withIndex.columnsIndex().get(i).width, info.width);
Assert.assertEquals(withIndex.columnsIndex().get(i).endOpenMarker, info.endOpenMarker);
Assert.assertEquals(withIndex.columnsIndex().get(i).firstName, info.firstName);
Assert.assertEquals(withIndex.columnsIndex().get(i).lastName, info.lastName);
}
for (int i = 0; i < withIndex.columnsIndex().size(); i++) Assert.assertEquals(offsets[i], input.readInt());
Assert.assertEquals(0, bb.remaining());
}
use of org.apache.cassandra.io.sstable.IndexInfo in project cassandra by apache.
the class ColumnIndex method addIndexBlock.
private void addIndexBlock() throws IOException {
IndexInfo cIndexInfo = new IndexInfo(firstClustering, lastClustering, startPosition, currentPosition() - startPosition, openMarker);
// for index #0 and always subtracting 1 for the index (which could be error-prone).
if (indexOffsets == null)
indexOffsets = new int[10];
else {
if (columnIndexCount >= indexOffsets.length)
indexOffsets = Arrays.copyOf(indexOffsets, indexOffsets.length + 10);
//the 0th element is always 0
if (columnIndexCount == 0) {
indexOffsets[columnIndexCount] = 0;
} else {
indexOffsets[columnIndexCount] = buffer != null ? Ints.checkedCast(buffer.position()) : indexSamplesSerializedSize;
}
}
columnIndexCount++;
// When column_index_cache_size_in_kb is reached, we switch to byte-buffer mode.
if (buffer == null) {
indexSamplesSerializedSize += idxSerializer.serializedSize(cIndexInfo);
if (indexSamplesSerializedSize + columnIndexCount * TypeSizes.sizeof(0) > DatabaseDescriptor.getColumnIndexCacheSize()) {
buffer = reuseOrAllocateBuffer();
for (IndexInfo indexSample : indexSamples) {
idxSerializer.serialize(indexSample, buffer);
}
} else {
indexSamples.add(cIndexInfo);
}
}
// don't put an else here...
if (buffer != null) {
idxSerializer.serialize(cIndexInfo, buffer);
}
firstClustering = null;
}
use of org.apache.cassandra.io.sstable.IndexInfo in project cassandra by apache.
the class UnfilteredRowIteratorWithLowerBound method getPartitionIndexLowerBound.
/**
* @return the lower bound stored on the index entry for this partition, if available.
*/
private ClusteringBound getPartitionIndexLowerBound() {
// DatabaseDescriptor.column_index_size_in_kb)
if (!canUseMetadataLowerBound())
maybeInit();
RowIndexEntry rowIndexEntry = sstable.getCachedPosition(partitionKey(), false);
if (rowIndexEntry == null || !rowIndexEntry.indexOnHeap())
return null;
try (RowIndexEntry.IndexInfoRetriever onHeapRetriever = rowIndexEntry.openWithIndex(null)) {
IndexInfo column = onHeapRetriever.columnsIndex(filter.isReversed() ? rowIndexEntry.columnsIndexCount() - 1 : 0);
ClusteringPrefix lowerBoundPrefix = filter.isReversed() ? column.lastName : column.firstName;
assert lowerBoundPrefix.getRawValues().length <= metadata().comparator.size() : String.format("Unexpected number of clustering values %d, expected %d or fewer for %s", lowerBoundPrefix.getRawValues().length, metadata().comparator.size(), sstable.getFilename());
return ClusteringBound.inclusiveOpen(filter.isReversed(), lowerBoundPrefix.getRawValues());
} catch (IOException e) {
throw new RuntimeException("should never occur", e);
}
}
Aggregations