Repository: ignite Updated Branches: refs/heads/ignite-1277 [created] ae17756c7
# IGNITE-1277: WIP: workable tests for IGFS data backups. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/0bfbe0b8 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/0bfbe0b8 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/0bfbe0b8 Branch: refs/heads/ignite-1277 Commit: 0bfbe0b8db079bda11bb75c31c22fcfac5d46035 Parents: 452af6a Author: iveselovskiy <[email protected]> Authored: Fri Aug 21 20:30:20 2015 +0300 Committer: iveselovskiy <[email protected]> Committed: Fri Aug 21 20:30:20 2015 +0300 ---------------------------------------------------------------------- .../internal/processors/igfs/IgfsProcessor.java | 8 - .../processors/igfs/IgfsAbstractSelfTest.java | 34 ++- .../igfs/IgfsBackupFailoverSelfTest.java | 268 +++++++++++++++++++ .../igfs/IgfsBackupsDualAsyncSelfTest.java | 40 +++ .../igfs/IgfsBackupsDualSyncSelfTest.java | 40 +++ .../igfs/IgfsBackupsPrimarySelfTest.java | 40 +++ 6 files changed, 416 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/0bfbe0b8/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java index af41ec4..f3522a8 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java @@ -311,14 +311,6 @@ public class IgfsProcessor extends IgfsProcessorAdapter { ", maxIgfsSpaceSize=" + maxSpaceSize + ']'); } - if (dataCacheCfg.getCacheMode() == PARTITIONED) { - int backups = dataCacheCfg.getBackups(); - - if (backups != 0) - throw new IgniteCheckedException("IGFS data cache cannot be used with backups (set backup count " + - "to 0 and restart the grid): " + cfg.getDataCacheName()); - } - if (cfg.getMaxSpaceSize() == 0 && dataCacheCfg.getMemoryMode() == OFFHEAP_VALUES) U.warn(log, "IGFS max space size is not specified but data cache values are stored off-heap (max " + "space will be limited to 80% of max JVM heap size): " + cfg.getName()); http://git-wip-us.apache.org/repos/asf/ignite/blob/0bfbe0b8/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java index a8a8957..85aaeb3 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsAbstractSelfTest.java @@ -146,6 +146,12 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { this(mode, ONHEAP_TIERED); } + /** + * Constructor. + * + * @param mode + * @param memoryMode + */ protected IgfsAbstractSelfTest(IgfsMode mode, CacheMemoryMode memoryMode) { assert mode != null && mode != PROXY; @@ -155,7 +161,12 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { dual = mode != PRIMARY; } - private static byte[] createChunk(int length) { + /** + * + * @param length + * @return + */ + static byte[] createChunk(int length) { byte[] chunk = new byte[length]; for (int i = 0; i < chunk.length; i++) @@ -246,6 +257,8 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { discoSpi.setIpFinder(new TcpDiscoveryVmIpFinder(true)); + prepareCacheConfigurations(dataCacheCfg, metaCacheCfg); + cfg.setDiscoverySpi(discoSpi); cfg.setCacheConfiguration(dataCacheCfg, metaCacheCfg); cfg.setFileSystemConfiguration(igfsCfg); @@ -257,6 +270,15 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { } /** + * + * @param dataCacheCfg + * @param metaCacheCfg + */ + protected void prepareCacheConfigurations(CacheConfiguration dataCacheCfg, CacheConfiguration metaCacheCfg) { + // Noop + } + + /** * Execute provided task in a separate thread. * * @param task Task to execute. @@ -2263,7 +2285,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { * @param chunks Data chunks. * @throws Exception If failed. */ - protected void createFile(IgfsImpl igfs, IgfsPath file, boolean overwrite, long blockSize, + protected static void createFile(IgfsImpl igfs, IgfsPath file, boolean overwrite, long blockSize, @Nullable byte[]... chunks) throws Exception { IgfsOutputStream os = null; @@ -2287,7 +2309,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { * @param chunks Data chunks. * @throws Exception If failed. */ - protected void appendFile(IgfsImpl igfs, IgfsPath file, @Nullable byte[]... chunks) + protected static void appendFile(IgfsImpl igfs, IgfsPath file, @Nullable byte[]... chunks) throws Exception { IgfsOutputStream os = null; @@ -2354,7 +2376,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { * @param paths Paths. * @throws IgniteCheckedException If failed. */ - protected void checkExist(IgfsImpl igfs, IgfsPath... paths) throws IgniteCheckedException { + protected static void checkExist(IgfsImpl igfs, IgfsPath... paths) throws IgniteCheckedException { for (IgfsPath path : paths) { assert igfs.context().meta().fileId(path) != null : "Path doesn't exist [igfs=" + igfs.name() + ", path=" + path + ']'; @@ -2463,7 +2485,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { * @throws IOException In case of IO exception. * @throws IgniteCheckedException In case of Grid exception. */ - protected void checkFileContent(IgfsImpl igfs, IgfsPath file, @Nullable byte[]... chunks) + protected static void checkFileContent(IgfsImpl igfs, IgfsPath file, @Nullable byte[]... chunks) throws IOException, IgniteCheckedException { if (chunks != null && chunks.length > 0) { IgfsInputStream is = null; @@ -2562,7 +2584,7 @@ public abstract class IgfsAbstractSelfTest extends IgfsCommonAbstractTest { * @param paths Paths to group. * @return Paths as array. */ - protected IgfsPath[] paths(IgfsPath... paths) { + protected static IgfsPath[] paths(IgfsPath... paths) { return paths; } http://git-wip-us.apache.org/repos/asf/ignite/blob/0bfbe0b8/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupFailoverSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupFailoverSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupFailoverSelfTest.java new file mode 100644 index 0000000..f8b794a --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupFailoverSelfTest.java @@ -0,0 +1,268 @@ +/* + * 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.igfs; + +import org.apache.ignite.*; +import org.apache.ignite.cache.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.igfs.*; +import org.apache.ignite.igfs.secondary.*; +import org.apache.ignite.internal.util.typedef.*; +import org.jetbrains.annotations.*; + +import java.util.*; + +import static org.apache.ignite.cache.CacheAtomicityMode.*; +import static org.apache.ignite.cache.CacheMode.*; +import static org.apache.ignite.internal.processors.igfs.IgfsAbstractSelfTest.*; + +/** + * + */ +public class IgfsBackupFailoverSelfTest extends IgfsCommonAbstractTest { + /** */ + protected static final IgfsPath DIR = new IgfsPath("/dir"); + + /** Sub-directory. */ + protected static final IgfsPath SUBDIR = new IgfsPath(DIR, "subdir"); + + /** Amount of blocks to prefetch. */ + protected static final int DFLT_PREFETCH_BLOCKS = 1; + + /** Amount of sequential block reads before prefetch is triggered. */ + protected static final int DFLT_SEQ_READS_BEFORE_PREFETCH = 2; + + /** Number of Ignite nodes. */ + protected int numIgfsNodes = 5; + + /** Number of backup copies of data (aka replication). */ + protected int numBackups = numIgfsNodes - 1; + + /** File block size. */ + protected int igfsBlockSize = 31; // Use Very small blocks. + + /** */ + protected int affGrpSize = 1; + + /** */ + protected IgfsMode igfsMode = IgfsMode.PRIMARY; + + /** Memory mode. */ + protected final CacheMemoryMode memoryMode; + + /** */ + protected NodeFsData[] nodeDatas; + + /** + * Structure to hold Ignite IGFS node data. + */ + static class NodeFsData { + /** */ + int idx; + + /** */ + Ignite ignite; + + /** */ + IgfsImpl igfsImpl; + } + + /** + * Constructor. + */ + public IgfsBackupFailoverSelfTest() { + + memoryMode = CacheMemoryMode.ONHEAP_TIERED; + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + super.beforeTest(); + + nodeDatas = new NodeFsData[numIgfsNodes]; + + for (int i = 0; i<numIgfsNodes; i++) { + NodeFsData data = new NodeFsData(); + + data.idx = i; + + IgfsIpcEndpointConfiguration igfsIpcCfg = createIgfsRestConfig(10500 + i); + + data.ignite = startGridWithIgfs(getTestGridName(i), "igfs", igfsMode, null, igfsIpcCfg); + + data.igfsImpl = (IgfsImpl) data.ignite.fileSystem("igfs"); + + nodeDatas[i] = data; + } + + // Ensure all the nodes are started and discovered each other. + checkTopology(numIgfsNodes); + } + + /** + * + * @param port + * @return + */ + protected IgfsIpcEndpointConfiguration createIgfsRestConfig(int port) { + IgfsIpcEndpointConfiguration cfg = new IgfsIpcEndpointConfiguration(); + + cfg.setType(IgfsIpcEndpointType.TCP); + cfg.setPort(port); + + return cfg; + } + + /** + * Start grid with IGFS. + * + * @param gridName Grid name. + * @param igfsName IGFS name + * @param mode IGFS mode. + * @param secondaryFs Secondary file system (optional). + * @param restCfg Rest configuration string (optional). + * @return Started grid instance. + * @throws Exception If failed. + */ + protected Ignite startGridWithIgfs(String gridName, String igfsName, IgfsMode mode, + @Nullable IgfsSecondaryFileSystem secondaryFs, @Nullable IgfsIpcEndpointConfiguration restCfg) throws Exception { + final FileSystemConfiguration igfsCfg = new FileSystemConfiguration(); + + igfsCfg.setDataCacheName("dataCache"); + igfsCfg.setMetaCacheName("metaCache"); + igfsCfg.setName(igfsName); + igfsCfg.setBlockSize(igfsBlockSize); + igfsCfg.setDefaultMode(mode); + igfsCfg.setIpcEndpointConfiguration(restCfg); + igfsCfg.setSecondaryFileSystem(secondaryFs); + igfsCfg.setPrefetchBlocks(DFLT_PREFETCH_BLOCKS); + igfsCfg.setSequentialReadsBeforePrefetch(DFLT_SEQ_READS_BEFORE_PREFETCH); + + CacheConfiguration dataCacheCfg = defaultCacheConfiguration(); + + dataCacheCfg.setName("dataCache"); + dataCacheCfg.setCacheMode(PARTITIONED); + dataCacheCfg.setNearConfiguration(null); + dataCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + dataCacheCfg.setAffinityMapper(new IgfsGroupDataBlocksKeyMapper(affGrpSize)); + dataCacheCfg.setBackups(numBackups); + dataCacheCfg.setAtomicityMode(TRANSACTIONAL); + dataCacheCfg.setMemoryMode(memoryMode); + dataCacheCfg.setOffHeapMaxMemory(0); + + CacheConfiguration metaCacheCfg = defaultCacheConfiguration(); + + metaCacheCfg.setName("metaCache"); + metaCacheCfg.setCacheMode(REPLICATED); + metaCacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC); + metaCacheCfg.setAtomicityMode(TRANSACTIONAL); + + IgniteConfiguration cfg = new IgniteConfiguration(); + + cfg.setGridName(gridName); + + cfg.setCacheConfiguration(dataCacheCfg, metaCacheCfg); + cfg.setFileSystemConfiguration(igfsCfg); + + cfg.setLocalHost("127.0.0.1"); + + return startGrid(gridName, cfg); + } + + /** {@inheritDoc} */ + @Override protected void afterTest() throws Exception { + super.afterTest(); + + G.stopAll(false); + + Arrays.fill(nodeDatas, null); + } + + /** + * + * @param length + * @return + */ + static byte[] createChunk(int length, int j) { + byte[] chunk = new byte[length]; + + for (int i = 0; i < chunk.length; i++) + chunk[i] = (byte)(i ^ j); + + return chunk; + } + + /** + * + * @throws Exception + */ + public void testTwoNodes() throws Exception { + final IgfsImpl igfs0 = nodeDatas[0].igfsImpl; + + clear(igfs0); + + IgfsAbstractSelfTest.create(igfs0, paths(DIR, SUBDIR), null); + + final int files = 500; + + final int fileSize = 16 * 1024; + + // Create files: + for (int f=0; f<files; f++) { + final byte[] chunk = createChunk(fileSize, f); + + createFile(igfs0, filePath(f), true, -1, chunk); + } + + // Check files: + for (int f=0; f<files; f++) { + IgfsPath path = filePath(f); + byte[] data = createChunk(fileSize, f); + + // Check through 1st node: + checkExist(igfs0, path); + checkFileContent(igfs0, path, data); + + // Check same file through other nodes: + for (int n=1; n<numIgfsNodes; n++) { + checkExist(nodeDatas[n].igfsImpl, path); + checkFileContent(nodeDatas[n].igfsImpl, path, data); + } + } + + // Now stop all the nodes but the 1st: + for (int n=1; n<numIgfsNodes; n++) + stopGrid(n); + + // Check files again: + for (int f=0; f<files; f++) { + IgfsPath path = filePath(f); + + byte[] data = createChunk(fileSize, f); + + // Check through 1st node: + checkExist(igfs0, path); + checkFileContent(igfs0, path, data); + } + } + + /** */ + private IgfsPath filePath(int j) { + return new IgfsPath(SUBDIR, "file" + j); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/0bfbe0b8/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupsDualAsyncSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupsDualAsyncSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupsDualAsyncSelfTest.java new file mode 100644 index 0000000..3c042d6 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupsDualAsyncSelfTest.java @@ -0,0 +1,40 @@ +/* + * 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.igfs; + +import org.apache.ignite.configuration.*; + +import static org.apache.ignite.igfs.IgfsMode.*; + +/** + * Tests for DUAL_ASYNC mode. + */ +public class IgfsBackupsDualAsyncSelfTest extends IgfsDualAbstractSelfTest { + /** + * Constructor. + */ + public IgfsBackupsDualAsyncSelfTest() { + super(DUAL_ASYNC); + } + + /** {@inheritDoc} */ + @Override protected void prepareCacheConfigurations(CacheConfiguration dataCacheCfg, + CacheConfiguration metaCacheCfg) { + dataCacheCfg.setBackups(1); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/0bfbe0b8/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupsDualSyncSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupsDualSyncSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupsDualSyncSelfTest.java new file mode 100644 index 0000000..5d7fdaf --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupsDualSyncSelfTest.java @@ -0,0 +1,40 @@ +/* + * 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.igfs; + +import org.apache.ignite.configuration.*; + +import static org.apache.ignite.igfs.IgfsMode.*; + +/** + * Tests for DUAL_SYNC mode. + */ +public class IgfsBackupsDualSyncSelfTest extends IgfsDualAbstractSelfTest { + /** + * Constructor. + */ + public IgfsBackupsDualSyncSelfTest() { + super(DUAL_SYNC); + } + + /** {@inheritDoc} */ + @Override protected void prepareCacheConfigurations(CacheConfiguration dataCacheCfg, + CacheConfiguration metaCacheCfg) { + dataCacheCfg.setBackups(1); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/0bfbe0b8/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupsPrimarySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupsPrimarySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupsPrimarySelfTest.java new file mode 100644 index 0000000..c4958a8 --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsBackupsPrimarySelfTest.java @@ -0,0 +1,40 @@ +/* + * 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.igfs; + +import org.apache.ignite.configuration.*; + +import static org.apache.ignite.igfs.IgfsMode.*; + +/** + * Tests for PRIMARY mode. + */ +public class IgfsBackupsPrimarySelfTest extends IgfsAbstractSelfTest { + /** + * Constructor. + */ + public IgfsBackupsPrimarySelfTest() { + super(PRIMARY); + } + + /** {@inheritDoc} */ + @Override protected void prepareCacheConfigurations(CacheConfiguration dataCacheCfg, + CacheConfiguration metaCacheCfg) { + dataCacheCfg.setBackups(1); + } +}
