use of org.apache.cassandra.db.ReadQuery in project cassandra by apache.
the class CompactionAllocationTest method testTinyPartitions.
private static void testTinyPartitions(String name, int numSSTable, int sstablePartitions, boolean overlap) throws Throwable {
String ksname = "ks_" + name.toLowerCase();
SchemaLoader.createKeyspace(ksname, KeyspaceParams.simple(1), CreateTableStatement.parse("CREATE TABLE tbl (k INT PRIMARY KEY, v INT)", ksname).build());
ColumnFamilyStore cfs = Schema.instance.getColumnFamilyStoreInstance(Schema.instance.getTableMetadata(ksname, "tbl").id);
Assert.assertNotNull(cfs);
cfs.disableAutoCompaction();
List<Runnable> reads = new ArrayList<>(numSSTable * (overlap ? 1 : sstablePartitions));
measure(new Workload() {
public void setup() {
cfs.disableAutoCompaction();
String insert = String.format("INSERT INTO %s.%s (k, v) VALUES (?,?)", ksname, "tbl");
String read = String.format("SELECT * FROM %s.%s WHERE k = ?", ksname, "tbl");
SelectStatement select = (SelectStatement) QueryProcessor.parseStatement(read).prepare(ClientState.forInternalCalls());
QueryState queryState = QueryState.forInternalCalls();
for (int f = 0; f < numSSTable; f++) {
for (int p = 0; p < sstablePartitions; p++) {
int key = overlap ? p : (f * sstablePartitions) + p;
QueryProcessor.executeInternal(insert, key, key);
if (!overlap || f == 0) {
QueryOptions options = QueryProcessor.makeInternalOptions(select, new Object[] { f });
ReadQuery query = select.getQuery(options, queryState.getNowInSeconds());
reads.add(() -> runQuery(query, cfs.metadata.get()));
}
}
cfs.forceBlockingFlush();
}
Assert.assertEquals(numSSTable, cfs.getLiveSSTables().size());
}
public List<Runnable> getReads() {
return reads;
}
public ColumnFamilyStore getCfs() {
return cfs;
}
public String name() {
return name;
}
});
}
use of org.apache.cassandra.db.ReadQuery in project cassandra by apache.
the class ViewBuilderTask method buildKey.
@SuppressWarnings("resource")
private void buildKey(DecoratedKey key) {
ReadQuery selectQuery = view.getReadQuery();
if (!selectQuery.selectsKey(key)) {
logger.trace("Skipping {}, view query filters", key);
return;
}
int nowInSec = FBUtilities.nowInSeconds();
SinglePartitionReadCommand command = view.getSelectStatement().internalReadForView(key, nowInSec);
// We're rebuilding everything from what's on disk, so we read everything, consider that as new updates
// and pretend that there is nothing pre-existing.
UnfilteredRowIterator empty = UnfilteredRowIterators.noRowsIterator(baseCfs.metadata(), key, Rows.EMPTY_STATIC_ROW, DeletionTime.LIVE, false);
try (ReadExecutionController orderGroup = command.executionController();
UnfilteredRowIterator data = UnfilteredPartitionIterators.getOnlyElement(command.executeLocally(orderGroup), command)) {
Iterator<Collection<Mutation>> mutations = baseCfs.keyspace.viewManager.forTable(baseCfs.metadata.id).generateViewUpdates(Collections.singleton(view), data, empty, nowInSec, true);
AtomicLong noBase = new AtomicLong(Long.MAX_VALUE);
mutations.forEachRemaining(m -> StorageProxy.mutateMV(key.getKey(), m, true, noBase, nanoTime()));
}
}
use of org.apache.cassandra.db.ReadQuery in project cassandra by apache.
the class CompactionAllocationTest method testMediumPartitions.
private static void testMediumPartitions(String name, int numSSTable, int sstablePartitions, boolean overlap, boolean overlapCK) throws Throwable {
String ksname = "ks_" + name.toLowerCase();
SchemaLoader.createKeyspace(ksname, KeyspaceParams.simple(1), CreateTableStatement.parse("CREATE TABLE tbl (k text, c text, v1 text, v2 text, v3 text, v4 text, PRIMARY KEY (k, c))", ksname).build());
ColumnFamilyStore cfs = Schema.instance.getColumnFamilyStoreInstance(Schema.instance.getTableMetadata(ksname, "tbl").id);
Assert.assertNotNull(cfs);
cfs.disableAutoCompaction();
int rowsPerPartition = 200;
List<Runnable> reads = new ArrayList<>(numSSTable * (overlap ? 1 : sstablePartitions));
measure(new Workload() {
public void setup() {
cfs.disableAutoCompaction();
String insert = String.format("INSERT INTO %s.%s (k, c, v1, v2, v3, v4) VALUES (?, ?, ?, ?, ?, ?)", ksname, "tbl");
String read = String.format("SELECT * FROM %s.%s WHERE k = ?", ksname, "tbl");
SelectStatement select = (SelectStatement) QueryProcessor.parseStatement(read).prepare(ClientState.forInternalCalls());
QueryState queryState = QueryState.forInternalCalls();
for (int f = 0; f < numSSTable; f++) {
for (int p = 0; p < sstablePartitions; p++) {
String key = String.format("%08d", overlap ? p : (f * sstablePartitions) + p);
for (int r = 0; r < rowsPerPartition; r++) {
QueryProcessor.executeInternal(insert, key, makeRandomString(6, overlapCK ? r : -1), makeRandomString(8), makeRandomString(8), makeRandomString(8), makeRandomString(8));
}
if (!overlap || f == 0) {
QueryOptions options = QueryProcessor.makeInternalOptions(select, new Object[] { key });
ReadQuery query = select.getQuery(options, queryState.getNowInSeconds());
reads.add(() -> runQuery(query, cfs.metadata.get()));
}
}
cfs.forceBlockingFlush();
}
Assert.assertEquals(numSSTable, cfs.getLiveSSTables().size());
}
public ColumnFamilyStore getCfs() {
return cfs;
}
public List<Runnable> getReads() {
return reads;
}
public String name() {
return name;
}
});
}
use of org.apache.cassandra.db.ReadQuery in project cassandra by apache.
the class CompactionAllocationTest method testWidePartitions.
private static void testWidePartitions(String name, int numSSTable, int sstablePartitions, boolean overlap, boolean overlapCK) throws Throwable {
String ksname = "ks_" + name.toLowerCase();
SchemaLoader.createKeyspace(ksname, KeyspaceParams.simple(1), CreateTableStatement.parse("CREATE TABLE tbl (k text, c text, v1 text, v2 text, v3 text, v4 text, PRIMARY KEY (k, c))", ksname).build());
ColumnFamilyStore cfs = Schema.instance.getColumnFamilyStoreInstance(Schema.instance.getTableMetadata(ksname, "tbl").id);
Assert.assertNotNull(cfs);
cfs.disableAutoCompaction();
int rowWidth = 100;
int rowsPerPartition = 1000;
List<Runnable> reads = new ArrayList<>(numSSTable * (overlap ? 1 : sstablePartitions));
measure(new Workload() {
public void setup() {
cfs.disableAutoCompaction();
String insert = String.format("INSERT INTO %s.%s (k, c, v1, v2, v3, v4) VALUES (?, ?, ?, ?, ?, ?)", ksname, "tbl");
String read = String.format("SELECT * FROM %s.%s WHERE k = ?", ksname, "tbl");
SelectStatement select = (SelectStatement) QueryProcessor.parseStatement(read).prepare(ClientState.forInternalCalls());
QueryState queryState = QueryState.forInternalCalls();
for (int f = 0; f < numSSTable; f++) {
for (int p = 0; p < sstablePartitions; p++) {
String key = String.format("%08d", overlap ? p : (f * sstablePartitions) + p);
for (int r = 0; r < rowsPerPartition; r++) {
QueryProcessor.executeInternal(insert, key, makeRandomString(6, overlapCK ? r : -1), makeRandomString(rowWidth >> 2), makeRandomString(rowWidth >> 2), makeRandomString(rowWidth >> 2), makeRandomString(rowWidth >> 2));
}
if (!overlap || f == 0) {
QueryOptions options = QueryProcessor.makeInternalOptions(select, new Object[] { key });
ReadQuery query = select.getQuery(options, queryState.getNowInSeconds());
reads.add(() -> runQuery(query, cfs.metadata.get()));
}
}
cfs.forceBlockingFlush();
}
Assert.assertEquals(numSSTable, cfs.getLiveSSTables().size());
}
public ColumnFamilyStore getCfs() {
return cfs;
}
public List<Runnable> getReads() {
return reads;
}
public String name() {
return name;
}
});
}
use of org.apache.cassandra.db.ReadQuery in project cassandra by apache.
the class MessageSerializationPropertyTest method withTable.
private static void withTable(SchemaProvider schema, Message<?> message, Consumer<TableMetadata> fn) {
TableMetadata metadata = null;
if (message.payload instanceof ReadQuery)
metadata = ((ReadQuery) message.payload).metadata();
if (metadata != null)
Mockito.when(schema.getTableMetadata(metadata.id)).thenReturn(metadata);
fn.accept(metadata);
if (metadata != null)
Mockito.when(schema.getTableMetadata(metadata.id)).thenReturn(null);
}
Aggregations