Search in sources :

Example 1 with CacheObject

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

the class GridCacheAffinityImpl method affinityKey.

/** {@inheritDoc} */
@Override
public Object affinityKey(K key) {
    A.notNull(key, "key");
    if (key instanceof CacheObject && !(key instanceof BinaryObject)) {
        CacheObjectContext ctx = cctx.cacheObjectContext();
        if (ctx == null)
            throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
        key = ((CacheObject) key).value(ctx, false);
    }
    CacheConfiguration ccfg = cctx.config();
    if (ccfg == null)
        throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
    return ccfg.getAffinityMapper().affinityKey(key);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteException(org.apache.ignite.IgniteException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 2 with CacheObject

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

the class GridDistributedCacheEntry method doneRemote.

/**
     *
     * @param lockVer Done version.
     * @param baseVer Base version.
     * @param pendingVers Pending versions that are less than lock version.
     * @param committedVers Completed versions for reordering.
     * @param rolledbackVers Rolled back versions for reordering.
     * @param sysInvalidate Flag indicating if this entry is done from invalidated transaction (in case of tx
     *      salvage). In this case all locks before salvaged lock will marked as used and corresponding
     *      transactions will be invalidated.
     * @throws GridCacheEntryRemovedException If entry has been removed.
     */
public void doneRemote(GridCacheVersion lockVer, GridCacheVersion baseVer, @Nullable Collection<GridCacheVersion> pendingVers, Collection<GridCacheVersion> committedVers, Collection<GridCacheVersion> rolledbackVers, boolean sysInvalidate) throws GridCacheEntryRemovedException {
    CacheLockCandidates prev = null;
    CacheLockCandidates owner = null;
    CacheObject val;
    synchronized (this) {
        checkObsolete();
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc != null) {
            prev = mvcc.allOwners();
            boolean emptyBefore = mvcc.isEmpty();
            // Order completed versions.
            if (!F.isEmpty(committedVers) || !F.isEmpty(rolledbackVers)) {
                mvcc.orderCompleted(lockVer, committedVers, rolledbackVers);
                if (!baseVer.equals(lockVer))
                    mvcc.orderCompleted(baseVer, committedVers, rolledbackVers);
            }
            if (sysInvalidate && baseVer != null)
                mvcc.salvageRemote(baseVer);
            owner = mvcc.doneRemote(lockVer, maskNull(pendingVers), maskNull(committedVers), maskNull(rolledbackVers));
            boolean emptyAfter = mvcc.isEmpty();
            checkCallbacks(emptyBefore, emptyAfter);
            if (emptyAfter)
                mvccExtras(null);
        }
        val = this.val;
    }
    // This call must be made outside of synchronization.
    checkOwnerChanged(prev, owner, val);
}
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)

Example 3 with CacheObject

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

the class GridDistributedCacheEntry method recheck.

/**
     * Rechecks if lock should be reassigned.
     */
public void recheck() {
    CacheLockCandidates prev = null;
    CacheLockCandidates owner = null;
    CacheObject val;
    synchronized (this) {
        GridCacheMvcc mvcc = mvccExtras();
        if (mvcc != null) {
            prev = mvcc.allOwners();
            boolean emptyBefore = mvcc.isEmpty();
            owner = mvcc.recheck();
            boolean emptyAfter = mvcc.isEmpty();
            checkCallbacks(emptyBefore, emptyAfter);
            if (emptyAfter)
                mvccExtras(null);
        }
        val = this.val;
    }
    // This call must be made outside of synchronization.
    checkOwnerChanged(prev, owner, val);
}
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)

Example 4 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)

Example 5 with CacheObject

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

the class GridDhtTransactionalCacheAdapter method createLockReply.

/**
     * @param nearNode Near node.
     * @param entries Entries.
     * @param req Lock request.
     * @param tx Transaction.
     * @param mappedVer Mapped version.
     * @param err Error.
     * @return Response.
     */
private GridNearLockResponse createLockReply(ClusterNode nearNode, List<GridCacheEntryEx> entries, GridNearLockRequest req, @Nullable GridDhtTxLocalAdapter tx, GridCacheVersion mappedVer, Throwable err) {
    assert mappedVer != null;
    assert tx == null || tx.xidVersion().equals(mappedVer);
    try {
        // Send reply back to originating near node.
        GridNearLockResponse res = new GridNearLockResponse(ctx.cacheId(), req.version(), req.futureId(), req.miniId(), tx != null && tx.onePhaseCommit(), entries.size(), err, null, ctx.deploymentEnabled());
        if (err == null) {
            res.pending(localDhtPendingVersions(entries, mappedVer));
            // We have to add completed versions for cases when nearLocal and remote transactions
            // execute concurrently.
            IgnitePair<Collection<GridCacheVersion>> versPair = ctx.tm().versions(req.version());
            res.completedVersions(versPair.get1(), versPair.get2());
            int i = 0;
            for (ListIterator<GridCacheEntryEx> it = entries.listIterator(); it.hasNext(); ) {
                GridCacheEntryEx e = it.next();
                assert e != null;
                while (true) {
                    try {
                        // Don't return anything for invalid partitions.
                        if (tx == null || !tx.isRollbackOnly()) {
                            GridCacheVersion dhtVer = req.dhtVersion(i);
                            GridCacheVersion ver = e.version();
                            boolean ret = req.returnValue(i) || dhtVer == null || !dhtVer.equals(ver);
                            CacheObject val = null;
                            if (ret)
                                val = e.innerGet(null, tx, /*read-through*/
                                false, /*update-metrics*/
                                true, /*event notification*/
                                req.returnValue(i), CU.subjectId(tx, ctx.shared()), null, tx != null ? tx.resolveTaskName() : null, null, req.keepBinary());
                            assert e.lockedBy(mappedVer) || (ctx.mvcc().isRemoved(e.context(), mappedVer) && req.timeout() > 0) : "Entry does not own lock for tx [locNodeId=" + ctx.localNodeId() + ", entry=" + e + ", mappedVer=" + mappedVer + ", ver=" + ver + ", tx=" + tx + ", req=" + req + ", err=" + err + ']';
                            boolean filterPassed = false;
                            if (tx != null && tx.onePhaseCommit()) {
                                IgniteTxEntry writeEntry = tx.entry(ctx.txKey(e.key()));
                                assert writeEntry != null : "Missing tx entry for locked cache entry: " + e;
                                filterPassed = writeEntry.filtersPassed();
                            }
                            if (ret && val == null)
                                val = e.valueBytes(null);
                            // We include values into response since they are required for local
                            // calls and won't be serialized. We are also including DHT version.
                            res.addValueBytes(ret ? val : null, filterPassed, ver, mappedVer);
                        } else {
                            // We include values into response since they are required for local
                            // calls and won't be serialized. We are also including DHT version.
                            res.addValueBytes(null, false, e.version(), mappedVer);
                        }
                        break;
                    } catch (GridCacheEntryRemovedException ignore) {
                        if (log.isDebugEnabled())
                            log.debug("Got removed entry when sending reply to DHT lock request " + "(will retry): " + e);
                        e = entryExx(e.key());
                        it.set(e);
                    }
                }
                i++;
            }
        }
        return res;
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to get value for lock reply message for node [node=" + U.toShortString(nearNode) + ", req=" + req + ']', e);
        return new GridNearLockResponse(ctx.cacheId(), req.version(), req.futureId(), req.miniId(), false, entries.size(), e, null, ctx.deploymentEnabled());
    }
}
Also used : IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Collection(java.util.Collection) GridNearLockResponse(org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockResponse) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) 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