use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class GridDhtCacheAdapter method processNearSingleGetRequest.
/**
* @param nodeId Node ID.
* @param req Get request.
*/
protected void processNearSingleGetRequest(final UUID nodeId, final GridNearSingleGetRequest req) {
assert ctx.affinityNode();
final CacheExpiryPolicy expiryPlc = CacheExpiryPolicy.fromRemote(req.createTtl(), req.accessTtl());
IgniteInternalFuture<GridCacheEntryInfo> fut = getDhtSingleAsync(nodeId, req.messageId(), req.key(), req.addReader(), req.readThrough(), req.topologyVersion(), req.subjectId(), req.taskNameHash(), expiryPlc, req.skipValues(), req.recovery());
fut.listen(new CI1<IgniteInternalFuture<GridCacheEntryInfo>>() {
@Override
public void apply(IgniteInternalFuture<GridCacheEntryInfo> f) {
GridNearSingleGetResponse res;
GridDhtFuture<GridCacheEntryInfo> fut = (GridDhtFuture<GridCacheEntryInfo>) f;
try {
GridCacheEntryInfo info = fut.get();
if (F.isEmpty(fut.invalidPartitions())) {
Message res0 = null;
if (info != null) {
if (req.needEntryInfo()) {
info.key(null);
res0 = info;
} else if (req.needVersion())
res0 = new CacheVersionedValue(info.value(), info.version());
else
res0 = info.value();
}
res = new GridNearSingleGetResponse(ctx.cacheId(), req.futureId(), null, res0, false, req.addDeploymentInfo());
if (info != null && req.skipValues())
res.setContainsValue();
} else {
AffinityTopologyVersion topVer = ctx.shared().exchange().lastTopologyFuture().initialVersion();
assert topVer.compareTo(req.topologyVersion()) > 0 : "Wrong ready topology version for " + "invalid partitions response [topVer=" + topVer + ", req=" + req + ']';
res = new GridNearSingleGetResponse(ctx.cacheId(), req.futureId(), topVer, null, true, req.addDeploymentInfo());
}
} catch (NodeStoppingException ignored) {
return;
} catch (IgniteCheckedException e) {
U.error(log, "Failed processing get request: " + req, e);
res = new GridNearSingleGetResponse(ctx.cacheId(), req.futureId(), req.topologyVersion(), null, false, req.addDeploymentInfo());
res.error(e);
}
try {
ctx.io().send(nodeId, res, ctx.ioPolicy());
} catch (IgniteCheckedException e) {
U.error(log, "Failed to send get response to node (is node still alive?) [nodeId=" + nodeId + ",req=" + req + ", res=" + res + ']', e);
}
sendTtlUpdateRequest(expiryPlc);
}
});
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class IgniteCacheAtomicProtocolTest method testPutMissedDhtRequest_UnstableTopology.
/**
* @throws Exception If failed.
*/
public void testPutMissedDhtRequest_UnstableTopology() throws Exception {
blockRebalance = true;
ccfg = cacheConfiguration(1, FULL_SYNC);
startServers(4);
client = true;
Ignite client = startGrid(4);
IgniteCache<Integer, Integer> nearCache = client.cache(TEST_CACHE);
testSpi(ignite(0)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return msg instanceof GridDhtAtomicAbstractUpdateRequest;
}
});
Integer key = primaryKey(ignite(0).cache(TEST_CACHE));
log.info("Start put [key=" + key + ']');
IgniteFuture<?> fut = nearCache.putAsync(key, key);
U.sleep(500);
assertFalse(fut.isDone());
stopGrid(0);
fut.get();
checkData(F.asMap(key, key));
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class IgniteTxCachePrimarySyncTest method singleKeyCommitFromPrimary.
/**
* @param ignite Node executing cache operation.
* @param ccfg Cache configuration.
* @param c Cache update closure.
* @throws Exception If failed.
*/
private void singleKeyCommitFromPrimary(Ignite ignite, final CacheConfiguration<Object, Object> ccfg, IgniteBiInClosure<Integer, IgniteCache<Object, Object>> c) throws Exception {
TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
IgniteCache<Object, Object> cache = ignite.cache(ccfg.getName());
final Integer key = primaryKey(cache);
cache.remove(key);
waitKeyRemoved(ccfg.getName(), key);
commSpi0.record(GridDhtTxFinishRequest.class);
commSpi0.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return msg instanceof GridDhtTxFinishRequest;
}
});
c.apply(key, cache);
assertEquals(key, cache.localPeek(key));
U.sleep(50);
for (int i = 0; i < SRVS; i++) {
Ignite node = ignite(i);
if (node != ignite)
assertNull(node.cache(DEFAULT_CACHE_NAME).localPeek(key));
}
commSpi0.stopBlock(true);
waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
List<Object> msgs = commSpi0.recordedMessages(true);
assertEquals(ccfg.getBackups(), msgs.size());
cache.remove(key);
waitKeyRemoved(ccfg.getName(), key);
c.apply(key, cache);
waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class IgniteTxCachePrimarySyncTest method singleKeyCommit.
/**
* @param client Node executing cache operation.
* @param ccfg Cache configuration.
* @param c Cache update closure.
* @throws Exception If failed.
*/
private void singleKeyCommit(Ignite client, final CacheConfiguration<Object, Object> ccfg, IgniteBiInClosure<Integer, IgniteCache<Object, Object>> c) throws Exception {
Ignite ignite = ignite(0);
assertNotSame(ignite, client);
TestRecordingCommunicationSpi commSpiClient = (TestRecordingCommunicationSpi) client.configuration().getCommunicationSpi();
TestRecordingCommunicationSpi commSpi0 = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
IgniteCache<Object, Object> cache = ignite.cache(ccfg.getName());
final Integer key = primaryKey(cache);
cache.remove(key);
waitKeyRemoved(ccfg.getName(), key);
IgniteCache<Object, Object> clientCache = client.cache(ccfg.getName());
commSpiClient.record(GridNearTxFinishRequest.class);
commSpi0.record(GridDhtTxFinishRequest.class);
commSpi0.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return msg instanceof GridDhtTxFinishRequest;
}
});
c.apply(key, clientCache);
assertEquals(key, cache.localPeek(key));
U.sleep(50);
boolean nearCache = ((IgniteCacheProxy) clientCache).context().isNear();
for (int i = 1; i < NODES; i++) {
Ignite node = ignite(i);
if (nearCache && node == client && !node.affinity(ccfg.getName()).isPrimaryOrBackup(node.cluster().localNode(), key))
assertEquals("Invalid value for node: " + i, key, ignite(i).cache(DEFAULT_CACHE_NAME).localPeek(key));
else
assertNull("Invalid value for node: " + i, ignite(i).cache(DEFAULT_CACHE_NAME).localPeek(key));
}
commSpi0.stopBlock(true);
waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
List<Object> msgs = commSpiClient.recordedMessages(true);
assertEquals(1, msgs.size());
GridNearTxFinishRequest req = (GridNearTxFinishRequest) msgs.get(0);
assertEquals(PRIMARY_SYNC, req.syncMode());
msgs = commSpi0.recordedMessages(true);
assertEquals(ccfg.getBackups(), msgs.size());
clientCache.remove(key);
waitKeyRemoved(ccfg.getName(), key);
c.apply(key, clientCache);
waitKeyUpdated(ignite, ccfg.getBackups() + 1, ccfg.getName(), key);
}
use of org.apache.ignite.plugin.extensions.communication.Message in project ignite by apache.
the class IgniteCacheReadFromBackupTest method testGetFromPrimaryPreloadInProgress.
/**
* @throws Exception If failed.
*/
public void testGetFromPrimaryPreloadInProgress() throws Exception {
for (final CacheConfiguration<Object, Object> ccfg : cacheConfigurations()) {
boolean near = (ccfg.getNearConfiguration() != null);
log.info("Test cache [mode=" + ccfg.getCacheMode() + ", atomicity=" + ccfg.getAtomicityMode() + ", backups=" + ccfg.getBackups() + ", near=" + near + "]");
ignite(0).createCache(ccfg);
awaitPartitionMapExchange();
try {
Map<Ignite, Integer> backupKeys = new HashMap<>();
Map<Ignite, Integer> nearKeys = new HashMap<>();
for (int i = 0; i < NODES; i++) {
Ignite ignite = ignite(i);
IgniteCache<Integer, Integer> cache = ignite.cache(ccfg.getName());
backupKeys.put(ignite, backupKey(cache));
if (ccfg.getCacheMode() == PARTITIONED)
nearKeys.put(ignite, nearKey(cache));
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
final int grpId = groupIdForCache(ignite, ccfg.getName());
spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (!msg.getClass().equals(GridDhtPartitionSupplyMessage.class))
return false;
return ((GridDhtPartitionSupplyMessage) msg).groupId() == grpId;
}
});
}
try (Ignite newNode = startGrid(NODES)) {
IgniteCache<Integer, Integer> cache = newNode.cache(ccfg.getName());
TestRecordingCommunicationSpi newNodeSpi = recordGetRequests(newNode, near);
Integer key = backupKey(cache);
assertNull(cache.get(key));
List<Object> msgs = newNodeSpi.recordedMessages(false);
assertEquals(1, msgs.size());
for (int i = 0; i < NODES; i++) {
Ignite ignite = ignite(i);
log.info("Check node: " + ignite.name());
checkLocalRead(ignite, ccfg, backupKeys.get(ignite), nearKeys.get(ignite));
}
for (int i = 0; i < NODES; i++) {
Ignite ignite = ignite(i);
TestRecordingCommunicationSpi spi = (TestRecordingCommunicationSpi) ignite.configuration().getCommunicationSpi();
spi.stopBlock(true);
}
awaitPartitionMapExchange();
checkLocalRead(NODES + 1, ccfg);
}
} finally {
ignite(0).destroyCache(ccfg.getName());
}
}
}
Aggregations