Search in sources :

Example 1 with SchemaOperationClientFuture

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

the class GridQueryProcessor method onSchemaFinishDiscovery.

/**
     * Process schema finish message from discovery thread.
     *
     * @param msg Message.
     */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
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);
        }
        // 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);
    }
    // Complete client future (if any).
    SchemaOperationClientFuture cliFut = schemaCliFuts.remove(opId);
    if (cliFut != null) {
        if (msg.hasError())
            cliFut.onDone(msg.error());
        else
            cliFut.onDone();
    }
}
Also used : SchemaProposeDiscoveryMessage(org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) SchemaOperationClientFuture(org.apache.ignite.internal.processors.query.schema.SchemaOperationClientFuture) UUID(java.util.UUID)

Example 2 with SchemaOperationClientFuture

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

the class GridQueryProcessor method onDisconnected.

/** {@inheritDoc} */
@Override
public void onDisconnected(IgniteFuture<?> reconnectFut) throws IgniteCheckedException {
    Collection<SchemaOperationClientFuture> futs;
    synchronized (stateMux) {
        disconnected = true;
        exchangeReady = false;
        // Clear client futures.
        futs = new ArrayList<>(schemaCliFuts.values());
        schemaCliFuts.clear();
        // Clear operations data.
        activeProposals.clear();
        schemaOps.clear();
    }
    // Complete client futures outside of synchronized block because they may have listeners/chains.
    for (SchemaOperationClientFuture fut : futs) fut.onDone(new SchemaOperationException("Client node is disconnected (operation result is unknown)."));
    if (idx != null)
        idx.onDisconnected(reconnectFut);
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) SchemaOperationClientFuture(org.apache.ignite.internal.processors.query.schema.SchemaOperationClientFuture)

Example 3 with SchemaOperationClientFuture

use of org.apache.ignite.internal.processors.query.schema.SchemaOperationClientFuture 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 {
                // 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());
            }
        }
    }
    // 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) 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)

Example 4 with SchemaOperationClientFuture

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

the class GridQueryProcessor method startIndexOperationDistributed.

/**
     * Start distributed index change operation.
     *
     * @param op Operation.
     * @return Future.
     */
private IgniteInternalFuture<?> startIndexOperationDistributed(SchemaAbstractOperation op) {
    SchemaOperationClientFuture fut = new SchemaOperationClientFuture(op.id());
    SchemaOperationClientFuture oldFut = schemaCliFuts.put(op.id(), fut);
    assert oldFut == null;
    try {
        ctx.discovery().sendCustomEvent(new SchemaProposeDiscoveryMessage(op));
        if (log.isDebugEnabled())
            log.debug("Sent schema propose discovery message [opId=" + op.id() + ", op=" + op + ']');
        boolean disconnected0;
        synchronized (stateMux) {
            disconnected0 = disconnected;
        }
        if (disconnected0) {
            fut.onDone(new SchemaOperationException("Client node is disconnected (operation result is unknown)."));
            schemaCliFuts.remove(op.id());
        }
    } catch (Exception e) {
        if (e instanceof SchemaOperationException)
            fut.onDone(e);
        else {
            fut.onDone(new SchemaOperationException("Failed to start schema change operation due to " + "unexpected exception [opId=" + op.id() + ", op=" + op + ']', e));
        }
        schemaCliFuts.remove(op.id());
    }
    return fut;
}
Also used : SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) SchemaProposeDiscoveryMessage(org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage) SchemaOperationClientFuture(org.apache.ignite.internal.processors.query.schema.SchemaOperationClientFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException) SchemaOperationException(org.apache.ignite.internal.processors.query.schema.SchemaOperationException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException)

Aggregations

SchemaOperationClientFuture (org.apache.ignite.internal.processors.query.schema.SchemaOperationClientFuture)4 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)3 UUID (java.util.UUID)2 DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)2 SchemaProposeDiscoveryMessage (org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage)2 SQLException (java.sql.SQLException)1 CacheException (javax.cache.CacheException)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)1 SchemaAbstractOperation (org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation)1 GridClosureException (org.apache.ignite.internal.util.lang.GridClosureException)1