Search in sources :

Example 11 with IColumn

use of org.apache.cassandra.db.IColumn in project brisk by riptano.

the class CassandraStorage method getNext.

@Override
public Tuple getNext() throws IOException {
    try {
        // load the next pair
        if (!reader.nextKeyValue())
            return null;
        CfDef cfDef = getCfDef();
        ByteBuffer key = (ByteBuffer) reader.getCurrentKey();
        SortedMap<ByteBuffer, IColumn> cf = (SortedMap<ByteBuffer, IColumn>) reader.getCurrentValue();
        assert key != null && cf != null;
        // and wrap it in a tuple
        Tuple tuple = TupleFactory.getInstance().newTuple(2);
        ArrayList<Tuple> columns = new ArrayList<Tuple>();
        tuple.set(0, new DataByteArray(key.array(), key.position() + key.arrayOffset(), key.limit() + key.arrayOffset()));
        for (Map.Entry<ByteBuffer, IColumn> entry : cf.entrySet()) {
            columns.add(columnToTuple(entry.getKey(), entry.getValue(), cfDef));
        }
        tuple.set(1, new DefaultDataBag(columns));
        return tuple;
    } catch (InterruptedException e) {
        throw new IOException(e.getMessage());
    }
}
Also used : IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) IColumn(org.apache.cassandra.db.IColumn)

Example 12 with IColumn

use of org.apache.cassandra.db.IColumn in project eiger by wlloyd.

the class MigrationManager method applyMigrations.

/**
     * gets called during startup if we notice a mismatch between the current migration version and the one saved. This
     * can only happen as a result of the commit log recovering schema updates, which overwrites lastVersionId.
     * 
     * This method silently eats IOExceptions thrown by Migration.apply() as a result of applying a migration out of
     * order.
     */
public static void applyMigrations(final UUID from, final UUID to) throws IOException {
    List<Future<?>> updates = new ArrayList<Future<?>>();
    Collection<IColumn> migrations = Migration.getLocalMigrations(from, to);
    for (IColumn col : migrations) {
        // assuming MessagingService.version_ is a bit of a risk, but you're playing with fire if you purposefully
        // take down a node to upgrade it during the middle of a schema update.
        final Migration migration = Migration.deserialize(col.value(), MessagingService.version_);
        Future<?> update = StageManager.getStage(Stage.MIGRATION).submit(new Runnable() {

            public void run() {
                try {
                    migration.apply();
                } catch (ConfigurationException ex) {
                    // this happens if we try to apply something that's already been applied. ignore and proceed.
                    logger.debug("Migration not applied " + ex.getMessage());
                } catch (IOException ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
        updates.add(update);
    }
    // wait on all the updates before proceeding.
    for (Future<?> f : updates) {
        try {
            f.get();
        } catch (InterruptedException e) {
            throw new IOException(e);
        } catch (ExecutionException e) {
            throw new IOException(e);
        }
    }
    // we don't need to send rpcs, but we need to update gossip
    passiveAnnounce(to);
}
Also used : Migration(org.apache.cassandra.db.migration.Migration) IColumn(org.apache.cassandra.db.IColumn) ConfigurationException(org.apache.cassandra.config.ConfigurationException) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException)

Example 13 with IColumn

use of org.apache.cassandra.db.IColumn in project eiger by wlloyd.

the class SimpleSliceReader method computeNext.

protected IColumn computeNext() {
    if (i++ >= columns)
        return endOfData();
    IColumn column;
    try {
        file.reset(mark);
        column = emptyColumnFamily.getColumnSerializer().deserialize(file);
    } catch (IOException e) {
        throw new RuntimeException("error reading " + i + " of " + columns, e);
    }
    if (finishColumn.remaining() > 0 && comparator.compare(column.name(), finishColumn) > 0)
        return endOfData();
    mark = file.mark();
    return column;
}
Also used : IColumn(org.apache.cassandra.db.IColumn) IOException(java.io.IOException)

Example 14 with IColumn

use of org.apache.cassandra.db.IColumn in project eiger by wlloyd.

the class SSTableImportTest method testImportSuperCf.

@Test
public void testImportSuperCf() throws IOException, ParseException, URISyntaxException {
    String jsonUrl = resourcePath("SuperCF.json");
    File tempSS = tempSSTableFile("Keyspace1", "Super4");
    SSTableImport.importJson(jsonUrl, "Keyspace1", "Super4", tempSS.getPath());
    // Verify results
    SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
    QueryFilter qf = QueryFilter.getNamesFilter(Util.dk("rowA"), new QueryPath("Super4", null, null), ByteBufferUtil.bytes("superA"));
    ColumnFamily cf = qf.getSSTableColumnIterator(reader).getColumnFamily();
    IColumn superCol = cf.getColumn(ByteBufferUtil.bytes("superA"));
    assert superCol != null;
    assert superCol.getSubColumns().size() > 0;
    IColumn subColumn = superCol.getSubColumn(ByteBufferUtil.bytes("636f6c4141"));
    assert subColumn.value().equals(hexToBytes("76616c75654141"));
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IColumn(org.apache.cassandra.db.IColumn) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 15 with IColumn

use of org.apache.cassandra.db.IColumn in project eiger by wlloyd.

the class SSTableImportTest method testImportCounterCf.

@Test
public void testImportCounterCf() throws IOException, URISyntaxException {
    // Import JSON to temp SSTable file
    String jsonUrl = resourcePath("CounterCF.json");
    File tempSS = tempSSTableFile("Keyspace1", "Counter1");
    SSTableImport.importJson(jsonUrl, "Keyspace1", "Counter1", tempSS.getPath());
    // Verify results
    SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
    QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Counter1"));
    IColumnIterator iter = qf.getSSTableColumnIterator(reader);
    ColumnFamily cf = iter.getColumnFamily();
    while (iter.hasNext()) cf.addColumn(iter.next());
    IColumn c = cf.getColumn(ByteBufferUtil.bytes("colAA"));
    assert c instanceof CounterColumn : c;
    assert ((CounterColumn) c).total() == 42;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IColumn(org.apache.cassandra.db.IColumn) IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator) CounterColumn(org.apache.cassandra.db.CounterColumn) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Aggregations

IColumn (org.apache.cassandra.db.IColumn)20 ColumnFamily (org.apache.cassandra.db.ColumnFamily)8 QueryPath (org.apache.cassandra.db.filter.QueryPath)6 Test (org.junit.Test)6 ByteBuffer (java.nio.ByteBuffer)5 File (java.io.File)4 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)4 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)4 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)4 IOException (java.io.IOException)3 Column (org.apache.cassandra.db.Column)3 IColumnIterator (org.apache.cassandra.db.columniterator.IColumnIterator)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)2 DecoratedKey (org.apache.cassandra.db.DecoratedKey)2 DeletedColumn (org.apache.cassandra.db.DeletedColumn)2 ExpiringColumn (org.apache.cassandra.db.ExpiringColumn)2 Row (org.apache.cassandra.db.Row)2 RowMutation (org.apache.cassandra.db.RowMutation)2 Table (org.apache.cassandra.db.Table)2 AbstractType (org.apache.cassandra.db.marshal.AbstractType)2