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