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)));
}
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);
}
}
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();
}
}
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();
}
}
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));
}
}
Aggregations