Search in sources :

Example 26 with CacheObject

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

the class GridNearTxRemote method addEntry.

/**
     * @param cacheCtx Cache context.
     * @param key Key to add to read set.
     * @param op Operation.
     * @param val Value.
     * @param drVer Data center replication version.
     * @param skipStore Skip store flag.
     * @throws IgniteCheckedException If failed.
     * @return {@code True} if entry has been enlisted.
     */
public boolean addEntry(GridCacheContext cacheCtx, IgniteTxKey key, GridCacheOperation op, CacheObject val, @Nullable GridCacheVersion drVer, boolean skipStore, boolean keepBinary) throws IgniteCheckedException {
    checkInternal(key);
    GridNearCacheEntry cached = cacheCtx.near().peekExx(key.key());
    try {
        if (cached == null) {
            evicted.add(key);
            return false;
        } else {
            cached.unswap();
            CacheObject peek = cached.peek(null);
            if (peek == null && cached.evictInternal(xidVer, null, false)) {
                cached.context().cache().removeIfObsolete(key.key());
                evicted.add(key);
                return false;
            } else {
                IgniteTxEntry txEntry = new IgniteTxEntry(cacheCtx, this, op, val, -1L, -1L, cached, drVer, skipStore, keepBinary);
                txState.addWriteEntry(key, txEntry);
                return true;
            }
        }
    } catch (GridCacheEntryRemovedException ignore) {
        evicted.add(key);
        if (log.isDebugEnabled())
            log.debug("Got removed entry when adding reads to remote transaction (will ignore): " + cached);
        return false;
    }
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject)

Example 27 with CacheObject

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

the class GridLocalCacheEntry method readyLocal.

/**
     * @param cand Candidate.
     */
void readyLocal(GridCacheMvccCandidate cand) {
    CacheObject val;
    CacheLockCandidates prev = null;
    CacheLockCandidates owner = null;
    synchronized (this) {
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc != null) {
            prev = mvcc.localOwners();
            owner = mvcc.readyLocal(cand);
            if (mvcc.isEmpty())
                mvccExtras(null);
        }
        val = this.val;
    }
    checkOwnerChanged(prev, owner, val);
}
Also used : GridCacheMvcc(org.apache.ignite.internal.processors.cache.GridCacheMvcc) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheLockCandidates(org.apache.ignite.internal.processors.cache.CacheLockCandidates)

Example 28 with CacheObject

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

the class GridLocalCacheEntry method recheck.

/**
     * Rechecks if lock should be reassigned.
     */
public void recheck() {
    CacheObject val;
    CacheLockCandidates prev = null;
    CacheLockCandidates owner = null;
    synchronized (this) {
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc != null) {
            prev = mvcc.allOwners();
            owner = mvcc.recheck();
            if (mvcc.isEmpty())
                mvccExtras(null);
        }
        val = this.val;
    }
    checkOwnerChanged(prev, owner, val);
}
Also used : GridCacheMvcc(org.apache.ignite.internal.processors.cache.GridCacheMvcc) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheLockCandidates(org.apache.ignite.internal.processors.cache.CacheLockCandidates)

Example 29 with CacheObject

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

the class GridLocalCacheEntry method releaseLocal.

/**
     * Releases local lock.
     *
     * @param threadId Thread ID.
     */
private void releaseLocal(long threadId) {
    CacheObject val;
    CacheLockCandidates prev = null;
    CacheLockCandidates owner = null;
    synchronized (this) {
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc != null) {
            prev = mvcc.localOwners();
            mvcc.releaseLocal(threadId);
            if (mvcc.isEmpty())
                mvccExtras(null);
            else
                owner = mvcc.allOwners();
        }
        val = this.val;
    }
    if (prev != null) {
        for (int i = 0; i < prev.size(); i++) {
            GridCacheMvccCandidate cand = prev.candidate(i);
            boolean unlocked = owner == null || !owner.hasCandidate(cand.version());
            if (unlocked)
                checkThreadChain(cand);
        }
    }
    checkOwnerChanged(prev, owner, val);
}
Also used : GridCacheMvcc(org.apache.ignite.internal.processors.cache.GridCacheMvcc) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheLockCandidates(org.apache.ignite.internal.processors.cache.CacheLockCandidates) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Example 30 with CacheObject

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

the class GridLocalAtomicCache method getAllInternal.

/**
     * Entry point to all public API get methods.
     *
     * @param keys Keys to remove.
     * @param storeEnabled Store enabled flag.
     * @param taskName Task name.
     * @param deserializeBinary Deserialize binary .
     * @param skipVals Skip value flag.
     * @param needVer Need version.
     * @return Key-value map.
     * @throws IgniteCheckedException If failed.
     */
@SuppressWarnings("ConstantConditions")
private Map<K, V> getAllInternal(@Nullable Collection<? extends K> keys, boolean storeEnabled, String taskName, boolean deserializeBinary, boolean skipVals, boolean needVer) throws IgniteCheckedException {
    ctx.checkSecurity(SecurityPermission.CACHE_READ);
    if (F.isEmpty(keys))
        return Collections.emptyMap();
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    UUID subjId = ctx.subjectIdPerCall(null, opCtx);
    Map<K, V> vals = U.newHashMap(keys.size());
    if (keyCheck)
        validateCacheKeys(keys);
    final IgniteCacheExpiryPolicy expiry = expiryPolicy(opCtx != null ? opCtx.expiry() : null);
    boolean success = true;
    boolean readNoEntry = ctx.readNoEntry(expiry, false);
    final boolean evt = !skipVals;
    for (K key : keys) {
        if (key == null)
            throw new NullPointerException("Null key.");
        KeyCacheObject cacheKey = ctx.toCacheKeyObject(key);
        boolean skipEntry = readNoEntry;
        if (readNoEntry) {
            CacheDataRow row = ctx.offheap().read(cacheKey);
            if (row != null) {
                long expireTime = row.expireTime();
                if (expireTime == 0 || expireTime > U.currentTimeMillis()) {
                    ctx.addResult(vals, cacheKey, row.value(), skipVals, false, deserializeBinary, true, null, row.version(), 0, 0, needVer);
                    if (configuration().isStatisticsEnabled() && !skipVals)
                        metrics0().onRead(true);
                    if (evt) {
                        ctx.events().readEvent(cacheKey, null, row.value(), subjId, taskName, !deserializeBinary);
                    }
                } else
                    skipEntry = false;
            } else
                success = false;
        }
        if (!skipEntry) {
            GridCacheEntryEx entry = null;
            while (true) {
                try {
                    entry = entryEx(cacheKey);
                    if (entry != null) {
                        CacheObject v;
                        if (needVer) {
                            EntryGetResult res = entry.innerGetVersioned(null, null, /*update-metrics*/
                            false, /*event*/
                            evt, subjId, null, taskName, expiry, !deserializeBinary, null);
                            if (res != null) {
                                ctx.addResult(vals, cacheKey, res, skipVals, false, deserializeBinary, true, needVer);
                            } else
                                success = false;
                        } else {
                            v = entry.innerGet(null, null, /*read-through*/
                            false, /*update-metrics*/
                            true, /*event*/
                            evt, subjId, null, taskName, expiry, !deserializeBinary);
                            if (v != null) {
                                ctx.addResult(vals, cacheKey, v, skipVals, false, deserializeBinary, true, null, 0, 0);
                            } else
                                success = false;
                        }
                    } else {
                        if (!storeEnabled && configuration().isStatisticsEnabled() && !skipVals)
                            metrics0().onRead(false);
                        success = false;
                    }
                    // While.
                    break;
                } catch (GridCacheEntryRemovedException ignored) {
                // No-op, retry.
                } finally {
                    if (entry != null)
                        ctx.evicts().touch(entry, ctx.affinity().affinityTopologyVersion());
                }
                if (!success && storeEnabled)
                    break;
            }
        }
    }
    if (success || !storeEnabled)
        return vals;
    return getAllAsync(keys, null, opCtx == null || !opCtx.skipStore(), false, subjId, taskName, deserializeBinary, opCtx != null && opCtx.recovery(), /*force primary*/
    false, expiry, skipVals, /*can remap*/
    true, needVer).get();
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.database.CacheDataRow) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) EntryGetResult(org.apache.ignite.internal.processors.cache.EntryGetResult) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) UUID(java.util.UUID) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

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