Search in sources :

Example 96 with CacheException

use of javax.cache.CacheException in project ignite by apache.

the class IgniteCacheProxy method query.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public <R> QueryCursor<R> query(Query<R> qry) {
    A.notNull(qry, "qry");
    GridCacheGateway<K, V> gate = this.gate;
    CacheOperationContext prev = onEnter(gate, opCtx);
    try {
        ctx.checkSecurity(SecurityPermission.CACHE_READ);
        validate(qry);
        convertToBinary(qry);
        CacheOperationContext opCtxCall = ctx.operationContextPerCall();
        boolean keepBinary = opCtxCall != null && opCtxCall.isKeepBinary();
        if (qry instanceof ContinuousQuery)
            return (QueryCursor<R>) queryContinuous((ContinuousQuery<K, V>) qry, qry.isLocal(), keepBinary);
        if (qry instanceof SqlQuery)
            return (QueryCursor<R>) ctx.kernalContext().query().querySql(ctx, (SqlQuery) qry, keepBinary);
        if (qry instanceof SqlFieldsQuery)
            return (FieldsQueryCursor<R>) ctx.kernalContext().query().querySqlFields(ctx, (SqlFieldsQuery) qry, keepBinary);
        if (qry instanceof ScanQuery)
            return query((ScanQuery) qry, null, projection(qry.isLocal()));
        return (QueryCursor<R>) query(qry, projection(qry.isLocal()));
    } catch (Exception e) {
        if (e instanceof CacheException)
            throw (CacheException) e;
        throw new CacheException(e);
    } finally {
        onLeave(gate, prev);
    }
}
Also used : SqlQuery(org.apache.ignite.cache.query.SqlQuery) CacheException(javax.cache.CacheException) ScanQuery(org.apache.ignite.cache.query.ScanQuery) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) ContinuousQuery(org.apache.ignite.cache.query.ContinuousQuery) QueryCursor(org.apache.ignite.cache.query.QueryCursor) FieldsQueryCursor(org.apache.ignite.cache.query.FieldsQueryCursor)

Example 97 with CacheException

use of javax.cache.CacheException 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 98 with CacheException

use of javax.cache.CacheException in project ignite by apache.

the class IgniteCacheProxy method query.

/** {@inheritDoc} */
@Override
public <T, R> QueryCursor<R> query(Query<T> qry, IgniteClosure<T, R> transformer) {
    A.notNull(qry, "qry");
    A.notNull(transformer, "transformer");
    if (!(qry instanceof ScanQuery))
        throw new UnsupportedOperationException("Transformers are supported only for SCAN queries.");
    GridCacheGateway<K, V> gate = this.gate;
    CacheOperationContext prev = onEnter(gate, opCtx);
    try {
        ctx.checkSecurity(SecurityPermission.CACHE_READ);
        validate(qry);
        return query((ScanQuery<K, V>) qry, transformer, projection(qry.isLocal()));
    } catch (Exception e) {
        if (e instanceof CacheException)
            throw (CacheException) e;
        throw new CacheException(e);
    } finally {
        onLeave(gate, prev);
    }
}
Also used : CacheException(javax.cache.CacheException) ScanQuery(org.apache.ignite.cache.query.ScanQuery) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException)

Example 99 with CacheException

use of javax.cache.CacheException in project ignite by apache.

the class CacheObjectBinaryProcessorImpl method metadata.

/** {@inheritDoc} */
@Override
public Map<Integer, BinaryType> metadata(Collection<Integer> typeIds) throws BinaryObjectException {
    try {
        Collection<BinaryMetadataKey> keys = new ArrayList<>(typeIds.size());
        for (Integer typeId : typeIds) keys.add(new BinaryMetadataKey(typeId));
        Map<Integer, BinaryType> res = U.newHashMap(metadataLocCache.size());
        for (Map.Entry<Integer, BinaryMetadataHolder> e : metadataLocCache.entrySet()) res.put(e.getKey(), e.getValue().metadata().wrap(binaryCtx));
        return res;
    } catch (CacheException e) {
        throw new BinaryObjectException(e);
    }
}
Also used : BinaryType(org.apache.ignite.binary.BinaryType) CacheException(javax.cache.CacheException) ArrayList(java.util.ArrayList) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 100 with CacheException

use of javax.cache.CacheException in project ignite by apache.

the class IgniteClientReconnectMassiveShutdownTest method massiveServersShutdown.

/**
     * @param stopType How tp stop node.
     * @throws Exception If any error occurs.
     */
private void massiveServersShutdown(final StopType stopType) throws Exception {
    clientMode = false;
    startGridsMultiThreaded(GRID_CNT);
    clientMode = true;
    startGridsMultiThreaded(GRID_CNT, CLIENT_GRID_CNT);
    final AtomicBoolean done = new AtomicBoolean();
    // Starting a cache dynamically.
    Ignite client = grid(GRID_CNT);
    assertTrue(client.configuration().isClientMode());
    final CacheConfiguration<String, Integer> cfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
    cfg.setCacheMode(PARTITIONED);
    cfg.setAtomicityMode(TRANSACTIONAL);
    cfg.setBackups(2);
    IgniteCache<String, Integer> cache = client.getOrCreateCache(cfg);
    assertNotNull(cache);
    HashMap<String, Integer> put = new HashMap<>();
    // Load some data.
    for (int i = 0; i < 10_000; i++) put.put(String.valueOf(i), i);
    cache.putAll(put);
    // Preparing client nodes and starting cache operations from them.
    final BlockingQueue<Integer> clientIdx = new LinkedBlockingQueue<>();
    for (int i = GRID_CNT; i < GRID_CNT + CLIENT_GRID_CNT; i++) clientIdx.add(i);
    final CountDownLatch latch = new CountDownLatch(CLIENT_GRID_CNT);
    IgniteInternalFuture<?> clientsFut = multithreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                int idx = clientIdx.take();
                Ignite ignite = grid(idx);
                Thread.currentThread().setName("client-thread-" + ignite.name());
                assertTrue(ignite.configuration().isClientMode());
                IgniteCache<String, Integer> cache = ignite.getOrCreateCache(cfg);
                assertNotNull(cache);
                IgniteTransactions txs = ignite.transactions();
                Random rand = new Random();
                latch.countDown();
                while (!done.get()) {
                    try (Transaction tx = txs.txStart(PESSIMISTIC, REPEATABLE_READ)) {
                        cache.put(String.valueOf(rand.nextInt(10_000)), rand.nextInt(50_000));
                        tx.commit();
                    } catch (ClusterTopologyException ex) {
                        ex.retryReadyFuture().get();
                    } catch (IgniteException | CacheException e) {
                        if (X.hasCause(e, IgniteClientDisconnectedException.class)) {
                            IgniteClientDisconnectedException cause = X.cause(e, IgniteClientDisconnectedException.class);
                            assert cause != null;
                            cause.reconnectFuture().get();
                        } else if (X.hasCause(e, ClusterTopologyException.class)) {
                            ClusterTopologyException cause = X.cause(e, ClusterTopologyException.class);
                            assert cause != null;
                            cause.retryReadyFuture().get();
                        } else
                            throw e;
                    }
                }
                return null;
            } catch (Throwable e) {
                log.error("Unexpected error: " + e, e);
                throw e;
            }
        }
    }, CLIENT_GRID_CNT, "client-thread");
    try {
        if (!latch.await(30, SECONDS)) {
            log.warning("Failed to wait for for clients start.");
            U.dumpThreads(log);
            fail("Failed to wait for for clients start.");
        }
        // Killing a half of server nodes.
        final int srvsToKill = GRID_CNT / 2;
        final BlockingQueue<Integer> victims = new LinkedBlockingQueue<>();
        for (int i = 0; i < srvsToKill; i++) victims.add(i);
        final BlockingQueue<Integer> assassins = new LinkedBlockingQueue<>();
        for (int i = srvsToKill; i < GRID_CNT; i++) assassins.add(i);
        IgniteInternalFuture<?> srvsShutdownFut = multithreadedAsync(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                Thread.sleep(5_000);
                Ignite assassin = grid(assassins.take());
                assertFalse(assassin.configuration().isClientMode());
                Ignite victim = grid(victims.take());
                assertFalse(victim.configuration().isClientMode());
                log.info("Kill node [node=" + victim.name() + ", from=" + assassin.name() + ']');
                switch(stopType) {
                    case CLOSE:
                        victim.close();
                        break;
                    case FAIL_EVENT:
                        UUID nodeId = victim.cluster().localNode().id();
                        assassin.configuration().getDiscoverySpi().failNode(nodeId, null);
                        break;
                    case SIMULATE_FAIL:
                        ((TcpDiscoverySpi) victim.configuration().getDiscoverySpi()).simulateNodeFailure();
                        break;
                    default:
                        fail();
                }
                return null;
            }
        }, assassins.size(), "kill-thread");
        srvsShutdownFut.get();
        Thread.sleep(15_000);
        done.set(true);
        clientsFut.get();
        awaitPartitionMapExchange();
        for (int k = 0; k < 10_000; k++) {
            String key = String.valueOf(k);
            Object val = cache.get(key);
            for (int i = srvsToKill; i < GRID_CNT; i++) assertEquals(val, ignite(i).cache(DEFAULT_CACHE_NAME).get(key));
        }
    } finally {
        done.set(true);
    }
}
Also used : HashMap(java.util.HashMap) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) IgniteTransactions(org.apache.ignite.IgniteTransactions) Random(java.util.Random) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteCache(org.apache.ignite.IgniteCache) CountDownLatch(java.util.concurrent.CountDownLatch) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteException(org.apache.ignite.IgniteException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Transaction(org.apache.ignite.transactions.Transaction) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException)

Aggregations

CacheException (javax.cache.CacheException)144 Ignite (org.apache.ignite.Ignite)42 IgniteException (org.apache.ignite.IgniteException)36 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)26 Transaction (org.apache.ignite.transactions.Transaction)25 ArrayList (java.util.ArrayList)19 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)19 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)18 IgniteCache (org.apache.ignite.IgniteCache)18 CountDownLatch (java.util.concurrent.CountDownLatch)17 List (java.util.List)16 Map (java.util.Map)16 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)15 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)13 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)13 HashMap (java.util.HashMap)12 IgniteTransactions (org.apache.ignite.IgniteTransactions)12 CyclicBarrier (java.util.concurrent.CyclicBarrier)11 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)10 Cache (javax.cache.Cache)9