Search in sources :

Example 81 with CacheObject

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

Example 82 with CacheObject

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

the class GridBinaryAffinityKeySelfTest method checkAffinity.

/**
     * @param ignite Ignite.
     * @throws Exception If failed.
     */
private void checkAffinity(Ignite ignite) throws Exception {
    Affinity<Object> aff = ignite.affinity(DEFAULT_CACHE_NAME);
    GridAffinityProcessor affProc = ((IgniteKernal) ignite).context().affinity();
    IgniteCacheObjectProcessor cacheObjProc = ((IgniteKernal) ignite).context().cacheObjects();
    CacheObjectContext cacheObjCtx = cacheObjProc.contextForCache(ignite.cache(DEFAULT_CACHE_NAME).getConfiguration(CacheConfiguration.class));
    for (int i = 0; i < 1000; i++) {
        assertEquals(i, aff.affinityKey(i));
        assertEquals(i, aff.affinityKey(new TestObject(i)));
        assertEquals(i, aff.affinityKey(ignite.binary().toBinary(new TestObject(i))));
        assertEquals(i, aff.affinityKey(new AffinityKey(0, i)));
        BinaryObjectBuilder bldr = ignite.binary().builder("TestObject2");
        bldr.setField("affKey", i);
        assertEquals(i, aff.affinityKey(bldr.build()));
        CacheObject cacheObj = cacheObjProc.toCacheObject(cacheObjCtx, new TestObject(i), true);
        assertEquals(i, aff.affinityKey(cacheObj));
        assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(new TestObject(i)));
        assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(cacheObj));
        assertEquals(i, affProc.affinityKey(DEFAULT_CACHE_NAME, i));
        assertEquals(i, affProc.affinityKey(DEFAULT_CACHE_NAME, new TestObject(i)));
        assertEquals(i, affProc.affinityKey(DEFAULT_CACHE_NAME, cacheObj));
        assertEquals(affProc.mapKeyToNode(DEFAULT_CACHE_NAME, i), affProc.mapKeyToNode(DEFAULT_CACHE_NAME, new TestObject(i)));
        assertEquals(affProc.mapKeyToNode(DEFAULT_CACHE_NAME, i), affProc.mapKeyToNode(DEFAULT_CACHE_NAME, cacheObj));
        assertEquals(affProc.mapKeyToNode(DEFAULT_CACHE_NAME, new AffinityKey(0, i)), affProc.mapKeyToNode(DEFAULT_CACHE_NAME, i));
    }
}
Also used : GridAffinityProcessor(org.apache.ignite.internal.processors.affinity.GridAffinityProcessor) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)82 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)74 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)42 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)41 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)34 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)24 CacheLockCandidates (org.apache.ignite.internal.processors.cache.CacheLockCandidates)17 GridCacheMvcc (org.apache.ignite.internal.processors.cache.GridCacheMvcc)17 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)14 ArrayList (java.util.ArrayList)13 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)12 IgniteTxEntry (org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry)12 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)11 GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)11 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)10 Nullable (org.jetbrains.annotations.Nullable)10 IgniteException (org.apache.ignite.IgniteException)9 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)9 IgniteTxKey (org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey)9 LinkedHashMap (java.util.LinkedHashMap)8