Search in sources :

Example 76 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class SelectTest method testMixedTTLOnColumnsWide.

@Test
public void testMixedTTLOnColumnsWide() throws Throwable {
    createTable("CREATE TABLE %s (k int, c int, i int, PRIMARY KEY (k, c))");
    execute("INSERT INTO %s (k, c) VALUES (2, 2);");
    execute("INSERT INTO %s (k, c, i) VALUES (1, 1, 1) USING TTL 100;");
    execute("INSERT INTO %s (k, c) VALUES (1, 2) ;");
    execute("INSERT INTO %s (k, c, i) VALUES (1, 3, 3) USING TTL 100;");
    execute("INSERT INTO %s (k, c, i) VALUES (3, 3, 3) USING TTL 100;");
    assertRows(execute("SELECT k, c, i FROM %s "), row(1, 1, 1), row(1, 2, null), row(1, 3, 3), row(2, 2, null), row(3, 3, 3));
    UntypedResultSet rs = execute("SELECT k, c, i, ttl(i) AS name_ttl FROM %s");
    assertEquals("name_ttl", rs.metadata().get(3).name.toString());
    int i = 0;
    for (UntypedResultSet.Row row : rs) {
        if (// Every odd row has a null i/ttl
        i % 2 == 0)
            assertTrue(row.getInt("name_ttl") >= 90 && row.getInt("name_ttl") <= 100);
        else
            assertTrue(row.has("name_ttl") == false);
        i++;
    }
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Test(org.junit.Test)

Example 77 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class TTLTest method checkTTLIsCapped.

/**
 * Verify that the computed TTL is equal to the maximum allowed ttl given the
 * {@link AbstractCell#localDeletionTime()} field limitation (CASSANDRA-14092)
 */
private void checkTTLIsCapped(String field) throws Throwable {
    // TTL is computed dynamically from row expiration time, so if it is
    // equal or higher to the minimum max TTL we compute before the query
    // we are fine.
    UntypedResultSet execute = execute("SELECT ttl(" + field + ") FROM %s WHERE k = 1");
    int minMaxTTL = computeMaxTTL();
    for (UntypedResultSet.Row row : execute) {
        int ttl = row.getInt("ttl(" + field + ")");
        assert (ttl >= minMaxTTL) : "ttl must be greater than or equal to minMaxTTL, but " + ttl + " is less than " + minMaxTTL;
    }
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 78 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class BatchlogManager method processBatchlogEntries.

private void processBatchlogEntries(UntypedResultSet batches, int pageSize, RateLimiter rateLimiter) {
    int positionInPage = 0;
    ArrayList<ReplayingBatch> unfinishedBatches = new ArrayList<>(pageSize);
    Set<UUID> hintedNodes = new HashSet<>();
    Set<UUID> replayedBatches = new HashSet<>();
    Exception caughtException = null;
    int skipped = 0;
    // Sending out batches for replay without waiting for them, so that one stuck batch doesn't affect others
    for (UntypedResultSet.Row row : batches) {
        UUID id = row.getUUID("id");
        int version = row.getInt("version");
        try {
            ReplayingBatch batch = new ReplayingBatch(id, version, row.getList("mutations", BytesType.instance));
            if (batch.replay(rateLimiter, hintedNodes) > 0) {
                unfinishedBatches.add(batch);
            } else {
                // no write mutations were sent (either expired or all CFs involved truncated).
                remove(id);
                ++totalBatchesReplayed;
            }
        } catch (IOException e) {
            logger.warn("Skipped batch replay of {} due to {}", id, e.getMessage());
            caughtException = e;
            remove(id);
            ++skipped;
        }
        if (++positionInPage == pageSize) {
            // We have reached the end of a batch. To avoid keeping more than a page of mutations in memory,
            // finish processing the page before requesting the next row.
            finishAndClearBatches(unfinishedBatches, hintedNodes, replayedBatches);
            positionInPage = 0;
        }
    }
    // finalize the incomplete last page of batches
    if (positionInPage > 0)
        finishAndClearBatches(unfinishedBatches, hintedNodes, replayedBatches);
    if (caughtException != null)
        logger.warn(String.format("Encountered %d unexpected exceptions while sending out batches", skipped), caughtException);
    // to preserve batch guarantees, we must ensure that hints (if any) have made it to disk, before deleting the batches
    HintsService.instance.flushAndFsyncBlockingly(hintedNodes);
    // once all generated hints are fsynced, actually delete the batches
    replayedBatches.forEach(BatchlogManager::remove);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) ArrayList(java.util.ArrayList) IOException(java.io.IOException) UUID(java.util.UUID) Hint(org.apache.cassandra.hints.Hint) TimeoutException(java.util.concurrent.TimeoutException) WriteTimeoutException(org.apache.cassandra.exceptions.WriteTimeoutException) WriteFailureException(org.apache.cassandra.exceptions.WriteFailureException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet)

Example 79 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class BatchlogManager method replayFailedBatches.

private void replayFailedBatches() {
    logger.trace("Started replayFailedBatches");
    // rate limit is in bytes per second. Uses Double.MAX_VALUE if disabled (set to 0 in cassandra.yaml).
    // max rate is scaled by the number of nodes in the cluster (same as for HHOM - see CASSANDRA-5272).
    int endpointsCount = StorageService.instance.getTokenMetadata().getSizeOfAllEndpoints();
    if (endpointsCount <= 0) {
        logger.trace("Replay cancelled as there are no peers in the ring.");
        return;
    }
    setRate(DatabaseDescriptor.getBatchlogReplayThrottleInKiB());
    UUID limitUuid = UUIDGen.maxTimeUUID(currentTimeMillis() - getBatchlogTimeout());
    ColumnFamilyStore store = Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME).getColumnFamilyStore(SystemKeyspace.BATCHES);
    int pageSize = calculatePageSize(store);
    // There cannot be any live content where token(id) <= token(lastReplayedUuid) as every processed batch is
    // deleted, but the tombstoned content may still be present in the tables. To avoid walking over it we specify
    // token(id) > token(lastReplayedUuid) as part of the query.
    String query = String.format("SELECT id, mutations, version FROM %s.%s WHERE token(id) > token(?) AND token(id) <= token(?)", SchemaConstants.SYSTEM_KEYSPACE_NAME, SystemKeyspace.BATCHES);
    UntypedResultSet batches = executeInternalWithPaging(query, pageSize, lastReplayedUuid, limitUuid);
    processBatchlogEntries(batches, pageSize, rateLimiter);
    lastReplayedUuid = limitUuid;
    logger.trace("Finished replayFailedBatches");
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) UUID(java.util.UUID) Hint(org.apache.cassandra.hints.Hint)

Example 80 with UntypedResultSet

use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.

the class CassandraNetworkAuthorizer method getAuthorizedDcs.

private Set<String> getAuthorizedDcs(String name) {
    QueryOptions options = QueryOptions.forInternalCalls(CassandraAuthorizer.authReadConsistencyLevel(), Lists.newArrayList(ByteBufferUtil.bytes(name)));
    ResultMessage.Rows rows = select(authorizeUserStatement, options);
    UntypedResultSet result = UntypedResultSet.create(rows.result);
    Set<String> dcs = null;
    if (!result.isEmpty() && result.one().has("dcs")) {
        dcs = result.one().getFrozenSet("dcs", UTF8Type.instance);
    }
    return dcs;
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) QueryOptions(org.apache.cassandra.cql3.QueryOptions)

Aggregations

UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)107 Test (org.junit.Test)35 UUID (java.util.UUID)8 ByteBuffer (java.nio.ByteBuffer)6 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)6 InetAddressAndPort (org.apache.cassandra.locator.InetAddressAndPort)6 HashSet (java.util.HashSet)5 Mutation (org.apache.cassandra.db.Mutation)5 VisibleForTesting (com.google.common.annotations.VisibleForTesting)4 HashMap (java.util.HashMap)4 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)4 TableMetadata (org.apache.cassandra.schema.TableMetadata)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)3 ResultMessage (org.apache.cassandra.transport.messages.ResultMessage)3 Predicate (com.google.common.base.Predicate)2 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 ArrayList (java.util.ArrayList)2