Package org.apache.cassandra.io

Examples of org.apache.cassandra.io.SSTable$KeyPositionInfo


        /* Figure out the keys in the index file to relocate the node */
        List<String> ssTables = Table.open(table).getAllSSTablesOnDisk();
        /* Load the indexes into memory */
        for ( String df : ssTables )
        {
          SSTable ssTable = new SSTable(df);
          ssTable.close();
        }
        /* We should have only one file since we just compacted. */       
        List<String> indexedKeys = SSTable.getIndexedKeys();       
        storageService_.relocate(indexedKeys.toArray( new String[0]) );
       
View Full Code Here


        logger_.info("Flushing " + this);
        ColumnFamilyStore cfStore = Table.open(table_).getColumnFamilyStore(cfName_);

        String directory = DatabaseDescriptor.getDataFileLocation();
        String filename = cfStore.getTempFileName();
        SSTable ssTable = new SSTable(directory, filename, StorageService.getPartitioner());

        // sort keys in the order they would be in when decorated
        final IPartitioner partitioner = StorageService.getPartitioner();
        final Comparator<String> dc = partitioner.getDecoratedKeyComparator();
        ArrayList<String> orderedKeys = new ArrayList<String>(columnFamilies_.keySet());
        Collections.sort(orderedKeys, new Comparator<String>()
        {
            public int compare(String o1, String o2)
            {
                return dc.compare(partitioner.decorateKey(o1), partitioner.decorateKey(o2));
            }
        });
        DataOutputBuffer buffer = new DataOutputBuffer();
        /* Use this BloomFilter to decide if a key exists in a SSTable */
        BloomFilter bf = new BloomFilter(columnFamilies_.size(), 15);
        for (String key : orderedKeys)
        {
            buffer.reset();
            ColumnFamily columnFamily = columnFamilies_.get(key);
            if ( columnFamily != null )
            {
                /* serialize the cf with column indexes */
                ColumnFamily.serializerWithIndexes().serialize( columnFamily, buffer );
                /* Now write the key and value to disk */
                ssTable.append(partitioner.decorateKey(key), buffer);
                bf.add(key);
            }
        }
        ssTable.closeRename(bf);
        cfStore.onMemtableFlush(cLogCtx);
        cfStore.storeLocation( ssTable.getDataFileLocation(), bf );
        buffer.close();
        isFlushed_ = true;
        logger_.info("Completed flushing " + this);
    }
View Full Code Here

                 * If the file is a Data File we need to load the indicies associated
                 * with this file. We also need to cache the file name in the SSTables
                 * list of the associated Column Family. Also merge the CBF into the
                 * sampler.
                */               
                SSTable ssTable = new SSTable(streamContext.getTargetFile(), StorageService.getPartitioner());
                ssTable.close();
                logger_.debug("Merging the counting bloom filter in the sampler ...");               
                String[] peices = FBUtilities.strip(fileName, "-");
                Table.open(peices[0]).getColumnFamilyStore(peices[1]).addToList(streamContext.getTargetFile());               
            }
           
View Full Code Here

        /*
         * Use the SSTable to write the contents of the TreeMap
         * to disk.
        */
        SSTable ssTable = new SSTable(directory, filename, StorageService.getPartitioner());
        List<String> keys = new ArrayList<String>( columnFamilies_.keySet() );
        Collections.sort(keys);       
        /* Use this BloomFilter to decide if a key exists in a SSTable */
        BloomFilter bf = new BloomFilter(keys.size(), 8);
        for ( String key : keys )
        {          
            byte[] bytes = columnFamilies_.get(key);
            if ( bytes.length > 0 )
            {             
                /* Now write the key and value to disk */
                ssTable.append(key, bytes);
                bf.add(key);
            }
        }
        ssTable.closeRename(bf);
        cfStore.storeLocation( ssTable.getDataFileLocation(), bf );
        columnFamilies_.clear();      
    }
View Full Code Here

        }
    }

    private ColumnFamily fetchColumnFamily(String key, String cf, IFilter filter, String ssTableFile) throws IOException
    {
        SSTable ssTable = new SSTable(ssTableFile, StorageService.getPartitioner());
        DataInputBuffer bufIn;
        bufIn = filter.next(key, cf, ssTable);
        if (bufIn.getLength() == 0)
        {
            return null;
View Full Code Here

        {
            return result;
        }

        mergedFileName = getTempFileName();
        SSTable ssTableRange = null;
        String lastkey = null;
        List<FileStruct> lfs = new ArrayList<FileStruct>();
        DataOutputBuffer bufOut = new DataOutputBuffer();
        int expectedBloomFilterSize = SSTable.getApproximateKeyCount(files);
        expectedBloomFilterSize = (expectedBloomFilterSize > 0) ? expectedBloomFilterSize : SSTable.indexInterval();
        logger_.debug("Expected bloom filter size : " + expectedBloomFilterSize);
        /* Create the bloom filter for the compacted file. */
        BloomFilter compactedRangeBloomFilter = new BloomFilter(expectedBloomFilterSize, 15);
        List<ColumnFamily> columnFamilies = new ArrayList<ColumnFamily>();

        while (pq.size() > 0 || lfs.size() > 0)
        {
            FileStruct fs = null;
            if (pq.size() > 0)
            {
                fs = pq.poll();
            }
            if (fs != null
                && (lastkey == null || lastkey.equals(fs.getKey())))
            {
                // The keys are the same so we need to add this to the
                // ldfs list
                lastkey = fs.getKey();
                lfs.add(fs);
            }
            else
            {
                Collections.sort(lfs, new FileStructComparator());
                ColumnFamily columnFamily;
                bufOut.reset();
                if (lfs.size() > 1)
                {
                    for (FileStruct filestruct : lfs)
                    {
                        try
                        {
                            /* read the length although we don't need it */
                            filestruct.getBufIn().readInt();
                            // Skip the Index
                            IndexHelper.skipBloomFilterAndIndex(filestruct.getBufIn());
                            // We want to add only 2 and resolve them right there in order to save on memory footprint
                            if (columnFamilies.size() > 1)
                            {
                                // Now merge the 2 column families
                                merge(columnFamilies);
                            }
                            // deserialize into column families
                            columnFamilies.add(ColumnFamily.serializer().deserialize(filestruct.getBufIn()));
                        }
                        catch (Exception ex)
                        {
                            logger_.warn(LogUtil.throwableToString(ex));
                        }
                    }
                    // Now after merging all crap append to the sstable
                    columnFamily = resolveAndRemoveDeleted(columnFamilies);
                    columnFamilies.clear();
                    if (columnFamily != null)
                    {
                        /* serialize the cf with column indexes */
                        ColumnFamily.serializerWithIndexes().serialize(columnFamily, bufOut);
                    }
                }
                else
                {
                    FileStruct filestruct = lfs.get(0);
                    /* read the length although we don't need it */
                    int size = filestruct.getBufIn().readInt();
                    bufOut.write(filestruct.getBufIn(), size);
                }
                if (Range.isTokenInRanges(StorageService.getPartitioner().getInitialToken(lastkey), ranges))
                {
                    if (ssTableRange == null)
                    {
                        if (target != null)
                        {
                            rangeFileLocation = rangeFileLocation + System.getProperty("file.separator") + "bootstrap";
                        }
                        FileUtils.createDirectory(rangeFileLocation);
                        ssTableRange = new SSTable(rangeFileLocation, mergedFileName, StorageService.getPartitioner());
                    }
                    try
                    {
                        ssTableRange.append(lastkey, bufOut);
                        compactedRangeBloomFilter.add(lastkey);
                    }
                    catch (Exception ex)
                    {
                        logger_.warn(LogUtil.throwableToString(ex));
                    }
                }
                totalkeysWritten++;
                for (FileStruct filestruct : lfs)
                {
                    try
                    {
                        filestruct.advance();
                        if (filestruct.isExhausted())
                        {
                            continue;
                        }
                        /* keep on looping until we find a key in the range */
                        while (!Range.isTokenInRanges(StorageService.getPartitioner().getInitialToken(filestruct.getKey()), ranges))
                        {
                            filestruct.advance();
                            if (filestruct.isExhausted())
                            {
                                break;
                            }
                        }
                        if (!filestruct.isExhausted())
                        {
                            pq.add(filestruct);
                        }
                        totalkeysRead++;
                    }
                    catch (Exception ex)
                    {
                        // Ignore the exception as it might be a corrupted file
                        // in any case we have read as far as possible from it
                        // and it will be deleted after compaction.
                        logger_.warn("corrupt sstable?", ex);
                        filestruct.close();
                    }
                }
                lfs.clear();
                lastkey = null;
                if (fs != null)
                {
                    // Add back the fs since we processed the rest of
                    // filestructs
                    pq.add(fs);
                }
            }
        }

        if (ssTableRange != null)
        {
            ssTableRange.closeRename(compactedRangeBloomFilter);
            if (fileList != null)
            {
                fileList.add(ssTableRange.getDataFileLocation());
            }
            if (compactedBloomFilters != null)
            {
                compactedBloomFilters.add(compactedRangeBloomFilter);
            }
View Full Code Here

            // TODO clean out bad files, if any
            return 0;
        }

        String mergedFileName = getTempFileName(files);
        SSTable ssTable = null;
        String lastkey = null;
        List<FileStruct> lfs = new ArrayList<FileStruct>();
        DataOutputBuffer bufOut = new DataOutputBuffer();
        int expectedBloomFilterSize = SSTable.getApproximateKeyCount(files);
        expectedBloomFilterSize = (expectedBloomFilterSize > 0) ? expectedBloomFilterSize : SSTable.indexInterval();
        logger_.debug("Expected bloom filter size : " + expectedBloomFilterSize);
        /* Create the bloom filter for the compacted file. */
        BloomFilter compactedBloomFilter = new BloomFilter(expectedBloomFilterSize, 15);
        List<ColumnFamily> columnFamilies = new ArrayList<ColumnFamily>();

        while (pq.size() > 0 || lfs.size() > 0)
        {
            FileStruct fs = null;
            if (pq.size() > 0)
            {
                fs = pq.poll();
            }
            if (fs != null
                && (lastkey == null || lastkey.equals(fs.getKey())))
            {
                // The keys are the same so we need to add this to the
                // ldfs list
                lastkey = fs.getKey();
                lfs.add(fs);
            }
            else
            {
                Collections.sort(lfs, new FileStructComparator());
                ColumnFamily columnFamily;
                bufOut.reset();
                if (lfs.size() > 1)
                {
                    for (FileStruct filestruct : lfs)
                    {
                        try
                        {
                            /* read the length although we don't need it */
                            filestruct.getBufIn().readInt();
                            // Skip the Index
                            IndexHelper.skipBloomFilterAndIndex(filestruct.getBufIn());
                            // We want to add only 2 and resolve them right there in order to save on memory footprint
                            if (columnFamilies.size() > 1)
                            {
                                merge(columnFamilies);
                            }
                            // deserialize into column families
                            columnFamilies.add(ColumnFamily.serializer().deserialize(filestruct.getBufIn()));
                        }
                        catch (Exception ex)
                        {
                            logger_.warn("error in filecompaction", ex);
                        }
                    }
                    // Now after merging all crap append to the sstable
                    columnFamily = resolveAndRemoveDeleted(columnFamilies);
                    columnFamilies.clear();
                    if (columnFamily != null)
                    {
                        /* serialize the cf with column indexes */
                        ColumnFamily.serializerWithIndexes().serialize(columnFamily, bufOut);
                    }
                }
                else
                {
                    FileStruct filestruct = lfs.get(0);
                    /* read the length although we don't need it */
                    int size = filestruct.getBufIn().readInt();
                    bufOut.write(filestruct.getBufIn(), size);
                }

                if (ssTable == null)
                {
                    ssTable = new SSTable(compactionFileLocation, mergedFileName, StorageService.getPartitioner());
                }
                ssTable.append(lastkey, bufOut);

                /* Fill the bloom filter with the key */
                doFill(compactedBloomFilter, lastkey);
                totalkeysWritten++;
                for (FileStruct filestruct : lfs)
                {
                    try
                    {
                        filestruct.advance();
                        if (filestruct.isExhausted())
                        {
                            continue;
                        }
                        pq.add(filestruct);
                        totalkeysRead++;
                    }
                    catch (Throwable ex)
                    {
                        // Ignore the exception as it might be a corrupted file
                        // in any case we have read as far as possible from it
                        // and it will be deleted after compaction.
                        logger_.warn("corrupt sstable?", ex);
                        filestruct.close();
                    }
                }
                lfs.clear();
                lastkey = null;
                if (fs != null)
                {
                    /* Add back the fs since we processed the rest of filestructs */
                    pq.add(fs);
                }
            }
        }
        if (ssTable != null)
        {
            // TODO if all the keys were the same nothing will be done here
            ssTable.closeRename(compactedBloomFilter);
            newfile = ssTable.getDataFileLocation();
        }
        lock_.writeLock().lock();
        try
        {
            for (String file : files)
View Full Code Here

        store.forceBlockingFlush();

        List<String> ssTables = table.getAllSSTablesOnDisk();
        /* the following call can happen if BF is wrong. Should return an empty buffer. */
        IFilter filter = new IdentityFilter();
        SSTable ssTable = new SSTable(ssTables.get(0), StorageService.getPartitioner());
        DataInputBuffer bufIn = filter.next("key2", "Standard1:Column1", ssTable);
        assertEquals(bufIn.getLength(), 0);
    }
View Full Code Here

        /* Figure out the keys in the index file to relocate the node */
        List<String> ssTables = Table.open(table).getAllSSTablesOnDisk();
        /* Load the indexes into memory */
        for ( String df : ssTables )
        {
          SSTable ssTable = new SSTable(df, StorageService.getPartitioner());
          ssTable.close();
        }
        /* We should have only one file since we just compacted. */       
        List<String> indexedKeys = SSTable.getIndexedKeys();       
        storageService_.relocate(indexedKeys.toArray( new String[0]) );
       
View Full Code Here

        /* Figure out the keys in the index file to relocate the node */
        List<String> ssTables = Table.open(table).getAllSSTablesOnDisk();
        /* Load the indexes into memory */
        for ( String df : ssTables )
        {
          SSTable ssTable = new SSTable(df, StorageService.getPartitioner());
          ssTable.close();
        }
        /* We should have only one file since we just compacted. */       
        List<String> indexedKeys = SSTable.getIndexedKeys();       
        storageService_.relocate(indexedKeys.toArray( new String[0]) );
       
View Full Code Here

TOP

Related Classes of org.apache.cassandra.io.SSTable$KeyPositionInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.