Search in sources :

Example 66 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridShmemCommunicationClient method sendMessage.

/**
 * {@inheritDoc}
 */
@Override
public synchronized void sendMessage(byte[] data, int len) throws IgniteCheckedException {
    if (closed())
        throw new IgniteCheckedException("Communication client was closed: " + this);
    try {
        shmem.outputStream().write(data, 0, len);
        metricsLsnr.onBytesSent(len);
    } catch (IOException e) {
        throw new IgniteCheckedException("Failed to send message to remote node: " + shmem, e);
    }
    markUsed();
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException)

Example 67 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class BPlusTree method find.

/**
 * {@inheritDoc}
 */
public final GridCursor<T> find(L lower, L upper, Object x) throws IgniteCheckedException {
    checkDestroyed();
    try {
        if (lower == null)
            return findLowerUnbounded(upper, x);
        ForwardCursor cursor = new ForwardCursor(lower, upper, x);
        cursor.find();
        return cursor;
    } catch (IgniteCheckedException e) {
        throw new IgniteCheckedException("Runtime failure on bounds: [lower=" + lower + ", upper=" + upper + "]", e);
    } catch (RuntimeException e) {
        throw new IgniteException("Runtime failure on bounds: [lower=" + lower + ", upper=" + upper + "]", e);
    } catch (AssertionError e) {
        throw new AssertionError("Assertion error on bounds: [lower=" + lower + ", upper=" + upper + "]", e);
    } finally {
        checkDestroyed();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException)

Example 68 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class VisorTaskUtils method resolveIgfsProfilerLogsDir.

/**
 * Resolve IGFS profiler logs directory.
 *
 * @param igfs IGFS instance to resolve logs dir for.
 * @return {@link Path} to log dir or {@code null} if not found.
 * @throws IgniteCheckedException if failed to resolve.
 */
public static Path resolveIgfsProfilerLogsDir(IgniteFileSystem igfs) throws IgniteCheckedException {
    String logsDir;
    if (igfs instanceof IgfsEx)
        logsDir = ((IgfsEx) igfs).clientLogDirectory();
    else if (igfs == null)
        throw new IgniteCheckedException("Failed to get profiler log folder (IGFS instance not found)");
    else
        throw new IgniteCheckedException("Failed to get profiler log folder (unexpected IGFS instance type)");
    URL logsDirUrl = U.resolveIgniteUrl(logsDir != null ? logsDir : DFLT_IGFS_LOG_DIR);
    return logsDirUrl != null ? new File(logsDirUrl.getPath()).toPath() : null;
}
Also used : IgfsEx(org.apache.ignite.internal.processors.igfs.IgfsEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) RandomAccessFile(java.io.RandomAccessFile) VisorLogFile(org.apache.ignite.internal.visor.log.VisorLogFile) File(java.io.File) URL(java.net.URL)

Example 69 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridNearTxLocal method getAllAsync.

/**
 * @param cacheCtx Cache context.
 * @param keys Keys to get.
 * @param deserializeBinary Deserialize binary flag.
 * @param skipVals Skip values flag.
 * @param keepCacheObjects Keep cache objects
 * @param skipStore Skip store flag.
 * @return Future for this get.
 */
@SuppressWarnings("unchecked")
public <K, V> IgniteInternalFuture<Map<K, V>> getAllAsync(final GridCacheContext cacheCtx, @Nullable final AffinityTopologyVersion entryTopVer, Collection<KeyCacheObject> keys, final boolean deserializeBinary, final boolean skipVals, final boolean keepCacheObjects, final boolean skipStore, final boolean recovery, final boolean needVer) {
    if (F.isEmpty(keys))
        return new GridFinishedFuture<>(Collections.<K, V>emptyMap());
    init();
    int keysCnt = keys.size();
    boolean single = keysCnt == 1;
    try {
        checkValid();
        final Map<K, V> retMap = new GridLeanMap<>(keysCnt);
        final Map<KeyCacheObject, GridCacheVersion> missed = new GridLeanMap<>(pessimistic() ? keysCnt : 0);
        CacheOperationContext opCtx = cacheCtx.operationContextPerCall();
        ExpiryPolicy expiryPlc = opCtx != null ? opCtx.expiry() : null;
        final Collection<KeyCacheObject> lockKeys = enlistRead(cacheCtx, entryTopVer, keys, expiryPlc, retMap, missed, keysCnt, deserializeBinary, skipVals, keepCacheObjects, skipStore, recovery, needVer);
        if (single && missed.isEmpty())
            return new GridFinishedFuture<>(retMap);
        // Handle locks.
        if (pessimistic() && !readCommitted() && !skipVals) {
            if (expiryPlc == null)
                expiryPlc = cacheCtx.expiry();
            long accessTtl = expiryPlc != null ? CU.toTtl(expiryPlc.getExpiryForAccess()) : CU.TTL_NOT_CHANGED;
            long createTtl = expiryPlc != null ? CU.toTtl(expiryPlc.getExpiryForCreation()) : CU.TTL_NOT_CHANGED;
            long timeout = remainingTime();
            if (timeout == -1)
                return new GridFinishedFuture<>(timeoutException());
            IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(lockKeys, timeout, this, true, true, isolation, isInvalidate(), createTtl, accessTtl);
            final ExpiryPolicy expiryPlc0 = expiryPlc;
            PLC2<Map<K, V>> plc2 = new PLC2<Map<K, V>>() {

                @Override
                public IgniteInternalFuture<Map<K, V>> postLock() throws IgniteCheckedException {
                    if (log.isDebugEnabled())
                        log.debug("Acquired transaction lock for read on keys: " + lockKeys);
                    // Load keys only after the locks have been acquired.
                    for (KeyCacheObject cacheKey : lockKeys) {
                        K keyVal = (K) (keepCacheObjects ? cacheKey : cacheCtx.cacheObjectContext().unwrapBinaryIfNeeded(cacheKey, !deserializeBinary, true));
                        if (retMap.containsKey(keyVal))
                            // We already have a return value.
                            continue;
                        IgniteTxKey txKey = cacheCtx.txKey(cacheKey);
                        IgniteTxEntry txEntry = entry(txKey);
                        assert txEntry != null;
                        // Check if there is cached value.
                        while (true) {
                            GridCacheEntryEx cached = txEntry.cached();
                            CacheObject val = null;
                            GridCacheVersion readVer = null;
                            EntryGetResult getRes = null;
                            try {
                                Object transformClo = (!F.isEmpty(txEntry.entryProcessors()) && cctx.gridEvents().isRecordable(EVT_CACHE_OBJECT_READ)) ? F.first(txEntry.entryProcessors()) : null;
                                if (needVer) {
                                    getRes = cached.innerGetVersioned(null, GridNearTxLocal.this, /*update-metrics*/
                                    true, /*event*/
                                    !skipVals, CU.subjectId(GridNearTxLocal.this, cctx), transformClo, resolveTaskName(), null, txEntry.keepBinary(), null);
                                    if (getRes != null) {
                                        val = getRes.value();
                                        readVer = getRes.version();
                                    }
                                } else {
                                    val = cached.innerGet(null, GridNearTxLocal.this, /*read through*/
                                    false, /*metrics*/
                                    true, /*events*/
                                    !skipVals, CU.subjectId(GridNearTxLocal.this, cctx), transformClo, resolveTaskName(), null, txEntry.keepBinary());
                                }
                                // If value is in cache and passed the filter.
                                if (val != null) {
                                    missed.remove(cacheKey);
                                    txEntry.setAndMarkValid(val);
                                    if (!F.isEmpty(txEntry.entryProcessors()))
                                        val = txEntry.applyEntryProcessors(val);
                                    cacheCtx.addResult(retMap, cacheKey, val, skipVals, keepCacheObjects, deserializeBinary, false, getRes, readVer, 0, 0, needVer);
                                    if (readVer != null)
                                        txEntry.entryReadVersion(readVer);
                                }
                                // While.
                                break;
                            } catch (GridCacheEntryRemovedException ignore) {
                                if (log.isDebugEnabled())
                                    log.debug("Got removed exception in get postLock (will retry): " + cached);
                                txEntry.cached(entryEx(cacheCtx, txKey, topologyVersion()));
                            }
                        }
                    }
                    if (!missed.isEmpty() && cacheCtx.isLocal()) {
                        AffinityTopologyVersion topVer = topologyVersionSnapshot();
                        if (topVer == null)
                            topVer = entryTopVer;
                        return checkMissed(cacheCtx, topVer != null ? topVer : topologyVersion(), retMap, missed, deserializeBinary, skipVals, keepCacheObjects, skipStore, recovery, needVer, expiryPlc0);
                    }
                    return new GridFinishedFuture<>(Collections.<K, V>emptyMap());
                }
            };
            FinishClosure<Map<K, V>> finClos = new FinishClosure<Map<K, V>>() {

                @Override
                Map<K, V> finish(Map<K, V> loaded) {
                    retMap.putAll(loaded);
                    return retMap;
                }
            };
            if (fut.isDone()) {
                try {
                    IgniteInternalFuture<Map<K, V>> fut1 = plc2.apply(fut.get(), null);
                    return fut1.isDone() ? new GridFinishedFuture<>(finClos.apply(fut1.get(), null)) : new GridEmbeddedFuture<>(finClos, fut1);
                } catch (GridClosureException e) {
                    return new GridFinishedFuture<>(e.unwrap());
                } catch (IgniteCheckedException e) {
                    try {
                        return plc2.apply(false, e);
                    } catch (Exception e1) {
                        return new GridFinishedFuture<>(e1);
                    }
                }
            } else {
                return new GridEmbeddedFuture<>(fut, plc2, finClos);
            }
        } else {
            assert optimistic() || readCommitted() || skipVals;
            if (!missed.isEmpty()) {
                if (!readCommitted())
                    for (Iterator<KeyCacheObject> it = missed.keySet().iterator(); it.hasNext(); ) {
                        KeyCacheObject cacheKey = it.next();
                        K keyVal = (K) (keepCacheObjects ? cacheKey : cacheCtx.cacheObjectContext().unwrapBinaryIfNeeded(cacheKey, !deserializeBinary, false));
                        if (retMap.containsKey(keyVal))
                            it.remove();
                    }
                if (missed.isEmpty())
                    return new GridFinishedFuture<>(retMap);
                AffinityTopologyVersion topVer = topologyVersionSnapshot();
                if (topVer == null)
                    topVer = entryTopVer;
                return checkMissed(cacheCtx, topVer != null ? topVer : topologyVersion(), retMap, missed, deserializeBinary, skipVals, keepCacheObjects, skipStore, recovery, needVer, expiryPlc);
            }
            return new GridFinishedFuture<>(retMap);
        }
    } catch (IgniteCheckedException e) {
        setRollbackOnly();
        return new GridFinishedFuture<>(e);
    }
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) ROLLING_BACK(org.apache.ignite.transactions.TransactionState.ROLLING_BACK) ROLLED_BACK(org.apache.ignite.transactions.TransactionState.ROLLED_BACK) MARKED_ROLLBACK(org.apache.ignite.transactions.TransactionState.MARKED_ROLLBACK) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) GridEmbeddedFuture(org.apache.ignite.internal.util.future.GridEmbeddedFuture) GridCacheVersion(org.apache.ignite.internal.processors.cache.version.GridCacheVersion) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) Iterator(java.util.Iterator) EntryGetResult(org.apache.ignite.internal.processors.cache.EntryGetResult) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) IgniteTxEntry(org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteTxRollbackCheckedException(org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException) IgniteTxTimeoutCheckedException(org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) CacheException(javax.cache.CacheException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) IgniteTxOptimisticCheckedException(org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) IgniteTxKey(org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap)

Example 70 with IgniteCheckedException

use of org.apache.ignite.IgniteCheckedException in project ignite by apache.

the class GridCacheMultithreadedFailoverAbstractTest method compare.

/**
 * Compare cache content.
 *
 * @param expVals Expected values.
 * @return {@code True} if check passed successfully.
 * @throws Exception If failed.
 */
private boolean compare(Map<Integer, Integer> expVals) throws Exception {
    cmpLatch = new CountDownLatch(putThreads());
    cmp = true;
    killLock.lock();
    try {
        log.info("Comparing cache content.");
        if (!cmpLatch.await(60_000, TimeUnit.MILLISECONDS))
            throw new IgniteCheckedException("Failed to suspend threads executing put.");
        if (compareCaches(expVals)) {
            log.info("Cache comparison succeeded.");
            return true;
        } else {
            log.error("Cache comparison failed.");
            return false;
        }
    } finally {
        killLock.unlock();
        lock.lock();
        try {
            cmp = false;
            putCond.signalAll();
        } finally {
            lock.unlock();
        }
        U.sleep(500);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1568 IgniteException (org.apache.ignite.IgniteException)388 ArrayList (java.util.ArrayList)237 IOException (java.io.IOException)226 ClusterNode (org.apache.ignite.cluster.ClusterNode)215 Map (java.util.Map)181 UUID (java.util.UUID)163 HashMap (java.util.HashMap)160 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)150 Test (org.junit.Test)143 List (java.util.List)139 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)138 Nullable (org.jetbrains.annotations.Nullable)134 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)118 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)109 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)105 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)104 Collection (java.util.Collection)97 HashSet (java.util.HashSet)97 Ignite (org.apache.ignite.Ignite)96