Search in sources :

Example 31 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(cacheAdapter.context(), 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 32 with CacheObjectContext

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

the class GridDhtTxQueryEnlistRequest method prepareMarshal.

/**
 * {@inheritDoc}
 */
@Override
public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException {
    super.prepareMarshal(ctx);
    GridCacheContext cctx = ctx.cacheContext(cacheId);
    CacheObjectContext objCtx = cctx.cacheObjectContext();
    if (!addDepInfo && cctx.deploymentEnabled())
        addDepInfo = true;
    if (keys != null) {
        for (int i = 0; i < keys.size(); i++) {
            keys.get(i).prepareMarshal(objCtx);
            if (vals != null) {
                Message val = vals.get(i);
                if (val instanceof CacheObject)
                    ((CacheObject) val).prepareMarshal(objCtx);
                else if (val instanceof CacheEntryInfoCollection) {
                    for (GridCacheEntryInfo entry : ((CacheEntryInfoCollection) val).infos()) {
                        CacheObject entryVal = entry.value();
                        if (entryVal != null)
                            entryVal.prepareMarshal(objCtx);
                    }
                } else if (val instanceof GridInvokeValue)
                    prepareInvokeValue(cctx, (GridInvokeValue) val);
            }
        }
    }
}
Also used : GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) GridCacheIdMessage(org.apache.ignite.internal.processors.cache.GridCacheIdMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) CacheEntryInfoCollection(org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext)

Example 33 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).context().operationContextPerCall();
        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) 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 34 with CacheObjectContext

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

the class IndexQueryProcessor method mergeIndexQueryCriteria.

/**
 * Merges multiple criteria for the same field into single criterion.
 */
private Map<String, RangeIndexQueryCriterion> mergeIndexQueryCriteria(InlineIndexImpl idx, SortedIndexDefinition idxDef, IndexQueryDesc idxQryDesc) throws IgniteCheckedException {
    Map<String, RangeIndexQueryCriterion> mergedCriteria = new HashMap<>();
    Map<String, IndexKeyDefinition> idxFlds = idxDef.indexKeyDefinitions();
    IndexKeyTypeSettings keyTypeSettings = idx.segment(0).rowHandler().indexKeyTypeSettings();
    CacheObjectContext coctx = idx.segment(0).cacheGroupContext().cacheObjectContext();
    IndexRowComparator keyCmp = idxDef.rowComparator();
    for (IndexQueryCriterion c : idxQryDesc.criteria()) {
        RangeIndexQueryCriterion crit = (RangeIndexQueryCriterion) c;
        String fldName = idxFlds.containsKey(crit.field()) ? crit.field() : QueryUtils.normalizeObjectName(crit.field(), false);
        IndexKeyDefinition keyDef = idxFlds.get(fldName);
        if (keyDef == null)
            throw failIndexQuery("Index doesn't match criteria", idxDef, idxQryDesc);
        IndexKey l = key(crit.lower(), crit.lowerNull(), keyDef, keyTypeSettings, coctx);
        IndexKey u = key(crit.upper(), crit.upperNull(), keyDef, keyTypeSettings, coctx);
        if (l != null && u != null && keyCmp.compareKey(l, u) > 0) {
            throw failIndexQuery("Illegal criterion: lower boundary is greater than the upper boundary: " + rangeDesc(crit, fldName, null, null), idxDef, idxQryDesc);
        }
        boolean lowIncl = crit.lowerIncl();
        boolean upIncl = crit.upperIncl();
        boolean lowNull = crit.lowerNull();
        boolean upNull = crit.upperNull();
        if (mergedCriteria.containsKey(fldName)) {
            RangeIndexQueryCriterion prev = mergedCriteria.get(fldName);
            IndexKey prevLower = (IndexKey) prev.lower();
            IndexKey prevUpper = (IndexKey) prev.upper();
            // Validate merged criteria.
            if (!checkBoundaries(l, prevUpper, crit.lowerIncl(), prev.upperIncl(), keyCmp) || !checkBoundaries(prevLower, u, prev.lowerIncl(), crit.upperIncl(), keyCmp)) {
                String prevDesc = rangeDesc(prev, null, prevLower == null ? null : prevLower.key(), prevUpper == null ? null : prevUpper.key());
                throw failIndexQuery("Failed to merge criterion " + rangeDesc(crit, fldName, null, null) + " with previous criteria range " + prevDesc, idxDef, idxQryDesc);
            }
            int lowCmp = 0;
            // Use previous lower boudary, as it's greater than the current.
            if (l == null || (prevLower != null && (lowCmp = keyCmp.compareKey(prevLower, l)) >= 0)) {
                l = prevLower;
                lowIncl = lowCmp != 0 ? prev.lowerIncl() : prev.lowerIncl() ? lowIncl : prev.lowerIncl();
                lowNull = prev.lowerNull();
            }
            int upCmp = 0;
            // Use previous upper boudary, as it's less than the current.
            if (u == null || (prevUpper != null && (upCmp = keyCmp.compareKey(prevUpper, u)) <= 0)) {
                u = prevUpper;
                upIncl = upCmp != 0 ? prev.upperIncl() : prev.upperIncl() ? upIncl : prev.upperIncl();
                upNull = prev.upperNull();
            }
        }
        RangeIndexQueryCriterion idxKeyCrit = new RangeIndexQueryCriterion(fldName, l, u);
        idxKeyCrit.lowerIncl(lowIncl);
        idxKeyCrit.upperIncl(upIncl);
        idxKeyCrit.lowerNull(lowNull);
        idxKeyCrit.upperNull(upNull);
        mergedCriteria.put(fldName, idxKeyCrit);
    }
    return mergedCriteria;
}
Also used : IndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IndexKeyDefinition(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition) RangeIndexQueryCriterion(org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion) IndexQueryCriterion(org.apache.ignite.cache.query.IndexQueryCriterion) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) RangeIndexQueryCriterion(org.apache.ignite.internal.cache.query.RangeIndexQueryCriterion) IndexKeyTypeSettings(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings) IndexRowComparator(org.apache.ignite.internal.cache.query.index.sorted.IndexRowComparator)

Example 35 with CacheObjectContext

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

the class GridNearTxQueryResultsEnlistRequest method prepareMarshal.

/**
 * {@inheritDoc}
 */
@Override
public void prepareMarshal(GridCacheSharedContext ctx) throws IgniteCheckedException {
    super.prepareMarshal(ctx);
    GridCacheContext cctx = ctx.cacheContext(cacheId);
    CacheObjectContext objCtx = cctx.cacheObjectContext();
    if (rows != null && keys == null) {
        keys = new KeyCacheObject[rows.size()];
        int i = 0;
        boolean keysOnly = op.isDeleteOrLock();
        values = keysOnly ? null : new CacheObject[keys.length];
        for (Object row : rows) {
            Object key, val = null;
            if (keysOnly)
                key = row;
            else {
                key = ((IgniteBiTuple) row).getKey();
                val = ((IgniteBiTuple) row).getValue();
            }
            assert key != null && (keysOnly || val != null) : "key=" + key + ", val=" + val;
            KeyCacheObject key0 = cctx.toCacheKeyObject(key);
            assert key0 != null;
            key0.prepareMarshal(objCtx);
            keys[i] = key0;
            if (!keysOnly) {
                CacheObject val0 = cctx.toCacheObject(val);
                assert val0 != null;
                val0.prepareMarshal(objCtx);
                values[i] = val0;
            }
            i++;
        }
    }
}
Also used : GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Aggregations

CacheObjectContext (org.apache.ignite.internal.processors.cache.CacheObjectContext)45 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)21 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)17 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)7 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)6 IgniteEx (org.apache.ignite.internal.IgniteEx)6 ArrayList (java.util.ArrayList)5 DataEntry (org.apache.ignite.internal.pagemem.wal.record.DataEntry)5 Test (org.junit.Test)5 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)4 MvccDataEntry (org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry)4 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)4 CacheDataRow (org.apache.ignite.internal.processors.cache.persistence.CacheDataRow)4 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)4 AffinityKeyMapper (org.apache.ignite.cache.affinity.AffinityKeyMapper)3 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)3 GridCacheDefaultAffinityKeyMapper (org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper)3 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)3 Message (org.apache.ignite.plugin.extensions.communication.Message)3