Search in sources :

Example 6 with ACTIVE

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());
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) JmxMetricExporterSpi(org.apache.ignite.spi.metric.jmx.JmxMetricExporterSpi) GridCacheUtils.cacheId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheId) CdcMain(org.apache.ignite.internal.cdc.CdcMain) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) RunWith(org.junit.runner.RunWith) DELETE(org.apache.ignite.cdc.AbstractCdcTest.ChangeEventType.DELETE) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) MetricExporterSpi(org.apache.ignite.spi.metric.MetricExporterSpi) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) EnumSet(java.util.EnumSet) Parameterized(org.junit.runners.Parameterized) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) WALMode(org.apache.ignite.configuration.WALMode) F(org.apache.ignite.internal.util.typedef.F) Iterator(java.util.Iterator) Collection(java.util.Collection) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) IgniteCache(org.apache.ignite.IgniteCache) Serializable(java.io.Serializable) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) UPDATE(org.apache.ignite.cdc.AbstractCdcTest.ChangeEventType.UPDATE) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Collections(java.util.Collections) IGNITE_DATA_STORAGE_FOLDER_BY_CONSISTENT_ID(org.apache.ignite.IgniteSystemProperties.IGNITE_DATA_STORAGE_FOLDER_BY_CONSISTENT_ID) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CdcMain(org.apache.ignite.internal.cdc.CdcMain) ArrayList(java.util.ArrayList) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 7 with ACTIVE

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);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) ATTR_MACS(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MACS) ObjectOutput(java.io.ObjectOutput) InetAddress(java.net.InetAddress) SB(org.apache.ignite.internal.util.typedef.internal.SB) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCluster(org.apache.ignite.IgniteCluster) Map(java.util.Map) BaselineTopology(org.apache.ignite.internal.processors.cluster.BaselineTopology) StartNodeCallable(org.apache.ignite.internal.util.nodestart.StartNodeCallable) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IgniteFuture(org.apache.ignite.lang.IgniteFuture) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) IgniteNodeStartUtils.parseFile(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.parseFile) Externalizable(java.io.Externalizable) ClusterGroupEmptyException(org.apache.ignite.cluster.ClusterGroupEmptyException) GridToStringExclude(org.apache.ignite.internal.util.tostring.GridToStringExclude) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Set(java.util.Set) UUID(java.util.UUID) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BaselineAutoAdjustStatus(org.apache.ignite.internal.processors.cluster.baseline.autoadjust.BaselineAutoAdjustStatus) CU(org.apache.ignite.internal.util.typedef.internal.CU) Optional(java.util.Optional) ObjectInput(java.io.ObjectInput) IgniteProductVersion(org.apache.ignite.lang.IgniteProductVersion) ShutdownPolicy(org.apache.ignite.ShutdownPolicy) IgniteFutureImpl(org.apache.ignite.internal.util.future.IgniteFutureImpl) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) DistributedEnumProperty(org.apache.ignite.internal.processors.configuration.distributed.DistributedEnumProperty) ClusterState(org.apache.ignite.cluster.ClusterState) GridCompoundFuture(org.apache.ignite.internal.util.future.GridCompoundFuture) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteLogger(org.apache.ignite.IgniteLogger) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) GridKernalContext(org.apache.ignite.internal.GridKernalContext) ClusterNode(org.apache.ignite.cluster.ClusterNode) CI1(org.apache.ignite.internal.util.typedef.CI1) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteComponentType(org.apache.ignite.internal.IgniteComponentType) ClusterStartNodeResult(org.apache.ignite.cluster.ClusterStartNodeResult) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) F(org.apache.ignite.internal.util.typedef.F) ATTR_IPS(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_IPS) A(org.apache.ignite.internal.util.typedef.internal.A) DynamicCacheDescriptor(org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) BaselineNode(org.apache.ignite.cluster.BaselineNode) File(java.io.File) ObjectStreamException(java.io.ObjectStreamException) IgniteSshHelper(org.apache.ignite.internal.util.nodestart.IgniteSshHelper) IgniteRemoteStartSpecification(org.apache.ignite.internal.util.nodestart.IgniteRemoteStartSpecification) Collections(java.util.Collections) IgniteNodeStartUtils.specifications(org.apache.ignite.internal.util.nodestart.IgniteNodeStartUtils.specifications) IgniteException(org.apache.ignite.IgniteException) BaselineNode(org.apache.ignite.cluster.BaselineNode)

Example 8 with ACTIVE

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);
}
Also used : IntStream(java.util.stream.IntStream) ClusterState(org.apache.ignite.cluster.ClusterState) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteCluster(org.apache.ignite.IgniteCluster) Map(java.util.Map) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) G(org.apache.ignite.internal.util.typedef.G) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) F(org.apache.ignite.internal.util.typedef.F) IgniteFuture(org.apache.ignite.lang.IgniteFuture) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) EventType(org.apache.ignite.events.EventType) EVT_CLUSTER_DEACTIVATED(org.apache.ignite.events.EventType.EVT_CLUSTER_DEACTIVATED) Collection(java.util.Collection) Event(org.apache.ignite.events.Event) EVT_CLUSTER_ACTIVATED(org.apache.ignite.events.EventType.EVT_CLUSTER_ACTIVATED) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) Collectors(java.util.stream.Collectors) StopNodeOrHaltFailureHandler(org.apache.ignite.failure.StopNodeOrHaltFailureHandler) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Comparator.comparingLong(java.util.Comparator.comparingLong) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Collections(java.util.Collections) Ignite(org.apache.ignite.Ignite)

Example 9 with ACTIVE

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");
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Arrays(java.util.Arrays) PartitionHashRecordV2(org.apache.ignite.internal.processors.cache.verify.PartitionHashRecordV2) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) CacheObjectBinaryProcessorImpl.binaryWorkDir(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl.binaryWorkDir) ByteBuffer(java.nio.ByteBuffer) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) Collections.singletonList(java.util.Collections.singletonList) PagePartitionMetaIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PagePartitionMetaIO) Map(java.util.Map) X(org.apache.ignite.internal.util.typedef.X) Path(java.nio.file.Path) FilePageStore(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStore) Parameterized(org.junit.runners.Parameterized) SNAPSHOT_METAFILE_EXT(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.SNAPSHOT_METAFILE_EXT) IgniteDataIntegrityViolationException(org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) MarshallerContextImpl.mappingFileStoreWorkDir(org.apache.ignite.internal.MarshallerContextImpl.mappingFileStoreWorkDir) FilePageStoreManager(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager) UUID(java.util.UUID) CacheDataRow(org.apache.ignite.internal.processors.cache.persistence.CacheDataRow) ByteOrder(java.nio.ByteOrder) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) PartitionKeyV2(org.apache.ignite.internal.processors.cache.verify.PartitionKeyV2) GridJobExecuteRequest(org.apache.ignite.internal.GridJobExecuteRequest) CU(org.apache.ignite.internal.util.typedef.internal.CU) BinaryObjectImpl(org.apache.ignite.internal.binary.BinaryObjectImpl) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) FilePageStoreManager.getPartitionFileName(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.getPartitionFileName) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) FilePageStoreManager.cacheDirName(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.cacheDirName) DR_NONE(org.apache.ignite.internal.processors.dr.GridDrType.DR_NONE) GridCacheAdapter(org.apache.ignite.internal.processors.cache.GridCacheAdapter) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PdsFolderSettings(org.apache.ignite.internal.processors.cache.persistence.filename.PdsFolderSettings) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteSnapshotManager.databaseRelativePath(org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.databaseRelativePath) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) ComputeJobResult(org.apache.ignite.compute.ComputeJobResult) PageIO(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) GridTestUtils.assertNotContains(org.apache.ignite.testframework.GridTestUtils.assertNotContains) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) VerifyBackupPartitionsTaskV2(org.apache.ignite.internal.processors.cache.verify.VerifyBackupPartitionsTaskV2) Before(org.junit.Before) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) F(org.apache.ignite.internal.util.typedef.F) VisorIdleVerifyTaskArg(org.apache.ignite.internal.visor.verify.VisorIdleVerifyTaskArg) Files(java.nio.file.Files) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) GridUnsafe(org.apache.ignite.internal.util.GridUnsafe) DFLT_SNAPSHOT_DIRECTORY(org.apache.ignite.configuration.IgniteConfiguration.DFLT_SNAPSHOT_DIRECTORY) TTL_ETERNAL(org.apache.ignite.internal.processors.cache.GridCacheUtils.TTL_ETERNAL) IOException(java.io.IOException) Test(org.junit.Test) File(java.io.File) CacheObjectBinaryProcessorImpl(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl) GridIterator(org.apache.ignite.internal.util.lang.GridIterator) GridTestUtils.assertContains(org.apache.ignite.testframework.GridTestUtils.assertContains) NONE(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion.NONE) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) GridTopic(org.apache.ignite.internal.GridTopic) Paths(java.nio.file.Paths) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CacheFilterEnum(org.apache.ignite.internal.visor.verify.CacheFilterEnum) GroupPartitionId.getTypeByPartId(org.apache.ignite.internal.processors.cache.persistence.partstate.GroupPartitionId.getTypeByPartId) Collections(java.util.Collections) TxState(org.apache.ignite.internal.processors.cache.mvcc.txlog.TxState) GridMessageListener(org.apache.ignite.internal.managers.communication.GridMessageListener) GridJobExecuteRequest(org.apache.ignite.internal.GridJobExecuteRequest) CU(org.apache.ignite.internal.util.typedef.internal.CU) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteEx(org.apache.ignite.internal.IgniteEx) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) UUID(java.util.UUID) File(java.io.File) Test(org.junit.Test)

Example 10 with ACTIVE

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());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IndexKeyTypeSettings(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) IgniteJdbcThinDriver(org.apache.ignite.IgniteJdbcThinDriver) Connection(java.sql.Connection) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) LongListReuseBag(org.apache.ignite.internal.processors.cache.persistence.tree.reuse.LongListReuseBag) IgniteEx(org.apache.ignite.internal.IgniteEx) VisorValidateIndexesJobResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesJobResult) ReadOnlyMetastorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadOnlyMetastorage) VisorValidateIndexesTaskArg(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskArg) PageIoResolver(org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIoResolver) Map(java.util.Map) DurableBackgroundCleanupIndexTreeTaskV2(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) InlineIndexTreeFactory(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.InlineIndexTreeFactory) SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) ReuseList(org.apache.ignite.internal.processors.cache.persistence.tree.reuse.ReuseList) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) INACTIVE(org.apache.ignite.cluster.ClusterState.INACTIVE) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Set(java.util.Set) UUID(java.util.UUID) DurableBackgroundCleanupIndexTreeTask(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTask) PreparedStatement(java.sql.PreparedStatement) IgniteCache(org.apache.ignite.IgniteCache) StopNodeFailureHandler(org.apache.ignite.failure.StopNodeFailureHandler) IgniteCacheOffheapManager(org.apache.ignite.internal.processors.cache.IgniteCacheOffheapManager) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClientConfiguration(org.apache.ignite.configuration.ClientConfiguration) DFLT_SCHEMA(org.apache.ignite.internal.processors.query.QueryUtils.DFLT_SCHEMA) GridTestUtils.getFieldValue(org.apache.ignite.testframework.GridTestUtils.getFieldValue) CallbackExecutorLogListener(org.apache.ignite.testframework.CallbackExecutorLogListener) NoopRowHandlerFactory(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.NoopRowHandlerFactory) IntStream(java.util.stream.IntStream) LogListener(org.apache.ignite.testframework.LogListener) InlineIndexTree(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexTree) IgniteThread(org.apache.ignite.thread.IgniteThread) IndexRow(org.apache.ignite.internal.cache.query.index.sorted.IndexRow) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) Deque(java.util.Deque) CacheGroupContext(org.apache.ignite.internal.processors.cache.CacheGroupContext) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteClient(org.apache.ignite.client.IgniteClient) ReadWriteMetastorage(org.apache.ignite.internal.processors.cache.persistence.metastorage.ReadWriteMetastorage) IndexName(org.apache.ignite.internal.cache.query.index.IndexName) DurableBackgroundTask(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTask) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) CheckpointListener(org.apache.ignite.internal.processors.cache.persistence.checkpoint.CheckpointListener) LinkedList(java.util.LinkedList) IGNITE_SYSTEM_WORKER_BLOCKED_TIMEOUT(org.apache.ignite.IgniteSystemProperties.IGNITE_SYSTEM_WORKER_BLOCKED_TIMEOUT) VisorValidateIndexesTaskResult(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTaskResult) ACTIVE(org.apache.ignite.cluster.ClusterState.ACTIVE) F(org.apache.ignite.internal.util.typedef.F) Properties(java.util.Properties) InlineIndexRowHandlerFactory(org.apache.ignite.internal.cache.query.index.sorted.InlineIndexRowHandlerFactory) ValidateIndexesPartitionResult(org.apache.ignite.internal.visor.verify.ValidateIndexesPartitionResult) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) TimeUnit(java.util.concurrent.TimeUnit) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) AtomicLong(java.util.concurrent.atomic.AtomicLong) Collectors.toList(java.util.stream.Collectors.toList) Ignition(org.apache.ignite.Ignition) GridCacheSharedContext(org.apache.ignite.internal.processors.cache.GridCacheSharedContext) IndexRowCache(org.apache.ignite.internal.cache.query.index.sorted.IndexRowCache) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) InlineRecommender(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineRecommender) GridTuple3(org.apache.ignite.internal.util.lang.GridTuple3) MessageOrderLogListener(org.apache.ignite.testframework.MessageOrderLogListener) DurableBackgroundCleanupIndexTreeTaskV2.idxTreeFactory(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2.idxTreeFactory) IoStatisticsHolder(org.apache.ignite.internal.metric.IoStatisticsHolder) Collections(java.util.Collections) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) VisorValidateIndexesTask(org.apache.ignite.internal.visor.verify.VisorValidateIndexesTask) Ignite(org.apache.ignite.Ignite)

Aggregations

ACTIVE (org.apache.ignite.cluster.ClusterState.ACTIVE)33 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)33 IgniteEx (org.apache.ignite.internal.IgniteEx)31 Test (org.junit.Test)31 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)30 IgniteCache (org.apache.ignite.IgniteCache)27 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)27 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)27 U (org.apache.ignite.internal.util.typedef.internal.U)25 List (java.util.List)23 Serializable (java.io.Serializable)22 Map (java.util.Map)22 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)22 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)22 File (java.io.File)21 UUID (java.util.UUID)21 CountDownLatch (java.util.concurrent.CountDownLatch)21 Ignite (org.apache.ignite.Ignite)21 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)21 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)20