Search in sources :

Example 1 with ReadQuery

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;
        }
    });
}
Also used : SelectStatement(org.apache.cassandra.cql3.statements.SelectStatement) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) QueryState(org.apache.cassandra.service.QueryState) QueryOptions(org.apache.cassandra.cql3.QueryOptions) ReadQuery(org.apache.cassandra.db.ReadQuery)

Example 2 with ReadQuery

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()));
    }
}
Also used : UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) ReadExecutionController(org.apache.cassandra.db.ReadExecutionController) AtomicLong(java.util.concurrent.atomic.AtomicLong) SinglePartitionReadCommand(org.apache.cassandra.db.SinglePartitionReadCommand) Collection(java.util.Collection) ReadQuery(org.apache.cassandra.db.ReadQuery)

Example 3 with ReadQuery

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;
        }
    });
}
Also used : ArrayList(java.util.ArrayList) QueryState(org.apache.cassandra.service.QueryState) QueryOptions(org.apache.cassandra.cql3.QueryOptions) SelectStatement(org.apache.cassandra.cql3.statements.SelectStatement) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) List(java.util.List) ArrayList(java.util.ArrayList) ReadQuery(org.apache.cassandra.db.ReadQuery)

Example 4 with ReadQuery

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;
        }
    });
}
Also used : ArrayList(java.util.ArrayList) QueryState(org.apache.cassandra.service.QueryState) QueryOptions(org.apache.cassandra.cql3.QueryOptions) SelectStatement(org.apache.cassandra.cql3.statements.SelectStatement) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) List(java.util.List) ArrayList(java.util.ArrayList) ReadQuery(org.apache.cassandra.db.ReadQuery)

Example 5 with ReadQuery

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);
}
Also used : TableMetadata(org.apache.cassandra.schema.TableMetadata) ReadQuery(org.apache.cassandra.db.ReadQuery)

Aggregations

ReadQuery (org.apache.cassandra.db.ReadQuery)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 QueryOptions (org.apache.cassandra.cql3.QueryOptions)3 SelectStatement (org.apache.cassandra.cql3.statements.SelectStatement)3 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)3 QueryState (org.apache.cassandra.service.QueryState)3 Collection (java.util.Collection)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 ReadExecutionController (org.apache.cassandra.db.ReadExecutionController)1 SinglePartitionReadCommand (org.apache.cassandra.db.SinglePartitionReadCommand)1 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)1 TableMetadata (org.apache.cassandra.schema.TableMetadata)1