anton-vinogradov commented on code in PR #10533: URL: https://github.com/apache/ignite/pull/10533#discussion_r1107189790
########## modules/indexing/src/test/java/org/apache/ignite/internal/processors/database/WalDisabledDuringIndexRecreateTest.java: ########## @@ -0,0 +1,308 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.database; + +import java.io.File; +import java.util.Arrays; +import java.util.EnumMap; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Predicate; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.binary.BinaryBasicIdMapper; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataRegionConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.cdc.CdcIndexRebuildTest.TestVal; +import org.apache.ignite.internal.metric.IoStatisticsHolder; +import org.apache.ignite.internal.pagemem.wal.WALIterator; +import org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType; +import org.apache.ignite.internal.processors.cache.persistence.tree.BPlusTree; +import org.apache.ignite.internal.processors.cache.persistence.tree.io.PageIO; +import org.apache.ignite.internal.processors.cache.persistence.tree.util.PageHandler; +import org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer; +import org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory; +import org.apache.ignite.internal.processors.cache.persistence.wal.reader.IgniteWalIteratorFactory.IteratorParametersBuilder; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.ListeningTestLogger; +import org.apache.ignite.testframework.LogListener; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.cluster.ClusterState.ACTIVE; +import static org.apache.ignite.cluster.ClusterState.INACTIVE; +import static org.apache.ignite.configuration.DataStorageConfiguration.DFLT_WAL_ARCHIVE_PATH; +import static org.apache.ignite.configuration.DataStorageConfiguration.DFLT_WAL_PATH; +import static org.apache.ignite.configuration.DataStorageConfiguration.UNLIMITED_WAL_ARCHIVE; +import static org.apache.ignite.internal.pagemem.wal.record.WALRecord.RecordType.BTREE_PAGE_INSERT; +import static org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheGroupId; +import static org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheId; +import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CACHE_DIR_PREFIX; +import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CACHE_GRP_DIR_PREFIX; +import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.DFLT_STORE_DIR; +import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.INDEX_FILE_NAME; +import static org.apache.ignite.internal.processors.query.schema.management.SortedIndexDescriptorFactory.H2_TREE; + +/** */ +@RunWith(Parameterized.class) +@SuppressWarnings({"resource"}) +public class WalDisabledDuringIndexRecreateTest extends GridCommonAbstractTest { + /** Batches count. */ + public static final int ENTRIES_CNT = 1_000; + + /** */ + public static final String GRP_NAME = "my-group"; + + /** */ + private ListeningTestLogger testLog; + + /** */ + @Parameterized.Parameter() + public boolean cacheGrps; + + /** */ + @Parameterized.Parameters(name = "cacheGroups={0}") + public static Iterable<Object> data() { + return Arrays.asList(true, false); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + return super.getConfiguration(igniteInstanceName) + .setGridLogger(testLog) + .setConsistentId(igniteInstanceName) + .setClusterStateOnStart(INACTIVE) + .setDataStorageConfiguration(new DataStorageConfiguration() + .setDefaultDataRegionConfiguration(new DataRegionConfiguration() + .setPersistenceEnabled(true)) + .setMaxWalArchiveSize(UNLIMITED_WAL_ARCHIVE)); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + cleanPersistenceDir(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + stopAllGrids(); + + cleanPersistenceDir(); + } + + /** */ + @Test + public void testDisabled() throws Exception { + WALPointer walStartPtr = createDataAndDeleteIndexBin(); + + awaitRebuild(); + + assertEquals( + (Long)3L, + countWalRecordsByTypes(wp -> wp.compareTo(walStartPtr) > 0).getOrDefault(BTREE_PAGE_INSERT, 0L) + ); + } + + /** */ + @Test + public void testRestartInCaseOfFailure() throws Exception { + WALPointer walStartPtr = createDataAndDeleteIndexBin(); + + String treeName = BPlusTree.treeName( + new BinaryBasicIdMapper().typeId(TestVal.class.getName()) + "_" + + TestVal.class.getSimpleName().toUpperCase() + "_F0_IDX", + H2_TREE + ); + + try { + AtomicInteger errCntr = new AtomicInteger(10); + + // Setting up wrapper that will fail on 10 put operation. + BPlusTree.testHndWrapper = (tree, hnd) -> { + if (!tree.name().equals(treeName)) + return hnd; + + PageHandler<Object, BPlusTree.Result> delegate = (PageHandler<Object, BPlusTree.Result>)hnd; + + return new PageHandler<BPlusTree.Get, BPlusTree.Result>() { + @Override public BPlusTree.Result run( + int cacheId, + long pageId, + long page, + long pageAddr, + PageIO io, + Boolean walPlc, + BPlusTree.Get arg, + int lvl, + IoStatisticsHolder statHolder + ) throws IgniteCheckedException { + if (arg instanceof BPlusTree.Put && errCntr.decrementAndGet() == 0) + throw new IgniteCheckedException("Test error!"); Review Comment: Proper explanation required. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
