Search in sources :

Example 11 with IgfsMode

use of org.apache.ignite.igfs.IgfsMode in project ignite by apache.

the class IgfsModeResolverSelfTest method testCanContain.

/**
     * @throws Exception If failed.
     */
public void testCanContain() throws Exception {
    for (IgfsMode m : IgfsMode.values()) {
        // Each mode can contain itself:
        assertTrue(IgfsUtils.canContain(m, m));
        // PRIMARY and PROXY can contain itself only:
        assertTrue(IgfsUtils.canContain(PRIMARY, m) == (m == PRIMARY));
        assertTrue(IgfsUtils.canContain(PROXY, m) == (m == PROXY));
        // Any mode but PRIMARY & PROXY can contain any mode:
        if (m != PRIMARY && m != PROXY)
            for (IgfsMode n : IgfsMode.values()) assertTrue(IgfsUtils.canContain(m, n));
    }
}
Also used : IgfsMode(org.apache.ignite.igfs.IgfsMode)

Example 12 with IgfsMode

use of org.apache.ignite.igfs.IgfsMode in project ignite by apache.

the class IgfsImpl method open.

/** {@inheritDoc} */
@Override
public IgfsInputStream open(final IgfsPath path, final int bufSize, final int seqReadsBeforePrefetch) {
    A.notNull(path, "path");
    A.ensure(bufSize >= 0, "bufSize >= 0");
    A.ensure(seqReadsBeforePrefetch >= 0, "seqReadsBeforePrefetch >= 0");
    return safeOp(new Callable<IgfsInputStream>() {

        @Override
        public IgfsInputStream call() throws Exception {
            if (log.isDebugEnabled())
                log.debug("Open file for reading [path=" + path + ", bufSize=" + bufSize + ']');
            int bufSize0 = bufSize == 0 ? cfg.getBufferSize() : bufSize;
            IgfsMode mode = resolveMode(path);
            switch(mode) {
                case PRIMARY:
                    {
                        IgfsEntryInfo info = meta.infoForPath(path);
                        if (info == null)
                            throw new IgfsPathNotFoundException("File not found: " + path);
                        if (!info.isFile())
                            throw new IgfsPathIsDirectoryException("Failed to open file (not a file): " + path);
                        // Input stream to read data from grid cache with separate blocks.
                        IgfsInputStreamImpl os = new IgfsInputStreamImpl(igfsCtx, path, info, cfg.getPrefetchBlocks(), seqReadsBeforePrefetch, null, info.length(), info.blockSize(), info.blocksCount(), false);
                        IgfsUtils.sendEvents(igfsCtx.kernalContext(), path, EVT_IGFS_FILE_OPENED_READ);
                        return os;
                    }
                case DUAL_ASYNC:
                case DUAL_SYNC:
                    {
                        assert IgfsUtils.isDualMode(mode);
                        IgfsSecondaryInputStreamDescriptor desc = meta.openDual(secondaryFs, path, bufSize0);
                        IgfsEntryInfo info = desc.info();
                        IgfsInputStreamImpl os = new IgfsInputStreamImpl(igfsCtx, path, info, cfg.getPrefetchBlocks(), seqReadsBeforePrefetch, desc.reader(), info.length(), info.blockSize(), info.blocksCount(), false);
                        IgfsUtils.sendEvents(igfsCtx.kernalContext(), path, EVT_IGFS_FILE_OPENED_READ);
                        return os;
                    }
                case PROXY:
                    {
                        assert secondaryFs != null;
                        IgfsFile info = info(path);
                        if (info == null)
                            throw new IgfsPathNotFoundException("File not found: " + path);
                        if (!info.isFile())
                            throw new IgfsPathIsDirectoryException("Failed to open file (not a file): " + path);
                        IgfsSecondaryFileSystemPositionedReadable secReader = new IgfsLazySecondaryFileSystemPositionedReadable(secondaryFs, path, bufSize);
                        long len = info.length();
                        int blockSize = info.blockSize() > 0 ? info.blockSize() : cfg.getBlockSize();
                        long blockCnt = len / blockSize;
                        if (len % blockSize != 0)
                            blockCnt++;
                        IgfsInputStream os = new IgfsInputStreamImpl(igfsCtx, path, null, cfg.getPrefetchBlocks(), seqReadsBeforePrefetch, secReader, info.length(), blockSize, blockCnt, true);
                        IgfsUtils.sendEvents(igfsCtx.kernalContext(), path, EVT_IGFS_FILE_OPENED_READ);
                        return os;
                    }
                default:
                    assert false : "Unexpected mode " + mode;
                    return null;
            }
        }
    });
}
Also used : IgfsInputStream(org.apache.ignite.igfs.IgfsInputStream) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException) IgfsPathIsDirectoryException(org.apache.ignite.igfs.IgfsPathIsDirectoryException) IgfsInvalidPathException(org.apache.ignite.igfs.IgfsInvalidPathException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgfsException(org.apache.ignite.igfs.IgfsException) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException) IgfsMode(org.apache.ignite.igfs.IgfsMode) IgfsSecondaryFileSystemPositionedReadable(org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystemPositionedReadable) IgfsFile(org.apache.ignite.igfs.IgfsFile) IgfsPathIsDirectoryException(org.apache.ignite.igfs.IgfsPathIsDirectoryException)

Example 13 with IgfsMode

use of org.apache.ignite.igfs.IgfsMode in project ignite by apache.

the class IgfsImpl method rename.

/** {@inheritDoc} */
@Override
public void rename(final IgfsPath src, final IgfsPath dest) {
    A.notNull(src, "src");
    A.notNull(dest, "dest");
    if (meta.isClient()) {
        meta.runClientTask(new IgfsClientRenameCallable(cfg.getName(), IgfsUserContext.currentUser(), src, dest));
        return;
    }
    safeOp(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            if (log.isDebugEnabled())
                log.debug("Rename file [src=" + src + ", dest=" + dest + ']');
            IgfsMode mode = resolveMode(src);
            if (src.equals(dest))
                // Rename to itself is a no-op.
                return null;
            // Cannot rename root directory.
            if (src.parent() == null)
                throw new IgfsInvalidPathException("Root directory cannot be renamed.");
            // Cannot move directory of upper level to self sub-dir.
            if (dest.isSubDirectoryOf(src))
                throw new IgfsInvalidPathException("Failed to rename directory (cannot move directory of " + "upper level to self sub-dir) [src=" + src + ", dest=" + dest + ']');
            if (evictExclude(src, mode == PRIMARY) != evictExclude(dest, modeRslvr.resolveMode(dest) == PRIMARY))
                throw new IgfsInvalidPathException("Cannot move file to a path with different eviction " + "exclude setting (need to copy and remove)");
            switch(mode) {
                case PRIMARY:
                    meta.move(src, dest);
                    break;
                case DUAL_ASYNC:
                case DUAL_SYNC:
                    await(src, dest);
                    meta.renameDual(secondaryFs, src, dest);
                    break;
                default:
                    assert mode == PROXY : "Unknown mode: " + mode;
                    secondaryFs.rename(src, dest);
                    break;
            }
            return null;
        }
    });
}
Also used : IgfsMode(org.apache.ignite.igfs.IgfsMode) IgfsClientRenameCallable(org.apache.ignite.internal.processors.igfs.client.IgfsClientRenameCallable) IgfsInvalidPathException(org.apache.ignite.igfs.IgfsInvalidPathException) IgfsPathIsDirectoryException(org.apache.ignite.igfs.IgfsPathIsDirectoryException) IgfsInvalidPathException(org.apache.ignite.igfs.IgfsInvalidPathException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgfsException(org.apache.ignite.igfs.IgfsException) IgfsPathNotFoundException(org.apache.ignite.igfs.IgfsPathNotFoundException)

Example 14 with IgfsMode

use of org.apache.ignite.igfs.IgfsMode in project ignite by apache.

the class IgfsUtils method validateLocalIgfsConfigurations.

/**
     * Validates local IGFS configurations. Compares attributes only for IGFSes with same name.
     *
     * @param igniteCfg Ignite config.
     * @throws IgniteCheckedException If any of IGFS configurations is invalid.
     */
private static void validateLocalIgfsConfigurations(IgniteConfiguration igniteCfg) throws IgniteCheckedException {
    if (igniteCfg.getFileSystemConfiguration() == null || igniteCfg.getFileSystemConfiguration().length == 0)
        return;
    Collection<String> cfgNames = new HashSet<>();
    for (FileSystemConfiguration cfg : igniteCfg.getFileSystemConfiguration()) {
        String name = cfg.getName();
        if (name == null)
            throw new IgniteCheckedException("IGFS name cannot be null");
        if (cfgNames.contains(name))
            throw new IgniteCheckedException("Duplicate IGFS name found (check configuration and " + "assign unique name to each): " + name);
        CacheConfiguration ccfgData = cfg.getDataCacheConfiguration();
        CacheConfiguration ccfgMeta = cfg.getMetaCacheConfiguration();
        if (QueryUtils.isEnabled(ccfgData))
            throw new IgniteCheckedException("IGFS data cache cannot start with enabled query indexing.");
        if (QueryUtils.isEnabled(ccfgMeta))
            throw new IgniteCheckedException("IGFS metadata cache cannot start with enabled query indexing.");
        if (ccfgMeta.getAtomicityMode() != TRANSACTIONAL)
            throw new IgniteCheckedException("IGFS metadata cache should be transactional: " + cfg.getName());
        if (!(ccfgData.getAffinityMapper() instanceof IgfsGroupDataBlocksKeyMapper))
            throw new IgniteCheckedException("Invalid IGFS data cache configuration (key affinity mapper class should be " + IgfsGroupDataBlocksKeyMapper.class.getSimpleName() + "): " + cfg);
        IgfsIpcEndpointConfiguration ipcCfg = cfg.getIpcEndpointConfiguration();
        if (ipcCfg != null) {
            final int tcpPort = ipcCfg.getPort();
            if (!(tcpPort >= MIN_TCP_PORT && tcpPort <= MAX_TCP_PORT))
                throw new IgniteCheckedException("IGFS endpoint TCP port is out of range [" + MIN_TCP_PORT + ".." + MAX_TCP_PORT + "]: " + tcpPort);
            if (ipcCfg.getThreadCount() <= 0)
                throw new IgniteCheckedException("IGFS endpoint thread count must be positive: " + ipcCfg.getThreadCount());
        }
        boolean secondary = cfg.getDefaultMode() == IgfsMode.PROXY;
        if (cfg.getPathModes() != null) {
            for (Map.Entry<String, IgfsMode> mode : cfg.getPathModes().entrySet()) {
                if (mode.getValue() == IgfsMode.PROXY)
                    secondary = true;
            }
        }
        if (secondary && cfg.getSecondaryFileSystem() == null) {
            // When working in any mode except of primary, secondary FS config must be provided.
            throw new IgniteCheckedException("Grid configuration parameter invalid: " + "secondaryFileSystem cannot be null when mode is not " + IgfsMode.PRIMARY);
        }
        cfgNames.add(name);
    }
}
Also used : IgfsGroupDataBlocksKeyMapper(org.apache.ignite.igfs.IgfsGroupDataBlocksKeyMapper) IgfsIpcEndpointConfiguration(org.apache.ignite.igfs.IgfsIpcEndpointConfiguration) IgfsMode(org.apache.ignite.igfs.IgfsMode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Map(java.util.Map) HashMap(java.util.HashMap) FileSystemConfiguration(org.apache.ignite.configuration.FileSystemConfiguration) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) HashSet(java.util.HashSet)

Example 15 with IgfsMode

use of org.apache.ignite.igfs.IgfsMode in project ignite by apache.

the class IgfsUtils method preparePathModes.

/**
     * Checks, filters and sorts the modes.
     *
     * @param dfltMode The root mode. Must always be not null.
     * @param modes The subdirectory modes.
     * @param dualParentsContainingPrimaryChildren The set to store parents into.
     * @return Descending list of filtered and checked modes.
     * @throws IgniteCheckedException On error.
     */
public static ArrayList<T2<IgfsPath, IgfsMode>> preparePathModes(final IgfsMode dfltMode, @Nullable List<T2<IgfsPath, IgfsMode>> modes, Set<IgfsPath> dualParentsContainingPrimaryChildren) throws IgniteCheckedException {
    if (modes == null)
        return null;
    // Sort by depth, shallow first.
    Collections.sort(modes, new Comparator<Map.Entry<IgfsPath, IgfsMode>>() {

        @Override
        public int compare(Map.Entry<IgfsPath, IgfsMode> o1, Map.Entry<IgfsPath, IgfsMode> o2) {
            return o1.getKey().depth() - o2.getKey().depth();
        }
    });
    ArrayList<T2<IgfsPath, IgfsMode>> resModes = new ArrayList<>(modes.size() + 1);
    resModes.add(new T2<>(IgfsPath.ROOT, dfltMode));
    for (T2<IgfsPath, IgfsMode> mode : modes) {
        assert mode.getKey() != null;
        for (T2<IgfsPath, IgfsMode> resMode : resModes) {
            if (mode.getKey().isSubDirectoryOf(resMode.getKey())) {
                assert resMode.getValue() != null;
                if (resMode.getValue() == mode.getValue())
                    // No reason to add a sub-path of the same mode, ignore this pair.
                    break;
                if (!canContain(resMode.getValue(), mode.getValue()))
                    throw new IgniteCheckedException("Subdirectory " + mode.getKey() + " mode " + mode.getValue() + " is not compatible with upper level " + resMode.getKey() + " directory mode " + resMode.getValue() + ".");
                // Add to the 1st position (deep first).
                resModes.add(0, mode);
                // Store primary paths inside dual paths in separate collection:
                if (mode.getValue() == PRIMARY)
                    dualParentsContainingPrimaryChildren.add(mode.getKey().parent());
                break;
            }
        }
    }
    // Remove root, because this class contract is that root mode is not contained in the list.
    resModes.remove(resModes.size() - 1);
    return resModes;
}
Also used : ArrayList(java.util.ArrayList) IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsMode(org.apache.ignite.igfs.IgfsMode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Map(java.util.Map) HashMap(java.util.HashMap) T2(org.apache.ignite.internal.util.typedef.T2)

Aggregations

IgfsMode (org.apache.ignite.igfs.IgfsMode)16 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)8 HashMap (java.util.HashMap)6 IgniteException (org.apache.ignite.IgniteException)5 IgfsException (org.apache.ignite.igfs.IgfsException)5 IgfsInvalidPathException (org.apache.ignite.igfs.IgfsInvalidPathException)5 IgfsPathIsDirectoryException (org.apache.ignite.igfs.IgfsPathIsDirectoryException)5 IgfsPathNotFoundException (org.apache.ignite.igfs.IgfsPathNotFoundException)5 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 FileSystemConfiguration (org.apache.ignite.configuration.FileSystemConfiguration)4 IgfsGroupDataBlocksKeyMapper (org.apache.ignite.igfs.IgfsGroupDataBlocksKeyMapper)4 IgfsPath (org.apache.ignite.igfs.IgfsPath)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)3 HashSet (java.util.HashSet)2 Map (java.util.Map)2 IgfsFile (org.apache.ignite.igfs.IgfsFile)2 IgfsIpcEndpointConfiguration (org.apache.ignite.igfs.IgfsIpcEndpointConfiguration)2 T2 (org.apache.ignite.internal.util.typedef.T2)2 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)2