Search in sources :

Example 1 with IgfsMetaUpdateTimesProcessor

use of org.apache.ignite.internal.processors.igfs.meta.IgfsMetaUpdateTimesProcessor 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

TreeSet (java.util.TreeSet)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)1 ClusterTopologyException (org.apache.ignite.cluster.ClusterTopologyException)1 IgfsConcurrentModificationException (org.apache.ignite.igfs.IgfsConcurrentModificationException)1 IgfsDirectoryNotEmptyException (org.apache.ignite.igfs.IgfsDirectoryNotEmptyException)1 IgfsException (org.apache.ignite.igfs.IgfsException)1 IgfsParentNotDirectoryException (org.apache.ignite.igfs.IgfsParentNotDirectoryException)1 IgfsPathAlreadyExistsException (org.apache.ignite.igfs.IgfsPathAlreadyExistsException)1 IgfsPathIsDirectoryException (org.apache.ignite.igfs.IgfsPathIsDirectoryException)1 IgfsPathIsNotDirectoryException (org.apache.ignite.igfs.IgfsPathIsNotDirectoryException)1 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)1 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)1 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)1 IgfsMetaUpdateTimesProcessor (org.apache.ignite.internal.processors.igfs.meta.IgfsMetaUpdateTimesProcessor)1 GridClosureException (org.apache.ignite.internal.util.lang.GridClosureException)1 IgniteUuid (org.apache.ignite.lang.IgniteUuid)1