Optimzied propertiea update.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/91fc9ab5 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/91fc9ab5 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/91fc9ab5 Branch: refs/heads/ignite-2817 Commit: 91fc9ab595968b86f7aad4237cea8f6fd0fbd1ce Parents: 57c8346 Author: thatcoach <ppoze...@list.ru> Authored: Tue Mar 15 23:06:14 2016 +0300 Committer: thatcoach <ppoze...@list.ru> Committed: Tue Mar 15 23:06:14 2016 +0300 ---------------------------------------------------------------------- .../internal/processors/igfs/IgfsImpl.java | 62 ++++----- .../processors/igfs/IgfsMetaManager.java | 133 +++++++++++-------- 2 files changed, 99 insertions(+), 96 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/91fc9ab5/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java index f44eda8..f413af3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsImpl.java @@ -17,24 +17,6 @@ package org.apache.ignite.internal.processors.igfs; -import java.io.IOException; -import java.io.OutputStream; -import java.net.URI; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.Callable; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicLong; import org.apache.ignite.Ignite; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; @@ -94,23 +76,29 @@ import org.apache.ignite.thread.IgniteThreadPoolExecutor; import org.jetbrains.annotations.Nullable; import org.jsr166.ConcurrentHashMap8; -import static org.apache.ignite.events.EventType.EVT_IGFS_DIR_DELETED; -import static org.apache.ignite.events.EventType.EVT_IGFS_DIR_RENAMED; -import static org.apache.ignite.events.EventType.EVT_IGFS_FILE_CLOSED_READ; -import static org.apache.ignite.events.EventType.EVT_IGFS_FILE_CLOSED_WRITE; -import static org.apache.ignite.events.EventType.EVT_IGFS_FILE_DELETED; -import static org.apache.ignite.events.EventType.EVT_IGFS_FILE_OPENED_READ; -import static org.apache.ignite.events.EventType.EVT_IGFS_FILE_OPENED_WRITE; -import static org.apache.ignite.events.EventType.EVT_IGFS_FILE_RENAMED; -import static org.apache.ignite.events.EventType.EVT_IGFS_META_UPDATED; -import static org.apache.ignite.events.EventType.EVT_NODE_FAILED; -import static org.apache.ignite.events.EventType.EVT_NODE_LEFT; -import static org.apache.ignite.igfs.IgfsMode.DUAL_ASYNC; -import static org.apache.ignite.igfs.IgfsMode.DUAL_SYNC; -import static org.apache.ignite.igfs.IgfsMode.PRIMARY; -import static org.apache.ignite.igfs.IgfsMode.PROXY; -import static org.apache.ignite.internal.GridTopic.TOPIC_IGFS; -import static org.apache.ignite.internal.IgniteNodeAttributes.ATTR_IGFS; +import java.io.IOException; +import java.io.OutputStream; +import java.net.URI; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicLong; + +import static org.apache.ignite.events.EventType.*; +import static org.apache.ignite.igfs.IgfsMode.*; +import static org.apache.ignite.internal.GridTopic.*; +import static org.apache.ignite.internal.IgniteNodeAttributes.*; /** * Cache-based IGFS implementation. @@ -636,9 +624,7 @@ public final class IgfsImpl implements IgfsEx { if (fileId == null) return null; - IgniteUuid parentId = fileIds.size() > 1 ? fileIds.get(fileIds.size() - 2) : null; - - IgfsFileInfo info = meta.updateProperties(parentId, fileId, path.name(), props); + IgfsFileInfo info = meta.updateProperties(fileId, props); if (info != null) { if (evts.isRecordable(EVT_IGFS_META_UPDATED)) http://git-wip-us.apache.org/repos/asf/ignite/blob/91fc9ab5/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 d7938b5..9422074 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 @@ -1459,67 +1459,28 @@ public class IgfsMetaManager extends IgfsManager { /** * Update file info (file properties) in cache in existing transaction. * - * @param parentId Parent ID ({@code null} if file is root). - * @param fileName To update listing. * @param fileId File ID to update information for. * @param props Properties to set for the file. * @return Updated file info or {@code null} if such file ID not found. * @throws IgniteCheckedException If operation failed. */ - @Nullable private IgfsFileInfo updatePropertiesNonTx(final @Nullable IgniteUuid parentId, final IgniteUuid fileId, - String fileName, Map<String, String> props) throws IgniteCheckedException { + @Nullable private IgfsFileInfo updatePropertiesNonTx(final IgniteUuid fileId, Map<String, String> props) + throws IgniteCheckedException { assert fileId != null; assert !F.isEmpty(props) : "Expects not-empty file's properties"; + validTxState(true); if (log.isDebugEnabled()) log.debug("Update file properties [fileId=" + fileId + ", props=" + props + ']'); try { - final IgfsFileInfo oldInfo; - final IgfsFileInfo parentInfo; - - // Lock file ID for this transaction. - if (parentId == null) { - oldInfo = info(fileId); - parentInfo = null; - } - else { - Map<IgniteUuid, IgfsFileInfo> locked = lockIds(parentId, fileId); - - oldInfo = locked.get(fileId); - parentInfo = locked.get(parentId); - - if (parentInfo == null) - return null; // Parent not found. - } + final IgfsFileInfo oldInfo = info(fileId); if (oldInfo == null) - return null; // File not found. - - if (parentInfo != null) { - if (!parentInfo.hasChild(fileName, fileId)) // File was removed or recreated. - return null; - } - - Map<String, String> tmp = oldInfo.properties(); - - tmp = tmp == null ? new GridLeanMap<String, String>(props.size()) : new GridLeanMap<>(tmp); - - for (Map.Entry<String, String> e : props.entrySet()) { - if (e.getValue() == null) - // Remove properties with 'null' values. - tmp.remove(e.getKey()); - else - // Add/overwrite property. - tmp.put(e.getKey(), e.getValue()); - } - - IgfsFileInfo newInfo = new IgfsFileInfo(oldInfo, tmp); - - id2InfoPrj.put(newInfo.id(), newInfo); + return null; - return newInfo; + return invokeAndGet(fileId, new UpdatePropertiesProcessor(props)); } catch (GridClosureException e) { throw U.cast(e); @@ -1529,15 +1490,13 @@ public class IgfsMetaManager extends IgfsManager { /** * Update file info (file properties) in cache. * - * @param parentId Parent ID ({@code null} if file is root). - * @param fileName To update listing. * @param fileId File ID to update information for. * @param props Properties to set for the file. * @return Updated file info or {@code null} if such file ID not found. * @throws IgniteCheckedException If operation failed. */ - @Nullable public IgfsFileInfo updateProperties(@Nullable IgniteUuid parentId, IgniteUuid fileId, String fileName, - Map<String, String> props) throws IgniteCheckedException { + @Nullable public IgfsFileInfo updateProperties(IgniteUuid fileId, Map<String, String> props) + throws IgniteCheckedException { if (busyLock.enterBusy()) { try { validTxState(false); @@ -1545,7 +1504,7 @@ public class IgfsMetaManager extends IgfsManager { IgniteInternalTx tx = startTx(); try { - IgfsFileInfo info = updatePropertiesNonTx(parentId, fileId, fileName, props); + IgfsFileInfo info = updatePropertiesNonTx(fileId, props); tx.commit(); @@ -1560,8 +1519,8 @@ public class IgfsMetaManager extends IgfsManager { } } else - throw new IllegalStateException("Failed to update properties because Grid is stopping [parentId=" + - parentId + ", fileId=" + fileId + ", fileName=" + fileName + ", props=" + props + ']'); + throw new IllegalStateException("Failed to update properties because Grid is stopping [fileId=" + fileId + + ", props=" + props + ']'); } /** @@ -2559,12 +2518,7 @@ public class IgfsMetaManager extends IgfsManager { fs.update(path, props); - IgfsFileInfo parentInfo = infos.get(path.parent()); - - assert path.parent() == null || parentInfo != null; - - return updatePropertiesNonTx(parentInfo == null ? null : parentInfo.id(), - infos.get(path).id(), path.name(), props); + return updatePropertiesNonTx(infos.get(path).id(), props); } @Override public IgfsFileInfo onFailure(@Nullable Exception err) throws IgniteCheckedException { @@ -3888,6 +3842,69 @@ public class IgfsMetaManager extends IgfsManager { } /** + * Update properties processor. + */ + private static class UpdatePropertiesProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, Void>, + Externalizable { + /** */ + private static final long serialVersionUID = 0L; + + /** Properties to be updated. */ + private Map<String, String> props; + + /** + * Constructor. + */ + public UpdatePropertiesProcessor() { + // No-op. + } + + /** + * Constructor. + * + * @param props Properties. + */ + public UpdatePropertiesProcessor(Map<String, String> props) { + this.props = props; + } + + /** {@inheritDoc} */ + @Override public Void process(MutableEntry<IgniteUuid, IgfsFileInfo> entry, Object... args) + throws EntryProcessorException { + IgfsFileInfo oldInfo = entry.getValue(); + + Map<String, String> tmp = oldInfo.properties(); + + tmp = tmp == null ? new GridLeanMap<String, String>(props.size()) : new GridLeanMap<>(tmp); + + for (Map.Entry<String, String> e : props.entrySet()) { + if (e.getValue() == null) + // Remove properties with 'null' values. + tmp.remove(e.getKey()); + else + // Add/overwrite property. + tmp.put(e.getKey(), e.getValue()); + } + + IgfsFileInfo newInfo = new IgfsFileInfo(oldInfo, tmp); + + entry.setValue(newInfo); + + return null; + } + + /** {@inheritDoc} */ + @Override public void writeExternal(ObjectOutput out) throws IOException { + U.writeStringMap(out, props); + } + + /** {@inheritDoc} */ + @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + props = U.readStringMap(in); + } + } + + /** * Update times entry processor. */ private static class UpdateTimesProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, Void>,