Search in sources :

Example 11 with IdleVerifyResultV2

use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.

the class IgniteClusterSnapshotCheckWithIndexesTest method testClusterSnapshotCheckWithIndexes.

/**
 * @throws Exception If fails.
 */
@Test
public void testClusterSnapshotCheckWithIndexes() throws Exception {
    IgniteEx ignite = startGridsWithCache(3, CACHE_KEYS_RANGE, key -> new Account(key, key), txFilteredCache("indexed"));
    ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get(TIMEOUT);
    IdleVerifyResultV2 res = ignite.context().cache().context().snapshotMgr().checkSnapshot(SNAPSHOT_NAME).get();
    StringBuilder b = new StringBuilder();
    res.print(b::append, true);
    assertTrue("Exceptions: " + b, F.isEmpty(res.exceptions()));
    assertContains(log, b.toString(), "The check procedure has finished, no conflicts have been found.");
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) Test(org.junit.Test)

Example 12 with IdleVerifyResultV2

use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.

the class IgniteClusterSnapshotCheckWithIndexesTest method testClusterSnapshotCheckEmptyCache.

/**
 * @throws Exception If fails.
 */
@Test
public void testClusterSnapshotCheckEmptyCache() throws Exception {
    IgniteEx ignite = startGridsWithCache(3, 0, key -> new Account(key, key), txFilteredCache("indexed"));
    ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get(TIMEOUT);
    IdleVerifyResultV2 res = ignite.context().cache().context().snapshotMgr().checkSnapshot(SNAPSHOT_NAME).get();
    StringBuilder b = new StringBuilder();
    res.print(b::append, true);
    assertTrue("Exceptions: " + b, F.isEmpty(res.exceptions()));
    assertTrue(F.isEmpty(res.exceptions()));
}
Also used : IgniteEx(org.apache.ignite.internal.IgniteEx) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) Test(org.junit.Test)

Example 13 with IdleVerifyResultV2

use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.

the class TxRollbackOnTimeoutOnePhaseCommitTest method doTestRollbackOnTimeoutPartitionDesync.

/**
 */
private void doTestRollbackOnTimeoutPartitionDesync(TransactionConcurrency concurrency) throws Exception {
    IgniteEx client = grid("client");
    assertNotNull(client.cache(DEFAULT_CACHE_NAME));
    int key = 0;
    Ignite primary = primaryNode(key, DEFAULT_CACHE_NAME);
    Ignite backup = backupNode(key, DEFAULT_CACHE_NAME);
    TestRecordingCommunicationSpi backupSpi = TestRecordingCommunicationSpi.spi(backup);
    backupSpi.blockMessages(GridDhtTxPrepareResponse.class, primary.name());
    IgniteInternalFuture fut = runAsync(() -> {
        try {
            backupSpi.waitForBlocked(1, 5000);
        } catch (InterruptedException e) {
            fail();
        }
        doSleep(500);
        backupSpi.stopBlock();
    });
    try (Transaction tx = client.transactions().txStart(concurrency, REPEATABLE_READ, 500, 1)) {
        client.cache(DEFAULT_CACHE_NAME).put(key, key);
        tx.commit();
    } catch (Exception e) {
        assertTrue(e.getClass().getName(), X.hasCause(e, TransactionTimeoutException.class));
    }
    fut.get();
    IdleVerifyResultV2 res = idleVerify(client, DEFAULT_CACHE_NAME);
    assertPartitionsSame(res);
    checkFutures();
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) Transaction(org.apache.ignite.transactions.Transaction) IgniteEx(org.apache.ignite.internal.IgniteEx) Ignite(org.apache.ignite.Ignite) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException)

Example 14 with IdleVerifyResultV2

use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.

the class IgniteSnapshotManager method checkSnapshot.

/**
 * The check snapshot procedure performs compute operation over the whole cluster to verify the snapshot
 * entirety and partitions consistency. The result future will be completed with an exception if this
 * exception is not related to the check procedure, and will be completed normally with the {@code IdleVerifyResult}.
 *
 * @param name Snapshot name.
 * @param grps Collection of cache group names to check.
 * @param includeCustomHandlers {@code True} to invoke all user-defined {@link SnapshotHandlerType#RESTORE}
 *                              handlers, otherwise only system consistency check will be performed.
 * @return Future with the result of execution snapshot partitions verify task, which besides calculating partition
 *         hashes of {@link IdleVerifyResultV2} also contains the snapshot metadata distribution across the cluster.
 */
public IgniteInternalFuture<SnapshotPartitionsVerifyTaskResult> checkSnapshot(String name, @Nullable Collection<String> grps, boolean includeCustomHandlers) {
    A.notNullOrEmpty(name, "Snapshot name cannot be null or empty.");
    A.ensure(U.alphanumericUnderscore(name), "Snapshot name must satisfy the following name pattern: a-zA-Z0-9_");
    A.ensure(grps == null || grps.stream().filter(Objects::isNull).collect(Collectors.toSet()).isEmpty(), "Collection of cache groups names cannot contain null elements.");
    GridFutureAdapter<SnapshotPartitionsVerifyTaskResult> res = new GridFutureAdapter<>();
    GridKernalContext kctx0 = cctx.kernalContext();
    Collection<ClusterNode> bltNodes = F.view(cctx.discovery().serverNodes(AffinityTopologyVersion.NONE), (node) -> CU.baselineNode(node, kctx0.state().clusterState()));
    kctx0.task().setThreadContext(TC_SKIP_AUTH, true);
    kctx0.task().setThreadContext(TC_SUBGRID, bltNodes);
    kctx0.task().execute(SnapshotMetadataCollectorTask.class, name).listen(f0 -> {
        if (f0.error() == null) {
            Map<ClusterNode, List<SnapshotMetadata>> metas = f0.result();
            Map<Integer, String> grpIds = grps == null ? Collections.emptyMap() : grps.stream().collect(Collectors.toMap(CU::cacheId, v -> v));
            for (List<SnapshotMetadata> nodeMetas : metas.values()) {
                for (SnapshotMetadata meta : nodeMetas) grpIds.keySet().removeAll(meta.partitions().keySet());
            }
            if (!grpIds.isEmpty()) {
                res.onDone(new SnapshotPartitionsVerifyTaskResult(metas, new IdleVerifyResultV2(Collections.singletonMap(cctx.localNode(), new IllegalArgumentException("Cache group(s) was not " + "found in the snapshot [groups=" + grpIds.values() + ", snapshot=" + name + ']')))));
                return;
            }
            kctx0.task().setThreadContext(TC_SKIP_AUTH, true);
            kctx0.task().setThreadContext(TC_SUBGRID, new ArrayList<>(metas.keySet()));
            Class<? extends AbstractSnapshotVerificationTask> cls = includeCustomHandlers ? SnapshotHandlerRestoreTask.class : SnapshotPartitionsVerifyTask.class;
            kctx0.task().execute(cls, new SnapshotPartitionsVerifyTaskArg(grps, metas)).listen(f1 -> {
                if (f1.error() == null)
                    res.onDone(f1.result());
                else if (f1.error() instanceof IgniteSnapshotVerifyException)
                    res.onDone(new SnapshotPartitionsVerifyTaskResult(metas, new IdleVerifyResultV2(((IgniteSnapshotVerifyException) f1.error()).exceptions())));
                else
                    res.onDone(f1.error());
            });
        } else {
            if (f0.error() instanceof IgniteSnapshotVerifyException)
                res.onDone(new SnapshotPartitionsVerifyTaskResult(null, new IdleVerifyResultV2(((IgniteSnapshotVerifyException) f0.error()).exceptions())));
            else
                res.onDone(f0.error());
        }
    });
    return res;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) StandaloneGridKernalContext(org.apache.ignite.internal.processors.cache.persistence.wal.reader.StandaloneGridKernalContext) GridKernalContext(org.apache.ignite.internal.GridKernalContext) PageIdUtils.toDetailString(org.apache.ignite.internal.pagemem.PageIdUtils.toDetailString) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CU(org.apache.ignite.internal.util.typedef.internal.CU) Objects(java.util.Objects) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) List(java.util.List) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2)

Example 15 with IdleVerifyResultV2

use of org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2 in project ignite by apache.

the class IgniteClusterSnapshotCheckTest method testClusterSnapshotCheckHashesSameAsIdleVerifyHashes.

/**
 * @throws Exception If fails.
 */
@Test
public void testClusterSnapshotCheckHashesSameAsIdleVerifyHashes() throws Exception {
    Random rnd = new Random();
    CacheConfiguration<Integer, Value> ccfg = txCacheConfig(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
    IgniteEx ignite = startGridsWithCache(1, CACHE_KEYS_RANGE, k -> new Value(new byte[rnd.nextInt(32768)]), ccfg);
    ignite.snapshot().createSnapshot(SNAPSHOT_NAME).get();
    IdleVerifyResultV2 idleVerifyRes = ignite.compute().execute(new TestVisorBackupPartitionsTask(), new VisorIdleVerifyTaskArg(new HashSet<>(singletonList(ccfg.getName())), new HashSet<>(), false, CacheFilterEnum.USER, true));
    IdleVerifyResultV2 snpVerifyRes = ignite.compute().execute(new TestSnapshotPartitionsVerifyTask(), new SnapshotPartitionsVerifyTaskArg(new HashSet<>(), Collections.singletonMap(ignite.cluster().localNode(), Collections.singletonList(snp(ignite).readSnapshotMetadata(SNAPSHOT_NAME, (String) ignite.configuration().getConsistentId()))))).idleVerifyResult();
    Map<PartitionKeyV2, List<PartitionHashRecordV2>> idleVerifyHashes = jobResults.get(TestVisorBackupPartitionsTask.class);
    Map<PartitionKeyV2, List<PartitionHashRecordV2>> snpCheckHashes = jobResults.get(TestVisorBackupPartitionsTask.class);
    assertFalse(F.isEmpty(idleVerifyHashes));
    assertFalse(F.isEmpty(snpCheckHashes));
    assertEquals(idleVerifyHashes, snpCheckHashes);
    assertEquals(idleVerifyRes, snpVerifyRes);
}
Also used : VisorIdleVerifyTaskArg(org.apache.ignite.internal.visor.verify.VisorIdleVerifyTaskArg) Random(java.util.Random) PartitionKeyV2(org.apache.ignite.internal.processors.cache.verify.PartitionKeyV2) IgniteEx(org.apache.ignite.internal.IgniteEx) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) ArrayList(java.util.ArrayList) IdleVerifyResultV2(org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

IdleVerifyResultV2 (org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2)21 IgniteEx (org.apache.ignite.internal.IgniteEx)17 Test (org.junit.Test)16 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 IOException (java.io.IOException)5 Path (java.nio.file.Path)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 IgniteException (org.apache.ignite.IgniteException)5 IgniteSnapshotManager.databaseRelativePath (org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.databaseRelativePath)5 File (java.io.File)4 Random (java.util.Random)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 RendezvousAffinityFunction (org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 IgniteDataIntegrityViolationException (org.apache.ignite.internal.processors.cache.persistence.wal.crc.IgniteDataIntegrityViolationException)4 PartitionKeyV2 (org.apache.ignite.internal.processors.cache.verify.PartitionKeyV2)4 VisorIdleVerifyTaskArg (org.apache.ignite.internal.visor.verify.VisorIdleVerifyTaskArg)4 Collections.singletonList (java.util.Collections.singletonList)3 HashSet (java.util.HashSet)3