use of org.apache.cassandra.schema.Keyspaces.KeyspacesDiff in project cassandra by apache.
the class DropIndexStatement method schemaChangeEvent.
SchemaChange schemaChangeEvent(KeyspacesDiff diff) {
assert diff.altered.size() == 1;
KeyspaceDiff ksDiff = diff.altered.get(0);
assert ksDiff.tables.altered.size() == 1;
Diff.Altered<TableMetadata> tableDiff = ksDiff.tables.altered.iterator().next();
return new SchemaChange(Change.UPDATED, Target.TABLE, keyspaceName, tableDiff.after.name);
}
use of org.apache.cassandra.schema.Keyspaces.KeyspacesDiff in project cassandra by apache.
the class Schema method transform.
/**
* See CASSANDRA-16856/16996. Make sure schema pulls are synchronized to prevent concurrent schema pull/writes
*/
public synchronized TransformationResult transform(SchemaTransformation transformation, boolean locally, long now) throws UnknownHostException {
KeyspacesDiff diff;
try {
Keyspaces before = keyspaces;
Keyspaces after = transformation.apply(before);
diff = Keyspaces.diff(before, after);
} catch (RuntimeException e) {
return new TransformationResult(e);
}
if (diff.isEmpty())
return new TransformationResult(diff, Collections.emptyList());
Collection<Mutation> mutations = SchemaKeyspace.convertSchemaDiffToMutations(diff, now);
SchemaKeyspace.applyChanges(mutations);
merge(diff);
updateVersion();
if (!locally)
passiveAnnounceVersion();
return new TransformationResult(diff, mutations);
}
use of org.apache.cassandra.schema.Keyspaces.KeyspacesDiff in project cassandra by apache.
the class AlterSchemaStatement method execute.
public ResultMessage execute(QueryState state, boolean locally) {
if (SchemaConstants.isLocalSystemKeyspace(keyspaceName))
throw ire("System keyspace '%s' is not user-modifiable", keyspaceName);
KeyspaceMetadata keyspace = Schema.instance.getKeyspaceMetadata(keyspaceName);
if (null != keyspace && keyspace.isVirtual())
throw ire("Virtual keyspace '%s' is not user-modifiable", keyspaceName);
validateKeyspaceName();
KeyspacesDiff diff = MigrationManager.announce(this, locally);
clientWarnings(diff).forEach(ClientWarn.instance::warn);
if (diff.isEmpty())
return new ResultMessage.Void();
/*
* When a schema alteration results in a new db object being created, we grant permissions on the new
* object to the user performing the request if:
* - the user is not anonymous
* - the configured IAuthorizer supports granting of permissions (not all do, AllowAllAuthorizer doesn't and
* custom external implementations may not)
*/
AuthenticatedUser user = state.getClientState().getUser();
if (null != user && !user.isAnonymous())
createdResources(diff).forEach(r -> grantPermissionsOnResource(r, user));
return new ResultMessage.SchemaChange(schemaChangeEvent(diff));
}
Aggregations