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 2016/03/17 21:08:42 UTC
[1/2] ignite git commit: WIP on move (1).
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 <pp...@list.ru>
Authored: Thu Mar 17 22:52:34 2016 +0300
Committer: thatcoach <pp...@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);
+ }
}
[2/2] ignite git commit: Finished with move.
Posted by vo...@apache.org.
Finished with move.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/b4079ceb
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/b4079ceb
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/b4079ceb
Branch: refs/heads/ignite-igfs-refactoring
Commit: b4079ceb73dfd2bdd2968e8aa7b85bee23c9a8a3
Parents: cc86501
Author: thatcoach <pp...@list.ru>
Authored: Thu Mar 17 23:03:13 2016 +0300
Committer: thatcoach <pp...@list.ru>
Committed: Thu Mar 17 23:03:13 2016 +0300
----------------------------------------------------------------------
.../processors/igfs/IgfsMetaManager.java | 99 +++++---------------
1 file changed, 25 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/b4079ceb/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 8084334..21e0e86 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
@@ -849,7 +849,7 @@ public class IgfsMetaManager extends IgfsManager {
// Prepare path IDs.
IgfsPathIds srcPathIds = pathIds(srcPath);
- IgfsPathIds dstPathIds2 = pathIds(dstPath);
+ IgfsPathIds dstPathIds = pathIds(dstPath);
// Source path must exists.
if (!srcPathIds.allPartsFound())
@@ -860,17 +860,17 @@ public class IgfsMetaManager extends IgfsManager {
// or source leaf depending on existence.
String dstName;
- if (dstPathIds2.lastExists())
+ if (dstPathIds.lastExists())
// Full destination path exists -> use source name.
dstName = srcPathIds.lastPart();
else {
- if (dstPathIds2.lastParentExists()) {
+ if (dstPathIds.lastParentExists()) {
// Destination path doesn't exists -> use destination name.
- dstName = dstPathIds2.lastPart();
+ dstName = dstPathIds.lastPart();
- assert dstPathIds2.lastHasParent();
+ assert dstPathIds.lastHasParent();
- dstPathIds2 = dstPathIds2.parent();
+ dstPathIds = dstPathIds.parent();
}
else
// Destination parent is not found either -> exception.
@@ -878,100 +878,51 @@ public class IgfsMetaManager extends IgfsManager {
"found: " + dstPath.parent());
}
- // ---------------------------------
-
- // 1. First get source and destination path IDs.
- List<IgniteUuid> dstPathIds = fileIds(dstPath);
-
+ // Lock participating IDs.
final Set<IgniteUuid> lockIds = new TreeSet<>(PATH_ID_SORTING_COMPARATOR);
srcPathIds.addExistingIds(lockIds);
+ dstPathIds.addExistingIds(lockIds);
- final IgniteUuid dstLeafId = dstPathIds.get(dstPathIds.size() - 1);
-
- if (dstLeafId == null) {
- // Delete null entry for the unexisting destination element:
- dstPathIds.remove(dstPathIds.size() - 1);
- }
-
- lockIds.addAll(dstPathIds);
-
- if (lockIds.remove(null)) {
- throw new IgfsPathNotFoundException("Failed to perform move because some path component was " +
- "not found. [src=" + srcPath + ", dst=" + dstPath + ']');
- }
-
- // 2. Start transaction.
IgniteInternalTx tx = startTx();
try {
- // 3. Obtain the locks.
+ // Obtain the locks.
final Map<IgniteUuid, IgfsFileInfo> lockInfos = lockIds(lockIds);
- // 4. Verify integrity of source directory.
- //if (!verifyPathIntegrity(srcPath, srcPathIds, lockInfos))
+ // Verify integrity of source and destination paths.
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, lockInfos)) {
- if (!dstPathIds2.verifyIntergrity(lockInfos))
+ if (!dstPathIds.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.lastParentId();
- IgfsFileInfo srcTargetInfo = lockInfos.get(srcTargetId);
- String srcName = srcPath.name();
-
- IgniteUuid dstTargetId;
- IgfsFileInfo dstTargetInfo;
-
- if (dstLeafId != null) {
- // Destination leaf exists. Check if it is an empty directory.
- IgfsFileInfo dstLeafInfo = lockInfos.get(dstLeafId);
+ // Addiional check: is destination directory?
+ IgfsFileInfo destInfo = lockInfos.get(dstPathIds.lastId());
- assert dstLeafInfo != null;
+ if (destInfo.isFile())
+ throw new IgfsPathAlreadyExistsException("Failed to perform move because destination points " +
+ "to existing file [src=" + srcPath + ", dst=" + dstPath + ']');
- if (dstLeafInfo.isDirectory()) {
- // Destination is a directory.
- dstTargetId = dstLeafId;
- dstTargetInfo = dstLeafInfo;
- }
- else {
- // Error, destination is existing file.
- throw new IgfsPathAlreadyExistsException("Failed to perform move " +
- "because destination points to " +
- "existing file [src=" + srcPath + ", dst=" + dstPath + ']');
- }
- }
- else {
- // Destination leaf doesn't exist, so we operate on parent.
- dstTargetId = dstPathIds.get(dstPathIds.size() - 1);
- dstTargetInfo = lockInfos.get(dstTargetId);
- }
-
- assert dstTargetInfo != null;
- assert dstTargetInfo.isDirectory();
-
- // 7. Last check: does destination target already have listing entry with the same name?
- if (dstTargetInfo.hasChild(dstName)) {
+ // Additional check: does destination already has child with the same name?
+ if (destInfo.hasChild(dstName))
throw new IgfsPathAlreadyExistsException("Failed to perform move because destination already " +
"contains entry with the same name existing file [src=" + srcPath +
", dst=" + dstPath + ']');
- }
- // 8. Actual move: remove from source parent and add to destination target.
- IgfsListingEntry entry = srcTargetInfo.listing().get(srcName);
+ // Actual move: remove from source parent and add to destination target.
+ IgfsFileInfo srcParentInfo = lockInfos.get(srcPathIds.lastParentId());
+
+ IgfsListingEntry entry = srcParentInfo.listing().get(srcPathIds.lastPart());
- transferEntry(entry, srcTargetId, srcName, dstTargetId, dstName);
+ transferEntry(entry, srcPathIds.lastParentId(), srcPathIds.lastPart(),
+ dstPathIds.lastId(), dstName);
tx.commit();
- IgfsPath realNewPath = new IgfsPath(dstDirPath, dstName);
+ IgfsPath realNewPath = new IgfsPath(dstPathIds.path(), dstName);
IgfsFileInfo moved = lockInfos.get(srcPathIds.lastId());