Search in sources :

Example 6 with GridClosureException

use of org.apache.ignite.internal.util.lang.GridClosureException in project ignite by apache.

the class GridNearTxLocal method putAsync0.

/**
 * Internal method for single update operation.
 *
 * @param cacheCtx Cache context.
 * @param key Key.
 * @param val Value.
 * @param entryProcessor Entry processor.
 * @param invokeArgs Optional arguments for EntryProcessor.
 * @param retval Return value flag.
 * @param filter Filter.
 * @return Operation future.
 */
private <K, V> IgniteInternalFuture putAsync0(final GridCacheContext cacheCtx, @Nullable AffinityTopologyVersion entryTopVer, K key, @Nullable V val, @Nullable EntryProcessor<K, V, Object> entryProcessor, @Nullable final Object[] invokeArgs, final boolean retval, @Nullable final CacheEntryPredicate filter) {
    assert key != null;
    try {
        beforePut(cacheCtx, retval);
        final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
        CacheOperationContext opCtx = cacheCtx.operationContextPerCall();
        final Byte dataCenterId = opCtx != null ? opCtx.dataCenterId() : null;
        KeyCacheObject cacheKey = cacheCtx.toCacheKeyObject(key);
        boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
        final CacheEntryPredicate[] filters = CU.filterArray(filter);
        final IgniteInternalFuture<Void> loadFut = enlistWrite(cacheCtx, entryTopVer, cacheKey, val, opCtx != null ? opCtx.expiry() : null, entryProcessor, invokeArgs, retval, /*lockOnly*/
        false, filters, ret, opCtx != null && opCtx.skipStore(), /*singleRmv*/
        false, keepBinary, opCtx != null && opCtx.recovery(), dataCenterId);
        if (pessimistic()) {
            assert loadFut == null || loadFut.isDone() : loadFut;
            if (loadFut != null)
                loadFut.get();
            final Collection<KeyCacheObject> enlisted = Collections.singleton(cacheKey);
            if (log.isDebugEnabled())
                log.debug("Before acquiring transaction lock for put on key: " + enlisted);
            long timeout = remainingTime();
            if (timeout == -1)
                return new GridFinishedFuture<>(timeoutException());
            IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(enlisted, timeout, this, // Needed to force load from store.
            entryProcessor != null, /*read*/
            retval, isolation, isInvalidate(), -1L, -1L);
            PLC1<GridCacheReturn> plc1 = new PLC1<GridCacheReturn>(ret) {

                @Override
                public GridCacheReturn postLock(GridCacheReturn ret) throws IgniteCheckedException {
                    if (log.isDebugEnabled())
                        log.debug("Acquired transaction lock for put on keys: " + enlisted);
                    postLockWrite(cacheCtx, enlisted, ret, /*remove*/
                    false, retval, /*read*/
                    false, -1L, filters, /*computeInvoke*/
                    true);
                    return ret;
                }
            };
            if (fut.isDone()) {
                try {
                    return nonInterruptable(plc1.apply(fut.get(), null));
                } catch (GridClosureException e) {
                    return new GridFinishedFuture<>(e.unwrap());
                } catch (IgniteCheckedException e) {
                    try {
                        return nonInterruptable(plc1.apply(false, e));
                    } catch (Exception e1) {
                        return new GridFinishedFuture<>(e1);
                    }
                }
            } else {
                return nonInterruptable(new GridEmbeddedFuture<>(fut, plc1));
            }
        } else
            return optimisticPutFuture(cacheCtx, loadFut, ret, keepBinary);
    } catch (IgniteCheckedException e) {
        return new GridFinishedFuture(e);
    } catch (RuntimeException e) {
        onException();
        throw e;
    }
}
Also used : GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) 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) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) CacheEntryPredicate(org.apache.ignite.internal.processors.cache.CacheEntryPredicate) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 7 with GridClosureException

use of org.apache.ignite.internal.util.lang.GridClosureException in project ignite by apache.

the class GridNearTxLocal method putAllAsync0.

/**
 * Internal method for all put and transform operations. Only one of {@code map}, {@code transformMap}
 * maps must be non-null.
 *
 * @param cacheCtx Context.
 * @param map Key-value map to store.
 * @param invokeMap Invoke map.
 * @param invokeArgs Optional arguments for EntryProcessor.
 * @param drMap DR map.
 * @param retval Key-transform value map to store.
 * @return Operation future.
 */
@SuppressWarnings("unchecked")
private <K, V> IgniteInternalFuture putAllAsync0(final GridCacheContext cacheCtx, @Nullable AffinityTopologyVersion entryTopVer, @Nullable Map<? extends K, ? extends V> map, @Nullable Map<? extends K, ? extends EntryProcessor<K, V, Object>> invokeMap, @Nullable final Object[] invokeArgs, @Nullable Map<KeyCacheObject, GridCacheDrInfo> drMap, final boolean retval) {
    try {
        beforePut(cacheCtx, retval);
    } catch (IgniteCheckedException e) {
        return new GridFinishedFuture(e);
    }
    final CacheOperationContext opCtx = cacheCtx.operationContextPerCall();
    final Byte dataCenterId;
    if (opCtx != null && opCtx.hasDataCenterId()) {
        assert drMap == null : drMap;
        assert map != null || invokeMap != null;
        dataCenterId = opCtx.dataCenterId();
    } else
        dataCenterId = null;
    // Cached entry may be passed only from entry wrapper.
    final Map<?, ?> map0 = map;
    final Map<?, EntryProcessor<K, V, Object>> invokeMap0 = (Map<K, EntryProcessor<K, V, Object>>) invokeMap;
    if (log.isDebugEnabled())
        log.debug("Called putAllAsync(...) [tx=" + this + ", map=" + map0 + ", retval=" + retval + "]");
    assert map0 != null || invokeMap0 != null;
    final GridCacheReturn ret = new GridCacheReturn(localResult(), false);
    if (F.isEmpty(map0) && F.isEmpty(invokeMap0)) {
        if (implicit())
            try {
                commit();
            } catch (IgniteCheckedException e) {
                return new GridFinishedFuture<>(e);
            }
        return new GridFinishedFuture<>(ret.success(true));
    }
    try {
        Set<?> keySet = map0 != null ? map0.keySet() : invokeMap0.keySet();
        final Collection<KeyCacheObject> enlisted = new ArrayList<>(keySet.size());
        final boolean keepBinary = opCtx != null && opCtx.isKeepBinary();
        final IgniteInternalFuture<Void> loadFut = enlistWrite(cacheCtx, entryTopVer, keySet, opCtx != null ? opCtx.expiry() : null, map0, invokeMap0, invokeArgs, retval, false, CU.filterArray(null), ret, enlisted, drMap, null, opCtx != null && opCtx.skipStore(), false, keepBinary, opCtx != null && opCtx.recovery(), dataCenterId);
        if (pessimistic()) {
            assert loadFut == null || loadFut.isDone() : loadFut;
            if (loadFut != null) {
                try {
                    loadFut.get();
                } catch (IgniteCheckedException e) {
                    return new GridFinishedFuture(e);
                }
            }
            if (log.isDebugEnabled())
                log.debug("Before acquiring transaction lock for put on keys: " + enlisted);
            long timeout = remainingTime();
            if (timeout == -1)
                return new GridFinishedFuture<>(timeoutException());
            IgniteInternalFuture<Boolean> fut = cacheCtx.cache().txLockAsync(enlisted, timeout, this, // Needed to force load from store.
            invokeMap != null, /*read*/
            retval, isolation, isInvalidate(), -1L, -1L);
            PLC1<GridCacheReturn> plc1 = new PLC1<GridCacheReturn>(ret) {

                @Override
                public GridCacheReturn postLock(GridCacheReturn ret) throws IgniteCheckedException {
                    if (log.isDebugEnabled())
                        log.debug("Acquired transaction lock for put on keys: " + enlisted);
                    postLockWrite(cacheCtx, enlisted, ret, /*remove*/
                    false, retval, /*read*/
                    false, -1L, CU.filterArray(null), /*computeInvoke*/
                    true);
                    return ret;
                }
            };
            if (fut.isDone()) {
                try {
                    return nonInterruptable(plc1.apply(fut.get(), null));
                } catch (GridClosureException e) {
                    return new GridFinishedFuture<>(e.unwrap());
                } catch (IgniteCheckedException e) {
                    try {
                        return nonInterruptable(plc1.apply(false, e));
                    } catch (Exception e1) {
                        return new GridFinishedFuture<>(e1);
                    }
                }
            } else {
                return nonInterruptable(new GridEmbeddedFuture<>(fut, plc1));
            }
        } else
            return optimisticPutFuture(cacheCtx, loadFut, ret, keepBinary);
    } catch (RuntimeException e) {
        onException();
        throw e;
    }
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) ArrayList(java.util.ArrayList) 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) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) GridCacheReturn(org.apache.ignite.internal.processors.cache.GridCacheReturn) 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) EntryProcessor(javax.cache.processor.EntryProcessor) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) GridLeanMap(org.apache.ignite.internal.util.GridLeanMap)

Example 8 with GridClosureException

use of org.apache.ignite.internal.util.lang.GridClosureException 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 9 with GridClosureException

use of org.apache.ignite.internal.util.lang.GridClosureException in project ignite by apache.

the class IgfsMetaManager method lock.

/**
 * Lock the file explicitly outside of transaction.
 *
 * @param fileId File ID to lock.
 * @param del If file is being locked for delete.
 * @return Locked file info or {@code null} if file cannot be locked or doesn't exist.
 * @throws IgniteCheckedException If the file with such id does not exist, or on another failure.
 */
@Nullable
public IgfsEntryInfo lock(IgniteUuid fileId, boolean del) throws IgniteCheckedException {
    if (busyLock.enterBusy()) {
        try {
            validTxState(false);
            assert fileId != null;
            try (GridNearTxLocal tx = startTx()) {
                // Lock file ID for this transaction.
                IgfsEntryInfo oldInfo = info(fileId);
                if (oldInfo == null)
                    return null;
                if (oldInfo.lockId() != null)
                    // The file is already locked, we cannot lock it.
                    return null;
                IgfsEntryInfo newInfo = invokeLock(fileId, del);
                tx.commit();
                return newInfo;
            } catch (GridClosureException e) {
                throw U.cast(e);
            }
        } finally {
            busyLock.leaveBusy();
        }
    } else
        throw new IllegalStateException("Failed to obtain lock because Grid is stopping: " + fileId);
}
Also used : GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) Nullable(org.jetbrains.annotations.Nullable)

Example 10 with GridClosureException

use of org.apache.ignite.internal.util.lang.GridClosureException in project ignite by apache.

the class IgfsMetaManager method updateInfo.

/**
 * Update file info in cache.
 *
 * @param fileId File ID to update information for.
 * @param proc Entry processor to invoke.
 * @return Updated file info or {@code null} if such file ID not found.
 * @throws IgniteCheckedException If failed.
 */
@Nullable
public IgfsEntryInfo updateInfo(IgniteUuid fileId, EntryProcessor<IgniteUuid, IgfsEntryInfo, IgfsEntryInfo> proc) throws IgniteCheckedException {
    validTxState(false);
    assert fileId != null;
    assert proc != null;
    if (busyLock.enterBusy()) {
        try {
            if (log.isDebugEnabled())
                log.debug("Update file info [fileId=" + fileId + ", proc=" + proc + ']');
            try (GridNearTxLocal tx = startTx()) {
                // Lock file ID for this transaction.
                IgfsEntryInfo oldInfo = info(fileId);
                if (oldInfo == null)
                    // File not found.
                    return null;
                IgfsEntryInfo newInfo = invokeAndGet(fileId, proc);
                if (newInfo == null)
                    throw fsException("Failed to update file info with null value" + " [oldInfo=" + oldInfo + ", newInfo=null, proc=" + proc + ']');
                if (!oldInfo.id().equals(newInfo.id()))
                    throw fsException("Failed to update file info (file IDs differ)" + " [oldInfo=" + oldInfo + ", newInfo=" + newInfo + ", proc=" + proc + ']');
                if (oldInfo.isDirectory() != newInfo.isDirectory())
                    throw fsException("Failed to update file info (file types differ)" + " [oldInfo=" + oldInfo + ", newInfo=" + newInfo + ", proc=" + proc + ']');
                tx.commit();
                return newInfo;
            } catch (GridClosureException e) {
                throw U.cast(e);
            }
        } finally {
            busyLock.leaveBusy();
        }
    } else
        throw new IllegalStateException("Failed to update file system entry info because Grid is stopping: " + fileId);
}
Also used : GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GridClosureException (org.apache.ignite.internal.util.lang.GridClosureException)14 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)11 NodeStoppingException (org.apache.ignite.internal.NodeStoppingException)8 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)8 KeyCacheObject (org.apache.ignite.internal.processors.cache.KeyCacheObject)8 CacheException (javax.cache.CacheException)7 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)7 IgniteTxRollbackCheckedException (org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException)7 Map (java.util.Map)6 IgniteTxOptimisticCheckedException (org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException)6 IgniteTxTimeoutCheckedException (org.apache.ignite.internal.transactions.IgniteTxTimeoutCheckedException)6 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)6 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 CacheObject (org.apache.ignite.internal.processors.cache.CacheObject)5 GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)5 GridEmbeddedFuture (org.apache.ignite.internal.util.future.GridEmbeddedFuture)5 CacheOperationContext (org.apache.ignite.internal.processors.cache.CacheOperationContext)4 IgniteCacheExpiryPolicy (org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy)4 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)4