Package org.gridgain.grid.kernal.processors.ggfs

Examples of org.gridgain.grid.kernal.processors.ggfs.GridGgfsFileInfo


        if (log.isDebugEnabled())
            log.debug("Update file properties [fileId=" + fileId + ", props=" + props + ']');

        try {
            GridGgfsFileInfo oldInfo;
            GridGgfsFileInfo parentInfo;

            // Lock file ID for this transaction.
            if (parentId == null) {
                oldInfo = info(fileId);
                parentInfo = null;
            }
            else {
                Map<GridUuid, GridGgfsFileInfo> locked = lockIds(parentId, fileId);

                oldInfo = locked.get(fileId);
                parentInfo = locked.get(parentId);

                if (parentInfo == null)
                    return null; // Parent not found.
            }

            assert validTxState(true);

            if (oldInfo == null)
                return null; // File not found.

            if (parentInfo != null) {
                Map<String, GridGgfsListingEntry> listing = parentInfo.listing();

                GridGgfsListingEntry entry = listing.get(fileName);

                if (entry == null || !entry.fileId().equals(fileId)) // File was removed or recreated.
                    return null;
            }

            Map<String, String> tmp = oldInfo.properties();

            tmp = tmp == null ? new GridLeanMap<String, String>(props.size()) : new GridLeanMap<>(tmp);

            for (Map.Entry<String, String> e : props.entrySet()) {
                if (e.getValue() == null)
                    // Remove properties with 'null' values.
                    tmp.remove(e.getKey());
                else
                    // Add/overwrite property.
                    tmp.put(e.getKey(), e.getValue());
            }

            GridGgfsFileInfo newInfo = new GridGgfsFileInfo(oldInfo, tmp);

            id2InfoPrj.putx(fileId, newInfo);

            if (parentId != null) {
                GridGgfsListingEntry entry = new GridGgfsListingEntry(newInfo);
View Full Code Here


                assert validTxState(false);

                GridCacheTx tx = metaCache.txStart(PESSIMISTIC, REPEATABLE_READ);

                try {
                    GridGgfsFileInfo info = updatePropertiesNonTx(parentId, fileId, fileName, props);

                    tx.commit();

                    return info;
                }
View Full Code Here

                GridCacheTx tx = metaCache.isLockedByThread(fileId) ? null : metaCache.txStart(PESSIMISTIC,
                    REPEATABLE_READ);

                try {
                    // Lock file ID for this transaction.
                    GridGgfsFileInfo oldInfo = info(fileId);

                    if (oldInfo == null)
                        return null; // File not found.

                    GridGgfsFileInfo newInfo = c.apply(oldInfo);

                    if (newInfo == null)
                        throw new GridGgfsException("Failed to update file info with null value" +
                            " [oldInfo=" + oldInfo + ", newInfo=" + newInfo + ", c=" + c + ']');

                    if (!oldInfo.id().equals(newInfo.id()))
                        throw new GridGgfsException("Failed to update file info (file IDs differ)" +
                            " [oldInfo=" + oldInfo + ", newInfo=" + newInfo + ", c=" + c + ']');

                    if (oldInfo.isDirectory() != newInfo.isDirectory())
                        throw new GridGgfsException("Failed to update file info (file types differ)" +
                            " [oldInfo=" + oldInfo + ", newInfo=" + newInfo + ", c=" + c + ']');

                    boolean b = metaCache.replace(fileId, oldInfo, newInfo);
View Full Code Here

                                    parentPath = curPath;
                            }

                            assert parentPath != null;

                            GridGgfsFileInfo parentInfo = infos.get(parentPath);

                            // Delegate to the secondary file system.
                            out = simpleCreate ? fs.create(path, overwrite) :
                                fs.create(path, bufSize, overwrite, replication, blockSize, props);

                            GridGgfsPath 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(EVT_GGFS_DIR_CREATED)) {
                                    GridGgfsPath evtPath = parent0;

                                    while (!parentPath.equals(evtPath)) {
                                        pendingEvts.addFirst(new GridGgfsEvent(evtPath, locNode, EVT_GGFS_DIR_CREATED));

                                        evtPath = evtPath.parent();

                                        assert evtPath != null; // If this fails, then ROOT does not exist.
                                    }
                                }
                            }

                            // Get created file info.
                            GridGgfsFile status = fs.info(path);

                            if (status == null)
                                throw new GridGgfsException("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 new GridGgfsException("Failed to open output stream to the file created in " +
                                    "the secondary file system because the path points to a directory: " + path);

                            GridGgfsFileInfo newInfo = new GridGgfsFileInfo(status.blockSize(), status.length(), affKey,
                                GridUuid.randomUuid(), ggfsCtx.ggfs().evictExclude(path, false), status.properties());

                            // Add new file info to the listing optionally removing the previous one.
                            GridUuid oldId = putIfAbsentNonTx(parentInfo.id(), path.name(), newInfo);

                            if (oldId != null) {
                                GridGgfsFileInfo oldInfo = info(oldId);

                                id2InfoPrj.removex(oldId); // Remove the old one.
                                id2InfoPrj.putx(newInfo.id(), newInfo); // Put the new one.

                                id2InfoPrj.transform(parentInfo.id(),
View Full Code Here

                        /** Output stream to the secondary file system. */
                        private OutputStream out;

                        @Override public GridGgfsSecondaryOutputStreamDescriptor onSuccess(Map<GridGgfsPath,
                            GridGgfsFileInfo> infos) throws Exception {
                            GridGgfsFileInfo info = infos.get(path);

                            if (info.isDirectory())
                                throw new GridGgfsException("Failed to open output stream to the file in the " +
                                    "secondary file system because the path points to a directory: " + path);

                            out = fs.append(path, bufSize, false, null);

                            // Synchronize file ending.
                            long len = info.length();
                            int blockSize = info.blockSize();

                            int remainder = (int)(len % blockSize);

                            if (remainder > 0) {
                                int blockIdx = (int)(len / blockSize);

                                GridGgfsReader reader = fs.open(path, bufSize);

                                try {
                                    ggfsCtx.data().dataBlock(info, path, blockIdx, reader).get();
                                }
                                finally {
                                    reader.close();
                                }
                            }

                            // Set lock and return.
                            info = lockInfo(info);

                            metaCache.putx(info.id(), info);

                            return new GridGgfsSecondaryOutputStreamDescriptor(infos.get(path.parent()).id(), info, out);
                        }

                        @Override public GridGgfsSecondaryOutputStreamDescriptor onFailure(@Nullable Exception err)
View Full Code Here

            try {
                assert fs != null;
                assert path != null;

                // First, try getting file info without any transactions and synchronization.
                GridGgfsFileInfo info = info(fileId(path));

                if (info != null) {
                    if (!info.isFile())
                        throw new GridGgfsInvalidPathException("Failed to open file (not a file): " + path);

                    return new GridGgfsSecondaryInputStreamDescriptor(info, fs.open(path, bufSize));
                }

                // If failed, try synchronize.
                SynchronizationTask<GridGgfsSecondaryInputStreamDescriptor> task =
                    new SynchronizationTask<GridGgfsSecondaryInputStreamDescriptor>() {
                        @Override public GridGgfsSecondaryInputStreamDescriptor onSuccess(
                            Map<GridGgfsPath, GridGgfsFileInfo> infos) throws Exception {
                            GridGgfsFileInfo info = infos.get(path);

                            if (info == null)
                                throw new GridGgfsFileNotFoundException("File not found: " + path);
                            if (!info.isFile())
                                throw new GridGgfsInvalidPathException("Failed to open file (not a file): " + path);

                            return new GridGgfsSecondaryInputStreamDescriptor(infos.get(path), fs.open(path, bufSize));
                        }
View Full Code Here

        assert path != null;

        if (busyLock.enterBusy()) {
            try {
                // First, try getting file info without any transactions and synchronization.
                GridGgfsFileInfo info = info(fileId(path));

                if (info != null)
                    return info;

                // If failed, try synchronize.
View Full Code Here

                                parentPath = curPath;
                        }

                        assert parentPath != null;

                        GridGgfsFileInfo parentPathInfo = infos.get(parentPath);

                        synchronize(fs, parentPath, parentPathInfo, path, true, null);

                        if (evts.isRecordable(EVT_GGFS_DIR_CREATED)) {
                            GridGgfsPath evtPath = path;
View Full Code Here

                // Events to fire (can be done outside of a transaction).
                final Collection<GridGgfsEvent> pendingEvts = new LinkedList<>();

                SynchronizationTask<Boolean> task = new SynchronizationTask<Boolean>() {
                    @Override public Boolean onSuccess(Map<GridGgfsPath, GridGgfsFileInfo> infos) throws Exception {
                        GridGgfsFileInfo srcInfo = infos.get(src);
                        GridGgfsFileInfo srcParentInfo = infos.get(src.parent());
                        GridGgfsFileInfo destInfo = infos.get(dest);
                        GridGgfsFileInfo destParentInfo = dest.parent() != null ? infos.get(dest.parent()) : null;

                        // Source path and destination (or destination parent) must exist.
                        if (srcInfo == null)
                            throw new GridGgfsFileNotFoundException("Failed to rename (source path not found): " + src);

                        if (destInfo == null && destParentInfo == null)
                            throw new GridGgfsFileNotFoundException("Failed to rename (destination path not found): " +
                                dest);

                        // Delegate to the secondary file system.
                        fs.rename(src, dest);

                        // Rename was successful, perform compensation in the local file system.
                        if (destInfo == null) {
                            // Move and rename.
                            assert destParentInfo != null;

                            moveNonTx(srcInfo.id(), src.name(), srcParentInfo.id(), dest.name(), destParentInfo.id());
                        }
                        else {
                            // Move.
                            if (destInfo.isFile())
                                throw new GridGgfsException("Failed to rename the path in the local file system " +
View Full Code Here

                assert fs != null;
                assert path != null;

                SynchronizationTask<Boolean> task = new SynchronizationTask<Boolean>() {
                    @Override public Boolean onSuccess(Map<GridGgfsPath, GridGgfsFileInfo> infos) throws Exception {
                        GridGgfsFileInfo info = infos.get(path);

                        if (info == null)
                            return false; // File doesn't exist in the secondary file system.

                        if (!fs.delete(path, recursive))
                            return false; // Delete failed remotely.

                        if (path.parent() != null) {
                            assert infos.containsKey(path.parent());

                            softDeleteNonTx(infos.get(path.parent()).id(), path.name(), info.id());
                        }
                        else {
                            assert ROOT_ID.equals(info.id());

                            softDeleteNonTx(null, path.name(), info.id());
                        }

                        // Update the deleted file info with path information for delete worker.
                        id2InfoPrj.transform(info.id(), new UpdatePath(path));

                        return true; // No additional handling is required.
                    }

                    @Override public Boolean onFailure(@Nullable Exception err) throws GridException {
View Full Code Here

TOP

Related Classes of org.gridgain.grid.kernal.processors.ggfs.GridGgfsFileInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.