ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [1/2] ignite git commit: WIP on move (1).
Date Thu, 17 Mar 2016 20:08:42 GMT
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 <ppozerov@list.ru>
Authored: Thu Mar 17 22:52:34 2016 +0300
Committer: thatcoach <ppozerov@list.ru>
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<IgniteUuid> srcPathIds = fileIds(srcPath);
                 List<IgniteUuid> dstPathIds = fileIds(dstPath);
 
-                final Set<IgniteUuid> allIds = new TreeSet<>(PATH_ID_SORTING_COMPARATOR);
+                final Set<IgniteUuid> 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<IgniteUuid, IgfsFileInfo> allInfos = lockIds(allIds);
+                    final Map<IgniteUuid, IgfsFileInfo> 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);
+    }
 }


Mime
View raw message