Search in sources :

Example 1 with IgfsMetaDirectoryListingRemoveProcessor

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

the class IgfsMetaManager method onSuccessCreate.

/**
     * A delegate method that performs file creation in the synchronization task.
     *
     * @param fs File system.
     * @param path Path.
     * @param simpleCreate "Simple create" flag.
     * @param props Properties..
     * @param overwrite Overwrite flag.
     * @param bufSize Buffer size.
     * @param replication Replication factor.
     * @param blockSize Block size.
     * @param affKey Affinity key.
     * @param infos Map from paths to corresponding infos.
     * @param pendingEvts A non-null collection the events are to be accumulated in.
     * @param t1 A signle-object tuple to hold the created output stream.
     * @return Output stream descriptor.
     * @throws Exception On error.
     */
IgfsCreateResult onSuccessCreate(IgfsSecondaryFileSystem fs, IgfsPath path, boolean simpleCreate, @Nullable final Map<String, String> props, boolean overwrite, int bufSize, short replication, long blockSize, IgniteUuid affKey, Map<IgfsPath, IgfsEntryInfo> infos, final Deque<IgfsEvent> pendingEvts, final T1<OutputStream> t1) throws Exception {
    validTxState(true);
    assert !infos.isEmpty();
    // Determine the first existing parent.
    IgfsPath parentPath = null;
    for (IgfsPath curPath : infos.keySet()) {
        if (parentPath == null || curPath.isSubDirectoryOf(parentPath))
            parentPath = curPath;
    }
    assert parentPath != null;
    IgfsEntryInfo parentInfo = infos.get(parentPath);
    // Delegate to the secondary file system.
    OutputStream out = simpleCreate ? fs.create(path, overwrite) : fs.create(path, bufSize, overwrite, replication, blockSize, props);
    t1.set(out);
    IgfsPath parent0 = path.parent();
    assert parent0 != null : "path.parent() is null (are we creating ROOT?): " + path;
    // If some of the parent directories were missing, synchronize again.
    if (!parentPath.equals(parent0)) {
        parentInfo = synchronize(fs, parentPath, parentInfo, parent0, true, null);
        // Fire notification about missing directories creation.
        if (evts.isRecordable(EventType.EVT_IGFS_DIR_CREATED)) {
            IgfsPath evtPath = parent0;
            while (!parentPath.equals(evtPath)) {
                pendingEvts.addFirst(new IgfsEvent(evtPath, locNode, EventType.EVT_IGFS_DIR_CREATED));
                evtPath = evtPath.parent();
                // If this fails, then ROOT does not exist.
                assert evtPath != null;
            }
        }
    }
    // Get created file info.
    IgfsFile status = fs.info(path);
    if (status == null)
        throw fsException("Failed to open output stream to the file created in " + "the secondary file system because it no longer exists: " + path);
    else if (status.isDirectory())
        throw fsException("Failed to open output stream to the file created in " + "the secondary file system because the path points to a directory: " + path);
    IgfsEntryInfo newInfo = IgfsUtils.createFile(IgniteUuid.randomUuid(), igfsCtx.configuration().getBlockSize(), status.length(), affKey, createFileLockId(false), igfsCtx.igfs().evictExclude(path, false), status.properties(), status.accessTime(), status.modificationTime());
    // Add new file info to the listing optionally removing the previous one.
    assert parentInfo != null;
    IgniteUuid oldId = putIfAbsentNonTx(parentInfo.id(), path.name(), newInfo);
    if (oldId != null) {
        IgfsEntryInfo oldInfo = info(oldId);
        // Otherwise cache is in inconsistent state.
        assert oldInfo != null;
        // The contact is that we cannot overwrite a file locked for writing:
        if (oldInfo.lockId() != null)
            throw fsException("Failed to overwrite file (file is opened for writing) [path=" + path + ", fileId=" + oldId + ", lockId=" + oldInfo.lockId() + ']');
        // Remove the old one.
        id2InfoPrj.remove(oldId);
        id2InfoPrj.invoke(parentInfo.id(), new IgfsMetaDirectoryListingRemoveProcessor(path.name(), parentInfo.listing().get(path.name()).fileId()));
        // Put new one.
        createNewEntry(newInfo, parentInfo.id(), path.name());
        igfsCtx.data().delete(oldInfo);
    }
    // Record CREATE event if needed.
    if (oldId == null && evts.isRecordable(EventType.EVT_IGFS_FILE_CREATED))
        pendingEvts.add(new IgfsEvent(path, locNode, EventType.EVT_IGFS_FILE_CREATED));
    return new IgfsCreateResult(newInfo, out);
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsEvent(org.apache.ignite.events.IgfsEvent) IgniteUuid(org.apache.ignite.lang.IgniteUuid) OutputStream(java.io.OutputStream) IgfsMetaDirectoryListingRemoveProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryListingRemoveProcessor) IgfsFile(org.apache.ignite.igfs.IgfsFile)

Example 2 with IgfsMetaDirectoryListingRemoveProcessor

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

the class IgfsMetaManager method transferEntry.

/**
     * Transfer entry from one directory to another.
     *
     * @param entry Entry to be transferred.
     * @param srcId Source ID.
     * @param srcName Source name.
     * @param destId Destination ID.
     * @param destName Destination name.
     * @throws IgniteCheckedException If failed.
     */
private void transferEntry(IgfsListingEntry entry, IgniteUuid srcId, String srcName, IgniteUuid destId, String destName) throws IgniteCheckedException {
    validTxState(true);
    if (F.eq(srcId, destId))
        id2InfoPrj.invoke(srcId, new IgfsMetaDirectoryListingRenameProcessor(srcName, destName));
    else {
        Map<IgniteUuid, EntryProcessor<IgniteUuid, IgfsEntryInfo, Void>> procMap = new HashMap<>();
        procMap.put(srcId, new IgfsMetaDirectoryListingRemoveProcessor(srcName, entry.fileId()));
        procMap.put(destId, new IgfsMetaDirectoryListingAddProcessor(destName, entry));
        id2InfoPrj.invokeAll(procMap);
    }
}
Also used : IgfsMetaDirectoryListingAddProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryListingAddProcessor) EntryProcessor(javax.cache.processor.EntryProcessor) HashMap(java.util.HashMap) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgfsMetaDirectoryListingRemoveProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryListingRemoveProcessor) IgfsMetaDirectoryListingRenameProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryListingRenameProcessor)

Example 3 with IgfsMetaDirectoryListingRemoveProcessor

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

the class IgfsMetaManager method delete.

/**
     * Remove entry from the metadata listing.
     * Used solely by IgfsDeleteWorker.
     *
     * @param parentId Parent ID.
     * @param name Name.
     * @param id ID.
     * @return {@code True} in case the entry really was removed from the cache by this call.
     * @throws IgniteCheckedException If failed.
     */
boolean delete(IgniteUuid parentId, String name, IgniteUuid id) throws IgniteCheckedException {
    if (busyLock.enterBusy()) {
        try {
            validTxState(false);
            try (GridNearTxLocal tx = startTx()) {
                Map<IgniteUuid, IgfsEntryInfo> infos = lockIds(parentId, id);
                IgfsEntryInfo victim = infos.get(id);
                if (victim == null)
                    return false;
                assert victim.isDirectory() || IgfsUtils.DELETE_LOCK_ID.equals(victim.lockId()) : " isDir: " + victim.isDirectory() + ", lockId: " + victim.lockId();
                // Proceed only in case both parent and child exist.
                if (infos.containsKey(parentId) && infos.containsKey(id)) {
                    IgfsEntryInfo parentInfo = infos.get(parentId);
                    assert parentInfo != null;
                    IgfsListingEntry childEntry = parentInfo.listing().get(name);
                    if (childEntry != null)
                        id2InfoPrj.invoke(parentId, new IgfsMetaDirectoryListingRemoveProcessor(name, id));
                    id2InfoPrj.remove(id);
                    tx.commit();
                    return true;
                }
                return false;
            }
        } finally {
            busyLock.leaveBusy();
        }
    } else
        throw new IllegalStateException("Failed to perform delete because Grid is stopping [parentId=" + parentId + ", name=" + name + ", id=" + id + ']');
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgfsMetaDirectoryListingRemoveProcessor(org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryListingRemoveProcessor) GridNearTxLocal(org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)

Aggregations

IgfsMetaDirectoryListingRemoveProcessor (org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryListingRemoveProcessor)3 IgniteUuid (org.apache.ignite.lang.IgniteUuid)3 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 EntryProcessor (javax.cache.processor.EntryProcessor)1 IgfsEvent (org.apache.ignite.events.IgfsEvent)1 IgfsFile (org.apache.ignite.igfs.IgfsFile)1 IgfsPath (org.apache.ignite.igfs.IgfsPath)1 GridNearTxLocal (org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal)1 IgfsMetaDirectoryListingAddProcessor (org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryListingAddProcessor)1 IgfsMetaDirectoryListingRenameProcessor (org.apache.ignite.internal.processors.igfs.meta.IgfsMetaDirectoryListingRenameProcessor)1