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

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


                GridGgfsMode mode = modeRslvr.resolveMode(path);

                if (mode == PROXY)
                    throw new GridException("PROXY mode cannot be used in GGFS directly: " + path);

                GridGgfsFileInfo info = resolveFileInfo(path, mode);

                if (info == null)
                    return null;

                return new GridGgfsFileImpl(path, info, data.groupBlockSize());
View Full Code Here


                else if (mode != PRIMARY) {
                    assert mode == DUAL_SYNC || mode == DUAL_ASYNC;

                    await(path);

                    GridGgfsFileInfo info = meta.updateDual(secondaryFs, path, props);

                    if (info == null)
                        return null;

                    return new GridGgfsFileImpl(path, info, data.groupBlockSize());
                }

                List<GridUuid> fileIds = meta.fileIds(path);

                GridUuid fileId = fileIds.get(fileIds.size() - 1);

                if (fileId == null)
                    return null;

                GridUuid parentId = fileIds.size() > 1 ? fileIds.get(fileIds.size() - 2) : null;

                GridGgfsFileInfo info = meta.updateProperties(parentId, fileId, path.name(), props);

                if (info != null) {
                    if (evts.isRecordable(EVT_GGFS_META_UPDATED))
                        evts.record(new GridGgfsEvent(path, localNode(), EVT_GGFS_META_UPDATED, props));
View Full Code Here

                for (int step = 0, size = components.size(); step < size; step++) {
                    GridUuid fileId = ids.get(step + 1); // Skip the first ROOT element.

                    if (fileId == null) {
                        GridGgfsFileInfo fileInfo = new GridGgfsFileInfo(true, props); // Create new directory.

                        String fileName = components.get(step); // Get current component name.

                        curPath = new GridGgfsPath(curPath, fileName);

                        try {
                            // Fails only if parent is not a directory or if modified concurrently.
                            GridUuid oldId = meta.putIfAbsent(parentId, fileName, fileInfo);

                            fileId = oldId == null ? fileInfo.id() : oldId; // Update node ID.

                            if (oldId == null && evts.isRecordable(EVT_GGFS_DIR_CREATED))
                                evts.record(new GridGgfsEvent(curPath, localNode(), EVT_GGFS_DIR_CREATED));
                        }
                        catch (GridException e) {
                            if (log.isDebugEnabled())
                                log.debug("Failed to create directory [path=" + path + ", parentId=" + parentId +
                                    ", fileName=" + fileName + ", step=" + step + ", e=" + e.getMessage() + ']');

                            // Check directory with such name already exists.
                            GridGgfsFileInfo stored = meta.info(meta.fileId(parentId, fileName));

                            if (stored == null)
                                throw new GridGgfsException(e);

                            if (!stored.isDirectory())
                                throw new GridGgfsParentNotDirectoryException("Failed to create directory (parent " +
                                    "element is not a directory)");

                            fileId = stored.id(); // Update node ID.
                        }
                    }

                    assert fileId != null;
View Full Code Here

                    assert secondaryFs != null;

                    Collection<GridGgfsFile> children = secondaryFs.listFiles(path);

                    for (GridGgfsFile child : children) {
                        GridGgfsFileInfo fsInfo = new GridGgfsFileInfo(cfg.getBlockSize(), child.length(),
                            evictExclude(path, false), child.properties());

                        files.add(new GridGgfsFileImpl(child.path(), fsInfo, data.groupBlockSize()));
                    }
                }

                GridUuid fileId = meta.fileId(path);

                if (fileId != null) {
                    GridGgfsFileInfo info = meta.info(fileId);

                    // Handle concurrent deletion.
                    if (info != null) {
                        if (info.isFile())
                            // If this is a file, return its description.
                            return Collections.<GridGgfsFile>singleton(new GridGgfsFileImpl(path, info,
                                data.groupBlockSize()));

                        // Perform the listing.
                        for (Map.Entry<String, GridGgfsListingEntry> e : info.listing().entrySet()) {
                            GridGgfsPath p = new GridGgfsPath(path, e.getKey());

                            files.add(new GridGgfsFileImpl(p, e.getValue(), data.groupBlockSize()));
                        }
                    }
View Full Code Here

                        evts.record(new GridGgfsEvent(path, localNode(), EVT_GGFS_FILE_OPENED_READ));

                    return os;
                }

                GridGgfsFileInfo info = meta.info(meta.fileId(path));

                if (info == null) {
                    checkConflictWithPrimary(path);

                    throw new GridGgfsFileNotFoundException("File not found: " + path);
                }

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

                // Input stream to read data from grid cache with separate blocks.
                GgfsEventAwareInputStream os = new GgfsEventAwareInputStream(ggfsCtx, path, info,
                    cfg.getPrefetchBlocks(), seqReadsBeforePrefetch, null, metrics);
View Full Code Here

                    throw new GridGgfsInvalidPathException("Failed to resolve parent directory: " + path);

                String fileName = path.name();

                // Constructs new file info.
                GridGgfsFileInfo info = new GridGgfsFileInfo(cfg.getBlockSize(), affKey, evictExclude(path, true),
                    props);

                // Add new file into tree structure.
                while (true) {
                    GridUuid oldId = meta.putIfAbsent(parentId, fileName, info);

                    if (oldId == null)
                        break;

                    if (!overwrite)
                        throw new GridGgfsPathAlreadyExistsException("Failed to create file (file already exists): " +
                            path);

                    GridGgfsFileInfo oldInfo = meta.info(oldId);

                    if (oldInfo.isDirectory())
                        throw new GridGgfsPathAlreadyExistsException("Failed to create file (path points to a " +
                            "directory): " + path);

                    // Remove old file from the tree.
                    // Only one file is deleted, so we use internal data loader.
                    deleteFile(path, new FileDescriptor(parentId, fileName, oldId, oldInfo.isFile()), false);

                    if (evts.isRecordable(EVT_GGFS_FILE_DELETED))
                        evts.record(new GridGgfsEvent(path, localNode(), EVT_GGFS_FILE_DELETED));
                }
View Full Code Here

                        bufSize == 0 ? cfg.getStreamBufferSize() : bufSize, mode, batch);
                }

                List<GridUuid> ids = meta.fileIds(path);

                GridGgfsFileInfo info = meta.info(ids.get(ids.size() - 1));

                // Resolve parent ID for the file.
                GridUuid parentId = ids.size() >= 2 ? ids.get(ids.size() - 2) : null;

                if (info == null) {
                    if (!create) {
                        checkConflictWithPrimary(path);

                        throw new GridGgfsFileNotFoundException("File not found: " + path);
                    }

                    if (parentId == null)
                        throw new GridGgfsInvalidPathException("Failed to resolve parent directory: " + path);

                    info = new GridGgfsFileInfo(cfg.getBlockSize(), /**affinity key*/null, evictExclude(path,
                        mode == PRIMARY), props);

                    GridUuid oldId = meta.putIfAbsent(parentId, path.name(), info);

                    if (oldId != null)
                        info = meta.info(oldId);

                    if (evts.isRecordable(EVT_GGFS_FILE_CREATED))
                        evts.record(new GridGgfsEvent(path, localNode(), EVT_GGFS_FILE_CREATED));
                }

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

                info = meta.lock(info.id());

                if (evts.isRecordable(EVT_GGFS_FILE_OPENED_WRITE))
                    evts.record(new GridGgfsEvent(path, localNode(), EVT_GGFS_FILE_OPENED_WRITE));

                return new GgfsEventAwareOutputStream(path, info, parentId, bufSize == 0 ?
View Full Code Here

                if (mode == PROXY)
                    throw new GridException("PROXY mode cannot be used in GGFS directly: " + path);

                // Check memory first.
                GridUuid fileId = meta.fileId(path);
                GridGgfsFileInfo info = meta.info(fileId);

                if (info == null && mode != PRIMARY) {
                    assert mode == DUAL_SYNC || mode == DUAL_ASYNC;
                    assert secondaryFs != null;

                    // Synchronize
                    info = meta.synchronizeFileDual(secondaryFs, path);
                }

                if (info == null)
                    throw new GridGgfsFileNotFoundException("File not found: " + path);

                if (!info.isFile())
                    throw new GridGgfsInvalidPathException("Failed to get affinity info for file (not a file): " +
                        path);

                return data.affinity(info, start, len, maxLen);
            }
View Full Code Here

     * @throws GridException If failed.
     */
    private void summary0(GridUuid fileId, GridGgfsPathSummary sum) throws GridException {
        assert sum != null;

        GridGgfsFileInfo info = meta.info(fileId);

        if (info != null) {
            if (info.isDirectory()) {
                if (!ROOT_ID.equals(info.id()))
                    sum.directoriesCount(sum.directoriesCount() + 1);

                for (GridGgfsListingEntry entry : info.listing().values())
                    summary0(entry.fileId(), sum);
            }
            else {
                sum.filesCount(sum.filesCount() + 1);
                sum.totalLength(sum.totalLength() + info.length());
            }
        }
    }
View Full Code Here

     * @return Detailed file descriptor or {@code null}, if file does not exist.
     * @throws GridException If failed.
     */
    @Nullable private FileDescriptor getFileDescriptor(GridGgfsPath path) throws GridException {
        List<GridUuid> ids = meta.fileIds(path);
        GridGgfsFileInfo fileInfo = meta.info(ids.get(ids.size() - 1));

        if (fileInfo == null)
            return null; // File does not exist.

        // Resolve parent ID for removed file.
        GridUuid parentId = ids.size() >= 2 ? ids.get(ids.size() - 2) : null;

        return new FileDescriptor(parentId, path.name(), fileInfo.id(), fileInfo.isFile());
    }
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.