use of org.apache.ignite.internal.processors.cache.GridCacheAffinityManager in project ignite by apache.
the class CacheContinuousQueryHandler method getOrCreatePartitionRecovery.
/**
* @param ctx Context.
* @param partId Partition id.
* @param topVer Topology version for current operation.
* @return Partition recovery.
*/
@NotNull
private CacheContinuousQueryPartitionRecovery getOrCreatePartitionRecovery(GridKernalContext ctx, int partId, AffinityTopologyVersion topVer) {
assert topVer != null && topVer.topologyVersion() > 0 : topVer;
CacheContinuousQueryPartitionRecovery rec = rcvs.get(partId);
if (rec == null) {
T2<Long, Long> partCntrs = null;
Map<UUID, Map<Integer, T2<Long, Long>>> initUpdCntrsPerNode = this.initUpdCntrsPerNode;
if (initUpdCntrsPerNode != null) {
GridCacheContext<K, V> cctx = cacheContext(ctx);
GridCacheAffinityManager aff = cctx.affinity();
for (ClusterNode node : aff.nodesByPartition(partId, topVer)) {
Map<Integer, T2<Long, Long>> map = initUpdCntrsPerNode.get(node.id());
if (map != null) {
partCntrs = map.get(partId);
break;
}
}
} else if (initUpdCntrs != null)
partCntrs = initUpdCntrs.get(partId);
rec = new CacheContinuousQueryPartitionRecovery(ctx.log(CU.CONTINUOUS_QRY_LOG_CATEGORY), topVer, partCntrs != null ? partCntrs.get2() : null);
CacheContinuousQueryPartitionRecovery oldRec = rcvs.putIfAbsent(partId, rec);
if (oldRec != null)
rec = oldRec;
}
return rec;
}
use of org.apache.ignite.internal.processors.cache.GridCacheAffinityManager in project ignite by apache.
the class CacheDataStructuresManager method removeSetData.
/**
* @param setId Set ID.
* @param topVer Topology version.
* @throws IgniteCheckedException If failed.
*/
private void removeSetData(IgniteUuid setId, AffinityTopologyVersion topVer) throws IgniteCheckedException {
boolean loc = cctx.isLocal();
GridCacheAffinityManager aff = cctx.affinity();
if (!loc) {
aff.affinityReadyFuture(topVer).get();
cctx.preloader().syncFuture().get();
}
IgniteInternalCache<?, ?> cache = cctx.cache();
final int BATCH_SIZE = 100;
Collection<SetItemKey> keys = new ArrayList<>(BATCH_SIZE);
for (Cache.Entry entry : cache.localEntries(new CachePeekMode[] { CachePeekMode.PRIMARY })) {
Object obj = entry.getKey();
if (!(obj instanceof SetItemKey && setId.equals(((SetItemKey) obj).setId())))
continue;
keys.add((SetItemKey) obj);
if (keys.size() == BATCH_SIZE) {
retryRemoveAll(cache, keys);
keys.clear();
}
}
if (!keys.isEmpty())
retryRemoveAll(cache, keys);
}
use of org.apache.ignite.internal.processors.cache.GridCacheAffinityManager in project ignite by apache.
the class IgniteCacheClientNodeChangingTopologyTest method testPessimisticTx2.
/**
* Tests specific scenario when mapping for first locked keys does not change, but changes for second one.
*
* @throws Exception If failed.
*/
@Test
public void testPessimisticTx2() throws Exception {
ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
ccfg.setCacheMode(PARTITIONED);
ccfg.setBackups(1);
ccfg.setAtomicityMode(TRANSACTIONAL);
ccfg.setWriteSynchronizationMode(FULL_SYNC);
ccfg.setRebalanceMode(SYNC);
IgniteEx ignite0 = startGrid(0);
IgniteEx ignite1 = startGrid(1);
IgniteEx ignite2 = startGrid(2);
awaitPartitionMapExchange();
final Ignite ignite3 = startClientGrid(3);
assertTrue(ignite3.configuration().isClientMode());
AffinityTopologyVersion topVer1 = new AffinityTopologyVersion(4, 0);
assertEquals(topVer1, ignite0.context().cache().internalCache(DEFAULT_CACHE_NAME).context().topology().readyTopologyVersion());
TestCommunicationSpi spi = (TestCommunicationSpi) ignite3.configuration().getCommunicationSpi();
IgniteBiTuple<Integer, Integer> keys = findKeys(ignite0, ignite0.localNode(), ignite1.localNode(), ignite2.localNode());
final Integer key1 = keys.get1();
final Integer key2 = keys.get2();
spi.blockMessages(GridNearLockRequest.class, ignite0.localNode().id());
spi.blockMessages(GridNearLockRequest.class, ignite1.localNode().id());
spi.blockMessages(GridNearLockRequest.class, ignite2.localNode().id());
final IgniteCache<Integer, Integer> cache = ignite3.cache(DEFAULT_CACHE_NAME);
IgniteInternalFuture<?> putFut = GridTestUtils.runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
Thread.currentThread().setName("put-thread");
try (Transaction tx = ignite3.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
cache.put(key1, 1);
cache.put(key2, 2);
tx.commit();
}
return null;
}
});
IgniteEx ignite4 = startGrid(4);
int minorVer = ignite4.configuration().isLateAffinityAssignment() ? 1 : 0;
AffinityTopologyVersion topVer2 = new AffinityTopologyVersion(5, minorVer);
ignite0.context().cache().context().exchange().affinityReadyFuture(topVer2).get();
assertEquals(topVer2, ignite0.context().cache().internalCache(DEFAULT_CACHE_NAME).context().topology().readyTopologyVersion());
GridCacheAffinityManager aff = ignite0.context().cache().internalCache(DEFAULT_CACHE_NAME).context().affinity();
List<ClusterNode> nodes1 = aff.nodesByKey(key1, topVer1);
List<ClusterNode> nodes2 = aff.nodesByKey(key1, topVer2);
assertEquals(nodes1, nodes2);
nodes1 = aff.nodesByKey(key2, topVer1);
nodes2 = aff.nodesByKey(key2, topVer2);
assertFalse(nodes1.get(0).equals(nodes2.get(0)));
assertFalse(putFut.isDone());
log.info("Stop block.");
spi.stopBlock();
putFut.get();
checkData(F.asMap(key1, 1, key2, 2), null, cache, 5);
}
use of org.apache.ignite.internal.processors.cache.GridCacheAffinityManager in project ignite by apache.
the class IgniteH2Indexing method backupFilter.
/** {@inheritDoc} */
@Override
public IndexingQueryFilter backupFilter(@Nullable final AffinityTopologyVersion topVer, @Nullable final int[] parts) {
final AffinityTopologyVersion topVer0 = topVer != null ? topVer : AffinityTopologyVersion.NONE;
return new IndexingQueryFilter() {
@Nullable
@Override
public <K, V> IgniteBiPredicate<K, V> forCache(String cacheName) {
final GridCacheAdapter<Object, Object> cache = ctx.cache().internalCache(cacheName);
if (cache.context().isReplicated())
return null;
final GridCacheAffinityManager aff = cache.context().affinity();
if (parts != null) {
if (parts.length < 64) {
// Fast scan for small arrays.
return new IgniteBiPredicate<K, V>() {
@Override
public boolean apply(K k, V v) {
int p = aff.partition(k);
for (int p0 : parts) {
if (p0 == p)
return true;
if (// Array is sorted.
p0 > p)
return false;
}
return false;
}
};
}
return new IgniteBiPredicate<K, V>() {
@Override
public boolean apply(K k, V v) {
int p = aff.partition(k);
return Arrays.binarySearch(parts, p) >= 0;
}
};
}
final ClusterNode locNode = ctx.discovery().localNode();
return new IgniteBiPredicate<K, V>() {
@Override
public boolean apply(K k, V v) {
return aff.primaryByKey(locNode, k, topVer0);
}
};
}
@Override
public boolean isValueRequired() {
return false;
}
@Override
public String toString() {
return "IndexingQueryFilter [ver=" + topVer + ']';
}
};
}
use of org.apache.ignite.internal.processors.cache.GridCacheAffinityManager in project ignite by apache.
the class GridCacheAbstractQueueFailoverDataConsistencySelfTest method primaryQueueNode.
/**
* @param queue Queue.
* @return Primary node for queue's header.
* @throws Exception If failed.
*/
private int primaryQueueNode(IgniteQueue queue) throws Exception {
GridCacheContext cctx = GridTestUtils.getFieldValue(queue, "cctx");
GridCacheAffinityManager aff = cctx.affinity();
CachePeekMode[] modes = new CachePeekMode[] { CachePeekMode.ALL };
for (int i = 0; i < gridCount(); i++) {
for (Cache.Entry e : grid(i).context().cache().internalCache(cctx.name()).localEntries(modes)) {
Object key = e.getKey();
if (aff.primaryByKey(grid(i).localNode(), key, AffinityTopologyVersion.NONE) && key instanceof GridCacheQueueHeaderKey)
return i;
}
}
fail("Failed to find primary node for queue header.");
return -1;
}
Aggregations