use of org.apache.ignite.internal.events.DiscoveryCustomEvent in project ignite by apache.
the class IgniteStatisticsConfigurationManager method afterTopologyUnlock.
/**
* Update statistics after topology change, if necessary.
*
* @param fut Topology change future.
*/
public void afterTopologyUnlock(GridDhtPartitionsExchangeFuture fut) {
topVer = fut.topologyVersion();
// Skip join/left client nodes.
if (fut.exchangeType() != GridDhtPartitionsExchangeFuture.ExchangeType.ALL || (persistence && cluster.clusterState().lastState() != ClusterState.ACTIVE))
return;
DiscoveryEvent evt = fut.firstEvent();
// Skip create/destroy caches.
if (evt.type() == DiscoveryCustomEvent.EVT_DISCOVERY_CUSTOM_EVT) {
DiscoveryCustomMessage msg = ((DiscoveryCustomEvent) evt).customMessage();
if (msg instanceof DynamicCacheChangeBatch)
return;
}
mgmtBusyExecutor.execute(this::updateAllLocalStatistics);
}
use of org.apache.ignite.internal.events.DiscoveryCustomEvent in project ignite by apache.
the class IgniteClusterSnapshotSelfTest method testClusterSnapshotOnMovingPartitionsCoordinatorLeft.
/**
* @throws Exception If fails.
*/
@Test
public void testClusterSnapshotOnMovingPartitionsCoordinatorLeft() throws Exception {
startGridsWithCache(2, dfltCacheCfg, CACHE_KEYS_RANGE);
for (Ignite grid : G.allGrids()) {
TestRecordingCommunicationSpi.spi(grid).blockMessages((node, msg) -> msg instanceof GridDhtPartitionSupplyMessage);
}
Ignite ignite = startGrid(2);
ignite.cluster().setBaselineTopology(ignite.cluster().topologyVersion());
TestRecordingCommunicationSpi.spi(grid(0)).waitForBlocked();
CountDownLatch latch = new CountDownLatch(G.allGrids().size());
IgniteInternalFuture<?> stopFut = GridTestUtils.runAsync(() -> {
try {
U.await(latch);
stopGrid(0);
} catch (IgniteInterruptedCheckedException e) {
fail("Must not fail here: " + e.getMessage());
}
});
Queue<T2<GridDhtPartitionExchangeId, Boolean>> exchFuts = new ConcurrentLinkedQueue<>();
for (Ignite ig : G.allGrids()) {
((IgniteEx) ig).context().cache().context().exchange().registerExchangeAwareComponent(new PartitionsExchangeAware() {
/**
* {@inheritDoc}
*/
@Override
public void onInitBeforeTopologyLock(GridDhtPartitionsExchangeFuture fut) {
if (!(fut.firstEvent() instanceof DiscoveryCustomEvent))
return;
try {
exchFuts.add(new T2<>(fut.exchangeId(), fut.rebalanced()));
latch.countDown();
stopFut.get();
} catch (IgniteCheckedException e) {
U.log(log, "Interrupted on coordinator: " + e.getMessage());
}
}
});
}
IgniteFuture<Void> fut = ignite.snapshot().createSnapshot(SNAPSHOT_NAME);
stopFut.get();
assertThrowsAnyCause(log, fut::get, IgniteException.class, "Snapshot creation has been finished with an error");
assertEquals("Snapshot futures expected: " + exchFuts, 3, exchFuts.size());
for (T2<GridDhtPartitionExchangeId, Boolean> exch : exchFuts) assertFalse("Snapshot `rebalanced` must be false with moving partitions: " + exch.get1(), exch.get2());
}
use of org.apache.ignite.internal.events.DiscoveryCustomEvent in project ignite by apache.
the class CacheBlockOnReadAbstractTest method createCachePredicate.
/**
* Checks that given discovery event is from "Create cache" operation.
*
* @param discoEvt Discovery event.
*/
private static boolean createCachePredicate(DiscoveryEvent discoEvt) {
if (discoEvt instanceof DiscoveryCustomEvent) {
DiscoveryCustomEvent discoCustomEvt = (DiscoveryCustomEvent) discoEvt;
DiscoveryCustomMessage customMsg = discoCustomEvt.customMessage();
if (customMsg instanceof DynamicCacheChangeBatch) {
DynamicCacheChangeBatch cacheChangeBatch = (DynamicCacheChangeBatch) customMsg;
ExchangeActions exchangeActions = U.field(cacheChangeBatch, "exchangeActions");
Collection<CacheActionData> startRequests = exchangeActions.cacheStartRequests();
return !startRequests.isEmpty();
}
}
return false;
}
use of org.apache.ignite.internal.events.DiscoveryCustomEvent in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method onAllReceived.
/**
*
*/
private void onAllReceived() {
try {
assert crd.isLocal();
if (!crd.equals(discoCache.serverNodes().get(0))) {
for (GridCacheContext cacheCtx : cctx.cacheContexts()) {
if (!cacheCtx.isLocal())
cacheCtx.topology().beforeExchange(this, !centralizedAff);
}
}
for (GridDhtPartitionsAbstractMessage msg : msgs.values()) {
if (msg instanceof GridDhtPartitionsSingleMessage) {
GridDhtPartitionsSingleMessage msg0 = (GridDhtPartitionsSingleMessage) msg;
for (Map.Entry<Integer, GridDhtPartitionMap> entry : msg0.partitions().entrySet()) {
Integer cacheId = entry.getKey();
GridCacheContext cacheCtx = cctx.cacheContext(cacheId);
GridDhtPartitionTopology top = cacheCtx != null ? cacheCtx.topology() : cctx.exchange().clientTopology(cacheId, this);
Map<Integer, T2<Long, Long>> cntrs = msg0.partitionUpdateCounters(cacheId);
if (cntrs != null)
top.applyUpdateCounters(cntrs);
}
}
}
if (discoEvt.type() == EVT_NODE_JOINED) {
if (cctx.kernalContext().state().active())
assignPartitionsStates();
} else if (discoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT) {
assert discoEvt instanceof DiscoveryCustomEvent;
if (((DiscoveryCustomEvent) discoEvt).customMessage() instanceof DynamicCacheChangeBatch) {
if (exchActions != null) {
if (exchActions.newClusterState() == ClusterState.ACTIVE)
assignPartitionsStates();
Set<String> caches = exchActions.cachesToResetLostPartitions();
if (!F.isEmpty(caches))
resetLostPartitions(caches);
}
}
} else if (discoEvt.type() == EVT_NODE_LEFT || discoEvt.type() == EVT_NODE_FAILED)
detectLostPartitions();
updateLastVersion(cctx.versions().last());
cctx.versions().onExchange(lastVer.get().order());
if (centralizedAff) {
IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>> fut = cctx.affinity().initAffinityOnNodeLeft(this);
if (!fut.isDone()) {
fut.listen(new IgniteInClosure<IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>>>() {
@Override
public void apply(IgniteInternalFuture<Map<Integer, Map<Integer, List<UUID>>>> fut) {
onAffinityInitialized(fut);
}
});
} else
onAffinityInitialized(fut);
} else {
List<ClusterNode> nodes;
synchronized (this) {
srvNodes.remove(cctx.localNode());
nodes = new ArrayList<>(srvNodes);
}
if (!nodes.isEmpty())
sendAllPartitions(nodes);
if (exchangeOnChangeGlobalState && !F.isEmpty(changeGlobalStateExceptions))
cctx.kernalContext().state().onFullResponseMessage(changeGlobalStateExceptions);
onDone(exchangeId().topologyVersion());
}
} catch (IgniteCheckedException e) {
if (reconnectOnError(e))
onDone(new IgniteNeedReconnectException(cctx.localNode(), e));
else
onDone(e);
}
}
use of org.apache.ignite.internal.events.DiscoveryCustomEvent in project ignite by apache.
the class CacheBlockOnReadAbstractTest method testUpdateBaselineTopologyTransactionalReplicated.
/**
* @throws Exception If failed.
*/
@Params(timeout = 5000L, atomicityMode = TRANSACTIONAL, cacheMode = REPLICATED)
@Test
public void testUpdateBaselineTopologyTransactionalReplicated() throws Exception {
doTest(asMessagePredicate(discoEvt -> {
if (discoEvt instanceof DiscoveryCustomEvent) {
DiscoveryCustomEvent discoCustomEvt = (DiscoveryCustomEvent) discoEvt;
DiscoveryCustomMessage customMsg = discoCustomEvt.customMessage();
return customMsg instanceof ChangeGlobalStateMessage;
}
return false;
}), () -> {
startNodesInClientMode(false);
IgniteEx ignite = startGrid(UUID.randomUUID().toString());
baseline.get(0).cluster().setBaselineTopology(baseline.get(0).context().discovery().topologyVersion());
baseline.add(ignite);
});
}
Aggregations