use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap in project ignite by apache.
the class GridDhtPartitionTopologyImpl method localUpdateCounters.
/**
* {@inheritDoc}
*/
@Override
public CachePartitionPartialCountersMap localUpdateCounters(boolean skipZeros) {
lock.readLock().lock();
try {
int locPartCnt = 0;
for (int i = 0; i < locParts.length(); i++) {
GridDhtLocalPartition part = locParts.get(i);
if (part != null)
locPartCnt++;
}
CachePartitionPartialCountersMap res = new CachePartitionPartialCountersMap(locPartCnt);
for (int i = 0; i < locParts.length(); i++) {
GridDhtLocalPartition part = locParts.get(i);
if (part == null)
continue;
long initCntr = part.initialUpdateCounter();
long updCntr = part.updateCounter();
if (skipZeros && initCntr == 0L && updCntr == 0L)
continue;
res.add(part.id(), initCntr, updCntr);
}
res.trim();
return res;
} finally {
lock.readLock().unlock();
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap in project ignite by apache.
the class GridDhtPartitionsStateValidator method validatePartitionsSizes.
/**
* Validate partitions cache sizes for given {@code top}.
*
* @param top Topology to validate.
* @param messages Single messages received from all nodes.
* @param ignoringNodes Nodes for what we ignore validation.
* @return Invalid partitions map with following structure:
* (partId, (nodeId, cacheSize)).
* If map is empty validation is successful.
*/
public Map<Integer, Map<UUID, Long>> validatePartitionsSizes(GridDhtPartitionTopology top, Map<UUID, GridDhtPartitionsSingleMessage> messages, Set<UUID> ignoringNodes) {
Map<Integer, Map<UUID, Long>> invalidPartitions = new HashMap<>();
Map<Integer, AbstractMap.Entry<UUID, Long>> sizesAndNodesByPartitions = new HashMap<>();
// Populate sizes statistics from local node partitions.
for (GridDhtLocalPartition part : top.currentLocalPartitions()) {
if (part.state() != GridDhtPartitionState.OWNING)
continue;
if (part.updateCounter() == 0 && part.fullSize() == 0)
continue;
sizesAndNodesByPartitions.put(part.id(), new AbstractMap.SimpleEntry<>(cctx.localNodeId(), part.fullSize()));
}
int partitions = top.partitions();
// Then process and validate sizes from other nodes.
for (Map.Entry<UUID, GridDhtPartitionsSingleMessage> e : messages.entrySet()) {
UUID nodeId = e.getKey();
if (ignoringNodes.contains(nodeId))
continue;
final GridDhtPartitionsSingleMessage message = e.getValue();
CachePartitionPartialCountersMap countersMap = message.partitionUpdateCounters(top.groupId(), partitions);
Map<Integer, Long> sizesMap = message.partitionSizes(top.groupId());
Set<Integer> ignorePartitions = shouldIgnore(top, nodeId, countersMap, sizesMap);
for (int i = 0; i < countersMap.size(); i++) {
int p = countersMap.partitionAt(i);
if (ignorePartitions != null && ignorePartitions.contains(p))
continue;
long currentSize = sizesMap.getOrDefault(p, 0L);
process(invalidPartitions, sizesAndNodesByPartitions, p, nodeId, currentSize);
}
}
return invalidPartitions;
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap in project ignite by apache.
the class GridCachePartitionExchangeManager method createPartitionsSingleMessage.
/**
* Creates partitions single message for selected cache groups.
*
* @param exchangeId Exchange ID.
* @param clientOnlyExchange Client exchange flag.
* @param sndCounters {@code True} if need send partition update counters.
* @param newCntrMap {@code True} if possible to use {@link CachePartitionPartialCountersMap}.
* @param grps Selected cache groups.
* @return Message.
*/
public GridDhtPartitionsSingleMessage createPartitionsSingleMessage(@Nullable GridDhtPartitionExchangeId exchangeId, boolean clientOnlyExchange, boolean sndCounters, boolean newCntrMap, ExchangeActions exchActions, Collection<CacheGroupContext> grps) {
GridDhtPartitionsSingleMessage m = new GridDhtPartitionsSingleMessage(exchangeId, clientOnlyExchange, cctx.versions().last(), true);
Map<Object, T2<Integer, GridPartitionStateMap>> dupData = new HashMap<>();
for (CacheGroupContext grp : grps) {
if (!grp.isLocal() && (exchActions == null || !exchActions.cacheGroupStopping(grp.groupId()))) {
GridDhtPartitionMap locMap = grp.topology().localPartitionMap();
addPartitionMap(m, dupData, true, grp.groupId(), locMap, grp.affinity().similarAffinityKey());
if (sndCounters) {
CachePartitionPartialCountersMap cntrsMap = grp.topology().localUpdateCounters(true);
m.addPartitionUpdateCounters(grp.groupId(), newCntrMap ? cntrsMap : CachePartitionPartialCountersMap.toCountersMap(cntrsMap));
}
m.addPartitionSizes(grp.groupId(), grp.topology().partitionSizes());
}
}
for (GridClientPartitionTopology top : clientTops.values()) {
if (m.partitions() != null && m.partitions().containsKey(top.groupId()))
continue;
GridDhtPartitionMap locMap = top.localPartitionMap();
addPartitionMap(m, dupData, true, top.groupId(), locMap, top.similarAffinityKey());
if (sndCounters) {
CachePartitionPartialCountersMap cntrsMap = top.localUpdateCounters(true);
m.addPartitionUpdateCounters(top.groupId(), newCntrMap ? cntrsMap : CachePartitionPartialCountersMap.toCountersMap(cntrsMap));
}
m.addPartitionSizes(top.groupId(), top.partitionSizes());
}
return m;
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap in project ignite by apache.
the class GridContinuousProcessor method processStartRequestV2.
/**
* @param topVer Current topology version.
* @param snd Sender.
* @param msg Start request.
*/
private void processStartRequestV2(final AffinityTopologyVersion topVer, final ClusterNode snd, final StartRoutineDiscoveryMessageV2 msg) {
StartRequestDataV2 reqData = msg.startRequestData();
ContinuousRoutineInfo routineInfo = new ContinuousRoutineInfo(snd.id(), msg.routineId(), reqData.handlerBytes(), reqData.nodeFilterBytes(), reqData.bufferSize(), reqData.interval(), reqData.autoUnsubscribe());
routinesInfo.addRoutineInfo(routineInfo);
final DiscoCache discoCache = ctx.discovery().discoCache(topVer);
// Should not use marshaller and send messages from discovery thread.
ctx.pools().getSystemExecutorService().execute(new Runnable() {
@Override
public void run() {
if (snd.id().equals(ctx.localNodeId())) {
StartFuture fut = startFuts.get(msg.routineId());
if (fut != null)
fut.initRemoteNodes(discoCache);
return;
}
StartRequestDataV2 reqData = msg.startRequestData();
Exception err = null;
IgnitePredicate<ClusterNode> nodeFilter = null;
byte[] cntrs = null;
if (reqData.nodeFilterBytes() != null) {
try {
if (ctx.config().isPeerClassLoadingEnabled() && reqData.className() != null) {
String clsName = reqData.className();
GridDeploymentInfo depInfo = reqData.deploymentInfo();
GridDeployment dep = ctx.deploy().getGlobalDeployment(depInfo.deployMode(), clsName, clsName, depInfo.userVersion(), snd.id(), depInfo.classLoaderId(), depInfo.participants(), null);
if (dep == null) {
throw new IgniteDeploymentCheckedException("Failed to obtain deployment " + "for class: " + clsName);
}
nodeFilter = U.unmarshal(marsh, reqData.nodeFilterBytes(), U.resolveClassLoader(dep.classLoader(), ctx.config()));
} else {
nodeFilter = U.unmarshal(marsh, reqData.nodeFilterBytes(), U.resolveClassLoader(ctx.config()));
}
if (nodeFilter != null)
ctx.resource().injectGeneric(nodeFilter);
} catch (Exception e) {
err = e;
U.error(log, "Failed to unmarshal continuous routine filter [" + "routineId=" + msg.routineId + ", srcNodeId=" + snd.id() + ']', e);
}
}
boolean register = err == null && (nodeFilter == null || nodeFilter.apply(ctx.discovery().localNode()));
if (register) {
try {
GridContinuousHandler hnd = U.unmarshal(marsh, reqData.handlerBytes(), U.resolveClassLoader(ctx.config()));
if (ctx.config().isPeerClassLoadingEnabled())
hnd.p2pUnmarshal(snd.id(), ctx);
if (msg.keepBinary()) {
assert hnd instanceof CacheContinuousQueryHandler : hnd;
((CacheContinuousQueryHandler) hnd).keepBinary(true);
}
registerHandler(snd.id(), msg.routineId, hnd, reqData.bufferSize(), reqData.interval(), reqData.autoUnsubscribe(), false);
if (hnd.isQuery()) {
GridCacheProcessor proc = ctx.cache();
if (proc != null) {
GridCacheAdapter cache = ctx.cache().internalCache(hnd.cacheName());
if (cache != null && !cache.isLocal() && cache.context().userCache()) {
CachePartitionPartialCountersMap cntrsMap = cache.context().topology().localUpdateCounters(false);
cntrs = U.marshal(marsh, cntrsMap);
}
}
}
} catch (Exception e) {
err = e;
U.error(log, "Failed to register continuous routine handler [" + "routineId=" + msg.routineId + ", srcNodeId=" + snd.id() + ']', e);
}
}
sendMessageStartResult(snd, msg.routineId(), cntrs, err);
}
});
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap in project ignite by apache.
the class CacheContinuousQueryFailoverAbstractSelfTest method checkPartCounter.
/**
* @param nodes Count nodes.
* @param killedNodeIdx Killed node index.
* @param updCntrs Update counters.
*/
private void checkPartCounter(int nodes, int killedNodeIdx, Map<Integer, Long> updCntrs) {
for (int i = 0; i < nodes; i++) {
if (i == killedNodeIdx)
continue;
Affinity<Object> aff = grid(i).affinity(DEFAULT_CACHE_NAME);
CachePartitionPartialCountersMap act = grid(i).cachex(DEFAULT_CACHE_NAME).context().topology().localUpdateCounters(false);
for (Map.Entry<Integer, Long> e : updCntrs.entrySet()) {
if (aff.mapPartitionToPrimaryAndBackups(e.getKey()).contains(grid(i).localNode())) {
int partIdx = act.partitionIndex(e.getKey());
assertEquals(e.getValue(), (Long) act.updateCounterAt(partIdx));
}
}
}
}
Aggregations