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);
}
}
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));
}
}
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);
}
}
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);
}
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;
}
Aggregations