Search in sources :

Example 6 with ColumnDefinition

use of org.apache.cassandra.config.ColumnDefinition in project eiger by wlloyd.

the class MultiDcCops2Test method setup.

@BeforeClass
public static void setup() throws IOException, InterruptedException, ConfigurationException, InvalidRequestException, SchemaDisagreementException, TException {
    Integer numDatacenters = Integer.getInteger("cassandra.multiDcTest.numDatacenters");
    assert numDatacenters != null : "You must set the numDatacenters to run the multiDc Tests";
    Integer nodesPerDatacenter = Integer.getInteger("cassandra.multiDcTest.nodesPerDatacenter");
    assert nodesPerDatacenter != null : "You must set nodesPerDatacenter to run the multiDc Tests";
    //Create a keyspace with a replication factor of 1 for each datacenter
    TTransport tr = new TFramedTransport(new TSocket("127.0.0.1", DEFAULT_THRIFT_PORT));
    TProtocol proto = new TBinaryProtocol(tr);
    Cassandra.Client client = new Cassandra.Client(proto);
    tr.open();
    //set the replication factor to 1 for each datacenter
    Map<String, String> ntsOptions = new HashMap<String, String>();
    assert numDatacenters > 0;
    for (int i = 0; i < numDatacenters; ++i) {
        ntsOptions.put("DC" + i, "1");
    }
    //We'll use the same set of columns as is used in the EmbeddedCassandraService
    // and we'll set the index type to KEYS so thrift doesn't complain
    Map<String, CFMetaData> cfDefs = schemaDefinition().iterator().next().cfMetaData();
    for (Entry<String, CFMetaData> cfEntry : cfDefs.entrySet()) {
        assert cfEntry.getKey() == cfEntry.getValue().cfName;
        for (ColumnDefinition colDef : cfEntry.getValue().getColumn_metadata().values()) {
            colDef.setIndexType(IndexType.KEYS, null);
        }
        cfEntry.getValue().readRepairChance(0);
    }
    KSMetaData keyspace1 = KSMetaData.testMetadataNotDurable("Keyspace1", NetworkTopologyStrategy.class, ntsOptions, cfDefs.values());
    client.system_add_keyspace(keyspace1.toThrift());
    //setup the normal test
    HashMap<String, Integer> localServerIPAndPorts = new HashMap<String, Integer>();
    for (int i = 1; i <= nodesPerDatacenter; ++i) {
        localServerIPAndPorts.put("127.0.0." + i, DEFAULT_THRIFT_PORT);
    }
    List<Map<String, Integer>> dcToServerIPAndPorts = new ArrayList();
    for (int dc = 0; dc < numDatacenters; ++dc) {
        HashMap<String, Integer> serverIPAndPorts = new HashMap<String, Integer>();
        for (int i = 0; i < nodesPerDatacenter; ++i) {
            int ipIndex = 1 + dc * nodesPerDatacenter + i;
            serverIPAndPorts.put("127.0.0." + ipIndex, DEFAULT_THRIFT_PORT);
        }
        dcToServerIPAndPorts.add(serverIPAndPorts);
    }
    Cops2Test.setLocalServerIPAndPorts(localServerIPAndPorts);
    Cops2Test.setDcToServerIPAndPorts(dcToServerIPAndPorts);
    Cops2Test.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM);
    //wait for the keyspace to show up at all nodes
    HashMap<String, Integer> allServerIPAndPorts = new HashMap<String, Integer>();
    for (int i = 1; i <= numDatacenters * nodesPerDatacenter; ++i) {
        allServerIPAndPorts.put("127.0.0." + i, DEFAULT_THRIFT_PORT);
    }
    waitForKeyspacePropagation(allServerIPAndPorts, "Keyspace1");
}
Also used : ColumnDefinition(org.apache.cassandra.config.ColumnDefinition) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) CFMetaData(org.apache.cassandra.config.CFMetaData) KSMetaData(org.apache.cassandra.config.KSMetaData) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket) BeforeClass(org.junit.BeforeClass)

Example 7 with ColumnDefinition

use of org.apache.cassandra.config.ColumnDefinition in project eiger by wlloyd.

the class ColumnFamilyStoreTest method testIndexCreate.

@Test
public void testIndexCreate() throws IOException, ConfigurationException, InterruptedException, ExecutionException {
    Table table = Table.open("Keyspace1");
    // create a row and update the birthdate value, test that the index query fetches the new version
    RowMutation rm;
    rm = new RowMutation("Keyspace1", ByteBufferUtil.bytes("k1"));
    rm.add(new QueryPath("Indexed2", null, ByteBufferUtil.bytes("birthdate")), ByteBufferUtil.bytes(1L), 1);
    rm.apply();
    ColumnFamilyStore cfs = table.getColumnFamilyStore("Indexed2");
    ColumnDefinition old = cfs.metadata.getColumn_metadata().get(ByteBufferUtil.bytes("birthdate"));
    ColumnDefinition cd = new ColumnDefinition(old.name, old.getValidator(), IndexType.KEYS, null, "birthdate_index");
    Future<?> future = cfs.indexManager.addIndexedColumn(cd);
    future.get();
    // we had a bug (CASSANDRA-2244) where index would get created but not flushed -- check for that
    assert cfs.indexManager.getIndexForColumn(cd.name).getIndexCfs().getSSTables().size() > 0;
    queryBirthdate(table);
    // validate that drop clears it out & rebuild works (CASSANDRA-2320)
    SecondaryIndex indexedCfs = cfs.indexManager.getIndexForColumn(ByteBufferUtil.bytes("birthdate"));
    cfs.indexManager.removeIndexedColumn(ByteBufferUtil.bytes("birthdate"));
    assert !indexedCfs.isIndexBuilt(ByteBufferUtil.bytes("birthdate"));
    // rebuild & re-query
    future = cfs.indexManager.addIndexedColumn(cd);
    future.get();
    queryBirthdate(table);
}
Also used : SSTable(org.apache.cassandra.io.sstable.SSTable) SecondaryIndex(org.apache.cassandra.db.index.SecondaryIndex) ColumnDefinition(org.apache.cassandra.config.ColumnDefinition) Test(org.junit.Test)

Example 8 with ColumnDefinition

use of org.apache.cassandra.config.ColumnDefinition in project stargate-core by tuplejump.

the class RowIndexSupport method loadOldRow.

private void loadOldRow(DecoratedKey dk, ByteBuffer pkBuf, List<Field> fields) {
    CellName clusteringKey = tableMapper.makeClusteringKey(pkBuf);
    Composite start = tableMapper.start(clusteringKey);
    Composite end = tableMapper.end(start);
    ColumnSlice columnSlice = new ColumnSlice(start, end);
    SliceQueryFilter sliceQueryFilter = new SliceQueryFilter(columnSlice, false, Integer.MAX_VALUE);
    QueryFilter queryFilter = new QueryFilter(dk, tableMapper.table.name, sliceQueryFilter, new Date().getTime());
    ColumnFamily columnFamily = tableMapper.table.getColumnFamily(queryFilter);
    Map<CellName, ColumnFamily> fullSlice = tableMapper.getRows(columnFamily);
    ColumnFamily oldDocument = fullSlice.get(clusteringKey);
    for (Cell cell : oldDocument) {
        CellName cellName = cell.name();
        ColumnIdentifier cql3ColName = cellName.cql3ColumnName(tableMapper.cfMetaData);
        String actualColName = cql3ColName.toString();
        ColumnDefinition columnDefinition = tableMapper.cfMetaData.getColumnDefinition(cql3ColName);
        if (options.shouldIndex(actualColName)) {
            addFields(cell, actualColName, columnDefinition, fields);
        }
    }
}
Also used : SliceQueryFilter(org.apache.cassandra.db.filter.SliceQueryFilter) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) Composite(org.apache.cassandra.db.composites.Composite) ColumnSlice(org.apache.cassandra.db.filter.ColumnSlice) SliceQueryFilter(org.apache.cassandra.db.filter.SliceQueryFilter) ColumnIdentifier(org.apache.cassandra.cql3.ColumnIdentifier) CellName(org.apache.cassandra.db.composites.CellName) ColumnDefinition(org.apache.cassandra.config.ColumnDefinition)

Example 9 with ColumnDefinition

use of org.apache.cassandra.config.ColumnDefinition in project stargate-core by tuplejump.

the class RowIndexSupport method addClusteringKeyFields.

private void addClusteringKeyFields(CellName clusteringKey, long timestamp, IndexEntryBuilder builder) {
    for (Map.Entry<String, ColumnDefinition> entry : options.clusteringKeysIndexed.entrySet()) {
        ByteBuffer value = clusteringKey.get(entry.getValue().position());
        addKeyField(timestamp, entry, value, builder);
    }
}
Also used : ByteBuffer(java.nio.ByteBuffer) ColumnDefinition(org.apache.cassandra.config.ColumnDefinition)

Example 10 with ColumnDefinition

use of org.apache.cassandra.config.ColumnDefinition in project stargate-core by tuplejump.

the class RowIndexSupport method addPartitionKeyFields.

private void addPartitionKeyFields(ByteBuffer rowKey, long timestamp, IndexEntryBuilder builder) {
    CType keyCType = tableMapper.cfMetaData.getKeyValidatorAsCType();
    Composite compoundRowKey = keyCType.fromByteBuffer(rowKey);
    for (Map.Entry<String, ColumnDefinition> entry : options.partitionKeysIndexed.entrySet()) {
        ByteBuffer value = compoundRowKey.get(entry.getValue().position());
        addKeyField(timestamp, entry, value, builder);
    }
}
Also used : Composite(org.apache.cassandra.db.composites.Composite) CType(org.apache.cassandra.db.composites.CType) ByteBuffer(java.nio.ByteBuffer) ColumnDefinition(org.apache.cassandra.config.ColumnDefinition)

Aggregations

ColumnDefinition (org.apache.cassandra.config.ColumnDefinition)17 ByteBuffer (java.nio.ByteBuffer)5 CFMetaData (org.apache.cassandra.config.CFMetaData)3 IOException (java.io.IOException)2 CellName (org.apache.cassandra.db.composites.CellName)2 Composite (org.apache.cassandra.db.composites.Composite)2 Options (com.tuplejump.stargate.lucene.Options)1 Properties (com.tuplejump.stargate.lucene.Properties)1 Type (com.tuplejump.stargate.lucene.Type)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConfigurationException (org.apache.cassandra.config.ConfigurationException)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 KSMetaData (org.apache.cassandra.config.KSMetaData)1 CQL3Type (org.apache.cassandra.cql3.CQL3Type)1 ColumnIdentifier (org.apache.cassandra.cql3.ColumnIdentifier)1 CType (org.apache.cassandra.db.composites.CType)1 CellNameType (org.apache.cassandra.db.composites.CellNameType)1 ColumnSlice (org.apache.cassandra.db.filter.ColumnSlice)1 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)1