use of org.apache.ignite.cluster.ClusterState.ACTIVE in project ignite by apache.
the class CdcSelfTest method testReReadWhenStateWasNotStored.
/**
*/
@Test
public void testReReadWhenStateWasNotStored() throws Exception {
IgniteEx ign = startGrid(getConfiguration("ignite-0"));
ign.cluster().state(ACTIVE);
IgniteCache<Integer, User> cache = ign.getOrCreateCache(DEFAULT_CACHE_NAME);
addData(cache, 0, KEYS_CNT);
for (int i = 0; i < 3; i++) {
UserCdcConsumer cnsmr = new UserCdcConsumer() {
@Override
protected boolean commit() {
return false;
}
};
CdcMain cdc = createCdc(cnsmr, getConfiguration(ign.name()));
IgniteInternalFuture<?> fut = runAsync(cdc);
waitForSize(KEYS_CNT, DEFAULT_CACHE_NAME, UPDATE, cnsmr);
checkMetrics(cdc, KEYS_CNT);
fut.cancel();
assertTrue(cnsmr.stopped());
}
AtomicBoolean consumeHalf = new AtomicBoolean(true);
AtomicBoolean halfCommitted = new AtomicBoolean(false);
int half = KEYS_CNT / 2;
UserCdcConsumer cnsmr = new UserCdcConsumer() {
@Override
public boolean onEvents(Iterator<CdcEvent> evts) {
if (consumeHalf.get() && F.size(data(UPDATE, cacheId(DEFAULT_CACHE_NAME))) == half) {
// This means that state committed as a result of the previous call.
halfCommitted.set(true);
return false;
}
while (evts.hasNext()) {
CdcEvent evt = evts.next();
if (!evt.primary())
continue;
data.computeIfAbsent(F.t(evt.value() == null ? DELETE : UPDATE, evt.cacheId()), k -> new ArrayList<>()).add((Integer) evt.key());
if (consumeHalf.get())
return F.size(data(UPDATE, cacheId(DEFAULT_CACHE_NAME))) == half;
}
return true;
}
};
CdcMain cdc = createCdc(cnsmr, getConfiguration(ign.name()));
IgniteInternalFuture<?> fut = runAsync(cdc);
waitForSize(half, DEFAULT_CACHE_NAME, UPDATE, cnsmr);
checkMetrics(cdc, half);
waitForCondition(halfCommitted::get, getTestTimeout());
fut.cancel();
assertTrue(cnsmr.stopped());
removeData(cache, 0, KEYS_CNT);
consumeHalf.set(false);
cdc = createCdc(cnsmr, getConfiguration(ign.name()));
fut = runAsync(cdc);
waitForSize(KEYS_CNT, DEFAULT_CACHE_NAME, UPDATE, cnsmr);
waitForSize(KEYS_CNT, DEFAULT_CACHE_NAME, DELETE, cnsmr);
checkMetrics(cdc, KEYS_CNT * 2 - half);
fut.cancel();
assertTrue(cnsmr.stopped());
}
use of org.apache.ignite.cluster.ClusterState.ACTIVE in project ignite by apache.
the class IgniteClusterImpl method validateBeforeBaselineChange.
/**
* Executes validation checks of cluster state and BaselineTopology before changing BaselineTopology to new one.
*/
private void validateBeforeBaselineChange(Collection<? extends BaselineNode> baselineTop) {
verifyBaselineTopologySupport(ctx.discovery().discoCache());
if (!ctx.state().clusterState().active())
throw new IgniteException("Changing BaselineTopology on inactive cluster is not allowed.");
if (baselineTop != null) {
if (baselineTop.isEmpty())
throw new IgniteException("BaselineTopology must contain at least one node.");
List<BaselineNode> currBlT = Optional.ofNullable(ctx.state().clusterState().baselineTopology()).map(BaselineTopology::currentBaseline).orElse(Collections.emptyList());
Collection<ClusterNode> srvrs = ctx.cluster().get().forServers().nodes();
for (BaselineNode node : baselineTop) {
Object consistentId = node.consistentId();
if (currBlT.stream().noneMatch(currBlTNode -> Objects.equals(currBlTNode.consistentId(), consistentId)) && srvrs.stream().noneMatch(currServersNode -> Objects.equals(currServersNode.consistentId(), consistentId)))
throw new IgniteException("Check arguments. Node with consistent ID [" + consistentId + "] not found in server nodes.");
}
Collection<Object> onlineNodes = onlineBaselineNodesRequestedForRemoval(baselineTop);
if (onlineNodes != null) {
if (!onlineNodes.isEmpty())
throw new IgniteException("Removing online nodes from BaselineTopology is not supported: " + onlineNodes);
}
}
}
use of org.apache.ignite.cluster.ClusterState.ACTIVE in project ignite by apache.
the class ClusterActivationEventTest method beforeTest.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTest() throws Exception {
super.beforeTest();
for (Ignite ignite : G.allGrids()) {
ignite.events().stopLocalListen(lsnr);
ignite.events().stopLocalListen(delayLsnr);
}
grid(0).cluster().state(ACTIVE);
grid(0).cache(DEFAULT_CACHE_NAME).removeAll();
Map<Integer, Integer> vals = IntStream.range(0, 100).boxed().collect(Collectors.toMap(i -> i, i -> i));
grid(0).cachex(DEFAULT_CACHE_NAME).putAll(vals);
}
use of org.apache.ignite.cluster.ClusterState.ACTIVE in project ignite by apache.
the class IgniteClusterSnapshotCheckTest method testClusterSnapshotCheckOtherCluster.
/**
* @throws Exception If fails.
*/
@Test
public void testClusterSnapshotCheckOtherCluster() throws Exception {
IgniteEx ig0 = startGridsWithCache(3, dfltCacheCfg.setAffinity(new RendezvousAffinityFunction(false, 1)), CACHE_KEYS_RANGE);
ig0.snapshot().createSnapshot(SNAPSHOT_NAME).get();
stopAllGrids();
// Cleanup persistence directory except created snapshots.
Arrays.stream(new File(U.defaultWorkDirectory()).listFiles()).filter(f -> !f.getName().equals(DFLT_SNAPSHOT_DIRECTORY)).forEach(U::delete);
Set<UUID> assigns = Collections.newSetFromMap(new ConcurrentHashMap<>());
for (int i = 4; i < 7; i++) {
startGrid(optimize(getConfiguration(getTestIgniteInstanceName(i)).setCacheConfiguration()));
UUID locNodeId = grid(i).localNode().id();
grid(i).context().io().addMessageListener(GridTopic.TOPIC_JOB, new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg, byte plc) {
if (msg instanceof GridJobExecuteRequest) {
GridJobExecuteRequest msg0 = (GridJobExecuteRequest) msg;
if (msg0.getTaskName().contains(SnapshotPartitionsVerifyTask.class.getName()))
assigns.add(locNodeId);
}
}
});
}
IgniteEx ignite = grid(4);
ignite.cluster().baselineAutoAdjustEnabled(false);
ignite.cluster().state(ACTIVE);
IdleVerifyResultV2 res = snp(ignite).checkSnapshot(SNAPSHOT_NAME).get();
StringBuilder b = new StringBuilder();
res.print(b::append, true);
// GridJobExecuteRequest is not send to the local node.
assertTrue("Number of jobs must be equal to the cluster size (except local node): " + assigns + ", count: " + assigns.size(), waitForCondition(() -> assigns.size() == 2, 5_000L));
assertTrue(F.isEmpty(res.exceptions()));
assertPartitionsSame(res);
assertContains(log, b.toString(), "The check procedure has finished, no conflicts have been found");
}
use of org.apache.ignite.cluster.ClusterState.ACTIVE in project ignite by apache.
the class LongDestroyDurableBackgroundTaskTest method testLongIndexDeletion.
/**
* Tests case when long index deletion operation happens. Checkpoint should run in the middle of index deletion
* operation. Node can restart without fully deleted index tree.
*
* @param restart Whether do the restart of one node.
* @param rebalance Whether add to topology one more node while the index is being deleted.
* @param multicolumn Is index multicolumn.
* @param checkWhenOneNodeStopped Whether try to check index and try to recreate it while one node with pending
* task is stopped.
* @param dropIdxWhenOneNodeStopped Whether drop index on alive nodes while one node with pending
* task is stopped.
* @throws Exception If failed.
*/
private void testLongIndexDeletion(boolean restart, boolean rebalance, boolean multicolumn, boolean checkWhenOneNodeStopped, boolean dropIdxWhenOneNodeStopped) throws Exception {
// If not restart, then assume that index is always dropped.
boolean dropIdxWhenOneNodeStopped0 = !restart || dropIdxWhenOneNodeStopped;
int nodeCnt = NODES_COUNT;
Ignite ignite = prepareAndPopulateCluster(nodeCnt, multicolumn, false);
Ignite aliveNode = grid(ALWAYS_ALIVE_NODE_NUM);
IgniteCache<Integer, Integer> cacheOnAliveNode = aliveNode.cache(DEFAULT_CACHE_NAME);
if (rebalance) {
startGrid(nodeCnt);
nodeCnt++;
Collection<ClusterNode> blt = IntStream.range(0, nodeCnt).mapToObj(i -> grid(i).localNode()).collect(toList());
ignite.cluster().setBaselineTopology(blt);
}
if (restart) {
blockDestroy.set(true);
stopGrid(RESTARTED_NODE_NUM, true);
awaitPartitionMapExchange();
checkSelectAndPlan(cacheOnAliveNode, false);
if (checkWhenOneNodeStopped) {
createIndex(cacheOnAliveNode, multicolumn);
checkSelectAndPlan(cacheOnAliveNode, true);
if (dropIdxWhenOneNodeStopped0)
query(cacheOnAliveNode, "drop index " + IDX_NAME);
forceCheckpoint(aliveNode);
aliveNode.cluster().active(false);
}
ignite = startGrid(RESTARTED_NODE_NUM);
awaitLatch(pendingDelLatch, "Test timed out: failed to await for durable background task completion.");
awaitPartitionMapExchange();
if (checkWhenOneNodeStopped) {
ignite.cluster().active(true);
// If index was dropped, we need to wait it's rebuild on restarted node.
if (!dropIdxWhenOneNodeStopped0)
awaitLatch(idxsRebuildLatch, "Failed to wait for indexes rebuilding.");
}
checkSelectAndPlan(cacheOnAliveNode, !dropIdxWhenOneNodeStopped0);
} else
awaitLatch(pendingDelLatch, "Test timed out: failed to await for durable background task completion.");
IgniteCache<Integer, Integer> cache = grid(RESTARTED_NODE_NUM).cache(DEFAULT_CACHE_NAME);
checkSelectAndPlan(cache, !dropIdxWhenOneNodeStopped0);
checkSelectAndPlan(cacheOnAliveNode, !dropIdxWhenOneNodeStopped0);
// Trying to recreate index if it was dropped.
if (dropIdxWhenOneNodeStopped0)
createIndex(cache, multicolumn);
checkSelectAndPlan(cache, true);
checkSelectAndPlan(cacheOnAliveNode, true);
forceCheckpoint();
validateIndexes(ignite);
assertFalse(blockedSysCriticalThreadLsnr.check());
}
Aggregations