use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage in project ignite by apache.
the class GridCachePartitionExchangeManager method onKernalStart0.
/** {@inheritDoc} */
@Override
protected void onKernalStart0(boolean reconnect) throws IgniteCheckedException {
super.onKernalStart0(reconnect);
ClusterNode loc = cctx.localNode();
long startTime = loc.metrics().getStartTime();
assert startTime > 0;
// Generate dummy discovery event for local node joining.
T2<DiscoveryEvent, DiscoCache> locJoin = cctx.discovery().localJoin();
DiscoveryEvent discoEvt = locJoin.get1();
DiscoCache discoCache = locJoin.get2();
GridDhtPartitionExchangeId exchId = initialExchangeId();
GridDhtPartitionsExchangeFuture fut = exchangeFuture(exchId, discoEvt, discoCache, null, null);
if (reconnect)
reconnectExchangeFut = new GridFutureAdapter<>();
exchWorker.addFirstExchangeFuture(fut);
if (!cctx.kernalContext().clientNode()) {
for (int cnt = 0; cnt < cctx.gridConfig().getRebalanceThreadPoolSize(); cnt++) {
final int idx = cnt;
cctx.io().addOrderedHandler(rebalanceTopic(cnt), new CI2<UUID, GridCacheMessage>() {
@Override
public void apply(final UUID id, final GridCacheMessage m) {
if (!enterBusy())
return;
try {
GridCacheContext cacheCtx = cctx.cacheContext(m.cacheId);
if (cacheCtx != null) {
if (m instanceof GridDhtPartitionSupplyMessage)
cacheCtx.preloader().handleSupplyMessage(idx, id, (GridDhtPartitionSupplyMessage) m);
else if (m instanceof GridDhtPartitionDemandMessage)
cacheCtx.preloader().handleDemandMessage(idx, id, (GridDhtPartitionDemandMessage) m);
else
U.error(log, "Unsupported message type: " + m.getClass().getName());
}
} finally {
leaveBusy();
}
}
});
}
}
new IgniteThread(cctx.igniteInstanceName(), "exchange-worker", exchWorker).start();
if (reconnect) {
fut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {
@Override
public void apply(IgniteInternalFuture<AffinityTopologyVersion> fut) {
try {
fut.get();
for (GridCacheContext cacheCtx : cctx.cacheContexts()) cacheCtx.preloader().onInitialExchangeComplete(null);
reconnectExchangeFut.onDone();
} catch (IgniteCheckedException e) {
for (GridCacheContext cacheCtx : cctx.cacheContexts()) cacheCtx.preloader().onInitialExchangeComplete(e);
reconnectExchangeFut.onDone(e);
}
}
});
} else {
if (log.isDebugEnabled())
log.debug("Beginning to wait on local exchange future: " + fut);
boolean first = true;
while (true) {
try {
fut.get(cctx.preloadExchangeTimeout());
break;
} catch (IgniteFutureTimeoutCheckedException ignored) {
if (first) {
U.warn(log, "Failed to wait for initial partition map exchange. " + "Possible reasons are: " + U.nl() + " ^-- Transactions in deadlock." + U.nl() + " ^-- Long running transactions (ignore if this is the case)." + U.nl() + " ^-- Unreleased explicit locks.");
first = false;
} else
U.warn(log, "Still waiting for initial partition map exchange [fut=" + fut + ']');
} catch (IgniteNeedReconnectException e) {
throw e;
} catch (Exception e) {
if (fut.reconnectOnError(e))
throw new IgniteNeedReconnectException(cctx.localNode(), e);
throw e;
}
}
AffinityTopologyVersion nodeStartVer = new AffinityTopologyVersion(discoEvt.topologyVersion(), 0);
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
if (nodeStartVer.equals(cacheCtx.startTopologyVersion()))
cacheCtx.preloader().onInitialExchangeComplete(null);
}
if (log.isDebugEnabled())
log.debug("Finished waiting for initial exchange: " + fut.exchangeId());
}
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage in project ignite by apache.
the class IgniteOnePhaseCommitInvokeTest method onePhaseInvoke.
/**
* @param withOldVal If {@code true}
* @param setVal Flag whether set value from entry processor.
* @param retPrev Flag whether entry processor should return previous value.
* @throws Exception If failed.
*/
private void onePhaseInvoke(final boolean withOldVal, final boolean setVal, final boolean retPrev) throws Exception {
log.info("Test onePhaseInvoke [withOldVal=" + withOldVal + ", setVal=" + setVal + ", retPrev=" + retPrev + ']');
Ignite srv0 = startGrid(0);
if (withOldVal)
srv0.cache(CACHE_NAME).put(1, 1);
client = true;
final Ignite clientNode = startGrid(1);
TestRecordingCommunicationSpi.spi(srv0).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return msg instanceof GridDhtPartitionSupplyMessage && ((GridDhtPartitionSupplyMessage) msg).cacheId() == CU.cacheId(CACHE_NAME);
}
});
client = false;
Ignite srv1 = startGrid(2);
TestRecordingCommunicationSpi.spi(srv1).blockMessages(GridDhtTxPrepareResponse.class, srv0.name());
IgniteInternalFuture<?> fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Object res = clientNode.cache(CACHE_NAME).invoke(1, new TestEntryProcessor(setVal, retPrev));
Object expRes;
if (retPrev)
expRes = withOldVal ? 1 : null;
else
expRes = null;
assertEquals(expRes, res);
return null;
}
});
U.sleep(1000);
stopGrid(0);
fut.get();
if (!setVal)
checkCacheData(F.asMap(1, null), CACHE_NAME);
else {
Object expVal;
if (setVal)
expVal = 2;
else
expVal = withOldVal ? 1 : null;
checkCacheData(F.asMap(1, expVal), CACHE_NAME);
}
checkOnePhaseCommitReturnValuesCleaned(-1);
}
use of org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage 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();
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).cacheId() == CU.cacheId(ccfg.getName());
}
});
}
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