Search in sources :

Example 11 with SchemaAlterTableAddColumnOperation

use of org.apache.ignite.internal.processors.query.schema.operation.SchemaAlterTableAddColumnOperation in project ignite by apache.

the class GridQueryProcessor method processSchemaOperationLocal.

/**
 * Process schema operation.
 *
 * @param op Operation.
 * @param type Type descriptor.
 * @param depId Cache deployment ID.
 * @param cancelTok Cancel token.
 * @throws SchemaOperationException If failed.
 */
@SuppressWarnings("StatementWithEmptyBody")
public void processSchemaOperationLocal(SchemaAbstractOperation op, QueryTypeDescriptorImpl type, IgniteUuid depId, SchemaIndexOperationCancellationToken cancelTok) throws SchemaOperationException {
    if (log.isDebugEnabled())
        log.debug("Started local index operation [opId=" + op.id() + ']');
    String cacheName = op.cacheName();
    GridCacheAdapter cache = ctx.cache().internalCache(cacheName);
    if (cache == null || !F.eq(depId, cache.context().dynamicDeploymentId()))
        throw new SchemaOperationException(SchemaOperationException.CODE_CACHE_NOT_FOUND, cacheName);
    try {
        if (op instanceof SchemaIndexCreateOperation) {
            final SchemaIndexCreateOperation op0 = (SchemaIndexCreateOperation) op;
            QueryIndexDescriptorImpl idxDesc = QueryUtils.createIndexDescriptor(type, op0.index());
            GridCacheContext cctx = cache.context();
            SchemaIndexCacheFilter filter = new TableCacheFilter(cctx, op0.tableName());
            SchemaIndexCacheVisitor visitor = new SchemaIndexCacheVisitorImpl(cctx, filter, cancelTok, op0.parallel());
            idx.dynamicIndexCreate(op0.schemaName(), op0.tableName(), idxDesc, op0.ifNotExists(), visitor);
        } else if (op instanceof SchemaIndexDropOperation) {
            SchemaIndexDropOperation op0 = (SchemaIndexDropOperation) op;
            idx.dynamicIndexDrop(op0.schemaName(), op0.indexName(), op0.ifExists());
        } else if (op instanceof SchemaAlterTableAddColumnOperation) {
            SchemaAlterTableAddColumnOperation op0 = (SchemaAlterTableAddColumnOperation) op;
            processDynamicAddColumn(type, op0.columns());
            idx.dynamicAddColumn(op0.schemaName(), op0.tableName(), op0.columns(), op0.ifTableExists(), op0.ifNotExists());
        } else if (op instanceof SchemaAlterTableDropColumnOperation) {
            SchemaAlterTableDropColumnOperation op0 = (SchemaAlterTableDropColumnOperation) op;
            processDynamicDropColumn(type, op0.columns());
            idx.dynamicDropColumn(op0.schemaName(), op0.tableName(), op0.columns(), op0.ifTableExists(), op0.ifExists());
        } else
            throw new SchemaOperationException("Unsupported operation: " + op);
    } catch (Exception e) {
        if (e instanceof SchemaOperationException)
            throw (SchemaOperationException) e;
        else
            throw new SchemaOperationException("Schema change operation failed: " + e.getMessage(), e);
    }
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) SchemaIndexCacheVisitor(org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitor) SchemaIndexCreateOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexCreateOperation) SchemaIndexCacheVisitorImpl(org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheVisitorImpl) SchemaIndexDropOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexDropOperation) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SQLException(java.sql.SQLException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) IgniteException(org.apache.ignite.IgniteException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) CacheException(javax.cache.CacheException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) SchemaAlterTableAddColumnOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaAlterTableAddColumnOperation) SchemaIndexCacheFilter(org.apache.ignite.internal.processors.query.schema.SchemaIndexCacheFilter) SchemaAlterTableDropColumnOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaAlterTableDropColumnOperation)

Example 12 with SchemaAlterTableAddColumnOperation

use of org.apache.ignite.internal.processors.query.schema.operation.SchemaAlterTableAddColumnOperation in project ignite by apache.

the class GridQueryProcessor method onSchemaProposeDiscovery.

/**
 * Process schema propose message from discovery thread.
 *
 * @param msg Message.
 * @return {@code True} if exchange should be triggered.
 */
private boolean onSchemaProposeDiscovery(SchemaProposeDiscoveryMessage msg) {
    SchemaAbstractOperation op = msg.operation();
    UUID opId = op.id();
    String cacheName = op.cacheName();
    if (!msg.initialized()) {
        // Ensure cache exists on coordinator node.
        DynamicCacheDescriptor cacheDesc = ctx.cache().cacheDescriptor(cacheName);
        if (cacheDesc == null) {
            if (log.isDebugEnabled())
                log.debug("Received schema propose discovery message, but cache doesn't exist " + "(will report error) [opId=" + opId + ", msg=" + msg + ']');
            msg.onError(new SchemaOperationException(SchemaOperationException.CODE_CACHE_NOT_FOUND, cacheName));
        } else {
            CacheConfiguration ccfg = cacheDesc.cacheConfiguration();
            if (ccfg.getCacheMode() == CacheMode.LOCAL) {
                // Distributed operation is not allowed on LOCAL caches.
                if (log.isDebugEnabled())
                    log.debug("Received schema propose discovery message, but cache is LOCAL " + "(will report error) [opId=" + opId + ", msg=" + msg + ']');
                msg.onError(new SchemaOperationException("Schema changes are not supported for LOCAL cache."));
            } else if (failOnStaticCacheSchemaChanges(cacheDesc)) {
                // Do not allow any schema changes when keep static cache configuration flag is set.
                if (log.isDebugEnabled())
                    log.debug("Received schema propose discovery message, but cache is statically configured " + "and " + IgniteSystemProperties.IGNITE_KEEP_STATIC_CACHE_CONFIGURATION + " flag is set (will report error) [opId=" + opId + ", msg=" + msg + ']');
                msg.onError(new SchemaOperationException("Schema changes are not supported for statically " + "configured cache when " + IgniteSystemProperties.IGNITE_KEEP_STATIC_CACHE_CONFIGURATION + " flag is set."));
            } else {
                // Preserve deployment ID so that we can distinguish between different caches with the same name.
                if (msg.deploymentId() == null)
                    msg.deploymentId(cacheDesc.deploymentId());
                assert F.eq(cacheDesc.deploymentId(), msg.deploymentId());
                if (msg.operation() instanceof SchemaAlterTableAddColumnOperation) {
                    SchemaAlterTableAddColumnOperation alterOp = (SchemaAlterTableAddColumnOperation) msg.operation();
                    try {
                        for (QueryField field : alterOp.columns()) {
                            if (!field.isNullable())
                                QueryUtils.checkNotNullAllowed(ccfg);
                        }
                    } catch (IgniteSQLException ex) {
                        msg.onError(new SchemaOperationException("Received schema propose discovery message, but " + "cache doesn't applicable for this modification", ex));
                    }
                }
            }
        }
    }
    // Complete client future and exit immediately in case of error.
    if (msg.hasError()) {
        SchemaOperationClientFuture cliFut = schemaCliFuts.remove(opId);
        if (cliFut != null)
            cliFut.onDone(msg.error());
        return false;
    }
    return onSchemaProposeDiscovery0(msg);
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) SchemaAbstractOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation) SchemaAlterTableAddColumnOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaAlterTableAddColumnOperation) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) SchemaOperationClientFuture(org.apache.ignite.internal.processors.query.schema.SchemaOperationClientFuture) UUID(java.util.UUID) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

SchemaAlterTableAddColumnOperation (org.apache.ignite.internal.processors.query.schema.operation.SchemaAlterTableAddColumnOperation)12 SchemaIndexCreateOperation (org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexCreateOperation)11 SchemaAlterTableDropColumnOperation (org.apache.ignite.internal.processors.query.schema.operation.SchemaAlterTableDropColumnOperation)10 SchemaIndexDropOperation (org.apache.ignite.internal.processors.query.schema.operation.SchemaIndexDropOperation)10 QueryEntity (org.apache.ignite.cache.QueryEntity)6 QueryIndex (org.apache.ignite.cache.QueryIndex)6 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)6 SchemaAbstractOperation (org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation)6 SchemaAddQueryEntityOperation (org.apache.ignite.internal.processors.query.schema.operation.SchemaAddQueryEntityOperation)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 Collection (java.util.Collection)4 Map (java.util.Map)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)4 Collections.newSetFromMap (java.util.Collections.newSetFromMap)3 HashSet (java.util.HashSet)3 IdentityHashMap (java.util.IdentityHashMap)3 LinkedList (java.util.LinkedList)3