@Override public void clearStorage() throws BackendException { openStores.clear(); try { KSMetaData ksMetaData = Schema.instance.getKSMetaData(keySpaceName); // Not a big deal if Keyspace doesn't not exist (dropped manually by user or tests). // This is called on per test setup basis to make sure that previous test cleaned // everything up, so first invocation would always fail as Keyspace doesn't yet exist. if (ksMetaData == null) return; for (String cfName : ksMetaData.cfMetaData().keySet()) StorageService.instance.truncate(keySpaceName, cfName); } catch (Exception e) { throw new PermanentBackendException(e); } }
private synchronized KeyspaceMetadata update(String keyspaceName, java.util.function.Function<KeyspaceMetadata, KeyspaceMetadata> transformation) { KeyspaceMetadata current = getKSMetaData(keyspaceName); if (current == null) throw new IllegalStateException(String.format("Keyspace %s doesn't exist", keyspaceName)); KeyspaceMetadata transformed = transformation.apply(current); setKeyspaceMetadata(transformed); return transformed; }
public void setKeyspace(String ks) throws InvalidRequestException { // Skip keyspace validation for non-authenticated users. Apparently, some client libraries // call set_keyspace() before calling login(), and we have to handle that. if (user != null && Schema.instance.getKSMetaData(ks) == null) throw new InvalidRequestException("Keyspace '" + ks + "' does not exist"); keyspace = ks; }
public static Iterable<ViewDefinition> findAll(String keyspace, String baseTable) { KeyspaceMetadata ksm = Schema.instance.getKSMetaData(keyspace); final UUID baseId = Schema.instance.getId(keyspace, baseTable); return Iterables.filter(ksm.views, view -> view.baseTableId.equals(baseId)); }
public void setKeyspace(String ks) throws InvalidRequestException { // Skip keyspace validation for non-authenticated users. Apparently, some client libraries // call set_keyspace() before calling login(), and we have to handle that. if (user != null && Schema.instance.getKSMetaData(ks) == null) throw new InvalidRequestException("Keyspace '" + ks + "' does not exist"); keyspace = ks; }
private synchronized KeyspaceMetadata update(String keyspaceName, java.util.function.Function<KeyspaceMetadata, KeyspaceMetadata> transformation) { KeyspaceMetadata current = getKSMetaData(keyspaceName); if (current == null) throw new IllegalStateException(String.format("Keyspace %s doesn't exist", keyspaceName)); KeyspaceMetadata transformed = transformation.apply(current); setKeyspaceMetadata(transformed); return transformed; }
public void validate(ClientState state) throws InvalidRequestException { if (ifNotExists && orReplace) throw new InvalidRequestException("Cannot use both 'OR REPLACE' and 'IF NOT EXISTS' directives"); if (Schema.instance.getKSMetaData(functionName.keyspace) == null) throw new InvalidRequestException(String.format("Cannot add aggregate '%s' to non existing keyspace '%s'.", functionName.name, functionName.keyspace)); }
private static void onCreateFunctionInternal(String ksName, String functionName, List<AbstractType<?>> argTypes) { // in case there are other overloads, we have to remove all overloads since argument type // matching may change (due to type casting) if (Schema.instance.getKSMetaData(ksName).functions.get(new FunctionName(ksName, functionName)).size() > 1) removeInvalidPreparedStatementsForFunction(ksName, functionName); }
public void validate(ClientState state) throws InvalidRequestException { UDFunction.assertUdfsEnabled(language); if (ifNotExists && orReplace) throw new InvalidRequestException("Cannot use both 'OR REPLACE' and 'IF NOT EXISTS' directives"); if (Schema.instance.getKSMetaData(functionName.keyspace) == null) throw new InvalidRequestException(String.format("Cannot add function '%s' to non existing keyspace '%s'.", functionName.name, functionName.keyspace)); }
public void validate(ClientState state) throws InvalidRequestException { UDFunction.assertUdfsEnabled(language); if (ifNotExists && orReplace) throw new InvalidRequestException("Cannot use both 'OR REPLACE' and 'IF NOT EXISTS' directives"); if (Schema.instance.getKSMetaData(functionName.keyspace) == null) throw new InvalidRequestException(String.format("Cannot add function '%s' to non existing keyspace '%s'.", functionName.name, functionName.keyspace)); }
public static void announceTypeDrop(UserType droppedType, boolean announceLocally) { KeyspaceMetadata ksm = Schema.instance.getKSMetaData(droppedType.keyspace); announce(SchemaKeyspace.dropTypeFromSchemaMutation(ksm, droppedType, FBUtilities.timestampMicros()), announceLocally); }
static void unloadLegacySchemaTables() { KeyspaceMetadata systemKeyspace = Schema.instance.getKSMetaData(SchemaConstants.SYSTEM_KEYSPACE_NAME); Tables systemTables = systemKeyspace.tables; for (CFMetaData table : LegacySchemaTables) systemTables = systemTables.without(table.cfName); LegacySchemaTables.forEach(Schema.instance::unload); LegacySchemaTables.forEach((cfm) -> org.apache.cassandra.db.Keyspace.openAndGetStore(cfm).invalidate()); Schema.instance.setKeyspaceMetadata(systemKeyspace.withSwapped(systemTables)); }
/** * Transform this raw statement into a CreateTableStatement. */ public ParsedStatement.Prepared prepare(ClientState clientState) throws RequestValidationException { KeyspaceMetadata ksm = Schema.instance.getKSMetaData(keyspace()); if (ksm == null) throw new ConfigurationException(String.format("Keyspace %s doesn't exist", keyspace())); return prepare(ksm.types); }
public static void announceViewDrop(String ksName, String viewName, boolean announceLocally) throws ConfigurationException { ViewDefinition view = Schema.instance.getView(ksName, viewName); if (view == null) throw new ConfigurationException(String.format("Cannot drop non existing materialized view '%s' in keyspace '%s'.", viewName, ksName)); KeyspaceMetadata ksm = Schema.instance.getKSMetaData(ksName); logger.info("Drop table '{}/{}'", view.ksName, view.viewName); announce(SchemaKeyspace.makeDropViewMutation(ksm, view, FBUtilities.timestampMicros()), announceLocally); }
public static void announceNewKeyspace(KeyspaceMetadata ksm, long timestamp, boolean announceLocally) throws ConfigurationException { ksm.validate(); if (Schema.instance.getKSMetaData(ksm.name) != null) throw new AlreadyExistsException(ksm.name); logger.info("Create new Keyspace: {}", ksm); announce(SchemaKeyspace.makeCreateKeyspaceMutation(ksm, timestamp), announceLocally); }
public static void announceNewType(UserType newType, boolean announceLocally) { KeyspaceMetadata ksm = Schema.instance.getKSMetaData(newType.keyspace); announce(SchemaKeyspace.makeCreateTypeMutation(ksm, newType, FBUtilities.timestampMicros()), announceLocally); }
public static void announceColumnFamilyDrop(String ksName, String cfName, boolean announceLocally) throws ConfigurationException { CFMetaData oldCfm = Schema.instance.getCFMetaData(ksName, cfName); if (oldCfm == null) throw new ConfigurationException(String.format("Cannot drop non existing table '%s' in keyspace '%s'.", cfName, ksName)); KeyspaceMetadata ksm = Schema.instance.getKSMetaData(ksName); logger.info("Drop table '{}/{}'", oldCfm.ksName, oldCfm.cfName); announce(SchemaKeyspace.makeDropTableMutation(ksm, oldCfm, FBUtilities.timestampMicros()), announceLocally); }
public static void announceViewUpdate(ViewDefinition view, boolean announceLocally) throws ConfigurationException { KeyspaceMetadata ksm = Schema.instance.getKSMetaData(view.ksName); long timestamp = FBUtilities.timestampMicros(); Mutation.SimpleBuilder builder = SchemaKeyspace.makeCreateKeyspaceMutation(ksm.name, ksm.params, timestamp); addViewUpdateToMutationBuilder(view, builder); announce(builder, announceLocally); }
public static void announceAggregateDrop(UDAggregate udf, boolean announceLocally) { logger.info("Drop aggregate function overload '{}' args '{}'", udf.name(), udf.argTypes()); KeyspaceMetadata ksm = Schema.instance.getKSMetaData(udf.name().keyspace); announce(SchemaKeyspace.makeDropAggregateMutation(ksm, udf, FBUtilities.timestampMicros()), announceLocally); }
public void updateView(ViewDefinition view) { ViewDefinition current = getKSMetaData(view.ksName).views.get(view.viewName).get(); boolean changeAffectsStatements = current.metadata.apply(view.metadata); Keyspace keyspace = Keyspace.open(current.ksName); keyspace.getColumnFamilyStore(current.viewName).reload(); Keyspace.open(current.ksName).viewManager.update(current.viewName); MigrationManager.instance.notifyUpdateView(current, changeAffectsStatements); }