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: IGNITE-3294: Preparing.
Date Fri, 10 Jun 2016 10:02:06 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-3294 3cee4ca74 -> dfaefc4b7


IGNITE-3294: Preparing.


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

Branch: refs/heads/ignite-3294
Commit: 670bad658e5dbe77fc3bdcf80a982c6e09fc9e84
Parents: 3cee4ca
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Fri Jun 10 12:49:32 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Fri Jun 10 12:49:32 2016 +0300

----------------------------------------------------------------------
 .../processors/igfs/IgfsMetaManager.java        | 67 +++++++++++++++++---
 .../IgfsSecondaryFileSystemCreateContext.java   | 28 ++++++++
 2 files changed, 87 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/670bad65/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 67a3bb9..20500e8 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
@@ -1151,7 +1151,7 @@ public class IgfsMetaManager extends IgfsManager {
      *
      * @param pathIds Path IDs.
      * @param lockInfos Lock infos.
-     * @return
+     * @return Whether to re-try.
      */
     private boolean isRetryForSecondary(IgfsPathIds pathIds, Map<IgniteUuid, IgfsEntryInfo>
lockInfos) {
         // We need to ensure that the last locked info is not linked with expected child.
@@ -2868,9 +2868,14 @@ public class IgfsMetaManager extends IgfsManager {
                     }
 
                     // Start TX.
+                    OutputStream secondaryOut = null;
+
                     try (IgniteInternalTx tx = startTx()) {
                         Map<IgniteUuid, IgfsEntryInfo> lockInfos = lockIds(lockIds);
 
+                        if (secondaryCtx != null && isRetryForSecondary(pathIds,
lockInfos))
+                            continue;
+
                         if (!pathIds.verifyIntegrity(lockInfos, relaxed))
                             // Directory structure changed concurrently. So we simply re-try.
                             continue;
@@ -2893,30 +2898,75 @@ public class IgfsMetaManager extends IgfsManager {
 
                             // At this point file can be re-created safely.
 
-                            // First step: add existing to trash listing.
+                            // Add existing to trash listing.
                             IgniteUuid oldId = pathIds.lastId();
 
                             id2InfoPrj.invoke(trashId, new IgfsMetaDirectoryListingAddProcessor(oldId.toString(),
                                 new IgfsListingEntry(oldInfo)));
 
-                            // Second step: replace ID in parent directory.
+                            // Replace ID in parent directory.
                             String name = pathIds.lastPart();
                             IgniteUuid parentId = pathIds.lastParentId();
 
                             id2InfoPrj.invoke(parentId, new IgfsMetaDirectoryListingReplaceProcessor(name,
overwriteId));
 
-                            // Third step: create the file.
-                            long createTime = System.currentTimeMillis();
+                            // Create the file.
+                            IgniteUuid newLockId = createFileLockId(false);
+
+                            long newAccessTime;
+                            long newModificationTime;
+                            Map<String, String> newProps;
+                            long newLen;
+                            int newBlockSize;
+
+                            if (secondaryCtx != null) {
+                                secondaryOut = secondaryCtx.create(path, overwrite, fileProps);
+
+                                IgfsFile secondaryFile = secondaryCtx.info(path);
+
+                                if (secondaryFile == null)
+                                    throw fsException("Failed to open output stream to the
file created in " +
+                                        "the secondary file system because it no longer exists:
" + path);
+                                else if (secondaryFile.isDirectory())
+                                    throw fsException("Failed to open output stream to the
file created in " +
+                                        "the secondary file system because the path points
to a directory: " + path);
+
+                                IgfsEntryInfo newInfo2 = IgfsUtils.createFile(
+                                    overwriteId,
+                                    secondaryFile.blockSize(),
+                                    secondaryFile.length(),
+                                    affKey,
+                                    newLockId,
+                                    evictExclude,
+                                    secondaryFile.properties(),
+                                    secondaryFile.accessTime(),
+                                    secondaryFile.modificationTime()
+                                );
+
+                                newAccessTime = secondaryFile.accessTime();
+                                newModificationTime = secondaryFile.modificationTime();
+                                newProps = secondaryFile.properties();
+                                newLen = secondaryFile.length();
+                                newBlockSize = (int)secondaryFile.length();
+                            }
+                            else {
+                                newAccessTime = System.currentTimeMillis();
+                                newModificationTime = newAccessTime;
+                                newProps = fileProps;
+                                newLen = 0;
+                                newBlockSize = blockSize;
+                            }
 
-                            IgfsEntryInfo newInfo = invokeAndGet(overwriteId, new IgfsMetaFileCreateProcessor(createTime,
-                                fileProps, blockSize, affKey, createFileLockId(false), evictExclude));
+                            IgfsEntryInfo newInfo = invokeAndGet(overwriteId,
+                                new IgfsMetaFileCreateProcessor(newAccessTime, newProps,
newBlockSize, affKey,
+                                    newLockId, evictExclude));
 
                             // Prepare result and commit.
                             tx.commit();
 
                             IgfsUtils.sendEvents(igfsCtx.kernalContext(), path, EventType.EVT_IGFS_FILE_OPENED_WRITE);
 
-                            return new IgfsCreateResult(newInfo, null);
+                            return new IgfsCreateResult(newInfo, secondaryOut);
                         }
                         else {
                             // Create file and parent folders.
@@ -2932,6 +2982,7 @@ public class IgfsMetaManager extends IgfsManager {
                             // Generate events.
                             generateCreateEvents(res.createdPaths(), true);
 
+                            // TODO: Set correct output stream.
                             return new IgfsCreateResult(res.info(), null);
                         }
                     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/670bad65/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsSecondaryFileSystemCreateContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsSecondaryFileSystemCreateContext.java
b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsSecondaryFileSystemCreateContext.java
index ef71c6c..f0fef70 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsSecondaryFileSystemCreateContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsSecondaryFileSystemCreateContext.java
@@ -17,8 +17,13 @@
 
 package org.apache.ignite.internal.processors.igfs;
 
+import org.apache.ignite.igfs.IgfsFile;
+import org.apache.ignite.igfs.IgfsPath;
 import org.apache.ignite.igfs.secondary.IgfsSecondaryFileSystem;
 
+import java.io.OutputStream;
+import java.util.Map;
+
 /**
  * Context for secondary file system create request.
  */
@@ -56,6 +61,29 @@ public class IgfsSecondaryFileSystemCreateContext {
     }
 
     /**
+     * Create file in the secondary file system.
+     *
+     * @param path Path.
+     * @param overwrite Overwrite flag.
+     * @param props Properties.
+     * @return Output stream.
+     */
+    public OutputStream create(IgfsPath path, boolean overwrite, Map<String, String>
props) {
+        return simpleCreate ? fs.create(path, overwrite) :
+            fs.create(path, bufSize, overwrite, replication, blockSize, props);
+    }
+
+    /**
+     * Get file info.
+     *
+     * @param path Path.
+     * @return File.
+     */
+    public IgfsFile info(IgfsPath path) {
+        return fs.info(path);
+    }
+
+    /**
      * @return Secondary file system.
      */
     public IgfsSecondaryFileSystem fileSystem() {


Mime
View raw message