Package org.apache.cassandra.io

Examples of org.apache.cassandra.io.SSTableWriter


    {
        File tempSS = createTemporarySSTable("Keyspace1", "Standard1");
        ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Standard1");
        IPartitioner<?> partitioner = DatabaseDescriptor.getPartitioner();
        DataOutputBuffer dob = new DataOutputBuffer();
        SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2, partitioner);
       
        // Add rowA
        cfamily.addColumn(new QueryPath("Standard1", null, "colA".getBytes()), "valA".getBytes(), 1, false);
        ColumnFamily.serializer().serializeWithIndexes(cfamily, dob);
        writer.append(partitioner.decorateKey("rowA"), dob);
        dob.reset();
        cfamily.clear();
       
        // Add rowB
        cfamily.addColumn(new QueryPath("Standard1", null, "colB".getBytes()), "valB".getBytes(), 1, false);
        ColumnFamily.serializer().serializeWithIndexes(cfamily, dob);
        writer.append(partitioner.decorateKey("rowB"), dob);
        dob.reset();
        cfamily.clear();
    
        SSTableReader reader = writer.closeAndOpenReader(0);
       
        // Export to JSON and verify
        File tempJson = File.createTempFile("Standard1", ".json");
        SSTableExport.export(reader, new PrintStream(tempJson.getPath()));
       
View Full Code Here


    {
        File tempSS = createTemporarySSTable("Keyspace1", "Super4");
        ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Super4");
        IPartitioner<?> partitioner = DatabaseDescriptor.getPartitioner();
        DataOutputBuffer dob = new DataOutputBuffer();
        SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2, partitioner);
       
        // Add rowA
        cfamily.addColumn(new QueryPath("Super4", "superA".getBytes(), "colA".getBytes()), "valA".getBytes(), 1, false);
        ColumnFamily.serializer().serializeWithIndexes(cfamily, dob);
        writer.append(partitioner.decorateKey("rowA"), dob);
        dob.reset();
        cfamily.clear();
       
        // Add rowB
        cfamily.addColumn(new QueryPath("Super4", "superB".getBytes(), "colB".getBytes()), "valB".getBytes(), 1, false);
        ColumnFamily.serializer().serializeWithIndexes(cfamily, dob);
        writer.append(partitioner.decorateKey("rowB"), dob);
        dob.reset();
        cfamily.clear();
    
        SSTableReader reader = writer.closeAndOpenReader(0);
       
        // Export to JSON and verify
        File tempJson = File.createTempFile("Super4", ".json");
        SSTableExport.export(reader, new PrintStream(tempJson.getPath()));
       
View Full Code Here

    {
        File tempSS = createTemporarySSTable("Keyspace1", "Standard1");
        ColumnFamily cfamily = ColumnFamily.create("Keyspace1", "Standard1");
        IPartitioner<?> partitioner = DatabaseDescriptor.getPartitioner();
        DataOutputBuffer dob = new DataOutputBuffer();
        SSTableWriter writer = new SSTableWriter(tempSS.getPath(), 2, partitioner);
       
        // Add rowA
        cfamily.addColumn(new QueryPath("Standard1", null, "name".getBytes()), "val".getBytes(), 1, false);
        ColumnFamily.serializer().serializeWithIndexes(cfamily, dob);
        writer.append(partitioner.decorateKey("rowA"), dob);
        dob.reset();
        cfamily.clear();
       
        SSTableReader reader = writer.closeAndOpenReader(0);
       
        // Export to JSON and verify
        File tempJson = File.createTempFile("Standard1", ".json");
        SSTableExport.export(reader, new PrintStream(tempJson.getPath()));
       
View Full Code Here


    private SSTableReader writeSortedContents() throws IOException
    {
        logger.info("Writing " + this);
        SSTableWriter writer = new SSTableWriter(cfs.getFlushPath(), columnFamilies.size(), StorageService.getPartitioner());

        DataOutputBuffer buffer = new DataOutputBuffer();
        for (Map.Entry<DecoratedKey, ColumnFamily> entry : columnFamilies.entrySet())
        {
            buffer.reset();
            /* serialize the cf with column indexes */
            ColumnFamily.serializer().serializeWithIndexes(entry.getValue(), buffer);
            /* Now write the key and value to disk */
            writer.append(entry.getKey(), buffer);
        }

        SSTableReader ssTable = writer.closeAndOpenReader();
        logger.info("Completed flushing " + ssTable.getFilename());
        return ssTable;
    }
View Full Code Here

    public SSTableReader writeSortedContents(List<DecoratedKey> sortedKeys) throws IOException
    {
        logger_.info("Writing " + this);
        ColumnFamilyStore cfStore = Table.open(table_).getColumnFamilyStore(cfName_);
        SSTableWriter writer = new SSTableWriter(cfStore.getTempSSTablePath(), columnFamilies_.size(), StorageService.getPartitioner());

        DataOutputBuffer buffer = new DataOutputBuffer();
        for (DecoratedKey key : sortedKeys)
        {
            buffer.reset();
            ColumnFamily columnFamily = columnFamilies_.get(key);
            /* serialize the cf with column indexes */
            ColumnFamily.serializer().serializeWithIndexes(columnFamily, buffer);
            /* Now write the key and value to disk */
            writer.append(key, buffer);
        }

        SSTableReader ssTable = writer.closeAndOpenReader(DatabaseDescriptor.getKeysCachedFraction(table_));
        isFlushed_ = true;
        logger_.info("Completed flushing " + ssTable.getFilename());
        return ssTable;
    }
View Full Code Here

       
        try
        {
            JSONObject json = (JSONObject)JSONValue.parseWithException(new FileReader(jsonFile));
           
            SSTableWriter writer = new SSTableWriter(ssTablePath, json.size(), partitioner);
            List<DecoratedKey<?>> decoratedKeys = new ArrayList<DecoratedKey<?>>();
           
            for (String key : (Set<String>)json.keySet())
                decoratedKeys.add(partitioner.decorateKey(key));
            Collections.sort(decoratedKeys);

            for (DecoratedKey<?> rowKey : decoratedKeys)
            {
                if (cfType.equals("Super"))
                    addToSuperCF((JSONObject)json.get(rowKey.key), cfamily);
                else
                    addToStandardCF((JSONArray)json.get(rowKey.key), cfamily);
                          
                ColumnFamily.serializer().serializeWithIndexes(cfamily, dob);
                writer.append(rowKey, dob);
                dob.reset();
                cfamily.clear();
            }
           
            writer.closeAndOpenReader(0);
        }
        catch (ClassCastException cce)
        {
            throw new RuntimeException("Invalid JSON input, or incorrect column family.", cce);
        }
View Full Code Here

    public SSTableReader writeSortedContents(List<DecoratedKey> sortedKeys) throws IOException
    {
        logger_.info("Writing " + this);
        ColumnFamilyStore cfStore = Table.open(table_).getColumnFamilyStore(cfName_);
        String path = cfStore.getTempSSTablePath();
        SSTableWriter writer = new SSTableWriter(path, sortedKeys.size(), StorageService.getPartitioner());

        for (DecoratedKey key : sortedKeys)
        {
            byte[] bytes = columnFamilies_.get(key);
            assert bytes.length > 0;
            writer.append(key, bytes);
        }
        SSTableReader sstable = writer.closeAndOpenReader(DatabaseDescriptor.getKeysCachedFraction(table_));
        logger_.info("Completed flushing " + writer.getFilename());
        return sstable;
    }
View Full Code Here

    public SSTableReader writeSortedContents(List<DecoratedKey> sortedKeys) throws IOException
    {
        logger_.info("Writing " + this);
        ColumnFamilyStore cfStore = Table.open(table_).getColumnFamilyStore(cfName_);
        SSTableWriter writer = new SSTableWriter(cfStore.getTempSSTablePath(), columnFamilies_.size(), StorageService.getPartitioner());

        DataOutputBuffer buffer = new DataOutputBuffer();
        for (DecoratedKey key : sortedKeys)
        {
            buffer.reset();
            ColumnFamily columnFamily = columnFamilies_.get(key);
            /* serialize the cf with column indexes */
            ColumnFamily.serializer().serializeWithIndexes(columnFamily, buffer);
            /* Now write the key and value to disk */
            writer.append(key, buffer);
        }

        SSTableReader ssTable = writer.closeAndOpenReader(DatabaseDescriptor.getKeysCachedFraction(table_));
        isFlushed_ = true;
        logger_.info("Completed flushing " + ssTable.getFilename());
        return ssTable;
    }
View Full Code Here

    public SSTableReader writeSortedContents(List<DecoratedKey> sortedKeys) throws IOException
    {
        logger_.info("Writing " + this);
        ColumnFamilyStore cfStore = Table.open(table_).getColumnFamilyStore(cfName_);
        String path = cfStore.getTempSSTablePath();
        SSTableWriter writer = new SSTableWriter(path, sortedKeys.size(), StorageService.getPartitioner());

        for (DecoratedKey key : sortedKeys)
        {
            byte[] bytes = columnFamilies_.get(key);
            assert bytes.length > 0;
            writer.append(key, bytes);
        }
        SSTableReader sstable = writer.closeAndOpenReader(DatabaseDescriptor.getKeysCachedFraction(table_));
        logger_.info("Completed flushing " + writer.getFilename());
        return sstable;
    }
View Full Code Here

    void flush(CommitLog.CommitLogContext cLogCtx) throws IOException
    {
        logger_.info("Flushing " + this);
        ColumnFamilyStore cfStore = Table.open(table_).getColumnFamilyStore(cfName_);

        SSTableWriter writer = new SSTableWriter(cfStore.getTempSSTablePath(), columnFamilies_.size(), 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();
        for (String key : orderedKeys)
        {
            buffer.reset();
            ColumnFamily columnFamily = columnFamilies_.get(key);
            if (columnFamily != null)
            {
                /* serialize the cf with column indexes */
                ColumnFamily.serializer().serializeWithIndexes(columnFamily, buffer);
                /* Now write the key and value to disk */
                writer.append(partitioner.decorateKey(key), buffer);
            }
        }
        SSTableReader ssTable = writer.closeAndOpenReader(DatabaseDescriptor.getKeysCachedFraction(table_));
        cfStore.onMemtableFlush(cLogCtx);
        cfStore.storeLocation(ssTable);
        buffer.close();
        isFlushed_ = true;
        logger_.info("Completed flushing " + this);
View Full Code Here

TOP

Related Classes of org.apache.cassandra.io.SSTableWriter

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.