private static UntypedResultSet query(String query, Object... values) { return QueryProcessor.executeOnceInternal(query, values); }
private static UntypedResultSet query(String query, Object... values) { return QueryProcessor.executeOnceInternal(query, values); }
private static UntypedResultSet query(String query, Object... values) { return QueryProcessor.executeOnceInternal(query, values); }
@VisibleForTesting static Optional<String> checkLegacyAuthTablesMessage() { List<String> existing = new ArrayList<>(LEGACY_AUTH_TABLES).stream().filter((legacyAuthTable) -> { UntypedResultSet result = QueryProcessor.executeOnceInternal(String.format("SELECT table_name FROM %s.%s WHERE keyspace_name='%s' AND table_name='%s'", SchemaConstants.SCHEMA_KEYSPACE_NAME, "tables", SchemaConstants.AUTH_KEYSPACE_NAME, legacyAuthTable)); return result != null && !result.isEmpty(); }).collect(Collectors.toList()); if (!existing.isEmpty()) return Optional.of(String.format("Legacy auth tables %s in keyspace %s still exist and have not been properly migrated.", Joiner.on(", ").join(existing), SchemaConstants.AUTH_KEYSPACE_NAME)); else return Optional.empty(); }; }
@VisibleForTesting static Optional<String> checkLegacyAuthTablesMessage() { List<String> existing = new ArrayList<>(LEGACY_AUTH_TABLES).stream().filter((legacyAuthTable) -> { UntypedResultSet result = QueryProcessor.executeOnceInternal(String.format("SELECT table_name FROM %s.%s WHERE keyspace_name='%s' AND table_name='%s'", SchemaConstants.SCHEMA_KEYSPACE_NAME, "tables", SchemaConstants.AUTH_KEYSPACE_NAME, legacyAuthTable)); return result != null && !result.isEmpty(); }).collect(Collectors.toList()); if (!existing.isEmpty()) return Optional.of(String.format("Legacy auth tables %s in keyspace %s still exist and have not been properly migrated.", Joiner.on(", ").join(existing), SchemaConstants.AUTH_KEYSPACE_NAME)); else return Optional.empty(); }; }
@VisibleForTesting static Optional<String> checkLegacyAuthTablesMessage() { List<String> existing = new ArrayList<>(LEGACY_AUTH_TABLES).stream().filter((legacyAuthTable) -> { UntypedResultSet result = QueryProcessor.executeOnceInternal(String.format("SELECT table_name FROM %s.%s WHERE keyspace_name='%s' AND table_name='%s'", SchemaConstants.SCHEMA_KEYSPACE_NAME, "tables", SchemaConstants.AUTH_KEYSPACE_NAME, legacyAuthTable)); return result != null && !result.isEmpty(); }).collect(Collectors.toList()); if (!existing.isEmpty()) return Optional.of(String.format("Legacy auth tables %s in keyspace %s still exist and have not been properly migrated.", Joiner.on(", ").join(existing), SchemaConstants.AUTH_KEYSPACE_NAME)); else return Optional.empty(); }; }
public static List<Pair<String, String>> loadPreparedStatements() { String query = String.format("SELECT logged_keyspace, query_string FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS); UntypedResultSet resultSet = executeOnceInternal(query); List<Pair<String, String>> r = new ArrayList<>(); for (UntypedResultSet.Row row : resultSet) r.add(Pair.create(row.has("logged_keyspace") ? row.getString("logged_keyspace") : null, row.getString("query_string"))); return r; } }
public static List<Pair<String, String>> loadPreparedStatements() { String query = String.format("SELECT logged_keyspace, query_string FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS); UntypedResultSet resultSet = executeOnceInternal(query); List<Pair<String, String>> r = new ArrayList<>(); for (UntypedResultSet.Row row : resultSet) r.add(Pair.create(row.has("logged_keyspace") ? row.getString("logged_keyspace") : null, row.getString("query_string"))); return r; } }
public static List<Pair<String, String>> loadPreparedStatements() { String query = String.format("SELECT logged_keyspace, query_string FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS); UntypedResultSet resultSet = executeOnceInternal(query); List<Pair<String, String>> r = new ArrayList<>(); for (UntypedResultSet.Row row : resultSet) r.add(Pair.create(row.has("logged_keyspace") ? row.getString("logged_keyspace") : null, row.getString("query_string"))); return r; } }
/** Migrates index_interval values to min_index_interval and sets index_interval to null */ private static void migrateIndexInterval() { for (UntypedResultSet.Row row : executeOnceInternal(String.format("SELECT * FROM system.%s", SCHEMA_COLUMNFAMILIES_CF))) { if (!row.has("index_interval")) continue; logger.debug("Migrating index_interval to min_index_interval"); CFMetaData table = CFMetaData.fromSchema(row); String query = String.format("SELECT writetime(type) FROM system.%s WHERE keyspace_name = ? AND columnfamily_name = ?", SCHEMA_COLUMNFAMILIES_CF); long timestamp = executeOnceInternal(query, table.ksName, table.cfName).one().getLong("writetime(type)"); try { table.toSchema(timestamp).apply(); } catch (ConfigurationException e) { // shouldn't happen } } }
public static MapType<?,?> getMapType(final String ksName, final String cfName, final String colName) { try { UntypedResultSet result = QueryProcessor.executeOnceInternal("SELECT validator FROM system.schema_columns WHERE keyspace_name = ? AND columnfamily_name = ? AND column_name = ?", new Object[] { ksName, cfName, colName }); Row row = result.one(); if ((row != null) && row.has("validator")) { AbstractType<?> type = TypeParser.parse(row.getString("validator")); if (type instanceof MapType) { return (MapType<?,?>)type; } } } catch (Exception e) { } return null; }
private static void setupVersion() { String req = "INSERT INTO system.%s (key, release_version, cql_version, thrift_version, native_protocol_version, data_center, rack, partitioner, rpc_address, broadcast_address, listen_address) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch(); executeOnceInternal(String.format(req, LOCAL_CF), LOCAL_KEY, FBUtilities.getReleaseVersionString(), QueryProcessor.CQL_VERSION.toString(), cassandraConstants.VERSION, String.valueOf(Server.CURRENT_VERSION), snitch.getDatacenter(FBUtilities.getBroadcastAddress()), snitch.getRack(FBUtilities.getBroadcastAddress()), DatabaseDescriptor.getPartitioner().getClass().getName(), DatabaseDescriptor.getRpcAddress(), FBUtilities.getBroadcastAddress(), FBUtilities.getLocalAddress()); }
private static void migrateCachingOption() { for (UntypedResultSet.Row row : executeOnceInternal(String.format("SELECT * FROM system.%s", SCHEMA_COLUMNFAMILIES_CF))) { if (!row.has("caching")) continue; if (!CachingOptions.isLegacy(row.getString("caching"))) continue; try { CachingOptions caching = CachingOptions.fromString(row.getString("caching")); CFMetaData table = CFMetaData.fromSchema(row); logger.info("Migrating caching option {} to {} for {}.{}", row.getString("caching"), caching.toString(), table.ksName, table.cfName); String query = String.format("SELECT writetime(type) FROM system.%s WHERE keyspace_name = ? AND columnfamily_name = ?", SCHEMA_COLUMNFAMILIES_CF); long timestamp = executeOnceInternal(query, table.ksName, table.cfName).one().getLong("writetime(type)"); table.toSchema(timestamp).apply(); } catch (ConfigurationException e) { // shouldn't happen } } }
public static void finishStartup() { setupVersion(); migrateIndexInterval(); migrateCachingOption(); // add entries to system schema columnfamilies for the hardcoded system definitions KSMetaData ksmd = Schema.instance.getKSMetaData(Keyspace.SYSTEM_KS); long timestamp = FBUtilities.timestampMicros(); // delete old, possibly obsolete entries in schema columnfamilies for (String cfname : Arrays.asList(SystemKeyspace.SCHEMA_KEYSPACES_CF, SystemKeyspace.SCHEMA_COLUMNFAMILIES_CF, SystemKeyspace.SCHEMA_COLUMNS_CF, SystemKeyspace.SCHEMA_TRIGGERS_CF, SystemKeyspace.SCHEMA_USER_TYPES_CF)) { executeOnceInternal(String.format("DELETE FROM system.%s USING TIMESTAMP ? WHERE keyspace_name = ?", cfname), timestamp, ksmd.name); } // (+1 to timestamp to make sure we don't get shadowed by the tombstones we just added) ksmd.toSchema(timestamp + 1).apply(); }
public static Pair<List<String>, List<String>> getUDTInfo(final String ksName, final String typeName) { try { UntypedResultSet result = QueryProcessor.executeOnceInternal("SELECT field_names, field_types FROM system_schema.types WHERE keyspace_name = ? AND type_name = ?", new Object[] { ksName, typeName }); Row row = result.one(); if ((row != null) && row.has("field_names")) { List<String> field_names = row.getList("field_names", UTF8Type.instance); List<String> field_types = row.getList("field_types", UTF8Type.instance); return Pair.<List<String>, List<String>> create(field_names, field_types); } } catch (Exception e) { } return null; }
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch(); executeOnceInternal(String.format(req, LOCAL), LOCAL, DatabaseDescriptor.getClusterName(),
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch(); executeOnceInternal(String.format(req, LOCAL), LOCAL, DatabaseDescriptor.getClusterName(),
/** * Add entries to system_schema.* for the hardcoded system keyspaces */ public static void saveSystemKeyspacesSchema() { KeyspaceMetadata system = Schema.instance.getKSMetaData(SchemaConstants.SYSTEM_KEYSPACE_NAME); KeyspaceMetadata schema = Schema.instance.getKSMetaData(SchemaConstants.SCHEMA_KEYSPACE_NAME); long timestamp = FBUtilities.timestampMicros(); // delete old, possibly obsolete entries in schema tables for (String schemaTable : ALL) { String query = String.format("DELETE FROM %s.%s USING TIMESTAMP ? WHERE keyspace_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, schemaTable); for (String systemKeyspace : SchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES) executeOnceInternal(query, timestamp, systemKeyspace); } // (+1 to timestamp to make sure we don't get shadowed by the tombstones we just added) makeCreateKeyspaceMutation(system, timestamp + 1).build().apply(); makeCreateKeyspaceMutation(schema, timestamp + 1).build().apply(); }
/** * Add entries to system_schema.* for the hardcoded system keyspaces */ public static void saveSystemKeyspacesSchema() { KeyspaceMetadata system = Schema.instance.getKSMetaData(SchemaConstants.SYSTEM_KEYSPACE_NAME); KeyspaceMetadata schema = Schema.instance.getKSMetaData(SchemaConstants.SCHEMA_KEYSPACE_NAME); long timestamp = FBUtilities.timestampMicros(); // delete old, possibly obsolete entries in schema tables for (String schemaTable : ALL) { String query = String.format("DELETE FROM %s.%s USING TIMESTAMP ? WHERE keyspace_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, schemaTable); for (String systemKeyspace : SchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES) executeOnceInternal(query, timestamp, systemKeyspace); } // (+1 to timestamp to make sure we don't get shadowed by the tombstones we just added) makeCreateKeyspaceMutation(system, timestamp + 1).build().apply(); makeCreateKeyspaceMutation(schema, timestamp + 1).build().apply(); }
/** * Add entries to system_schema.* for the hardcoded system keyspaces */ public static void saveSystemKeyspacesSchema() { KeyspaceMetadata system = Schema.instance.getKSMetaData(SchemaConstants.SYSTEM_KEYSPACE_NAME); KeyspaceMetadata schema = Schema.instance.getKSMetaData(SchemaConstants.SCHEMA_KEYSPACE_NAME); long timestamp = FBUtilities.timestampMicros(); // delete old, possibly obsolete entries in schema tables for (String schemaTable : ALL) { String query = String.format("DELETE FROM %s.%s USING TIMESTAMP ? WHERE keyspace_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, schemaTable); for (String systemKeyspace : SchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES) executeOnceInternal(query, timestamp, systemKeyspace); } // (+1 to timestamp to make sure we don't get shadowed by the tombstones we just added) makeCreateKeyspaceMutation(system, timestamp + 1).build().apply(); makeCreateKeyspaceMutation(schema, timestamp + 1).build().apply(); }