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();
}
use of org.apache.cassandra.cql3.UntypedResultSet in project cassandra by apache.
the class SystemKeyspace method loadPreparedStatements.
public static int loadPreparedStatements(TriFunction<MD5Digest, String, String, Boolean> onLoaded) {
String query = String.format("SELECT prepared_id, logged_keyspace, query_string FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS);
UntypedResultSet resultSet = executeOnceInternal(query);
int counter = 0;
for (UntypedResultSet.Row row : resultSet) {
if (onLoaded.accept(MD5Digest.wrap(row.getByteArray("prepared_id")), row.getString("query_string"), row.has("logged_keyspace") ? row.getString("logged_keyspace") : null))
counter++;
}
return counter;
}
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.name().equals("Versions") && dataDirectory.tryList().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");
}
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 InetAddressAndPort getPreferredIP(InetAddressAndPort ep) {
String req = "SELECT preferred_ip, preferred_port FROM system.%s WHERE peer=? AND peer_port = ?";
UntypedResultSet result = executeInternal(String.format(req, PEERS_V2), ep.getAddress(), ep.getPort());
if (!result.isEmpty() && result.one().has("preferred_ip")) {
UntypedResultSet.Row row = result.one();
return InetAddressAndPort.getByAddressOverrideDefaults(row.getInetAddress("preferred_ip"), row.getInt("preferred_port"));
}
return ep;
}
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));
}
Aggregations