use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition 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.distributed.dht.topology.GridDhtLocalPartition 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.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class CheckpointWorkflow method fillCacheGroupState.
/**
* Fill cache group state in checkpoint record.
*
* @param cpRec Checkpoint record for filling.
* @throws IgniteCheckedException if fail.
*/
private void fillCacheGroupState(CheckpointRecord cpRec) throws IgniteCheckedException {
GridCompoundFuture grpHandleFut = checkpointCollectPagesInfoPool == null ? null : new GridCompoundFuture();
for (CacheGroupContext grp : cacheGroupsContexts.get()) {
if (grp.isLocal() || !grp.walEnabled())
continue;
Runnable r = () -> {
ArrayList<GridDhtLocalPartition> parts = new ArrayList<>(grp.topology().localPartitions().size());
for (GridDhtLocalPartition part : grp.topology().currentLocalPartitions()) parts.add(part);
CacheState state = new CacheState(parts.size());
for (GridDhtLocalPartition part : parts) {
GridDhtPartitionState partState = part.state();
if (partState == LOST)
partState = OWNING;
state.addPartitionState(part.id(), part.dataStore().fullSize(), part.updateCounter(), (byte) partState.ordinal());
}
synchronized (cpRec) {
cpRec.addCacheGroupState(grp.groupId(), state);
}
};
if (checkpointCollectPagesInfoPool == null)
r.run();
else
try {
GridFutureAdapter<?> res = new GridFutureAdapter<>();
checkpointCollectPagesInfoPool.execute(U.wrapIgniteFuture(r, res));
grpHandleFut.add(res);
} catch (RejectedExecutionException e) {
assert false : "Task should never be rejected by async runner";
// to protect from disabled asserts and call to failure handler
throw new IgniteException(e);
}
}
if (grpHandleFut != null) {
grpHandleFut.markInitialized();
grpHandleFut.get();
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class CacheDhtLocalPartitionAfterRemoveSelfTest method testMemoryUsage.
/**
* @throws Exception If failed.
*/
@Test
public void testMemoryUsage() throws Exception {
assertEquals(10_000, GridDhtLocalPartition.MAX_DELETE_QUEUE_SIZE);
IgniteCache<TestKey, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
for (int i = 0; i < 20_000; ++i) cache.put(new TestKey(String.valueOf(i)), i);
for (int i = 0; i < 20_000; ++i) assertEquals((Object) i, cache.getAndRemove(new TestKey(String.valueOf(i))));
assertEquals(0, cache.size());
for (int g = 0; g < GRID_CNT; g++) {
cache = grid(g).cache(DEFAULT_CACHE_NAME);
for (GridDhtLocalPartition p : dht(cache).topology().localPartitions()) {
long size = p.dataStore().fullSize();
assertTrue("Unexpected size: " + size, size <= 32);
}
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition in project ignite by apache.
the class IgniteCacheOffheapManagerImpl method cacheData.
/**
* @param primary Primary data flag.
* @param backup Backup data flag.
* @param topVer Topology version.
* @return Data stores iterator.
*/
private Iterator<CacheDataStore> cacheData(boolean primary, boolean backup, AffinityTopologyVersion topVer) {
assert primary || backup;
if (grp.isLocal())
return singletonIterator(locCacheDataStore);
IgnitePredicate<GridDhtLocalPartition> filter;
if (primary && backup)
filter = F.alwaysTrue();
else {
IntSet parts = ImmutableIntSet.wrap(primary ? grp.affinity().primaryPartitions(ctx.localNodeId(), topVer) : grp.affinity().backupPartitions(ctx.localNodeId(), topVer));
filter = part -> parts.contains(part.id());
}
return cacheDataStores(filter).iterator();
}
Aggregations