IGNITE-3613 IGFS: Fixed IgfsImpl.size() to take secondary fie system in count. This closes #1023.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/43f65fe9 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/43f65fe9 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/43f65fe9 Branch: refs/heads/ignite-3443 Commit: 43f65fe91d85ba8f3c16e13bdf5ea815d3a48d71 Parents: 0852bae Author: tledkov-gridgain <[email protected]> Authored: Tue Sep 13 17:30:47 2016 +0300 Committer: vozerov-gridgain <[email protected]> Committed: Tue Sep 13 17:30:47 2016 +0300 ---------------------------------------------------------------------- .../internal/processors/igfs/IgfsImpl.java | 69 ++++++++++---------- .../igfs/IgfsDualAbstractSelfTest.java | 14 ++++ 2 files changed, 47 insertions(+), 36 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/43f65fe9/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java index 273e67d..2720f24 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java @@ -598,16 +598,7 @@ public final class IgfsImpl implements IgfsEx { if (log.isDebugEnabled()) log.debug("Calculating path summary: " + path); - IgniteUuid fileId = meta.fileId(path); - - if (fileId == null) - throw new IgfsPathNotFoundException("Failed to get path summary (path not found): " + path); - - IgfsPathSummary sum = new IgfsPathSummary(path); - - summary0(fileId, sum); - - return sum; + return summary0(path); } }); } @@ -1259,9 +1250,7 @@ public final class IgfsImpl implements IgfsEx { @Override public IgfsMetrics metrics() { return safeOp(new Callable<IgfsMetrics>() { @Override public IgfsMetrics call() throws Exception { - IgfsPathSummary sum = new IgfsPathSummary(); - - summary0(IgfsUtils.ROOT_ID, sum); + IgfsPathSummary sum = summary0(IgfsPath.ROOT); long secondarySpaceSize = 0; @@ -1310,44 +1299,52 @@ public final class IgfsImpl implements IgfsEx { return safeOp(new Callable<Long>() { @Override public Long call() throws Exception { - IgniteUuid nextId = meta.fileId(path); + return summary0(path).totalLength(); + } + }); + } - if (nextId == null) - return 0L; + /** + * Get summary for path. + * + * @param path Path. + * @return Summary. + * @throws IgniteCheckedException If failed. + */ + private IgfsPathSummary summary0(IgfsPath path) throws IgniteCheckedException { + IgfsFile info = info(path); - IgfsPathSummary sum = new IgfsPathSummary(path); + if (info == null) + throw new IgfsPathNotFoundException("Failed to get path summary (path not found): " + path); - summary0(nextId, sum); + IgfsPathSummary sum = new IgfsPathSummary(path); - return sum.totalLength(); - } - }); + summaryRecursive(info, sum); + + return sum; } /** * Calculates size of directory or file for given ID. * - * @param fileId File ID. + * @param file IGFS File object. * @param sum Summary object that will collect information. * @throws IgniteCheckedException If failed. */ - private void summary0(IgniteUuid fileId, IgfsPathSummary sum) throws IgniteCheckedException { + private void summaryRecursive(IgfsFile file, IgfsPathSummary sum) throws IgniteCheckedException { + assert file != null; assert sum != null; - IgfsEntryInfo info = meta.info(fileId); - - if (info != null) { - if (info.isDirectory()) { - if (!IgfsUtils.ROOT_ID.equals(info.id())) - sum.directoriesCount(sum.directoriesCount() + 1); + if (file.isDirectory()) { + if (!F.eq(IgfsPath.ROOT, file.path())) + sum.directoriesCount(sum.directoriesCount() + 1); - for (IgfsListingEntry entry : info.listing().values()) - summary0(entry.fileId(), sum); - } - else { - sum.filesCount(sum.filesCount() + 1); - sum.totalLength(sum.totalLength() + info.length()); - } + for (IgfsFile childFile : listFiles(file.path())) + summaryRecursive(childFile, sum); + } + else { + sum.filesCount(sum.filesCount() + 1); + sum.totalLength(sum.totalLength() + file.length()); } } http://git-wip-us.apache.org/repos/asf/ignite/blob/43f65fe9/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java index 57bc4f3..742d20c 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsDualAbstractSelfTest.java @@ -1599,4 +1599,18 @@ public abstract class IgfsDualAbstractSelfTest extends IgfsAbstractSelfTest { // No-op. } } + + /** + * + * @throws Exception If failed. + */ + public void testSecondarySize() throws Exception { + igfs.mkdirs(SUBDIR); + + createFile(igfsSecondary, FILE, chunk); + createFile(igfsSecondary, new IgfsPath(SUBDIR, "file2"), chunk); + + assertEquals(chunk.length, igfs.size(FILE)); + assertEquals(chunk.length * 2, igfs.size(SUBDIR)); + } } \ No newline at end of file
