Search in sources :

Example 1 with SchemaOperationManager

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

the class GridQueryProcessor method startSchemaChange.

/**
     * Initiate actual schema change operation.
     *
     * @param schemaOp Schema operation.
     */
@SuppressWarnings({ "unchecked", "ThrowableInstanceNeverThrown" })
private void startSchemaChange(SchemaOperation schemaOp) {
    assert Thread.holdsLock(stateMux);
    assert !schemaOp.started();
    // Get current cache state.
    SchemaProposeDiscoveryMessage msg = schemaOp.proposeMessage();
    String cacheName = msg.operation().cacheName();
    DynamicCacheDescriptor cacheDesc = ctx.cache().cacheDescriptor(cacheName);
    boolean cacheExists = cacheDesc != null && F.eq(msg.deploymentId(), cacheDesc.deploymentId());
    boolean cacheRegistered = cacheExists && cacheNames.contains(cacheName);
    // Validate schema state and decide whether we should proceed or not.
    SchemaAbstractOperation op = msg.operation();
    QueryTypeDescriptorImpl type = null;
    SchemaOperationException err;
    boolean nop = false;
    if (cacheExists) {
        if (cacheRegistered) {
            // If cache is started, we perform validation against real schema.
            T3<QueryTypeDescriptorImpl, Boolean, SchemaOperationException> res = prepareChangeOnStartedCache(op);
            assert res.get2() != null;
            type = res.get1();
            nop = res.get2();
            err = res.get3();
        } else {
            // If cache is not started yet, there is no schema. Take schema from cache descriptor and validate.
            QuerySchema schema = cacheDesc.schema();
            T2<Boolean, SchemaOperationException> res = prepareChangeOnNotStartedCache(op, schema);
            assert res.get1() != null;
            type = null;
            nop = res.get1();
            err = res.get2();
        }
    } else
        err = new SchemaOperationException(SchemaOperationException.CODE_CACHE_NOT_FOUND, cacheName);
    // Start operation.
    SchemaOperationWorker worker = new SchemaOperationWorker(ctx, this, msg.deploymentId(), op, nop, err, cacheRegistered, type);
    SchemaOperationManager mgr = new SchemaOperationManager(ctx, this, worker, ctx.clientNode() ? null : coordinator());
    schemaOp.manager(mgr);
    mgr.start();
    // Unwind pending IO messages.
    if (!ctx.clientNode() && coordinator().isLocal())
        unwindPendingMessages(schemaOp.id(), mgr);
    // Schedule operation finish handling if needed.
    if (schemaOp.hasFinishMessage())
        schemaOp.doFinish();
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) SchemaOperationManager(org.apache.ignite.internal.processors.query.schema.SchemaOperationManager) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) SchemaOperationWorker(org.apache.ignite.internal.processors.query.schema.SchemaOperationWorker) SchemaAbstractOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation) SchemaProposeDiscoveryMessage(org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)1 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)1 SchemaOperationManager (org.apache.ignite.internal.processors.query.schema.SchemaOperationManager)1 SchemaOperationWorker (org.apache.ignite.internal.processors.query.schema.SchemaOperationWorker)1 SchemaProposeDiscoveryMessage (org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage)1 SchemaAbstractOperation (org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation)1