Search in sources :

Example 11 with CacheObjectContext

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

the class IgniteCacheTtlCleanupSelfTest method testDeferredDeleteTtl.

/**
     * @throws Exception If failed.
     */
public void testDeferredDeleteTtl() throws Exception {
    IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME).withExpiryPolicy(new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 5)));
    int cnt = GridDhtLocalPartition.MAX_DELETE_QUEUE_SIZE / PART_NUM + 100;
    for (long i = 0; i < cnt; i++) grid(0).cache(DEFAULT_CACHE_NAME).put(i * PART_NUM, i);
    for (int i = 0; i < cnt; i++) cache.put(i * PART_NUM, i);
    // Wait 5 seconds.
    Thread.sleep(6_000);
    assertEquals(cnt, grid(0).cache(DEFAULT_CACHE_NAME).size());
    GridCacheAdapter<Object, Object> cacheAdapter = ((IgniteKernal) grid(0)).internalCache(DEFAULT_CACHE_NAME);
    IgniteCacheObjectProcessor cacheObjects = cacheAdapter.context().cacheObjects();
    CacheObjectContext cacheObjCtx = cacheAdapter.context().cacheObjectContext();
    for (int i = 0; i < 100; i++) assertNull(cacheAdapter.map().getEntry(cacheObjects.toCacheKeyObject(cacheObjCtx, null, i, true)));
}
Also used : IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteCacheObjectProcessor(org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor) Duration(javax.cache.expiry.Duration) CreatedExpiryPolicy(javax.cache.expiry.CreatedExpiryPolicy) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext)

Example 12 with CacheObjectContext

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

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

the class GridQueryProcessor method remove.

/**
     * @param cacheName Cache name.
     * @param key Key.
     * @throws IgniteCheckedException Thrown in case of any errors.
     */
public void remove(String cacheName, KeyCacheObject key, int partId, CacheObject val, GridCacheVersion ver) throws IgniteCheckedException {
    assert key != null;
    if (log.isDebugEnabled())
        log.debug("Remove [cacheName=" + cacheName + ", key=" + key + ", val=" + val + "]");
    if (idx == null)
        return;
    if (!busyLock.enterBusy())
        throw new IllegalStateException("Failed to remove from index (grid is stopping).");
    try {
        CacheObjectContext coctx = cacheObjectContext(cacheName);
        QueryTypeDescriptorImpl desc = typeByValue(cacheName, coctx, key, val, false);
        if (desc == null)
            return;
        idx.remove(cacheName, desc, key, partId, val, ver);
    } finally {
        busyLock.leaveBusy();
    }
}
Also used : CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext)

Example 14 with CacheObjectContext

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

the class GridQueryProcessor method store.

/**
     * Writes key-value pair to index.
     *
     * @param cacheName Cache name.
     * @param key Key.
     * @param val Value.
     * @param ver Cache entry version.
     * @param expirationTime Expiration time or 0 if never expires.
     * @throws IgniteCheckedException In case of error.
     */
@SuppressWarnings({ "unchecked", "ConstantConditions" })
public void store(final String cacheName, final KeyCacheObject key, int partId, @Nullable CacheObject prevVal, @Nullable GridCacheVersion prevVer, final CacheObject val, GridCacheVersion ver, long expirationTime, long link) throws IgniteCheckedException {
    assert key != null;
    assert val != null;
    if (log.isDebugEnabled())
        log.debug("Store [cache=" + cacheName + ", key=" + key + ", val=" + val + "]");
    if (idx == null)
        return;
    if (!busyLock.enterBusy())
        throw new NodeStoppingException("Operation has been cancelled (node is stopping).");
    try {
        CacheObjectContext coctx = cacheObjectContext(cacheName);
        QueryTypeDescriptorImpl desc = typeByValue(cacheName, coctx, key, val, true);
        if (prevVal != null) {
            QueryTypeDescriptorImpl prevValDesc = typeByValue(cacheName, coctx, key, prevVal, false);
            if (prevValDesc != null && prevValDesc != desc)
                idx.remove(cacheName, prevValDesc, key, partId, prevVal, prevVer);
        }
        if (desc == null)
            return;
        idx.store(cacheName, desc, key, partId, val, ver, expirationTime, link);
    } finally {
        busyLock.leaveBusy();
    }
}
Also used : NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext)

Example 15 with CacheObjectContext

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

CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)15 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)3 GridKernalContext (org.apache.ignite.internal.GridKernalContext)2 IgniteKernal (org.apache.ignite.internal.IgniteKernal)2 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)2 GridCacheDefaultAffinityKeyMapper (org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper)2 IgniteCacheObjectProcessor (org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 CreatedExpiryPolicy (javax.cache.expiry.CreatedExpiryPolicy)1 Duration (javax.cache.expiry.Duration)1 Ignite (org.apache.ignite.Ignite)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteLogger (org.apache.ignite.IgniteLogger)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1