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());
}
}
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);
}
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;
}
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"));
}
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;
}
Aggregations