Search in sources :

Example 51 with KeyCacheObject

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

the class GridDhtCacheAdapter method processForceKeysRequest0.

/**
 * @param node Node originated request.
 * @param msg Force keys message.
 */
private void processForceKeysRequest0(ClusterNode node, GridDhtForceKeysRequest msg) {
    try {
        ClusterNode loc = ctx.localNode();
        GridDhtForceKeysResponse res = new GridDhtForceKeysResponse(ctx.cacheId(), msg.futureId(), msg.miniId(), ctx.deploymentEnabled());
        GridDhtPartitionTopology top = ctx.topology();
        for (KeyCacheObject k : msg.keys()) {
            int p = ctx.affinity().partition(k);
            GridDhtLocalPartition locPart = top.localPartition(p, AffinityTopologyVersion.NONE, false);
            // If this node is no longer an owner.
            if (locPart == null && !top.owners(p).contains(loc)) {
                res.addMissed(k);
                continue;
            }
            GridCacheEntryEx entry;
            while (true) {
                ctx.shared().database().checkpointReadLock();
                try {
                    entry = ctx.dht().entryEx(k);
                    entry.unswap();
                    if (ctx.mvccEnabled()) {
                        List<GridCacheEntryInfo> infos = entry.allVersionsInfo();
                        if (infos == null) {
                            assert entry.obsolete() : entry;
                            continue;
                        }
                        for (int i = 0; i < infos.size(); i++) res.addInfo(infos.get(i));
                    } else {
                        GridCacheEntryInfo info = entry.info();
                        if (info == null) {
                            assert entry.obsolete() : entry;
                            continue;
                        }
                        if (!info.isNew())
                            res.addInfo(info);
                    }
                    entry.touch();
                    break;
                } catch (GridCacheEntryRemovedException ignore) {
                    if (log.isDebugEnabled())
                        log.debug("Got removed entry: " + k);
                } catch (GridDhtInvalidPartitionException ignore) {
                    if (log.isDebugEnabled())
                        log.debug("Local node is no longer an owner: " + p);
                    res.addMissed(k);
                    break;
                } finally {
                    ctx.shared().database().checkpointReadUnlock();
                }
            }
        }
        if (log.isDebugEnabled())
            log.debug("Sending force key response [node=" + node.id() + ", res=" + res + ']');
        ctx.io().send(node, res, ctx.ioPolicy());
    } catch (ClusterTopologyCheckedException ignore) {
        if (log.isDebugEnabled())
            log.debug("Received force key request form failed node (will ignore) [nodeId=" + node.id() + ", req=" + msg + ']');
    } catch (IgniteCheckedException e) {
        U.error(log, "Failed to reply to force key request [nodeId=" + node.id() + ", req=" + msg + ']', e);
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridDhtForceKeysResponse(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysResponse) GridCacheEntryInfo(org.apache.ignite.internal.processors.cache.GridCacheEntryInfo) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridDhtPartitionTopology(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionTopology) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 52 with KeyCacheObject

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

the class GridDhtCacheAdapter method loadEntry.

/**
 * @param key Key.
 * @param val Value.
 * @param ver Cache version.
 * @param p Optional predicate.
 * @param topVer Topology version.
 * @param replicate Replication flag.
 * @param plc Expiry policy.
 */
private void loadEntry(KeyCacheObject key, Object val, GridCacheVersion ver, @Nullable IgniteBiPredicate<K, V> p, AffinityTopologyVersion topVer, boolean replicate, @Nullable ExpiryPolicy plc) {
    if (p != null && !p.apply(key.<K>value(ctx.cacheObjectContext(), false), (V) val))
        return;
    try {
        GridDhtLocalPartition part = ctx.group().topology().localPartition(ctx.affinity().partition(key), AffinityTopologyVersion.NONE, true);
        // Reserve to make sure that partition does not get unloaded.
        if (part.reserve()) {
            GridCacheEntryEx entry = null;
            ctx.shared().database().checkpointReadLock();
            try {
                long ttl = CU.ttlForLoad(plc);
                if (ttl == CU.TTL_ZERO)
                    return;
                CacheObject cacheVal = ctx.toCacheObject(val);
                entry = entryEx(key);
                entry.initialValue(cacheVal, ver, ttl, CU.EXPIRE_TIME_CALCULATE, false, topVer, replicate ? DR_LOAD : DR_NONE, true, false);
            } catch (IgniteCheckedException e) {
                throw new IgniteException("Failed to put cache value: " + entry, e);
            } catch (GridCacheEntryRemovedException ignore) {
                if (log.isDebugEnabled())
                    log.debug("Got removed entry during loadCache (will ignore): " + entry);
            } finally {
                if (entry != null)
                    entry.touch();
                part.release();
                ctx.shared().database().checkpointReadUnlock();
            }
        } else if (log.isDebugEnabled())
            log.debug("Will node load entry into cache (partition is invalid): " + part);
    } catch (GridDhtInvalidPartitionException e) {
        if (log.isDebugEnabled())
            log.debug(S.toString("Ignoring entry for partition that does not belong", "key", key, true, "val", val, true, "err", e, false));
    }
}
Also used : GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) GridDhtLocalPartition(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 53 with KeyCacheObject

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

the class CdcCacheVersionTest method removeConflictData.

/**
 */
private void removeConflictData(IgniteEx cli, IgniteCache<Integer, User> cache, int from, int to, TransactionConcurrency concurrency, TransactionIsolation isolation) {
    try {
        IgniteInternalCache<Integer, User> intCache = cli.cachex(cache.getName());
        Map<KeyCacheObject, GridCacheVersion> drMap = new HashMap<>();
        for (int i = from; i < to; i++) {
            drMap.put(new KeyCacheObjectImpl(i, null, intCache.affinity().partition(i)), new GridCacheVersion(1, i, 1, OTHER_CLUSTER_ID));
        }
        if (concurrency != null) {
            try (Transaction tx = cli.transactions().txStart(concurrency, isolation)) {
                intCache.removeAllConflict(drMap);
                tx.commit();
            }
        } else
            intCache.removeAllConflict(drMap);
    } catch (IgniteCheckedException e) {
        throw new IgniteException(e);
    }
}
Also used : GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Transaction(org.apache.ignite.transactions.Transaction) HashMap(java.util.HashMap) IgniteException(org.apache.ignite.IgniteException) KeyCacheObjectImpl(org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 54 with KeyCacheObject

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

the class RecordDataV1Serializer method readPlainDataEntry.

/**
 * @param in Input to read from.
 * @return Read entry.
 */
DataEntry readPlainDataEntry(ByteBufferBackedDataInput in, RecordType type) throws IOException, IgniteCheckedException {
    int cacheId = in.readInt();
    int keySize = in.readInt();
    byte keyType = in.readByte();
    byte[] keyBytes = new byte[keySize];
    in.readFully(keyBytes);
    int valSize = in.readInt();
    byte valType = 0;
    byte[] valBytes = null;
    if (valSize >= 0) {
        valType = in.readByte();
        valBytes = new byte[valSize];
        in.readFully(valBytes);
    }
    byte ord = in.readByte();
    GridCacheOperation op = GridCacheOperation.fromOrdinal(ord & 0xFF);
    GridCacheVersion nearXidVer = readVersion(in, true);
    GridCacheVersion writeVer = readVersion(in, false);
    int partId = in.readInt();
    long partCntr = in.readLong();
    long expireTime = in.readLong();
    byte flags = type == DATA_RECORD_V2 ? in.readByte() : (byte) 0;
    GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
    if (cacheCtx != null) {
        CacheObjectContext coCtx = cacheCtx.cacheObjectContext();
        KeyCacheObject key = co.toKeyCacheObject(coCtx, keyType, keyBytes);
        if (key.partition() == -1)
            key.partition(partId);
        CacheObject val = valBytes != null ? co.toCacheObject(coCtx, valType, valBytes) : null;
        return new DataEntry(cacheId, key, val, op, nearXidVer, writeVer, expireTime, partId, partCntr, flags);
    } else
        return new LazyDataEntry(cctx, cacheId, keyType, keyBytes, valType, valBytes, op, nearXidVer, writeVer, expireTime, partId, partCntr, flags);
}
Also used : DataEntry(org.apache.ignite.internal.pagemem.wal.record.DataEntry) MvccDataEntry(org.apache.ignite.internal.pagemem.wal.record.MvccDataEntry) LazyDataEntry(org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) GridCacheContext(org.apache.ignite.internal.processors.cache.GridCacheContext) LazyDataEntry(org.apache.ignite.internal.pagemem.wal.record.LazyDataEntry) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheOperation(org.apache.ignite.internal.processors.cache.GridCacheOperation) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 55 with KeyCacheObject

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

the class GridLocalLockFuture method addEntries.

/**
 * @param keys Keys.
 * @return {@code False} in case of error.
 * @throws IgniteCheckedException If failed.
 */
public boolean addEntries(Collection<KeyCacheObject> keys) throws IgniteCheckedException {
    for (KeyCacheObject key : keys) {
        while (true) {
            GridLocalCacheEntry entry = null;
            try {
                entry = cache.entryExx(key);
                entry.unswap(false);
                if (!cctx.isAll(entry, filter)) {
                    onFailed();
                    return false;
                }
                // Removed exception may be thrown here.
                GridCacheMvccCandidate cand = addEntry(entry);
                if (cand == null && isDone())
                    return false;
                break;
            } catch (GridCacheEntryRemovedException ignored) {
                if (log.isDebugEnabled())
                    log.debug("Got removed entry in lockAsync(..) method (will retry): " + entry);
            }
        }
    }
    if (timeout > 0) {
        timeoutObj = new LockTimeoutObject();
        cctx.time().addTimeoutObject(timeoutObj);
    }
    return true;
}
Also used : GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridCacheMvccCandidate(org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate)

Aggregations

KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)171 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)99 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)92 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)73 GridCacheVersion (org.apache.ignite.internal.processors.cache.version.GridCacheVersion)58 ArrayList (java.util.ArrayList)50 Map (java.util.Map)39 GridCacheEntryEx (org.apache.ignite.internal.processors.cache.GridCacheEntryEx)37 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)34 ClusterNode (org.apache.ignite.cluster.ClusterNode)33 HashMap (java.util.HashMap)32 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)31 EntryGetResult (org.apache.ignite.internal.processors.cache.EntryGetResult)29 GridCacheContext (org.apache.ignite.internal.processors.cache.GridCacheContext)27 IgniteBiTuple (org.apache.ignite.lang.IgniteBiTuple)27 IgniteException (org.apache.ignite.IgniteException)25 LinkedHashMap (java.util.LinkedHashMap)24 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)24 GridDhtInvalidPartitionException (org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException)21 GridCacheOperation (org.apache.ignite.internal.processors.cache.GridCacheOperation)20