Search in sources :

Example 21 with CacheDataRow

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

the class GridCacheMapEntry method innerUpdate.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public GridCacheUpdateAtomicResult innerUpdate(final GridCacheVersion newVer, final UUID evtNodeId, final UUID affNodeId, final GridCacheOperation op, @Nullable final Object writeObj, @Nullable final Object[] invokeArgs, final boolean writeThrough, final boolean readThrough, final boolean retval, final boolean keepBinary, @Nullable final IgniteCacheExpiryPolicy expiryPlc, final boolean evt, final boolean metrics, final boolean primary, final boolean verCheck, final AffinityTopologyVersion topVer, @Nullable final CacheEntryPredicate[] filter, final GridDrType drType, final long explicitTtl, final long explicitExpireTime, @Nullable final GridCacheVersion conflictVer, final boolean conflictResolve, final boolean intercept, @Nullable final UUID subjId, final String taskName, @Nullable final CacheObject prevVal, @Nullable final Long updateCntr, @Nullable final GridDhtAtomicAbstractUpdateFuture fut) throws IgniteCheckedException, GridCacheEntryRemovedException, GridClosureException {
    assert cctx.atomic() && !detached();
    AtomicCacheUpdateClosure c;
    if (!primary && !isNear())
        ensureFreeSpace();
    synchronized (this) {
        checkObsolete();
        boolean internal = isInternal() || !context().userCache();
        Map<UUID, CacheContinuousQueryListener> lsnrs = cctx.continuousQueries().updateListeners(internal, false);
        boolean needVal = lsnrs != null || intercept || retval || op == GridCacheOperation.TRANSFORM || !F.isEmptyOrNulls(filter);
        // Possibly read value from store.
        boolean readFromStore = readThrough && needVal && (cctx.readThrough() && (op == GridCacheOperation.TRANSFORM || cctx.loadPreviousValue()));
        c = new AtomicCacheUpdateClosure(this, newVer, op, writeObj, invokeArgs, readFromStore, writeThrough, keepBinary, expiryPlc, primary, verCheck, filter, explicitTtl, explicitExpireTime, conflictVer, conflictResolve, intercept, updateCntr);
        key.valueBytes(cctx.cacheObjectContext());
        if (isNear()) {
            CacheDataRow dataRow = val != null ? new CacheDataRowAdapter(key, val, ver, expireTimeExtras()) : null;
            c.call(dataRow);
        } else
            cctx.offheap().invoke(key, localPartition(), c);
        GridCacheUpdateAtomicResult updateRes = c.updateRes;
        assert updateRes != null : c;
        CacheObject oldVal = c.oldRow != null ? c.oldRow.value() : null;
        CacheObject updateVal = null;
        GridCacheVersion updateVer = c.newVer;
        // Apply metrics.
        if (metrics && updateRes.outcome().updateReadMetrics() && cctx.cache().configuration().isStatisticsEnabled() && needVal) {
            // PutIfAbsent methods must not update hit/miss statistics.
            if (op != GridCacheOperation.UPDATE || F.isEmpty(filter) || !cctx.putIfAbsentFilter(filter))
                cctx.cache().metrics0().onRead(oldVal != null);
        }
        switch(updateRes.outcome()) {
            case VERSION_CHECK_FAILED:
                {
                    if (!cctx.isNear()) {
                        CacheObject evtVal;
                        if (op == GridCacheOperation.TRANSFORM) {
                            EntryProcessor<Object, Object, ?> entryProcessor = (EntryProcessor<Object, Object, ?>) writeObj;
                            CacheInvokeEntry<Object, Object> entry = new CacheInvokeEntry<>(key, prevVal, version(), keepBinary, this);
                            try {
                                entryProcessor.process(entry, invokeArgs);
                                evtVal = entry.modified() ? cctx.toCacheObject(cctx.unwrapTemporary(entry.getValue())) : prevVal;
                            } catch (Exception ignore) {
                                evtVal = prevVal;
                            }
                        } else
                            evtVal = (CacheObject) writeObj;
                        long updateCntr0 = nextPartCounter();
                        if (updateCntr != null)
                            updateCntr0 = updateCntr;
                        onUpdateFinished(updateCntr0);
                        cctx.continuousQueries().onEntryUpdated(key, evtVal, prevVal, isInternal() || !context().userCache(), partition(), primary, false, updateCntr0, null, topVer);
                    }
                    return updateRes;
                }
            case CONFLICT_USE_OLD:
            case FILTER_FAILED:
            case INVOKE_NO_OP:
            case INTERCEPTOR_CANCEL:
                return updateRes;
        }
        assert updateRes.outcome() == UpdateOutcome.SUCCESS || updateRes.outcome() == UpdateOutcome.REMOVE_NO_VAL;
        CacheObject evtOld = null;
        if (evt && op == TRANSFORM && cctx.events().isRecordable(EVT_CACHE_OBJECT_READ)) {
            assert writeObj instanceof EntryProcessor : writeObj;
            evtOld = cctx.unwrapTemporary(oldVal);
            Object transformClo = EntryProcessorResourceInjectorProxy.unwrap(writeObj);
            cctx.events().addEvent(partition(), key, evtNodeId, null, newVer, EVT_CACHE_OBJECT_READ, evtOld, evtOld != null, evtOld, evtOld != null, subjId, transformClo.getClass().getName(), taskName, keepBinary);
        }
        if (c.op == GridCacheOperation.UPDATE) {
            updateVal = val;
            assert updateVal != null : c;
            drReplicate(drType, updateVal, updateVer, topVer);
            recordNodeId(affNodeId, topVer);
            if (evt && cctx.events().isRecordable(EVT_CACHE_OBJECT_PUT)) {
                if (evtOld == null)
                    evtOld = cctx.unwrapTemporary(oldVal);
                cctx.events().addEvent(partition(), key, evtNodeId, null, newVer, EVT_CACHE_OBJECT_PUT, updateVal, true, evtOld, evtOld != null, subjId, null, taskName, keepBinary);
            }
        } else {
            assert c.op == GridCacheOperation.DELETE : c.op;
            clearReaders();
            drReplicate(drType, null, newVer, topVer);
            recordNodeId(affNodeId, topVer);
            if (evt && cctx.events().isRecordable(EVT_CACHE_OBJECT_REMOVED)) {
                if (evtOld == null)
                    evtOld = cctx.unwrapTemporary(oldVal);
                cctx.events().addEvent(partition(), key, evtNodeId, null, newVer, EVT_CACHE_OBJECT_REMOVED, null, false, evtOld, evtOld != null, subjId, null, taskName, keepBinary);
            }
        }
        if (updateRes.success())
            updateMetrics(c.op, metrics);
        // Continuous query filter should be perform under lock.
        if (lsnrs != null) {
            CacheObject evtVal = cctx.unwrapTemporary(updateVal);
            CacheObject evtOldVal = cctx.unwrapTemporary(oldVal);
            cctx.continuousQueries().onEntryUpdated(lsnrs, key, evtVal, evtOldVal, internal, partition(), primary, false, c.updateRes.updateCounter(), fut, topVer);
        }
        cctx.dataStructures().onEntryUpdated(key, c.op == GridCacheOperation.DELETE, keepBinary);
        if (intercept) {
            if (c.op == GridCacheOperation.UPDATE) {
                cctx.config().getInterceptor().onAfterPut(new CacheLazyEntry(cctx, key, null, updateVal, null, keepBinary, c.updateRes.updateCounter()));
            } else {
                assert c.op == GridCacheOperation.DELETE : c.op;
                cctx.config().getInterceptor().onAfterRemove(new CacheLazyEntry(cctx, key, null, oldVal, null, keepBinary, c.updateRes.updateCounter()));
            }
        }
    }
    onUpdateFinished(c.updateRes.updateCounter());
    return c.updateRes;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) StorageException(org.apache.ignite.internal.pagemem.wal.StorageException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) CacheContinuousQueryListener(org.apache.ignite.internal.processors.cache.query.continuous.CacheContinuousQueryListener) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) EntryProcessor(javax.cache.processor.EntryProcessor) CacheDataRowAdapter(org.apache.ignite.internal.processors.cache.database.CacheDataRowAdapter) UUID(java.util.UUID)

Example 22 with CacheDataRow

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

the class GridCacheMapEntry method unswap.

/**
     * Unswaps an entry.
     *
     * @param needVal If {@code false} then do not to deserialize value during unswap.
     * @param checkExpire If {@code true} checks for expiration, as result entry can be obsoleted or marked deleted.
     * @return Value.
     * @throws IgniteCheckedException If failed.
     * @throws GridCacheEntryRemovedException If entry was removed.
     */
@Nullable
protected CacheDataRow unswap(boolean needVal, boolean checkExpire) throws IgniteCheckedException, GridCacheEntryRemovedException {
    boolean obsolete = false;
    boolean deferred = false;
    GridCacheVersion ver0 = null;
    synchronized (this) {
        checkObsolete();
        if (isStartVersion() && ((flags & IS_UNSWAPPED_MASK) == 0)) {
            CacheDataRow read = cctx.offheap().read(this);
            flags |= IS_UNSWAPPED_MASK;
            if (read != null) {
                CacheObject val = read.value();
                update(val, read.expireTime(), 0, read.version(), false);
                long delta = checkExpire ? (read.expireTime() == 0 ? 0 : read.expireTime() - U.currentTimeMillis()) : 0;
                if (delta >= 0)
                    return read;
                else {
                    if (onExpired(this.val, null)) {
                        if (cctx.deferredDelete()) {
                            deferred = true;
                            ver0 = ver;
                        } else
                            obsolete = true;
                    }
                }
            }
        }
    }
    if (obsolete) {
        onMarkedObsolete();
        cctx.cache().removeEntry(this);
    }
    if (deferred) {
        assert ver0 != null;
        cctx.onDeferredDelete(this, ver0);
    }
    return null;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with CacheDataRow

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

the class IgniteCacheLockPartitionOnAffinityRunTest method getOrganizationCountFromPartitionMap.

/**
     * @param ignite Ignite.
     * @param orgId Organization id.
     * @return Count of found Person object with specified orgId
     * @throws Exception If failed.
     */
private static int getOrganizationCountFromPartitionMap(final IgniteEx ignite, int orgId) throws Exception {
    int part = ignite.affinity(Organization.class.getSimpleName()).partition(orgId);
    GridCacheAdapter<?, ?> cacheAdapterOrg = ignite.context().cache().internalCache(Organization.class.getSimpleName());
    GridDhtLocalPartition pOrgs = cacheAdapterOrg.context().topology().localPartition(part, AffinityTopologyVersion.NONE, false);
    int cnt = 0;
    GridCursor<? extends CacheDataRow> c = pOrgs.dataStore().cursor();
    CacheObjectContext ctx = cacheAdapterOrg.context().cacheObjectContext();
    while (c.next()) {
        CacheDataRow e = c.get();
        Integer k = e.key().value(ctx, false);
        Organization org = e.value().value(ctx, false);
        if (org != null && org.getId() == orgId)
            ++cnt;
    }
    return cnt;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)

Example 24 with CacheDataRow

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

the class IgniteCacheLockPartitionOnAffinityRunTest method getPersonsCountFromPartitionMap.

/**
     * @param ignite Ignite.
     * @param orgId Organization id.
     * @return Count of found Person object with specified orgId
     * @throws Exception If failed.
     */
private static int getPersonsCountFromPartitionMap(final IgniteEx ignite, int orgId) throws Exception {
    int part = ignite.affinity(Organization.class.getSimpleName()).partition(orgId);
    GridCacheAdapter<?, ?> cacheAdapterPers = ignite.context().cache().internalCache(Person.class.getSimpleName());
    GridDhtLocalPartition pPers = cacheAdapterPers.context().topology().localPartition(part, AffinityTopologyVersion.NONE, false);
    int cnt = 0;
    GridCursor<? extends CacheDataRow> c = pPers.dataStore().cursor();
    CacheObjectContext ctx = cacheAdapterPers.context().cacheObjectContext();
    while (c.next()) {
        CacheDataRow e = c.get();
        Person.Key k = e.key().value(ctx, false);
        Person p = e.value().value(ctx, false);
        if (p != null && p.getOrgId() == orgId && k.orgId == orgId)
            ++cnt;
    }
    return cnt;
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)

Aggregations

CacheDataRow (org.apache.ignite.internal.processors.cache.database.CacheDataRow)24 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)13 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)9 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)7 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)6 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)6 UUID (java.util.UUID)5 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)5 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)5 GridDhtLocalPartition (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition)5 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)4 GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException)4 GridCloseableIteratorAdapter (org.apache.ignite.internal.util.GridCloseableIteratorAdapter)4 IgniteException (org.apache.ignite.IgniteException)3 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)3 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)3 NoSuchElementException (java.util.NoSuchElementException)2 EntryProcessor (javax.cache.processor.EntryProcessor)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 StorageException (org.apache.ignite.internal.pagemem.wal.StorageException)2