Search in sources :

Example 6 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(InetAddress ep) {
    try {
        if (FBUtilities.getBroadcastAddress().equals(ep)) {
            return new CassandraVersion(FBUtilities.getReleaseVersionString());
        }
        String req = "SELECT release_version FROM system.%s WHERE peer=?";
        UntypedResultSet result = executeInternal(format(req, PEERS), ep);
        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 7 with UntypedResultSet

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

the class SystemKeyspace method getBootstrapState.

public static BootstrapState getBootstrapState() {
    String req = "SELECT bootstrapped FROM system.%s WHERE key='%s'";
    UntypedResultSet result = executeInternal(format(req, LOCAL, LOCAL));
    if (result.isEmpty() || !result.one().has("bootstrapped"))
        return BootstrapState.NEEDS_BOOTSTRAP;
    return BootstrapState.valueOf(result.one().getString("bootstrapped"));
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 8 with UntypedResultSet

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

the class SystemKeyspace method getTransferredRanges.

public static synchronized Map<InetAddress, Set<Range<Token>>> getTransferredRanges(String description, String keyspace, IPartitioner partitioner) {
    Map<InetAddress, Set<Range<Token>>> result = new HashMap<>();
    String query = "SELECT * FROM system.%s WHERE operation = ? AND keyspace_name = ?";
    UntypedResultSet rs = executeInternal(format(query, TRANSFERRED_RANGES), description, keyspace);
    for (UntypedResultSet.Row row : rs) {
        InetAddress peer = row.getInetAddress("peer");
        Set<ByteBuffer> rawRanges = row.getSet("ranges", BytesType.instance);
        Set<Range<Token>> ranges = Sets.newHashSetWithExpectedSize(rawRanges.size());
        for (ByteBuffer rawRange : rawRanges) {
            ranges.add(byteBufferToRange(rawRange, partitioner));
        }
        result.put(peer, ranges);
    }
    return ImmutableMap.copyOf(result);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) ImmutableSet(com.google.common.collect.ImmutableSet) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) InetAddress(java.net.InetAddress) ByteBuffer(java.nio.ByteBuffer)

Example 9 with UntypedResultSet

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

the class SystemKeyspace method isViewStatusReplicated.

public static boolean isViewStatusReplicated(String keyspaceName, String viewName) {
    String req = "SELECT status_replicated FROM %s.\"%s\" WHERE keyspace_name=? AND view_name=?";
    UntypedResultSet result = executeInternal(format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_VIEWS), keyspaceName, viewName);
    if (result.isEmpty())
        return false;
    UntypedResultSet.Row row = result.one();
    return row.has("status_replicated") && row.getBoolean("status_replicated");
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 10 with UntypedResultSet

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

the class SystemKeyspace method getLocalHostId.

/**
     * Read the host ID from the system keyspace, creating (and storing) one if
     * none exists.
     */
public static UUID getLocalHostId() {
    String req = "SELECT host_id FROM system.%s WHERE key='%s'";
    UntypedResultSet result = executeInternal(format(req, LOCAL, LOCAL));
    // Look up the Host UUID (return it if found)
    if (!result.isEmpty() && result.one().has("host_id"))
        return result.one().getUUID("host_id");
    // ID not found, generate a new one, persist, and then return it.
    UUID hostId = UUID.randomUUID();
    logger.warn("No host ID found, created {} (Note: This should happen exactly once per node).", hostId);
    return setLocalHostId(hostId);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

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