use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest 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.dht.preloader.GridDhtForceKeysRequest in project ignite by apache.
the class CacheMvccBackupsAbstractTest method doTestRebalanceNodeAdd.
/**
* @throws Exception If failed.
*/
private void doTestRebalanceNodeAdd(boolean delayRebalance) throws Exception {
testSpi = true;
final Ignite node1 = startGrid(0);
final IgniteCache<Object, Object> cache = node1.createCache(cacheConfiguration(cacheMode(), FULL_SYNC, 1, 16).setIndexedTypes(Integer.class, Integer.class));
try (Transaction tx = node1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
SqlFieldsQuery qry = new SqlFieldsQuery("INSERT INTO Integer (_key, _val) values " + "(1,1),(2,2),(3,3),(4,4),(5,5)");
cache.query(qry).getAll();
tx.commit();
}
TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(node1);
// Check for a force key request.
spi.closure(new IgniteBiInClosure<ClusterNode, Message>() {
@Override
public void apply(ClusterNode node, Message msg) {
if (delayRebalance && msg instanceof GridDhtPartitionSupplyMessage)
doSleep(500);
if (msg instanceof GridDhtForceKeysResponse)
fail("Force key request");
}
});
final Ignite node2 = startGrid(1);
TestRecordingCommunicationSpi.spi(node2).closure(new IgniteBiInClosure<ClusterNode, Message>() {
@Override
public void apply(ClusterNode node, Message msg) {
if (msg instanceof GridDhtForceKeysRequest)
fail("Force key request");
}
});
IgniteCache<Object, Object> cache2 = node2.cache(DEFAULT_CACHE_NAME);
try (Transaction tx = node2.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
SqlFieldsQuery qry = new SqlFieldsQuery("DELETE FROM Integer WHERE _key IN " + "(1,2,3,4,5)");
cache2.query(qry).getAll();
tx.commit();
}
awaitPartitionMapExchange();
doSleep(2000);
stopGrid(1);
try (Transaction tx = node1.transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
SqlFieldsQuery qry = new SqlFieldsQuery("INSERT INTO Integer (_key, _val) values " + "(1,1),(2,2),(3,3),(4,4),(5,5)");
cache.query(qry).getAll();
tx.commit();
}
doSleep(1000);
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtForceKeysRequest in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testNoForceKeysRequests.
/**
* @throws Exception If failed.
*/
@Test
public void testNoForceKeysRequests() throws Exception {
cacheC = new IgniteClosure<String, CacheConfiguration[]>() {
@Override
public CacheConfiguration[] apply(String s) {
return null;
}
};
final AtomicBoolean fail = new AtomicBoolean();
spiC = new IgniteClosure<String, TestRecordingCommunicationSpi>() {
@Override
public TestRecordingCommunicationSpi apply(String s) {
TestRecordingCommunicationSpi spi = new TestRecordingCommunicationSpi();
spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (msg instanceof GridDhtForceKeysRequest || msg instanceof GridDhtForceKeysResponse) {
fail.set(true);
U.dumpStack(log, "Unexpected message: " + msg);
}
return false;
}
});
return spi;
}
};
final int SRVS = 3;
for (int i = 0; i < SRVS; i++) startGrid(i);
startClientGrid(SRVS);
final List<CacheConfiguration> ccfgs = new ArrayList<>();
ccfgs.add(cacheConfiguration("tc1", TRANSACTIONAL, 0));
ccfgs.add(cacheConfiguration("tc2", TRANSACTIONAL, 1));
ccfgs.add(cacheConfiguration("tc3", TRANSACTIONAL, 2));
for (CacheConfiguration ccfg : ccfgs) ignite(0).createCache(ccfg);
final int NODES = SRVS + 1;
final AtomicInteger nodeIdx = new AtomicInteger();
final long stopTime = System.currentTimeMillis() + 60_000;
IgniteInternalFuture<?> updateFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
int idx = nodeIdx.getAndIncrement();
Ignite node = grid(idx);
List<IgniteCache<Object, Object>> caches = new ArrayList<>();
for (CacheConfiguration ccfg : ccfgs) caches.add(node.cache(ccfg.getName()));
while (!fail.get() && System.currentTimeMillis() < stopTime) {
for (IgniteCache<Object, Object> cache : caches) cacheOperations(cache);
}
return null;
}
}, NODES, "update-thread");
IgniteInternalFuture<?> srvRestartFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
while (!fail.get() && System.currentTimeMillis() < stopTime) {
Ignite node = startGrid(NODES);
List<IgniteCache<Object, Object>> caches = new ArrayList<>();
for (CacheConfiguration ccfg : ccfgs) caches.add(node.cache(ccfg.getName()));
for (int i = 0; i < 2; i++) {
for (IgniteCache<Object, Object> cache : caches) cacheOperations(cache);
}
U.sleep(500);
stopGrid(NODES);
U.sleep(500);
}
return null;
}
}, "srv-restart");
srvRestartFut.get();
updateFut.get();
assertFalse("Unexpected messages.", fail.get());
}
Aggregations