Search in sources :

Example 46 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.

the class IgniteCheckpointDirtyPagesForLowLoadTest method testManyCachesAndNotManyPuts.

/**
 * @throws Exception if failed.
 */
@Test
public void testManyCachesAndNotManyPuts() throws Exception {
    try {
        IgniteEx ignite = startGrid(0);
        ignite.active(true);
        log.info("Saving initial data to caches");
        for (int g = 0; g < GROUPS; g++) {
            for (int c = 0; c < CACHES_IN_GRP; c++) {
                TreeMap<Long, Long> data = new TreeMap<>();
                for (int j = 0; j < PARTS; j++) {
                    // to fill each partition cache with at least 1 element
                    data.put((long) j, (long) j);
                }
                ignite.cache("dummyCache" + c + "." + g).putAll(data);
            }
        }
        GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager) (ignite.context().cache().context().database());
        Collection<Integer> pageCntObserved = new ArrayList<>();
        boolean checkpointWithLowNumOfPagesFound = false;
        for (int i = 0; i < 20; i++) {
            Random random = new Random();
            // touch some entry
            int d = random.nextInt(PARTS) + PARTS;
            int cIdx = random.nextInt(CACHES_IN_GRP);
            int gIdx = random.nextInt(GROUPS);
            String fullname = "dummyCache" + cIdx + "." + gIdx;
            ignite.cache(fullname).put(d, d);
            if (log.isInfoEnabled())
                log.info("Put to cache [" + fullname + "] value " + d);
            long start = System.nanoTime();
            try {
                final int cpTimeout = 25000;
                db.wakeupForCheckpoint("").get(cpTimeout, TimeUnit.MILLISECONDS);
            } catch (IgniteFutureTimeoutCheckedException ignored) {
                long msPassed = U.millisSinceNanos(start);
                log.error("Timeout during waiting for checkpoint to start:" + " [" + msPassed + "] but checkpoint is not running");
                continue;
            }
            final int timeout = 5000;
            int currCpPages = waitForCurrentCheckpointPagesCounterUpdated(db, timeout);
            if (currCpPages < 0) {
                log.error("Timeout during waiting for checkpoint counter to be updated");
                continue;
            }
            pageCntObserved.add(currCpPages);
            log.info("Current CP pages: " + currCpPages);
            if (currCpPages < PARTS * GROUPS) {
                // reasonable number of pages in CP
                checkpointWithLowNumOfPagesFound = true;
                break;
            }
        }
        stopGrid(0);
        assertTrue("All checkpoints mark too much pages: " + pageCntObserved, checkpointWithLowNumOfPagesFound);
    } finally {
        stopAllGrids();
    }
}
Also used : GridCacheDatabaseSharedManager(org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Random(java.util.Random) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 47 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.

the class TxPartitionCounterStateConsistencyTest method testPartitionConsistencyCancelledRebalanceCoordinatorIsDemander.

/**
 * Tests reproduces the problem: if coordinator is a demander after activation and supplier has left, new
 * rebalance will finish and cause no partition inconsistencies.
 *
 * @throws Exception If failed.
 */
@Test
public void testPartitionConsistencyCancelledRebalanceCoordinatorIsDemander() throws Exception {
    backups = 2;
    Ignite crd = startGrids(SERVER_NODES);
    crd.cluster().active(true);
    int[] primaryParts = crd.affinity(DEFAULT_CACHE_NAME).primaryPartitions(crd.cluster().localNode());
    IgniteCache<Object, Object> cache = crd.cache(DEFAULT_CACHE_NAME);
    List<Integer> p1Keys = partitionKeys(cache, primaryParts[0], 2, 0);
    assertTrue(crd.affinity(DEFAULT_CACHE_NAME).isPrimary(crd.cluster().localNode(), p1Keys.get(0)));
    final String primName = crd.name();
    cache.put(p1Keys.get(0), 0);
    cache.put(p1Keys.get(1), 1);
    forceCheckpoint();
    List<Ignite> backups = Arrays.asList(grid(1), grid(2));
    assertFalse(backups.contains(crd));
    final String demanderName = backups.get(0).name();
    stopGrid(true, demanderName);
    // Create counters delta.
    cache.remove(p1Keys.get(1));
    stopAllGrids();
    crd = startNodeWithBlockingSupplying(0);
    startGrid(1);
    startNodeWithBlockingSupplying(2);
    crd.cluster().active(true);
    TestRecordingCommunicationSpi spi0 = TestRecordingCommunicationSpi.spi(crd);
    TestRecordingCommunicationSpi spi2 = TestRecordingCommunicationSpi.spi(ignite(2));
    IgniteInternalFuture fut = GridTestUtils.runAsync(() -> {
        try {
            GridTestUtils.waitForCondition(() -> spi0.hasBlockedMessages() || spi2.hasBlockedMessages(), 10_000);
            // Stop before supplying rebalance. New rebalance must start with second backup as supplier
            // doing full rebalance.
            stopGrid(primName);
            spi2.stopBlock();
        } catch (Exception e) {
            fail();
        }
    });
    try {
        fut.get(10_000);
    } catch (IgniteFutureTimeoutCheckedException e) {
        for (Ignite ignite : G.allGrids()) {
            final PartitionUpdateCounter cntr = counter(primaryParts[0], ignite.name());
            log.info("Node: " + ignite.name() + ", cntr=" + cntr);
        }
        assertPartitionsSame(idleVerify(crd, DEFAULT_CACHE_NAME));
        fail("Rebalancing is expected");
    }
    awaitPartitionMapExchange();
    assertPartitionsSame(idleVerify(grid(demanderName), DEFAULT_CACHE_NAME));
}
Also used : PartitionUpdateCounter(org.apache.ignite.internal.processors.cache.PartitionUpdateCounter) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) CacheInvalidStateException(org.apache.ignite.internal.processors.cache.CacheInvalidStateException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) TransactionRollbackException(org.apache.ignite.transactions.TransactionRollbackException) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) Ignite(org.apache.ignite.Ignite) Test(org.junit.Test)

Example 48 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.

the class GridServiceDeploymentCompoundFutureSelfTest method testWaitForCompletionOnFailingFuture.

/**
 * @throws Exception If failed.
 */
@Test
public void testWaitForCompletionOnFailingFuture() throws Exception {
    GridServiceDeploymentCompoundFuture<IgniteUuid> compFut = new GridServiceDeploymentCompoundFuture<>();
    int failingFutsNum = 2;
    int completingFutsNum = 5;
    Collection<GridServiceDeploymentFuture> failingFuts = new ArrayList<>(completingFutsNum);
    for (int i = 0; i < failingFutsNum; i++) {
        ServiceConfiguration failingCfg = config("Failed-" + i);
        GridServiceDeploymentFuture<IgniteUuid> failingFut = new GridServiceDeploymentFuture<>(failingCfg, IgniteUuid.randomUuid());
        failingFuts.add(failingFut);
        compFut.add(failingFut);
    }
    List<GridFutureAdapter<Object>> futs = new ArrayList<>(completingFutsNum);
    for (int i = 0; i < completingFutsNum; i++) {
        GridServiceDeploymentFuture<IgniteUuid> fut = new GridServiceDeploymentFuture<>(config(String.valueOf(i)), IgniteUuid.randomUuid());
        futs.add(fut);
        compFut.add(fut);
    }
    compFut.markInitialized();
    List<Exception> causes = new ArrayList<>();
    for (GridServiceDeploymentFuture fut : failingFuts) {
        Exception cause = new Exception("Test error");
        causes.add(cause);
        fut.onDone(cause);
    }
    try {
        compFut.get(100);
        fail("Should never reach here.");
    } catch (IgniteFutureTimeoutCheckedException e) {
        log.info("Expected exception: " + e.getMessage());
    }
    for (GridFutureAdapter<Object> fut : futs) fut.onDone();
    try {
        compFut.get();
        fail("Should never reach here.");
    } catch (IgniteCheckedException ce) {
        log.info("Expected exception: " + ce.getMessage());
        IgniteException e = U.convertException(ce);
        assertTrue(e instanceof ServiceDeploymentException);
        Throwable[] supErrs = e.getSuppressed();
        assertEquals(failingFutsNum, supErrs.length);
        for (int i = 0; i < failingFutsNum; i++) assertEquals(causes.get(i), supErrs[i].getCause());
    }
}
Also used : ArrayList(java.util.ArrayList) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) ServiceDeploymentException(org.apache.ignite.services.ServiceDeploymentException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ServiceConfiguration(org.apache.ignite.services.ServiceConfiguration) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteException(org.apache.ignite.IgniteException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 49 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.

the class GridFutureAdapterSelfTest method checkChaining.

/**
 * @param exec Executor for chain callback.
 * @throws Exception If failed.
 */
@SuppressWarnings("ErrorNotRethrown")
private void checkChaining(ExecutorService exec) throws Exception {
    final CX1<IgniteInternalFuture<Object>, Object> passThrough = new CX1<IgniteInternalFuture<Object>, Object>() {

        @Override
        public Object applyx(IgniteInternalFuture<Object> f) throws IgniteCheckedException {
            return f.get();
        }
    };
    GridFutureAdapter<Object> fut = new GridFutureAdapter<>();
    IgniteInternalFuture<Object> chain = exec != null ? fut.chain(passThrough, exec) : fut.chain(passThrough);
    assertFalse(fut.isDone());
    assertFalse(chain.isDone());
    try {
        chain.get(20);
        fail("Expects timeout exception.");
    } catch (IgniteFutureTimeoutCheckedException e) {
        info("Expected timeout exception: " + e.getMessage());
    }
    fut.onDone("result");
    assertEquals("result", exec == null ? chain.get(1) : chain.get());
    // Test exception re-thrown.
    fut = new GridFutureAdapter<>();
    chain = exec != null ? fut.chain(passThrough, exec) : fut.chain(passThrough);
    fut.onDone(new ClusterGroupEmptyCheckedException("test exception"));
    try {
        chain.get();
        fail("Expects failed with exception.");
    } catch (ClusterGroupEmptyCheckedException e) {
        info("Expected exception: " + e.getMessage());
    }
    // Test error re-thrown.
    fut = new GridFutureAdapter<>();
    chain = exec != null ? fut.chain(passThrough, exec) : fut.chain(passThrough);
    try {
        fut.onDone(new StackOverflowError("test error"));
        if (exec == null)
            fail("Expects failed with error.");
    } catch (StackOverflowError e) {
        info("Expected error: " + e.getMessage());
    }
    try {
        chain.get();
        fail("Expects failed with error.");
    } catch (StackOverflowError e) {
        info("Expected error: " + e.getMessage());
    }
}
Also used : ClusterGroupEmptyCheckedException(org.apache.ignite.internal.cluster.ClusterGroupEmptyCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) CX1(org.apache.ignite.internal.util.typedef.CX1)

Example 50 with IgniteFutureTimeoutCheckedException

use of org.apache.ignite.internal.IgniteFutureTimeoutCheckedException in project ignite by apache.

the class CacheObjectBinaryProcessorImpl method metadata.

/**
 * {@inheritDoc}
 */
@Nullable
@Override
public BinaryType metadata(final int typeId, final int schemaId) {
    BinaryMetadataHolder holder = metadataLocCache.get(typeId);
    if (ctx.clientNode()) {
        if (holder == null || !holder.metadata().hasSchema(schemaId)) {
            if (log.isDebugEnabled())
                log.debug("Waiting for client metadata update" + " [typeId=" + typeId + ", schemaId=" + schemaId + ", pendingVer=" + (holder == null ? "NA" : holder.pendingVersion()) + ", acceptedVer=" + (holder == null ? "NA" : holder.acceptedVersion()) + ']');
            try {
                transport.requestUpToDateMetadata(typeId).get();
            } catch (IgniteCheckedException ignored) {
            // No-op.
            }
            holder = metadataLocCache.get(typeId);
            IgniteFuture<?> reconnectFut0 = reconnectFut;
            if (holder == null && reconnectFut0 != null)
                throw new IgniteClientDisconnectedException(reconnectFut0, "Client node disconnected.");
            if (log.isDebugEnabled())
                log.debug("Finished waiting for client metadata update" + " [typeId=" + typeId + ", schemaId=" + schemaId + ", pendingVer=" + (holder == null ? "NA" : holder.pendingVersion()) + ", acceptedVer=" + (holder == null ? "NA" : holder.acceptedVersion()) + ']');
        }
    } else {
        if (holder != null && IgniteThread.current() instanceof IgniteDiscoveryThread)
            return holder.metadata().wrap(binaryCtx);
        else if (holder != null && (holder.pendingVersion() - holder.acceptedVersion() > 0)) {
            if (log.isDebugEnabled())
                log.debug("Waiting for metadata update" + " [typeId=" + typeId + ", schemaId=" + schemaId + ", pendingVer=" + holder.pendingVersion() + ", acceptedVer=" + holder.acceptedVersion() + ']');
            long t0 = System.nanoTime();
            GridFutureAdapter<MetadataUpdateResult> fut = transport.awaitMetadataUpdate(typeId, holder.pendingVersion());
            try {
                fut.get();
            } catch (IgniteCheckedException e) {
                log.error("Failed to wait for metadata update [typeId=" + typeId + ", schemaId=" + schemaId + ']', e);
            }
            if (log.isDebugEnabled())
                log.debug("Finished waiting for metadata update" + " [typeId=" + typeId + ", waitTime=" + NANOSECONDS.convert(System.nanoTime() - t0, MILLISECONDS) + "ms" + ", schemaId=" + schemaId + ", pendingVer=" + holder.pendingVersion() + ", acceptedVer=" + holder.acceptedVersion() + ']');
            holder = metadataLocCache.get(typeId);
        } else if (holder == null || !holder.metadata().hasSchema(schemaId)) {
            // Last resort waiting.
            U.warn(log, "Schema is missing while no metadata updates are in progress " + "(will wait for schema update within timeout defined by " + IGNITE_WAIT_SCHEMA_UPDATE + " system property)" + " [typeId=" + typeId + ", missingSchemaId=" + schemaId + ", pendingVer=" + (holder == null ? "NA" : holder.pendingVersion()) + ", acceptedVer=" + (holder == null ? "NA" : holder.acceptedVersion()) + ", binMetaUpdateTimeout=" + waitSchemaTimeout + ']');
            long t0 = System.nanoTime();
            GridFutureAdapter<?> fut = transport.awaitSchemaUpdate(typeId, schemaId);
            try {
                fut.get(waitSchemaTimeout);
            } catch (IgniteFutureTimeoutCheckedException e) {
                log.error("Timed out while waiting for schema update [typeId=" + typeId + ", schemaId=" + schemaId + ']');
            } catch (IgniteCheckedException ignored) {
            // No-op.
            }
            holder = metadataLocCache.get(typeId);
            if (log.isDebugEnabled() && holder != null && holder.metadata().hasSchema(schemaId))
                log.debug("Found the schema after wait" + " [typeId=" + typeId + ", waitTime=" + NANOSECONDS.convert(System.nanoTime() - t0, MILLISECONDS) + "ms" + ", schemaId=" + schemaId + ", pendingVer=" + holder.pendingVersion() + ", acceptedVer=" + holder.acceptedVersion() + ']');
        }
    }
    if (holder != null && metadataFileStore != null) {
        try {
            metadataFileStore.waitForWriteCompletion(typeId, holder.pendingVersion());
        } catch (IgniteCheckedException e) {
            log.warning("Failed to wait for metadata write operation for [typeId=" + typeId + ", typeVer=" + holder.acceptedVersion() + ']', e);
            return null;
        }
    }
    return holder != null ? holder.metadata().wrap(binaryCtx) : null;
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) IgniteDiscoveryThread(org.apache.ignite.spi.discovery.IgniteDiscoveryThread) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)74 Test (org.junit.Test)38 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)34 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)31 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)29 Ignite (org.apache.ignite.Ignite)18 IgniteEx (org.apache.ignite.internal.IgniteEx)17 IgniteException (org.apache.ignite.IgniteException)16 ArrayList (java.util.ArrayList)14 Transaction (org.apache.ignite.transactions.Transaction)14 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)12 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 Map (java.util.Map)10 CacheException (javax.cache.CacheException)10 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)10 CountDownLatch (java.util.concurrent.CountDownLatch)8 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)8 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)7