Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2284F200BA7 for ; Fri, 16 Sep 2016 07:49:19 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 2126C160AC6; Fri, 16 Sep 2016 05:49:19 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id C521A160AD7 for ; Fri, 16 Sep 2016 07:49:17 +0200 (CEST) Received: (qmail 22960 invoked by uid 500); 16 Sep 2016 05:49:17 -0000 Mailing-List: contact commits-help@ignite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ignite.apache.org Delivered-To: mailing list commits@ignite.apache.org Received: (qmail 22534 invoked by uid 99); 16 Sep 2016 05:49:16 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Sep 2016 05:49:16 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8D328E03CE; Fri, 16 Sep 2016 05:49:16 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: akuznetsov@apache.org To: commits@ignite.apache.org Date: Fri, 16 Sep 2016 05:49:33 -0000 Message-Id: <22711c3fa2b54c29987c7aa3ad899763@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [19/50] [abbrv] ignite git commit: IGNITE-3613 IGFS: Fixed IgfsImpl.size() to take secondary fie system in count. This closes #1023. archived-at: Fri, 16 Sep 2016 05:49:19 -0000 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 Authored: Tue Sep 13 17:30:47 2016 +0300 Committer: vozerov-gridgain 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() { @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() { @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