Search in sources :

Example 1 with CachePartialUpdateException

use of org.apache.ignite.cache.CachePartialUpdateException in project ignite by apache.

the class PlatformCache method convertException.

/** {@inheritDoc} */
@Override
public Exception convertException(Exception e) {
    if (e instanceof CachePartialUpdateException)
        return new PlatformCachePartialUpdateException((CachePartialUpdateCheckedException) e.getCause(), platformCtx, keepBinary);
    if (e instanceof CachePartialUpdateCheckedException)
        return new PlatformCachePartialUpdateException((CachePartialUpdateCheckedException) e, platformCtx, keepBinary);
    if (e.getCause() instanceof EntryProcessorException)
        return (Exception) e.getCause();
    TransactionDeadlockException deadlockException = X.cause(e, TransactionDeadlockException.class);
    if (deadlockException != null)
        return deadlockException;
    TransactionTimeoutException timeoutException = X.cause(e, TransactionTimeoutException.class);
    if (timeoutException != null)
        return timeoutException;
    return super.convertException(e);
}
Also used : TransactionDeadlockException(org.apache.ignite.transactions.TransactionDeadlockException) EntryProcessorException(javax.cache.processor.EntryProcessorException) TransactionTimeoutException(org.apache.ignite.transactions.TransactionTimeoutException) CachePartialUpdateException(org.apache.ignite.cache.CachePartialUpdateException) CachePartialUpdateCheckedException(org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException)

Example 2 with CachePartialUpdateException

use of org.apache.ignite.cache.CachePartialUpdateException in project ignite by apache.

the class GridCacheAtomicInvalidPartitionHandlingSelfTest method checkRestarts.

/**
     * @param writeSync Write synchronization mode to check.
     * @throws Exception If failed.
     */
private void checkRestarts(CacheWriteSynchronizationMode writeSync) throws Exception {
    this.writeSync = writeSync;
    final int gridCnt = 6;
    startGrids(gridCnt);
    awaitPartitionMapExchange();
    try {
        assertEquals(testClientNode(), (boolean) grid(0).configuration().isClientMode());
        final IgniteCache<Object, Object> cache = grid(0).cache(DEFAULT_CACHE_NAME);
        final int range = 100_000;
        final Set<Integer> keys = new LinkedHashSet<>();
        try (IgniteDataStreamer<Integer, Integer> streamer = grid(0).dataStreamer(DEFAULT_CACHE_NAME)) {
            streamer.allowOverwrite(true);
            for (int i = 0; i < range; i++) {
                streamer.addData(i, 0);
                keys.add(i);
                if (i > 0 && i % 10_000 == 0)
                    System.err.println("Put: " + i);
            }
        }
        final Affinity<Integer> aff = grid(0).affinity(DEFAULT_CACHE_NAME);
        boolean putDone = GridTestUtils.waitForCondition(new GridAbsPredicate() {

            @Override
            public boolean apply() {
                Iterator<Integer> it = keys.iterator();
                while (it.hasNext()) {
                    Integer key = it.next();
                    Collection<ClusterNode> affNodes = aff.mapKeyToPrimaryAndBackups(key);
                    for (int i = 0; i < gridCnt; i++) {
                        ClusterNode locNode = grid(i).localNode();
                        IgniteCache<Object, Object> cache = grid(i).cache(DEFAULT_CACHE_NAME);
                        Object val = cache.localPeek(key);
                        if (affNodes.contains(locNode)) {
                            if (val == null)
                                return false;
                        } else
                            assertNull(val);
                    }
                    it.remove();
                }
                return true;
            }
        }, 30_000);
        assertTrue(putDone);
        assertTrue(keys.isEmpty());
        final AtomicBoolean done = new AtomicBoolean();
        delay = true;
        System.err.println("FINISHED PUTS");
        // Start put threads.
        IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                Random rnd = new Random();
                while (!done.get()) {
                    try {
                        int cnt = rnd.nextInt(5);
                        if (cnt < 2) {
                            int key = rnd.nextInt(range);
                            int val = rnd.nextInt();
                            cache.put(key, val);
                        } else {
                            Map<Integer, Integer> upd = new TreeMap<>();
                            for (int i = 0; i < cnt; i++) upd.put(rnd.nextInt(range), rnd.nextInt());
                            cache.putAll(upd);
                        }
                    } catch (CachePartialUpdateException ignored) {
                    // No-op.
                    }
                }
                return null;
            }
        }, 4, "putAll-thread");
        Random rnd = new Random();
        // Restart random nodes.
        for (int r = 0; r < 20; r++) {
            int idx0 = rnd.nextInt(gridCnt - 1) + 1;
            stopGrid(idx0);
            U.sleep(200);
            startGrid(idx0);
        }
        done.set(true);
        awaitPartitionMapExchange();
        fut.get();
        for (int k = 0; k < range; k++) {
            Collection<ClusterNode> affNodes = affinity(cache).mapKeyToPrimaryAndBackups(k);
            // Test is valid with at least one backup.
            assert affNodes.size() >= 2;
            Object val = null;
            GridCacheVersion ver = null;
            UUID nodeId = null;
            for (int i = 0; i < gridCnt; i++) {
                ClusterNode locNode = grid(i).localNode();
                GridCacheAdapter<Object, Object> c = ((IgniteKernal) grid(i)).internalCache(DEFAULT_CACHE_NAME);
                GridCacheEntryEx entry = null;
                try {
                    entry = c.entryEx(k);
                    entry.unswap();
                } catch (GridDhtInvalidPartitionException ignored) {
                // Skip key.
                }
                for (int r = 0; r < 10; r++) {
                    try {
                        if (affNodes.contains(locNode)) {
                            assert c.affinity().isPrimaryOrBackup(locNode, k);
                            boolean primary = c.affinity().isPrimary(locNode, k);
                            assertNotNull("Failed to find entry on node for key [locNode=" + locNode.id() + ", key=" + k + ']', entry);
                            if (val == null) {
                                assertNull(ver);
                                val = CU.value(entry.rawGet(), entry.context(), false);
                                ver = entry.version();
                                nodeId = locNode.id();
                            } else {
                                assertNotNull(ver);
                                assertEquals("Failed to check value for key [key=" + k + ", node=" + locNode.id() + ", primary=" + primary + ", recNodeId=" + nodeId + ']', val, CU.value(entry.rawGet(), entry.context(), false));
                                assertEquals("Failed to check version for key [key=" + k + ", node=" + locNode.id() + ", primary=" + primary + ", recNodeId=" + nodeId + ']', ver, entry.version());
                            }
                        } else
                            assertTrue("Invalid entry: " + entry, entry == null || !entry.partitionValid());
                    } catch (AssertionError e) {
                        if (r == 9) {
                            info("Failed to verify cache contents: " + e.getMessage());
                            throw e;
                        }
                        info("Failed to verify cache contents, will retry: " + e.getMessage());
                        // Give some time to finish async updates.
                        U.sleep(1000);
                    }
                }
            }
        }
    } finally {
        stopAllGrids();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) Random(java.util.Random) Iterator(java.util.Iterator) UUID(java.util.UUID) ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteCache(org.apache.ignite.IgniteCache) CachePartialUpdateException(org.apache.ignite.cache.CachePartialUpdateException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) CachePartialUpdateException(org.apache.ignite.cache.CachePartialUpdateException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteException(org.apache.ignite.IgniteException) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtInvalidPartitionException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) Collection(java.util.Collection) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 3 with CachePartialUpdateException

use of org.apache.ignite.cache.CachePartialUpdateException in project ignite by apache.

the class GridCacheUtils method convertToCacheException.

/**
     * @param e Ignite checked exception.
     * @return CacheException runtime exception, never null.
     */
@NotNull
public static RuntimeException convertToCacheException(IgniteCheckedException e) {
    IgniteClientDisconnectedCheckedException disconnectedErr = e.getCause(IgniteClientDisconnectedCheckedException.class);
    if (disconnectedErr != null) {
        assert disconnectedErr.reconnectFuture() != null : disconnectedErr;
        e = disconnectedErr;
    }
    if (e.hasCause(CacheWriterException.class))
        return new CacheWriterException(U.convertExceptionNoWrap(e));
    if (e instanceof CachePartialUpdateCheckedException)
        return new CachePartialUpdateException((CachePartialUpdateCheckedException) e);
    else if (e instanceof CacheAtomicUpdateTimeoutCheckedException)
        return new CacheAtomicUpdateTimeoutException(e.getMessage(), e);
    else if (e instanceof ClusterTopologyServerNotFoundException)
        return new CacheServerNotFoundException(e.getMessage(), e);
    if (e.getCause() instanceof CacheException)
        return (CacheException) e.getCause();
    if (e.getCause() instanceof NullPointerException)
        return (NullPointerException) e.getCause();
    C1<IgniteCheckedException, IgniteException> converter = U.getExceptionConverter(e.getClass());
    return converter != null ? new CacheException(converter.apply(e)) : new CacheException(e);
}
Also used : CacheAtomicUpdateTimeoutException(org.apache.ignite.cache.CacheAtomicUpdateTimeoutException) CacheServerNotFoundException(org.apache.ignite.cache.CacheServerNotFoundException) CacheException(javax.cache.CacheException) CachePartialUpdateException(org.apache.ignite.cache.CachePartialUpdateException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyServerNotFoundException(org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) CacheWriterException(javax.cache.integration.CacheWriterException) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with CachePartialUpdateException

use of org.apache.ignite.cache.CachePartialUpdateException in project ignite by apache.

the class GridCacheIncrementTransformTest method testIncrement.

/**
     * @param restarts Whether test is running with node restarts.
     * @throws Exception If failed.
     */
private void testIncrement(boolean restarts) throws Exception {
    Random rnd = new Random();
    for (int i = 0; i < NUM_ITERS; i++) {
        int idx = -1;
        Ignite ignite = null;
        while (ignite == null) {
            idx = rnd.nextInt(GRID_CNT);
            ignite = restarts ? grids.getAndSet(idx, null) : grid(idx);
        }
        IgniteCache<String, TestObject> cache = ignite.<String, TestObject>cache(DEFAULT_CACHE_NAME).withNoRetries();
        assertNotNull(cache);
        TestObject obj = cache.get("key");
        assertNotNull(obj);
        assertEquals(i, obj.val);
        while (true) {
            try {
                cache.invoke("key", new Processor());
                break;
            } catch (CachePartialUpdateException ignored) {
                // Need to re-check if update actually succeeded.
                TestObject updated = cache.get("key");
                if (updated != null && updated.val == i + 1)
                    break;
            }
        }
        if (restarts)
            assert grids.compareAndSet(idx, null, ignite);
    }
}
Also used : EntryProcessor(javax.cache.processor.EntryProcessor) Random(java.util.Random) CachePartialUpdateException(org.apache.ignite.cache.CachePartialUpdateException) Ignite(org.apache.ignite.Ignite)

Aggregations

CachePartialUpdateException (org.apache.ignite.cache.CachePartialUpdateException)4 Random (java.util.Random)2 IgniteException (org.apache.ignite.IgniteException)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 LinkedHashSet (java.util.LinkedHashSet)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 UUID (java.util.UUID)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 CacheException (javax.cache.CacheException)1 CacheWriterException (javax.cache.integration.CacheWriterException)1 EntryProcessor (javax.cache.processor.EntryProcessor)1 EntryProcessorException (javax.cache.processor.EntryProcessorException)1 Ignite (org.apache.ignite.Ignite)1 IgniteCache (org.apache.ignite.IgniteCache)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 CacheAtomicUpdateTimeoutException (org.apache.ignite.cache.CacheAtomicUpdateTimeoutException)1 CacheServerNotFoundException (org.apache.ignite.cache.CacheServerNotFoundException)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1