Search in sources :

Example 86 with UntypedResultSet

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

the class SystemKeyspace method isViewBuilt.

public static boolean isViewBuilt(String keyspaceName, String viewName) {
    String req = "SELECT view_name FROM %s.\"%s\" WHERE keyspace_name=? AND view_name=?";
    UntypedResultSet result = executeInternal(format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_VIEWS), keyspaceName, viewName);
    return !result.isEmpty();
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 87 with UntypedResultSet

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

the class SystemKeyspace method loadPreparedStatements.

public static int loadPreparedStatements(TriFunction<MD5Digest, String, String, Boolean> onLoaded) {
    String query = String.format("SELECT prepared_id, logged_keyspace, query_string FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS);
    UntypedResultSet resultSet = executeOnceInternal(query);
    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 88 with UntypedResultSet

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

the class SystemKeyspace method getPreviousVersionString.

/**
 * Try to determine what the previous version, if any, was installed on this node.
 * Primary source of truth is the release version in system.local. If the previous
 * version cannot be determined by looking there then either:
 * * the node never had a C* install before
 * * the was a very old version (pre 1.2) installed, which did not include system.local
 *
 * @return either a version read from the system.local table or one of two special values
 * indicating either no previous version (SystemUpgrade.NULL_VERSION) or an unreadable,
 * legacy version (SystemUpgrade.UNREADABLE_VERSION).
 */
private static String getPreviousVersionString() {
    String req = "SELECT release_version FROM system.%s WHERE key='%s'";
    UntypedResultSet result = executeInternal(format(req, SystemKeyspace.LOCAL, SystemKeyspace.LOCAL));
    if (result.isEmpty() || !result.one().has("release_version")) {
        // from there, but it informs us that this isn't a completely new node.
        for (File dataDirectory : Directories.getKSChildDirectories(SchemaConstants.SYSTEM_KEYSPACE_NAME)) {
            if (dataDirectory.name().equals("Versions") && dataDirectory.tryList().length > 0) {
                logger.trace("Found unreadable versions info in pre 1.2 system.Versions table");
                return UNREADABLE_VERSION.toString();
            }
        }
        // no previous version information found, we can assume that this is a new node
        return NULL_VERSION.toString();
    }
    // report back whatever we found in the system table
    return result.one().getString("release_version");
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 89 with UntypedResultSet

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

the class SystemKeyspace method getPreferredIP.

/**
 * Get preferred IP for given endpoint if it is known. Otherwise this returns given endpoint itself.
 *
 * @param ep endpoint address to check
 * @return Preferred IP for given endpoint if present, otherwise returns given ep
 */
public static InetAddressAndPort getPreferredIP(InetAddressAndPort ep) {
    String req = "SELECT preferred_ip, preferred_port FROM system.%s WHERE peer=? AND peer_port = ?";
    UntypedResultSet result = executeInternal(String.format(req, PEERS_V2), ep.getAddress(), ep.getPort());
    if (!result.isEmpty() && result.one().has("preferred_ip")) {
        UntypedResultSet.Row row = result.one();
        return InetAddressAndPort.getByAddressOverrideDefaults(row.getInetAddress("preferred_ip"), row.getInt("preferred_port"));
    }
    return ep;
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 90 with UntypedResultSet

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

the class SystemKeyspace method getSavedTokens.

public static Collection<Token> getSavedTokens() {
    String req = "SELECT tokens FROM system.%s WHERE key='%s'";
    UntypedResultSet result = executeInternal(format(req, LOCAL, LOCAL));
    return result.isEmpty() || !result.one().has("tokens") ? Collections.<Token>emptyList() : deserializeTokens(result.one().getSet("tokens", UTF8Type.instance));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

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