Search in sources :

Example 1 with KeyspacesDiff

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);
}
Also used : KeyspaceDiff(org.apache.cassandra.schema.KeyspaceMetadata.KeyspaceDiff) KeyspaceDiff(org.apache.cassandra.schema.KeyspaceMetadata.KeyspaceDiff) KeyspacesDiff(org.apache.cassandra.schema.Keyspaces.KeyspacesDiff) SchemaChange(org.apache.cassandra.transport.Event.SchemaChange)

Example 2 with KeyspacesDiff

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);
}
Also used : KeyspacesDiff(org.apache.cassandra.schema.Keyspaces.KeyspacesDiff)

Example 3 with KeyspacesDiff

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));
}
Also used : ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) ImmutableSet(com.google.common.collect.ImmutableSet) QueryState(org.apache.cassandra.service.QueryState) ClientWarn(org.apache.cassandra.service.ClientWarn) SchemaChange(org.apache.cassandra.transport.Event.SchemaChange) ClientState(org.apache.cassandra.service.ClientState) Set(java.util.Set) AuthenticatedUser(org.apache.cassandra.auth.AuthenticatedUser) CQLStatement(org.apache.cassandra.cql3.CQLStatement) IResource(org.apache.cassandra.auth.IResource) KeyspacesDiff(org.apache.cassandra.schema.Keyspaces.KeyspacesDiff) DatabaseDescriptor(org.apache.cassandra.config.DatabaseDescriptor) QueryOptions(org.apache.cassandra.cql3.QueryOptions) InvalidRequestException(org.apache.cassandra.exceptions.InvalidRequestException) org.apache.cassandra.schema(org.apache.cassandra.schema) KeyspacesDiff(org.apache.cassandra.schema.Keyspaces.KeyspacesDiff) SchemaChange(org.apache.cassandra.transport.Event.SchemaChange) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) AuthenticatedUser(org.apache.cassandra.auth.AuthenticatedUser)

Aggregations

KeyspacesDiff (org.apache.cassandra.schema.Keyspaces.KeyspacesDiff)3 SchemaChange (org.apache.cassandra.transport.Event.SchemaChange)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Set (java.util.Set)1 AuthenticatedUser (org.apache.cassandra.auth.AuthenticatedUser)1 IResource (org.apache.cassandra.auth.IResource)1 DatabaseDescriptor (org.apache.cassandra.config.DatabaseDescriptor)1 CQLStatement (org.apache.cassandra.cql3.CQLStatement)1 QueryOptions (org.apache.cassandra.cql3.QueryOptions)1 InvalidRequestException (org.apache.cassandra.exceptions.InvalidRequestException)1 org.apache.cassandra.schema (org.apache.cassandra.schema)1 KeyspaceDiff (org.apache.cassandra.schema.KeyspaceMetadata.KeyspaceDiff)1 ClientState (org.apache.cassandra.service.ClientState)1 ClientWarn (org.apache.cassandra.service.ClientWarn)1 QueryState (org.apache.cassandra.service.QueryState)1 ResultMessage (org.apache.cassandra.transport.messages.ResultMessage)1