Search in sources :

Example 46 with CacheObject

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

the class DataPageIO method writeFragment.

/**
 * Try to write fragment data.
 *
 * @param rowOff Offset in row data bytes.
 * @param payloadSize Data length that should be written in this fragment.
 * @param type Type of the part of entry.
 * @return Actually written data.
 * @throws IgniteCheckedException If fail.
 */
private int writeFragment(final CacheDataRow row, final ByteBuffer buf, final int rowOff, final int payloadSize, final EntryPart type, final int keySize, final int valSize) throws IgniteCheckedException {
    if (payloadSize == 0)
        return 0;
    final int prevLen;
    final int curLen;
    int cacheIdSize = row.cacheId() == 0 ? 0 : 4;
    switch(type) {
        case CACHE_ID:
            prevLen = 0;
            curLen = cacheIdSize;
            break;
        case KEY:
            prevLen = cacheIdSize;
            curLen = cacheIdSize + keySize;
            break;
        case EXPIRE_TIME:
            prevLen = cacheIdSize + keySize;
            curLen = cacheIdSize + keySize + 8;
            break;
        case VALUE:
            prevLen = cacheIdSize + keySize + 8;
            curLen = cacheIdSize + keySize + valSize + 8;
            break;
        case VERSION:
            prevLen = cacheIdSize + keySize + valSize + 8;
            curLen = cacheIdSize + keySize + valSize + CacheVersionIO.size(row.version(), false) + 8;
            break;
        default:
            throw new IllegalArgumentException("Unknown entry part type: " + type);
    }
    if (curLen <= rowOff)
        return 0;
    final int len = Math.min(curLen - rowOff, payloadSize);
    if (type == EntryPart.EXPIRE_TIME)
        writeExpireTimeFragment(buf, row.expireTime(), rowOff, len, prevLen);
    else if (type == EntryPart.CACHE_ID)
        writeCacheIdFragment(buf, row.cacheId(), rowOff, len, prevLen);
    else if (type != EntryPart.VERSION) {
        // Write key or value.
        final CacheObject co = type == EntryPart.KEY ? row.key() : row.value();
        co.putValue(buf, rowOff - prevLen, len);
    } else
        writeVersionFragment(buf, row.version(), rowOff, len, prevLen);
    return len;
}
Also used : CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 47 with CacheObject

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

the class DataPageIO method getRowSize.

/**
 * @param row Row.
 * @param withCacheId If {@code true} adds cache ID size.
 * @return Entry size on page.
 * @throws IgniteCheckedException If failed.
 */
public static int getRowSize(CacheDataRow row, boolean withCacheId) throws IgniteCheckedException {
    KeyCacheObject key = row.key();
    CacheObject val = row.value();
    int keyLen = key.valueBytesLength(null);
    int valLen = val.valueBytesLength(null);
    return keyLen + valLen + CacheVersionIO.size(row.version(), false) + 8 + (withCacheId ? 4 : 0);
}
Also used : CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 48 with CacheObject

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

the class GridNearCacheEntry method removeLock.

/**
 * Unlocks local lock.
 *
 * @return Removed candidate, or <tt>null</tt> if thread still holds the lock.
 */
@Nullable
@Override
public GridCacheMvccCandidate removeLock() {
    CacheLockCandidates prev = null;
    CacheLockCandidates owner = null;
    CacheObject val;
    UUID locId = cctx.nodeId();
    GridCacheMvccCandidate cand = null;
    lockEntry();
    try {
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc != null) {
            prev = mvcc.allOwners();
            boolean emptyBefore = mvcc.isEmpty();
            cand = mvcc.localCandidate(locId, Thread.currentThread().getId());
            assert cand == null || cand.nearLocal();
            if (cand != null && cand.owner()) {
                // If a reentry, then release reentry. Otherwise, remove lock.
                GridCacheMvccCandidate reentry = cand.unenter();
                if (reentry != null) {
                    assert reentry.reentry();
                    return reentry;
                }
                mvcc.remove(cand.version());
                owner = mvcc.allOwners();
            } else
                return null;
            boolean emptyAfter = mvcc.isEmpty();
            checkCallbacks(emptyBefore, emptyAfter);
            if (emptyAfter)
                mvccExtras(null);
        }
        val = this.val;
    } finally {
        unlockEntry();
    }
    assert cand != null;
    assert owner != prev;
    if (log.isDebugEnabled())
        log.debug("Released local candidate from entry [owner=" + owner + ", prev=" + prev + ", entry=" + this + ']');
    cctx.mvcc().removeExplicitLock(cand);
    checkThreadChain(cand);
    // This call must be outside of synchronization.
    checkOwnerChanged(prev, owner, val);
    return cand;
}
Also used : GridCacheMvcc(org.apache.ignite.internal.processors.cache.GridCacheMvcc) CacheLockCandidates(org.apache.ignite.internal.processors.cache.CacheLockCandidates) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) UUID(java.util.UUID) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate) Nullable(org.jetbrains.annotations.Nullable)

Example 49 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(ctx, 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 (ctx.statisticsEnabled() && !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;
                        }
                    }
                    // 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) {
            if (!storeEnabled && ctx.statisticsEnabled() && !skipVals)
                metrics0().onRead(false);
        }
    }
    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, needVer).get();
}
Also used : CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.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)

Example 50 with CacheObject

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

the class GridCacheQueryManager method store.

/**
     * Writes key-value pair to index.
     *
     * @param key Key.
     * @param partId Partition.
     * @param prevVal Previous value.
     * @param prevVer Previous version.
     * @param val Value.
     * @param ver Cache entry version.
     * @param expirationTime Expiration time or 0 if never expires.
     * @param link Link.
     * @throws IgniteCheckedException In case of error.
     */
public void store(KeyCacheObject key, int partId, @Nullable CacheObject prevVal, @Nullable GridCacheVersion prevVer, CacheObject val, GridCacheVersion ver, long expirationTime, long link) throws IgniteCheckedException {
    assert key != null;
    assert val != null;
    assert enabled();
    if (key instanceof GridCacheInternal)
        // No-op.
        return;
    if (!enterBusy())
        throw new NodeStoppingException("Operation has been cancelled (node is stopping).");
    try {
        if (isIndexingSpiEnabled()) {
            CacheObjectContext coctx = cctx.cacheObjectContext();
            Object key0 = unwrapIfNeeded(key, coctx);
            Object val0 = unwrapIfNeeded(val, coctx);
            cctx.kernalContext().indexing().store(cacheName, key0, val0, expirationTime);
        }
        if (qryProcEnabled)
            qryProc.store(cacheName, key, partId, prevVal, prevVer, val, ver, expirationTime, link);
    } finally {
        invalidateResultCache();
        leaveBusy();
    }
}
Also used : NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) GridCacheInternal(org.apache.ignite.internal.processors.cache.GridCacheInternal) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext)

Aggregations

CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)96 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)86 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)46 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)44 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)38 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)26 CacheLockCandidates (org.apache.ignite.internal.processors.cache.CacheLockCandidates)17 GridCacheMvcc (org.apache.ignite.internal.processors.cache.GridCacheMvcc)17 ArrayList (java.util.ArrayList)15 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)15 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)15 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)13 Nullable (org.jetbrains.annotations.Nullable)13 UUID (java.util.UUID)11 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)11 GridCacheMvccCandidate (org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)11 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)11 IgniteException (org.apache.ignite.IgniteException)10 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)10 LinkedHashMap (java.util.LinkedHashMap)9