Search in sources :

Example 6 with IgfsMode

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

the class IgfsImpl method setTimes.

/**
 * {@inheritDoc}
 */
@Override
public void setTimes(final IgfsPath path, final long modificationTime, final long accessTime) {
    A.notNull(path, "path");
    if (accessTime == -1 && modificationTime == -1)
        return;
    if (meta.isClient()) {
        meta.runClientTask(new IgfsClientSetTimesCallable(cfg.getName(), IgfsUserContext.currentUser(), path, accessTime, modificationTime));
        return;
    }
    safeOp(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            IgfsMode mode = resolveMode(path);
            if (mode == PROXY)
                secondaryFs.setTimes(path, modificationTime, accessTime);
            else {
                meta.updateTimes(path, modificationTime, accessTime, IgfsUtils.isDualMode(mode) ? secondaryFs : null);
            }
            return null;
        }
    });
}
Also used : IgfsMode(org.apache.ignite.igfs.IgfsMode) IgfsClientSetTimesCallable(org.apache.ignite.internal.processors.igfs.client.IgfsClientSetTimesCallable) 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 7 with IgfsMode

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

the class IgfsImpl method mkdirs.

/**
 * {@inheritDoc}
 */
@Override
public void mkdirs(final IgfsPath path, @Nullable final Map<String, String> props) {
    A.notNull(path, "path");
    if (meta.isClient()) {
        meta.runClientTask(new IgfsClientMkdirsCallable(cfg.getName(), IgfsUserContext.currentUser(), path, props));
        return;
    }
    safeOp(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            if (log.isDebugEnabled())
                log.debug("Make directories: " + path);
            IgfsMode mode = resolveMode(path);
            switch(mode) {
                case PRIMARY:
                    meta.mkdirs(path, props == null ? DFLT_DIR_META : new HashMap<>(props));
                    break;
                case DUAL_ASYNC:
                case DUAL_SYNC:
                    await(path);
                    meta.mkdirsDual(secondaryFs, path, props);
                    break;
                case PROXY:
                    secondaryFs.mkdirs(path, props);
                    break;
            }
            return null;
        }
    });
}
Also used : IgfsMode(org.apache.ignite.igfs.IgfsMode) IgfsClientMkdirsCallable(org.apache.ignite.internal.processors.igfs.client.IgfsClientMkdirsCallable) 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 8 with IgfsMode

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

the class IgfsImpl method update.

/**
 * {@inheritDoc}
 */
@Override
public IgfsFile update(final IgfsPath path, final Map<String, String> props) {
    A.notNull(path, "path");
    A.notNull(props, "props");
    A.ensure(!props.isEmpty(), "!props.isEmpty()");
    if (meta.isClient())
        return meta.runClientTask(new IgfsClientUpdateCallable(cfg.getName(), IgfsUserContext.currentUser(), path, props));
    return safeOp(new Callable<IgfsFile>() {

        @Override
        public IgfsFile call() throws Exception {
            if (log.isDebugEnabled())
                log.debug("Set file properties [path=" + path + ", props=" + props + ']');
            IgfsMode mode = resolveMode(path);
            switch(mode) {
                case PRIMARY:
                    {
                        List<IgniteUuid> fileIds = meta.idsForPath(path);
                        IgniteUuid fileId = fileIds.get(fileIds.size() - 1);
                        if (fileId != null) {
                            IgfsEntryInfo info = meta.updateProperties(fileId, props);
                            if (info != null) {
                                if (evts.isRecordable(EVT_IGFS_META_UPDATED))
                                    evts.record(new IgfsEvent(path, igfsCtx.localNode(), EVT_IGFS_META_UPDATED, props));
                                return new IgfsFileImpl(path, info, data.groupBlockSize());
                            }
                        }
                        break;
                    }
                case DUAL_ASYNC:
                case DUAL_SYNC:
                    {
                        await(path);
                        IgfsEntryInfo info = meta.updateDual(secondaryFs, path, props);
                        if (info != null)
                            return new IgfsFileImpl(path, info, data.groupBlockSize());
                        break;
                    }
                default:
                    assert mode == PROXY : "Unknown mode: " + mode;
                    IgfsFile status = secondaryFs.update(path, props);
                    return status != null ? new IgfsFileImpl(status, data.groupBlockSize()) : null;
            }
            return null;
        }
    });
}
Also used : IgfsMode(org.apache.ignite.igfs.IgfsMode) IgfsClientUpdateCallable(org.apache.ignite.internal.processors.igfs.client.IgfsClientUpdateCallable) IgniteUuid(org.apache.ignite.lang.IgniteUuid) IgfsEvent(org.apache.ignite.events.IgfsEvent) IgfsFile(org.apache.ignite.igfs.IgfsFile) 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 9 with IgfsMode

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

the class IgfsModeResolver method writeExternal.

/**
 * {@inheritDoc}
 */
@Override
public void writeExternal(ObjectOutput out) throws IOException {
    U.writeEnum(out, dfltMode);
    if (modes != null) {
        out.writeBoolean(true);
        out.writeInt(modes.size());
        for (T2<IgfsPath, IgfsMode> pathMode : modes) {
            assert pathMode.getKey() != null;
            pathMode.getKey().writeExternal(out);
            U.writeEnum(out, pathMode.getValue());
        }
    } else
        out.writeBoolean(false);
    if (!F.isEmpty(dualParentsWithPrimaryChildren)) {
        out.writeBoolean(true);
        out.writeInt(dualParentsWithPrimaryChildren.size());
        for (IgfsPath p : dualParentsWithPrimaryChildren) p.writeExternal(out);
    } else
        out.writeBoolean(false);
}
Also used : IgfsPath(org.apache.ignite.igfs.IgfsPath) IgfsMode(org.apache.ignite.igfs.IgfsMode)

Example 10 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)

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