use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class CacheMvccTransactionsTest method getAllByReadMode.
/**
* Reads value from cache for the given key using given read mode.
*
* // TODO IGNITE-6938 remove inTx flag
* // TODO IGNITE-6739 add SQL-get support "select _key, _val from cache where _key in ... keySet"
* @param inTx Flag whether current read is inside transaction.
* This is because reads can't see writes made in current transaction.
* @param cache Cache.
* @param keys Key.
* @param readMode Read mode.
* @return Value.
*/
private Map getAllByReadMode(boolean inTx, IgniteCache cache, Set keys, ReadMode readMode) {
// TODO Remove in IGNITE-6938
if (inTx)
readMode = GET;
switch(readMode) {
case GET:
return cache.getAll(keys);
case SCAN:
Map res = (Map) cache.query(new ScanQuery(new IgniteBiPredicate() {
@Override
public boolean apply(Object k, Object v) {
return keys.contains(k);
}
})).getAll().stream().collect(Collectors.toMap(v -> ((IgniteBiTuple) v).getKey(), v -> ((IgniteBiTuple) v).getValue()));
assertTrue(res.size() <= keys.size());
return res;
default:
throw new IgniteException("Unsupported read mode: " + readMode);
}
}
use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class CacheMvccTransactionsTest method getByReadMode.
/**
* Reads value from cache for the given key using given read mode.
*
* // TODO IGNITE-6938 remove inTx flag
* // TODO IGNITE-6739 add SQL-get support "select _key, _val from cache where _key = key"
* @param inTx Flag whether current read is inside transaction.
* This is because reads can't see writes made in current transaction.
* @param cache Cache.
* @param key Key.
* @param readMode Read mode.
* @return Value.
*/
private Object getByReadMode(boolean inTx, IgniteCache cache, final Object key, ReadMode readMode) {
// TODO Remove in IGNITE-6938
if (inTx)
readMode = GET;
switch(readMode) {
case GET:
return cache.get(key);
case SCAN:
List res = cache.query(new ScanQuery(new IgniteBiPredicate() {
@Override
public boolean apply(Object k, Object v) {
return k.equals(key);
}
})).getAll();
assertTrue(res.size() <= 1);
return res.isEmpty() ? null : ((IgniteBiTuple) res.get(0)).getValue();
default:
throw new IgniteException("Unsupported read mode: " + readMode);
}
}
use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class IgnitePdsConsistencyOnDelayedPartitionOwning method checkConsistencyNodeLeft.
/**
*/
@Test
public void checkConsistencyNodeLeft() throws Exception {
IgniteEx crd = (IgniteEx) startGridsMultiThreaded(4);
crd.cluster().active(true);
for (int i = 0; i < PARTS; i++) crd.cache(DEFAULT_CACHE_NAME).put(i, i);
forceCheckpoint();
stopGrid(1);
for (int i = 0; i < PARTS; i++) crd.cache(DEFAULT_CACHE_NAME).put(i, i + 1);
// Block supply messages from all owners.
TestRecordingCommunicationSpi spi0 = TestRecordingCommunicationSpi.spi(grid(0));
TestRecordingCommunicationSpi spi2 = TestRecordingCommunicationSpi.spi(grid(2));
TestRecordingCommunicationSpi spi3 = TestRecordingCommunicationSpi.spi(grid(3));
IgniteBiPredicate<ClusterNode, Message> pred = new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode clusterNode, Message msg) {
return msg instanceof GridDhtPartitionSupplyMessage;
}
};
spi0.blockMessages(pred);
spi2.blockMessages(pred);
spi3.blockMessages(pred);
GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
startGrid(1);
return null;
}
});
spi0.waitForBlocked();
spi2.waitForBlocked();
spi3.waitForBlocked();
spi0.stopBlock();
spi2.stopBlock();
CountDownLatch topInitLatch = new CountDownLatch(1);
CountDownLatch enableDurabilityCPStartLatch = new CountDownLatch(1);
CountDownLatch delayedOnwningLatch = new CountDownLatch(1);
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager) grid(1).context().cache().context().database();
dbMgr.addCheckpointListener(new CheckpointListener() {
@Override
public void onMarkCheckpointBegin(Context ctx) throws IgniteCheckedException {
// No-op.
}
@Override
public void onCheckpointBegin(Context ctx) throws IgniteCheckedException {
// No-op.
}
@Override
public void beforeCheckpointBegin(Context ctx) throws IgniteCheckedException {
String reason = ctx.progress().reason();
String reason0 = WalStateManager.reason(cacheId(DEFAULT_CACHE_NAME), new AffinityTopologyVersion(6, 0));
if (reason != null && reason.equals(reason0)) {
enableDurabilityCPStartLatch.countDown();
try {
assertTrue(U.await(delayedOnwningLatch, 10_000, TimeUnit.MILLISECONDS));
} catch (IgniteInterruptedCheckedException e) {
fail(X.getFullStackTrace(e));
}
}
}
});
TestRecordingCommunicationSpi.spi(grid(1)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode clusterNode, Message msg) {
if (msg instanceof GridDhtPartitionDemandMessage) {
GridDhtPartitionDemandMessage msg0 = (GridDhtPartitionDemandMessage) msg;
return msg0.topologyVersion().equals(new AffinityTopologyVersion(7, 0));
}
return false;
}
});
grid(1).context().cache().context().exchange().registerExchangeAwareComponent(new PartitionsExchangeAware() {
@Override
public void onDoneBeforeTopologyUnlock(GridDhtPartitionsExchangeFuture fut) {
if (fut.initialVersion().equals(new AffinityTopologyVersion(7, 0))) {
topInitLatch.countDown();
try {
assertTrue(U.await(enableDurabilityCPStartLatch, 20_000, TimeUnit.MILLISECONDS));
} catch (IgniteInterruptedCheckedException e) {
fail(X.getFullStackTrace(e));
}
System.out.println();
}
}
});
// Trigger rebalancing remap because owner has left.
IgniteInternalFuture stopFut = GridTestUtils.runAsync(new Runnable() {
@Override
public void run() {
// TODO start cache.
stopGrid(2);
}
});
// Wait for topology (7,0) init on grid1 before finishing rebalancing on (6,0).
assertTrue(U.await(topInitLatch, 20_000, TimeUnit.MILLISECONDS));
// Release last supply message, causing triggering a cp for enabling durability.
spi3.stopBlock();
// Wait for new rebalancing assignments ready on grid1.
TestRecordingCommunicationSpi.spi(grid(1)).waitForBlocked();
// Triggers spurious ideal switching before rebalancing has finished for (7,0).
delayedOnwningLatch.countDown();
stopFut.get();
TestRecordingCommunicationSpi.spi(grid(1)).stopBlock();
awaitPartitionMapExchange();
assertPartitionsSame(idleVerify(grid(0), DEFAULT_CACHE_NAME));
CacheGroupContext grpCtx = grid(1).context().cache().cacheGroup(cacheId(DEFAULT_CACHE_NAME));
if (grpCtx != null)
assertTrue(grpCtx.localWalEnabled());
}
use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class ClientFastReplyCoordinatorFailureTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setFailureHandler(new StopNodeOrHaltFailureHandler());
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(IP_FINDER));
TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
// Block messages to old coordinator right before killing it.
if (igniteInstanceName.contains("client")) {
commSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (msg instanceof GridDhtPartitionsSingleMessage && (node.id().getLeastSignificantBits() & OLD_CRD_BITS) == 0) {
info("Going to block message [node=" + node + ", msg=" + msg + ']');
clientSingleMesssageLatch.countDown();
return true;
}
return false;
}
});
if (delayNodeFailedMsg) {
TcpDiscoverySpi spi = new TestDiscoverySpi();
spi.setIpFinder(IP_FINDER);
cfg.setDiscoverySpi(spi);
}
} else if (getTestIgniteInstanceName(3).equals(igniteInstanceName)) {
commSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (msg instanceof GridDhtPartitionsSingleMessage && (node.id().getLeastSignificantBits() & OLD_CRD_BITS) == 0L) {
info("Going to block message [node=" + node + ", msg=" + msg + ']');
newSrvSingleMesssageLatch.countDown();
return true;
}
return false;
}
});
} else if (delayNodeFailedMsg) {
commSpi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (msg instanceof GridDhtPartitionsSingleRequest && node.isClient()) {
GridTestUtils.runAsync(() -> {
try {
Thread.sleep(1_000);
} catch (InterruptedException ignore) {
// No-op.
}
PART_SINGLE_REQ_MSG_LATCH.countDown();
});
}
return false;
}
});
}
cfg.setCommunicationSpi(commSpi);
return cfg;
}
use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class CacheContinuousQueryBufferLimitTest method doTestContinuousQueryPendingBufferLimit.
/**
* @param locBlockPred Block predicate on local node to emulate message delivery issues.
* @param pendingLimit Test limit of pending entries.
* @throws Exception If fails.
*/
private void doTestContinuousQueryPendingBufferLimit(IgniteBiPredicate<ClusterNode, Message> locBlockPred, int pendingLimit) throws Exception {
AtomicInteger keys = new AtomicInteger();
IgniteEx locIgnite = startGrid(0);
IgniteEx rmtIgnite = startGrid(1);
IgniteCache<Integer, Integer> cache = locIgnite.cache(DEFAULT_CACHE_NAME);
CacheConfiguration<Integer, Integer> ccfg = cache.getConfiguration(CacheConfiguration.class);
for (int i = 0; i < TOTAL_KEYS; i++) cache.put(i, i);
assertEquals(PARTS, ccfg.getAffinity().partitions());
GridAtomicLong lastAcked = new GridAtomicLong();
ContinuousQuery<Integer, Integer> cq = new ContinuousQuery<>();
cq.setRemoteFilterFactory(FactoryBuilder.factoryOf(RMT_FILTER));
cq.setLocalListener((events) -> events.forEach(e -> lastAcked.setIfGreater(((CacheQueryEntryEvent<?, ?>) e).getPartitionUpdateCounter())));
cq.setLocal(false);
IgniteInternalFuture<?> updFut = null;
try (QueryCursor<?> qry = locIgnite.cache(DEFAULT_CACHE_NAME).query(cq)) {
awaitPartitionMapExchange();
// Partition Id, Update Counter, Continuous Entry.
ConcurrentMap<Long, CacheContinuousQueryEntry> pending = getContinuousQueryPendingBuffer(rmtIgnite, CU.cacheId(DEFAULT_CACHE_NAME), 0);
spi(locIgnite).blockMessages(locBlockPred);
updFut = GridTestUtils.runMultiThreadedAsync(() -> {
while (keys.get() <= OVERFLOW_KEYS_COUNT) cache.put(keys.incrementAndGet(), 0);
}, 3, "cq-put-");
assertNotNull("Partition remote buffers must be inited", pending);
log.warning("Waiting for pending buffer being overflowed within " + OVERFLOW_KEYS_COUNT + " number of keys.");
boolean await = waitForCondition(() -> pending.size() > pendingLimit, () -> keys.get() <= OVERFLOW_KEYS_COUNT);
assertFalse("Pending buffer exceeded the limit despite entries have been acked " + "[lastAcked=" + lastAcked + ", pending=" + S.compact(pending.keySet(), i -> i + 1) + ']', await);
} finally {
spi(locIgnite).stopBlock();
if (updFut != null)
updFut.cancel();
}
}
Aggregations