use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap in project ignite by apache.
the class GridCachePartitionExchangeManager method createPartitionsSingleMessage.
/**
* @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}.
* @return Message.
*/
public GridDhtPartitionsSingleMessage createPartitionsSingleMessage(@Nullable GridDhtPartitionExchangeId exchangeId, boolean clientOnlyExchange, boolean sndCounters, boolean newCntrMap, ExchangeActions exchActions) {
GridDhtPartitionsSingleMessage m = new GridDhtPartitionsSingleMessage(exchangeId, clientOnlyExchange, cctx.versions().last(), true);
Map<Object, T2<Integer, GridPartitionStateMap>> dupData = new HashMap<>();
for (CacheGroupContext grp : cctx.cache().cacheGroups()) {
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));
}
}
}
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));
}
}
return m;
}
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 updCntr = part.updateCounter();
long initCntr = part.initialUpdateCounter();
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 validatePartitionsUpdateCounters.
/**
* Validate partitions update counters 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, updateCounter)).
* If map is empty validation is successful.
*/
public Map<Integer, Map<UUID, Long>> validatePartitionsUpdateCounters(GridDhtPartitionTopology top, Map<UUID, GridDhtPartitionsSingleMessage> messages, Set<UUID> ignoringNodes) {
Map<Integer, Map<UUID, Long>> invalidPartitions = new HashMap<>();
Map<Integer, AbstractMap.Entry<UUID, Long>> updateCountersAndNodesByPartitions = new HashMap<>();
// Populate counters statistics from local node partitions.
for (GridDhtLocalPartition part : top.currentLocalPartitions()) {
if (part.state() != GridDhtPartitionState.OWNING)
continue;
if (part.updateCounter() == 0 && part.fullSize() == 0)
continue;
updateCountersAndNodesByPartitions.put(part.id(), new AbstractMap.SimpleEntry<>(cctx.localNodeId(), part.updateCounter()));
}
int partitions = top.partitions();
// Then process and validate counters 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 currentCounter = countersMap.updateCounterAt(i);
process(invalidPartitions, updateCountersAndNodesByPartitions, p, nodeId, currentCounter);
}
}
return invalidPartitions;
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap in project ignite by apache.
the class CacheExchangeMessageDuplicatedStateTest method checkSingleMessage.
/**
* @param msg Message.
*/
private void checkSingleMessage(GridDhtPartitionsSingleMessage msg) {
Map<Integer, Integer> dupPartsData = getFieldValue(msg, "dupPartsData");
assertNotNull(dupPartsData);
checkSingleMessage(AFF1_CACHE1, AFF1_CACHE2, dupPartsData, msg);
checkSingleMessage(AFF4_FILTER_CACHE1, AFF4_FILTER_CACHE2, dupPartsData, msg);
assertFalse(dupPartsData.containsKey(CU.cacheId(AFF3_CACHE1)));
Map<Integer, CachePartitionPartialCountersMap> partCntrs = getFieldValue(msg, "partCntrs");
if (partCntrs != null) {
for (CachePartitionPartialCountersMap cntrs : partCntrs.values()) assertEquals(0, cntrs.size());
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.CachePartitionPartialCountersMap in project ignite by apache.
the class CachePartitionPartialCountersMapSelfTest method testAddAndRemove.
/**
*/
@Test
public void testAddAndRemove() throws Exception {
CachePartitionPartialCountersMap map = new CachePartitionPartialCountersMap(10);
for (int p = 0; p < 10; p++) map.add(p, 2 * p, 3 * p);
for (int p = 0; p < 10; p++) {
assertEquals(p, map.partitionAt(p));
assertEquals(2 * p, map.initialUpdateCounterAt(p));
assertEquals(3 * p, map.updateCounterAt(p));
}
map.remove(3);
map.remove(11);
map.remove(7);
assertEquals(8, map.size());
int idx = 0;
for (int p = 0; p < 10; p++) {
if (p == 3 || p == 10 || p == 7)
continue;
assertEquals(p, map.partitionAt(idx));
assertEquals(2 * p, map.initialUpdateCounterAt(idx));
assertEquals(3 * p, map.updateCounterAt(idx));
idx++;
}
}
Aggregations