Search in sources :

Example 36 with UntypedResultSet

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

the class SystemKeyspace method getBuiltIndexes.

public static List<String> getBuiltIndexes(String keyspaceName, Set<String> indexNames) {
    List<String> names = new ArrayList<>(indexNames);
    String req = "SELECT index_name from %s.\"%s\" WHERE table_name=? AND index_name IN ?";
    UntypedResultSet results = executeInternal(format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_INDEXES), keyspaceName, names);
    return StreamSupport.stream(results.spliterator(), false).map(r -> r.getString("index_name")).collect(Collectors.toList());
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) Rows(org.apache.cassandra.db.rows.Rows) java.util(java.util) OpenDataException(javax.management.openmbean.OpenDataException) PartitionUpdate(org.apache.cassandra.db.partitions.PartitionUpdate) org.apache.cassandra.io.util(org.apache.cassandra.io.util) org.apache.cassandra.db.marshal(org.apache.cassandra.db.marshal) LoggerFactory(org.slf4j.LoggerFactory) CommitLogPosition(org.apache.cassandra.db.commitlog.CommitLogPosition) TabularData(javax.management.openmbean.TabularData) QueryProcessor(org.apache.cassandra.cql3.QueryProcessor) org.apache.cassandra.utils(org.apache.cassandra.utils) ByteBuffer(java.nio.ByteBuffer) InetAddress(java.net.InetAddress) IEndpointSnitch(org.apache.cassandra.locator.IEndpointSnitch) HashMultimap(com.google.common.collect.HashMultimap) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException) StreamSupport(java.util.stream.StreamSupport) ProtocolVersion(org.apache.cassandra.transport.ProtocolVersion) Collections.singletonMap(java.util.Collections.singletonMap) org.apache.cassandra.cql3.functions(org.apache.cassandra.cql3.functions) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) MessagingService(org.apache.cassandra.net.MessagingService) Collections.emptyMap(java.util.Collections.emptyMap) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) Commit(org.apache.cassandra.service.paxos.Commit) QueryProcessor.executeInternal(org.apache.cassandra.cql3.QueryProcessor.executeInternal) RestorableMeter(org.apache.cassandra.metrics.RestorableMeter) StorageService(org.apache.cassandra.service.StorageService) IOException(java.io.IOException) org.apache.cassandra.dht(org.apache.cassandra.dht) Collectors(java.util.stream.Collectors) File(java.io.File) SetMultimap(com.google.common.collect.SetMultimap) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) QueryProcessor.executeOnceInternal(org.apache.cassandra.cql3.QueryProcessor.executeOnceInternal) IOError(java.io.IOError) TimeUnit(java.util.concurrent.TimeUnit) PaxosState(org.apache.cassandra.service.paxos.PaxosState) ByteStreams(com.google.common.io.ByteStreams) UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) CompactionHistoryTabularData(org.apache.cassandra.db.compaction.CompactionHistoryTabularData) org.apache.cassandra.schema(org.apache.cassandra.schema) SchemaConstants(org.apache.cassandra.schema.SchemaConstants) CreateTableStatement(org.apache.cassandra.cql3.statements.CreateTableStatement)

Example 37 with UntypedResultSet

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

the class SystemKeyspace method getAvailableRanges.

public static synchronized Set<Range<Token>> getAvailableRanges(String keyspace, IPartitioner partitioner) {
    Set<Range<Token>> result = new HashSet<>();
    String query = "SELECT * FROM system.%s WHERE keyspace_name=?";
    UntypedResultSet rs = executeInternal(format(query, AVAILABLE_RANGES), keyspace);
    for (UntypedResultSet.Row row : rs) {
        Set<ByteBuffer> rawRanges = row.getSet("ranges", BytesType.instance);
        for (ByteBuffer rawRange : rawRanges) {
            result.add(byteBufferToRange(rawRange, partitioner));
        }
    }
    return ImmutableSet.copyOf(result);
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) ByteBuffer(java.nio.ByteBuffer)

Example 38 with UntypedResultSet

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

the class SystemKeyspace method isIndexBuilt.

public static boolean isIndexBuilt(String keyspaceName, String indexName) {
    String req = "SELECT index_name FROM %s.\"%s\" WHERE table_name=? AND index_name=?";
    UntypedResultSet result = executeInternal(format(req, SchemaConstants.SYSTEM_KEYSPACE_NAME, BUILT_INDEXES), keyspaceName, indexName);
    return !result.isEmpty();
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet)

Example 39 with UntypedResultSet

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

the class LocalSessions method start.

/**
     * Loads sessions out of the repairs table and sets state to started
     */
public synchronized void start() {
    Preconditions.checkArgument(!started, "LocalSessions.start can only be called once");
    Preconditions.checkArgument(sessions.isEmpty(), "No sessions should be added before start");
    UntypedResultSet rows = QueryProcessor.executeInternalWithPaging(String.format("SELECT * FROM %s.%s", keyspace, table), 1000);
    Map<UUID, LocalSession> loadedSessions = new HashMap<>();
    for (UntypedResultSet.Row row : rows) {
        try {
            LocalSession session = load(row);
            loadedSessions.put(session.sessionID, session);
        } catch (IllegalArgumentException | NullPointerException e) {
            logger.warn("Unable to load malformed repair session {}, ignoring", row.has("parent_id") ? row.getUUID("parent_id") : null);
        }
    }
    sessions = ImmutableMap.copyOf(loadedSessions);
    started = true;
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) HashMap(java.util.HashMap) UUID(java.util.UUID)

Example 40 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 InetAddress getPreferredIP(InetAddress ep) {
    String req = "SELECT preferred_ip FROM system.%s WHERE peer=?";
    UntypedResultSet result = executeInternal(format(req, PEERS), ep);
    if (!result.isEmpty() && result.one().has("preferred_ip"))
        return result.one().getInetAddress("preferred_ip");
    return ep;
}
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