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/15 21:11:40 UTC
[2/9] ignite git commit: WIP.
WIP.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/13e2c1ee
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/13e2c1ee
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/13e2c1ee
Branch: refs/heads/ignite-2817
Commit: 13e2c1eecf7b953cc8a9bda20e4aa19a9897e455
Parents: 112bcfe
Author: thatcoach <pp...@list.ru>
Authored: Tue Mar 15 21:59:15 2016 +0300
Committer: thatcoach <pp...@list.ru>
Committed: Tue Mar 15 21:59:15 2016 +0300
----------------------------------------------------------------------
.../processors/igfs/IgfsMetaManager.java | 116 ++++++-------------
1 file changed, 33 insertions(+), 83 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/13e2c1ee/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 488e332..644f617 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
@@ -479,11 +479,7 @@ public class IgfsMetaManager extends IgfsManager {
if (oldInfo.lockId() != null)
return null; // The file is already locked, we cannot lock it.
- IgniteUuid lockId = createFileLockId(delete);
-
- id2InfoPrj.invoke(fileId, new FileLockProcessor(lockId));
-
- IgfsFileInfo newInfo = id2InfoPrj.get(fileId);
+ IgfsFileInfo newInfo = invokeLock(fileId, delete);
tx.commit();
@@ -1595,9 +1591,7 @@ public class IgfsMetaManager extends IgfsManager {
if (oldInfo == null)
throw fsException("File has been deleted concurrently [path=" + path + ", id=" + fileId + ']');
- id2InfoPrj.invoke(fileId, new FileReserveSpaceProcessor(space, affRange));
-
- IgfsFileInfo newInfo = id2InfoPrj.get(fileId);
+ IgfsFileInfo newInfo = invokeAndGet(fileId, new FileReserveSpaceProcessor(space, affRange));
tx.commit();
@@ -1875,6 +1869,35 @@ public class IgfsMetaManager extends IgfsManager {
}
/**
+ * Invoke lock processor.
+ *
+ * @param id File ID.
+ * @param delete Whether lock is taken for delete.
+ * @return Resulting file info.
+ * @throws IgniteCheckedException If failed.
+ */
+ private IgfsFileInfo invokeLock(IgniteUuid id, boolean delete) throws IgniteCheckedException {
+ return invokeAndGet(id, new FileLockProcessor(createFileLockId(delete)));
+ }
+
+ /**
+ * Invoke some processor and return new value.
+ *
+ * @param id ID.
+ * @param proc Processor.
+ * @return New file info.
+ * @throws IgniteCheckedException If failed.
+ */
+ private IgfsFileInfo invokeAndGet(IgniteUuid id, EntryProcessor<IgniteUuid, IgfsFileInfo, Void> proc)
+ throws IgniteCheckedException {
+ assert validTxState(true);
+
+ id2InfoPrj.invoke(id, proc);
+
+ return id2InfoPrj.get(id);
+ }
+
+ /**
* Create the file in DUAL mode.
*
* @param fs File system.
@@ -2087,11 +2110,7 @@ public class IgfsMetaManager extends IgfsManager {
}
// Set lock and return.
- IgniteUuid lockId = createFileLockId(false);
-
- id2InfoPrj.invoke(info.id(), new FileLockProcessor(lockId));
-
- IgfsFileInfo lockedInfo = id2InfoPrj.get(info.id());
+ IgfsFileInfo lockedInfo = invokeLock(info.id(), false);
return new IgfsSecondaryOutputStreamDescriptor(infos.get(path.parent()).id(),
lockedInfo, out);
@@ -3377,16 +3396,7 @@ public class IgfsMetaManager extends IgfsManager {
+ "[fileName=" + name + ", fileId=" + lowermostExistingInfo.id()
+ ", lockId=" + lockId + ']');
- IgniteUuid newLockId = createFileLockId(false);
-
- id2InfoPrj.invoke(lowermostExistingInfo.id(), new FileLockProcessor(newLockId));
-
- IgfsFileInfo lockedInfo = id2InfoPrj.get(lowermostExistingInfo.id());
-
- assert lockedInfo != null; // we already checked lock above.
- assert lockedInfo.lockId() != null;
- assert lockedInfo.lockId().equals(newLockId);
- assert lockedInfo.id().equals(lowermostExistingInfo.id());
+ IgfsFileInfo lockedInfo = invokeLock(lowermostExistingInfo.id(), false);
IgniteBiTuple<IgfsFileInfo, IgniteUuid> t2 = new T2<>(lockedInfo, parentId);
@@ -3674,66 +3684,6 @@ public class IgfsMetaManager extends IgfsManager {
}
/**
- * Processor closure to locks a file for writing.
- */
- private static class LockFileProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, IgfsFileInfo>,
- Externalizable {
- /** */
- private static final long serialVersionUID = 0L;
-
- /** New lock id to lock the entry. */
- private IgniteUuid newLockId;
-
- /**
- * Constructor.
- */
- public LockFileProcessor(IgniteUuid newLockId) {
- assert newLockId != null;
-
- this.newLockId = newLockId;
- }
-
- /**
- * Empty constructor required for {@link Externalizable}.
- */
- public LockFileProcessor() {
- // No-op.
- }
-
- /** {@inheritDoc} */
- @Override @Nullable public IgfsFileInfo process(MutableEntry<IgniteUuid, IgfsFileInfo> entry,
- Object... arguments) throws EntryProcessorException {
- final IgfsFileInfo info = entry.getValue();
-
- assert info != null;
-
- if (info.lockId() != null)
- return null; // file is already locked.
-
- IgfsFileInfo newInfo = new IgfsFileInfo(info, newLockId, info.modificationTime());
-
- entry.setValue(newInfo);
-
- return newInfo;
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- U.writeGridUuid(out, newLockId);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- newLockId = U.readGridUuid(in);
- }
-
- /** {@inheritDoc} */
- @Override public String toString() {
- return S.toString(LockFileProcessor.class, this);
- }
- }
-
- /**
* File lock entry processor.
*/
private static class FileLockProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, Void>, Externalizable {