Search in sources :

Example 16 with UntypedResultSet

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

the class SystemKeyspace method checkHealth.

/**
     * One of three things will happen if you try to read the system keyspace:
     * 1. files are present and you can read them: great
     * 2. no files are there: great (new node is assumed)
     * 3. files are present but you can't read them: bad
     * @throws ConfigurationException
     */
public static void checkHealth() throws ConfigurationException {
    Keyspace keyspace;
    try {
        keyspace = Keyspace.open(SchemaConstants.SYSTEM_KEYSPACE_NAME);
    } catch (AssertionError err) {
        // this happens when a user switches from OPP to RP.
        ConfigurationException ex = new ConfigurationException("Could not read system keyspace!");
        ex.initCause(err);
        throw ex;
    }
    ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(LOCAL);
    String req = "SELECT cluster_name FROM system.%s WHERE key='%s'";
    UntypedResultSet result = executeInternal(format(req, LOCAL, LOCAL));
    if (result.isEmpty() || !result.one().has("cluster_name")) {
        // this is a brand new node
        if (!cfs.getLiveSSTables().isEmpty())
            throw new ConfigurationException("Found system keyspace files, but they couldn't be loaded!");
        // no system files.  this is a new node.
        return;
    }
    String savedClusterName = result.one().getString("cluster_name");
    if (!DatabaseDescriptor.getClusterName().equals(savedClusterName))
        throw new ConfigurationException("Saved cluster name " + savedClusterName + " != configured name " + DatabaseDescriptor.getClusterName());
}
Also used : UntypedResultSet(org.apache.cassandra.cql3.UntypedResultSet) ConfigurationException(org.apache.cassandra.exceptions.ConfigurationException)

Example 17 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 18 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 19 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 20 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)

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