IGNITE-9980 Added additional flag to filter caches by types to control.sh - Fixes #5496.
Signed-off-by: Alexey Goncharuk <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/9199aac1 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/9199aac1 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/9199aac1 Branch: refs/heads/ignite-10044 Commit: 9199aac144844aa8e4a44e36e366af25dd90eb18 Parents: 6613376 Author: vd-pyatkov <[email protected]> Authored: Thu Dec 6 18:39:07 2018 +0300 Committer: Alexey Goncharuk <[email protected]> Committed: Thu Dec 6 18:39:07 2018 +0300 ---------------------------------------------------------------------- .../internal/commandline/CommandHandler.java | 24 ++- .../commandline/cache/CacheArguments.java | 18 ++ .../verify/VerifyBackupPartitionsTaskV2.java | 97 ++++++++-- .../internal/visor/verify/CacheFilterEnum.java | 52 ++++++ .../verify/VisorIdleVerifyDumpTaskArg.java | 30 +++- .../ignite/util/GridCommandHandlerTest.java | 177 ++++++++++++++++++- 6 files changed, 376 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/9199aac1/modules/core/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java index 56f278b..da6495f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/commandline/CommandHandler.java @@ -101,6 +101,7 @@ import org.apache.ignite.internal.visor.tx.VisorTxSortOrder; import org.apache.ignite.internal.visor.tx.VisorTxTask; import org.apache.ignite.internal.visor.tx.VisorTxTaskArg; import org.apache.ignite.internal.visor.tx.VisorTxTaskResult; +import org.apache.ignite.internal.visor.verify.CacheFilterEnum; import org.apache.ignite.internal.visor.verify.IndexIntegrityCheckIssue; import org.apache.ignite.internal.visor.verify.IndexValidationIssue; import org.apache.ignite.internal.visor.verify.ValidateIndexesPartitionResult; @@ -195,6 +196,9 @@ public class CommandHandler { /** */ private static final String CMD_SKIP_ZEROS = "--skipZeros"; + /** Cache filter. */ + private static final String CACHE_FILTER = "--cacheFilter"; + /** */ private static final String CMD_USER_ATTRIBUTES = "--user-attributes"; @@ -809,10 +813,14 @@ public class CommandHandler { nl(); log(i("Subcommands:")); - usageCache(LIST, "regexPattern", "[groups|seq]", "[nodeId]", op(CONFIG), op(OUTPUT_FORMAT, MULTI_LINE.text())); - usageCache(CONTENTION, "minQueueSize", "[nodeId]", "[maxPrint]"); - usageCache(IDLE_VERIFY, op(CMD_DUMP), op(CMD_SKIP_ZEROS), "[cache1,...,cacheN]"); - usageCache(VALIDATE_INDEXES, "[cache1,...,cacheN]", "[nodeId]", op(or(VI_CHECK_FIRST + " N", VI_CHECK_THROUGH + " K"))); + usageCache(LIST, "regexPattern", op(or("groups","seq")), op("nodeId"), op(CONFIG), op(OUTPUT_FORMAT, MULTI_LINE + .text())); + usageCache(CONTENTION, "minQueueSize", op("nodeId"), op("maxPrint")); + usageCache(IDLE_VERIFY, op(CMD_DUMP), op(CMD_SKIP_ZEROS), "[cache1,...,cacheN]", + op(CACHE_FILTER, or(CacheFilterEnum.ALL.toString(), CacheFilterEnum.SYSTEM.toString(), CacheFilterEnum.PERSISTENT.toString(), + CacheFilterEnum.NOT_PERSISTENT.toString()))); + usageCache(VALIDATE_INDEXES, "[cache1,...,cacheN]", op("nodeId"), op(or(VI_CHECK_FIRST + " N", + VI_CHECK_THROUGH + " K"))); usageCache(DISTRIBUTION, or("nodeId", NULL), "[cacheName1,...,cacheNameN]", op(CMD_USER_ATTRIBUTES, "attName1,...,attrNameN")); usageCache(RESET_LOST_PARTITIONS, "cacheName1,...,cacheNameN"); nl(); @@ -1133,7 +1141,7 @@ public class CommandHandler { String path = executeTask( client, VisorIdleVerifyDumpTask.class, - new VisorIdleVerifyDumpTaskArg(cacheArgs.caches(), cacheArgs.isSkipZeros()) + new VisorIdleVerifyDumpTaskArg(cacheArgs.caches(), cacheArgs.isSkipZeros(), cacheArgs.getCacheFilterEnum()) ); log("VisorIdleVerifyDumpTask successfully written output to '" + path + "'"); @@ -2049,6 +2057,12 @@ public class CommandHandler { cacheArgs.dump(true); else if (CMD_SKIP_ZEROS.equals(nextArg)) cacheArgs.skipZeros(true); + else if (CACHE_FILTER.equals(nextArg)) { + String filter = nextArg("The cache filter should be specified. The following values can be " + + "used: " + Arrays.toString(CacheFilterEnum.values()) + '.').toUpperCase(); + + cacheArgs.setCacheFilterEnum(CacheFilterEnum.valueOf(filter)); + } else parseCacheNames(nextArg, cacheArgs); } http://git-wip-us.apache.org/repos/asf/ignite/blob/9199aac1/modules/core/src/main/java/org/apache/ignite/internal/commandline/cache/CacheArguments.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/commandline/cache/CacheArguments.java b/modules/core/src/main/java/org/apache/ignite/internal/commandline/cache/CacheArguments.java index e92b627..9372391 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/commandline/cache/CacheArguments.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/commandline/cache/CacheArguments.java @@ -19,6 +19,7 @@ package org.apache.ignite.internal.commandline.cache; import java.util.Set; import java.util.UUID; import org.apache.ignite.internal.commandline.OutputFormat; +import org.apache.ignite.internal.visor.verify.CacheFilterEnum; import org.apache.ignite.internal.visor.verify.VisorViewCacheCmd; import org.jetbrains.annotations.Nullable; @@ -71,6 +72,23 @@ public class CacheArguments { /** Full config flag. */ private boolean fullConfig; + /** Cache filter. */ + private CacheFilterEnum cacheFilterEnum = CacheFilterEnum.ALL; + + /** + * @return Gets filter of caches, which will by checked. + */ + public CacheFilterEnum getCacheFilterEnum() { + return cacheFilterEnum; + } + + /** + * @param cacheFilterEnum Cache filter. + */ + public void setCacheFilterEnum(CacheFilterEnum cacheFilterEnum) { + this.cacheFilterEnum = cacheFilterEnum; + } + /** * @return Full config flag. */ http://git-wip-us.apache.org/repos/asf/ignite/blob/9199aac1/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/verify/VerifyBackupPartitionsTaskV2.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/verify/VerifyBackupPartitionsTaskV2.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/verify/VerifyBackupPartitionsTaskV2.java index e698e3a..14995cb 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/verify/VerifyBackupPartitionsTaskV2.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/verify/VerifyBackupPartitionsTaskV2.java @@ -36,20 +36,26 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; import org.apache.ignite.IgniteInterruptedException; import org.apache.ignite.IgniteLogger; +import org.apache.ignite.cache.CacheMode; import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.compute.ComputeJob; import org.apache.ignite.compute.ComputeJobAdapter; import org.apache.ignite.compute.ComputeJobResult; import org.apache.ignite.compute.ComputeTaskAdapter; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.DataStorageConfiguration; import org.apache.ignite.internal.IgniteEx; import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.DynamicCacheDescriptor; +import org.apache.ignite.internal.processors.cache.GridCacheUtils; import org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition; import org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtPartitionState; import org.apache.ignite.internal.processors.cache.persistence.CacheDataRow; import org.apache.ignite.internal.processors.task.GridInternal; import org.apache.ignite.internal.util.lang.GridIterator; import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.internal.visor.verify.CacheFilterEnum; +import org.apache.ignite.internal.visor.verify.VisorIdleVerifyDumpTaskArg; import org.apache.ignite.internal.visor.verify.VisorIdleVerifyTaskArg; import org.apache.ignite.lang.IgniteProductVersion; import org.apache.ignite.resources.IgniteInstanceResource; @@ -176,7 +182,7 @@ public class VerifyBackupPartitionsTaskV2 extends ComputeTaskAdapter<VisorIdleVe for (String cacheName : arg.getCaches()) { DynamicCacheDescriptor desc = ignite.context().cache().cacheDescriptor(cacheName); - if (desc == null) { + if (desc == null || !isCacheMatchFilter(cacheName)) { missingCaches.add(cacheName); continue; @@ -185,15 +191,13 @@ public class VerifyBackupPartitionsTaskV2 extends ComputeTaskAdapter<VisorIdleVe grpIds.add(desc.groupId()); } - if (!missingCaches.isEmpty()) { - StringBuilder strBuilder = new StringBuilder("The following caches do not exist: "); - - for (String name : missingCaches) - strBuilder.append(name).append(", "); - - strBuilder.delete(strBuilder.length() - 2, strBuilder.length()); - - throw new IgniteException(strBuilder.toString()); + handlingMissedCaches(missingCaches); + } + else if (onlySpecificCaches()) { + for (DynamicCacheDescriptor desc : ignite.context().cache().cacheDescriptors().values()) { + if (desc.cacheConfiguration().getCacheMode() != CacheMode.LOCAL + && isCacheMatchFilter(desc.cacheName())) + grpIds.add(desc.groupId()); } } else { @@ -260,6 +264,79 @@ public class VerifyBackupPartitionsTaskV2 extends ComputeTaskAdapter<VisorIdleVe } /** + * Checks and throw exception if caches was missed. + * + * @param missingCaches Missing caches. + */ + private void handlingMissedCaches(Set<String> missingCaches) { + if (missingCaches.isEmpty()) + return; + + StringBuilder strBuilder = new StringBuilder("The following caches do not exist"); + + if (onlySpecificCaches()) { + VisorIdleVerifyDumpTaskArg vdta = (VisorIdleVerifyDumpTaskArg)arg; + + strBuilder.append(" or do not match to the given filter [") + .append(vdta.getCacheFilterEnum()) + .append("]: "); + } + else + strBuilder.append(": "); + + for (String name : missingCaches) + strBuilder.append(name).append(", "); + + strBuilder.delete(strBuilder.length() - 2, strBuilder.length()); + + throw new IgniteException(strBuilder.toString()); + } + + /** + * @return True if validates only specific caches, else false. + */ + private boolean onlySpecificCaches() { + if (arg instanceof VisorIdleVerifyDumpTaskArg) { + VisorIdleVerifyDumpTaskArg vdta = (VisorIdleVerifyDumpTaskArg)arg; + + return vdta.getCacheFilterEnum() != CacheFilterEnum.ALL; + } + + return false; + } + + /** + * @param cacheName Cache name. + */ + private boolean isCacheMatchFilter(String cacheName) { + if (arg instanceof VisorIdleVerifyDumpTaskArg) { + DataStorageConfiguration dsc = ignite.context().config().getDataStorageConfiguration(); + DynamicCacheDescriptor desc = ignite.context().cache().cacheDescriptor(cacheName); + CacheConfiguration cc = desc.cacheConfiguration(); + VisorIdleVerifyDumpTaskArg vdta = (VisorIdleVerifyDumpTaskArg)arg; + + switch (vdta.getCacheFilterEnum()) { + case SYSTEM: + return !desc.cacheType().userCache(); + + case NOT_PERSISTENT: + return desc.cacheType().userCache() && !GridCacheUtils.isPersistentCache(cc, dsc); + + case PERSISTENT: + return desc.cacheType().userCache() && GridCacheUtils.isPersistentCache(cc, dsc); + + case ALL: + break; + + default: + assert false: "Illegal cache filter: " + vdta.getCacheFilterEnum(); + } + } + + return true; + } + + /** * @param grpCtx Group context. * @param part Local partition. */ http://git-wip-us.apache.org/repos/asf/ignite/blob/9199aac1/modules/core/src/main/java/org/apache/ignite/internal/visor/verify/CacheFilterEnum.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/verify/CacheFilterEnum.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/verify/CacheFilterEnum.java new file mode 100644 index 0000000..4e87d50 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/verify/CacheFilterEnum.java @@ -0,0 +1,52 @@ +/* + * 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.visor.verify; + +import org.jetbrains.annotations.Nullable; + +/** + * Represents a type of cache(s) that can be used for comparing update counters and checksums between primary and backup partitions. + * <br> + * @see org.apache.ignite.internal.processors.cache.verify.VerifyBackupPartitionsTaskV2 + */ +public enum CacheFilterEnum { + /** All. */ + ALL, + + /** System. */ + SYSTEM, + + /** Persistent. */ + PERSISTENT, + + /** Not persistent. */ + NOT_PERSISTENT; + + /** Enumerated values. */ + private static final CacheFilterEnum[] VALS = values(); + + /** + * Efficiently gets enumerated value from its ordinal. + * + * @param ord Ordinal value. + * @return Enumerated value or {@code null} if ordinal out of range. + */ + public static @Nullable CacheFilterEnum fromOrdinal(int ord) { + return ord >= 0 && ord < VALS.length ? VALS[ord] : null; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9199aac1/modules/core/src/main/java/org/apache/ignite/internal/visor/verify/VisorIdleVerifyDumpTaskArg.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/verify/VisorIdleVerifyDumpTaskArg.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/verify/VisorIdleVerifyDumpTaskArg.java index 6316c24..29dfb5b 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/verify/VisorIdleVerifyDumpTaskArg.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/verify/VisorIdleVerifyDumpTaskArg.java @@ -22,6 +22,7 @@ import java.io.ObjectInput; import java.io.ObjectOutput; import java.util.Set; import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; /** * Arguments for {@link VisorIdleVerifyDumpTask}. @@ -29,9 +30,13 @@ import org.apache.ignite.internal.util.typedef.internal.S; public class VisorIdleVerifyDumpTaskArg extends VisorIdleVerifyTaskArg { /** */ private static final long serialVersionUID = 0L; + /** */ private boolean skipZeros; + /** Cache kind. */ + private CacheFilterEnum cacheFilterEnum; + /** * Default constructor. */ @@ -41,10 +46,12 @@ public class VisorIdleVerifyDumpTaskArg extends VisorIdleVerifyTaskArg { /** * @param caches Caches. * @param skipZeros Skip zeros partitions. + * @param cacheFilterEnum Cache kind. */ - public VisorIdleVerifyDumpTaskArg(Set<String> caches, boolean skipZeros) { + public VisorIdleVerifyDumpTaskArg(Set<String> caches, boolean skipZeros, CacheFilterEnum cacheFilterEnum) { super(caches); this.skipZeros = skipZeros; + this.cacheFilterEnum = cacheFilterEnum; } /** @@ -54,16 +61,37 @@ public class VisorIdleVerifyDumpTaskArg extends VisorIdleVerifyTaskArg { return skipZeros; } + /** + * @return Kind fo cache. + */ + public CacheFilterEnum getCacheFilterEnum() { + return cacheFilterEnum; + } + /** {@inheritDoc} */ @Override protected void writeExternalData(ObjectOutput out) throws IOException { super.writeExternalData(out); + out.writeBoolean(skipZeros); + + U.writeEnum(out, cacheFilterEnum); } /** {@inheritDoc} */ @Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException, ClassNotFoundException { super.readExternalData(protoVer, in); + skipZeros = in.readBoolean(); + + if (protoVer >= V2) + cacheFilterEnum = CacheFilterEnum.fromOrdinal(in.readByte()); + else + cacheFilterEnum = CacheFilterEnum.ALL; + } + + /** {@inheritDoc} */ + @Override public byte getProtocolVersion() { + return V2; } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/ignite/blob/9199aac1/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java index 67fee0a..f5fa887 100644 --- a/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java +++ b/modules/core/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java @@ -19,6 +19,7 @@ package org.apache.ignite.util; import java.io.ByteArrayOutputStream; import java.io.File; +import java.io.IOException; import java.io.PrintStream; import java.nio.file.DirectoryStream; import java.nio.file.Files; @@ -48,6 +49,7 @@ import org.apache.ignite.IgniteCache; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction; import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.configuration.AtomicConfiguration; import org.apache.ignite.configuration.CacheConfiguration; import org.apache.ignite.configuration.ConnectorConfiguration; import org.apache.ignite.configuration.DataRegionConfiguration; @@ -64,6 +66,7 @@ import org.apache.ignite.internal.commandline.OutputFormat; import org.apache.ignite.internal.commandline.cache.CacheCommand; import org.apache.ignite.internal.managers.communication.GridIoMessage; import org.apache.ignite.internal.pagemem.wal.record.DataEntry; +import org.apache.ignite.internal.processors.cache.CacheGroupContext; import org.apache.ignite.internal.processors.cache.CacheObjectImpl; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.apache.ignite.internal.processors.cache.GridCacheEntryEx; @@ -79,15 +82,18 @@ import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx import org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry; import org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl; import org.apache.ignite.internal.processors.cache.version.GridCacheVersion; +import org.apache.ignite.internal.processors.datastructures.GridCacheInternalKeyImpl; import org.apache.ignite.internal.util.lang.GridAbsPredicate; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.G; import org.apache.ignite.internal.util.typedef.T2; import org.apache.ignite.internal.util.typedef.X; +import org.apache.ignite.internal.util.typedef.internal.CU; import org.apache.ignite.internal.util.typedef.internal.SB; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.internal.visor.tx.VisorTxInfo; import org.apache.ignite.internal.visor.tx.VisorTxTaskResult; +import org.apache.ignite.internal.visor.verify.CacheFilterEnum; import org.apache.ignite.lang.IgniteBiPredicate; import org.apache.ignite.lang.IgniteInClosure; import org.apache.ignite.lang.IgnitePredicate; @@ -126,6 +132,12 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest { /** Option is used for auto confirmation. */ private static final String CMD_AUTO_CONFIRMATION = "--yes"; + /** Atomic configuration. */ + private AtomicConfiguration atomicConfiguration; + + /** Additional data region configuration. */ + private DataRegionConfiguration dataRegionConfiguration; + /** * @return Folder in work directory. * @throws IgniteCheckedException If failed to resolve folder name. @@ -186,12 +198,19 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest { @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + if (atomicConfiguration != null) + cfg.setAtomicConfiguration(atomicConfiguration); + cfg.setCommunicationSpi(new TestRecordingCommunicationSpi()); cfg.setConnectorConfiguration(new ConnectorConfiguration()); - DataStorageConfiguration memCfg = new DataStorageConfiguration().setDefaultDataRegionConfiguration( - new DataRegionConfiguration().setMaxSize(50L * 1024 * 1024)); + DataStorageConfiguration memCfg = new DataStorageConfiguration() + .setDefaultDataRegionConfiguration(new DataRegionConfiguration() + .setMaxSize(50L * 1024 * 1024)); + + if (dataRegionConfiguration != null) + memCfg.setDataRegionConfigurations(dataRegionConfiguration); cfg.setDataStorageConfiguration(memCfg); @@ -1055,25 +1074,171 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest { .setBackups(1) .setName(DEFAULT_CACHE_NAME)); + for (int i = 0; i < 100; i++) + cache.put(i, i); + + corruptingAndCheckDefaultCache(ignite, parts, CacheFilterEnum.ALL); + } + + /** + * @param ignite Ignite. + * @param parts Parts. + */ + private void corruptingAndCheckDefaultCache(IgniteEx ignite, int parts, CacheFilterEnum cacheFilterEnum) throws IOException { injectTestSystemOut(); + GridCacheContext<Object, Object> cacheCtx = ignite.cachex(DEFAULT_CACHE_NAME).context(); + + corruptDataEntry(cacheCtx, 0, true, false); + + corruptDataEntry(cacheCtx, parts / 2, false, true); + + assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify", "--dump", "--cacheFilter", cacheFilterEnum.toString())); + + Matcher fileNameMatcher = dumpFileNameMatcher(); + + if (fileNameMatcher.find()) { + String dumpWithConflicts = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1)))); + + assertTrue(dumpWithConflicts.contains("found 2 conflict partitions: [counterConflicts=1, hashConflicts=1]")); + } + else + fail("Should be found dump with conflicts"); + } + + /** + * Tests that idle verify print partitions info over system caches. + * + * @throws Exception If failed. + */ + public void testCacheIdleVerifyDumpForCorruptedDataOnSystemCache() throws Exception { + int parts = 32; + + atomicConfiguration = new AtomicConfiguration() + .setAffinity(new RendezvousAffinityFunction(false, parts)) + .setBackups(2); + + IgniteEx ignite = (IgniteEx)startGrids(3); + + ignite.cluster().active(true); + + injectTestSystemOut(); + + // Adding some assignments without deployments. + for (int i = 0; i < 100; i++) { + ignite.semaphore("s" + i, i, false, true); + + ignite.atomicSequence("sq" + i, 0, true) + .incrementAndGet(); + } + + CacheGroupContext storedSysCacheCtx = ignite.context().cache().cacheGroup(CU.cacheId("default-ds-group")); + + assertNotNull(storedSysCacheCtx); + + corruptDataEntry(storedSysCacheCtx.caches().get(0), new GridCacheInternalKeyImpl("sq0", + "default-ds-group"), true, false); + + corruptDataEntry(storedSysCacheCtx.caches().get(0), new GridCacheInternalKeyImpl("sq" + parts / 2, + "default-ds-group"), false, true); + + CacheGroupContext memorySysCacheCtx = ignite.context().cache().cacheGroup(CU.cacheId("default-volatile-ds-group")); + + assertNotNull(memorySysCacheCtx); + + corruptDataEntry(memorySysCacheCtx.caches().get(0), new GridCacheInternalKeyImpl("s0", + "default-volatile-ds-group"), true, false); + + corruptDataEntry(memorySysCacheCtx.caches().get(0), new GridCacheInternalKeyImpl("s" + parts / 2, + "default-volatile-ds-group"), false, true); + + assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify", "--dump", "--cacheFilter", CacheFilterEnum.SYSTEM.toString())); + + Matcher fileNameMatcher = dumpFileNameMatcher(); + + if (fileNameMatcher.find()) { + String dumpWithConflicts = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1)))); + + assertTrue(dumpWithConflicts.contains("found 4 conflict partitions: [counterConflicts=2, " + + "hashConflicts=2]")); + } + else + fail("Should be found dump with conflicts"); + } + + /** + * Tests that idle verify print partitions info over persistence client caches. + * + * @throws Exception If failed. + */ + public void testCacheIdleVerifyDumpForCorruptedDataOnPersistenceClientCache() throws Exception { + int parts = 32; + + dataRegionConfiguration = new DataRegionConfiguration() + .setName("persistence-region") + .setMaxSize(100L * 1024 * 1024) + .setPersistenceEnabled(true); + + IgniteEx ignite = (IgniteEx)startGrids(3); + + ignite.cluster().active(true); + + IgniteCache<Object, Object> cache = ignite.createCache(new CacheConfiguration<>() + .setAffinity(new RendezvousAffinityFunction(false, parts)) + .setBackups(2) + .setName(DEFAULT_CACHE_NAME) + .setDataRegionName("persistence-region")); + + // Adding some assignments without deployments. for (int i = 0; i < 100; i++) cache.put(i, i); + corruptingAndCheckDefaultCache(ignite, parts, CacheFilterEnum.PERSISTENT); + } + + /** + * Tests that idle verify print partitions info over none-persistence client caches. + * + * @throws Exception If failed. + */ + public void testCacheIdleVerifyDumpForCorruptedDataOnNonePersistenceClientCache() throws Exception { + int parts = 32; + + dataRegionConfiguration = new DataRegionConfiguration() + .setName("none-persistence-region"); + + IgniteEx ignite = (IgniteEx)startGrids(3); + + ignite.cluster().active(true); + + IgniteCache<Object, Object> cache = ignite.createCache(new CacheConfiguration<>() + .setAffinity(new RendezvousAffinityFunction(false, parts)) + .setBackups(2) + .setName(DEFAULT_CACHE_NAME) + .setDataRegionName("none-persistence-region")); + + // Adding some assignments without deployments. + for (int i = 0; i < 100; i++) + cache.put(i, i); + + injectTestSystemOut(); + GridCacheContext<Object, Object> cacheCtx = ignite.cachex(DEFAULT_CACHE_NAME).context(); corruptDataEntry(cacheCtx, 0, true, false); - corruptDataEntry(cacheCtx, 0 + parts / 2, false, true); + corruptDataEntry(cacheCtx, parts / 2, false, true); - assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify", "--dump")); + assertEquals(EXIT_CODE_OK, execute("--cache", "idle_verify", "--dump", "--cacheFilter", CacheFilterEnum + .NOT_PERSISTENT.toString())); Matcher fileNameMatcher = dumpFileNameMatcher(); if (fileNameMatcher.find()) { String dumpWithConflicts = new String(Files.readAllBytes(Paths.get(fileNameMatcher.group(1)))); - assertTrue(dumpWithConflicts.contains("found 2 conflict partitions: [counterConflicts=1, hashConflicts=1]")); + assertTrue(dumpWithConflicts.contains("found 1 conflict partitions: [counterConflicts=0, " + + "hashConflicts=1]")); } else fail("Should be found dump with conflicts"); @@ -1629,7 +1794,7 @@ public class GridCommandHandlerTest extends GridCommonAbstractTest { */ private void corruptDataEntry( GridCacheContext<Object, Object> ctx, - int key, + Object key, boolean breakCntr, boolean breakData ) {
