Index: modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfo.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfo.java (revision 29acb33293c3d3130e16b7ff4d6b7ae260b7b78b) +++ modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfo.java (revision ) @@ -152,62 +152,62 @@ } /** {@inheritDoc} */ - public boolean isFile() { + @Override public boolean isFile() { return true; } /** {@inheritDoc} */ - public long length() { + @Override public long length() { return len; } /** {@inheritDoc} */ - public int blockSize() { + @Override public int blockSize() { return blockSize; } /** {@inheritDoc} */ - public long blocksCount() { + @Override public long blocksCount() { return (len + blockSize() - 1) / blockSize(); } /** {@inheritDoc} */ - public Map listing() { + @Override public Map listing() { return Collections.emptyMap(); } /** {@inheritDoc} */ - public boolean hasChildren() { + @Override public boolean hasChildren() { return false; } /** {@inheritDoc} */ - public boolean hasChild(String name) { + @Override public boolean hasChild(String name) { return false; } /** {@inheritDoc} */ - public boolean hasChild(String name, IgniteUuid expId) { + @Override public boolean hasChild(String name, IgniteUuid expId) { return false; } /** {@inheritDoc} */ - @Nullable public IgniteUuid affinityKey() { + @Override @Nullable public IgniteUuid affinityKey() { return affKey; } /** {@inheritDoc} */ - public IgfsFileMap fileMap() { + @Override public IgfsFileMap fileMap() { return fileMap; } /** {@inheritDoc} */ - @Nullable public IgniteUuid lockId() { + @Override @Nullable public IgniteUuid lockId() { return lockId; } /** {@inheritDoc} */ - public boolean evictExclude() { + @Override public boolean evictExclude() { return evictExclude; } \ No newline at end of file Index: modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java (revision 29acb33293c3d3130e16b7ff4d6b7ae260b7b78b) +++ modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java (revision ) @@ -494,8 +494,8 @@ @Override public boolean exists(final IgfsPath path) { A.notNull(path, "path"); - if (meta.isClient()) - return meta.runClientTask(new IgfsClientExistsCallable(cfg.getName(), path)); + if (meta.isReadRemote()) + return meta.runRemote(new IgfsClientExistsCallable(cfg.getName(), path)); return safeOp(new Callable() { @Override public Boolean call() throws Exception { @@ -544,8 +544,8 @@ @Override @Nullable public IgfsFile info(final IgfsPath path) { A.notNull(path, "path"); - if (meta.isClient()) - return meta.runClientTask(new IgfsClientInfoCallable(cfg.getName(), path)); + if (meta.isReadRemote()) + return meta.runRemote(new IgfsClientInfoCallable(cfg.getName(), path)); return safeOp(new Callable() { @Override public IgfsFile call() throws Exception { @@ -570,8 +570,8 @@ @Override public IgfsPathSummary summary(final IgfsPath path) { A.notNull(path, "path"); - if (meta.isClient()) - return meta.runClientTask(new IgfsClientSummaryCallable(cfg.getName(), path)); + if (meta.isReadRemote()) + return meta.runRemote(new IgfsClientSummaryCallable(cfg.getName(), path)); return safeOp(new Callable() { @Override public IgfsPathSummary call() throws Exception { @@ -589,8 +589,8 @@ A.notNull(props, "props"); A.ensure(!props.isEmpty(), "!props.isEmpty()"); - if (meta.isClient()) - return meta.runClientTask(new IgfsClientUpdateCallable(cfg.getName(), path, props)); + if (meta.isModifyRemote()) + return meta.runRemote(new IgfsClientUpdateCallable(cfg.getName(), path, props)); return safeOp(new Callable() { @Override public IgfsFile call() throws Exception { @@ -652,8 +652,8 @@ A.notNull(src, "src"); A.notNull(dest, "dest"); - if (meta.isClient()) { - meta.runClientTask(new IgfsClientRenameCallable(cfg.getName(), src, dest)); + if (meta.isModifyRemote()) { + meta.runRemote(new IgfsClientRenameCallable(cfg.getName(), src, dest)); return; } @@ -712,8 +712,8 @@ @Override public boolean delete(final IgfsPath path, final boolean recursive) { A.notNull(path, "path"); - if (meta.isClient()) - return meta.runClientTask(new IgfsClientDeleteCallable(cfg.getName(), path, recursive)); + if (meta.isModifyRemote()) + return meta.runRemote(new IgfsClientDeleteCallable(cfg.getName(), path, recursive)); return safeOp(new Callable() { @Override public Boolean call() throws Exception { @@ -754,8 +754,8 @@ @Override public void mkdirs(final IgfsPath path, @Nullable final Map props) { A.notNull(path, "path"); - if (meta.isClient()) { - meta.runClientTask(new IgfsClientMkdirsCallable(cfg.getName(), path, props)); + if (meta.isModifyRemote()) { + meta.runRemote(new IgfsClientMkdirsCallable(cfg.getName(), path, props)); return ; } @@ -799,8 +799,8 @@ @Override public Collection listPaths(final IgfsPath path) { A.notNull(path, "path"); - if (meta.isClient()) - meta.runClientTask(new IgfsClientListPathsCallable(cfg.getName(), path)); + if (meta.isReadRemote()) + meta.runRemote(new IgfsClientListPathsCallable(cfg.getName(), path)); return safeOp(new Callable>() { @Override public Collection call() throws Exception { @@ -848,8 +848,8 @@ @Override public Collection listFiles(final IgfsPath path) { A.notNull(path, "path"); - if (meta.isClient()) - meta.runClientTask(new IgfsClientListFilesCallable(cfg.getName(), path)); + if (meta.isReadRemote()) + meta.runRemote(new IgfsClientListFilesCallable(cfg.getName(), path)); return safeOp(new Callable>() { @Override public Collection call() throws Exception { @@ -1225,8 +1225,8 @@ if (accessTime == -1 && modificationTime == -1) return; - if (meta.isClient()) { - meta.runClientTask(new IgfsClientSetTimesCallable(cfg.getName(), path, accessTime, modificationTime)); + if (meta.isModifyRemote()) { + meta.runRemote(new IgfsClientSetTimesCallable(cfg.getName(), path, accessTime, modificationTime)); return; } @@ -1267,8 +1267,8 @@ A.ensure(start >= 0, "start >= 0"); A.ensure(len >= 0, "len >= 0"); - if (meta.isClient()) - return meta.runClientTask(new IgfsClientAffinityCallable(cfg.getName(), path, start, len, maxLen)); + if (meta.isReadRemote()) + return meta.runRemote(new IgfsClientAffinityCallable(cfg.getName(), path, start, len, maxLen)); return safeOp(new Callable>() { @Override public Collection call() throws Exception { @@ -1350,8 +1350,8 @@ @Override public long size(final IgfsPath path) { A.notNull(path, "path"); - if (meta.isClient()) - return meta.runClientTask(new IgfsClientSizeCallable(cfg.getName(), path)); + if (meta.isReadRemote()) + return meta.runRemote(new IgfsClientSizeCallable(cfg.getName(), path)); return safeOp(new Callable() { @Override public Long call() throws Exception { \ No newline at end of file Index: modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDirectoryInfo.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDirectoryInfo.java (revision 29acb33293c3d3130e16b7ff4d6b7ae260b7b78b) +++ modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsDirectoryInfo.java (revision ) @@ -62,7 +62,7 @@ * @param len New length. * @return Updated file info. */ - public IgfsEntryInfo length(long len) { + @Override public IgfsEntryInfo length(long len) { throw new UnsupportedOperationException("length"); } @@ -107,47 +107,47 @@ } /** {@inheritDoc} */ - protected IgfsDirectoryInfo copy() { + @Override protected IgfsDirectoryInfo copy() { return new IgfsDirectoryInfo(id, listing, props, accessTime, modificationTime); } /** {@inheritDoc} */ - public boolean isFile() { + @Override public boolean isFile() { return false; } /** {@inheritDoc} */ - public long length() { + @Override public long length() { return 0; } /** {@inheritDoc} */ - public int blockSize() { + @Override public int blockSize() { return 0; } /** {@inheritDoc} */ - public long blocksCount() { + @Override public long blocksCount() { return 0; } /** {@inheritDoc} */ - public Map listing() { + @Override public Map listing() { return listing != null ? listing : Collections.emptyMap(); } /** {@inheritDoc} */ - public boolean hasChildren() { + @Override public boolean hasChildren() { return !F.isEmpty(listing); } /** {@inheritDoc} */ - public boolean hasChild(String name) { + @Override public boolean hasChild(String name) { return listing != null && listing.containsKey(name); } /** {@inheritDoc} */ - public boolean hasChild(String name, IgniteUuid expId) { + @Override public boolean hasChild(String name, IgniteUuid expId) { if (listing != null) { IgfsListingEntry entry = listing.get(name); @@ -159,22 +159,22 @@ } /** {@inheritDoc} */ - @Nullable public IgniteUuid affinityKey() { + @Override @Nullable public IgniteUuid affinityKey() { return null; } /** {@inheritDoc} */ - public IgfsFileMap fileMap() { + @Override public IgfsFileMap fileMap() { return null; } /** {@inheritDoc} */ - @Nullable public IgniteUuid lockId() { + @Override @Nullable public IgniteUuid lockId() { return null; } /** {@inheritDoc} */ - public boolean evictExclude() { + @Override public boolean evictExclude() { return true; } Index: modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== --- modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java (revision 29acb33293c3d3130e16b7ff4d6b7ae260b7b78b) +++ modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java (revision ) @@ -140,7 +140,7 @@ private GridEventStorageManager evts; /** Local node. */ - private ClusterNode locNode; + private volatile ClusterNode locNode; /** Busy lock. */ private final GridSpinBusyLock busyLock = new GridSpinBusyLock(); @@ -152,7 +152,7 @@ private final boolean client; /** Compute facade for client tasks. */ - private IgniteCompute cliCompute; + private IgniteCompute rmtCompute; /** * Constructor. @@ -235,39 +235,58 @@ } /** - * @return Client flag. + * Check whether remote task execution is needed for read-only operation. + * + * @return {@code True} if remote task execution is needed. */ - boolean isClient() { - return client; + boolean isReadRemote() { + return client || + cfg.isColocateMetadata() && !metaCache.affinity().isPrimaryOrBackup(localNode(), IgfsUtils.ROOT_ID); } /** + * Check whether remote task execution is needed. + * + * @return {@code True} if remote task execution is needed. + */ + boolean isModifyRemote() { + return client || cfg.isColocateMetadata() && !metaCache.affinity().isPrimary(localNode(), IgfsUtils.ROOT_ID); + } + + /** + * Check whether remote task execution is needed for the given ID. + * + * @param fileId Identifier of the modified file. + * @return {@code True} if remote task execution is needed. + */ + private boolean isModifyRemote(IgniteUuid fileId) { + assert fileId != null; + + return client || !metaCache.affinity().isPrimary(localNode(), fileId); + } + + /** * Run client task. * * @param task Task. * @return Result. */ - T runClientTask(IgfsClientAbstractCallable task) { - try { - return runClientTask(IgfsUtils.ROOT_ID, task); + T runRemote(IgfsClientAbstractCallable task) { + return runRemote(IgfsUtils.ROOT_ID, task); - } + } - catch (ClusterTopologyException e) { - throw new IgfsException("Failed to execute operation because there are no IGFS metadata nodes." , e); - } - } /** * Run client task. * - * @param affinityFileId Affinity fileId. + * @param affKey Affinity fileId. * @param task Task. * @return Result. */ - T runClientTask(IgniteUuid affinityFileId, IgfsClientAbstractCallable task) { + T runRemote(IgniteUuid affKey, IgfsClientAbstractCallable task) { try { return (cfg.isColocateMetadata()) ? - clientCompute().affinityCall(cfg.getMetaCacheName(), affinityFileId, task) : - clientCompute().call(task); + remoteCompute().affinityCall(cfg.getMetaCacheName(), affKey, task) : + remoteCompute().call(task); } catch (ClusterTopologyException e) { throw new IgfsException("Failed to execute operation because there are no IGFS metadata nodes." , e); @@ -279,27 +298,39 @@ * * @return Compute facade. */ - private IgniteCompute clientCompute() { - assert client; + private IgniteCompute remoteCompute() { + IgniteCompute remoteCompute0 = rmtCompute; - IgniteCompute cliCompute0 = cliCompute; - - if (cliCompute0 == null) { + if (remoteCompute0 == null) { IgniteEx ignite = igfsCtx.kernalContext().grid(); ClusterGroup cluster = ignite.cluster().forIgfsMetadataDataNodes(cfg.getName(), cfg.getMetaCacheName()); - cliCompute0 = ignite.compute(cluster); + remoteCompute0 = ignite.compute(cluster); - cliCompute = cliCompute0; + rmtCompute = remoteCompute0; } - assert cliCompute0 != null; + assert remoteCompute0 != null; - return cliCompute0; + return remoteCompute0; } /** + * Get local node. + * + * @return Local node. + */ + private ClusterNode localNode() { + ClusterNode locNode0 = locNode; + + if (locNode0 == null) + locNode0 = igfsCtx.kernalContext().discovery().localNode(); + + return locNode0; + } + + /** * Gets file ID for specified path. * * @param path Path. @@ -423,7 +454,7 @@ // Get IDs. if (client) { - List ids = runClientTask(new IgfsClientMetaIdsForPathCallable(cfg.getName(), path)); + List ids = runRemote(new IgfsClientMetaIdsForPathCallable(cfg.getName(), path)); return new IgfsPathIds(path, parts, ids.toArray(new IgniteUuid[ids.size()])); } @@ -635,7 +666,7 @@ if (del) return IgfsUtils.DELETE_LOCK_ID; - return IgniteUuid.fromUuid(locNode.id()); + return IgniteUuid.fromUuid(localNode().id()); } /** @@ -666,8 +697,8 @@ final boolean updateSpace, final long space, @Nullable final IgfsFileAffinityRange affRange) throws IgniteCheckedException { - if(client) { - runClientTask(new IgfsClientMetaUnlockCallable(cfg.getName(), fileId, lockId, modificationTime, + if(isModifyRemote(fileId)) { + runRemote(new IgfsClientMetaUnlockCallable(cfg.getName(), fileId, lockId, modificationTime, updateSpace, space, affRange)); return; @@ -1534,6 +1565,7 @@ * @param space Space. * @param affRange Affinity range. * @return New file info. + * @throws IgniteCheckedException If failed. */ public IgfsEntryInfo reserveSpace(IgniteUuid fileId, long space, IgfsFileAffinityRange affRange) throws IgniteCheckedException { @@ -1897,8 +1929,7 @@ IgfsPath evtPath = parent0; while (!parentPath.equals(evtPath)) { - pendingEvts.addFirst(new IgfsEvent(evtPath, locNode, - EventType.EVT_IGFS_DIR_CREATED)); + pendingEvts.addFirst(new IgfsEvent(evtPath, localNode(), EventType.EVT_IGFS_DIR_CREATED)); evtPath = evtPath.parent(); @@ -1955,7 +1986,7 @@ // 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)); + pendingEvts.add(new IgfsEvent(path, localNode(), EventType.EVT_IGFS_FILE_CREATED)); return new IgfsCreateResult(newInfo, out); } @@ -2032,7 +2063,7 @@ } if (evts.isRecordable(EventType.EVT_IGFS_FILE_OPENED_WRITE)) - pendingEvts.add(new IgfsEvent(path, locNode, EventType.EVT_IGFS_FILE_OPENED_WRITE)); + pendingEvts.add(new IgfsEvent(path, localNode(), EventType.EVT_IGFS_FILE_OPENED_WRITE)); return new IgfsCreateResult(lockedInfo, outT1.get()); } @@ -2073,7 +2104,7 @@ * @throws IgniteCheckedException If failed. */ @Nullable public IgfsEntryInfo infoForPath(IgfsPath path) throws IgniteCheckedException { - return client ? runClientTask(new IgfsClientMetaInfoForPathCallable(cfg.getName(), path)) : info(fileId(path)); + return client ? runRemote(new IgfsClientMetaInfoForPathCallable(cfg.getName(), path)) : info(fileId(path)); } /** @@ -2084,7 +2115,7 @@ * @throws IgniteCheckedException If failed. */ public List idsForPath(IgfsPath path) throws IgniteCheckedException { - return client ? runClientTask(new IgfsClientMetaIdsForPathCallable(cfg.getName(), path)) : fileIds(path); + return client ? runRemote(new IgfsClientMetaIdsForPathCallable(cfg.getName(), path)) : fileIds(path); } /** @@ -2258,7 +2289,8 @@ IgfsPath evtPath = path; while (!parentPath.equals(evtPath)) { - pendingEvts.addFirst(new IgfsEvent(evtPath, locNode, EventType.EVT_IGFS_DIR_CREATED)); + pendingEvts.addFirst(new IgfsEvent(evtPath, localNode(), + EventType.EVT_IGFS_DIR_CREATED)); evtPath = evtPath.parent(); @@ -2355,11 +2387,11 @@ pendingEvts.add(new IgfsEvent( src, destInfo == null ? dest : new IgfsPath(dest, src.name()), - locNode, + localNode(), EventType.EVT_IGFS_FILE_RENAMED)); } else if (evts.isRecordable(EventType.EVT_IGFS_DIR_RENAMED)) - pendingEvts.add(new IgfsEvent(src, dest, locNode, EventType.EVT_IGFS_DIR_RENAMED)); + pendingEvts.add(new IgfsEvent(src, dest, localNode(), EventType.EVT_IGFS_DIR_RENAMED)); return true; } @@ -2715,7 +2747,7 @@ strict, created); - assert strict && info != null || !strict; + assert !strict || info != null; if (info != null) infos.put(path, info); @@ -2724,7 +2756,7 @@ if (parentPath.equals(firstParentPath)) infos.put(firstParentPath, idToInfo.get(pathToId.get(firstParentPath))); else { - assert strict && created.get(parentPath) != null || !strict; + assert !strict || created.get(parentPath) != null; if (created.get(parentPath) != null) infos.put(parentPath, created.get(parentPath)); \ No newline at end of file