Search in sources :

Example 41 with IgniteException

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

the class GridDhtAtomicCache method get0.

/**
     *  @param key Key.
     *  @param deserializeBinary Deserialize binary.
     *  @param needVer Need version.
     *  @return Value.
     *  @throws IgniteCheckedException If failed.
     */
@Nullable
public V get0(K key, boolean deserializeBinary, boolean needVer) throws IgniteCheckedException {
    ctx.checkSecurity(SecurityPermission.CACHE_READ);
    if (keyCheck)
        validateCacheKey(key);
    String taskName = ctx.kernalContext().job().currentTaskName();
    CacheOperationContext opCtx = ctx.operationContextPerCall();
    UUID subjId = ctx.subjectIdPerCall(null, opCtx);
    final ExpiryPolicy expiryPlc = opCtx != null ? opCtx.expiry() : null;
    final boolean skipStore = opCtx != null && opCtx.skipStore();
    try {
        return getAsync0(ctx.toCacheKeyObject(key), !ctx.config().isReadFromBackup(), subjId, taskName, deserializeBinary, opCtx != null && opCtx.recovery(), expiryPlc, false, skipStore, true, needVer).get();
    } catch (IgniteException e) {
        if (e.getCause(IgniteCheckedException.class) != null)
            throw e.getCause(IgniteCheckedException.class);
        else
            throw e;
    }
}
Also used : CacheOperationContext(org.apache.ignite.internal.processors.cache.CacheOperationContext) IgniteException(org.apache.ignite.IgniteException) IgniteCacheExpiryPolicy(org.apache.ignite.internal.processors.cache.IgniteCacheExpiryPolicy) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) UUID(java.util.UUID) Nullable(org.jetbrains.annotations.Nullable)

Example 42 with IgniteException

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

the class GridCacheAtomicSequenceImpl method internalUpdate.

/**
     * Synchronous sequence update operation. Will add given amount to the sequence value.
     *
     * @param l Increment amount.
     * @param updateCall Cache call that will update sequence reservation count in accordance with l.
     * @param updated If {@code true}, will return sequence value after update, otherwise will return sequence value
     *      prior to update.
     * @return Sequence value.
     * @throws IgniteCheckedException If update failed.
     */
@SuppressWarnings("SignalWithoutCorrespondingAwait")
private long internalUpdate(long l, @Nullable Callable<Long> updateCall, boolean updated) throws IgniteCheckedException {
    checkRemoved();
    assert l > 0;
    lock.lock();
    try {
        // If reserved range isn't exhausted.
        long locVal0 = locVal;
        if (locVal0 + l <= upBound) {
            locVal = locVal0 + l;
            return updated ? locVal0 + l : locVal0;
        }
        if (updateCall == null)
            updateCall = internalUpdate(l, updated);
        try {
            return updateCall.call();
        } catch (IgniteCheckedException | IgniteException | IllegalStateException e) {
            throw e;
        } catch (Exception e) {
            throw new IgniteCheckedException(e);
        }
    } finally {
        lock.unlock();
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) InvalidObjectException(java.io.InvalidObjectException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) ObjectStreamException(java.io.ObjectStreamException)

Example 43 with IgniteException

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

the class IgfsMetaManager method create.

/**
     * Create a file.
     *
     * @param path Path.
     * @param dirProps Directory properties.
     * @param overwrite Overwrite flag.
     * @param blockSize Block size.
     * @param affKey Affinity key.
     * @param evictExclude Evict exclude flag.
     * @param fileProps File properties.
     * @param secondaryCtx Secondary file system create context.
     * @return @return Operation result.
     * @throws IgniteCheckedException If failed.
     */
IgfsCreateResult create(final IgfsPath path, Map<String, String> dirProps, final boolean overwrite, final int blockSize, @Nullable final IgniteUuid affKey, final boolean evictExclude, @Nullable Map<String, String> fileProps, @Nullable IgfsSecondaryFileSystemCreateContext secondaryCtx) throws IgniteCheckedException {
    validTxState(false);
    while (true) {
        if (busyLock.enterBusy()) {
            OutputStream secondaryOut = null;
            try {
                // Prepare path IDs.
                IgfsPathIds pathIds = pathIds(path);
                // Prepare lock IDs.
                Set<IgniteUuid> lockIds = new TreeSet<>(PATH_ID_SORTING_COMPARATOR);
                pathIds.addExistingIds(lockIds, relaxed);
                pathIds.addSurrogateIds(lockIds);
                // In overwrite mode we also lock ID of potential replacement as well as trash ID.
                IgniteUuid overwriteId = IgniteUuid.randomUuid();
                IgniteUuid trashId = IgfsUtils.randomTrashId();
                if (overwrite) {
                    lockIds.add(overwriteId);
                    // Trash ID is only added if we suspect conflict.
                    if (pathIds.allExists())
                        lockIds.add(trashId);
                }
                // Start TX.
                try (GridNearTxLocal tx = startTx()) {
                    Map<IgniteUuid, IgfsEntryInfo> lockInfos = lockIds(lockIds);
                    if (secondaryCtx != null && isRetryForSecondary(pathIds, lockInfos))
                        continue;
                    if (!pathIds.verifyIntegrity(lockInfos, relaxed))
                        // Directory structure changed concurrently. So we simply re-try.
                        continue;
                    if (pathIds.allExists()) {
                        // All participants found.
                        IgfsEntryInfo oldInfo = lockInfos.get(pathIds.lastId());
                        // Check: is it a file?
                        if (!oldInfo.isFile())
                            throw new IgfsPathIsDirectoryException("Failed to create a file: " + path);
                        // Check: can we overwrite it?
                        if (!overwrite)
                            throw new IgfsPathAlreadyExistsException("Failed to create a file: " + path);
                        // Check if file already opened for write.
                        if (oldInfo.lockId() != null)
                            throw new IgfsException("File is already opened for write: " + path);
                        // At this point file can be re-created safely.
                        // Add existing to trash listing.
                        IgniteUuid oldId = pathIds.lastId();
                        id2InfoPrj.invoke(trashId, new IgfsMetaDirectoryListingAddProcessor(IgfsUtils.composeNameForTrash(path, oldId), new IgfsListingEntry(oldInfo)));
                        // Replace ID in parent directory.
                        String name = pathIds.lastPart();
                        IgniteUuid parentId = pathIds.lastParentId();
                        id2InfoPrj.invoke(parentId, new IgfsMetaDirectoryListingReplaceProcessor(name, overwriteId));
                        // Create the file.
                        IgniteUuid newLockId = createFileLockId(false);
                        long newAccessTime;
                        long newModificationTime;
                        Map<String, String> newProps;
                        long newLen;
                        int newBlockSize;
                        if (secondaryCtx != null) {
                            secondaryOut = secondaryCtx.create();
                            newAccessTime = 0L;
                            newModificationTime = 0L;
                            newProps = null;
                        } else {
                            newAccessTime = System.currentTimeMillis();
                            newModificationTime = newAccessTime;
                            newProps = fileProps;
                        }
                        newLen = 0L;
                        newBlockSize = blockSize;
                        IgfsEntryInfo newInfo = invokeAndGet(overwriteId, new IgfsMetaFileCreateProcessor(newAccessTime, newModificationTime, newProps, newBlockSize, affKey, newLockId, evictExclude, newLen));
                        // Prepare result and commit.
                        tx.commit();
                        IgfsUtils.sendEvents(igfsCtx.kernalContext(), path, EventType.EVT_IGFS_FILE_OPENED_WRITE);
                        return new IgfsCreateResult(newInfo, secondaryOut);
                    } else {
                        // Create file and parent folders.
                        T1<OutputStream> secondaryOutHolder = null;
                        if (secondaryCtx != null)
                            secondaryOutHolder = new T1<>();
                        IgfsPathsCreateResult res;
                        try {
                            res = createFile(pathIds, lockInfos, dirProps, fileProps, blockSize, affKey, evictExclude, secondaryCtx, secondaryOutHolder);
                        } finally {
                            if (secondaryOutHolder != null)
                                secondaryOut = secondaryOutHolder.get();
                        }
                        if (res == null)
                            continue;
                        // Commit.
                        tx.commit();
                        // Generate events.
                        generateCreateEvents(res.createdPaths(), true);
                        return new IgfsCreateResult(res.info(), secondaryOut);
                    }
                }
            } catch (IgniteException | IgniteCheckedException e) {
                U.closeQuiet(secondaryOut);
                throw e;
            } catch (Exception e) {
                U.closeQuiet(secondaryOut);
                throw new IgniteCheckedException("Create failed due to unexpected exception: " + path, e);
            } finally {
                busyLock.leaveBusy();
            }
        } else
            throw new IllegalStateException("Failed to mkdir because Grid is stopping. [path=" + path + ']');
    }
}
Also used : OutputStream(java.io.OutputStream) IgfsPathAlreadyExistsException(org.apache.ignite.igfs.IgfsPathAlreadyExistsException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TreeSet(java.util.TreeSet) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteException(org.apache.ignite.IgniteException) T1(org.apache.ignite.internal.util.typedef.T1) IgfsMetaDirectoryListingAddProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryListingAddProcessor) IgfsMetaFileCreateProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaFileCreateProcessor) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgfsPathAlreadyExistsException(org.apache.ignite.igfs.IgfsPathAlreadyExistsException) IgfsParentNotDirectoryException(org.apache.ignite.igfs.IgfsParentNotDirectoryException) IgfsPathIsDirectoryException(org.apache.ignite.igfs.IgfsPathIsDirectoryException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgfsDirectoryNotEmptyException(org.apache.ignite.igfs.IgfsDirectoryNotEmptyException) IgfsException(org.apache.ignite.igfs.IgfsException) IgfsConcurrentModificationException(org.apache.ignite.igfs.IgfsConcurrentModificationException) IgfsPathIsNotDirectoryException(org.apache.ignite.igfs.IgfsPathIsNotDirectoryException) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) IgfsException(org.apache.ignite.igfs.IgfsException) IgfsMetaDirectoryListingReplaceProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryListingReplaceProcessor) IgfsPathIsDirectoryException(org.apache.ignite.igfs.IgfsPathIsDirectoryException)

Example 44 with IgniteException

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

the class IgfsIpcHandler method processPathControlRequest.

/**
     * Processes path control request.
     *
     * @param ses Session.
     * @param cmd Command.
     * @param msg Message.
     * @return Response message.
     * @throws IgniteCheckedException If failed.
     */
private IgfsMessage processPathControlRequest(final IgfsClientSession ses, final IgfsIpcCommand cmd, IgfsMessage msg) throws IgniteCheckedException {
    final IgfsPathControlRequest req = (IgfsPathControlRequest) msg;
    if (log.isDebugEnabled())
        log.debug("Processing path control request [igfsName=" + igfs.name() + ", req=" + req + ']');
    final IgfsControlResponse res = new IgfsControlResponse();
    final String userName = req.userName();
    assert userName != null;
    try {
        IgfsUserContext.doAs(userName, new IgniteOutClosure<Object>() {

            @Override
            public Void apply() {
                switch(cmd) {
                    case EXISTS:
                        res.response(igfs.exists(req.path()));
                        break;
                    case INFO:
                        res.response(igfs.info(req.path()));
                        break;
                    case PATH_SUMMARY:
                        res.response(igfs.summary(req.path()));
                        break;
                    case UPDATE:
                        res.response(igfs.update(req.path(), req.properties()));
                        break;
                    case RENAME:
                        igfs.rename(req.path(), req.destinationPath());
                        res.response(true);
                        break;
                    case DELETE:
                        res.response(igfs.delete(req.path(), req.flag()));
                        break;
                    case MAKE_DIRECTORIES:
                        igfs.mkdirs(req.path(), req.properties());
                        res.response(true);
                        break;
                    case LIST_PATHS:
                        res.paths(igfs.listPaths(req.path()));
                        break;
                    case LIST_FILES:
                        res.files(igfs.listFiles(req.path()));
                        break;
                    case SET_TIMES:
                        igfs.setTimes(req.path(), req.modificationTime(), req.accessTime());
                        res.response(true);
                        break;
                    case AFFINITY:
                        res.locations(igfs.affinity(req.path(), req.start(), req.length()));
                        break;
                    case OPEN_READ:
                        {
                            IgfsInputStream igfsIn = !req.flag() ? igfs.open(req.path(), bufSize) : igfs.open(req.path(), bufSize, req.sequentialReadsBeforePrefetch());
                            long streamId = registerResource(ses, igfsIn);
                            if (log.isDebugEnabled())
                                log.debug("Opened IGFS input stream for file read [igfsName=" + igfs.name() + ", path=" + req.path() + ", streamId=" + streamId + ", ses=" + ses + ']');
                            res.response(new IgfsInputStreamDescriptor(streamId, igfsIn.length()));
                            break;
                        }
                    case OPEN_CREATE:
                        {
                            long streamId = registerResource(ses, igfs.create(// Path.
                            req.path(), // Buffer size.
                            bufSize, // Overwrite if exists.
                            req.flag(), // Affinity key based on replication factor.
                            affinityKey(req), // Replication factor.
                            req.replication(), // Block size.
                            req.blockSize(), // File properties.
                            req.properties()));
                            if (log.isDebugEnabled())
                                log.debug("Opened IGFS output stream for file create [igfsName=" + igfs.name() + ", path=" + req.path() + ", streamId=" + streamId + ", ses=" + ses + ']');
                            res.response(streamId);
                            break;
                        }
                    case OPEN_APPEND:
                        {
                            long streamId = registerResource(ses, igfs.append(// Path.
                            req.path(), // Buffer size.
                            bufSize, // Create if absent.
                            req.flag(), // File properties.
                            req.properties()));
                            if (log.isDebugEnabled())
                                log.debug("Opened IGFS output stream for file append [igfsName=" + igfs.name() + ", path=" + req.path() + ", streamId=" + streamId + ", ses=" + ses + ']');
                            res.response(streamId);
                            break;
                        }
                    default:
                        assert false : "Unhandled path control request command: " + cmd;
                        break;
                }
                return null;
            }
        });
    } catch (IgniteException e) {
        throw new IgniteCheckedException(e);
    }
    if (log.isDebugEnabled())
        log.debug("Finished processing path control request [igfsName=" + igfs.name() + ", req=" + req + ", res=" + res + ']');
    return res;
}
Also used : IgfsInputStream(org.apache.ignite.igfs.IgfsInputStream) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgfsPathControlRequest(org.apache.ignite.internal.igfs.common.IgfsPathControlRequest) IgfsControlResponse(org.apache.ignite.internal.igfs.common.IgfsControlResponse)

Example 45 with IgniteException

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

the class IgfsMetaManager method updateTimes.

/**
     * Update times.
     *
     * @param path Path.
     * @param accessTime Access time.
     * @param modificationTime Modification time.
     * @param secondaryFs Secondary file system.
     * @throws IgniteCheckedException If failed.
     */
public void updateTimes(IgfsPath path, long modificationTime, long accessTime, IgfsSecondaryFileSystem secondaryFs) throws IgniteCheckedException {
    while (true) {
        if (busyLock.enterBusy()) {
            try {
                validTxState(false);
                // Prepare path IDs.
                IgfsPathIds pathIds = pathIds(path);
                // Prepare lock IDs.
                Set<IgniteUuid> lockIds = new TreeSet<>(PATH_ID_SORTING_COMPARATOR);
                pathIds.addExistingIds(lockIds, relaxed);
                // Start TX.
                try (GridNearTxLocal tx = startTx()) {
                    Map<IgniteUuid, IgfsEntryInfo> lockInfos = lockIds(lockIds);
                    if (secondaryFs != null && isRetryForSecondary(pathIds, lockInfos))
                        continue;
                    if (!pathIds.verifyIntegrity(lockInfos, relaxed))
                        // Directory structure changed concurrently. So we re-try.
                        continue;
                    if (pathIds.allExists()) {
                        // All files are in place. Update both primary and secondary file systems.
                        if (secondaryFs != null)
                            secondaryFs.setTimes(path, modificationTime, accessTime);
                        IgniteUuid targetId = pathIds.lastExistingId();
                        IgfsEntryInfo targetInfo = lockInfos.get(targetId);
                        id2InfoPrj.invoke(targetId, new IgfsMetaUpdateTimesProcessor(accessTime == -1 ? targetInfo.accessTime() : accessTime, modificationTime == -1 ? targetInfo.modificationTime() : modificationTime));
                        tx.commit();
                        return;
                    } else {
                        // Propagate call to the secondary FS, as we might haven't cache this part yet.
                        if (secondaryFs != null) {
                            secondaryFs.setTimes(path, modificationTime, accessTime);
                            return;
                        } else
                            throw new IgfsPathNotFoundException("Failed to update times (path not found): " + path);
                    }
                }
            } catch (IgniteException | IgniteCheckedException e) {
                throw e;
            } catch (Exception e) {
                throw new IgniteCheckedException("setTimes failed due to unexpected exception: " + path, e);
            } finally {
                busyLock.leaveBusy();
            }
        } else
            throw new IllegalStateException("Failed to update times because Grid is stopping: " + path);
    }
}
Also used : GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException) IgfsPathAlreadyExistsException(org.apache.ignite.igfs.IgfsPathAlreadyExistsException) IgfsParentNotDirectoryException(org.apache.ignite.igfs.IgfsParentNotDirectoryException) IgfsPathIsDirectoryException(org.apache.ignite.igfs.IgfsPathIsDirectoryException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) ClusterTopologyException(org.apache.ignite.cluster.ClusterTopologyException) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgfsDirectoryNotEmptyException(org.apache.ignite.igfs.IgfsDirectoryNotEmptyException) IgfsException(org.apache.ignite.igfs.IgfsException) IgfsConcurrentModificationException(org.apache.ignite.igfs.IgfsConcurrentModificationException) IgfsPathIsNotDirectoryException(org.apache.ignite.igfs.IgfsPathIsNotDirectoryException) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException) GridClosureException(org.apache.ignite.internal.util.lang.GridClosureException) IgfsMetaUpdateTimesProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaUpdateTimesProcessor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) TreeSet(java.util.TreeSet) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgniteException(org.apache.ignite.IgniteException)

Aggregations

IgniteException (org.apache.ignite.IgniteException)414 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)114 Ignite (org.apache.ignite.Ignite)82 ClusterNode (org.apache.ignite.cluster.ClusterNode)47 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)42 ArrayList (java.util.ArrayList)40 UUID (java.util.UUID)40 CountDownLatch (java.util.concurrent.CountDownLatch)40 IOException (java.io.IOException)32 HashMap (java.util.HashMap)32 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)31 CacheException (javax.cache.CacheException)31 Transaction (org.apache.ignite.transactions.Transaction)28 CyclicBarrier (java.util.concurrent.CyclicBarrier)21 Map (java.util.Map)20 IgniteCache (org.apache.ignite.IgniteCache)19 ClusterStartNodeResult (org.apache.ignite.cluster.ClusterStartNodeResult)18 Nullable (org.jetbrains.annotations.Nullable)18 List (java.util.List)17 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)16