Search in sources :

Example 6 with KSMetaData

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();
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) KSMetaData(org.apache.cassandra.config.KSMetaData) ByteBuffer(java.nio.ByteBuffer)

Example 7 with KSMetaData

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;
}
Also used : Schema(org.apache.avro.Schema) ByteBuffer(java.nio.ByteBuffer) QueryPath(org.apache.cassandra.db.filter.QueryPath) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) KSMetaData(org.apache.cassandra.config.KSMetaData)

Example 8 with KSMetaData

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);
}
Also used : KSMetaData(org.apache.cassandra.config.KSMetaData)

Example 9 with KSMetaData

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);
}
Also used : KSMetaData(org.apache.cassandra.config.KSMetaData)

Example 10 with KSMetaData

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;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) ArrayList(java.util.ArrayList) KSMetaData(org.apache.cassandra.config.KSMetaData)

Aggregations

KSMetaData (org.apache.cassandra.config.KSMetaData)10 ByteBuffer (java.nio.ByteBuffer)3 QueryPath (org.apache.cassandra.db.filter.QueryPath)3 CFMetaData (org.apache.cassandra.config.CFMetaData)2 ConfigurationException (org.apache.cassandra.exceptions.ConfigurationException)2 DataOutputStream (java.io.DataOutputStream)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Schema (org.apache.avro.Schema)1 ColumnDefinition (org.apache.cassandra.config.ColumnDefinition)1 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 TFramedTransport (org.apache.thrift.transport.TFramedTransport)1 TSocket (org.apache.thrift.transport.TSocket)1 TTransport (org.apache.thrift.transport.TTransport)1 BeforeClass (org.junit.BeforeClass)1