Search in sources :

Example 81 with UntypedResultSet

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

the class PasswordAuthenticator method queryHashedPassword.

private String queryHashedPassword(String username) {
    try {
        QueryOptions options = QueryOptions.forInternalCalls(consistencyForRoleRead(username), Lists.newArrayList(ByteBufferUtil.bytes(username)));
        ResultMessage.Rows rows = select(authenticateStatement, options);
        // invalidate the cache and throw an appropriate exception.
        if (rows.result.isEmpty())
            return NO_SUCH_CREDENTIAL;
        UntypedResultSet result = UntypedResultSet.create(rows.result);
        if (!result.one().has(SALTED_HASH))
            return NO_SUCH_CREDENTIAL;
        return result.one().getString(SALTED_HASH);
    } catch (RequestExecutionException e) {
        throw new AuthenticationException("Unable to perform authentication: " + e.getMessage(), e);
    }
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) RequestExecutionException(org.apache.cassandra.exceptions.RequestExecutionException) AuthenticationException(org.apache.cassandra.exceptions.AuthenticationException) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) QueryOptions(org.apache.cassandra.cql3.QueryOptions)

Example 82 with UntypedResultSet

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

the class SystemKeyspace method getRack.

/**
 * Gets the stored rack for the local node, or null if none have been set yet.
 */
public static String getRack() {
    String req = "SELECT rack FROM system.%s WHERE key='%s'";
    UntypedResultSet result = executeInternal(format(req, LOCAL, LOCAL));
    // Look up the Rack (return it if found)
    if (!result.isEmpty() && result.one().has("rack"))
        return result.one().getString("rack");
    return null;
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 83 with UntypedResultSet

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

the class SystemKeyspace method loadPreparedStatement.

public static int loadPreparedStatement(MD5Digest digest, TriFunction<MD5Digest, String, String, Boolean> onLoaded) {
    String query = String.format("SELECT prepared_id, logged_keyspace, query_string FROM %s.%s WHERE prepared_id = ?", SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS);
    UntypedResultSet resultSet = executeOnceInternal(query, digest.byteBuffer());
    int counter = 0;
    for (UntypedResultSet.Row row : resultSet) {
        if (onLoaded.accept(MD5Digest.wrap(row.getByteArray("prepared_id")), row.getString("query_string"), row.has("logged_keyspace") ? row.getString("logged_keyspace") : null))
            counter++;
    }
    return counter;
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 84 with UntypedResultSet

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

the class SystemKeyspace method getReleaseVersion.

/**
 * Get release version for given endpoint.
 * If release version is unknown, then this returns null.
 *
 * @param ep endpoint address to check
 * @return Release version or null if version is unknown.
 */
public static CassandraVersion getReleaseVersion(InetAddressAndPort ep) {
    try {
        if (FBUtilities.getBroadcastAddressAndPort().equals(ep)) {
            return CURRENT_VERSION;
        }
        String req = "SELECT release_version FROM system.%s WHERE peer=? AND peer_port=?";
        UntypedResultSet result = executeInternal(String.format(req, PEERS_V2), ep.getAddress(), ep.getPort());
        if (result != null && result.one().has("release_version")) {
            return new CassandraVersion(result.one().getString("release_version"));
        }
        // version is unknown
        return null;
    } catch (IllegalArgumentException e) {
        // version string cannot be parsed
        return null;
    }
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 85 with UntypedResultSet

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

the class SystemKeyspace method loadPaxosState.

public static PaxosState loadPaxosState(DecoratedKey key, TableMetadata metadata, int nowInSec) {
    String req = "SELECT * FROM system.%s WHERE row_key = ? AND cf_id = ?";
    UntypedResultSet results = QueryProcessor.executeInternalWithNow(nowInSec, nanoTime(), format(req, PAXOS), key.getKey(), metadata.id.asUUID());
    if (results.isEmpty())
        return new PaxosState(key, metadata);
    UntypedResultSet.Row row = results.one();
    Commit promised = row.has("in_progress_ballot") ? new Commit(row.getUUID("in_progress_ballot"), new PartitionUpdate.Builder(metadata, key, metadata.regularAndStaticColumns(), 1).build()) : Commit.emptyCommit(key, metadata);
    // either we have both a recently accepted ballot and update or we have neither
    Commit accepted = row.has("proposal_version") && row.has("proposal") ? new Commit(row.getUUID("proposal_ballot"), PartitionUpdate.fromBytes(row.getBytes("proposal"), row.getInt("proposal_version"))) : Commit.emptyCommit(key, metadata);
    // either most_recent_commit and most_recent_commit_at will both be set, or neither
    Commit mostRecent = row.has("most_recent_commit_version") && row.has("most_recent_commit") ? new Commit(row.getUUID("most_recent_commit_at"), PartitionUpdate.fromBytes(row.getBytes("most_recent_commit"), row.getInt("most_recent_commit_version"))) : Commit.emptyCommit(key, metadata);
    return new PaxosState(promised, accepted, mostRecent);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) PaxosState(org.apache.cassandra.service.paxos.PaxosState) Commit(org.apache.cassandra.service.paxos.Commit) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate)

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