Search in sources :

Example 21 with ClusterTopologyServerNotFoundException

use of org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException in project ignite by apache.

the class GridNearAtomicUpdateFuture method mapUpdate.

/**
 * @param topNodes Cache nodes.
 * @param topVer Topology version.
 * @param futId Future ID.
 * @param remapKeys Keys to remap.
 * @return Mapping.
 * @throws Exception If failed.
 */
private Map<UUID, PrimaryRequestState> mapUpdate(Collection<ClusterNode> topNodes, AffinityTopologyVersion topVer, Long futId, @Nullable Collection<KeyCacheObject> remapKeys, boolean mappingKnown) throws Exception {
    Iterator<?> it = null;
    if (vals != null)
        it = vals.iterator();
    Iterator<GridCacheDrInfo> conflictPutValsIt = null;
    if (conflictPutVals != null)
        conflictPutValsIt = conflictPutVals.iterator();
    Iterator<GridCacheVersion> conflictRmvValsIt = null;
    if (conflictRmvVals != null)
        conflictRmvValsIt = conflictRmvVals.iterator();
    Map<UUID, PrimaryRequestState> pendingMappings = U.newHashMap(topNodes.size());
    // Create mappings first, then send messages.
    for (Object key : keys) {
        if (key == null)
            throw new NullPointerException("Null key.");
        Object val;
        GridCacheVersion conflictVer;
        long conflictTtl;
        long conflictExpireTime;
        if (vals != null) {
            val = it.next();
            conflictVer = null;
            conflictTtl = CU.TTL_NOT_CHANGED;
            conflictExpireTime = CU.EXPIRE_TIME_CALCULATE;
            if (val == null)
                throw new NullPointerException("Null value.");
        } else if (conflictPutVals != null) {
            GridCacheDrInfo conflictPutVal = conflictPutValsIt.next();
            val = conflictPutVal.valueEx();
            conflictVer = conflictPutVal.version();
            conflictTtl = conflictPutVal.ttl();
            conflictExpireTime = conflictPutVal.expireTime();
        } else if (conflictRmvVals != null) {
            val = null;
            conflictVer = conflictRmvValsIt.next();
            conflictTtl = CU.TTL_NOT_CHANGED;
            conflictExpireTime = CU.EXPIRE_TIME_CALCULATE;
        } else {
            val = null;
            conflictVer = null;
            conflictTtl = CU.TTL_NOT_CHANGED;
            conflictExpireTime = CU.EXPIRE_TIME_CALCULATE;
        }
        if (val == null && op != GridCacheOperation.DELETE)
            continue;
        KeyCacheObject cacheKey = cctx.toCacheKeyObject(key);
        if (remapKeys != null && !remapKeys.contains(cacheKey))
            continue;
        if (op != TRANSFORM) {
            val = cctx.toCacheObject(val);
            if (op == CREATE || op == UPDATE)
                cctx.validateKeyAndValue(cacheKey, (CacheObject) val);
        } else
            val = EntryProcessorResourceInjectorProxy.wrap(cctx.kernalContext(), (EntryProcessor) val);
        List<ClusterNode> nodes = cctx.affinity().nodesByKey(cacheKey, topVer);
        if (F.isEmpty(nodes))
            throw new ClusterTopologyServerNotFoundException("Failed to map keys for cache " + "(all partition nodes left the grid).");
        ClusterNode primary = nodes.get(0);
        boolean needPrimaryRes = !mappingKnown || primary.isLocal() || nearEnabled;
        UUID nodeId = primary.id();
        PrimaryRequestState mapped = pendingMappings.get(nodeId);
        if (mapped == null) {
            byte flags = GridNearAtomicAbstractUpdateRequest.flags(nearEnabled, topLocked, retval, mappingKnown, needPrimaryRes, skipStore, keepBinary, recovery);
            GridNearAtomicFullUpdateRequest req = new GridNearAtomicFullUpdateRequest(cctx.cacheId(), nodeId, futId, topVer, syncMode, op, expiryPlc, invokeArgs, filter, taskNameHash, flags, cctx.deploymentEnabled(), keys.size());
            mapped = new PrimaryRequestState(req, nodes, false);
            pendingMappings.put(nodeId, mapped);
        }
        if (mapped.req.initMappingLocally())
            mapped.addMapping(nodes);
        mapped.req.addUpdateEntry(cacheKey, val, conflictTtl, conflictExpireTime, conflictVer);
    }
    return pendingMappings;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheDrInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) UUID(java.util.UUID) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 22 with ClusterTopologyServerNotFoundException

use of org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException in project ignite by apache.

the class GridNearAtomicUpdateFuture method map.

/**
 * @param topVer Topology version.
 * @param remapKeys Keys to remap.
 */
private void map(AffinityTopologyVersion topVer, @Nullable Collection<KeyCacheObject> remapKeys) {
    Collection<ClusterNode> topNodes = CU.affinityNodes(cctx, topVer);
    if (F.isEmpty(topNodes)) {
        completeFuture(null, new ClusterTopologyServerNotFoundException("Failed to map keys for cache (all partition nodes left the grid)."), null);
        return;
    }
    long futId = cctx.mvcc().nextAtomicId();
    Exception err = null;
    PrimaryRequestState singleReq0 = null;
    Map<UUID, PrimaryRequestState> mappings0 = null;
    int size = keys.size();
    boolean mappingKnown = cctx.topology().rebalanceFinished(topVer);
    try {
        if (size == 1) {
            assert remapKeys == null || remapKeys.size() == 1;
            singleReq0 = mapSingleUpdate(topVer, futId, mappingKnown);
        } else {
            Map<UUID, PrimaryRequestState> pendingMappings = mapUpdate(topNodes, topVer, futId, remapKeys, mappingKnown);
            if (pendingMappings.size() == 1)
                singleReq0 = F.firstValue(pendingMappings);
            else {
                mappings0 = pendingMappings;
                assert !mappings0.isEmpty() || size == 0 : this;
            }
        }
        synchronized (this) {
            assert topVer.topologyVersion() > 0 : topVer;
            assert this.topVer == AffinityTopologyVersion.ZERO : this;
            this.topVer = topVer;
            this.futId = futId;
            resCnt = 0;
            singleReq = singleReq0;
            mappings = mappings0;
            this.remapKeys = null;
        }
        if (storeFuture() && !cctx.mvcc().addAtomicFuture(futId, this)) {
            assert isDone();
            return;
        }
    } catch (Exception e) {
        err = e;
    }
    if (err != null) {
        completeFuture(null, err, futId);
        return;
    }
    // Optimize mapping for single key.
    if (singleReq0 != null)
        sendSingleRequest(singleReq0.req.nodeId(), singleReq0.req);
    else {
        assert mappings0 != null;
        if (size == 0) {
            completeFuture(new GridCacheReturn(cctx, true, true, null, null, true), null, futId);
            return;
        } else
            sendUpdateRequests(mappings0);
    }
    if (syncMode == FULL_ASYNC) {
        completeFuture(new GridCacheReturn(cctx, true, true, null, null, true), null, futId);
        return;
    }
    if (mappingKnown && syncMode == FULL_SYNC && cctx.discovery().topologyVersion() != topVer.topologyVersion())
        checkDhtNodes(futId);
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) UUID(java.util.UUID) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IgniteCacheRestartingException(org.apache.ignite.IgniteCacheRestartingException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) CacheStoppedException(org.apache.ignite.internal.processors.cache.CacheStoppedException) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException)

Example 23 with ClusterTopologyServerNotFoundException

use of org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException in project ignite by apache.

the class IgniteH2Indexing method executeUpdateTransactional.

/**
 * Execute update in transactional mode.
 *
 * @param qryId Query id.
 * @param qryDesc Query descriptor.
 * @param qryParams Query parameters.
 * @param dml Plan.
 * @param loc Local flag.
 * @param cancel Cancel hook.
 * @return Update result.
 * @throws IgniteCheckedException If failed.
 */
private UpdateResult executeUpdateTransactional(long qryId, QueryDescriptor qryDesc, QueryParameters qryParams, QueryParserResultDml dml, boolean loc, GridQueryCancel cancel) throws IgniteCheckedException {
    UpdatePlan plan = dml.plan();
    GridCacheContext cctx = plan.cacheContext();
    assert cctx != null;
    assert cctx.transactional();
    GridNearTxLocal tx = tx(ctx);
    boolean implicit = (tx == null);
    boolean commit = implicit && qryParams.autoCommit();
    if (implicit)
        tx = txStart(cctx, qryParams.timeout());
    requestSnapshot(tx);
    try (GridNearTxLocal toCommit = commit ? tx : null) {
        DmlDistributedPlanInfo distributedPlan = loc ? null : plan.distributedPlan();
        long timeout = implicit ? tx.remainingTime() : operationTimeout(qryParams.timeout(), tx);
        if (cctx.isReplicated() || distributedPlan == null || ((plan.mode() == UpdateMode.INSERT || plan.mode() == UpdateMode.MERGE) && !plan.isLocalSubquery())) {
            boolean sequential = true;
            UpdateSourceIterator<?> it;
            if (plan.fastResult()) {
                IgniteBiTuple row = plan.getFastRow(qryParams.arguments());
                assert row != null;
                EnlistOperation op = UpdatePlan.enlistOperation(plan.mode());
                it = new DmlUpdateSingleEntryIterator<>(op, op.isDeleteOrLock() ? row.getKey() : row);
            } else if (plan.hasRows()) {
                it = new DmlUpdateResultsIterator(UpdatePlan.enlistOperation(plan.mode()), plan, plan.createRows(qryParams.arguments()));
            } else {
                SqlFieldsQuery selectFieldsQry = new SqlFieldsQuery(plan.selectQuery(), qryDesc.collocated()).setArgs(qryParams.arguments()).setDistributedJoins(qryDesc.distributedJoins()).setEnforceJoinOrder(qryDesc.enforceJoinOrder()).setLocal(qryDesc.local()).setPageSize(qryParams.pageSize()).setTimeout((int) timeout, TimeUnit.MILLISECONDS).setLazy(qryParams.lazy());
                FieldsQueryCursor<List<?>> cur = executeSelectForDml(qryId, qryDesc.schemaName(), selectFieldsQry, MvccUtils.mvccTracker(cctx, tx), cancel, (int) timeout);
                it = plan.iteratorForTransaction(connMgr, cur);
            }
            // TODO: IGNITE-11176 - Need to support cancellation
            IgniteInternalFuture<Long> fut = tx.updateAsync(cctx, it, qryParams.pageSize(), timeout, sequential);
            UpdateResult res = new UpdateResult(fut.get(), X.EMPTY_OBJECT_ARRAY, plan.distributedPlan() != null ? plan.distributedPlan().derivedPartitions() : null);
            if (commit)
                toCommit.commit();
            return res;
        }
        int[] ids = U.toIntArray(distributedPlan.getCacheIds());
        int flags = 0;
        if (qryDesc.enforceJoinOrder())
            flags |= GridH2QueryRequest.FLAG_ENFORCE_JOIN_ORDER;
        if (distributedPlan.isReplicatedOnly())
            flags |= GridH2QueryRequest.FLAG_REPLICATED;
        if (qryParams.lazy())
            flags |= GridH2QueryRequest.FLAG_LAZY;
        flags = GridH2QueryRequest.setDataPageScanEnabled(flags, qryParams.dataPageScanEnabled());
        int[] parts = PartitionResult.calculatePartitions(qryParams.partitions(), distributedPlan.derivedPartitions(), qryParams.arguments());
        if (parts != null && parts.length == 0)
            return new UpdateResult(0, X.EMPTY_OBJECT_ARRAY, distributedPlan.derivedPartitions());
        else {
            // TODO: IGNITE-11176 - Need to support cancellation
            IgniteInternalFuture<Long> fut = tx.updateAsync(cctx, ids, parts, qryDesc.schemaName(), qryDesc.sql(), qryParams.arguments(), flags, qryParams.pageSize(), timeout);
            UpdateResult res = new UpdateResult(fut.get(), X.EMPTY_OBJECT_ARRAY, distributedPlan.derivedPartitions());
            if (commit)
                toCommit.commit();
            return res;
        }
    } catch (ClusterTopologyServerNotFoundException e) {
        throw new CacheServerNotFoundException(e.getMessage(), e);
    } catch (IgniteCheckedException e) {
        IgniteSQLException sqlEx = X.cause(e, IgniteSQLException.class);
        if (sqlEx != null)
            throw sqlEx;
        Exception ex = IgniteUtils.convertExceptionNoWrap(e);
        if (ex instanceof IgniteException)
            throw (IgniteException) ex;
        U.error(log, "Error during update [localNodeId=" + ctx.localNodeId() + "]", ex);
        throw new IgniteSQLException("Failed to run update. " + ex.getMessage(), ex);
    } finally {
        if (commit)
            cctx.tm().resetContext();
    }
}
Also used : FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor) CacheServerNotFoundException(org.apache.ignite.cache.CacheServerNotFoundException) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) EnlistOperation(org.apache.ignite.internal.processors.query.EnlistOperation) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) DmlUpdateResultsIterator(org.apache.ignite.internal.processors.query.h2.dml.DmlUpdateResultsIterator) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) DmlDistributedPlanInfo(org.apache.ignite.internal.processors.query.h2.dml.DmlDistributedPlanInfo) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) BatchUpdateException(java.sql.BatchUpdateException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteClusterReadOnlyException(org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException) CacheServerNotFoundException(org.apache.ignite.cache.CacheServerNotFoundException) SQLException(java.sql.SQLException) IgniteException(org.apache.ignite.IgniteException) CacheException(javax.cache.CacheException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IgniteSQLException(org.apache.ignite.internal.processors.query.IgniteSQLException) UpdatePlan(org.apache.ignite.internal.processors.query.h2.dml.UpdatePlan)

Aggregations

ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)23 ClusterNode (org.apache.ignite.cluster.ClusterNode)15 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)12 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)9 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)8 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)7 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)7 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)7 ArrayList (java.util.ArrayList)5 UUID (java.util.UUID)5 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)5 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)5 Map (java.util.Map)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 IgniteException (org.apache.ignite.IgniteException)3 CachePartialUpdateCheckedException (org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException)3 GridDistributedTxMapping (org.apache.ignite.internal.processors.cache.distributed.GridDistributedTxMapping)3 Collections (java.util.Collections)2