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/14 10:39:25 UTC
[2/3] ignite git commit: IGNITE-2814: Lock routine.
IGNITE-2814: Lock routine.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/5ea6d67d
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/5ea6d67d
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/5ea6d67d
Branch: refs/heads/ignite-2814
Commit: 5ea6d67d82898fa49d900a9a9e049f5bfaeb0fe6
Parents: 3c62cfa
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Mon Mar 14 12:21:57 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Mon Mar 14 12:21:57 2016 +0300
----------------------------------------------------------------------
.../processors/igfs/IgfsMetaManager.java | 98 ++++++++++++--------
1 file changed, 61 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/5ea6d67d/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 943f009..50d553f 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
@@ -466,10 +466,11 @@ public class IgfsMetaManager extends IgfsManager {
* Lock the file explicitly outside of transaction.
*
* @param fileId File ID to lock.
+ * @param delete If file is being locked for delete.
* @return Locked file info or {@code null} if file cannot be locked or doesn't exist.
* @throws IgniteCheckedException If the file with such id does not exist, or on another failure.
*/
- public @Nullable IgfsFileInfo lock(IgniteUuid fileId, boolean isDeleteLock) throws IgniteCheckedException {
+ public @Nullable IgfsFileInfo lock(IgniteUuid fileId, boolean delete) throws IgniteCheckedException {
if (busyLock.enterBusy()) {
try {
assert validTxState(false);
@@ -487,13 +488,11 @@ public class IgfsMetaManager extends IgfsManager {
if (oldInfo.lockId() != null)
return null; // The file is already locked, we cannot lock it.
- IgfsFileInfo newInfo = lockInfo(oldInfo, isDeleteLock);
+ IgniteUuid lockId = createFileLockId(delete);
- boolean put = id2InfoPrj.replace(fileId, oldInfo, newInfo);
+ id2InfoPrj.invoke(fileId, new FileLockProcessor(lockId));
- assert put : "Value was not stored in cache [fileId=" + fileId + ", newInfo=" + newInfo + ']';
-
- assert newInfo.id().equals(oldInfo.id()); // Same id.
+ IgfsFileInfo newInfo = id2InfoPrj.get(fileId);
tx.commit();
@@ -515,30 +514,13 @@ public class IgfsMetaManager extends IgfsManager {
}
/**
- * Set lock on file info.
+ * Create file lock ID.
*
- * @param info File info.
- * @return New file info with lock set, or null if the info passed in is already locked.
- * @throws IgniteCheckedException In case lock is already set on that file.
+ * @param delete If lock ID is required for file deletion.
+ * @return Lock ID.
*/
- private @Nullable IgfsFileInfo lockInfo(IgfsFileInfo info, boolean isDeleteLock) {
- assert info != null;
-
- if (info.lockId() != null)
- return null; // Null return value indicates that the file is already locked.
-
- return new IgfsFileInfo(info, composeLockId(isDeleteLock), info.modificationTime());
- }
-
- /**
- * Gets a new lock id.
- * The returned Id #globalId() method will return the Id of the node which locked the file.
- *
- * @param isDeleteLock if this is special delete lock.
- * @return The new lock id.
- */
- private IgniteUuid composeLockId(boolean isDeleteLock) {
- if (isDeleteLock)
+ private IgniteUuid createFileLockId(boolean delete) {
+ if (delete)
return IgfsUtils.DELETE_LOCK_ID;
return IgniteUuid.fromUuid(locNode.id());
@@ -606,6 +588,50 @@ public class IgfsMetaManager extends IgfsManager {
}
/**
+ * File lock entry processor.
+ */
+ private static class FileLockProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, Void>, Externalizable {
+ /** Lock Id. */
+ private IgniteUuid lockId;
+
+ /**
+ * Default constructor.
+ */
+ public FileLockProcessor() {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param lockId Lock ID.
+ */
+ public FileLockProcessor(IgniteUuid lockId) {
+ this.lockId = lockId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public Void process(MutableEntry<IgniteUuid, IgfsFileInfo> entry, Object... args)
+ throws EntryProcessorException {
+ IgfsFileInfo old = entry.getValue();
+
+ entry.setValue(new IgfsFileInfo(old, lockId, old.modificationTime()));
+
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ U.writeGridUuid(out, lockId);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ lockId = U.readGridUuid(in);
+ }
+ }
+
+ /**
* File unlock entry processor.
*/
private static class FileUnlockProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, Void>, Externalizable {
@@ -2031,7 +2057,7 @@ public class IgfsMetaManager extends IgfsManager {
"the secondary file system because the path points to a directory: " + path);
IgfsFileInfo newInfo = new IgfsFileInfo(status.blockSize(), status.length(), affKey,
- composeLockId(false), igfsCtx.igfs().evictExclude(path, false), status.properties(),
+ createFileLockId(false), igfsCtx.igfs().evictExclude(path, false), status.properties(),
status.accessTime(), status.modificationTime());
// Add new file info to the listing optionally removing the previous one.
@@ -2152,13 +2178,11 @@ public class IgfsMetaManager extends IgfsManager {
}
// Set lock and return.
- IgfsFileInfo lockedInfo = lockInfo(info, false);
-
- assert lockedInfo != null; // We checked the lock above.
+ IgniteUuid lockId = createFileLockId(false);
- boolean put = id2InfoPrj.put(info.id(), lockedInfo);
+ id2InfoPrj.invoke(info.id(), new FileLockProcessor(lockId));
- assert put;
+ IgfsFileInfo lockedInfo = id2InfoPrj.get(info.id());
return new IgfsSecondaryOutputStreamDescriptor(infos.get(path.parent()).id(),
lockedInfo, out);
@@ -3494,7 +3518,7 @@ public class IgfsMetaManager extends IgfsManager {
@Override protected IgfsFileInfo buildLeaf() {
long t = System.currentTimeMillis();
- return new IgfsFileInfo(blockSize, 0L, affKey, composeLockId(false),
+ return new IgfsFileInfo(blockSize, 0L, affKey, createFileLockId(false),
evictExclude, leafProps, t, t);
}
};
@@ -3544,7 +3568,7 @@ public class IgfsMetaManager extends IgfsManager {
+ "[fileName=" + name + ", fileId=" + lowermostExistingInfo.id()
+ ", lockId=" + lockId + ']');
- IgniteUuid newLockId = composeLockId(false);
+ IgniteUuid newLockId = createFileLockId(false);
EntryProcessorResult<IgfsFileInfo> result
= id2InfoPrj.invoke(lowermostExistingInfo.id(),
@@ -3592,7 +3616,7 @@ public class IgfsMetaManager extends IgfsManager {
long t = System.currentTimeMillis();
final IgfsFileInfo newFileInfo = new IgfsFileInfo(cfg.getBlockSize(), 0L,
- affKey, composeLockId(false), evictExclude, fileProps, t, t);
+ affKey, createFileLockId(false), evictExclude, fileProps, t, t);
assert newFileInfo.lockId() != null; // locked info should be created.