You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2015/09/18 10:11:45 UTC

[5/5] ignite git commit: IGNITE-586: Fixed rename issue.

IGNITE-586: Fixed rename issue.


Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7c4de845
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7c4de845
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7c4de845

Branch: refs/heads/ignite-586
Commit: 7c4de8454189b0aa453b17fc5be82bef963b9c72
Parents: a28295e
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri Sep 18 11:10:19 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Fri Sep 18 11:10:19 2015 +0300

----------------------------------------------------------------------
 .../internal/processors/igfs/IgfsImpl.java      | 168 +++++++++----------
 .../processors/igfs/IgfsMetaManager.java        |  12 +-
 2 files changed, 87 insertions(+), 93 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/7c4de845/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 aa5b4d1..e7d63f2 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
@@ -692,95 +692,87 @@ public final class IgfsImpl implements IgfsEx {
                     return null;
                 }
 
-                // Resolve source file info.
-                final FileDescriptor srcDesc = getFileDescriptor(src);
-
-                // File not found.
-                if (srcDesc == null || srcDesc.parentId == null) {
-                    if (mode == PRIMARY)
-                        checkConflictWithPrimary(src);
-
-                    throw new IgfsPathNotFoundException("Failed to rename (source path not found): " + src);
-                }
-
-                // Resolve destination file info.
-                FileDescriptor destDesc = getFileDescriptor(dest);
-
-                final String destFileName;
-
-                boolean newDest = destDesc == null;
-
-                if (newDest) {
-                    // Case mv "/x/y/foo" -> "/a/b/foo"
-                    IgfsPath destParent = dest.parent();
-
-                    assert destParent != null;
-
-                    // Use parent directory for destination parent and destination path name as destination name.
-                    destDesc = getFileDescriptor(destParent);
-
-                    // Destination directory doesn't exist.
-                    if (destDesc == null)
-                        throw new IgfsPathNotFoundException("Failed to rename (destination directory does not " +
-                            "exist): " + dest);
-
-                    destFileName = dest.name();
-                }
-                else
-                    // Use destination directory for destination parent and source path name as destination name.
-                    // Case mv "/x/y/foo" -> "/a/b/"
-                    destFileName = src.name();
-
-                // Can move only into directory, but not into file.
-                if (destDesc.isFile)
-                    throw new IgfsParentNotDirectoryException("Failed to rename (destination is not a directory): "
-                        + dest);
-
-                // Src path id chain, including root:
-                final List<IgniteUuid> srcIds = meta.fileIds(src);
-
-                assert srcIds != null;
-
-                if (srcIds.contains(null))
-                    throw new IgfsPathNotFoundException("Failed to rename (Some of the source path components " +
-                        "was concurrently deleted): " + src);
-
-                // Actual destination file (that must exist):
-                final IgfsPath destDir = newDest ? dest.parent() : dest;
-
-                assert destDir != null;
-
-                List<IgniteUuid> destIds = meta.fileIds(destDir);
-
-                assert destIds != null;
-                assert destIds.size() == destDir.depth() + 1: "dest ids = " + destIds + ", dest = " + destDir;
-
-                if (destIds.contains(null))
-                    throw new IgfsPathNotFoundException("Failed to rename (Some of the destination path components " +
-                        "was concurrently deleted): " + dest);
-
+//                // Resolve source file info.
+//                final FileDescriptor srcDesc = getFileDescriptor(src);
+//
+//                // File not found.
+//                if (srcDesc == null || srcDesc.parentId == null) {
+//                    if (mode == PRIMARY)
+//                        checkConflictWithPrimary(src);
+//
+//                    throw new IgfsPathNotFoundException("Failed to perform rename (source path not found): " + src);
+//                }
+//
+//                // Resolve destination file info.
+//                FileDescriptor destDesc = getFileDescriptor(dest);
+//
+//                final String destFileName;
+//
+//                boolean newDest = destDesc == null;
+//
+//                if (newDest) {
+//                    // Case mv "/x/y/foo" -> "/a/b/foo"
+//                    IgfsPath destParent = dest.parent();
+//
+//                    assert destParent != null;
+//
+//                    // Use parent directory for destination parent and destination path name as destination name.
+//                    destDesc = getFileDescriptor(destParent);
+//
+//                    // Destination directory doesn't exist.
+//                    if (destDesc == null)
+//                        throw new IgfsPathNotFoundException("Failed to rename (destination directory does not " +
+//                            "exist): " + dest);
+//
+//                    destFileName = dest.name();
+//                }
+//                else
+//                    // Use destination directory for destination parent and source path name as destination name.
+//                    // Case mv "/x/y/foo" -> "/a/b/"
+//                    destFileName = src.name();
+//
+//                // Can move only into directory, but not into file.
+//                if (destDesc.isFile)
+//                    throw new IgfsParentNotDirectoryException("Failed to rename (destination is not a directory): "
+//                        + dest);
+//
+//                // Src path id chain, including root:
+//                final List<IgniteUuid> srcIds = meta.fileIds(src);
+//
+//                assert srcIds != null;
+//
+//                if (srcIds.contains(null))
+//                    throw new IgfsPathNotFoundException("Failed to rename (Some of the source path components " +
+//                        "was concurrently deleted): " + src);
+//
+//                // Actual destination file (that must exist):
+//                final IgfsPath destDir = newDest ? dest.parent() : dest;
+//
+//                assert destDir != null;
+//
+//                List<IgniteUuid> destIds = meta.fileIds(destDir);
+//
+//                assert destIds != null;
+//                assert destIds.size() == destDir.depth() + 1: "dest ids = " + destIds + ", dest = " + destDir;
+//
+//                if (destIds.contains(null))
 //                    throw new IgfsPathNotFoundException("Failed to rename (Some of the destination path components " +
-//                        "was concurrently deleted): " + destDir);
-
-//                meta.move(srcIds, src,
-//                    destIds/*tail is the target dir id, it must exist*/,
-//                    destDir/*dest directory (parent), it must exist. */,
-//                    destFileName);
-
-                meta.move0(src, dest);
-
-                if (srcDesc.isFile) { // Renamed a file.
-                    if (evts.isRecordable(EVT_IGFS_FILE_RENAMED))
-                        evts.record(new IgfsEvent(
-                            src,
-                            newDest ? dest : new IgfsPath(dest, destFileName),
-                            localNode(),
-                            EVT_IGFS_FILE_RENAMED));
-                }
-                else { // Renamed a directory.
-                    if (evts.isRecordable(EVT_IGFS_DIR_RENAMED))
-                        evts.record(new IgfsEvent(src, dest, localNode(), EVT_IGFS_DIR_RENAMED));
-                }
+//                        "was concurrently deleted): " + dest);
+//
+////                    throw new IgfsPathNotFoundException("Failed to rename (Some of the destination path components " +
+////                        "was concurrently deleted): " + destDir);
+//
+////                meta.move(srcIds, src,
+////                    destIds/*tail is the target dir id, it must exist*/,
+////                    destDir/*dest directory (parent), it must exist. */,
+////                    destFileName);
+
+                IgfsFileInfo info = meta.move0(src, dest);
+
+                int evtTyp = info.isFile() ? EVT_IGFS_FILE_RENAMED : EVT_IGFS_DIR_RENAMED;
+
+                if (evts.isRecordable(evtTyp))
+                    evts.record(new IgfsEvent(src, dest, localNode(), evtTyp));
 
                 return null;
             }

http://git-wip-us.apache.org/repos/asf/ignite/blob/7c4de845/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 bef39bc..c904871 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
@@ -826,9 +826,10 @@ public class IgfsMetaManager extends IgfsManager {
      * Move routine.
      * @param srcPath Source path.
      * @param dstPath Destinatoin path.
+     * @return File info of renamed entry.
      * @throws IgniteCheckedException In case of exception.
      */
-    public void move0(IgfsPath srcPath, IgfsPath dstPath) throws IgniteCheckedException {
+    public IgfsFileInfo move0(IgfsPath srcPath, IgfsPath dstPath) throws IgniteCheckedException {
         if (busyLock.enterBusy()) {
             try {
                 assert validTxState(false);
@@ -863,7 +864,7 @@ public class IgfsMetaManager extends IgfsManager {
                             "structure changed concurrently [src=" + srcPath + ", dst=" + dstPath + ']');
                     }
 
-                    // 6. At this point we are safe to proceed with real move.
+                    // 6. Calculate source and destination targets which will be changed.
                     IgniteUuid srcTargetId = srcPathIds.get(srcPathIds.size() - 2);
                     IgfsFileInfo srcTargetInfo = allInfos.get(srcTargetId);
                     String srcName = srcPath.name();
@@ -872,7 +873,6 @@ public class IgfsMetaManager extends IgfsManager {
                     IgfsFileInfo dstTargetInfo;
                     String dstName;
 
-                    // 7. Calculate the target.
                     if (dstLeafId != null) {
                         // Destination leaf exists. Check if it is an empty directory.
                         IgfsFileInfo dstLeafInfo = allInfos.get(dstLeafId);
@@ -901,20 +901,22 @@ public class IgfsMetaManager extends IgfsManager {
                     assert dstTargetInfo != null;
                     assert dstTargetInfo.isDirectory();
 
-                    // 8. Last check: does destination target already have listing entry with the same name?
+                    // 7. Last check: does destination target already have listing entry with the same name?
                     if (dstTargetInfo.listing().containsKey(dstName)) {
                         throw new IgniteCheckedException("Failed to perform move because destination already " +
                             "contains entry with the same name existing file [src=" + srcPath +
                             ", dst=" + dstPath + ']');
                     }
 
-                    // 9. Actual move: remove from source parent and add to destination target.
+                    // 8. Actual move: remove from source parent and add to destination target.
                     IgfsListingEntry entry = srcTargetInfo.listing().get(srcName);
 
                     id2InfoPrj.invoke(srcTargetId, new UpdateListing(srcName, entry, true));
                     id2InfoPrj.invoke(dstTargetId, new UpdateListing(dstName, entry, false));
 
                     tx.commit();
+
+                    return allInfos.get(srcPathIds.get(srcPathIds.size() - 1));
                 }
                 finally {
                     tx.close();