Search in sources :

Example 1 with IgfsMetaDirectoryCreateProcessor

use of org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryCreateProcessor in project ignite by apache.

the class IgfsMetaManager method createFileOrDirectory.

/**
     * Create file or directory.
     *
     * @param dir Directory flag.
     * @param pathIds Path IDs.
     * @param lockInfos Lock infos.
     * @param dirProps Directory properties.
     * @param fileProps File properties.
     * @param blockSize Block size.
     * @param affKey Affinity key.
     * @param evictExclude Evict exclude flag.
     * @param secondaryCtx Secondary file system create context.
     * @param secondaryOutHolder Secondary output stream holder.
     * @return Result.
     * @throws IgniteCheckedException If failed.
     */
@SuppressWarnings("unchecked")
private IgfsPathsCreateResult createFileOrDirectory(boolean dir, IgfsPathIds pathIds, Map<IgniteUuid, IgfsEntryInfo> lockInfos, Map<String, String> dirProps, Map<String, String> fileProps, int blockSize, @Nullable IgniteUuid affKey, boolean evictExclude, @Nullable IgfsSecondaryFileSystemCreateContext secondaryCtx, @Nullable T1<OutputStream> secondaryOutHolder) throws IgniteCheckedException {
    // This is our starting point.
    int lastExistingIdx = pathIds.lastExistingIndex();
    IgfsEntryInfo lastExistingInfo = lockInfos.get(pathIds.lastExistingId());
    // If current info already contains entry with the same name as it's child, then something
    // has changed concurrently. We must re-try because we cannot get info of this unexpected
    // element due to possible deadlocks.
    int curIdx = lastExistingIdx + 1;
    String curPart = pathIds.part(curIdx);
    IgniteUuid curId = pathIds.surrogateId(curIdx);
    if (lastExistingInfo.hasChild(curPart))
        return null;
    // Create entry in the secondary file system if needed.
    if (secondaryCtx != null) {
        assert secondaryOutHolder != null;
        secondaryOutHolder.set(secondaryCtx.create());
    }
    Map<IgniteUuid, EntryProcessor> procMap = new HashMap<>();
    // First step: add new entry to the last existing element.
    procMap.put(lastExistingInfo.id(), new IgfsMetaDirectoryListingAddProcessor(curPart, new IgfsListingEntry(curId, dir || !pathIds.isLastIndex(curIdx))));
    // Events support.
    IgfsPath lastCreatedPath = pathIds.lastExistingPath();
    List<IgfsPath> createdPaths = new ArrayList<>(pathIds.count() - curIdx);
    // Second step: create middle directories.
    long curTime = System.currentTimeMillis();
    while (curIdx < pathIds.count() - 1) {
        lastCreatedPath = new IgfsPath(lastCreatedPath, curPart);
        int nextIdx = curIdx + 1;
        String nextPart = pathIds.part(nextIdx);
        IgniteUuid nextId = pathIds.surrogateId(nextIdx);
        long accessTime;
        long modificationTime;
        Map<String, String> props;
        if (secondaryCtx != null) {
            accessTime = 0L;
            modificationTime = 0L;
            props = null;
        } else {
            accessTime = curTime;
            modificationTime = curTime;
            props = dirProps;
        }
        procMap.put(curId, new IgfsMetaDirectoryCreateProcessor(accessTime, modificationTime, props, nextPart, new IgfsListingEntry(nextId, dir || !pathIds.isLastIndex(nextIdx))));
        // Save event.
        createdPaths.add(lastCreatedPath);
        // Advance things further.
        curIdx++;
        curPart = nextPart;
        curId = nextId;
    }
    // Third step: create leaf.
    if (dir) {
        long accessTime;
        long modificationTime;
        Map<String, String> props;
        if (secondaryCtx != null) {
            accessTime = 0L;
            modificationTime = 0L;
            props = null;
        } else {
            accessTime = curTime;
            modificationTime = curTime;
            props = dirProps;
        }
        procMap.put(curId, new IgfsMetaDirectoryCreateProcessor(accessTime, modificationTime, props));
    } else {
        long newAccessTime;
        long newModificationTime;
        Map<String, String> newProps;
        long newLen;
        int newBlockSize;
        if (secondaryCtx != null) {
            newAccessTime = 0L;
            newModificationTime = 0L;
            newProps = null;
        } else {
            newAccessTime = curTime;
            newModificationTime = curTime;
            newProps = fileProps;
        }
        newLen = 0L;
        newBlockSize = blockSize;
        procMap.put(curId, new IgfsMetaFileCreateProcessor(newAccessTime, newModificationTime, newProps, newBlockSize, affKey, createFileLockId(false), evictExclude, newLen));
    }
    createdPaths.add(pathIds.path());
    // Execute cache operations.
    Map<Object, EntryProcessorResult> invokeRes = ((IgniteInternalCache) id2InfoPrj).invokeAll(procMap);
    IgfsEntryInfo info = (IgfsEntryInfo) invokeRes.get(curId).get();
    return new IgfsPathsCreateResult(createdPaths, info);
}
Also used : IgfsMetaDirectoryListingAddProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryListingAddProcessor) HashMap(java.util.HashMap) IgfsMetaFileCreateProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaFileCreateProcessor) ArrayList(java.util.ArrayList) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) IgfsPath(org.apache.ignite.igfs.IgfsPath) EntryProcessor(javax.cache.processor.EntryProcessor) EntryProcessorResult(javax.cache.processor.EntryProcessorResult) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgfsMetaDirectoryCreateProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryCreateProcessor)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 EntryProcessor (javax.cache.processor.EntryProcessor)1 EntryProcessorResult (javax.cache.processor.EntryProcessorResult)1 IgfsPath (org.apache.ignite.igfs.IgfsPath)1 IgniteInternalCache (org.apache.ignite.internal.processors.cache.IgniteInternalCache)1 IgfsMetaDirectoryCreateProcessor (org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryCreateProcessor)1 IgfsMetaDirectoryListingAddProcessor (org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryListingAddProcessor)1 IgfsMetaFileCreateProcessor (org.apache.ignite.internal.processors.igfs.meta.IgfsMetaFileCreateProcessor)1 IgniteUuid (org.apache.ignite.lang.IgniteUuid)1