Repository: ignite
Updated Branches:
  refs/heads/ignite-2817 [created] 91fc9ab59


WIP.


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

Branch: refs/heads/ignite-2817
Commit: 112bcfe5c0bf6cc46a51167fb4d2431f28a7e02d
Parents: 7b7233e
Author: thatcoach <ppoze...@list.ru>
Authored: Tue Mar 15 21:46:22 2016 +0300
Committer: thatcoach <ppoze...@list.ru>
Committed: Tue Mar 15 21:46:22 2016 +0300

----------------------------------------------------------------------
 .../processors/igfs/IgfsMetaManager.java        | 174 +++++++++----------
 1 file changed, 82 insertions(+), 92 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/112bcfe5/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 463e7a8..488e332 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
@@ -17,32 +17,6 @@
 
 package org.apache.ignite.internal.processors.igfs;
 
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Deque;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.concurrent.CountDownLatch;
-import javax.cache.processor.EntryProcessor;
-import javax.cache.processor.EntryProcessorException;
-import javax.cache.processor.EntryProcessorResult;
-import javax.cache.processor.MutableEntry;
-
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.IgniteInterruptedException;
@@ -85,14 +59,35 @@ import org.apache.ignite.lang.IgniteClosure;
 import org.apache.ignite.lang.IgniteUuid;
 import org.jetbrains.annotations.Nullable;
 
-import static org.apache.ignite.events.EventType.EVT_IGFS_DIR_CREATED;
-import static org.apache.ignite.events.EventType.EVT_IGFS_DIR_RENAMED;
-import static org.apache.ignite.events.EventType.EVT_IGFS_FILE_CREATED;
-import static org.apache.ignite.events.EventType.EVT_IGFS_FILE_RENAMED;
-import static org.apache.ignite.events.EventType.EVT_IGFS_FILE_OPENED_WRITE;
-import static org.apache.ignite.internal.processors.igfs.IgfsFileInfo.builder;
-import static 
org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
-import static 
org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+import javax.cache.processor.EntryProcessor;
+import javax.cache.processor.EntryProcessorException;
+import javax.cache.processor.MutableEntry;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.concurrent.CountDownLatch;
+
+import static org.apache.ignite.events.EventType.*;
+import static org.apache.ignite.internal.processors.igfs.IgfsFileInfo.*;
+import static org.apache.ignite.transactions.TransactionConcurrency.*;
+import static org.apache.ignite.transactions.TransactionIsolation.*;
 
 /**
  * Cache based structure (meta data) manager.
@@ -806,10 +801,7 @@ public class IgfsMetaManager extends IgfsManager {
         if (childEntry != null)
             return childEntry.fileId();
 
-        if (!id2InfoPrj.putIfAbsent(newFileInfo.id(), newFileInfo))
-            throw fsException("Failed to add file details into cache: " + 
newFileInfo);
-
-        id2InfoPrj.invoke(parentId, new ListingAdd(fileName, new 
IgfsListingEntry(newFileInfo)));
+        createNewEntry(newFileInfo, parentId, fileName);
 
         return null;
     }
@@ -918,8 +910,7 @@ public class IgfsMetaManager extends IgfsManager {
                     // 8. Actual move: remove from source parent and add to 
destination target.
                     IgfsListingEntry entry = 
srcTargetInfo.listing().get(srcName);
 
-                    id2InfoPrj.invoke(srcTargetId, new ListingRemove(srcName, 
entry.fileId()));
-                    id2InfoPrj.invoke(dstTargetId, new ListingAdd(dstName, 
entry));
+                    transferEntry(entry, srcTargetId, srcName, dstTargetId, 
dstName);
 
                     tx.commit();
 
@@ -1047,11 +1038,7 @@ public class IgfsMetaManager extends IgfsManager {
                 " directory (file already exists) [fileId=" + fileId + ", 
destFileName=" + destFileName +
                 ", destParentId=" + destParentId + ']'));
 
-        // Remove listing entry from the source parent listing.
-        id2InfoPrj.invoke(srcParentId, new ListingRemove(srcFileName, 
srcEntry.fileId()));
-
-        // Add listing entry into the destination parent listing.
-        id2InfoPrj.invoke(destParentId, new ListingAdd(destFileName, 
srcEntry));
+        transferEntry(srcEntry, srcParentId, srcFileName, destParentId, 
destFileName);
     }
 
     /**
@@ -1088,11 +1075,7 @@ public class IgfsMetaManager extends IgfsManager {
 
                     IgfsFileInfo newInfo = new IgfsFileInfo(transferListing);
 
-                    id2InfoPrj.put(newInfo.id(), newInfo);
-
-                    // Add new info to trash listing.
-                    id2InfoPrj.invoke(trashId, new 
ListingAdd(newInfo.id().toString(),
-                        new IgfsListingEntry(newInfo)));
+                    createNewEntry(newInfo, trashId, newInfo.id().toString());
 
                     // Remove listing entries from root.
                     // Note that root directory properties and other 
attributes are preserved:
@@ -1191,10 +1174,7 @@ public class IgfsMetaManager extends IgfsManager {
 
                     assert victimId.equals(srcEntry.fileId());
 
-                    id2InfoPrj.invoke(srcParentId, new 
ListingRemove(srcFileName, srcEntry.fileId()));
-
-                    // Add listing entry into the destination parent listing.
-                    id2InfoPrj.invoke(trashId, new ListingAdd(destFileName, 
srcEntry));
+                    transferEntry(srcEntry, srcParentId, srcFileName, trashId, 
destFileName);
 
                     if (victimInfo.isFile())
                         // Update a file info of the removed file with a file 
path,
@@ -1269,11 +1249,7 @@ public class IgfsMetaManager extends IgfsManager {
 
                 IgfsFileInfo newInfo = new IgfsFileInfo(transferListing);
 
-                id2InfoPrj.getAndPut(newInfo.id(), newInfo);
-
-                // Add new info to trash listing.
-                id2InfoPrj.invoke(trashId, new 
ListingAdd(newInfo.id().toString(),
-                    new IgfsListingEntry(newInfo)));
+                createNewEntry(newInfo, trashId, newInfo.id().toString());
 
                 // Remove listing entries from root.
                 for (Map.Entry<String, IgfsListingEntry> entry : 
transferListing.entrySet())
@@ -1353,7 +1329,7 @@ public class IgfsMetaManager extends IgfsManager {
 
                                 // Delete only files or empty folders.
                                 if (!entryInfo.hasChildren()) {
-                                    id2InfoPrj.getAndRemove(childId);
+                                    id2InfoPrj.remove(childId);
 
                                     newListing.remove(childName);
 
@@ -1428,11 +1404,9 @@ public class IgfsMetaManager extends IgfsManager {
                         IgfsListingEntry childEntry = 
parentInfo.listing().get(name);
 
                         if (childEntry != null)
-                            id2InfoPrj.invoke(parentId, new 
ListingRemove(name, childEntry.fileId()));
-
-                        IgfsFileInfo deleted = id2InfoPrj.getAndRemove(id);
+                            id2InfoPrj.invoke(parentId, new 
ListingRemove(name, id));
 
-                        assert victim.id().equals(deleted.id());
+                        id2InfoPrj.remove(id);
 
                         res = true;
                     }
@@ -1547,15 +1521,7 @@ public class IgfsMetaManager extends IgfsManager {
 
             IgfsFileInfo newInfo = new IgfsFileInfo(oldInfo, tmp);
 
-            id2InfoPrj.put(fileId, newInfo);
-
-            if (parentId != null) {
-                IgfsListingEntry entry = new IgfsListingEntry(newInfo);
-
-                assert id2InfoPrj.get(parentId) != null;
-
-                id2InfoPrj.invoke(parentId, new ListingAdd(fileName, entry));
-            }
+            id2InfoPrj.put(newInfo.id(), newInfo);
 
             return newInfo;
         }
@@ -1873,6 +1839,42 @@ public class IgfsMetaManager extends IgfsManager {
     }
 
     /**
+     * Put new entry to meta cache immediately linking it to parent.
+     *
+     * @param info Info to put.
+     * @param parentId Parent ID.
+     * @param name Name in parent.
+     * @throws IgniteCheckedException If failed.
+     */
+    private void createNewEntry(IgfsFileInfo info, IgniteUuid parentId, String 
name) throws IgniteCheckedException {
+        assert validTxState(true);
+
+        if (!id2InfoPrj.putIfAbsent(info.id(), info))
+            throw fsException("Failed to create new metadata entry due to ID 
conflict: " + info.id());
+
+        if (parentId != null)
+            id2InfoPrj.invoke(parentId, new ListingAdd(name, new 
IgfsListingEntry(info)));
+    }
+
+    /**
+     * Transfer entry from one directory to another.
+     *
+     * @param entry Entry to be transfered.
+     * @param srcId Source ID.
+     * @param srcName Source name.
+     * @param destId Destination ID.
+     * @param destName Destination name.
+     * @throws IgniteCheckedException If failed.
+     */
+    private void transferEntry(IgfsListingEntry entry, IgniteUuid srcId, 
String srcName,
+        IgniteUuid destId, String destName) throws IgniteCheckedException {
+        assert validTxState(true);
+
+        id2InfoPrj.invoke(srcId, new ListingRemove(srcName, entry.fileId()));
+        id2InfoPrj.invoke(destId, new ListingAdd(destName, entry));
+    }
+
+    /**
      * Create the file in DUAL mode.
      *
      * @param fs File system.
@@ -1983,12 +1985,10 @@ public class IgfsMetaManager extends IgfsManager {
                                         path + ", fileId=" + oldId + ", 
lockId=" + oldInfo.lockId() + ']');
 
                                 id2InfoPrj.remove(oldId); // Remove the old 
one.
-                                id2InfoPrj.put(newInfo.id(), newInfo); // Put 
the new one.
-
                                 id2InfoPrj.invoke(parentInfo.id(),
                                     new ListingRemove(path.name(), 
parentInfo.listing().get(path.name()).fileId()));
-                                id2InfoPrj.invoke(parentInfo.id(),
-                                    new ListingAdd(path.name(), new 
IgfsListingEntry(newInfo)));
+
+                                createNewEntry(newInfo, parentInfo.id(), 
path.name()); // Put new one.
 
                                 IgniteInternalFuture<?> delFut = 
igfsCtx.data().delete(oldInfo);
                             }
@@ -3379,11 +3379,9 @@ public class IgfsMetaManager extends IgfsManager {
 
                                         IgniteUuid newLockId = 
createFileLockId(false);
 
-                                        EntryProcessorResult<IgfsFileInfo> 
result
-                                            = 
id2InfoPrj.invoke(lowermostExistingInfo.id(),
-                                                new 
LockFileProcessor(newLockId));
+                                        
id2InfoPrj.invoke(lowermostExistingInfo.id(), new FileLockProcessor(newLockId));
 
-                                        IgfsFileInfo lockedInfo = result.get();
+                                        IgfsFileInfo lockedInfo = 
id2InfoPrj.get(lowermostExistingInfo.id());
 
                                         assert lockedInfo != null; // we 
already checked lock above.
                                         assert lockedInfo.lockId() != null;
@@ -3411,11 +3409,8 @@ public class IgfsMetaManager extends IgfsManager {
 
                                         assert deletedEntry != null;
 
-                                        id2InfoPrj.invoke(parentId, new 
ListingRemove(name, deletedEntry.fileId()));
-
-                                        // Add listing entry into the 
destination parent listing.
-                                        id2InfoPrj.invoke(trashId,
-                                            new 
ListingAdd(lowermostExistingInfo.id().toString(), deletedEntry));
+                                        transferEntry(deletedEntry, parentId, 
name, trashId,
+                                            
lowermostExistingInfo.id().toString());
 
                                         // Update a file info of the removed 
file with a file path,
                                         // which will be used by delete worker 
for event notifications.
@@ -3429,12 +3424,7 @@ public class IgfsMetaManager extends IgfsManager {
 
                                         assert newFileInfo.lockId() != null; 
// locked info should be created.
 
-                                        boolean put = 
id2InfoPrj.putIfAbsent(newFileInfo.id(), newFileInfo);
-
-                                        assert put;
-
-                                        id2InfoPrj.invoke(parentId,
-                                                new ListingAdd(name, new 
IgfsListingEntry(newFileInfo)));
+                                        createNewEntry(newFileInfo, parentId, 
name);
 
                                         IgniteBiTuple<IgfsFileInfo, 
IgniteUuid> t2 = new T2<>(newFileInfo, parentId);
 

Reply via email to