use of org.apache.cassandra.config.KSMetaData in project eiger by wlloyd.
the class DefsTable method dumpToStorage.
/** dumps current keyspace definitions to storage */
public static synchronized void dumpToStorage(UUID version) throws IOException {
final ByteBuffer versionKey = Migration.toUTF8Bytes(version);
// build a list of keyspaces
Collection<String> ksnames = org.apache.cassandra.config.Schema.instance.getNonSystemTables();
// persist keyspaces under new version
RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, versionKey);
long now = System.currentTimeMillis();
for (String ksname : ksnames) {
KSMetaData ksm = org.apache.cassandra.config.Schema.instance.getTableDefinition(ksname);
rm.add(new QueryPath(Migration.SCHEMA_CF, null, ByteBufferUtil.bytes(ksm.name)), SerDeUtils.serialize(ksm.toAvro()), now);
}
// add the schema
rm.add(new QueryPath(Migration.SCHEMA_CF, null, DEFINITION_SCHEMA_COLUMN_NAME), ByteBufferUtil.bytes(org.apache.cassandra.db.migration.avro.KsDef.SCHEMA$.toString()), now);
rm.apply();
// apply new version
rm = new RowMutation(Table.SYSTEM_TABLE, Migration.LAST_MIGRATION_KEY);
rm.add(new QueryPath(Migration.SCHEMA_CF, null, Migration.LAST_MIGRATION_KEY), ByteBuffer.wrap(UUIDGen.decompose(version)), now);
rm.apply();
}
use of org.apache.cassandra.config.KSMetaData in project eiger by wlloyd.
the class DefsTable method loadFromStorage.
/** loads a version of keyspace definitions from storage */
public static synchronized Collection<KSMetaData> loadFromStorage(UUID version) throws IOException {
DecoratedKey vkey = StorageService.getPartitioner().decorateKey(Migration.toUTF8Bytes(version));
Table defs = Table.open(Table.SYSTEM_TABLE);
ColumnFamilyStore cfStore = defs.getColumnFamilyStore(Migration.SCHEMA_CF);
QueryFilter filter = QueryFilter.getIdentityFilter(vkey, new QueryPath(Migration.SCHEMA_CF));
ColumnFamily cf = cfStore.getColumnFamily(filter);
IColumn avroschema = cf.getColumn(DEFINITION_SCHEMA_COLUMN_NAME);
if (avroschema == null)
// TODO: more polite way to handle this?
throw new RuntimeException("Cannot read system table! Are you upgrading a pre-release version?");
ByteBuffer value = avroschema.value();
Schema schema = Schema.parse(ByteBufferUtil.string(value));
// deserialize keyspaces using schema
Collection<KSMetaData> keyspaces = new ArrayList<KSMetaData>();
for (IColumn column : cf.getSortedColumns()) {
if (column.name().equals(DEFINITION_SCHEMA_COLUMN_NAME))
continue;
org.apache.cassandra.db.migration.avro.KsDef ks = SerDeUtils.deserialize(schema, column.value(), new org.apache.cassandra.db.migration.avro.KsDef());
keyspaces.add(KSMetaData.fromAvro(ks));
}
return keyspaces;
}
use of org.apache.cassandra.config.KSMetaData in project eiger by wlloyd.
the class RowMutation method apply.
/*
* This is equivalent to calling commit. Applies the changes to
* to the table that is obtained by calling Table.open().
*/
@Override
public void apply() throws IOException {
KSMetaData ksm = Schema.instance.getTableDefinition(getTable());
Table.open(table_).apply(this, ksm.durableWrites);
}
use of org.apache.cassandra.config.KSMetaData in project eiger by wlloyd.
the class PendingTransactionMutation method apply.
/*
* This is equivalent to calling commit. Applies the changes to
* to the table that is obtained by calling Table.open().
*/
@Override
public void apply() throws IOException {
KSMetaData ksm = Schema.instance.getTableDefinition(getTable());
Table.open(table_).apply(this, ksm.durableWrites);
}
use of org.apache.cassandra.config.KSMetaData in project eiger by wlloyd.
the class Migration method makeDefinitionMutation.
/**
* Definitions are serialized as a row with a UUID key, with a magical column named DEFINITION_SCHEMA_COLUMN_NAME
* (containing the Avro Schema) and a column per keyspace. Each keyspace column contains a avro.KsDef object
* encoded with the Avro schema.
*/
final RowMutation makeDefinitionMutation(KSMetaData add, KSMetaData remove, UUID versionId) throws IOException {
// collect all keyspaces, while removing 'remove' and adding 'add'
List<KSMetaData> ksms = new ArrayList<KSMetaData>();
for (String tableName : schema.getNonSystemTables()) {
if (remove != null && remove.name.equals(tableName) || add != null && add.name.equals(tableName))
continue;
ksms.add(schema.getTableDefinition(tableName));
}
if (add != null)
ksms.add(add);
// wrap in mutation
RowMutation rm = new RowMutation(Table.SYSTEM_TABLE, toUTF8Bytes(versionId));
long now = LamportClock.getVersion();
// add a column for each keyspace
for (KSMetaData ksm : ksms) rm.add(new QueryPath(SCHEMA_CF, null, ByteBufferUtil.bytes(ksm.name)), SerDeUtils.serialize(ksm.toAvro()), now);
// add the schema
rm.add(new QueryPath(SCHEMA_CF, null, DefsTable.DEFINITION_SCHEMA_COLUMN_NAME), ByteBufferUtil.bytes(org.apache.cassandra.db.migration.avro.KsDef.SCHEMA$.toString()), now);
return rm;
}
Aggregations