src/java/org/apache/cassandra/io/sstable/SSTableReader.java
/**
     * Loads ifile, dfile and indexSummary, and optionally recreates the bloom filter.
     */
Loads ifile, dfile and indexSummary, and optionally recreates the bloom filter.
Loads ifile dfile and indexSummary and optionally recreates the bloom filter .
private void load(boolean recreatebloom, Set<DecoratedKey> keysToLoadInCache) throws IOException
    {
        boolean cacheLoading = keyCache != null && !keysToLoadInCache.isEmpty();
        SegmentedFile.Builder ibuilder = SegmentedFile.getBuilder(DatabaseDescriptor.getIndexAccessMode());
        SegmentedFile.Builder dbuilder = compression
                                          ? SegmentedFile.getCompressedBuilder()
                                          : SegmentedFile.getBuilder(DatabaseDescriptor.getDiskAccessMode());
        RandomAccessReader input = RandomAccessReader.open(new File(descriptor.filenameFor(Component.PRIMARY_INDEX)), true);
        DecoratedKey left = null, right = null;
        try
        {
            long indexSize = input.length();
            long histogramCount = sstableMetadata.estimatedRowSize.count();
            long estimatedKeys = histogramCount > 0 && !sstableMetadata.estimatedRowSize.isOverflowed()
                               ? histogramCount
                               : SSTable.estimateRowsFromIndex(input); 
            indexSummary = new IndexSummary(estimatedKeys);
            if (recreatebloom)
                bf = LegacyBloomFilter.getFilter(estimatedKeys, 15);
            while (true)
            {
                long indexPosition = input.getFilePointer();
                if (indexPosition == indexSize)
                    break;
                ByteBuffer key = null, skippedKey;
                skippedKey = ByteBufferUtil.readWithShortLength(input);
                boolean shouldAddEntry = indexSummary.shouldAddEntry();
                if (shouldAddEntry || cacheLoading || recreatebloom)
                {
                    key = skippedKey;
                }
                if(null == left)
                    left = decodeKey(partitioner, descriptor, skippedKey);
                right = decodeKey(partitioner, descriptor, skippedKey);
                long dataPosition = input.readLong();
                if (key != null)
                {
                    DecoratedKey decoratedKey = decodeKey(partitioner, descriptor, key);
                    if (recreatebloom)
                        bf.add(decoratedKey.key);
                    if (shouldAddEntry)
                        indexSummary.addEntry(decoratedKey, indexPosition);
                    if (cacheLoading && keysToLoadInCache.contains(decoratedKey))
                        cacheKey(decoratedKey, dataPosition);
                }
                indexSummary.incrementRowid();
                ibuilder.addPotentialBoundary(indexPosition);
                dbuilder.addPotentialBoundary(dataPosition);
            }
            indexSummary.complete();
        }
        finally
        {
            FileUtils.closeQuietly(input);
        }
        this.first = getMinimalKey(left);
        this.last = getMinimalKey(right);
        ifile = ibuilder.complete(descriptor.filenameFor(Component.PRIMARY_INDEX));
        dfile = dbuilder.complete(descriptor.filenameFor(Component.DATA));
    }
private void load ( boolean recreatebloom , Set < DecoratedKey > keysToLoadInCache ) throws IOException { boolean cacheLoading = keyCache != null && ! keysToLoadInCache . isEmpty ( ) ; SegmentedFile . Builder ibuilder = SegmentedFile . getBuilder ( DatabaseDescriptor . getIndexAccessMode ( ) ) ; SegmentedFile . Builder dbuilder = compression ? SegmentedFile . getCompressedBuilder ( ) : SegmentedFile . getBuilder ( DatabaseDescriptor . getDiskAccessMode ( ) ) ; RandomAccessReader input = RandomAccessReader . open ( new File ( descriptor . filenameFor ( Component . PRIMARY_INDEX ) ) , true ) ; DecoratedKey left = null , right = null ; try { long indexSize = input . length ( ) ; long histogramCount = sstableMetadata . estimatedRowSize . count ( ) ; long estimatedKeys = histogramCount > 0 && ! sstableMetadata . estimatedRowSize . isOverflowed ( ) ? histogramCount : SSTable . estimateRowsFromIndex ( input ) ; indexSummary = new IndexSummary ( estimatedKeys ) ; if ( recreatebloom ) bf = LegacyBloomFilter . getFilter ( estimatedKeys , 15 ) ; while ( true ) { long indexPosition = input . getFilePointer ( ) ; if ( indexPosition == indexSize ) break ; ByteBuffer key = null , skippedKey ; skippedKey = ByteBufferUtil . readWithShortLength ( input ) ; boolean shouldAddEntry = indexSummary . shouldAddEntry ( ) ; if ( shouldAddEntry || cacheLoading || recreatebloom ) { key = skippedKey ; } if ( null == left ) left = decodeKey ( partitioner , descriptor , skippedKey ) ; right = decodeKey ( partitioner , descriptor , skippedKey ) ; long dataPosition = input . readLong ( ) ; if ( key != null ) { DecoratedKey decoratedKey = decodeKey ( partitioner , descriptor , key ) ; if ( recreatebloom ) bf . add ( decoratedKey . key ) ; if ( shouldAddEntry ) indexSummary . addEntry ( decoratedKey , indexPosition ) ; if ( cacheLoading && keysToLoadInCache . contains ( decoratedKey ) ) cacheKey ( decoratedKey , dataPosition ) ; } indexSummary . incrementRowid ( ) ; ibuilder . addPotentialBoundary ( indexPosition ) ; dbuilder . addPotentialBoundary ( dataPosition ) ; } indexSummary . complete ( ) ; } finally { FileUtils . closeQuietly ( input ) ; } this . first = getMinimalKey ( left ) ; this . last = getMinimalKey ( right ) ; ifile = ibuilder . complete ( descriptor . filenameFor ( Component . PRIMARY_INDEX ) ) ; dfile = dbuilder . complete ( descriptor . filenameFor ( Component . DATA ) ) ; }
Loads ifile, dfile and indexSummary, and optionally recreates the bloom filter.
Loads ifile dfile and indexSummary and optionally recreates the bloom filter .
// we read the positions in a BRAF so we don't have to worry about an entry spanning a mmap boundary. // statistics is supposed to be optional // if key cache could be used and we have key already pre-loaded // finalize the state of the reader