You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by av...@apache.org on 2016/06/16 11:31:13 UTC

[06/13] ignite git commit: IGNITE-3312: IGFS: Fixed a bug introduced during create() routine reworking.

IGNITE-3312: IGFS: Fixed a bug introduced during create() routine reworking.


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

Branch: refs/heads/master
Commit: b46422ad64f531900263fb36f6ff28373e4346f1
Parents: e733e91
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Jun 15 16:02:53 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Jun 15 16:37:44 2016 +0300

----------------------------------------------------------------------
 .../processors/igfs/IgfsMetaManager.java        | 39 +++++++++++++++-----
 1 file changed, 30 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/b46422ad/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 fd0b07e..1640918 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
@@ -2896,7 +2896,7 @@ public class IgfsMetaManager extends IgfsManager {
                         else {
                             // Create file and parent folders.
                             IgfsPathsCreateResult res = createFile(pathIds, lockInfos, dirProps, fileProps, blockSize,
-                                affKey, evictExclude, null);
+                                affKey, evictExclude, null, null);
 
                             if (res == null)
                                 continue;
@@ -3060,11 +3060,21 @@ public class IgfsMetaManager extends IgfsManager {
                         }
                         else {
                             // Create file and parent folders.
+                            T1<OutputStream> secondaryOutHolder = null;
+
                             if (secondaryCtx != null)
-                                secondaryOut = secondaryCtx.create();
+                                secondaryOutHolder = new T1<>();
 
-                            IgfsPathsCreateResult res = createFile(pathIds, lockInfos, dirProps, fileProps, blockSize,
-                                affKey, evictExclude, secondaryCtx);
+                            IgfsPathsCreateResult res;
+
+                            try {
+                                res = createFile(pathIds, lockInfos, dirProps, fileProps, blockSize,
+                                    affKey, evictExclude, secondaryCtx, secondaryOutHolder);
+                            }
+                            finally {
+                                if (secondaryOutHolder != null)
+                                    secondaryOut =  secondaryOutHolder.get();
+                            }
 
                             if (res == null)
                                 continue;
@@ -3114,7 +3124,7 @@ public class IgfsMetaManager extends IgfsManager {
             throw new IgfsParentNotDirectoryException("Failed to create directory (parent " +
                 "element is not a directory)");
 
-        return createFileOrDirectory(true, pathIds, lockInfos, dirProps, null, 0, null, false, null);
+        return createFileOrDirectory(true, pathIds, lockInfos, dirProps, null, 0, null, false, null, null);
     }
 
     /**
@@ -3128,12 +3138,14 @@ public class IgfsMetaManager extends IgfsManager {
      * @param affKey Affinity key (optional)
      * @param evictExclude Evict exclude flag.
      * @param secondaryCtx Secondary file system create context.
+     * @param secondaryOutHolder Holder for the secondary output stream.
      * @return Result or {@code} if the first parent already contained child with the same name.
      * @throws IgniteCheckedException If failed.
      */
     @Nullable private IgfsPathsCreateResult createFile(IgfsPathIds pathIds, Map<IgniteUuid, IgfsEntryInfo> lockInfos,
         Map<String, String> dirProps, Map<String, String> fileProps, int blockSize, @Nullable IgniteUuid affKey,
-        boolean evictExclude, @Nullable IgfsSecondaryFileSystemCreateContext secondaryCtx)
+        boolean evictExclude, @Nullable IgfsSecondaryFileSystemCreateContext secondaryCtx,
+        @Nullable T1<OutputStream> secondaryOutHolder)
         throws IgniteCheckedException{
         // Check if entry we are going to write to is directory.
         if (lockInfos.get(pathIds.lastExistingId()).isFile())
@@ -3141,7 +3153,7 @@ public class IgfsMetaManager extends IgfsManager {
                 "(parent element is not a directory): " + pathIds.path());
 
         return createFileOrDirectory(false, pathIds, lockInfos, dirProps, fileProps, blockSize, affKey, evictExclude,
-            secondaryCtx);
+            secondaryCtx, secondaryOutHolder);
     }
 
     /**
@@ -3156,6 +3168,7 @@ public class IgfsMetaManager extends IgfsManager {
      * @param affKey Affinity key.
      * @param evictExclude Evict exclude flag.
      * @param secondaryCtx Secondary file system create context.
+     * @param secondaryOutHolder Secondary output stream holder.
      * @return Result.
      * @throws IgniteCheckedException If failed.
      */
@@ -3163,7 +3176,8 @@ public class IgfsMetaManager extends IgfsManager {
     private IgfsPathsCreateResult createFileOrDirectory(boolean dir, IgfsPathIds pathIds,
         Map<IgniteUuid, IgfsEntryInfo> lockInfos, Map<String, String> dirProps, Map<String, String> fileProps,
         int blockSize, @Nullable IgniteUuid affKey, boolean evictExclude,
-        @Nullable IgfsSecondaryFileSystemCreateContext secondaryCtx) throws IgniteCheckedException {
+        @Nullable IgfsSecondaryFileSystemCreateContext secondaryCtx, @Nullable T1<OutputStream> secondaryOutHolder)
+        throws IgniteCheckedException {
         // This is our starting point.
         int lastExistingIdx = pathIds.lastExistingIndex();
         IgfsEntryInfo lastExistingInfo = lockInfos.get(pathIds.lastExistingId());
@@ -3179,6 +3193,13 @@ public class IgfsMetaManager extends IgfsManager {
         if (lastExistingInfo.hasChild(curPart))
             return null;
 
+        // Create entry in the secondary file system if needed.
+        if (secondaryCtx != null) {
+            assert secondaryOutHolder != null;
+
+            secondaryOutHolder.set(secondaryCtx.create());
+        }
+
         Map<IgniteUuid, EntryProcessor> procMap = new HashMap<>();
 
         // First step: add new entry to the last existing element.
@@ -3210,7 +3231,7 @@ public class IgfsMetaManager extends IgfsManager {
 
                 if (secondaryInfo == null)
                     throw new IgfsException("Failed to perform operation because secondary file system path was " +
-                        "modified concurrnetly: " + lastCreatedPath);
+                        "modified concurrently: " + lastCreatedPath);
                 else if (secondaryInfo.isFile())
                     throw new IgfsException("Failed to perform operation because secondary file system entity is " +
                         "not directory: " + lastCreatedPath);