use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest in project ignite by apache.
the class GridDhtAtomicCache method start.
/**
* {@inheritDoc}
*/
@SuppressWarnings({ "IfMayBeConditional", "SimplifiableIfStatement" })
@Override
public void start() throws IgniteCheckedException {
super.start();
CacheMetricsImpl m = new CacheMetricsImpl(ctx);
if (ctx.dht().near() != null)
m.delegate(ctx.dht().near().metrics0());
metrics = m;
ctx.io().addCacheHandler(ctx.cacheId(), GridNearGetRequest.class, new CI2<UUID, GridNearGetRequest>() {
@Override
public void apply(UUID nodeId, GridNearGetRequest req) {
processNearGetRequest(nodeId, req);
}
});
ctx.io().addCacheHandler(ctx.cacheId(), GridNearSingleGetRequest.class, new CI2<UUID, GridNearSingleGetRequest>() {
@Override
public void apply(UUID nodeId, GridNearSingleGetRequest req) {
processNearSingleGetRequest(nodeId, req);
}
});
ctx.io().addCacheHandler(ctx.cacheId(), GridNearAtomicAbstractUpdateRequest.class, new CI2<UUID, GridNearAtomicAbstractUpdateRequest>() {
@Override
public void apply(UUID nodeId, GridNearAtomicAbstractUpdateRequest req) {
processNearAtomicUpdateRequest(nodeId, req);
}
@Override
public String toString() {
return "GridNearAtomicAbstractUpdateRequest handler " + "[msgIdx=" + GridNearAtomicAbstractUpdateRequest.CACHE_MSG_IDX + ']';
}
});
ctx.io().addCacheHandler(ctx.cacheId(), GridNearAtomicUpdateResponse.class, new CI2<UUID, GridNearAtomicUpdateResponse>() {
@Override
public void apply(UUID nodeId, GridNearAtomicUpdateResponse res) {
processNearAtomicUpdateResponse(nodeId, res);
}
@Override
public String toString() {
return "GridNearAtomicUpdateResponse handler " + "[msgIdx=" + GridNearAtomicUpdateResponse.CACHE_MSG_IDX + ']';
}
});
ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicAbstractUpdateRequest.class, new CI2<UUID, GridDhtAtomicAbstractUpdateRequest>() {
@Override
public void apply(UUID nodeId, GridDhtAtomicAbstractUpdateRequest req) {
processDhtAtomicUpdateRequest(nodeId, req);
}
@Override
public String toString() {
return "GridDhtAtomicUpdateRequest handler " + "[msgIdx=" + GridDhtAtomicUpdateRequest.CACHE_MSG_IDX + ']';
}
});
ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicUpdateResponse.class, new CI2<UUID, GridDhtAtomicUpdateResponse>() {
@Override
public void apply(UUID nodeId, GridDhtAtomicUpdateResponse res) {
processDhtAtomicUpdateResponse(nodeId, res);
}
@Override
public String toString() {
return "GridDhtAtomicUpdateResponse handler " + "[msgIdx=" + GridDhtAtomicUpdateResponse.CACHE_MSG_IDX + ']';
}
});
ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicDeferredUpdateResponse.class, new CI2<UUID, GridDhtAtomicDeferredUpdateResponse>() {
@Override
public void apply(UUID nodeId, GridDhtAtomicDeferredUpdateResponse res) {
processDhtAtomicDeferredUpdateResponse(nodeId, res);
}
@Override
public String toString() {
return "GridDhtAtomicDeferredUpdateResponse handler " + "[msgIdx=" + GridDhtAtomicDeferredUpdateResponse.CACHE_MSG_IDX + ']';
}
});
ctx.io().addCacheHandler(ctx.cacheId(), GridDhtAtomicNearResponse.class, new CI2<UUID, GridDhtAtomicNearResponse>() {
@Override
public void apply(UUID uuid, GridDhtAtomicNearResponse msg) {
processDhtAtomicNearResponse(uuid, msg);
}
@Override
public String toString() {
return "GridDhtAtomicNearResponse handler " + "[msgIdx=" + GridDhtAtomicNearResponse.CACHE_MSG_IDX + ']';
}
});
ctx.io().addCacheHandler(ctx.cacheId(), GridNearAtomicCheckUpdateRequest.class, new CI2<UUID, GridNearAtomicCheckUpdateRequest>() {
@Override
public void apply(UUID uuid, GridNearAtomicCheckUpdateRequest msg) {
processCheckUpdateRequest(uuid, msg);
}
@Override
public String toString() {
return "GridNearAtomicCheckUpdateRequest handler " + "[msgIdx=" + GridNearAtomicCheckUpdateRequest.CACHE_MSG_IDX + ']';
}
});
ctx.io().addCacheHandler(ctx.cacheId(), GridDhtForceKeysRequest.class, new MessageHandler<GridDhtForceKeysRequest>() {
@Override
public void onMessage(ClusterNode node, GridDhtForceKeysRequest msg) {
processForceKeysRequest(node, msg);
}
});
ctx.io().addCacheHandler(ctx.cacheId(), GridDhtForceKeysResponse.class, new MessageHandler<GridDhtForceKeysResponse>() {
@Override
public void onMessage(ClusterNode node, GridDhtForceKeysResponse msg) {
processForceKeyResponse(node, msg);
}
});
if (near == null) {
ctx.io().addCacheHandler(ctx.cacheId(), GridNearGetResponse.class, new CI2<UUID, GridNearGetResponse>() {
@Override
public void apply(UUID nodeId, GridNearGetResponse res) {
processNearGetResponse(nodeId, res);
}
});
ctx.io().addCacheHandler(ctx.cacheId(), GridNearSingleGetResponse.class, new CI2<UUID, GridNearSingleGetResponse>() {
@Override
public void apply(UUID nodeId, GridNearSingleGetResponse res) {
processNearSingleGetResponse(nodeId, res);
}
});
}
}
use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest in project ignite by apache.
the class KillCommandsCommandShTest method testCancelConsistencyTask.
/**
*/
@Test
public void testCancelConsistencyTask() throws InterruptedException {
String consistencyCacheName = "consistencyCache";
CacheConfiguration<Integer, Integer> cfg = new CacheConfiguration<>();
cfg.setName(consistencyCacheName);
cfg.setBackups(SERVER_NODE_CNT - 1);
cfg.setAffinity(new RendezvousAffinityFunction().setPartitions(1));
IgniteCache<Integer, Integer> cache = client.getOrCreateCache(cfg);
int entries = 10_000;
for (int i = 0; i < entries; i++) cache.put(i, i);
AtomicInteger getCnt = new AtomicInteger();
CountDownLatch thLatch = new CountDownLatch(1);
Thread th = new Thread(() -> {
IgnitePredicate<ComputeJobView> repairJobFilter = job -> job.taskClassName().equals(VisorConsistencyRepairTask.class.getName());
for (IgniteEx node : srvs) {
SystemView<ComputeJobView> jobs = node.context().systemView().view(JOBS_VIEW);
// Found.
assertTrue(F.iterator0(jobs, true, repairJobFilter).hasNext());
}
int res = execute("--consistency", "status");
assertEquals(EXIT_CODE_OK, res);
assertContains(log, testOut.toString(), "Status: 1024/" + entries);
assertNotContains(log, testOut.toString(), VisorConsistencyStatusTask.NOTHING_FOUND);
testOut.reset();
res = execute("--kill", "consistency");
assertEquals(EXIT_CODE_OK, res);
try {
assertTrue(GridTestUtils.waitForCondition(() -> {
for (IgniteEx node : srvs) {
SystemView<ComputeJobView> jobs = node.context().systemView().view(JOBS_VIEW);
if (// Found.
F.iterator0(jobs, true, repairJobFilter).hasNext())
return false;
}
return true;
}, // Missed.
5000L));
} catch (IgniteInterruptedCheckedException e) {
fail();
}
thLatch.countDown();
});
// GridNearGetRequest messages count required to pefrom getAll() with readRepair from all nodes twice.
// First will be finished (which generates status), second will be frozen.
int twiceGetMsgCnt = SERVER_NODE_CNT * (SERVER_NODE_CNT - 1) * 2;
for (IgniteEx server : srvs) {
TestRecordingCommunicationSpi spi = ((TestRecordingCommunicationSpi) server.configuration().getCommunicationSpi());
AtomicInteger locLimit = new AtomicInteger(SERVER_NODE_CNT - 1);
spi.blockMessages((node, message) -> {
if (message instanceof GridNearGetRequest) {
// Each node should perform get twice.
if (getCnt.incrementAndGet() == twiceGetMsgCnt)
th.start();
// Cancellation should stop the process.
assertTrue(getCnt.get() <= twiceGetMsgCnt);
// Blocking to freeze '--consistency repair' operation (except first get).
return locLimit.decrementAndGet() < 0;
}
return false;
});
}
injectTestSystemOut();
assertEquals(EXIT_CODE_UNEXPECTED_ERROR, execute("--consistency", "repair", ConsistencyCommand.STRATEGY, ReadRepairStrategy.LWW.toString(), ConsistencyCommand.PARTITION, "0", ConsistencyCommand.CACHE, consistencyCacheName));
assertContains(log, testOut.toString(), "Operation execution cancelled.");
assertContains(log, testOut.toString(), VisorConsistencyRepairTask.NOTHING_FOUND);
assertNotContains(log, testOut.toString(), VisorConsistencyRepairTask.CONSISTENCY_VIOLATIONS_FOUND);
thLatch.await();
for (IgniteEx server : srvs) {
// Restoring messaging for other tests.
TestRecordingCommunicationSpi spi = ((TestRecordingCommunicationSpi) server.configuration().getCommunicationSpi());
spi.stopBlock();
}
testOut.reset();
int res = execute("--consistency", "status");
assertEquals(EXIT_CODE_OK, res);
assertContains(log, testOut.toString(), VisorConsistencyStatusTask.NOTHING_FOUND);
assertNotContains(log, testOut.toString(), "Status");
}
use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest in project ignite by apache.
the class GridDhtTransactionalCacheAdapter method start.
/** {@inheritDoc} */
@Override
public void start() throws IgniteCheckedException {
super.start();
preldr = new GridDhtPreloader(ctx);
preldr.start();
ctx.io().addHandler(ctx.cacheId(), GridNearGetRequest.class, new CI2<UUID, GridNearGetRequest>() {
@Override
public void apply(UUID nodeId, GridNearGetRequest req) {
processNearGetRequest(nodeId, req);
}
});
ctx.io().addHandler(ctx.cacheId(), GridNearSingleGetRequest.class, new CI2<UUID, GridNearSingleGetRequest>() {
@Override
public void apply(UUID nodeId, GridNearSingleGetRequest req) {
processNearSingleGetRequest(nodeId, req);
}
});
ctx.io().addHandler(ctx.cacheId(), GridNearLockRequest.class, new CI2<UUID, GridNearLockRequest>() {
@Override
public void apply(UUID nodeId, GridNearLockRequest req) {
processNearLockRequest(nodeId, req);
}
});
ctx.io().addHandler(ctx.cacheId(), GridDhtLockRequest.class, new CI2<UUID, GridDhtLockRequest>() {
@Override
public void apply(UUID nodeId, GridDhtLockRequest req) {
processDhtLockRequest(nodeId, req);
}
});
ctx.io().addHandler(ctx.cacheId(), GridDhtLockResponse.class, new CI2<UUID, GridDhtLockResponse>() {
@Override
public void apply(UUID nodeId, GridDhtLockResponse req) {
processDhtLockResponse(nodeId, req);
}
});
ctx.io().addHandler(ctx.cacheId(), GridNearUnlockRequest.class, new CI2<UUID, GridNearUnlockRequest>() {
@Override
public void apply(UUID nodeId, GridNearUnlockRequest req) {
processNearUnlockRequest(nodeId, req);
}
});
ctx.io().addHandler(ctx.cacheId(), GridDhtUnlockRequest.class, new CI2<UUID, GridDhtUnlockRequest>() {
@Override
public void apply(UUID nodeId, GridDhtUnlockRequest req) {
processDhtUnlockRequest(nodeId, req);
}
});
}
use of org.apache.ignite.internal.processors.cache.distributed.near.GridNearGetRequest in project ignite by apache.
the class CacheMvccAbstractBasicCoordinatorFailoverTest method readInProgressCoordinatorFails.
/**
* @param readDelay {@code True} if delays get requests.
* @param readInTx {@code True} to read inside transaction.
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
protected void readInProgressCoordinatorFails(boolean readDelay, final boolean readInTx, final TransactionConcurrency concurrency, final TransactionIsolation isolation, ReadMode readMode, WriteMode writeMode, @Nullable IgniteInClosure<CacheConfiguration> cfgC) throws Exception {
final int COORD_NODES = 5;
final int SRV_NODES = 4;
if (readDelay)
testSpi = true;
startGrids(COORD_NODES);
startGridsMultiThreaded(COORD_NODES, SRV_NODES);
client = true;
Ignite client = startGrid(COORD_NODES + SRV_NODES);
final List<String> cacheNames = new ArrayList<>();
final int KEYS = 100;
final Map<Integer, Integer> vals = new LinkedHashMap<>();
for (int i = 0; i < KEYS; i++) vals.put(i, 0);
String[] exclude = new String[COORD_NODES];
for (int i = 0; i < COORD_NODES; i++) exclude[i] = testNodeName(i);
for (CacheConfiguration ccfg : cacheConfigurations()) {
ccfg.setName("cache-" + cacheNames.size());
if (cfgC != null)
cfgC.apply(ccfg);
// First server nodes are 'dedicated' coordinators.
ccfg.setNodeFilter(new TestCacheNodeExcludingFilter(exclude));
cacheNames.add(ccfg.getName());
IgniteCache cache = client.createCache(ccfg);
boolean updated = false;
while (!updated) {
try (Transaction tx = client.transactions().txStart(concurrency, isolation)) {
tx.timeout(TX_TIMEOUT);
writeAllByMode(cache, vals, writeMode, INTEGER_CODEC);
tx.commit();
updated = true;
} catch (Exception e) {
handleTxException(e);
}
}
}
if (readDelay) {
for (int i = COORD_NODES; i < COORD_NODES + SRV_NODES + 1; i++) {
TestRecordingCommunicationSpi.spi(ignite(i)).closure(new IgniteBiInClosure<ClusterNode, Message>() {
@Override
public void apply(ClusterNode node, Message msg) {
if (msg instanceof GridNearGetRequest)
doSleep(ThreadLocalRandom.current().nextLong(50) + 1);
}
});
}
}
final AtomicBoolean done = new AtomicBoolean();
try {
final AtomicInteger readNodeIdx = new AtomicInteger(0);
IgniteInternalFuture getFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
Ignite node = ignite(COORD_NODES + (readNodeIdx.getAndIncrement() % (SRV_NODES + 1)));
int cnt = 0;
while (!done.get() && !Thread.currentThread().isInterrupted()) {
for (String cacheName : cacheNames) {
IgniteCache cache = node.cache(cacheName);
Map<Integer, Integer> res = null;
if (readInTx) {
try (Transaction tx = node.transactions().txStart(concurrency, isolation)) {
tx.timeout(TX_TIMEOUT);
res = readAllByMode(cache, vals.keySet(), readMode, INTEGER_CODEC);
tx.commit();
} catch (Exception e) {
// TODO Remove catch clause when IGNITE-8841 implemented.
handleTxException(e);
}
} else
res = readAllByMode(cache, vals.keySet(), readMode, INTEGER_CODEC);
if (readInTx) {
// TODO IGNITE-8841
assertTrue("res.size=" + (res == null ? 0 : res.size()) + ", res=" + res, res == null || vals.size() == res.size());
} else {
assertEquals(vals.size(), res.size());
Integer val0 = null;
for (Integer val : res.values()) {
if (val0 == null)
val0 = val;
else
assertEquals(val0, val);
}
}
}
cnt++;
}
log.info("Finished [node=" + node.name() + ", readCnt=" + cnt + ']');
return null;
} catch (Throwable e) {
error("Unexpected error: " + e, e);
throw e;
}
}
}, ((SRV_NODES + 1) + 1) * 2, "get-thread");
IgniteInternalFuture putFut1 = GridTestUtils.runAsync(new Callable() {
@Override
public Void call() throws Exception {
Ignite node = ignite(COORD_NODES);
List<IgniteCache> caches = new ArrayList<>();
for (String cacheName : cacheNames) caches.add(node.cache(cacheName));
Integer val = 1;
while (!done.get()) {
Map<Integer, Integer> vals = new LinkedHashMap<>();
for (int i = 0; i < KEYS; i++) vals.put(i, val);
for (IgniteCache cache : caches) {
try {
try (Transaction tx = node.transactions().txStart(concurrency, isolation)) {
tx.timeout(TX_TIMEOUT);
writeAllByMode(cache, vals, writeMode, INTEGER_CODEC);
tx.commit();
}
} catch (Exception e) {
handleTxException(e);
}
}
val++;
}
return null;
}
}, "putAll-thread");
IgniteInternalFuture putFut2 = GridTestUtils.runAsync(new Callable() {
@Override
public Void call() throws Exception {
Ignite node = ignite(COORD_NODES);
IgniteCache cache = node.cache(cacheNames.get(0));
Integer val = 0;
while (!done.get()) {
try {
try (Transaction tx = node.transactions().txStart(concurrency, isolation)) {
tx.timeout(TX_TIMEOUT);
writeByMode(cache, Integer.MAX_VALUE, val, writeMode, INTEGER_CODEC);
tx.commit();
}
} catch (Exception e) {
handleTxException(e);
}
val++;
}
return null;
}
}, "put-thread");
for (int i = 0; i < COORD_NODES && !getFut.isDone(); i++) {
U.sleep(3000);
stopGrid(i);
awaitPartitionMapExchange();
}
done.set(true);
getFut.get();
putFut1.get();
putFut2.get();
for (Ignite node : G.allGrids()) checkActiveQueriesCleanup(node);
} finally {
done.set(true);
}
}
Aggregations