Search in sources :

Example 6 with GridCacheDrInfo

use of org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo 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.
     */
@SuppressWarnings("ForLoopReplaceableByForEach")
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);
        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();
        UUID nodeId = primary.id();
        PrimaryRequestState mapped = pendingMappings.get(nodeId);
        if (mapped == null) {
            GridNearAtomicFullUpdateRequest req = new GridNearAtomicFullUpdateRequest(cctx.cacheId(), nodeId, futId, topVer, topLocked, syncMode, op, retval, expiryPlc, invokeArgs, filter, subjId, taskNameHash, needPrimaryRes, skipStore, keepBinary, recovery, 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) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) UUID(java.util.UUID) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 7 with GridCacheDrInfo

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

the class IgniteDrDataStreamerCacheUpdater method receive.

/** {@inheritDoc} */
@Override
public void receive(IgniteCache<KeyCacheObject, CacheObject> cache0, Collection<Map.Entry<KeyCacheObject, CacheObject>> col) {
    try {
        String cacheName = cache0.getConfiguration(CacheConfiguration.class).getName();
        GridKernalContext ctx = ((IgniteKernal) cache0.unwrap(Ignite.class)).context();
        IgniteLogger log = ctx.log(IgniteDrDataStreamerCacheUpdater.class);
        GridCacheAdapter internalCache = ctx.cache().internalCache(cacheName);
        CacheOperationContext opCtx = ((IgniteCacheProxy) cache0).operationContext();
        IgniteInternalCache cache = opCtx != null ? new GridCacheProxyImpl(internalCache.context(), internalCache, opCtx) : internalCache;
        assert !F.isEmpty(col);
        if (log.isDebugEnabled())
            log.debug("Running DR put job [nodeId=" + ctx.localNodeId() + ", cacheName=" + cacheName + ']');
        CacheObjectContext cacheObjCtx = cache.context().cacheObjectContext();
        for (Map.Entry<KeyCacheObject, CacheObject> entry0 : col) {
            GridCacheRawVersionedEntry entry = (GridCacheRawVersionedEntry) entry0;
            entry.unmarshal(cacheObjCtx, ctx.config().getMarshaller());
            KeyCacheObject key = entry.getKey();
            // Ensure that receiver to not receive special-purpose values for TTL and expire time.
            assert entry.ttl() != CU.TTL_NOT_CHANGED && entry.ttl() != CU.TTL_ZERO && entry.ttl() >= 0;
            assert entry.expireTime() != CU.EXPIRE_TIME_CALCULATE && entry.expireTime() >= 0;
            CacheObject cacheVal = entry.getValue();
            GridCacheDrInfo val = cacheVal != null ? entry.ttl() != CU.TTL_ETERNAL ? new GridCacheDrExpirationInfo(cacheVal, entry.version(), entry.ttl(), entry.expireTime()) : new GridCacheDrInfo(cacheVal, entry.version()) : null;
            if (val == null)
                cache.removeAllConflict(Collections.singletonMap(key, entry.version()));
            else
                cache.putAllConflict(Collections.singletonMap(key, val));
        }
        if (log.isDebugEnabled())
            log.debug("DR put job finished [nodeId=" + ctx.localNodeId() + ", cacheName=" + cacheName + ']');
    } catch (IgniteCheckedException e) {
        throw U.convertException(e);
    }
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) GridKernalContext(org.apache.ignite.internal.GridKernalContext) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) GridCacheProxyImpl(org.apache.ignite.internal.processors.cache.GridCacheProxyImpl) IgniteCacheProxy(org.apache.ignite.internal.processors.cache.IgniteCacheProxy) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) GridCacheDrInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheDrExpirationInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrExpirationInfo) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) Ignite(org.apache.ignite.Ignite) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteLogger(org.apache.ignite.IgniteLogger) GridCacheRawVersionedEntry(org.apache.ignite.internal.processors.cache.version.GridCacheRawVersionedEntry) Map(java.util.Map) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

GridCacheDrInfo (org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo)7 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)6 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)5 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)3 CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)3 Map (java.util.Map)2 UUID (java.util.UUID)2 EntryProcessor (javax.cache.processor.EntryProcessor)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 ClusterTopologyServerNotFoundException (org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException)2 GridCacheDrExpirationInfo (org.apache.ignite.internal.processors.cache.dr.GridCacheDrExpirationInfo)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 Ignite (org.apache.ignite.Ignite)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1