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/16 11:12:44 UTC
[1/8] ignite git commit: IGNITE-2838: IGFS: Opimized format of
IgfsListingEntry. Now it contains only file ID and boolean flag endicating
whether this a directory or file.
Repository: ignite
Updated Branches:
refs/heads/ignite-1786 e2ae00013 -> f55b2dbc1
IGNITE-2838: IGFS: Opimized format of IgfsListingEntry. Now it contains only file ID and boolean flag endicating whether this a directory or file.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/7b7233ef
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/7b7233ef
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/7b7233ef
Branch: refs/heads/ignite-1786
Commit: 7b7233efeeacc0c65833dec925a73906d9880608
Parents: 18de768
Author: thatcoach <pp...@list.ru>
Authored: Tue Mar 15 20:46:13 2016 +0300
Committer: thatcoach <pp...@list.ru>
Committed: Tue Mar 15 20:46:13 2016 +0300
----------------------------------------------------------------------
.../internal/processors/igfs/IgfsFileImpl.java | 29 ---
.../internal/processors/igfs/IgfsFileInfo.java | 38 +++-
.../internal/processors/igfs/IgfsImpl.java | 8 +-
.../processors/igfs/IgfsListingEntry.java | 129 ++---------
.../processors/igfs/IgfsMetaManager.java | 221 +++----------------
.../processors/igfs/IgfsOutputStreamImpl.java | 2 -
6 files changed, 88 insertions(+), 339 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/7b7233ef/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileImpl.java
index 4a96e81..3576a06 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileImpl.java
@@ -124,35 +124,6 @@ public final class IgfsFileImpl implements IgfsFile, Externalizable {
modificationTime = info.modificationTime();
}
- /**
- * Constructs file instance.
- *
- * @param path Path.
- * @param entry Listing entry.
- */
- public IgfsFileImpl(IgfsPath path, IgfsListingEntry entry, long globalGrpSize) {
- A.notNull(path, "path");
- A.notNull(entry, "entry");
-
- this.path = path;
- fileId = entry.fileId();
-
- blockSize = entry.blockSize();
-
- // By contract file must have blockSize > 0, while directory's blockSize == 0:
- assert entry.isFile() == (blockSize > 0);
- assert entry.isDirectory() == (blockSize == 0);
-
- grpBlockSize = entry.affinityKey() == null ? globalGrpSize :
- entry.length() == 0 ? globalGrpSize : entry.length();
-
- len = entry.length();
- props = entry.properties();
-
- accessTime = entry.accessTime();
- modificationTime = entry.modificationTime();
- }
-
/** {@inheritDoc} */
@Override public IgfsPath path() {
return path;
http://git-wip-us.apache.org/repos/asf/ignite/blob/7b7233ef/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfo.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfo.java
index 0a85657..ba484bb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfo.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfo.java
@@ -297,9 +297,6 @@ public final class IgfsFileInfo implements Externalizable {
this.props = props == null || props.isEmpty() ? null :
cpProps ? new GridLeanMap<>(props) : props;
- if (listing == null && isDir)
- this.listing = Collections.emptyMap();
-
this.lockId = lockId;
this.evictExclude = evictExclude;
}
@@ -410,13 +407,38 @@ public final class IgfsFileInfo implements Externalizable {
* @return Directory listing.
*/
public Map<String, IgfsListingEntry> listing() {
- // Always wrap into unmodifiable map to be able to avoid illegal modifications in order pieces of the code.
- if (isFile())
- return Collections.unmodifiableMap(Collections.<String, IgfsListingEntry>emptyMap());
+ return listing != null ? listing : Collections.<String, IgfsListingEntry>emptyMap();
+ }
+
+ /**
+ * @return {@code True} if at least one child exists.
+ */
+ public boolean hasChildren() {
+ return !F.isEmpty(listing);
+ }
+
+ /**
+ * @param name Child name.
+ * @return {@code True} if child with such name exists.
+ */
+ public boolean hasChild(String name) {
+ return listing != null && listing.containsKey(name);
+ }
- assert listing != null;
+ /**
+ * @param name Child name.
+ * @param expId Expected child ID.
+ * @return {@code True} if child with such name exists.
+ */
+ public boolean hasChild(String name, IgniteUuid expId) {
+ if (listing != null) {
+ IgfsListingEntry entry = listing.get(name);
+
+ if (entry != null)
+ return F.eq(expId, entry.fileId());
+ }
- return Collections.unmodifiableMap(listing);
+ return false;
}
/**
http://git-wip-us.apache.org/repos/asf/ignite/blob/7b7233ef/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 0e52927..f44eda8 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
@@ -870,9 +870,13 @@ public final class IgfsImpl implements IgfsEx {
// Perform the listing.
for (Map.Entry<String, IgfsListingEntry> e : info.listing().entrySet()) {
- IgfsPath p = new IgfsPath(path, e.getKey());
+ IgfsFileInfo childInfo = meta.info(e.getValue().fileId());
- files.add(new IgfsFileImpl(p, e.getValue(), data.groupBlockSize()));
+ if (childInfo != null) {
+ IgfsPath childPath = new IgfsPath(path, e.getKey());
+
+ files.add(new IgfsFileImpl(childPath, childInfo, data.groupBlockSize()));
+ }
}
}
} else if (mode == PRIMARY) {
http://git-wip-us.apache.org/repos/asf/ignite/blob/7b7233ef/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsListingEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsListingEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsListingEntry.java
index 1cdc8a9..61d9265 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsListingEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsListingEntry.java
@@ -21,7 +21,8 @@ import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
-import java.util.Map;
+
+import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.lang.IgniteUuid;
@@ -34,25 +35,10 @@ public class IgfsListingEntry implements Externalizable {
private static final long serialVersionUID = 0L;
/** File id. */
- private IgniteUuid fileId;
-
- /** File affinity key. */
- private IgniteUuid affKey;
-
- /** Positive block size if file, 0 if directory. */
- private int blockSize;
-
- /** File length. */
- private long len;
-
- /** Last access time. */
- private long accessTime;
+ private IgniteUuid id;
- /** Last modification time. */
- private long modificationTime;
-
- /** File properties. */
- private Map<String, String> props;
+ /** Directory marker. */
+ private boolean dir;
/**
* Empty constructor required by {@link Externalizable}.
@@ -65,132 +51,51 @@ public class IgfsListingEntry implements Externalizable {
* @param fileInfo File info to construct listing entry from.
*/
public IgfsListingEntry(IgfsFileInfo fileInfo) {
- fileId = fileInfo.id();
- affKey = fileInfo.affinityKey();
-
- if (fileInfo.isFile()) {
- blockSize = fileInfo.blockSize();
- len = fileInfo.length();
- }
-
- props = fileInfo.properties();
- accessTime = fileInfo.accessTime();
- modificationTime = fileInfo.modificationTime();
- }
-
- /**
- * Creates listing entry with updated length.
- *
- * @param entry Entry.
- * @param len New length.
- */
- public IgfsListingEntry(IgfsListingEntry entry, long len, long accessTime, long modificationTime) {
- fileId = entry.fileId;
- affKey = entry.affKey;
- blockSize = entry.blockSize;
- props = entry.props;
- this.accessTime = accessTime;
- this.modificationTime = modificationTime;
-
- this.len = len;
+ id = fileInfo.id();
+ dir = fileInfo.isDirectory();
}
/**
* @return Entry file ID.
*/
public IgniteUuid fileId() {
- return fileId;
- }
-
- /**
- * @return File affinity key, if specified.
- */
- public IgniteUuid affinityKey() {
- return affKey;
+ return id;
}
/**
* @return {@code True} if entry represents file.
*/
public boolean isFile() {
- return blockSize > 0;
+ return !dir;
}
/**
* @return {@code True} if entry represents directory.
*/
public boolean isDirectory() {
- return blockSize == 0;
- }
-
- /**
- * @return Block size.
- */
- public int blockSize() {
- return blockSize;
- }
-
- /**
- * @return Length.
- */
- public long length() {
- return len;
- }
-
- /**
- * @return Last access time.
- */
- public long accessTime() {
- return accessTime;
- }
-
- /**
- * @return Last modification time.
- */
- public long modificationTime() {
- return modificationTime;
- }
-
- /**
- * @return Properties map.
- */
- public Map<String, String> properties() {
- return props;
+ return dir;
}
/** {@inheritDoc} */
@Override public void writeExternal(ObjectOutput out) throws IOException {
- U.writeGridUuid(out, fileId);
- out.writeInt(blockSize);
- out.writeLong(len);
- U.writeStringMap(out, props);
- out.writeLong(accessTime);
- out.writeLong(modificationTime);
+ U.writeGridUuid(out, id);
+ out.writeBoolean(dir);
}
/** {@inheritDoc} */
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
- fileId = U.readGridUuid(in);
- blockSize = in.readInt();
- len = in.readLong();
- props = U.readStringMap(in);
- accessTime = in.readLong();
- modificationTime = in.readLong();
+ id = U.readGridUuid(in);
+ dir = in.readBoolean();
}
/** {@inheritDoc} */
- @Override public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof IgfsListingEntry)) return false;
-
- IgfsListingEntry that = (IgfsListingEntry)o;
-
- return fileId.equals(that.fileId);
+ @Override public boolean equals(Object other) {
+ return this == other || other instanceof IgfsListingEntry && F.eq(id, ((IgfsListingEntry)other).id);
}
/** {@inheritDoc} */
@Override public int hashCode() {
- return fileId.hashCode();
+ return id.hashCode();
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/7b7233ef/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 d3aae58..463e7a8 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
@@ -801,18 +801,12 @@ public class IgfsMetaManager extends IgfsManager {
if (!parentInfo.isDirectory())
throw fsException(new IgfsPathIsNotDirectoryException("Parent file is not a directory: " + parentInfo));
- Map<String, IgfsListingEntry> parentListing = parentInfo.listing();
+ IgfsListingEntry childEntry = parentInfo.listing().get(fileName);
- assert parentListing != null;
+ if (childEntry != null)
+ return childEntry.fileId();
- IgfsListingEntry entry = parentListing.get(fileName);
-
- if (entry != null)
- return entry.fileId();
-
- IgniteUuid fileId = newFileInfo.id();
-
- if (!id2InfoPrj.putIfAbsent(fileId, newFileInfo))
+ if (!id2InfoPrj.putIfAbsent(newFileInfo.id(), newFileInfo))
throw fsException("Failed to add file details into cache: " + newFileInfo);
id2InfoPrj.invoke(parentId, new ListingAdd(fileName, new IgfsListingEntry(newFileInfo)));
@@ -915,7 +909,7 @@ public class IgfsMetaManager extends IgfsManager {
assert dstTargetInfo.isDirectory();
// 7. Last check: does destination target already have listing entry with the same name?
- if (dstTargetInfo.listing().containsKey(dstName)) {
+ if (dstTargetInfo.hasChild(dstName)) {
throw new IgfsPathAlreadyExistsException("Failed to perform move because destination already " +
"contains entry with the same name existing file [src=" + srcPath +
", dst=" + dstPath + ']');
@@ -973,14 +967,8 @@ public class IgfsMetaManager extends IgfsManager {
// If parent info is null, it doesn't exist.
if (parentInfo != null) {
- IgfsListingEntry childEntry = parentInfo.listing().get(pathParts.get(i));
-
- // If expected child exists.
- if (childEntry != null) {
- // If child ID matches expected ID.
- if (F.eq(childEntry.fileId(), expIds.get(i + 1)))
- continue;
- }
+ if (parentInfo.hasChild(pathParts.get(i), expIds.get(i + 1)))
+ continue;
}
}
@@ -1046,7 +1034,6 @@ public class IgfsMetaManager extends IgfsManager {
fileId + ']'));
IgfsListingEntry srcEntry = srcInfo.listing().get(srcFileName);
- IgfsListingEntry destEntry = destInfo.listing().get(destFileName);
// If source file does not exist or was re-created.
if (srcEntry == null || !srcEntry.fileId().equals(fileId))
@@ -1055,10 +1042,10 @@ public class IgfsMetaManager extends IgfsManager {
", srcParentId=" + srcParentId + ", srcEntry=" + srcEntry + ']'));
// If stored file already exist.
- if (destEntry != null)
+ if (destInfo.hasChild(destFileName))
throw fsException(new IgfsPathAlreadyExistsException("Failed to add file name into the destination " +
" directory (file already exists) [fileId=" + fileId + ", destFileName=" + destFileName +
- ", destParentId=" + destParentId + ", destEntry=" + destEntry + ']'));
+ ", destParentId=" + destParentId + ']'));
// Remove listing entry from the source parent listing.
id2InfoPrj.invoke(srcParentId, new ListingRemove(srcFileName, srcEntry.fileId()));
@@ -1174,7 +1161,7 @@ public class IgfsMetaManager extends IgfsManager {
final IgfsFileInfo victimInfo = infoMap.get(victimId);
- if (!recursive && victimInfo.isDirectory() && !victimInfo.listing().isEmpty())
+ if (!recursive && victimInfo.hasChildren())
// Throw exception if not empty and not recursive.
throw new IgfsDirectoryNotEmptyException("Failed to remove directory (directory is not " +
"empty and recursive flag is not set).");
@@ -1187,7 +1174,7 @@ public class IgfsMetaManager extends IgfsManager {
final String destFileName = victimId.toString();
- assert destInfo.listing().get(destFileName) == null : "Failed to add file name into the " +
+ assert !destInfo.hasChild(destFileName) : "Failed to add file name into the " +
"destination directory (file already exists) [destName=" + destFileName + ']';
IgfsFileInfo srcParentInfo = infoMap.get(pathIdList.get(pathIdList.size() - 2));
@@ -1338,8 +1325,8 @@ public class IgfsMetaManager extends IgfsManager {
int i = 1;
- for (IgfsListingEntry entry : listing.values())
- allIds[i++] = entry.fileId();
+ for (IgfsListingEntry childEntry : listing.values())
+ allIds[i++] = childEntry.fileId();
Map<IgniteUuid, IgfsFileInfo> locks = lockIds(allIds);
@@ -1347,35 +1334,37 @@ public class IgfsMetaManager extends IgfsManager {
// Ensure parent is still in place.
if (parentInfo != null) {
- Map<String, IgfsListingEntry> newListing =
- new HashMap<>(parentInfo.listing().size(), 1.0f);
+ Map<String, IgfsListingEntry> parentListing = parentInfo.listing();
+
+ Map<String, IgfsListingEntry> newListing = new HashMap<>(parentListing.size(), 1.0f);
- newListing.putAll(parentInfo.listing());
+ newListing.putAll(parentListing);
// Remove child entries if possible.
for (Map.Entry<String, IgfsListingEntry> entry : listing.entrySet()) {
- IgniteUuid entryId = entry.getValue().fileId();
+ String childName = entry.getKey();
+ IgniteUuid childId = entry.getValue().fileId();
- IgfsFileInfo entryInfo = locks.get(entryId);
+ IgfsFileInfo entryInfo = locks.get(childId);
if (entryInfo != null) {
// File must be locked for deletion:
assert entryInfo.isDirectory() || IgfsUtils.DELETE_LOCK_ID.equals(entryInfo.lockId());
// Delete only files or empty folders.
- if (entryInfo.isFile() || entryInfo.isDirectory() && entryInfo.listing().isEmpty()) {
- id2InfoPrj.getAndRemove(entryId);
+ if (!entryInfo.hasChildren()) {
+ id2InfoPrj.getAndRemove(childId);
- newListing.remove(entry.getKey());
+ newListing.remove(childName);
- res.add(entryId);
+ res.add(childId);
}
}
else {
// Entry was deleted concurrently.
- newListing.remove(entry.getKey());
+ newListing.remove(childName);
- res.add(entryId);
+ res.add(childId);
}
}
@@ -1436,10 +1425,10 @@ public class IgfsMetaManager extends IgfsManager {
assert parentInfo != null;
- IgfsListingEntry listingEntry = parentInfo.listing().get(name);
+ IgfsListingEntry childEntry = parentInfo.listing().get(name);
- if (listingEntry != null)
- id2InfoPrj.invoke(parentId, new ListingRemove(name, listingEntry.fileId()));
+ if (childEntry != null)
+ id2InfoPrj.invoke(parentId, new ListingRemove(name, childEntry.fileId()));
IgfsFileInfo deleted = id2InfoPrj.getAndRemove(id);
@@ -1481,13 +1470,9 @@ public class IgfsMetaManager extends IgfsManager {
IgfsFileInfo trashInfo = id2InfoPrj.get(trashId);
- if (trashInfo != null) {
- Map<String, IgfsListingEntry> listing = trashInfo.listing();
-
- if (listing != null && !listing.isEmpty()) {
- for (IgfsListingEntry entry : listing.values())
- ids.add(entry.fileId());
- }
+ if (trashInfo != null && trashInfo.hasChildren()) {
+ for (IgfsListingEntry entry : trashInfo.listing().values())
+ ids.add(entry.fileId());
}
}
@@ -1543,11 +1528,7 @@ public class IgfsMetaManager extends IgfsManager {
return null; // File not found.
if (parentInfo != null) {
- Map<String, IgfsListingEntry> listing = parentInfo.listing();
-
- IgfsListingEntry entry = listing.get(fileName);
-
- if (entry == null || !entry.fileId().equals(fileId)) // File was removed or recreated.
+ if (!parentInfo.hasChild(fileName, fileId)) // File was removed or recreated.
return null;
}
@@ -1622,35 +1603,6 @@ public class IgfsMetaManager extends IgfsManager {
}
/**
- * Asynchronously updates record in parent listing.
- *
- * @param parentId Parent ID.
- * @param fileId File ID.
- * @param fileName File name.
- * @param lenDelta Length delta.
- * @param modificationTime Last modification time.
- */
- public void updateParentListingAsync(IgniteUuid parentId, IgniteUuid fileId, String fileName, long lenDelta,
- long modificationTime) {
- if (busyLock.enterBusy()) {
- try {
- assert parentId != null;
-
- assert validTxState(false);
-
- id2InfoPrj.invokeAsync(parentId, new UpdateListingEntry(fileId, fileName, lenDelta, -1,
- modificationTime));
- }
- finally {
- busyLock.leaveBusy();
- }
- }
- else
- throw new IllegalStateException("Failed to update parent listing because Grid is stopping [parentId=" +
- parentId + ", fileId=" + fileId + ", fileName=" + fileName + ']');
- }
-
- /**
* Reserve space for file.
*
* @param path File path.
@@ -2980,10 +2932,8 @@ public class IgfsMetaManager extends IgfsManager {
throw fsException(new IgfsPathNotFoundException("Failed to update times " +
"(parent was not found): " + fileName));
- IgfsListingEntry entry = parentInfo.listing().get(fileName);
-
// Validate listing.
- if (entry == null || !entry.fileId().equals(fileId))
+ if (!parentInfo.hasChild(fileName, fileId))
throw fsException(new IgfsConcurrentModificationException("Failed to update times " +
"(file concurrently modified): " + fileName));
@@ -2994,9 +2944,6 @@ public class IgfsMetaManager extends IgfsManager {
modificationTime == -1 ? fileInfo.modificationTime() : modificationTime)
);
- id2InfoPrj.invoke(parentId, new UpdateListingEntry(fileId, fileName, 0, accessTime,
- modificationTime));
-
tx.commit();
}
finally {
@@ -3143,100 +3090,6 @@ public class IgfsMetaManager extends IgfsManager {
}
/**
- * Updates file length information in parent listing.
- */
- private static final class UpdateListingEntry implements EntryProcessor<IgniteUuid, IgfsFileInfo, Void>,
- Externalizable {
- /** */
- private static final long serialVersionUID = 0L;
-
- /** File name. */
- private String fileName;
-
- /** File id. */
- private IgniteUuid fileId;
-
- /** Length delta. */
- private long lenDelta;
-
- /** Last access time. */
- private long accessTime;
-
- /** Last modification time. */
- private long modificationTime;
-
- /**
- * Empty constructor required by {@link Externalizable}.
- */
- public UpdateListingEntry() {
- // No-op.
- }
-
- /**
- * @param fileId Expected file id in parent directory listing.
- * @param fileName File name.
- * @param lenDelta Length delta.
- * @param accessTime Last access time.
- * @param modificationTime Last modification time.
- */
- private UpdateListingEntry(IgniteUuid fileId,
- String fileName,
- long lenDelta,
- long accessTime,
- long modificationTime) {
- this.fileId = fileId;
- this.fileName = fileName;
- this.lenDelta = lenDelta;
- this.accessTime = accessTime;
- this.modificationTime = modificationTime;
- }
-
- /** {@inheritDoc} */
- @Override public Void process(MutableEntry<IgniteUuid, IgfsFileInfo> e, Object... args) {
- IgfsFileInfo fileInfo = e.getValue();
-
- Map<String, IgfsListingEntry> listing = fileInfo.listing();
-
- IgfsListingEntry entry = listing.get(fileName);
-
- if (entry == null || !entry.fileId().equals(fileId))
- return null;
-
- entry = new IgfsListingEntry(entry, entry.length() + lenDelta,
- accessTime == -1 ? entry.accessTime() : accessTime,
- modificationTime == -1 ? entry.modificationTime() : modificationTime);
-
- // Create new map to replace info.
- listing = new HashMap<>(listing);
-
- // Modify listing map in-place since map is serialization-safe.
- listing.put(fileName, entry);
-
- e.setValue(new IgfsFileInfo(listing, fileInfo));
-
- return null;
- }
-
- /** {@inheritDoc} */
- @Override public void writeExternal(ObjectOutput out) throws IOException {
- U.writeGridUuid(out, fileId);
- out.writeUTF(fileName);
- out.writeLong(lenDelta);
- out.writeLong(accessTime);
- out.writeLong(modificationTime);
- }
-
- /** {@inheritDoc} */
- @Override public void readExternal(ObjectInput in) throws IOException {
- fileId = U.readGridUuid(in);
- fileName = in.readUTF();
- lenDelta = in.readLong();
- accessTime = in.readLong();
- modificationTime = in.readLong();
- }
- }
-
- /**
* Remove entry from directory listing.
*/
@GridInternal
@@ -3608,13 +3461,9 @@ public class IgfsMetaManager extends IgfsManager {
throw new IgfsParentNotDirectoryException("Failed to " + (append ? "open" : "create" )
+ " file (parent element is not a directory)");
- Map<String, IgfsListingEntry> parentListing = lowermostExistingInfo.listing();
-
final String uppermostFileToBeCreatedName = b.components.get(b.existingIdCnt - 1);
- final IgfsListingEntry entry = parentListing.get(uppermostFileToBeCreatedName);
-
- if (entry == null) {
+ if (!lowermostExistingInfo.hasChild(uppermostFileToBeCreatedName)) {
b.doBuild();
assert b.leafInfo != null;
http://git-wip-us.apache.org/repos/asf/ignite/blob/7b7233ef/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsOutputStreamImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsOutputStreamImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsOutputStreamImpl.java
index 8c11073..3bf1011 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsOutputStreamImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsOutputStreamImpl.java
@@ -381,8 +381,6 @@ class IgfsOutputStreamImpl extends IgfsOutputStreamAdapter {
throw new IOException("File to read file metadata: " + fileInfo.path(), e);
}
- meta.updateParentListingAsync(parentId, fileInfo.id(), fileName, bytes, modificationTime);
-
if (err != null)
throw err;
}
[7/8] ignite git commit: Merge remote-tracking branch 'origin/master'
Posted by vo...@apache.org.
Merge remote-tracking branch 'origin/master'
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/dfe5ea80
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/dfe5ea80
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/dfe5ea80
Branch: refs/heads/ignite-1786
Commit: dfe5ea80e7d24df78bdb85c80fd05bb7391391b4
Parents: c638f1e 843b286
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Mar 16 13:11:18 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Mar 16 13:11:18 2016 +0300
----------------------------------------------------------------------
.../internal/websession/IgniteWebSessionSelfTestSuite.java | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
[3/8] ignite git commit: IGNITE-2792: User-defined configuration is
not passed to system caches anymore. This closes #551.
Posted by vo...@apache.org.
IGNITE-2792: User-defined configuration is not passed to system caches anymore. This closes #551.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/297cbcbb
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/297cbcbb
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/297cbcbb
Branch: refs/heads/ignite-1786
Commit: 297cbcbb5ba12ec688ea9e1ad4c32cdeea0ba7aa
Parents: dda1f0e
Author: dkarachentsev <dk...@gridgain.com>
Authored: Wed Mar 16 11:56:14 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Mar 16 11:56:14 2016 +0300
----------------------------------------------------------------------
.../processors/cache/GridCacheAdapter.java | 10 +-
.../processors/cache/GridCacheUtils.java | 14 ++
.../transactions/IgniteTransactionsImpl.java | 9 +-
.../cache/IgniteTxConfigCacheSelfTest.java | 249 +++++++++++++++++++
.../ignite/testsuites/IgniteCacheTestSuite.java | 2 +
.../hadoop/cache/HadoopTxConfigCacheTest.java | 42 ++++
.../testsuites/IgniteHadoopTestSuite.java | 3 +
7 files changed, 320 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/297cbcbb/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 9827dad..86036ac 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -3431,7 +3431,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
A.notNull(concurrency, "concurrency");
A.notNull(isolation, "isolation");
- TransactionConfiguration cfg = ctx.gridConfig().getTransactionConfiguration();
+ TransactionConfiguration cfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config());
return txStart(
concurrency,
@@ -4220,7 +4220,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
IgniteTxLocalAdapter tx = ctx.tm().threadLocalTx(ctx);
if (tx == null || tx.implicit()) {
- TransactionConfiguration tCfg = ctx.gridConfig().getTransactionConfiguration();
+ TransactionConfiguration tCfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config());
CacheOperationContext opCtx = ctx.operationContextPerCall();
@@ -4317,6 +4317,8 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
CacheOperationContext opCtx = ctx.operationContextPerCall();
+ final TransactionConfiguration txCfg = CU.transactionConfiguration(ctx, ctx.kernalContext().config());
+
if (tx == null || tx.implicit()) {
boolean skipStore = ctx.skipStore(); // Save value of thread-local flag.
@@ -4329,7 +4331,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
ctx.systemTx() ? ctx : null,
OPTIMISTIC,
READ_COMMITTED,
- ctx.kernalContext().config().getTransactionConfiguration().getDefaultTxTimeout(),
+ txCfg.getDefaultTxTimeout(),
!skipStore,
0);
@@ -5001,7 +5003,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
ctx.systemTx() ? ctx : null,
OPTIMISTIC,
READ_COMMITTED,
- ctx.kernalContext().config().getTransactionConfiguration().getDefaultTxTimeout(),
+ CU.transactionConfiguration(ctx, ctx.kernalContext().config()).getDefaultTxTimeout(),
opCtx == null || !opCtx.skipStore(),
0);
http://git-wip-us.apache.org/repos/asf/ignite/blob/297cbcbb/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
index 25ea14c..94307ca 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
@@ -57,6 +57,7 @@ import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.FileSystemConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.TransactionConfiguration;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.IgniteClientDisconnectedCheckedException;
import org.apache.ignite.internal.IgniteInternalFuture;
@@ -157,6 +158,9 @@ public class GridCacheUtils {
/** Empty predicate array. */
private static final IgnitePredicate[] EMPTY = new IgnitePredicate[0];
+ /** Default transaction config. */
+ private static final TransactionConfiguration DEFAULT_TX_CFG = new TransactionConfiguration();
+
/** Partition to state transformer. */
private static final IgniteClosure PART2STATE =
new C1<GridDhtLocalPartition, GridDhtPartitionState>() {
@@ -1864,4 +1868,14 @@ public class GridCacheUtils {
public static boolean isSwapEnabled(ClusterNode node) {
return !node.attributes().containsKey(NOOP_SWAP_SPACE_SPI_ATTR_NAME);
}
+
+ /**
+ * @return default TX configuration if system cache is used or current grid TX config otherwise.
+ */
+ public static TransactionConfiguration transactionConfiguration(final @Nullable GridCacheContext sysCacheCtx,
+ final IgniteConfiguration cfg) {
+ return sysCacheCtx != null && sysCacheCtx.systemTx()
+ ? DEFAULT_TX_CFG
+ : cfg.getTransactionConfiguration();
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/297cbcbb/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
index 76f2f77..7c7b5a8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/transactions/IgniteTransactionsImpl.java
@@ -23,14 +23,13 @@ import org.apache.ignite.internal.IgniteTransactionsEx;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.GridCacheSharedContext;
import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.transactions.Transaction;
import org.apache.ignite.transactions.TransactionConcurrency;
import org.apache.ignite.transactions.TransactionIsolation;
import org.apache.ignite.transactions.TransactionMetrics;
import org.jetbrains.annotations.Nullable;
-import static org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE;
-
/**
* Grid transactions implementation.
*/
@@ -47,7 +46,7 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx {
/** {@inheritDoc} */
@Override public Transaction txStart() throws IllegalStateException {
- TransactionConfiguration cfg = cctx.gridConfig().getTransactionConfiguration();
+ TransactionConfiguration cfg = CU.transactionConfiguration(null, cctx.kernalContext().config());
return txStart0(
cfg.getDefaultTxConcurrency(),
@@ -63,7 +62,7 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx {
A.notNull(concurrency, "concurrency");
A.notNull(isolation, "isolation");
- TransactionConfiguration cfg = cctx.gridConfig().getTransactionConfiguration();
+ TransactionConfiguration cfg = CU.transactionConfiguration(null, cctx.kernalContext().config());
return txStart0(
concurrency,
@@ -124,7 +123,7 @@ public class IgniteTransactionsImpl<K, V> implements IgniteTransactionsEx {
checkTransactional(ctx);
- TransactionConfiguration cfg = cctx.gridConfig().getTransactionConfiguration();
+ TransactionConfiguration cfg = CU.transactionConfiguration(ctx, cctx.kernalContext().config());
return txStart0(concurrency,
isolation,
http://git-wip-us.apache.org/repos/asf/ignite/blob/297cbcbb/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
new file mode 100644
index 0000000..94b5620
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteTxConfigCacheSelfTest.java
@@ -0,0 +1,249 @@
+/*
+ * 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.cache;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.TransactionConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.apache.ignite.transactions.TransactionTimeoutException;
+
+import javax.cache.CacheException;
+import javax.cache.processor.EntryProcessor;
+import javax.cache.processor.EntryProcessorException;
+import javax.cache.processor.MutableEntry;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+
+/**
+ * Test checks that grid transaction configuration doesn't influence system caches.
+ */
+public class IgniteTxConfigCacheSelfTest extends GridCommonAbstractTest {
+ /** Ip finder. */
+ private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+ /** Test cache name. */
+ private static final String CACHE_NAME = "cache_name";
+
+ /** Timeout of transaction. */
+ private static final long TX_TIMEOUT = 100;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+ IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+ ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
+
+ CacheConfiguration ccfg = new CacheConfiguration();
+
+ ccfg.setAtomicityMode(atomicityMode());
+ ccfg.setBackups(1);
+
+ cfg.setCacheConfiguration(ccfg);
+
+ final TransactionConfiguration txCfg = new TransactionConfiguration();
+
+ txCfg.setDefaultTxTimeout(TX_TIMEOUT);
+
+ cfg.setTransactionConfiguration(txCfg);
+
+ return cfg;
+ }
+
+ /**
+ * @return Cache atomicity mode.
+ */
+ public CacheAtomicityMode atomicityMode() {
+ return TRANSACTIONAL;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ startGrids(1);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+ }
+
+ /**
+ * Success if user tx was timed out.
+ *
+ * @throws Exception
+ */
+ public void testUserTxTimeout() throws Exception {
+ final Ignite ignite = grid(0);
+
+ final IgniteCache<Object, Object> cache = ignite.getOrCreateCache(CACHE_NAME);
+
+ checkImplicitTxTimeout(cache);
+ checkExplicitTxTimeout(cache, ignite);
+ }
+
+ /**
+ * Success if system caches weren't timed out.
+ *
+ * @throws Exception
+ */
+ public void testSystemCacheTx() throws Exception {
+ final Ignite ignite = grid(0);
+
+ final IgniteInternalCache<Object, Object> utilCache = getSystemCache(ignite, CU.UTILITY_CACHE_NAME);
+
+ checkImplicitTxSuccess(utilCache);
+ checkStartTxSuccess(utilCache);
+
+ final IgniteInternalCache<Object, Object> atomicsCache = getSystemCache(ignite, CU.ATOMICS_CACHE_NAME);
+
+ checkImplicitTxSuccess(atomicsCache);
+ checkStartTxSuccess(atomicsCache);
+ }
+
+ /**
+ * Extract system cache from kernal.
+ *
+ * @param ignite Ignite instance.
+ * @param cacheName System cache name.
+ * @return Internal cache instance.
+ */
+ protected IgniteInternalCache<Object, Object> getSystemCache(final Ignite ignite, final String cacheName) {
+ return ((IgniteKernal) ignite).context().cache().cache(cacheName);
+ }
+
+ /**
+ * Success if implicit tx fails.
+ *
+ * @param cache Cache name.
+ * @throws Exception
+ */
+ protected void checkImplicitTxTimeout(final IgniteCache<Object, Object> cache) throws Exception {
+ try {
+ cache.invoke("key", new EntryProcessor<Object, Object, Object>() {
+ @Override public Object process(final MutableEntry<Object, Object> entry, final Object... args)
+ throws EntryProcessorException {
+ try {
+ sleepForTxFailure();
+ } catch (InterruptedException e) {
+ throw new EntryProcessorException(e);
+ }
+
+ return null;
+ }
+ });
+
+ fail("Timeout exception must be thrown");
+ }
+ catch (CacheException e) {
+ // OK
+ }
+
+ cache.clear();
+ }
+
+ /**
+ * Success if explicit tx fails.
+ *
+ * @param cache Cache name.
+ * @param ignite Ignite instance.
+ * @throws Exception
+ */
+ protected void checkExplicitTxTimeout(final IgniteCache<Object, Object> cache, final Ignite ignite)
+ throws Exception {
+ try (final Transaction tx = ignite.transactions().txStart()) {
+ assert tx != null;
+
+ sleepForTxFailure();
+
+ cache.put("key", "val");
+
+ fail("Timeout exception must be thrown");
+ }
+ catch (CacheException e) {
+ assert e.getCause() instanceof TransactionTimeoutException;
+ }
+
+ assert !cache.containsKey("key");
+ }
+
+ /**
+ * Success if explicit tx doesn't fail.
+ *
+ * @param cache Cache instance.
+ * @throws Exception
+ */
+ protected void checkStartTxSuccess(final IgniteInternalCache<Object, Object> cache) throws Exception {
+ try (final IgniteInternalTx tx = CU.txStartInternal(cache.context(), cache, PESSIMISTIC, READ_COMMITTED)) {
+ assert tx != null;
+
+ sleepForTxFailure();
+
+ cache.put("key", "val");
+
+ tx.commit();
+ }
+
+ assert cache.containsKey("key");
+
+ cache.clear();
+ }
+
+ /**
+ * Success if implicit tx fails.
+ *
+ * @param cache Cache instance.
+ * @throws Exception
+ */
+ protected void checkImplicitTxSuccess(final IgniteInternalCache<Object, Object> cache) throws Exception {
+ cache.invoke("key", new EntryProcessor<Object, Object, Object>() {
+ @Override public Object process(final MutableEntry<Object, Object> entry, final Object... args)
+ throws EntryProcessorException {
+ try {
+ sleepForTxFailure();
+ } catch (InterruptedException e) {
+ throw new EntryProcessorException(e);
+ }
+ return null;
+ }
+ });
+
+ cache.clear();
+ }
+
+ /**
+ * Sleep multiple {@link #TX_TIMEOUT} times.
+ *
+ * @throws InterruptedException
+ */
+ private void sleepForTxFailure() throws InterruptedException {
+ Thread.sleep(TX_TIMEOUT * 3);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/297cbcbb/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
index 045ff6f..2613175 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite.java
@@ -107,6 +107,7 @@ import org.apache.ignite.internal.processors.cache.IgniteCacheTxNearEnabledInvok
import org.apache.ignite.internal.processors.cache.IgniteClientAffinityAssignmentSelfTest;
import org.apache.ignite.internal.processors.cache.IgnitePutAllLargeBatchSelfTest;
import org.apache.ignite.internal.processors.cache.IgnitePutAllUpdateNonPreloadedPartitionSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteTxConfigCacheSelfTest;
import org.apache.ignite.internal.processors.cache.context.IgniteCacheAtomicExecutionContextTest;
import org.apache.ignite.internal.processors.cache.context.IgniteCacheContinuousExecutionContextTest;
import org.apache.ignite.internal.processors.cache.context.IgniteCacheIsolatedExecutionContextTest;
@@ -293,6 +294,7 @@ public class IgniteCacheTestSuite extends TestSuite {
suite.addTestSuite(CachePutEventListenerErrorSelfTest.class);
+ suite.addTestSuite(IgniteTxConfigCacheSelfTest.class);
return suite;
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/297cbcbb/modules/hadoop/src/test/java/org/apache/ignite/hadoop/cache/HadoopTxConfigCacheTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/hadoop/cache/HadoopTxConfigCacheTest.java b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/cache/HadoopTxConfigCacheTest.java
new file mode 100644
index 0000000..6f910f1
--- /dev/null
+++ b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/cache/HadoopTxConfigCacheTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.hadoop.cache;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.processors.cache.IgniteTxConfigCacheSelfTest;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+
+/**
+ * Test checks whether hadoop system cache doesn't use user defined TX config.
+ */
+public class HadoopTxConfigCacheTest extends IgniteTxConfigCacheSelfTest {
+ /**
+ * Success if system caches weren't timed out.
+ *
+ * @throws Exception
+ */
+ public void testSystemCacheTx() throws Exception {
+ final Ignite ignite = grid(0);
+
+ final IgniteInternalCache<Object, Object> hadoopCache = getSystemCache(ignite, CU.SYS_CACHE_HADOOP_MR);
+
+ checkImplicitTxSuccess(hadoopCache);
+ checkStartTxSuccess(hadoopCache);
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/297cbcbb/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
index acd255c..e03e4e1 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
@@ -35,6 +35,7 @@ import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.apache.ignite.IgniteSystemProperties;
import org.apache.ignite.client.hadoop.HadoopClientProtocolEmbeddedSelfTest;
import org.apache.ignite.client.hadoop.HadoopClientProtocolSelfTest;
+import org.apache.ignite.hadoop.cache.HadoopTxConfigCacheTest;
import org.apache.ignite.hadoop.fs.KerberosHadoopFileSystemFactorySelfTest;
import org.apache.ignite.igfs.Hadoop1OverIgfsDualAsyncTest;
import org.apache.ignite.igfs.Hadoop1OverIgfsDualSyncTest;
@@ -181,6 +182,8 @@ public class IgniteHadoopTestSuite extends TestSuite {
suite.addTest(new TestSuite(ldr.loadClass(HadoopCommandLineTest.class.getName())));
suite.addTest(new TestSuite(ldr.loadClass(HadoopSecondaryFileSystemConfigurationTest.class.getName())));
+
+ suite.addTest(new TestSuite(ldr.loadClass(HadoopTxConfigCacheTest.class.getName())));
return suite;
}
[6/8] ignite git commit: IGNITE-2843 .NET: Added
CacheConfiguration.WriteThrough/ReadThrough properties. This closes #556.
Posted by vo...@apache.org.
IGNITE-2843 .NET: Added CacheConfiguration.WriteThrough/ReadThrough properties. This closes #556.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c638f1e7
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c638f1e7
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c638f1e7
Branch: refs/heads/ignite-1786
Commit: c638f1e7e9a6994cf38de4d444354a0938de0d31
Parents: ad6bbd9
Author: Pavel Tupitsyn <pt...@gridgain.com>
Authored: Wed Mar 16 13:11:05 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Mar 16 13:11:05 2016 +0300
----------------------------------------------------------------------
.../utils/PlatformConfigurationUtils.java | 4 +
.../Apache.Ignite.Core.Tests.csproj | 1 +
.../Cache/CacheConfigurationTest.cs | 5 +-
.../Cache/Store/CacheStoreTest.cs | 5 +-
.../Cache/Store/CacheStoreTestCodeConfig.cs | 106 +++++++++++++++++++
.../IgniteConfigurationSerializerTest.cs | 4 +-
.../Cache/Configuration/CacheConfiguration.cs | 36 +++++++
.../IgniteConfigurationSection.xsd | 2 +
8 files changed, 158 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
index 50728a1..e08d1ba 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformConfigurationUtils.java
@@ -140,6 +140,8 @@ import java.util.Map;
ccfg.setWriteBehindFlushSize(in.readInt());
ccfg.setWriteBehindFlushThreadCount(in.readInt());
ccfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.fromOrdinal(in.readInt()));
+ ccfg.setReadThrough(in.readBoolean());
+ ccfg.setWriteThrough(in.readBoolean());
Object storeFactory = in.readObjectDetached();
@@ -419,6 +421,8 @@ import java.util.Map;
writer.writeInt(ccfg.getWriteBehindFlushSize());
writer.writeInt(ccfg.getWriteBehindFlushThreadCount());
writer.writeInt(ccfg.getWriteSynchronizationMode() == null ? 0 : ccfg.getWriteSynchronizationMode().ordinal());
+ writer.writeBoolean(ccfg.isReadThrough());
+ writer.writeBoolean(ccfg.isWriteThrough());
if (ccfg.getCacheStoreFactory() instanceof PlatformDotNetCacheStoreFactoryNative)
writer.writeObject(((PlatformDotNetCacheStoreFactoryNative)ccfg.getCacheStoreFactory()).getNativeFactory());
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
index 8c266d7..0dcd1f0 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Apache.Ignite.Core.Tests.csproj
@@ -91,6 +91,7 @@
<Compile Include="Cache\Store\CacheParallelLoadStoreTest.cs" />
<Compile Include="Cache\Store\CacheStoreSessionTest.cs" />
<Compile Include="Cache\Store\CacheStoreTest.cs" />
+ <Compile Include="Cache\Store\CacheStoreTestCodeConfig.cs" />
<Compile Include="Cache\Store\CacheTestParallelLoadStore.cs" />
<Compile Include="Cache\Store\CacheTestStore.cs" />
<Compile Include="Compute\CancellationTest.cs" />
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
index 9f019832..bc259e5 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/CacheConfigurationTest.cs
@@ -24,8 +24,6 @@ namespace Apache.Ignite.Core.Tests.Cache
using Apache.Ignite.Core.Cache.Configuration;
using Apache.Ignite.Core.Cache.Store;
using Apache.Ignite.Core.Common;
- using Apache.Ignite.Core.Discovery.Tcp;
- using Apache.Ignite.Core.Discovery.Tcp.Static;
using NUnit.Framework;
/// <summary>
@@ -436,6 +434,9 @@ namespace Apache.Ignite.Core.Tests.Cache
WriteBehindBatchSize = 18,
WriteBehindEnabled = false,
WriteSynchronizationMode = CacheWriteSynchronizationMode.PrimarySync,
+ CacheStoreFactory = new CacheStoreFactoryTest(),
+ ReadThrough = true,
+ WriteThrough = true,
QueryEntities = new[]
{
new QueryEntity
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs
index b48cdc9..cc46642 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTest.cs
@@ -15,6 +15,7 @@
* limitations under the License.
*/
+#pragma warning disable 618
namespace Apache.Ignite.Core.Tests.Cache.Store
{
using System;
@@ -134,7 +135,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
///
/// </summary>
[TestFixtureSetUp]
- public void BeforeTests()
+ public virtual void BeforeTests()
{
TestUtils.KillProcesses();
@@ -156,7 +157,7 @@ namespace Apache.Ignite.Core.Tests.Cache.Store
///
/// </summary>
[TestFixtureTearDown]
- public virtual void AfterTests()
+ public void AfterTests()
{
Ignition.StopAll(true);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTestCodeConfig.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTestCodeConfig.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTestCodeConfig.cs
new file mode 100644
index 0000000..0b6f771
--- /dev/null
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Cache/Store/CacheStoreTestCodeConfig.cs
@@ -0,0 +1,106 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Cache.Store
+{
+ using System;
+ using Apache.Ignite.Core.Binary;
+ using Apache.Ignite.Core.Cache.Configuration;
+ using Apache.Ignite.Core.Cache.Store;
+ using Apache.Ignite.Core.Common;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Tests cache store without Spring.
+ /// </summary>
+ public class CacheStoreTestCodeConfig : CacheStoreTest
+ {
+ /// <summary>
+ /// Fixture setup.
+ /// </summary>
+ [TestFixtureSetUp]
+ public override void BeforeTests()
+ {
+ var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
+ {
+ BinaryConfiguration = new BinaryConfiguration(typeof(Key), typeof(Value)),
+ CacheConfiguration = new[]
+ {
+ new CacheConfiguration
+ {
+ Name = "binary_store",
+ CacheMode = CacheMode.Local,
+ AtomicityMode = CacheAtomicityMode.Transactional,
+ WriteThrough = true,
+ ReadThrough = true,
+ KeepBinaryInStore = true,
+ CacheStoreFactory = new StoreFactory()
+ },
+ new CacheConfiguration
+ {
+ Name = "object_store",
+ CacheMode = CacheMode.Local,
+ AtomicityMode = CacheAtomicityMode.Transactional,
+ WriteThrough = true,
+ ReadThrough = true,
+ KeepBinaryInStore = false,
+ CacheStoreFactory = new StoreFactory()
+ },
+ new CacheConfiguration
+ {
+ Name = "template_store*",
+ CacheMode = CacheMode.Local,
+ AtomicityMode = CacheAtomicityMode.Transactional,
+ WriteThrough = true,
+ ReadThrough = true,
+ KeepBinaryInStore = false,
+ CacheStoreFactory = new StoreFactory()
+ },
+ new CacheConfiguration
+ {
+ Name = "custom_store",
+ CacheMode = CacheMode.Local,
+ AtomicityMode = CacheAtomicityMode.Transactional,
+ WriteThrough = true,
+ ReadThrough = true,
+ CacheStoreFactory = new CustomStoreFactory()
+ },
+ }
+ };
+
+ Ignition.Start(cfg);
+ }
+
+ [Serializable]
+ private class StoreFactory : IFactory<ICacheStore>
+ {
+ public ICacheStore CreateInstance()
+ {
+ return new CacheTestStore();
+ }
+ }
+
+ [Serializable]
+ private class CustomStoreFactory : IFactory<ICacheStore>
+ {
+ public ICacheStore CreateInstance()
+ {
+ return new CacheTestStore {IntProperty = 42, StringProperty = "String value"};
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
index d944a04..e221a55 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/IgniteConfigurationSerializerTest.cs
@@ -68,7 +68,7 @@ namespace Apache.Ignite.Core.Tests
<iLifecycleBean type='Apache.Ignite.Core.Tests.IgniteConfigurationSerializerTest+LifecycleBean, Apache.Ignite.Core.Tests' foo='15' />
</lifecycleBeans>
<cacheConfiguration>
- <cacheConfiguration cacheMode='Replicated'>
+ <cacheConfiguration cacheMode='Replicated' readThrough='true' writeThrough='true'>
<queryEntities>
<queryEntity keyType='System.Int32' valueType='System.String'>
<fields>
@@ -120,6 +120,8 @@ namespace Apache.Ignite.Core.Tests
var cacheCfg = cfg.CacheConfiguration.First();
Assert.AreEqual(CacheMode.Replicated, cacheCfg.CacheMode);
+ Assert.IsTrue(cacheCfg.ReadThrough);
+ Assert.IsTrue(cacheCfg.WriteThrough);
var queryEntity = cacheCfg.QueryEntities.Single();
Assert.AreEqual(typeof(int), queryEntity.KeyType);
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
index b319be9..ba509fc 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Cache/Configuration/CacheConfiguration.cs
@@ -135,6 +135,12 @@ namespace Apache.Ignite.Core.Cache.Configuration
/// <summary> Default value for 'copyOnRead' flag. </summary>
public const bool DefaultCopyOnRead = true;
+ /// <summary> Default value for read-through behavior. </summary>
+ public const bool DefaultReadThrough = false;
+
+ /// <summary> Default value for write-through behavior. </summary>
+ public const bool DefaultWriteThrough = false;
+
/// <summary>
/// Gets or sets the cache name.
/// </summary>
@@ -255,6 +261,8 @@ namespace Apache.Ignite.Core.Cache.Configuration
WriteBehindFlushSize = reader.ReadInt();
WriteBehindFlushThreadCount = reader.ReadInt();
WriteSynchronizationMode = (CacheWriteSynchronizationMode) reader.ReadInt();
+ ReadThrough = reader.ReadBoolean();
+ WriteThrough = reader.ReadBoolean();
CacheStoreFactory = reader.ReadObject<IFactory<ICacheStore>>();
var count = reader.ReadInt();
@@ -303,6 +311,8 @@ namespace Apache.Ignite.Core.Cache.Configuration
writer.WriteInt(WriteBehindFlushSize);
writer.WriteInt(WriteBehindFlushThreadCount);
writer.WriteInt((int) WriteSynchronizationMode);
+ writer.WriteBoolean(ReadThrough);
+ writer.WriteBoolean(WriteThrough);
writer.WriteObject(CacheStoreFactory);
if (QueryEntities != null)
@@ -589,10 +599,36 @@ namespace Apache.Ignite.Core.Cache.Configuration
/// <summary>
/// Gets or sets the factory for underlying persistent storage for read-through and write-through operations.
+ /// <para />
+ /// See <see cref="ReadThrough"/> and <see cref="WriteThrough"/> properties to enable read-through and
+ /// write-through behavior so that cache store is invoked on get and/or put operations.
+ /// <para />
+ /// If both <see cref="ReadThrough"/> and <see cref="WriteThrough"/> are <code>false</code>, cache store
+ /// will be invoked only on <see cref="ICache{TK,TV}.LoadCache"/> calls.
/// </summary>
public IFactory<ICacheStore> CacheStoreFactory { get; set; }
/// <summary>
+ /// Gets or sets a value indicating whether read-through should be enabled for cache operations.
+ /// <para />
+ /// When in read-through mode, cache misses that occur due to cache entries not existing
+ /// as a result of performing a "get" operations will appropriately cause the
+ /// configured <see cref="ICacheStore"/> (see <see cref="CacheStoreFactory"/>) to be invoked.
+ /// </summary>
+ [DefaultValue(DefaultReadThrough)]
+ public bool ReadThrough { get; set; }
+
+ /// <summary>
+ /// Gets or sets a value indicating whether write-through should be enabled for cache operations.
+ /// <para />
+ /// When in "write-through" mode, cache updates that occur as a result of performing "put" operations
+ /// will appropriately cause the configured
+ /// <see cref="ICacheStore"/> (see <see cref="CacheStoreFactory"/>) to be invoked.
+ /// </summary>
+ [DefaultValue(DefaultWriteThrough)]
+ public bool WriteThrough { get; set; }
+
+ /// <summary>
/// Gets or sets the query entity configuration.
/// </summary>
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
http://git-wip-us.apache.org/repos/asf/ignite/blob/c638f1e7/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
index 12a4660..8902d3a 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/IgniteConfigurationSection.xsd
@@ -190,6 +190,8 @@
<xs:attribute name="longQueryWarningTimeout" type="xs:string" />
<xs:attribute name="sqlEscapeAll" type="xs:boolean" />
<xs:attribute name="sqlOnheapRowCacheSize" type="xs:int" />
+ <xs:attribute name="readThrough" type="xs:boolean" />
+ <xs:attribute name="writeThrough" type="xs:boolean" />
</xs:complexType>
</xs:element>
</xs:sequence>
[4/8] ignite git commit: IGNITE-2842: IGFS: Optimized create/mkdirs
operations with help of entry processors.
Posted by vo...@apache.org.
IGNITE-2842: IGFS: Optimized create/mkdirs operations with help of entry processors.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/ad6bbd9a
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/ad6bbd9a
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/ad6bbd9a
Branch: refs/heads/ignite-1786
Commit: ad6bbd9ad55a5cc1fdf526b5d511465628a8dca5
Parents: 297cbcb
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Mar 16 12:31:37 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Mar 16 12:31:37 2016 +0300
----------------------------------------------------------------------
.../internal/processors/igfs/IgfsFileInfo.java | 13 +
.../processors/igfs/IgfsListingEntry.java | 15 +-
.../processors/igfs/IgfsMetaManager.java | 262 ++++++++++++++++---
3 files changed, 251 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/ad6bbd9a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfo.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfo.java
index ba484bb..13c54ff 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfo.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsFileInfo.java
@@ -345,6 +345,19 @@ public final class IgfsFileInfo implements Externalizable {
}
/**
+ * Temporal hack to change ID before saving entry to cache. Currently we have too much constructors and adding
+ * more will make things even worse. Instead, we use this method until directories and files are split into
+ * separate entities.
+ *
+ * @param id ID.
+ * @deprecated Use only on not-yet-saved entries.
+ */
+ @Deprecated
+ public void id(IgniteUuid id) {
+ this.id = id;
+ }
+
+ /**
* @return {@code True} if this is a file.
*/
public boolean isFile() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/ad6bbd9a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsListingEntry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsListingEntry.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsListingEntry.java
index 61d9265..4fe0dca 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsListingEntry.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsListingEntry.java
@@ -34,7 +34,7 @@ public class IgfsListingEntry implements Externalizable {
/** */
private static final long serialVersionUID = 0L;
- /** File id. */
+ /** ID. */
private IgniteUuid id;
/** Directory marker. */
@@ -48,6 +48,8 @@ public class IgfsListingEntry implements Externalizable {
}
/**
+ * Constructor.
+ *
* @param fileInfo File info to construct listing entry from.
*/
public IgfsListingEntry(IgfsFileInfo fileInfo) {
@@ -56,6 +58,17 @@ public class IgfsListingEntry implements Externalizable {
}
/**
+ * Constructor.
+ *
+ * @param id File ID.
+ * @param dir Directory marker.
+ */
+ public IgfsListingEntry(IgniteUuid id, boolean dir) {
+ this.id = id;
+ this.dir = dir;
+ }
+
+ /**
* @return Entry file ID.
*/
public IgniteUuid fileId() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/ad6bbd9a/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 df69d49..2a85cf8 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
@@ -1868,13 +1868,11 @@ public class IgfsMetaManager extends IgfsManager {
* @return New file info.
* @throws IgniteCheckedException If failed.
*/
- private IgfsFileInfo invokeAndGet(IgniteUuid id, EntryProcessor<IgniteUuid, IgfsFileInfo, Void> proc)
+ private IgfsFileInfo invokeAndGet(IgniteUuid id, EntryProcessor<IgniteUuid, IgfsFileInfo, IgfsFileInfo> proc)
throws IgniteCheckedException {
validTxState(true);
- id2InfoPrj.invoke(id, proc);
-
- return getInfo(id);
+ return id2InfoPrj.invoke(id, proc).get();
}
/**
@@ -3493,7 +3491,7 @@ public class IgfsMetaManager extends IgfsManager {
private final SortedSet<IgniteUuid> idSet = new TreeSet<IgniteUuid>(PATH_ID_SORTING_COMPARATOR);
/** The middle node properties. */
- private final Map<String, String> middleProps;
+ private final Map<String, String> props;
/** The leaf node properties. */
private final Map<String, String> leafProps;
@@ -3557,7 +3555,7 @@ public class IgfsMetaManager extends IgfsManager {
* Constructor.
*
* @param path Path.
- * @param middleProps Middle properties.
+ * @param props Middle properties.
* @param leafProps Leaf properties.
* @param leafDir Whether leaf is directory or file.
* @param blockSize Block size.
@@ -3565,13 +3563,13 @@ public class IgfsMetaManager extends IgfsManager {
* @param evictExclude Evict exclude flag.
* @throws IgniteCheckedException If failed.
*/
- private DirectoryChainBuilder(IgfsPath path, Map<String,String> middleProps, Map<String,String> leafProps,
+ private DirectoryChainBuilder(IgfsPath path, Map<String,String> props, Map<String,String> leafProps,
boolean leafDir, int blockSize, @Nullable IgniteUuid affKey, boolean evictExclude)
throws IgniteCheckedException {
this.path = path;
this.components = path.components();
this.idList = fileIds(path);
- this.middleProps = middleProps;
+ this.props = props;
this.leafProps = leafProps;
this.leafDir = leafDir;
this.blockSize = blockSize;
@@ -3617,44 +3615,46 @@ public class IgfsMetaManager extends IgfsManager {
* Does the main portion of job building the renmaining path.
*/
public final void doBuild() throws IgniteCheckedException {
- IgfsFileInfo childInfo = null;
+ // Fix current time. It will be used in all created entities.
+ long createTime = System.currentTimeMillis();
+ IgfsListingEntry childInfo = null;
String childName = null;
- IgfsFileInfo newInfo;
-
IgniteUuid parentId = null;
// This loop creates the missing directory chain from the bottom to the top:
for (int i = components.size() - 1; i >= existingIdCnt - 1; i--) {
- // Required entry does not exist.
- // Create new directory info:
+ IgniteUuid childId = IgniteUuid.randomUuid();
+ boolean childDir;
+
if (childName == null) {
assert childInfo == null;
- long t = System.currentTimeMillis();
+ if (leafDir) {
+ childDir = true;
- if (leafDir)
- newInfo = new IgfsFileInfo(true, leafProps, t, t);
- else
- newInfo = new IgfsFileInfo(blockSize, 0L, affKey, createFileLockId(false), evictExclude,
- leafProps, t, t);
+ leafInfo = invokeAndGet(childId, new DirectoryCreateProcessor(createTime, leafProps));
+ }
+ else {
+ childDir = false;
- leafInfo = newInfo;
+ leafInfo = invokeAndGet(childId, new FileCreateProcessor(createTime, leafProps, blockSize,
+ affKey, createFileLockId(false), evictExclude));
+ }
}
else {
assert childInfo != null;
- newInfo = new IgfsFileInfo(Collections.singletonMap(childName,
- new IgfsListingEntry(childInfo)), middleProps);
+ childDir = true;
+
+ id2InfoPrj.invoke(childId, new DirectoryCreateProcessor(createTime, props, childName, childInfo));
if (parentId == null)
- parentId = newInfo.id();
+ parentId = childId;
}
- id2InfoPrj.put(newInfo.id(), newInfo);
-
- childInfo = newInfo;
+ childInfo = new IgfsListingEntry(childId, childDir);
childName = components.get(i);
}
@@ -3665,7 +3665,7 @@ public class IgfsMetaManager extends IgfsManager {
leafParentId = parentId;
// Now link the newly created directory chain to the lowermost existing parent:
- id2InfoPrj.invoke(lowermostExistingId, new ListingAdd(childName, new IgfsListingEntry(childInfo)));
+ id2InfoPrj.invoke(lowermostExistingId, new ListingAdd(childName, childInfo));
}
/**
@@ -3692,9 +3692,193 @@ public class IgfsMetaManager extends IgfsManager {
}
/**
+ * File create processor.
+ */
+ private static class FileCreateProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, IgfsFileInfo>,
+ Externalizable {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** Create time. */
+ private long createTime;
+
+ /** Properties. */
+ private Map<String, String> props;
+
+ /** Block size. */
+ private int blockSize;
+
+ /** Affintiy key. */
+ private IgniteUuid affKey;
+
+ /** Lcok ID. */
+ private IgniteUuid lockId;
+
+ /** Evict exclude flag. */
+ private boolean evictExclude;
+
+ /**
+ * Constructor.
+ */
+ public FileCreateProcessor() {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param createTime Create time.
+ * @param props Properties.
+ * @param blockSize Block size.
+ * @param affKey Affinity key.
+ * @param lockId Lock ID.
+ * @param evictExclude Evict exclude flag.
+ */
+ public FileCreateProcessor(long createTime, Map<String, String> props, int blockSize,
+ @Nullable IgniteUuid affKey, IgniteUuid lockId, boolean evictExclude) {
+ this.createTime = createTime;
+ this.props = props;
+ this.blockSize = blockSize;
+ this.affKey = affKey;
+ this.lockId = lockId;
+ this.evictExclude = evictExclude;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsFileInfo process(MutableEntry<IgniteUuid, IgfsFileInfo> entry, Object... args)
+ throws EntryProcessorException {
+ IgfsFileInfo info = new IgfsFileInfo(blockSize, 0L, affKey, lockId, evictExclude, props,
+ createTime, createTime);
+
+ info.id(entry.getKey());
+
+ entry.setValue(info);
+
+ return info;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeLong(createTime);
+ U.writeStringMap(out, props);
+ out.writeInt(blockSize);
+ out.writeObject(affKey);
+ out.writeObject(lockId);
+ out.writeBoolean(evictExclude);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ createTime = in.readLong();
+ props = U.readStringMap(in);
+ blockSize = in.readInt();
+ affKey = (IgniteUuid)in.readObject();
+ lockId = (IgniteUuid)in.readObject();
+ evictExclude = in.readBoolean();
+ }
+ }
+
+ /**
+ * Directory create processor.
+ */
+ private static class DirectoryCreateProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, IgfsFileInfo>,
+ Externalizable {
+ /** */
+ private static final long serialVersionUID = 0L;
+
+ /** Create time. */
+ private long createTime;
+
+ /** Properties. */
+ private Map<String, String> props;
+
+ /** Child name (optional). */
+ private String childName;
+
+ /** Child entry (optional. */
+ private IgfsListingEntry childEntry;
+
+ /**
+ * Constructor.
+ */
+ public DirectoryCreateProcessor() {
+ // No-op.
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param createTime Create time.
+ * @param props Properties.
+ */
+ public DirectoryCreateProcessor(long createTime, Map<String, String> props) {
+ this(createTime, props, null, null);
+ }
+
+ /**
+ * Constructor.
+ *
+ * @param createTime Create time.
+ * @param props Properties.
+ * @param childName Child name.
+ * @param childEntry Child entry.
+ */
+ public DirectoryCreateProcessor(long createTime, Map<String, String> props, String childName,
+ IgfsListingEntry childEntry) {
+ this.createTime = createTime;
+ this.props = props;
+ this.childName = childName;
+ this.childEntry = childEntry;
+ }
+
+ /** {@inheritDoc} */
+ @Override public IgfsFileInfo process(MutableEntry<IgniteUuid, IgfsFileInfo> entry, Object... args)
+ throws EntryProcessorException {
+
+ IgfsFileInfo info = new IgfsFileInfo(true, props, createTime, createTime);
+
+ if (childName != null)
+ info = new IgfsFileInfo(Collections.singletonMap(childName, childEntry), info);
+
+ info.id(entry.getKey());
+
+ entry.setValue(info);
+
+ return info;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void writeExternal(ObjectOutput out) throws IOException {
+ out.writeLong(createTime);
+ U.writeStringMap(out, props);
+
+ if (childName != null) {
+ out.writeBoolean(true);
+
+ U.writeString(out, childName);
+ out.writeObject(childEntry);
+ }
+ else
+ out.writeBoolean(false);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ createTime = in.readLong();
+ props = U.readStringMap(in);
+
+ if (in.readBoolean()) {
+ childName = U.readString(in);
+ childEntry = (IgfsListingEntry)in.readObject();
+ }
+ }
+ }
+
+ /**
* File lock entry processor.
*/
- private static class FileLockProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, Void>, Externalizable {
+ private static class FileLockProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, IgfsFileInfo>,
+ Externalizable {
/** */
private static final long serialVersionUID = 0L;
@@ -3718,13 +3902,15 @@ public class IgfsMetaManager extends IgfsManager {
}
/** {@inheritDoc} */
- @Override public Void process(MutableEntry<IgniteUuid, IgfsFileInfo> entry, Object... args)
+ @Override public IgfsFileInfo process(MutableEntry<IgniteUuid, IgfsFileInfo> entry, Object... args)
throws EntryProcessorException {
- IgfsFileInfo old = entry.getValue();
+ IgfsFileInfo oldInfo = entry.getValue();
- entry.setValue(new IgfsFileInfo(old, lockId, old.modificationTime()));
+ IgfsFileInfo newInfo = new IgfsFileInfo(oldInfo, lockId, oldInfo.modificationTime());
- return null;
+ entry.setValue(newInfo);
+
+ return newInfo;
}
/** {@inheritDoc} */
@@ -3789,7 +3975,7 @@ public class IgfsMetaManager extends IgfsManager {
/**
* File reserve space entry processor.
*/
- private static class FileReserveSpaceProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, Void>,
+ private static class FileReserveSpaceProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, IgfsFileInfo>,
Externalizable {
/** */
private static final long serialVersionUID = 0L;
@@ -3819,7 +4005,7 @@ public class IgfsMetaManager extends IgfsManager {
}
/** {@inheritDoc} */
- @Override public Void process(MutableEntry<IgniteUuid, IgfsFileInfo> entry, Object... args)
+ @Override public IgfsFileInfo process(MutableEntry<IgniteUuid, IgfsFileInfo> entry, Object... args)
throws EntryProcessorException {
IgfsFileInfo oldInfo = entry.getValue();
@@ -3833,7 +4019,7 @@ public class IgfsMetaManager extends IgfsManager {
entry.setValue(newInfo);
- return null;
+ return newInfo;
}
/** {@inheritDoc} */
@@ -3852,7 +4038,7 @@ public class IgfsMetaManager extends IgfsManager {
/**
* Update properties processor.
*/
- private static class UpdatePropertiesProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, Void>,
+ private static class UpdatePropertiesProcessor implements EntryProcessor<IgniteUuid, IgfsFileInfo, IgfsFileInfo>,
Externalizable {
/** */
private static final long serialVersionUID = 0L;
@@ -3877,7 +4063,7 @@ public class IgfsMetaManager extends IgfsManager {
}
/** {@inheritDoc} */
- @Override public Void process(MutableEntry<IgniteUuid, IgfsFileInfo> entry, Object... args)
+ @Override public IgfsFileInfo process(MutableEntry<IgniteUuid, IgfsFileInfo> entry, Object... args)
throws EntryProcessorException {
IgfsFileInfo oldInfo = entry.getValue();
@@ -3898,7 +4084,7 @@ public class IgfsMetaManager extends IgfsManager {
entry.setValue(newInfo);
- return null;
+ return newInfo;
}
/** {@inheritDoc} */
[2/8] ignite git commit: IGNITE-2817: IGFS: Optimized
"updateProperties" and several other cache operations. Reafactored
IgfsMetaManager a bit to simplify work with cache.
Posted by vo...@apache.org.
IGNITE-2817: IGFS: Optimized "updateProperties" and several other cache operations. Reafactored IgfsMetaManager a bit to simplify work with cache.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/dda1f0ed
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/dda1f0ed
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/dda1f0ed
Branch: refs/heads/ignite-1786
Commit: dda1f0ed449111b7e1011a669b30bc3b4c5d2d92
Parents: 7b7233e
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Mar 16 09:14:49 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Mar 16 09:14:49 2016 +0300
----------------------------------------------------------------------
.../internal/processors/igfs/IgfsImpl.java | 4 +-
.../processors/igfs/IgfsMetaManager.java | 641 ++++++++++---------
.../igfs/IgfsMetaManagerSelfTest.java | 23 +-
3 files changed, 336 insertions(+), 332 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/dda1f0ed/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..3065427 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
@@ -636,9 +636,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/dda1f0ed/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 463e7a8..df69d49 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
@@ -40,7 +40,6 @@ import java.util.TreeSet;
import java.util.concurrent.CountDownLatch;
import javax.cache.processor.EntryProcessor;
import javax.cache.processor.EntryProcessorException;
-import javax.cache.processor.EntryProcessorResult;
import javax.cache.processor.MutableEntry;
import org.apache.ignite.IgniteCheckedException;
@@ -238,7 +237,7 @@ public class IgfsMetaManager extends IgfsManager {
@Nullable public IgniteUuid fileId(IgfsPath path) throws IgniteCheckedException {
if (busyLock.enterBusy()) {
try {
- assert validTxState(false);
+ validTxState(false);
return fileId(path, false);
}
@@ -322,7 +321,7 @@ public class IgfsMetaManager extends IgfsManager {
public List<IgniteUuid> fileIds(IgfsPath path) throws IgniteCheckedException {
if (busyLock.enterBusy()) {
try {
- assert validTxState(false);
+ validTxState(false);
return fileIds(path, false);
}
@@ -407,7 +406,7 @@ public class IgfsMetaManager extends IgfsManager {
if (fileId == null)
return null;
- IgfsFileInfo info = id2InfoPrj.get(fileId);
+ IgfsFileInfo info = getInfo(fileId);
// Force root ID always exist in cache.
if (info == null && IgfsUtils.ROOT_ID.equals(fileId))
@@ -433,13 +432,14 @@ public class IgfsMetaManager extends IgfsManager {
public Map<IgniteUuid, IgfsFileInfo> infos(Collection<IgniteUuid> fileIds) throws IgniteCheckedException {
if (busyLock.enterBusy()) {
try {
- assert validTxState(false);
+ validTxState(false);
+
assert fileIds != null;
if (F.isEmpty(fileIds))
return Collections.emptyMap();
- Map<IgniteUuid, IgfsFileInfo> map = id2InfoPrj.getAll(fileIds);
+ Map<IgniteUuid, IgfsFileInfo> map = getInfos(fileIds);
// Force root ID always exist in cache.
if (fileIds.contains(IgfsUtils.ROOT_ID) && !map.containsKey(IgfsUtils.ROOT_ID)) {
@@ -469,7 +469,8 @@ public class IgfsMetaManager extends IgfsManager {
public @Nullable IgfsFileInfo lock(IgniteUuid fileId, boolean delete) throws IgniteCheckedException {
if (busyLock.enterBusy()) {
try {
- assert validTxState(false);
+ validTxState(false);
+
assert fileId != null;
IgniteInternalTx tx = startTx();
@@ -484,11 +485,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();
@@ -530,7 +527,8 @@ public class IgfsMetaManager extends IgfsManager {
* @throws IgniteCheckedException If failed.
*/
public void unlock(final IgfsFileInfo info, final long modificationTime) throws IgniteCheckedException {
- assert validTxState(false);
+ validTxState(false);
+
assert info != null;
if (busyLock.enterBusy()) {
@@ -546,7 +544,7 @@ public class IgfsMetaManager extends IgfsManager {
try {
IgfsUtils.doInTransactionWithRetries(id2InfoPrj, new IgniteOutClosureX<Void>() {
@Override public Void applyx() throws IgniteCheckedException {
- assert validTxState(true);
+ validTxState(true);
IgniteUuid fileId = info.id();
@@ -569,7 +567,7 @@ public class IgfsMetaManager extends IgfsManager {
});
}
finally {
- assert validTxState(false);
+ validTxState(false);
if (interrupted)
Thread.currentThread().interrupt();
@@ -591,7 +589,8 @@ public class IgfsMetaManager extends IgfsManager {
* @throws IgniteCheckedException If failed.
*/
private Map<IgniteUuid, IgfsFileInfo> lockIds(IgniteUuid... fileIds) throws IgniteCheckedException {
- assert validTxState(true);
+ validTxState(true);
+
assert fileIds != null && fileIds.length > 0;
Arrays.sort(fileIds);
@@ -631,13 +630,13 @@ public class IgfsMetaManager extends IgfsManager {
*/
private Map<IgniteUuid, IgfsFileInfo> lockIds(Collection<IgniteUuid> fileIds) throws IgniteCheckedException {
assert isSorted(fileIds);
- assert validTxState(true);
+ validTxState(true);
if (log.isDebugEnabled())
log.debug("Locking file ids: " + fileIds);
// Lock files and get their infos.
- Map<IgniteUuid, IgfsFileInfo> map = id2InfoPrj.getAll(fileIds);
+ Map<IgniteUuid, IgfsFileInfo> map = getInfos(fileIds);
if (log.isDebugEnabled())
log.debug("Locked file ids: " + fileIds);
@@ -769,7 +768,7 @@ public class IgfsMetaManager extends IgfsManager {
assert fileId != null;
IgfsFileInfo info = skipTx ? id2InfoPrj.getAllOutTx(Collections.singleton(fileId)).get(fileId) :
- id2InfoPrj.get(fileId);
+ getInfo(fileId);
return info == null ? Collections.<String, IgfsListingEntry>emptyMap() : info.listing();
}
@@ -789,7 +788,7 @@ public class IgfsMetaManager extends IgfsManager {
log.debug("Locking parent id [parentId=" + parentId + ", fileName=" + fileName + ", newFileInfo=" +
newFileInfo + ']');
- assert validTxState(true);
+ validTxState(true);
// Lock only parent file ID.
IgfsFileInfo parentInfo = info(parentId);
@@ -806,10 +805,7 @@ public class IgfsMetaManager extends IgfsManager {
if (childEntry != null)
return childEntry.fileId();
- if (!id2InfoPrj.putIfAbsent(newFileInfo.id(), newFileInfo))
- throw fsException("Failed to add file details into cache: " + newFileInfo);
-
- id2InfoPrj.invoke(parentId, new ListingAdd(fileName, new IgfsListingEntry(newFileInfo)));
+ createNewEntry(newFileInfo, parentId, fileName);
return null;
}
@@ -825,7 +821,7 @@ public class IgfsMetaManager extends IgfsManager {
public IgfsFileInfo move(IgfsPath srcPath, IgfsPath dstPath) throws IgniteCheckedException {
if (busyLock.enterBusy()) {
try {
- assert validTxState(false);
+ validTxState(false);
// 1. First get source and destination path IDs.
List<IgniteUuid> srcPathIds = fileIds(srcPath);
@@ -918,8 +914,7 @@ public class IgfsMetaManager extends IgfsManager {
// 8. Actual move: remove from source parent and add to destination target.
IgfsListingEntry entry = srcTargetInfo.listing().get(srcName);
- id2InfoPrj.invoke(srcTargetId, new ListingRemove(srcName, entry.fileId()));
- id2InfoPrj.invoke(dstTargetId, new ListingAdd(dstName, entry));
+ transferEntry(entry, srcTargetId, srcName, dstTargetId, dstName);
tx.commit();
@@ -990,7 +985,7 @@ public class IgfsMetaManager extends IgfsManager {
*/
private void moveNonTx(IgniteUuid fileId, @Nullable String srcFileName, IgniteUuid srcParentId, String destFileName,
IgniteUuid destParentId) throws IgniteCheckedException {
- assert validTxState(true);
+ validTxState(true);
assert fileId != null;
assert srcFileName != null;
@@ -1047,11 +1042,7 @@ public class IgfsMetaManager extends IgfsManager {
" directory (file already exists) [fileId=" + fileId + ", destFileName=" + destFileName +
", destParentId=" + destParentId + ']'));
- // Remove listing entry from the source parent listing.
- id2InfoPrj.invoke(srcParentId, new ListingRemove(srcFileName, srcEntry.fileId()));
-
- // Add listing entry into the destination parent listing.
- id2InfoPrj.invoke(destParentId, new ListingAdd(destFileName, srcEntry));
+ transferEntry(srcEntry, srcParentId, srcFileName, destParentId, destFileName);
}
/**
@@ -1064,7 +1055,7 @@ public class IgfsMetaManager extends IgfsManager {
IgniteUuid format() throws IgniteCheckedException {
if (busyLock.enterBusy()) {
try {
- assert validTxState(false);
+ validTxState(false);
IgniteUuid trashId = IgfsUtils.randomTrashId();
@@ -1088,11 +1079,7 @@ public class IgfsMetaManager extends IgfsManager {
IgfsFileInfo newInfo = new IgfsFileInfo(transferListing);
- id2InfoPrj.put(newInfo.id(), newInfo);
-
- // Add new info to trash listing.
- id2InfoPrj.invoke(trashId, new ListingAdd(newInfo.id().toString(),
- new IgfsListingEntry(newInfo)));
+ createNewEntry(newInfo, trashId, newInfo.id().toString());
// Remove listing entries from root.
// Note that root directory properties and other attributes are preserved:
@@ -1128,7 +1115,7 @@ public class IgfsMetaManager extends IgfsManager {
IgniteUuid softDelete(final IgfsPath path, final boolean recursive) throws IgniteCheckedException {
if (busyLock.enterBusy()) {
try {
- assert validTxState(false);
+ validTxState(false);
final SortedSet<IgniteUuid> allIds = new TreeSet<>(PATH_ID_SORTING_COMPARATOR);
@@ -1191,15 +1178,12 @@ public class IgfsMetaManager extends IgfsManager {
assert victimId.equals(srcEntry.fileId());
- id2InfoPrj.invoke(srcParentId, new ListingRemove(srcFileName, srcEntry.fileId()));
-
- // Add listing entry into the destination parent listing.
- id2InfoPrj.invoke(trashId, new ListingAdd(destFileName, srcEntry));
+ transferEntry(srcEntry, srcParentId, srcFileName, trashId, destFileName);
if (victimInfo.isFile())
// Update a file info of the removed file with a file path,
// which will be used by delete worker for event notifications.
- id2InfoPrj.invoke(victimId, new UpdatePath(path));
+ invokeUpdatePath(victimId, path);
tx.commit();
@@ -1233,7 +1217,7 @@ public class IgfsMetaManager extends IgfsManager {
@Nullable private IgniteUuid softDeleteNonTx(@Nullable IgniteUuid parentId, @Nullable String name, IgniteUuid id,
IgniteUuid trashId)
throws IgniteCheckedException {
- assert validTxState(true);
+ validTxState(true);
IgniteUuid resId;
@@ -1241,7 +1225,7 @@ public class IgfsMetaManager extends IgfsManager {
// Handle special case when we deleting root directory.
assert IgfsUtils.ROOT_ID.equals(id);
- IgfsFileInfo rootInfo = id2InfoPrj.get(IgfsUtils.ROOT_ID);
+ IgfsFileInfo rootInfo = getInfo(IgfsUtils.ROOT_ID);
if (rootInfo == null)
return null; // Root was never created.
@@ -1269,11 +1253,7 @@ public class IgfsMetaManager extends IgfsManager {
IgfsFileInfo newInfo = new IgfsFileInfo(transferListing);
- id2InfoPrj.getAndPut(newInfo.id(), newInfo);
-
- // Add new info to trash listing.
- id2InfoPrj.invoke(trashId, new ListingAdd(newInfo.id().toString(),
- new IgfsListingEntry(newInfo)));
+ createNewEntry(newInfo, trashId, newInfo.id().toString());
// Remove listing entries from root.
for (Map.Entry<String, IgfsListingEntry> entry : transferListing.entrySet())
@@ -1311,7 +1291,7 @@ public class IgfsMetaManager extends IgfsManager {
try {
assert parentId != null;
assert listing != null;
- assert validTxState(false);
+ validTxState(false);
IgniteInternalTx tx = startTx();
@@ -1353,7 +1333,7 @@ public class IgfsMetaManager extends IgfsManager {
// Delete only files or empty folders.
if (!entryInfo.hasChildren()) {
- id2InfoPrj.getAndRemove(childId);
+ id2InfoPrj.remove(childId);
newListing.remove(childName);
@@ -1402,7 +1382,7 @@ public class IgfsMetaManager extends IgfsManager {
boolean delete(IgniteUuid parentId, String name, IgniteUuid id) throws IgniteCheckedException {
if (busyLock.enterBusy()) {
try {
- assert validTxState(false);
+ validTxState(false);
IgniteInternalTx tx = startTx();
@@ -1428,11 +1408,9 @@ public class IgfsMetaManager extends IgfsManager {
IgfsListingEntry childEntry = parentInfo.listing().get(name);
if (childEntry != null)
- id2InfoPrj.invoke(parentId, new ListingRemove(name, childEntry.fileId()));
+ id2InfoPrj.invoke(parentId, new ListingRemove(name, id));
- IgfsFileInfo deleted = id2InfoPrj.getAndRemove(id);
-
- assert victim.id().equals(deleted.id());
+ id2InfoPrj.remove(id);
res = true;
}
@@ -1468,7 +1446,7 @@ public class IgfsMetaManager extends IgfsManager {
for (int i = 0; i < IgfsUtils.TRASH_CONCURRENCY; i++) {
IgniteUuid trashId = IgfsUtils.trashId(i);
- IgfsFileInfo trashInfo = id2InfoPrj.get(trashId);
+ IgfsFileInfo trashInfo = getInfo(trashId);
if (trashInfo != null && trashInfo.hasChildren()) {
for (IgfsListingEntry entry : trashInfo.listing().values())
@@ -1489,75 +1467,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";
- assert validTxState(true);
+
+ 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.
+ return null;
- 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(fileId, newInfo);
-
- if (parentId != null) {
- IgfsListingEntry entry = new IgfsListingEntry(newInfo);
-
- assert id2InfoPrj.get(parentId) != null;
-
- id2InfoPrj.invoke(parentId, new ListingAdd(fileName, entry));
- }
-
- return newInfo;
+ return invokeAndGet(fileId, new UpdatePropertiesProcessor(props));
}
catch (GridClosureException e) {
throw U.cast(e);
@@ -1567,23 +1498,21 @@ 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 {
- assert validTxState(false);
+ validTxState(false);
IgniteInternalTx tx = startTx();
try {
- IgfsFileInfo info = updatePropertiesNonTx(parentId, fileId, fileName, props);
+ IgfsFileInfo info = updatePropertiesNonTx(fileId, props);
tx.commit();
@@ -1598,8 +1527,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 + ']');
}
/**
@@ -1613,7 +1542,7 @@ public class IgfsMetaManager extends IgfsManager {
*/
public IgfsFileInfo reserveSpace(IgfsPath path, IgniteUuid fileId, long space, IgfsFileAffinityRange affRange)
throws IgniteCheckedException {
- assert validTxState(false);
+ validTxState(false);
if (busyLock.enterBusy()) {
try {
@@ -1629,9 +1558,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();
@@ -1663,7 +1590,7 @@ public class IgfsMetaManager extends IgfsManager {
*/
@Nullable public IgfsFileInfo updateInfo(IgniteUuid fileId, IgniteClosure<IgfsFileInfo, IgfsFileInfo> c)
throws IgniteCheckedException {
- assert validTxState(false);
+ validTxState(false);
assert fileId != null;
assert c != null;
@@ -1672,7 +1599,7 @@ public class IgfsMetaManager extends IgfsManager {
if (log.isDebugEnabled())
log.debug("Update file info [fileId=" + fileId + ", c=" + c + ']');
- IgniteInternalTx tx = id2InfoPrj.isLockedByThread(fileId) ? null : startTx();
+ IgniteInternalTx tx = startTx();
try {
// Lock file ID for this transaction.
@@ -1732,14 +1659,14 @@ public class IgfsMetaManager extends IgfsManager {
*/
boolean mkdirs(final IgfsPath path, final Map<String, String> props) throws IgniteCheckedException {
assert props != null;
- assert validTxState(false);
+ validTxState(false);
DirectoryChainBuilder b = null;
while (true) {
if (busyLock.enterBusy()) {
try {
- b = new DirectoryChainBuilder(path, props, props);
+ b = new DirectoryChainBuilder(path, props);
// Start TX.
IgniteInternalTx tx = startTx();
@@ -1873,6 +1800,106 @@ public class IgfsMetaManager extends IgfsManager {
}
/**
+ * Put new entry to meta cache immediately linking it to parent.
+ *
+ * @param info Info to put.
+ * @param parentId Parent ID.
+ * @param name Name in parent.
+ * @throws IgniteCheckedException If failed.
+ */
+ private void createNewEntry(IgfsFileInfo info, IgniteUuid parentId, String name) throws IgniteCheckedException {
+ validTxState(true);
+
+ if (!id2InfoPrj.putIfAbsent(info.id(), info))
+ throw fsException("Failed to create new metadata entry due to ID conflict: " + info.id());
+
+ if (parentId != null)
+ id2InfoPrj.invoke(parentId, new ListingAdd(name, new IgfsListingEntry(info)));
+ }
+
+ /**
+ * Transfer entry from one directory to another.
+ *
+ * @param entry Entry to be transfered.
+ * @param srcId Source ID.
+ * @param srcName Source name.
+ * @param destId Destination ID.
+ * @param destName Destination name.
+ * @throws IgniteCheckedException If failed.
+ */
+ private void transferEntry(IgfsListingEntry entry, IgniteUuid srcId, String srcName,
+ IgniteUuid destId, String destName) throws IgniteCheckedException {
+ validTxState(true);
+
+ id2InfoPrj.invoke(srcId, new ListingRemove(srcName, entry.fileId()));
+ id2InfoPrj.invoke(destId, new ListingAdd(destName, entry));
+ }
+
+ /**
+ * 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 path update processor.
+ *
+ * @param id File ID.
+ * @param path Path to be updated.
+ * @throws IgniteCheckedException If failed.
+ */
+ private void invokeUpdatePath(IgniteUuid id, IgfsPath path) throws IgniteCheckedException {
+ validTxState(true);
+
+ id2InfoPrj.invoke(id, new UpdatePath(path));
+ }
+
+ /**
+ * 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 {
+ validTxState(true);
+
+ id2InfoPrj.invoke(id, proc);
+
+ return getInfo(id);
+ }
+
+ /**
+ * Get info.
+ *
+ * @param id ID.
+ * @return Info.
+ * @throws IgniteCheckedException If failed.
+ */
+ @Nullable private IgfsFileInfo getInfo(IgniteUuid id) throws IgniteCheckedException {
+ return id2InfoPrj.get(id);
+ }
+
+ /**
+ * Get several infos.
+ *
+ * @param ids IDs.
+ * @return Infos map.
+ * @throws IgniteCheckedException If failed.
+ */
+ private Map<IgniteUuid, IgfsFileInfo> getInfos(Collection<IgniteUuid> ids) throws IgniteCheckedException {
+ return id2InfoPrj.getAll(ids);
+ }
+
+ /**
* Create the file in DUAL mode.
*
* @param fs File system.
@@ -1913,7 +1940,7 @@ public class IgfsMetaManager extends IgfsManager {
@Override public IgfsSecondaryOutputStreamDescriptor onSuccess(Map<IgfsPath,
IgfsFileInfo> infos) throws Exception {
- assert validTxState(true);
+ validTxState(true);
assert !infos.isEmpty();
@@ -1983,12 +2010,10 @@ public class IgfsMetaManager extends IgfsManager {
path + ", fileId=" + oldId + ", lockId=" + oldInfo.lockId() + ']');
id2InfoPrj.remove(oldId); // Remove the old one.
- id2InfoPrj.put(newInfo.id(), newInfo); // Put the new one.
-
id2InfoPrj.invoke(parentInfo.id(),
new ListingRemove(path.name(), parentInfo.listing().get(path.name()).fileId()));
- id2InfoPrj.invoke(parentInfo.id(),
- new ListingAdd(path.name(), new IgfsListingEntry(newInfo)));
+
+ createNewEntry(newInfo, parentInfo.id(), path.name()); // Put new one.
IgniteInternalFuture<?> delFut = igfsCtx.data().delete(oldInfo);
}
@@ -2052,7 +2077,7 @@ public class IgfsMetaManager extends IgfsManager {
@Override public IgfsSecondaryOutputStreamDescriptor onSuccess(Map<IgfsPath,
IgfsFileInfo> infos) throws Exception {
- assert validTxState(true);
+ validTxState(true);
final IgfsFileInfo info = infos.get(path);
@@ -2087,11 +2112,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);
@@ -2453,7 +2474,7 @@ public class IgfsMetaManager extends IgfsManager {
}
// Update the deleted file info with path information for delete worker.
- id2InfoPrj.invoke(info.id(), new UpdatePath(path));
+ invokeUpdatePath(info.id(), path);
return true; // No additional handling is required.
}
@@ -2505,12 +2526,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 {
@@ -2865,7 +2881,7 @@ public class IgfsMetaManager extends IgfsManager {
*/
private <K, V> boolean putx(IgniteInternalCache<K, V> cache, K key, IgniteClosure<V, V> c)
throws IgniteCheckedException {
- assert validTxState(true);
+ validTxState(true);
V oldVal = cache.get(key);
V newVal = c.apply(oldVal);
@@ -2877,16 +2893,10 @@ public class IgfsMetaManager extends IgfsManager {
* Check transaction is (not) started.
*
* @param inTx Expected transaction state.
- * @return Transaction state is correct.
*/
- private boolean validTxState(boolean inTx) {
- boolean txState = inTx == (id2InfoPrj.tx() != null);
-
- assert txState : (inTx ? "Method cannot be called outside transaction " :
- "Method cannot be called in transaction ") + "[tx=" + id2InfoPrj.tx() + ", threadId=" +
- Thread.currentThread().getId() + ']';
-
- return txState;
+ private void validTxState(boolean inTx) {
+ assert (inTx && id2InfoPrj.tx() != null) || (!inTx && id2InfoPrj.tx() == null) :
+ "Invalid TX state [expected=" + inTx + ", actual=" + (id2InfoPrj.tx() != null) + ']';
}
/**
@@ -2912,7 +2922,7 @@ public class IgfsMetaManager extends IgfsManager {
long modificationTime) throws IgniteCheckedException {
if (busyLock.enterBusy()) {
try {
- assert validTxState(false);
+ validTxState(false);
// Start pessimistic transaction.
IgniteInternalTx tx = startTx();
@@ -3310,7 +3320,8 @@ public class IgfsMetaManager extends IgfsManager {
final @Nullable IgniteUuid affKey,
final boolean evictExclude,
@Nullable Map<String, String> fileProps) throws IgniteCheckedException {
- assert validTxState(false);
+ validTxState(false);
+
assert path != null;
final String name = path.name();
@@ -3322,15 +3333,7 @@ public class IgfsMetaManager extends IgfsManager {
while (true) {
if (busyLock.enterBusy()) {
try {
- b = new DirectoryChainBuilder(path, dirProps, fileProps) {
- /** {@inheritDoc} */
- @Override protected IgfsFileInfo buildLeaf() {
- long t = System.currentTimeMillis();
-
- return new IgfsFileInfo(blockSize, 0L, affKey, createFileLockId(false),
- evictExclude, leafProps, t, t);
- }
- };
+ b = new DirectoryChainBuilder(path, dirProps, fileProps, blockSize, affKey, evictExclude);
// Start Tx:
IgniteInternalTx tx = startTx();
@@ -3377,18 +3380,7 @@ public class IgfsMetaManager extends IgfsManager {
+ "[fileName=" + name + ", fileId=" + lowermostExistingInfo.id()
+ ", lockId=" + lockId + ']');
- IgniteUuid newLockId = createFileLockId(false);
-
- EntryProcessorResult<IgfsFileInfo> result
- = id2InfoPrj.invoke(lowermostExistingInfo.id(),
- new LockFileProcessor(newLockId));
-
- IgfsFileInfo lockedInfo = result.get();
-
- 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);
@@ -3411,15 +3403,12 @@ public class IgfsMetaManager extends IgfsManager {
assert deletedEntry != null;
- id2InfoPrj.invoke(parentId, new ListingRemove(name, deletedEntry.fileId()));
-
- // Add listing entry into the destination parent listing.
- id2InfoPrj.invoke(trashId,
- new ListingAdd(lowermostExistingInfo.id().toString(), deletedEntry));
+ transferEntry(deletedEntry, parentId, name, trashId,
+ lowermostExistingInfo.id().toString());
// Update a file info of the removed file with a file path,
// which will be used by delete worker for event notifications.
- id2InfoPrj.invoke(lowermostExistingInfo.id(), new UpdatePath(path));
+ invokeUpdatePath(lowermostExistingInfo.id(), path);
// Make a new locked info:
long t = System.currentTimeMillis();
@@ -3429,12 +3418,7 @@ public class IgfsMetaManager extends IgfsManager {
assert newFileInfo.lockId() != null; // locked info should be created.
- boolean put = id2InfoPrj.putIfAbsent(newFileInfo.id(), newFileInfo);
-
- assert put;
-
- id2InfoPrj.invoke(parentId,
- new ListingAdd(name, new IgfsListingEntry(newFileInfo)));
+ createNewEntry(newFileInfo, parentId, name);
IgniteBiTuple<IgfsFileInfo, IgniteUuid> t2 = new T2<>(newFileInfo, parentId);
@@ -3497,54 +3481,103 @@ public class IgfsMetaManager extends IgfsManager {
/** File chain builder. */
private class DirectoryChainBuilder {
/** The requested path to be created. */
- protected final IgfsPath path;
+ private final IgfsPath path;
/** Full path components. */
- protected final List<String> components;
+ private final List<String> components;
/** The list of ids. */
- protected final List<IgniteUuid> idList;
+ private final List<IgniteUuid> idList;
/** The set of ids. */
- protected final SortedSet<IgniteUuid> idSet;
+ private final SortedSet<IgniteUuid> idSet = new TreeSet<IgniteUuid>(PATH_ID_SORTING_COMPARATOR);
/** The middle node properties. */
- protected final Map<String, String> middleProps;
+ private final Map<String, String> middleProps;
/** The leaf node properties. */
- protected final Map<String, String> leafProps;
+ private final Map<String, String> leafProps;
/** The lowermost exsiting path id. */
- protected final IgniteUuid lowermostExistingId;
+ private final IgniteUuid lowermostExistingId;
/** The existing path. */
- protected final IgfsPath existingPath;
+ private final IgfsPath existingPath;
/** The created leaf info. */
- protected IgfsFileInfo leafInfo;
+ private IgfsFileInfo leafInfo;
/** The leaf parent id. */
- protected IgniteUuid leafParentId;
+ private IgniteUuid leafParentId;
/** The number of existing ids. */
- protected final int existingIdCnt;
+ private final int existingIdCnt;
+
+ /** Whether laef is directory. */
+ private final boolean leafDir;
+
+ /** Block size. */
+ private final int blockSize;
+
+ /** Affinity key. */
+ private final IgniteUuid affKey;
+
+ /** Evict exclude flag. */
+ private final boolean evictExclude;
/**
- * Creates the builder and performa all the initial calculations.
+ * Constructor for directories.
+ *
+ * @param path Path.
+ * @param props Properties.
+ * @throws IgniteCheckedException If failed.
*/
- protected DirectoryChainBuilder(IgfsPath path,
- Map<String,String> middleProps, Map<String,String> leafProps) throws IgniteCheckedException {
- this.path = path;
+ protected DirectoryChainBuilder(IgfsPath path, Map<String, String> props) throws IgniteCheckedException {
+ this(path, props, props, true, 0, null, false);
+ }
- this.components = path.components();
+ /**
+ * Constructor for files.
+ *
+ * @param path Path.
+ * @param dirProps Directory properties.
+ * @param fileProps File properties.
+ * @param blockSize Block size.
+ * @param affKey Affinity key (optional).
+ * @param evictExclude Evict exclude flag.
+ * @throws IgniteCheckedException If failed.
+ */
+ protected DirectoryChainBuilder(IgfsPath path, Map<String, String> dirProps, Map<String, String> fileProps,
+ int blockSize, @Nullable IgniteUuid affKey, boolean evictExclude)
+ throws IgniteCheckedException {
+ this(path, dirProps, fileProps, false, blockSize, affKey, evictExclude);
+ }
+ /**
+ * Constructor.
+ *
+ * @param path Path.
+ * @param middleProps Middle properties.
+ * @param leafProps Leaf properties.
+ * @param leafDir Whether leaf is directory or file.
+ * @param blockSize Block size.
+ * @param affKey Affinity key (optional).
+ * @param evictExclude Evict exclude flag.
+ * @throws IgniteCheckedException If failed.
+ */
+ private DirectoryChainBuilder(IgfsPath path, Map<String,String> middleProps, Map<String,String> leafProps,
+ boolean leafDir, int blockSize, @Nullable IgniteUuid affKey, boolean evictExclude)
+ throws IgniteCheckedException {
+ this.path = path;
+ this.components = path.components();
this.idList = fileIds(path);
-
- this.idSet = new TreeSet<IgniteUuid>(PATH_ID_SORTING_COMPARATOR);
-
this.middleProps = middleProps;
-
this.leafProps = leafProps;
+ this.leafDir = leafDir;
+ this.blockSize = blockSize;
+ this.affKey = affKey;
+ this.evictExclude = evictExclude;
+
// Store all the non-null ids in the set & construct existing path in one loop:
IgfsPath existingPath = path.root();
@@ -3555,7 +3588,7 @@ public class IgfsMetaManager extends IgfsManager {
int idIdx = 0;
- for (IgniteUuid id: idList) {
+ for (IgniteUuid id : idList) {
if (id == null)
break;
@@ -3581,33 +3614,6 @@ public class IgfsMetaManager extends IgfsManager {
}
/**
- * Builds middle nodes.
- */
- protected IgfsFileInfo buildMiddleNode(String childName, IgfsFileInfo childInfo) {
- return new IgfsFileInfo(Collections.singletonMap(childName,
- new IgfsListingEntry(childInfo)), middleProps);
- }
-
- /**
- * Builds leaf.
- */
- protected IgfsFileInfo buildLeaf() {
- long t = System.currentTimeMillis();
-
- return new IgfsFileInfo(true, leafProps, t, t);
- }
-
- /**
- * Links newly created chain to existing parent.
- */
- final void linkBuiltChainToExistingParent(String childName, IgfsFileInfo childInfo)
- throws IgniteCheckedException {
- assert childInfo != null;
-
- id2InfoPrj.invoke(lowermostExistingId, new ListingAdd(childName, new IgfsListingEntry(childInfo)));
- }
-
- /**
* Does the main portion of job building the renmaining path.
*/
public final void doBuild() throws IgniteCheckedException {
@@ -3615,7 +3621,8 @@ public class IgfsMetaManager extends IgfsManager {
String childName = null;
- IgfsFileInfo newLeafInfo;
+ IgfsFileInfo newInfo;
+
IgniteUuid parentId = null;
// This loop creates the missing directory chain from the bottom to the top:
@@ -3625,28 +3632,29 @@ public class IgfsMetaManager extends IgfsManager {
if (childName == null) {
assert childInfo == null;
- newLeafInfo = buildLeaf();
+ long t = System.currentTimeMillis();
- assert newLeafInfo != null;
+ if (leafDir)
+ newInfo = new IgfsFileInfo(true, leafProps, t, t);
+ else
+ newInfo = new IgfsFileInfo(blockSize, 0L, affKey, createFileLockId(false), evictExclude,
+ leafProps, t, t);
- leafInfo = newLeafInfo;
+ leafInfo = newInfo;
}
else {
assert childInfo != null;
- newLeafInfo = buildMiddleNode(childName, childInfo);
-
- assert newLeafInfo != null;
+ newInfo = new IgfsFileInfo(Collections.singletonMap(childName,
+ new IgfsListingEntry(childInfo)), middleProps);
if (parentId == null)
- parentId = newLeafInfo.id();
+ parentId = newInfo.id();
}
- boolean put = id2InfoPrj.putIfAbsent(newLeafInfo.id(), newLeafInfo);
+ id2InfoPrj.put(newInfo.id(), newInfo);
- assert put; // Because we used a new id that should be unique.
-
- childInfo = newLeafInfo;
+ childInfo = newInfo;
childName = components.get(i);
}
@@ -3657,7 +3665,7 @@ public class IgfsMetaManager extends IgfsManager {
leafParentId = parentId;
// Now link the newly created directory chain to the lowermost existing parent:
- linkBuiltChainToExistingParent(childName, childInfo);
+ id2InfoPrj.invoke(lowermostExistingId, new ListingAdd(childName, new IgfsListingEntry(childInfo)));
}
/**
@@ -3674,7 +3682,7 @@ public class IgfsMetaManager extends IgfsManager {
}
}
- if (leafInfo.isDirectory())
+ if (leafDir)
IgfsUtils.sendEvents(igfsCtx.kernalContext(), path, EVT_IGFS_DIR_CREATED);
else {
IgfsUtils.sendEvents(igfsCtx.kernalContext(), path, EVT_IGFS_FILE_CREATED);
@@ -3684,66 +3692,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 {
@@ -3902,6 +3850,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>,
http://git-wip-us.apache.org/repos/asf/ignite/blob/dda1f0ed/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManagerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManagerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManagerSelfTest.java
index f3d35f4..72a2bee 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManagerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/igfs/IgfsMetaManagerSelfTest.java
@@ -171,33 +171,30 @@ public class IgfsMetaManagerSelfTest extends IgfsCommonAbstractTest {
assertNull("Unexpected stored properties: " + info, info.properties().get(key1));
assertNull("Unexpected stored properties: " + info, info.properties().get(key2));
- info = mgr.updateProperties(ROOT_ID, fileId, fileName, F.asMap(key1, "1"));
+ info = mgr.updateProperties(fileId, F.asMap(key1, "1"));
assertEquals("Unexpected stored properties: " + info, "1", info.properties().get(key1));
- info = mgr.updateProperties(ROOT_ID, fileId, fileName, F.asMap(key2, "2"));
+ info = mgr.updateProperties(fileId, F.asMap(key2, "2"));
// assertEquals("Unexpected stored properties: " + info, F.asMap(key1, "1", key2, "2"), info.properties());
assertEquals("Unexpected stored properties: " + info, "1", info.properties().get(key1));
assertEquals("Unexpected stored properties: " + info, "2", info.properties().get(key2));
- info = mgr.updateProperties(ROOT_ID, fileId, fileName, F.<String, String>asMap(key1, null));
+ info = mgr.updateProperties(fileId, F.<String, String>asMap(key1, null));
assertEquals("Unexpected stored properties: " + info, "2", info.properties().get(key2));
- info = mgr.updateProperties(ROOT_ID, fileId, fileName, F.<String, String>asMap(key2, null));
+ info = mgr.updateProperties(fileId, F.<String, String>asMap(key2, null));
assertNull("Unexpected stored properties: " + info, info.properties().get(key1));
assertNull("Unexpected stored properties: " + info, info.properties().get(key2));
-
- assertNull(mgr.updateProperties(ROOT_ID, fileId, "not_exists", F.<String, String>asMap(key2, null)));
}
mgr.softDelete(new IgfsPath("/dir"), true);
mgr.softDelete(new IgfsPath("/file"), false);
- assertNull(mgr.updateProperties(ROOT_ID, dir.id(), "dir", F.asMap("p", "7")));
- assertNull(mgr.updateProperties(ROOT_ID, file.id(), "file", F.asMap("q", "8")));
+ assertNull(mgr.updateProperties(dir.id(), F.asMap("p", "7")));
}
private IgfsFileInfo mkdirsAndGetInfo(String path) throws IgniteCheckedException {
@@ -309,8 +306,8 @@ public class IgfsMetaManagerSelfTest extends IgfsCommonAbstractTest {
expectsRenameFail("/a/k", "/a/b/", "Failed to perform move because destination already " +
"contains entry with the same name existing file");
- mgr.delete(a.id(), "k", k.id());
- mgr.delete(b.id(), "k", z.id());
+ mgr.delete(a.id(), "k", z.id());
+ mgr.delete(b.id(), "k", k.id());
System.out.println("/: " + mgr.directoryListing(ROOT_ID));
System.out.println("a: " + mgr.directoryListing(a.id()));
@@ -339,9 +336,7 @@ public class IgfsMetaManagerSelfTest extends IgfsCommonAbstractTest {
assertEquals(F.asMap("a", new IgfsListingEntry(a), "f1", new IgfsListingEntry(f1)),
mgr.directoryListing(ROOT_ID));
- assertEquals(
- F.asMap("b", new IgfsListingEntry(b),
- "f2", new IgfsListingEntry(f2)),
+ assertEquals(F.asMap("b", new IgfsListingEntry(b), "f2", new IgfsListingEntry(f2)),
mgr.directoryListing(a.id()));
assertEmpty(mgr.directoryListing(b.id()));
@@ -423,7 +418,7 @@ public class IgfsMetaManagerSelfTest extends IgfsCommonAbstractTest {
Class<? extends Throwable> cls, @Nullable String msg) {
assertThrows(log, new Callable() {
@Override public Object call() throws Exception {
- return mgr.updateProperties(null, fileId, "file", props);
+ return mgr.updateProperties(fileId, props);
}
}, cls, msg);
}
[5/8] ignite git commit: IGNITE-2765 WebSessionFilter doesn't survive
client reconnect Test fixes.
Posted by vo...@apache.org.
IGNITE-2765 WebSessionFilter doesn't survive client reconnect
Test fixes.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/843b2869
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/843b2869
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/843b2869
Branch: refs/heads/ignite-1786
Commit: 843b2869d5b5663fd000aa0ac6320de87d776fb3
Parents: ad6bbd9
Author: Anton Vinogradov <av...@apache.org>
Authored: Wed Mar 16 13:07:50 2016 +0300
Committer: Anton Vinogradov <av...@apache.org>
Committed: Wed Mar 16 13:09:05 2016 +0300
----------------------------------------------------------------------
.../internal/websession/IgniteWebSessionSelfTestSuite.java | 5 +++++
1 file changed, 5 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/843b2869/modules/web/src/test/java/org/apache/ignite/internal/websession/IgniteWebSessionSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/web/src/test/java/org/apache/ignite/internal/websession/IgniteWebSessionSelfTestSuite.java b/modules/web/src/test/java/org/apache/ignite/internal/websession/IgniteWebSessionSelfTestSuite.java
index c69b019..2e47262 100644
--- a/modules/web/src/test/java/org/apache/ignite/internal/websession/IgniteWebSessionSelfTestSuite.java
+++ b/modules/web/src/test/java/org/apache/ignite/internal/websession/IgniteWebSessionSelfTestSuite.java
@@ -62,6 +62,11 @@ public class IgniteWebSessionSelfTestSuite extends TestSuite {
@Override public void testInvalidatedSession() throws Exception {
fail("https://issues.apache.org/jira/browse/IGNITE-810");
}
+
+ /** {@inheritDoc} */
+ @Override public void testClientReconnectRequest() throws Exception {
+ fail("https://issues.apache.org/jira/browse/IGNITE-810");
+ }
}
/**
[8/8] ignite git commit: Merge branch 'master' into ignite-1786
Posted by vo...@apache.org.
Merge branch 'master' into ignite-1786
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/f55b2dbc
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/f55b2dbc
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/f55b2dbc
Branch: refs/heads/ignite-1786
Commit: f55b2dbc11ad58a28e2d5c84a634aa31e3f3e21d
Parents: e2ae000 dfe5ea8
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Wed Mar 16 13:12:34 2016 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Wed Mar 16 13:12:34 2016 +0300
----------------------------------------------------------------------
.../processors/cache/GridCacheAdapter.java | 10 +-
.../processors/cache/GridCacheUtils.java | 14 +
.../transactions/IgniteTransactionsImpl.java | 9 +-
.../internal/processors/igfs/IgfsFileImpl.java | 29 -
.../internal/processors/igfs/IgfsFileInfo.java | 51 +-
.../internal/processors/igfs/IgfsImpl.java | 12 +-
.../processors/igfs/IgfsListingEntry.java | 134 +--
.../processors/igfs/IgfsMetaManager.java | 994 ++++++++++---------
.../processors/igfs/IgfsOutputStreamImpl.java | 2 -
.../utils/PlatformConfigurationUtils.java | 4 +
.../cache/IgniteTxConfigCacheSelfTest.java | 249 +++++
.../igfs/IgfsMetaManagerSelfTest.java | 23 +-
.../ignite/testsuites/IgniteCacheTestSuite.java | 2 +
.../hadoop/cache/HadoopTxConfigCacheTest.java | 42 +
.../testsuites/IgniteHadoopTestSuite.java | 3 +
.../Apache.Ignite.Core.Tests.csproj | 1 +
.../Cache/CacheConfigurationTest.cs | 5 +-
.../Cache/Store/CacheStoreTest.cs | 5 +-
.../Cache/Store/CacheStoreTestCodeConfig.cs | 106 ++
.../IgniteConfigurationSerializerTest.cs | 4 +-
.../Cache/Configuration/CacheConfiguration.cs | 36 +
.../IgniteConfigurationSection.xsd | 2 +
.../IgniteWebSessionSelfTestSuite.java | 5 +
23 files changed, 1088 insertions(+), 654 deletions(-)
----------------------------------------------------------------------