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/18 13:31:28 UTC
[3/4] ignite git commit: Refactored common code base of create and
append.
Refactored common code base of create and append.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/383169c7
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/383169c7
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/383169c7
Branch: refs/heads/ignite-igfs-refactoring
Commit: 383169c729c01bfc7d3f29c1c8e82e61b57238f9
Parents: 3f24853
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Fri Mar 18 15:30:50 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Fri Mar 18 15:30:50 2016 +0300
----------------------------------------------------------------------
.../apache/ignite/internal/IgniteKernal.java | 6 +-
.../processors/igfs/IgfsMetaManager.java | 244 +++++++++----------
.../processors/igfs/IgfsPathsCreateResult.java | 77 ++++++
3 files changed, 190 insertions(+), 137 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/383169c7/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 8df89f3..1771967 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -858,9 +858,9 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
startProcessor(new DataStreamProcessor(ctx));
startProcessor((GridProcessor)IGFS.create(ctx, F.isEmpty(cfg.getFileSystemConfiguration())));
startProcessor(new GridContinuousProcessor(ctx));
- startProcessor((GridProcessor)(cfg.isPeerClassLoadingEnabled() ?
- IgniteComponentType.HADOOP.create(ctx, true): // No-op when peer class loading is enabled.
- IgniteComponentType.HADOOP.createIfInClassPath(ctx, cfg.getHadoopConfiguration() != null)));
+// startProcessor((GridProcessor)(cfg.isPeerClassLoadingEnabled() ?
+// IgniteComponentType.HADOOP.create(ctx, true): // No-op when peer class loading is enabled.
+// IgniteComponentType.HADOOP.createIfInClassPath(ctx, cfg.getHadoopConfiguration() != null)));
startProcessor(new DataStructuresProcessor(ctx));
startProcessor(createComponent(PlatformProcessor.class, ctx));
http://git-wip-us.apache.org/repos/asf/ignite/blob/383169c7/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 ef2bffb..4918c23 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
@@ -3452,80 +3452,20 @@ public class IgfsMetaManager extends IgfsManager {
return t2;
}
else {
- // Need to create directory structure first. This is our starting point:
- int lastExistingIdx = pathIds.lastExistingIndex();
- IgfsFileInfo lastExistingInfo = lockInfos.get(pathIds.lastExistingId());
+ // Create file and parent folders.
+ IgfsPathsCreateResult res =
+ createFile(pathIds, lockInfos, dirProps, fileProps, blockSize, affKey, evictExclude);
- // Check if entry we are going to write to is directory.
- if (lastExistingInfo.isFile())
- throw new IgfsParentNotDirectoryException("Failed to open file for write file " +
- "(parent element is not a directory): " + path);
-
- // If current info already contains entry with the same name as it's child, then something
- // has changed concurrently. We must re-try because we cannot get info of this unexpected
- // element due to possible deadlocks.
- int curIdx = lastExistingIdx + 1;
-
- String curPart = pathIds.part(curIdx);
- IgniteUuid curId = pathIds.surrogateId(curIdx);
- IgniteUuid curParentId = lastExistingInfo.id();
-
- if (lastExistingInfo.hasChild(curPart))
+ if (res == null)
continue;
- // First step: add new entry to the last existing element.
- id2InfoPrj.invoke(lastExistingInfo.id(), new ListingAddProcessor(curPart,
- new IgfsListingEntry(curId, !pathIds.isLastIndex(curIdx))));
-
- // Events support.
- IgfsPath lastCreatedPath = pathIds.lastExistingPath();
-
- Collection<IgfsPath> createdPaths = new ArrayList<>(pathIds.count() - curIdx);
-
- // Second step: create middle directories.
- long createTime = System.currentTimeMillis();
-
- while (curIdx < pathIds.count() - 1) {
- String nextPart = pathIds.part(curIdx + 1);
- IgniteUuid nextId = pathIds.surrogateId(curIdx + 1);
-
- // This flag will be true for all directories except the last one.
- id2InfoPrj.invoke(curId, new DirectoryCreateProcessor(createTime, dirProps,
- nextPart, new IgfsListingEntry(nextId, !pathIds.isLastIndex(curIdx + 1))));
-
- // Save event.
- lastCreatedPath = new IgfsPath(lastCreatedPath, curPart);
-
- createdPaths.add(lastCreatedPath);
-
- // Advance things further.
- curIdx++;
-
- curParentId = curId;
-
- curPart = nextPart;
- curId = nextId;
- }
-
- // Third step: create leaf file.
- IgfsFileInfo info = invokeAndGet(curId, new FileCreateProcessor(createTime, fileProps,
- blockSize, affKey, createFileLockId(false), evictExclude));
-
- IgniteBiTuple<IgfsFileInfo, IgniteUuid> t2 = new T2<>(info, curParentId);
-
+ // Commit.
tx.commit();
// Generate events.
- if (evts.isRecordable(EventType.EVT_IGFS_DIR_CREATED)) {
- for (IgfsPath createdPath : createdPaths)
- IgfsUtils.sendEvents(igfsCtx.kernalContext(), createdPath,
- EventType.EVT_IGFS_DIR_CREATED);
- }
+ generateCreateFileEvents(res.createdPaths());
- IgfsUtils.sendEvents(igfsCtx.kernalContext(), path, EventType.EVT_IGFS_FILE_CREATED);
- IgfsUtils.sendEvents(igfsCtx.kernalContext(), path, EventType.EVT_IGFS_FILE_OPENED_WRITE);
-
- return t2;
+ return new T2<>(res.info(), res.parentId());
}
}
finally {
@@ -3541,8 +3481,6 @@ public class IgfsMetaManager extends IgfsManager {
}
}
- private
-
/**
* Create a new file.
*
@@ -3648,93 +3586,131 @@ public class IgfsMetaManager extends IgfsManager {
return t2;
}
else {
- // Need to create directory structure first. This is our starting point:
- int lastExistingIdx = pathIds.lastExistingIndex();
- IgfsFileInfo lastExistingInfo = lockInfos.get(pathIds.lastExistingId());
+ // Create file and parent folders.
+ IgfsPathsCreateResult res =
+ createFile(pathIds, lockInfos, dirProps, fileProps, blockSize, affKey, evictExclude);
- // Check if entry we are going to write to is directory.
- if (lastExistingInfo.isFile())
- throw new IgfsParentNotDirectoryException("Failed to open file for write file " +
- "(parent element is not a directory): " + path);
+ if (res == null)
+ continue;
- // If current info already contains entry with the same name as it's child, then something
- // has changed concurrently. We must re-try because we cannot get info of this unexpected
- // element due to possible deadlocks.
- int curIdx = lastExistingIdx + 1;
+ // Commit.
+ tx.commit();
- String curPart = pathIds.part(curIdx);
- IgniteUuid curId = pathIds.surrogateId(curIdx);
- IgniteUuid curParentId = lastExistingInfo.id();
+ // Generate events.
+ generateCreateFileEvents(res.createdPaths());
- if (lastExistingInfo.hasChild(curPart))
- continue;
+ return new T2<>(res.info(), res.parentId());
+ }
+ }
+ finally {
+ tx.close();
+ }
+ }
+ finally {
+ busyLock.leaveBusy();
+ }
+ }
+ else
+ throw new IllegalStateException("Failed to mkdir because Grid is stopping. [path=" + path + ']');
+ }
+ }
- // First step: add new entry to the last existing element.
- id2InfoPrj.invoke(lastExistingInfo.id(), new ListingAddProcessor(curPart,
- new IgfsListingEntry(curId, !pathIds.isLastIndex(curIdx))));
+ /**
+ * Create file and all it's parents.
+ *
+ * @param pathIds Paths IDs.
+ * @param lockInfos Lock infos.
+ * @param dirProps Directory properties.
+ * @param fileProps File propertris.
+ * @param blockSize Block size.
+ * @param affKey Affinity key (optional)
+ * @param evictExclude Evict exclude flag.
+ * @return Result or {@code} if the first parent already contained child with the same name.
+ * @throws IgniteCheckedException If failed.
+ */
+ @Nullable private IgfsPathsCreateResult createFile(IgfsPathIds pathIds, Map<IgniteUuid, IgfsFileInfo> lockInfos,
+ Map<String, String> dirProps, Map<String, String> fileProps, int blockSize, @Nullable IgniteUuid affKey,
+ boolean evictExclude) throws IgniteCheckedException{
+ // This is our starting point:
+ int lastExistingIdx = pathIds.lastExistingIndex();
+ IgfsFileInfo lastExistingInfo = lockInfos.get(pathIds.lastExistingId());
+
+ if (lastExistingInfo.hasChild(pathIds.part(lastExistingIdx + 1)))
+ return null;
- // Events support.
- IgfsPath lastCreatedPath = pathIds.lastExistingPath();
+ // Check if entry we are going to write to is directory.
+ if (lastExistingInfo.isFile())
+ throw new IgfsParentNotDirectoryException("Failed to open file for write " +
+ "(parent element is not a directory): " + pathIds.path());
- Collection<IgfsPath> createdPaths = new ArrayList<>(pathIds.count() - curIdx);
+ // If current info already contains entry with the same name as it's child, then something
+ // has changed concurrently. We must re-try because we cannot get info of this unexpected
+ // element due to possible deadlocks.
+ int curIdx = lastExistingIdx + 1;
- // Second step: create middle directories.
- long createTime = System.currentTimeMillis();
+ String curPart = pathIds.part(curIdx);
+ IgniteUuid curId = pathIds.surrogateId(curIdx);
+ IgniteUuid curParentId = lastExistingInfo.id();
- while (curIdx < pathIds.count() - 1) {
- String nextPart = pathIds.part(curIdx + 1);
- IgniteUuid nextId = pathIds.surrogateId(curIdx + 1);
+ // First step: add new entry to the last existing element.
+ id2InfoPrj.invoke(lastExistingInfo.id(), new ListingAddProcessor(curPart,
+ new IgfsListingEntry(curId, !pathIds.isLastIndex(curIdx))));
- // This flag will be true for all directories except the last one.
- id2InfoPrj.invoke(curId, new DirectoryCreateProcessor(createTime, dirProps,
- nextPart, new IgfsListingEntry(nextId, !pathIds.isLastIndex(curIdx + 1))));
+ // Events support.
+ IgfsPath lastCreatedPath = pathIds.lastExistingPath();
- // Save event.
- lastCreatedPath = new IgfsPath(lastCreatedPath, curPart);
+ List<IgfsPath> createdPaths = new ArrayList<>(pathIds.count() - curIdx);
- createdPaths.add(lastCreatedPath);
+ // Second step: create middle directories.
+ long createTime = System.currentTimeMillis();
- // Advance things further.
- curIdx++;
+ while (curIdx < pathIds.count() - 1) {
+ String nextPart = pathIds.part(curIdx + 1);
+ IgniteUuid nextId = pathIds.surrogateId(curIdx + 1);
- curParentId = curId;
+ // This flag will be true for all directories except the last one.
+ id2InfoPrj.invoke(curId, new DirectoryCreateProcessor(createTime, dirProps,
+ nextPart, new IgfsListingEntry(nextId, !pathIds.isLastIndex(curIdx + 1))));
- curPart = nextPart;
- curId = nextId;
- }
+ // Save event.
+ lastCreatedPath = new IgfsPath(lastCreatedPath, curPart);
- // Third step: create leaf file.
- IgfsFileInfo info = invokeAndGet(curId, new FileCreateProcessor(createTime, fileProps,
- blockSize, affKey, createFileLockId(false), evictExclude));
+ createdPaths.add(lastCreatedPath);
- IgniteBiTuple<IgfsFileInfo, IgniteUuid> t2 = new T2<>(info, curParentId);
+ // Advance things further.
+ curIdx++;
- tx.commit();
+ curParentId = curId;
- // Generate events.
- if (evts.isRecordable(EventType.EVT_IGFS_DIR_CREATED)) {
- for (IgfsPath createdPath : createdPaths)
- IgfsUtils.sendEvents(igfsCtx.kernalContext(), createdPath,
- EventType.EVT_IGFS_DIR_CREATED);
- }
+ curPart = nextPart;
+ curId = nextId;
+ }
- IgfsUtils.sendEvents(igfsCtx.kernalContext(), path, EventType.EVT_IGFS_FILE_CREATED);
- IgfsUtils.sendEvents(igfsCtx.kernalContext(), path, EventType.EVT_IGFS_FILE_OPENED_WRITE);
+ // Third step: create leaf file.
+ IgfsFileInfo info = invokeAndGet(curId, new FileCreateProcessor(createTime, fileProps,
+ blockSize, affKey, createFileLockId(false), evictExclude));
- return t2;
- }
- }
- finally {
- tx.close();
- }
- }
- finally {
- busyLock.leaveBusy();
- }
- }
- else
- throw new IllegalStateException("Failed to mkdir because Grid is stopping. [path=" + path + ']');
+ createdPaths.add(pathIds.path());
+
+ return new IgfsPathsCreateResult(createdPaths, info, curParentId);
+ }
+
+ /**
+ * Generate events for created file.
+ *
+ * @param createdPaths Created paths.
+ */
+ private void generateCreateFileEvents(List<IgfsPath> createdPaths) {
+ if (evts.isRecordable(EventType.EVT_IGFS_DIR_CREATED)) {
+ for (int i = 0; i < createdPaths.size() - 1; i++)
+ IgfsUtils.sendEvents(igfsCtx.kernalContext(), createdPaths.get(i),
+ EventType.EVT_IGFS_DIR_CREATED);
}
+
+ IgfsPath filePath = createdPaths.get(createdPaths.size() - 1);
+
+ IgfsUtils.sendEvents(igfsCtx.kernalContext(), filePath, EventType.EVT_IGFS_FILE_CREATED);
+ IgfsUtils.sendEvents(igfsCtx.kernalContext(), filePath, EventType.EVT_IGFS_FILE_OPENED_WRITE);
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/383169c7/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPathsCreateResult.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPathsCreateResult.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPathsCreateResult.java
new file mode 100644
index 0000000..3b620f8
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsPathsCreateResult.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.igfs;
+
+import org.apache.ignite.igfs.IgfsPath;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lang.IgniteUuid;
+
+import java.util.List;
+
+/**
+ * IGFS paths create result.
+ */
+public class IgfsPathsCreateResult {
+ /** Created paths. */
+ private final List<IgfsPath> paths;
+
+ /** Info of the last created file. */
+ private final IgfsFileInfo info;
+
+ /** Parent ID. */
+ private final IgniteUuid parentId;
+
+ /**
+ * Constructor.
+ *
+ * @param paths Created paths.
+ * @param info Info of the last created file.
+ * @param parentId Parent ID.
+ */
+ public IgfsPathsCreateResult(List<IgfsPath> paths, IgfsFileInfo info, IgniteUuid parentId) {
+ this.paths = paths;
+ this.info = info;
+ this.parentId = parentId;
+ }
+
+ /**
+ * @return Created paths.
+ */
+ public List<IgfsPath> createdPaths() {
+ return paths;
+ }
+
+ /**
+ * @return Info of the last created file.
+ */
+ public IgfsFileInfo info() {
+ return info;
+ }
+
+ /**
+ * @return Parent ID.
+ */
+ public IgniteUuid parentId() {
+ return parentId;
+ }
+
+ /** {@inheritDoc} */
+ @Override public String toString() {
+ return S.toString(IgfsPathsCreateResult.class, this);
+ }
+}