Search in sources :

Example 1 with GridCacheDrExpirationInfo

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

the class GridDhtAtomicCache method remapToNewPrimary.

/**
     * @param req Request to remap.
     */
void remapToNewPrimary(GridNearAtomicAbstractUpdateRequest req) {
    assert req.writeSynchronizationMode() == FULL_ASYNC : req;
    if (log.isDebugEnabled())
        log.debug("Remapping near update request locally: " + req);
    Collection<?> vals;
    Collection<GridCacheDrInfo> drPutVals;
    Collection<GridCacheVersion> drRmvVals;
    if (req.conflictVersions() == null) {
        vals = req.values();
        drPutVals = null;
        drRmvVals = null;
    } else if (req.operation() == UPDATE) {
        int size = req.keys().size();
        drPutVals = new ArrayList<>(size);
        for (int i = 0; i < size; i++) {
            long ttl = req.conflictTtl(i);
            if (ttl == CU.TTL_NOT_CHANGED)
                drPutVals.add(new GridCacheDrInfo(req.value(i), req.conflictVersion(i)));
            else
                drPutVals.add(new GridCacheDrExpirationInfo(req.value(i), req.conflictVersion(i), ttl, req.conflictExpireTime(i)));
        }
        vals = null;
        drRmvVals = null;
    } else {
        assert req.operation() == DELETE : req;
        drRmvVals = req.conflictVersions();
        vals = null;
        drPutVals = null;
    }
    GridNearAtomicUpdateFuture updateFut = new GridNearAtomicUpdateFuture(ctx, this, ctx.config().getWriteSynchronizationMode(), req.operation(), req.keys(), vals, req.invokeArguments(), drPutVals, drRmvVals, req.returnValue(), false, req.expiry(), req.filter(), req.subjectId(), req.taskNameHash(), req.skipStore(), req.keepBinary(), req.recovery(), MAX_RETRIES);
    updateFut.map();
}
Also used : GridCacheDrInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheDrExpirationInfo(org.apache.ignite.internal.processors.cache.dr.GridCacheDrExpirationInfo) ArrayList(java.util.ArrayList)

Example 2 with GridCacheDrExpirationInfo

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

GridCacheDrExpirationInfo (org.apache.ignite.internal.processors.cache.dr.GridCacheDrExpirationInfo)2 GridCacheDrInfo (org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Ignite (org.apache.ignite.Ignite)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 GridKernalContext (org.apache.ignite.internal.GridKernalContext)1 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)1 CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)1 CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)1 GridCacheAdapter (org.apache.ignite.internal.processors.cache.GridCacheAdapter)1 GridCacheProxyImpl (org.apache.ignite.internal.processors.cache.GridCacheProxyImpl)1 IgniteCacheProxy (org.apache.ignite.internal.processors.cache.IgniteCacheProxy)1 IgniteInternalCache (org.apache.ignite.internal.processors.cache.IgniteInternalCache)1 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)1 GridCacheRawVersionedEntry (org.apache.ignite.internal.processors.cache.version.GridCacheRawVersionedEntry)1 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)1