Search in sources :

Example 1 with DynamicCacheDescriptor

use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor in project ignite by apache.

the class GridDiscoveryManager method resolveDiscoCache.

/**
     * Gets discovery cache for given topology version.
     *
     * @param cacheId Cache ID (participates in exception message).
     * @param topVer Topology version.
     * @return Discovery cache.
     */
private DiscoCache resolveDiscoCache(int cacheId, AffinityTopologyVersion topVer) {
    Snapshot snap = topSnap.get();
    DiscoCache cache = AffinityTopologyVersion.NONE.equals(topVer) || topVer.equals(snap.topVer) ? snap.discoCache : discoCacheHist.get(topVer);
    if (cache == null) {
        DynamicCacheDescriptor desc = ctx.cache().cacheDescriptor(cacheId);
        throw new IgniteException("Failed to resolve nodes topology [" + "cacheName=" + (desc != null ? desc.cacheConfiguration().getName() : "N/A") + ", topVer=" + topVer + ", history=" + discoCacheHist.keySet() + ", snap=" + snap + ", locNode=" + ctx.discovery().localNode() + ']');
    }
    return cache;
}
Also used : ClusterMetricsSnapshot(org.apache.ignite.internal.ClusterMetricsSnapshot) IgniteException(org.apache.ignite.IgniteException) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)

Example 2 with DynamicCacheDescriptor

use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor in project ignite by apache.

the class GridDhtPartitionsExchangeFuture method init.

/**
     * Starts activity.
     *
     * @throws IgniteInterruptedCheckedException If interrupted.
     */
public void init() throws IgniteInterruptedCheckedException {
    if (isDone())
        return;
    initTs = U.currentTimeMillis();
    U.await(evtLatch);
    assert discoEvt != null : this;
    assert exchId.nodeId().equals(discoEvt.eventNode().id()) : this;
    assert !dummy && !forcePreload : this;
    try {
        discoCache.updateAlives(cctx.discovery());
        AffinityTopologyVersion topVer = topologyVersion();
        srvNodes = new ArrayList<>(discoCache.serverNodes());
        remaining.addAll(F.nodeIds(F.view(srvNodes, F.remoteNodes(cctx.localNodeId()))));
        crd = srvNodes.isEmpty() ? null : srvNodes.get(0);
        boolean crdNode = crd != null && crd.isLocal();
        skipPreload = cctx.kernalContext().clientNode();
        ExchangeType exchange;
        if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
            DiscoveryCustomMessage msg = ((DiscoveryCustomEvent) discoEvt).customMessage();
            if (msg instanceof DynamicCacheChangeBatch) {
                assert exchActions != null && !exchActions.empty();
                exchange = onCacheChangeRequest(crdNode);
            } else if (msg instanceof StartFullSnapshotAckDiscoveryMessage)
                exchange = CU.clientNode(discoEvt.eventNode()) ? onClientNodeEvent(crdNode) : onServerNodeEvent(crdNode);
            else {
                assert affChangeMsg != null : this;
                exchange = onAffinityChangeRequest(crdNode);
            }
        } else {
            if (discoEvt.type() == EVT_NODE_JOINED) {
                if (!discoEvt.eventNode().isLocal()) {
                    Collection<DynamicCacheDescriptor> receivedCaches = cctx.cache().startReceivedCaches(discoEvt.eventNode().id(), topVer);
                    cctx.affinity().initStartedCaches(crdNode, this, receivedCaches);
                } else
                    cctx.cache().startCachesOnLocalJoin(topVer);
            }
            exchange = CU.clientNode(discoEvt.eventNode()) ? onClientNodeEvent(crdNode) : onServerNodeEvent(crdNode);
        }
        updateTopologies(crdNode);
        if (exchActions != null && exchActions.hasStop())
            cctx.cache().context().database().beforeCachesStop();
        switch(exchange) {
            case ALL:
                {
                    distributedExchange();
                    break;
                }
            case CLIENT:
                {
                    initTopologies();
                    clientOnlyExchange();
                    break;
                }
            case NONE:
                {
                    initTopologies();
                    onDone(topVer);
                    break;
                }
            default:
                assert false;
        }
    } catch (IgniteInterruptedCheckedException e) {
        onDone(e);
        throw e;
    } catch (IgniteNeedReconnectException e) {
        onDone(e);
    } catch (Throwable e) {
        if (reconnectOnError(e))
            onDone(new IgniteNeedReconnectException(cctx.localNode(), e));
        else {
            U.error(log, "Failed to reinitialize local partitions (preloading will be stopped): " + exchId, e);
            onDone(e);
        }
        if (e instanceof Error)
            throw (Error) e;
    }
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) DiscoveryCustomEvent(org.apache.ignite.internal.events.DiscoveryCustomEvent) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) StartFullSnapshotAckDiscoveryMessage(org.apache.ignite.internal.pagemem.snapshot.StartFullSnapshotAckDiscoveryMessage) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) IgniteNeedReconnectException(org.apache.ignite.internal.IgniteNeedReconnectException)

Example 3 with DynamicCacheDescriptor

use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor 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 4 with DynamicCacheDescriptor

use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor 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)

Example 5 with DynamicCacheDescriptor

use of org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor in project ignite by apache.

the class AbstractSchemaSelfTest method assertIndexDescriptor.

/**
     * Make sure index exists in cache descriptor.
     *
     * @param node Node.
     * @param cacheName Cache name.
     * @param tblName Table name.
     * @param idxName Index name.
     * @param fields Fields.
     */
protected static void assertIndexDescriptor(IgniteEx node, String cacheName, String tblName, String idxName, IgniteBiTuple<String, Boolean>... fields) {
    awaitCompletion();
    DynamicCacheDescriptor desc = node.context().cache().cacheDescriptor(cacheName);
    assert desc != null;
    for (QueryEntity entity : desc.schema().entities()) {
        if (F.eq(tblName, entity.getTableName())) {
            for (QueryIndex idx : entity.getIndexes()) {
                if (F.eq(QueryUtils.indexName(entity, idx), idxName)) {
                    LinkedHashMap<String, Boolean> idxFields = idx.getFields();
                    assertEquals(idxFields.size(), fields.length);
                    int i = 0;
                    for (String idxField : idxFields.keySet()) {
                        assertEquals(idxField.toLowerCase(), fields[i].get1().toLowerCase());
                        assertEquals(idxFields.get(idxField), fields[i].get2());
                        i++;
                    }
                    return;
                }
            }
        }
    }
    fail("Index not found [node=" + node.name() + ", cacheName=" + cacheName + ", tlbName=" + tblName + ", idxName=" + idxName + ']');
}
Also used : DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity)

Aggregations

DynamicCacheDescriptor (org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor)10 UUID (java.util.UUID)2 QueryEntity (org.apache.ignite.cache.QueryEntity)2 QueryIndex (org.apache.ignite.cache.QueryIndex)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2 SchemaOperationClientFuture (org.apache.ignite.internal.processors.query.schema.SchemaOperationClientFuture)2 SchemaOperationException (org.apache.ignite.internal.processors.query.schema.SchemaOperationException)2 SchemaProposeDiscoveryMessage (org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage)2 SchemaAbstractOperation (org.apache.ignite.internal.processors.query.schema.operation.SchemaAbstractOperation)2 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Ignite (org.apache.ignite.Ignite)1 IgniteException (org.apache.ignite.IgniteException)1 AffinityFunction (org.apache.ignite.cache.affinity.AffinityFunction)1 AffinityFunctionContext (org.apache.ignite.cache.affinity.AffinityFunctionContext)1 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)1