Search in sources :

Example 1 with SchemaProposeDiscoveryMessage

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

the class GridQueryProcessor method onSchemaFinishDiscovery.

/**
 * Process schema finish message from discovery thread.
 *
 * @param msg Message.
 */
private void onSchemaFinishDiscovery(SchemaFinishDiscoveryMessage msg) {
    UUID opId = msg.operation().id();
    if (log.isDebugEnabled())
        log.debug("Received schema finish message (discovery) [opId=" + opId + ", msg=" + msg + ']');
    synchronized (stateMux) {
        if (disconnected)
            return;
        boolean completedOpAdded = completedOpIds.add(opId);
        assert completedOpAdded;
        // Remove propose message so that it will not be shared with joining nodes.
        SchemaProposeDiscoveryMessage proposeMsg = activeProposals.remove(opId);
        assert proposeMsg != null;
        // Apply changes to public cache schema if operation is successful and original cache is still there.
        if (!msg.hasError()) {
            DynamicCacheDescriptor cacheDesc = ctx.cache().cacheDescriptor(msg.operation().cacheName());
            if (cacheDesc != null && F.eq(cacheDesc.deploymentId(), proposeMsg.deploymentId())) {
                cacheDesc.schemaChangeFinish(msg);
                try {
                    ctx.cache().saveCacheConfiguration(cacheDesc);
                } catch (IgniteCheckedException e) {
                    U.error(log, "Error while saving cache configuration on disk, cfg = " + cacheDesc.cacheConfiguration(), e);
                }
            }
        }
        // Propose message will be used from exchange thread to
        msg.proposeMessage(proposeMsg);
        if (exchangeReady) {
            SchemaOperation op = schemaOps.get(proposeMsg.schemaName());
            if (F.eq(op.id(), opId)) {
                // Completed top operation.
                op.finishMessage(msg);
                if (op.started())
                    op.doFinish();
            } else {
                // Completed operation in the middle, will schedule completion later.
                while (op != null) {
                    if (F.eq(op.id(), opId))
                        break;
                    op = op.next();
                }
                assert op != null;
                assert !op.started();
                op.finishMessage(msg);
            }
        } else {
            // Set next operation as top-level one.
            String schemaName = proposeMsg.schemaName();
            SchemaOperation op = schemaOps.remove(schemaName);
            assert op != null;
            assert F.eq(op.id(), opId);
            // Chain to the next operation (if any).
            SchemaOperation nextOp = op.next();
            if (nextOp != null)
                schemaOps.put(schemaName, nextOp);
        }
        // Clean stale IO messages from just-joined nodes.
        cleanStaleStatusMessages(opId);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) SchemaProposeDiscoveryMessage(org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) UUID(java.util.UUID)

Example 2 with SchemaProposeDiscoveryMessage

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

the class GridQueryProcessor method processStatusMessage.

/**
 * Process status message.
 *
 * @param msg Status message.
 */
private void processStatusMessage(SchemaOperationStatusMessage msg) {
    synchronized (stateMux) {
        if (completedOpIds.contains(msg.operationId())) {
            // Received message from a node which joined topology in the middle of operation execution.
            if (log.isDebugEnabled())
                log.debug("Received status message for completed operation (will ignore) [" + "opId=" + msg.operationId() + ", sndNodeId=" + msg.senderNodeId() + ']');
            return;
        }
        UUID opId = msg.operationId();
        SchemaProposeDiscoveryMessage proposeMsg = activeProposals.get(opId);
        if (proposeMsg != null) {
            SchemaOperation op = schemaOps.get(proposeMsg.schemaName());
            if (op != null && F.eq(op.id(), opId) && op.started() && coordinator().isLocal()) {
                if (log.isDebugEnabled())
                    log.debug("Received status message [opId=" + msg.operationId() + ", sndNodeId=" + msg.senderNodeId() + ']');
                op.manager().onNodeFinished(msg.senderNodeId(), unmarshalSchemaError(msg.errorBytes()));
                return;
            }
        }
        // Put to pending set if operation is not visible/ready yet.
        pendingMsgs.add(msg);
        if (log.isDebugEnabled())
            log.debug("Received status message (added to pending set) [opId=" + msg.operationId() + ", sndNodeId=" + msg.senderNodeId() + ']');
    }
}
Also used : SchemaProposeDiscoveryMessage(org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage) UUID(java.util.UUID)

Example 3 with SchemaProposeDiscoveryMessage

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

the class GridQueryProcessor method startSchemaChange.

/**
 * Initiate actual schema change operation.
 *
 * @param schemaOp Schema operation.
 */
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 {
            T2<Boolean, SchemaOperationException> res = prepareChangeOnNotStartedCache(op, cacheDesc);
            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) SchemaAbstractOperation(org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation) SchemaProposeDiscoveryMessage(org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage) 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) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 4 with SchemaProposeDiscoveryMessage

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

the class GridCacheProcessor method processCustomExchangeTask.

/**
 * Process custom exchange task.
 *
 * @param task Task.
 */
void processCustomExchangeTask(CachePartitionExchangeWorkerTask task) {
    if (task instanceof SchemaExchangeWorkerTask) {
        SchemaAbstractDiscoveryMessage msg = ((SchemaExchangeWorkerTask) task).message();
        if (msg instanceof SchemaProposeDiscoveryMessage) {
            SchemaProposeDiscoveryMessage msg0 = (SchemaProposeDiscoveryMessage) msg;
            ctx.query().onSchemaPropose(msg0);
        } else
            U.warn(log, "Unsupported schema discovery message: " + msg);
    } else if (task instanceof SchemaNodeLeaveExchangeWorkerTask) {
        SchemaNodeLeaveExchangeWorkerTask task0 = (SchemaNodeLeaveExchangeWorkerTask) task;
        ctx.query().onNodeLeave(task0.node());
    } else if (task instanceof ClientCacheChangeDummyDiscoveryMessage) {
        ClientCacheChangeDummyDiscoveryMessage task0 = (ClientCacheChangeDummyDiscoveryMessage) task;
        sharedCtx.affinity().processClientCachesRequests(task0);
    } else if (task instanceof ClientCacheUpdateTimeout) {
        ClientCacheUpdateTimeout task0 = (ClientCacheUpdateTimeout) task;
        sharedCtx.affinity().sendClientCacheChangesMessage(task0);
    } else if (task instanceof CacheStatisticsModeChangeTask) {
        CacheStatisticsModeChangeTask task0 = (CacheStatisticsModeChangeTask) task;
        processStatisticsModeChange(task0.message());
    } else if (task instanceof TxTimeoutOnPartitionMapExchangeChangeTask) {
        TxTimeoutOnPartitionMapExchangeChangeTask task0 = (TxTimeoutOnPartitionMapExchangeChangeTask) task;
        sharedCtx.tm().processTxTimeoutOnPartitionMapExchangeChange(task0.message());
    } else if (task instanceof StopCachesOnClientReconnectExchangeTask) {
        StopCachesOnClientReconnectExchangeTask task0 = (StopCachesOnClientReconnectExchangeTask) task;
        stopCachesOnClientReconnect(task0.stoppedCaches());
        task0.onDone();
    } else if (task instanceof WalStateNodeLeaveExchangeTask) {
        WalStateNodeLeaveExchangeTask task0 = (WalStateNodeLeaveExchangeTask) task;
        sharedCtx.walState().onNodeLeft(task0.node().id());
    } else if (task instanceof FinishPreloadingTask) {
        FinishPreloadingTask task0 = (FinishPreloadingTask) task;
        CacheGroupContext grp = cacheGroup(task0.groupId());
        if (grp != null)
            grp.preloader().finishPreloading(task0.topologyVersion(), task0.rebalanceId());
    } else
        U.warn(log, "Unsupported custom exchange task: " + task);
}
Also used : StopCachesOnClientReconnectExchangeTask(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.StopCachesOnClientReconnectExchangeTask) SchemaExchangeWorkerTask(org.apache.ignite.internal.processors.query.schema.SchemaExchangeWorkerTask) FinishPreloadingTask(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.FinishPreloadingTask) SchemaProposeDiscoveryMessage(org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage) SchemaNodeLeaveExchangeWorkerTask(org.apache.ignite.internal.processors.query.schema.SchemaNodeLeaveExchangeWorkerTask) SchemaAbstractDiscoveryMessage(org.apache.ignite.internal.processors.query.schema.message.SchemaAbstractDiscoveryMessage)

Example 5 with SchemaProposeDiscoveryMessage

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

the class GridQueryProcessor method collectGridNodeData.

/**
 * {@inheritDoc}
 */
@Override
public void collectGridNodeData(DiscoveryDataBag dataBag) {
    LinkedHashMap<UUID, SchemaProposeDiscoveryMessage> proposals;
    // Collect active proposals.
    synchronized (stateMux) {
        proposals = new LinkedHashMap<>(activeProposals);
    }
    dataBag.addGridCommonData(DiscoveryDataExchangeType.QUERY_PROC.ordinal(), proposals);
    // node from server node.
    if (!dataBag.isJoiningNodeClient()) {
        HashMap<String, Serializable> nodeSpecificMap = new HashMap<>();
        Serializable oldVal = nodeSpecificMap.put(INLINE_SIZES_DISCO_BAG_KEY, collectSecondaryIndexesInlineSize());
        assert oldVal == null : oldVal;
        dataBag.addNodeSpecificData(DiscoveryDataExchangeType.QUERY_PROC.ordinal(), nodeSpecificMap);
    }
}
Also used : Serializable(java.io.Serializable) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SchemaProposeDiscoveryMessage(org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage) UUID(java.util.UUID)

Aggregations

SchemaProposeDiscoveryMessage (org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage)10 UUID (java.util.UUID)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 Serializable (java.io.Serializable)2 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CacheException (javax.cache.CacheException)2 IgniteException (org.apache.ignite.IgniteException)2 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)2 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)2 SQLException (java.sql.SQLException)1 Collections.newSetFromMap (java.util.Collections.newSetFromMap)1 Map (java.util.Map)1 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)1