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;
}
}
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"));
}
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);
}
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");
}
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);
}
Aggregations