IGNITE-8945 Stored cache data files corruption when node stops abruptly. - Fixes #4319.
Signed-off-by: Ivan Rakov <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/fff979a9 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/fff979a9 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/fff979a9 Branch: refs/heads/ignite-8446 Commit: fff979a9ef0713500c2e913b6268e040155ddeeb Parents: efa3269 Author: Ivan Daschinskiy <[email protected]> Authored: Wed Jul 11 17:33:57 2018 +0300 Committer: Ivan Rakov <[email protected]> Committed: Wed Jul 11 17:33:57 2018 +0300 ---------------------------------------------------------------------- .../persistence/file/FilePageStoreManager.java | 42 ++- ...heConfigurationFileConsistencyCheckTest.java | 289 +++++++++++++++++++ .../IgnitePdsCorruptedCacheDataTest.java | 146 ---------- ...nitePdsDuplicatedCacheConfigurationTest.java | 161 ----------- .../ignite/testsuites/IgnitePdsTestSuite.java | 4 +- .../ignite/testsuites/IgnitePdsTestSuite2.java | 3 - 6 files changed, 320 insertions(+), 325 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/fff979a9/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java index c8a64c8..3d23d53 100755 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/file/FilePageStoreManager.java @@ -22,6 +22,7 @@ import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -94,6 +95,9 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen public static final String CACHE_DATA_FILENAME = "cache_data.dat"; /** */ + public static final String CACHE_DATA_TMP_FILENAME = CACHE_DATA_FILENAME + ".tmp"; + + /** */ public static final String DFLT_STORE_DIR = "db"; /** */ @@ -321,12 +325,19 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen if (overwrite || !file.exists() || file.length() == 0) { try { - file.createNewFile(); + File tmp = new File(file.getParent(), file.getName() + ".tmp"); + + tmp.createNewFile(); // Pre-existing file will be truncated upon stream open. - try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(file))) { + try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(tmp))) { marshaller.marshal(cacheData, stream); } + + if (file.exists()) + file.delete(); + + Files.move(tmp.toPath(), file.toPath()); } catch (IOException ex) { throw new IgniteCheckedException("Failed to persist cache configuration: " + cacheData.config().getName(), ex); @@ -688,6 +699,20 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen for (File file : files) { if (file.isDirectory()) { + File[] tmpFiles = file.listFiles(new FilenameFilter() { + @Override public boolean accept(File dir, String name) { + return name.endsWith(CACHE_DATA_TMP_FILENAME); + } + }); + + if (tmpFiles != null) { + for (File tmpFile: tmpFiles) { + if (!tmpFile.delete()) + log.warning("Failed to delete temporary cache config file" + + "(make sure Ignite process has enough rights):" + file.getName()); + } + } + if (file.getName().startsWith(CACHE_DIR_PREFIX)) { File conf = new File(file, CACHE_DATA_FILENAME); @@ -748,18 +773,9 @@ public class FilePageStoreManager extends GridCacheSharedManagerAdapter implemen try (InputStream stream = new BufferedInputStream(new FileInputStream(conf))) { return marshaller.unmarshal(stream, U.resolveClassLoader(igniteCfg)); } - catch (IOException e) { - throw new IgniteCheckedException("Failed to read cache configuration from disk for cache: " + - conf.getAbsolutePath(), e); - } - catch (IgniteCheckedException e) { - if (e.hasCause(ClassNotFoundException.class)) + catch (IgniteCheckedException | IOException e) { throw new IgniteCheckedException("An error occurred during cache configuration loading from file [file=" + - conf.getAbsolutePath() + "]. You may want to remove the configuration file; cache will be running " + - "after next node start if static Ignite Configuration contains correct configuration of this cache. " + - "If it was started dynamically, you may need to start it again (all data will be present).", e); - else - throw e; + conf.getAbsolutePath() + "]", e); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/fff979a9/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheConfigurationFileConsistencyCheckTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheConfigurationFileConsistencyCheckTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheConfigurationFileConsistencyCheckTest.java new file mode 100644 index 0000000..74a3950 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCacheConfigurationFileConsistencyCheckTest.java @@ -0,0 +1,289 @@ +/* + * 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.cache.persistence; + +import java.io.BufferedOutputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.FilenameFilter; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; +import org.apache.ignite.Ignite; +import org.apache.ignite.IgniteCheckedException; +import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; +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.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; +import org.apache.ignite.internal.processors.cache.StoredCacheData; +import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager; +import org.apache.ignite.marshaller.Marshaller; +import org.apache.ignite.marshaller.jdk.JdkMarshaller; +import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; +import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; +import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; + +import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CACHE_DATA_FILENAME; +import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CACHE_DATA_TMP_FILENAME; + +/** + * Tests that ignite can start when caches' configurations with same name in different groups stored. + */ +public class IgnitePdsCacheConfigurationFileConsistencyCheckTest extends GridCommonAbstractTest { + /** */ + private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); + + /** */ + private static final int CACHES = 4; + + /** */ + private static final int NODES = 4; + + /** */ + private static final String ODD_GROUP_NAME = "group-odd"; + + /** */ + private static final String EVEN_GROUP_NAME = "group-even"; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + return cfg.setDiscoverySpi(new TcpDiscoverySpi() + .setIpFinder(IP_FINDER)) + .setDataStorageConfiguration(new DataStorageConfiguration() + .setDefaultDataRegionConfiguration(new DataRegionConfiguration() + .setMaxSize(200 * 1024 * 1024) + .setPersistenceEnabled(true))); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + stopAllGrids(); + + cleanPersistenceDir(); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + stopAllGrids(); + + cleanPersistenceDir(); + + super.afterTest(); + } + + /** + * Tests that ignite can start when caches' configurations with same name in different groups stored. + * + * @throws Exception If fails. + */ + public void testStartDuplicatedCacheConfigurations() throws Exception { + IgniteEx ig0 = (IgniteEx)startGrids(NODES); + + ig0.cluster().active(true); + + startCaches(ig0); + + DynamicCacheDescriptor desc = ig0.context().cache().cacheDescriptor(cacheName(3)); + + storeInvalidCacheData(desc); + + stopAllGrids(); + + startGrids(NODES); + + desc = ig0.context().cache().cacheDescriptor(cacheName(3)); + + assertEquals("expected that group of " + cacheName(3) + " is " + EVEN_GROUP_NAME, EVEN_GROUP_NAME, + desc.groupDescriptor().groupName()); + + } + + /** + * Check that cache_data.dat.tmp files are deleted after node restarts. + * + * @throws Exception If failed. + */ + public void testTmpCacheConfigurationsDelete() throws Exception { + IgniteEx ig0 = (IgniteEx)startGrids(NODES); + + ig0.cluster().active(true); + + startCaches(ig0); + + DynamicCacheDescriptor desc = ig0.context().cache().cacheDescriptor(cacheName(3)); + + storeTmpCacheData(desc); + + stopAllGrids(); + + startGrids(NODES); + + for (int i = 0; i < NODES; i++) { + IgniteEx ig = grid(i); + + GridCacheSharedContext sharedCtx = ig.context().cache().context(); + + FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore(); + + File[] tmpFile = pageStore.cacheWorkDir(true, ODD_GROUP_NAME).listFiles(new FilenameFilter() { + @Override public boolean accept(File dir, String name) { + return name.endsWith(CACHE_DATA_TMP_FILENAME); + } + }); + + assertNotNull(tmpFile); + + assertEquals(0, tmpFile.length); + } + } + + /** + * Check that exception contains proper filename when trying to read corrupted cache configuration file. + * + * @throws Exception If failed. + */ + public void testCorruptedCacheConfigurationsValidation() throws Exception { + IgniteEx ig0 = (IgniteEx)startGrids(NODES); + + ig0.cluster().active(true); + + startCaches(ig0); + + DynamicCacheDescriptor desc = ig0.context().cache().cacheDescriptor(cacheName(2)); + + corruptCacheData(desc); + + stopAllGrids(); + + GridTestUtils.assertThrowsAnyCause(log, () -> startGrids(NODES), IgniteCheckedException.class, + desc.cacheName() + CACHE_DATA_FILENAME); + } + + /** + * Store cache descriptor to PDS with invalid group name. + * + * @param cacheDescr Cache descr. + * @throws IgniteCheckedException If fails. + */ + private void storeInvalidCacheData(DynamicCacheDescriptor cacheDescr) throws IgniteCheckedException { + for (int i = 0; i < NODES; i++) { + IgniteEx ig = grid(i); + + GridCacheSharedContext sharedCtx = ig.context().cache().context(); + + FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore(); + + StoredCacheData corrData = cacheDescr.toStoredData(); + + corrData.config().setGroupName(ODD_GROUP_NAME); + + pageStore.storeCacheData(corrData, true); + } + } + + /** + * Store temp cache descriptor to PDS. + * + * @param cacheDescr Cache descr. + * @throws IgniteCheckedException If fails. + */ + private void storeTmpCacheData(DynamicCacheDescriptor cacheDescr) throws Exception { + Marshaller marshaller = new JdkMarshaller(); + + for (int i = 0; i < NODES; i++) { + IgniteEx ig = grid(i); + + GridCacheSharedContext sharedCtx = ig.context().cache().context(); + + FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore(); + + StoredCacheData data = cacheDescr.toStoredData(); + + data.config().setGroupName(ODD_GROUP_NAME); + + File tmp = new File(pageStore.cacheWorkDir(true, ODD_GROUP_NAME), data.config().getName() + CACHE_DATA_TMP_FILENAME); + + try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(tmp))) { + marshaller.marshal(data, stream); + } + } + } + + /** + * Store temp cache descriptor to PDS. + * + * @param cacheDescr Cache descr. + * @throws IgniteCheckedException If fails. + */ + private void corruptCacheData(DynamicCacheDescriptor cacheDescr) throws Exception { + for (int i = 0; i < NODES; i++) { + IgniteEx ig = grid(i); + + GridCacheSharedContext sharedCtx = ig.context().cache().context(); + + FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore(); + + StoredCacheData data = cacheDescr.toStoredData(); + + data.config().setGroupName(ODD_GROUP_NAME); + + File config = new File(pageStore.cacheWorkDir(true, ODD_GROUP_NAME), data.config().getName() + CACHE_DATA_FILENAME); + + try (DataOutputStream os = new DataOutputStream(new FileOutputStream(config))) { + os.writeLong(-1L); + } + + } + } + + /** + * @param ignite Ignite instance. + */ + private void startCaches(Ignite ignite) { + List<CacheConfiguration> ccfg = new ArrayList<>(CACHES); + + for (int i = 0; i < CACHES; i++) { + ccfg.add(new CacheConfiguration<>(cacheName(i)) + .setGroupName(i % 2 == 0 ? ODD_GROUP_NAME : EVEN_GROUP_NAME) + .setBackups(1) + .setAffinity(new RendezvousAffinityFunction(false, 32))); + } + + ignite.createCaches(ccfg); + } + + /** + * Generate cache name from idx. + * + * @param idx Index. + */ + private String cacheName(int idx) { + return "cache" + idx; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/fff979a9/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCorruptedCacheDataTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCorruptedCacheDataTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCorruptedCacheDataTest.java deleted file mode 100644 index 6eff6f6..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsCorruptedCacheDataTest.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * 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.cache.persistence; - -import java.io.File; -import javax.cache.configuration.Factory; -import org.apache.ignite.IgniteCache; -import org.apache.ignite.IgniteCheckedException; -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.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.logger.NullLogger; -import org.apache.ignite.testframework.GridTestUtils; -import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; - -import static org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CACHE_DATA_FILENAME; - -/** - * - */ -public class IgnitePdsCorruptedCacheDataTest extends GridCommonAbstractTest { - /** Test cache name. */ - private static final String TEST_CACHE = "test_cache"; - - /** Start grid with known cache factory. */ - private boolean withFactory; - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - cleanPersistenceDir(); - - super.beforeTest(); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - cleanPersistenceDir(); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); - - DataStorageConfiguration dsCfg = new DataStorageConfiguration(); - - dsCfg.setDefaultDataRegionConfiguration( - new DataRegionConfiguration() - .setPersistenceEnabled(true) - ); - - cfg.setDataStorageConfiguration(dsCfg); - cfg.setCacheConfiguration(getCacheConfiguration()); - cfg.setClassLoader(withFactory ? getExternalClassLoader() : U.gridClassLoader()); - - return cfg; - } - - /** - * @return Cache configuration. - * @throws Exception if failed. - */ - @SuppressWarnings("unchecked") - private CacheConfiguration getCacheConfiguration() throws Exception { - CacheConfiguration cacheCfg = new CacheConfiguration(TEST_CACHE); - - if (withFactory) { - Factory storeFactory = (Factory)getExternalClassLoader() - .loadClass("org.apache.ignite.tests.p2p.CacheDeploymentTestStoreFactory") - .newInstance(); - - cacheCfg.setCacheStoreFactory(storeFactory); - } - - return cacheCfg; - } - - /** - * @throws Exception if failed. - */ - public void testFilePageStoreManagerShouldThrowExceptionWhenFactoryClassCannotBeLoaded() throws Exception { - withFactory = true; - - IgniteEx ignite = (IgniteEx)startGrid(); - - ignite.cluster() - .active(true); - - IgniteCache<Integer, String> cache = ignite.cache(TEST_CACHE); - - cache.put(1, "test value"); - - GridCacheSharedContext sharedCtx = ignite.context().cache().context(); - FilePageStoreManager pageStore = (FilePageStoreManager)sharedCtx.pageStore(); - - assertNotNull(pageStore); - - File cacheData = new File( - pageStore.cacheWorkDir(ignite.context().cache().cacheConfiguration(TEST_CACHE)), - CACHE_DATA_FILENAME - ); - - assertTrue(cacheData.exists()); - - stopGrid(); - - withFactory = false; - - GridTestUtils.assertThrowsAnyCause( - new NullLogger(), - this::startGrid, - IgniteCheckedException.class, - "An error occurred during cache configuration loading from file" - ); - - assertTrue(cacheData.delete()); - - ignite = (IgniteEx)startGrid(); - - ignite.cluster() - .active(true); - - cache = ignite.cache(TEST_CACHE); - - assertEquals("test value", cache.get(1)); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/fff979a9/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDuplicatedCacheConfigurationTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDuplicatedCacheConfigurationTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDuplicatedCacheConfigurationTest.java deleted file mode 100644 index 66459bd..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/IgnitePdsDuplicatedCacheConfigurationTest.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * 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.cache.persistence; - -import java.util.ArrayList; -import java.util.List; -import org.apache.ignite.Ignite; -import org.apache.ignite.IgniteCheckedException; -import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; -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.processors.cache.DynamicCacheDescriptor; -import org.apache.ignite.internal.processors.cache.GridCacheSharedContext; -import org.apache.ignite.internal.processors.cache.StoredCacheData; -import org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager; -import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi; -import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder; -import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder; -import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; - -/** - * Tests that ignite can start when caches' configurations with same name in different groups stored. - */ -public class IgnitePdsDuplicatedCacheConfigurationTest extends GridCommonAbstractTest { - /** */ - private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - - /** */ - private static final int CACHES = 4; - - /** */ - private static final int NODES = 4; - - /** */ - private static final String ODD_GROUP_NAME = "group-odd"; - - /** */ - private static final String EVEN_GROUP_NAME = "group-even"; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); - - return cfg.setDiscoverySpi(new TcpDiscoverySpi() - .setIpFinder(IP_FINDER)) - .setDataStorageConfiguration(new DataStorageConfiguration() - .setDefaultDataRegionConfiguration(new DataRegionConfiguration() - .setMaxSize(200 * 1024 * 1024) - .setPersistenceEnabled(true))); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - super.beforeTest(); - - stopAllGrids(); - - cleanPersistenceDir(); - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - stopAllGrids(); - - cleanPersistenceDir(); - - super.afterTest(); - } - - /** - * Tests that ignite can start when caches' configurations with same name in different groups stored. - * - * @throws Exception If fails. - */ - public void testStartDuplicatedCacheConfigurations() throws Exception { - IgniteEx ig0 = (IgniteEx)startGrids(NODES); - - ig0.cluster().active(true); - - startCaches(ig0); - - DynamicCacheDescriptor desc = ig0.context().cache().cacheDescriptor(cacheName(3)); - - storeInvalidCacheData(desc); - - stopAllGrids(); - - startGrids(NODES); - - desc = ig0.context().cache().cacheDescriptor(cacheName(3)); - - assertEquals("expected that group of " + cacheName(3) + " is " + EVEN_GROUP_NAME, EVEN_GROUP_NAME, - desc.groupDescriptor().groupName()); - - } - - /** - * Store cache descriptor to PDS with invalid group name. - * - * @param cacheDescr Cache descr. - * @throws IgniteCheckedException If fails. - */ - private void storeInvalidCacheData(DynamicCacheDescriptor cacheDescr) throws IgniteCheckedException { - for (int i = 0; i < NODES; i++) { - IgniteEx ig = grid(i); - - GridCacheSharedContext sharedCtx = ig.context().cache().context(); - - FilePageStoreManager pageStore = (FilePageStoreManager) sharedCtx.pageStore(); - - StoredCacheData corrData = cacheDescr.toStoredData(); - - corrData.config().setGroupName(ODD_GROUP_NAME); - - pageStore.storeCacheData(corrData, true); - } - } - - /** - * @param ignite Ignite instance. - */ - private void startCaches(Ignite ignite) { - List<CacheConfiguration> ccfg = new ArrayList<>(CACHES); - - for (int i = 0; i < CACHES; i++) { - ccfg.add(new CacheConfiguration<>(cacheName(i)) - .setGroupName(i % 2 == 0 ? ODD_GROUP_NAME : EVEN_GROUP_NAME) - .setBackups(1) - .setAffinity(new RendezvousAffinityFunction(false, 32))); - } - - ignite.createCaches(ccfg); - } - - /** - * Generate cache name from idx. - * - * @param idx Index. - */ - private String cacheName(int idx) { - return "cache" + idx; - } -} http://git-wip-us.apache.org/repos/asf/ignite/blob/fff979a9/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java index 39c4a2b..d445d9b 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite.java @@ -21,7 +21,7 @@ import junit.framework.TestSuite; import org.apache.ignite.internal.processors.cache.IgniteClusterActivateDeactivateTestWithPersistence; import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsDestroyCacheTest; import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsDestroyCacheWithoutCheckpointsTest; -import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsDuplicatedCacheConfigurationTest; +import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsCacheConfigurationFileConsistencyCheckTest; import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsDynamicCacheTest; import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsSingleNodePutGetPersistenceTest; import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsCacheRestoreTest; @@ -133,7 +133,7 @@ public class IgnitePdsTestSuite extends TestSuite { suite.addTestSuite(IgnitePdsDestroyCacheTest.class); suite.addTestSuite(IgnitePdsDestroyCacheWithoutCheckpointsTest.class); - suite.addTestSuite(IgnitePdsDuplicatedCacheConfigurationTest.class); + suite.addTestSuite(IgnitePdsCacheConfigurationFileConsistencyCheckTest.class); suite.addTestSuite(DefaultPageSizeBackwardsCompatibilityTest.class); http://git-wip-us.apache.org/repos/asf/ignite/blob/fff979a9/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java index 24255f7..1b25b0f 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite2.java @@ -22,7 +22,6 @@ import org.apache.ignite.internal.processors.cache.persistence.IgniteDataStorage import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsContinuousRestartTest; import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsContinuousRestartTestWithExpiryPolicy; import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsContinuousRestartTestWithSharedGroupAndIndexes; -import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsCorruptedCacheDataTest; import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsCorruptedStoreTest; import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsExchangeDuringCheckpointTest; import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsPageSizesTest; @@ -176,8 +175,6 @@ public class IgnitePdsTestSuite2 extends TestSuite { suite.addTestSuite(IgnitePdsCorruptedStoreTest.class); - suite.addTestSuite(IgnitePdsCorruptedCacheDataTest.class); - suite.addTestSuite(IgniteWalIteratorSwitchSegmentTest.class); suite.addTestSuite(IgniteWalIteratorExceptionDuringReadTest.class);
