Search in sources :

Example 41 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, System.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(metadata, key, metadata.regularAndStaticColumns(), 1)) : 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)

Example 42 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)

Example 43 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.getName().equals("Versions") && dataDirectory.listFiles().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) File(java.io.File)

Example 44 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 45 with UntypedResultSet

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

the class SystemKeyspace method getSSTableReadMeter.

/**
     * Returns a RestorableMeter tracking the average read rate of a particular SSTable, restoring the last-seen rate
     * from values in system.sstable_activity if present.
     * @param keyspace the keyspace the sstable belongs to
     * @param table the table the sstable belongs to
     * @param generation the generation number for the sstable
     */
public static RestorableMeter getSSTableReadMeter(String keyspace, String table, int generation) {
    String cql = "SELECT * FROM system.%s WHERE keyspace_name=? and columnfamily_name=? and generation=?";
    UntypedResultSet results = executeInternal(format(cql, SSTABLE_ACTIVITY), keyspace, table, generation);
    if (results.isEmpty())
        return new RestorableMeter();
    UntypedResultSet.Row row = results.one();
    double m15rate = row.getDouble("rate_15m");
    double m120rate = row.getDouble("rate_120m");
    return new RestorableMeter(m15rate, m120rate);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) RestorableMeter(org.apache.cassandra.metrics.RestorableMeter)

Aggregations

UntypedResultSet (org.apache.cassandra.cql3.UntypedResultSet)71 Test (org.junit.Test)22 Mutation (org.apache.cassandra.db.Mutation)5 ByteBuffer (java.nio.ByteBuffer)4 UUID (java.util.UUID)4 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)4 TableMetadata (org.apache.cassandra.schema.TableMetadata)4 File (java.io.File)3 InetAddress (java.net.InetAddress)3 SchemaLoader.createKeyspace (org.apache.cassandra.SchemaLoader.createKeyspace)3 PartitionUpdate (org.apache.cassandra.db.partitions.PartitionUpdate)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 IOException (java.io.IOException)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HashMap (java.util.HashMap)2 Row (org.apache.cassandra.cql3.UntypedResultSet.Row)2 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)2