Return-Path: X-Original-To: apmail-ignite-commits-archive@minotaur.apache.org Delivered-To: apmail-ignite-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 25B0E188EB for ; Thu, 17 Mar 2016 20:08:43 +0000 (UTC) Received: (qmail 45561 invoked by uid 500); 17 Mar 2016 20:08:43 -0000 Delivered-To: apmail-ignite-commits-archive@ignite.apache.org Received: (qmail 45521 invoked by uid 500); 17 Mar 2016 20:08:42 -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 45511 invoked by uid 99); 17 Mar 2016 20:08:42 -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; Thu, 17 Mar 2016 20:08:42 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BC8ACDFC55; Thu, 17 Mar 2016 20:08:42 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vozerov@apache.org To: commits@ignite.apache.org Date: Thu, 17 Mar 2016 20:08:42 -0000 Message-Id: <739a5847f6244caea54d958ccbf895b2@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] ignite git commit: WIP on move (1). Repository: ignite Updated Branches: refs/heads/ignite-igfs-refactoring e15ff973e -> b4079ceb7 WIP on move (1). Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/cc86501b Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/cc86501b Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/cc86501b Branch: refs/heads/ignite-igfs-refactoring Commit: cc86501b033517222844086b9be6fb4b9eca77f0 Parents: e15ff97 Author: thatcoach Authored: Thu Mar 17 22:52:34 2016 +0300 Committer: thatcoach Committed: Thu Mar 17 22:52:34 2016 +0300 ---------------------------------------------------------------------- .../processors/igfs/IgfsMetaManager.java | 67 ++++++++++++++------ .../internal/processors/igfs/IgfsPathIds.java | 25 ++++++++ 2 files changed, 73 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/cc86501b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java index 626881b..8084334 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManager.java @@ -847,13 +847,45 @@ public class IgfsMetaManager extends IgfsManager { try { validTxState(false); + // Prepare path IDs. + IgfsPathIds srcPathIds = pathIds(srcPath); + IgfsPathIds dstPathIds2 = pathIds(dstPath); + + // Source path must exists. + if (!srcPathIds.allPartsFound()) + throw new IgfsPathNotFoundException("Failed to perform move because source path is not " + + "found: " + srcPath); + + // At this point we need to understand name of resulting entry. It will be either destination leaf + // or source leaf depending on existence. + String dstName; + + if (dstPathIds2.lastExists()) + // Full destination path exists -> use source name. + dstName = srcPathIds.lastPart(); + else { + if (dstPathIds2.lastParentExists()) { + // Destination path doesn't exists -> use destination name. + dstName = dstPathIds2.lastPart(); + + assert dstPathIds2.lastHasParent(); + + dstPathIds2 = dstPathIds2.parent(); + } + else + // Destination parent is not found either -> exception. + throw new IgfsPathNotFoundException("Failed to perform move because destination path is not " + + "found: " + dstPath.parent()); + } + + // --------------------------------- + // 1. First get source and destination path IDs. - List srcPathIds = fileIds(srcPath); List dstPathIds = fileIds(dstPath); - final Set allIds = new TreeSet<>(PATH_ID_SORTING_COMPARATOR); + final Set lockIds = new TreeSet<>(PATH_ID_SORTING_COMPARATOR); - allIds.addAll(srcPathIds); + srcPathIds.addExistingIds(lockIds); final IgniteUuid dstLeafId = dstPathIds.get(dstPathIds.size() - 1); @@ -862,11 +894,11 @@ public class IgfsMetaManager extends IgfsManager { dstPathIds.remove(dstPathIds.size() - 1); } - allIds.addAll(dstPathIds); + lockIds.addAll(dstPathIds); - if (allIds.remove(null)) { + if (lockIds.remove(null)) { throw new IgfsPathNotFoundException("Failed to perform move because some path component was " + - "not found. [src=" + srcPath + ", dst=" + dstPath + ']'); + "not found. [src=" + srcPath + ", dst=" + dstPath + ']'); } // 2. Start transaction. @@ -874,34 +906,33 @@ public class IgfsMetaManager extends IgfsManager { try { // 3. Obtain the locks. - final Map allInfos = lockIds(allIds); + final Map lockInfos = lockIds(lockIds); // 4. Verify integrity of source directory. - if (!verifyPathIntegrity(srcPath, srcPathIds, allInfos)) { + //if (!verifyPathIntegrity(srcPath, srcPathIds, lockInfos)) + if (!srcPathIds.verifyIntergrity(lockInfos)) throw new IgfsPathNotFoundException("Failed to perform move because source directory " + "structure changed concurrently [src=" + srcPath + ", dst=" + dstPath + ']'); - } // 5. Verify integrity of destination directory. final IgfsPath dstDirPath = dstLeafId != null ? dstPath : dstPath.parent(); - if (!verifyPathIntegrity(dstDirPath, dstPathIds, allInfos)) { + //if (!verifyPathIntegrity(dstDirPath, dstPathIds, lockInfos)) { + if (!dstPathIds2.verifyIntergrity(lockInfos)) throw new IgfsPathNotFoundException("Failed to perform move because destination directory " + "structure changed concurrently [src=" + srcPath + ", dst=" + dstPath + ']'); - } // 6. Calculate source and destination targets which will be changed. - IgniteUuid srcTargetId = srcPathIds.get(srcPathIds.size() - 2); - IgfsFileInfo srcTargetInfo = allInfos.get(srcTargetId); + IgniteUuid srcTargetId = srcPathIds.lastParentId(); + IgfsFileInfo srcTargetInfo = lockInfos.get(srcTargetId); String srcName = srcPath.name(); IgniteUuid dstTargetId; IgfsFileInfo dstTargetInfo; - String dstName; if (dstLeafId != null) { // Destination leaf exists. Check if it is an empty directory. - IgfsFileInfo dstLeafInfo = allInfos.get(dstLeafId); + IgfsFileInfo dstLeafInfo = lockInfos.get(dstLeafId); assert dstLeafInfo != null; @@ -909,7 +940,6 @@ public class IgfsMetaManager extends IgfsManager { // Destination is a directory. dstTargetId = dstLeafId; dstTargetInfo = dstLeafInfo; - dstName = srcPath.name(); } else { // Error, destination is existing file. @@ -921,8 +951,7 @@ public class IgfsMetaManager extends IgfsManager { else { // Destination leaf doesn't exist, so we operate on parent. dstTargetId = dstPathIds.get(dstPathIds.size() - 1); - dstTargetInfo = allInfos.get(dstTargetId); - dstName = dstPath.name(); + dstTargetInfo = lockInfos.get(dstTargetId); } assert dstTargetInfo != null; @@ -944,7 +973,7 @@ public class IgfsMetaManager extends IgfsManager { IgfsPath realNewPath = new IgfsPath(dstDirPath, dstName); - IgfsFileInfo moved = allInfos.get(srcPathIds.get(srcPathIds.size() - 1)); + IgfsFileInfo moved = lockInfos.get(srcPathIds.lastId()); // Set the new path to the info to simplify event creation: return IgfsFileInfo.builder(moved).path(realNewPath).build(); http://git-wip-us.apache.org/repos/asf/ignite/blob/cc86501b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPathIds.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPathIds.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPathIds.java index 63f281d..8d0bf5c 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPathIds.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPathIds.java @@ -135,6 +135,14 @@ public class IgfsPathIds { return parts.length == lastExistingIdx + 1; } + public boolean lastExists() { + return lastExistingIdx == ids.length - 1; + } + + public boolean lastParentExists() { + return lastHasParent() && lastExistingIdx == ids.length - 2; + } + /** * Add existing IDs to provided collection. * @@ -172,4 +180,21 @@ public class IgfsPathIds { return true; } + + /** + * Get parent entity. + * + * @return Parent entity. + */ + public IgfsPathIds parent() { + assert ids.length > 1; + + String[] parentParts = new String[parts.length - 1]; + IgniteUuid[] parentIds = new IgniteUuid[ids.length - 1]; + + System.arraycopy(parts, 0, parentParts, 0, parentParts.length); + System.arraycopy(ids, 0, parentIds, 0, parentIds.length); + + return new IgfsPathIds(path.parent(), parentParts, parentIds); + } }