You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by mr...@apache.org on 2015/06/09 13:08:25 UTC
svn commit: r1684378 - in /jackrabbit/oak/branches/1.2: ./
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/
oak-core/src/main/java/org/apache/jackrabbi...
Author: mreutegg
Date: Tue Jun 9 11:08:25 2015
New Revision: 1684378
URL: http://svn.apache.org/r1684378
Log:
OAK-2685: Track root state revision when reading the tree
Merged revisions 1677804 and 1677806 from trunk
Added:
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/TieredDiffCache.java
- copied unchanged from r1677806, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/TieredDiffCache.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKey.java
- copied unchanged from r1677806, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKey.java
jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKeyTest.java
- copied unchanged from r1677806, jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/util/RevisionsKeyTest.java
Removed:
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ContentChangeInfo.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/ContentChangeInfoProvider.java
Modified:
jackrabbit/oak/branches/1.2/ (props changed)
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DiffCache.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LocalDiffCache.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCache.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheType.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/StringValue.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventGenerator.java
jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/NodeObserver.java
jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java
jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AmnesiaDiffCache.java
jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreDiffTest.java
jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/LocalDiffCacheTest.java
jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MeasureMemory.java
jackrabbit/oak/branches/1.2/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventQueue.java
Propchange: jackrabbit/oak/branches/1.2/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Jun 9 11:08:25 2015
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677939,1677991,1678173,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679235,1679958,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680805-1680806,1680903,1681282,1681767,1681918,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683089,1683213,1683249,1683278,1683323,1683687,1684174-1684175
+/jackrabbit/oak/trunk:1672350,1672468,1672537,1672603,1672642,1672644,1672834-1672835,1673351,1673410,1673414,1673436,1673644,1673662-1673664,1673669,1673695,1673738,1673787,1673791,1674046,1674065,1674075,1674107,1674228,1674780,1674880,1675054-1675055,1675319,1675332,1675354,1675357,1675382,1675555,1675566,1675593,1676198,1676237,1676407,1676458,1676539,1676670,1676693,1676703,1676725,1677579,1677581,1677609,1677611,1677774,1677788,1677797,1677804,1677806,1677939,1677991,1678173,1678323,1678758,1678938,1678954,1679144,1679165,1679191,1679235,1679958,1680182,1680222,1680232,1680236,1680461,1680633,1680643,1680805-1680806,1680903,1681282,1681767,1681918,1682218,1682235,1682437,1682494,1682555,1682855,1682904,1683089,1683213,1683249,1683278,1683323,1683687,1684174-1684175
/jackrabbit/trunk:1345480
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/Commit.java Tue Jun 9 11:08:25 2015
@@ -569,7 +569,7 @@ public class Commit {
}
list.add(p);
}
- DiffCache.Entry cacheEntry = nodeStore.getLocalDiffCache().newEntry(before, revision);
+ DiffCache.Entry cacheEntry = nodeStore.getDiffCache().newEntry(before, revision);
LastRevTracker tracker = nodeStore.createTracker(revision, isBranchCommit);
List<String> added = new ArrayList<String>();
List<String> removed = new ArrayList<String>();
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DiffCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DiffCache.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DiffCache.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DiffCache.java Tue Jun 9 11:08:25 2015
@@ -20,6 +20,8 @@ import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.apache.jackrabbit.oak.cache.CacheStats;
+
/**
* A cache for child node diffs.
*/
@@ -60,7 +62,13 @@ public interface DiffCache {
Entry newEntry(@Nonnull Revision from,
@Nonnull Revision to);
- public interface Entry {
+ /**
+ * @return the statistics for this cache.
+ */
+ @Nonnull
+ Iterable<CacheStats> getStats();
+
+ interface Entry {
/**
* Appends changes about children of the node at the given path.
@@ -81,7 +89,7 @@ public interface DiffCache {
boolean done();
}
- public interface Loader {
+ interface Loader {
String call();
}
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentMK.java Tue Jun 9 11:08:25 2015
@@ -45,7 +45,6 @@ import org.apache.jackrabbit.oak.commons
import org.apache.jackrabbit.oak.plugins.document.DocumentNodeState.Children;
import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoBlobStore;
-import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDiffCache;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoVersionGCSupport;
import org.apache.jackrabbit.oak.plugins.document.persistentCache.CacheType;
@@ -53,6 +52,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore;
import org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore;
import org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions;
+import org.apache.jackrabbit.oak.plugins.document.util.RevisionsKey;
import org.apache.jackrabbit.oak.plugins.document.util.StringValue;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
import org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore;
@@ -512,13 +512,11 @@ public class DocumentMK implements Micro
private DocumentNodeStore nodeStore;
private DocumentStore documentStore;
private DiffCache diffCache;
- private LocalDiffCache localDiffCache;
private BlobStore blobStore;
private int clusterId = Integer.getInteger("oak.documentMK.clusterId", 0);
private int asyncDelay = 1000;
private boolean timing;
private boolean logging;
- private boolean disableLocalDiffCache = Boolean.getBoolean("oak.documentMK.disableLocalDiffCache");
private Weigher<CacheValue, CacheValue> weigher = new EmpiricalWeigher();
private long memoryCacheSize = DEFAULT_MEMORY_CACHE_SIZE;
private int nodeCachePercentage = DEFAULT_NODE_CACHE_PERCENTAGE;
@@ -562,10 +560,6 @@ public class DocumentMK implements Micro
}
this.blobStore = s;
}
-
- if (this.diffCache == null) {
- this.diffCache = new MongoDiffCache(db, changesSizeMB, this);
- }
}
return this;
}
@@ -681,23 +675,11 @@ public class DocumentMK implements Micro
public DiffCache getDiffCache() {
if (diffCache == null) {
- diffCache = new MemoryDiffCache(this);
+ diffCache = new TieredDiffCache(this);
}
return diffCache;
}
- public LocalDiffCache getLocalDiffCache() {
- if (localDiffCache == null && !disableLocalDiffCache) {
- localDiffCache = new LocalDiffCache(this);
- }
- return localDiffCache;
- }
-
- public Builder setDisableLocalDiffCache(boolean disableLocalDiffCache) {
- this.disableLocalDiffCache = disableLocalDiffCache;
- return this;
- }
-
public Builder setDiffCache(DiffCache diffCache) {
this.diffCache = diffCache;
return this;
@@ -815,6 +797,14 @@ public class DocumentMK implements Micro
return memoryCacheSize * diffCachePercentage / 100;
}
+ public long getMemoryDiffCacheSize() {
+ return getDiffCacheSize() / 2;
+ }
+
+ public long getLocalDiffCacheSize() {
+ return getDiffCacheSize() / 2;
+ }
+
public Builder setUseSimpleRevision(boolean useSimpleRevision) {
this.useSimpleRevision = useSimpleRevision;
return this;
@@ -915,12 +905,12 @@ public class DocumentMK implements Micro
return buildCache(CacheType.DOC_CHILDREN, getDocChildrenCacheSize(), null, null);
}
- public Cache<PathRev, StringValue> buildDiffCache() {
- return buildCache(CacheType.DIFF, getDiffCacheSize(), null, null);
+ public Cache<PathRev, StringValue> buildMemoryDiffCache() {
+ return buildCache(CacheType.DIFF, getMemoryDiffCacheSize(), null, null);
}
- public Cache<StringValue, LocalDiffCache.ConsolidatedDiff> buildConsolidatedDiffCache() {
- return buildCache(CacheType.CONSOLIDATED_DIFF, getDiffCacheSize(), null, null);
+ public Cache<RevisionsKey, LocalDiffCache.Diff> buildLocalDiffCache() {
+ return buildCache(CacheType.LOCAL_DIFF, getLocalDiffCacheSize(), null, null);
}
public Cache<CacheValue, NodeDocument> buildDocumentCache(DocumentStore docStore) {
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeState.java Tue Jun 9 11:08:25 2015
@@ -54,7 +54,6 @@ import org.slf4j.LoggerFactory;
import com.google.common.base.Function;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
-import com.google.common.collect.Maps;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
@@ -82,29 +81,80 @@ public class DocumentNodeState extends A
final String path;
final Revision rev;
- final Map<String, PropertyState> properties = Maps.newHashMap();
Revision lastRevision;
+ final Revision rootRevision;
+ final Map<String, PropertyState> properties;
final boolean hasChildren;
private final DocumentNodeStore store;
- DocumentNodeState(@Nonnull DocumentNodeStore store, @Nonnull String path,
+ DocumentNodeState(@Nonnull DocumentNodeStore store,
+ @Nonnull String path,
@Nonnull Revision rev) {
this(store, path, rev, false);
}
DocumentNodeState(@Nonnull DocumentNodeStore store, @Nonnull String path,
@Nonnull Revision rev, boolean hasChildren) {
+ this(store, path, rev, new HashMap<String, PropertyState>(),
+ hasChildren, null, null);
+ }
+
+ private DocumentNodeState(@Nonnull DocumentNodeStore store,
+ @Nonnull String path,
+ @Nonnull Revision rev,
+ @Nonnull Map<String, PropertyState> properties,
+ boolean hasChildren,
+ @Nullable Revision lastRevision,
+ @Nullable Revision rootRevision) {
this.store = checkNotNull(store);
this.path = checkNotNull(path);
this.rev = checkNotNull(rev);
+ this.lastRevision = lastRevision;
+ this.rootRevision = rootRevision != null ? rootRevision : rev;
this.hasChildren = hasChildren;
+ this.properties = checkNotNull(properties);
+ }
+
+ /**
+ * Creates a copy of this {@code DocumentNodeState} with the
+ * {@link #rootRevision} set to the given {@code root} revision. This method
+ * returns {@code this} instance if the given {@code root} revision is
+ * the same as the one in this instance.
+ *
+ * @param root the root revision for the copy of this node state.
+ * @return a copy of this node state with the given root revision.
+ */
+ DocumentNodeState withRootRevision(@Nonnull Revision root) {
+ if (rootRevision.equals(root)) {
+ return this;
+ } else {
+ return new DocumentNodeState(store, path, rev, properties,
+ hasChildren, lastRevision, root);
+ }
}
+ @Nonnull
Revision getRevision() {
return rev;
}
+ /**
+ * Returns the root revision for this node state. This is the read revision
+ * passed from the parent node state. This revision therefore reflects the
+ * revision of the root node state where the traversal down the tree
+ * started. The returned revision is only maintained on a best effort basis
+ * and may be the same as {@link #getRevision()} if this node state is
+ * retrieved directly from the {@code DocumentNodeStore}.
+ *
+ * @return the revision of the root node state is available, otherwise the
+ * same value as returned by {@link #getRevision()}.
+ */
+ @Nonnull
+ Revision getRootRevision() {
+ return rootRevision;
+ }
+
//--------------------------< NodeState >-----------------------------------
@Override
@@ -168,7 +218,18 @@ public class DocumentNodeState extends A
@Nonnull
@Override
public NodeState getChildNode(@Nonnull String name) {
- return getChildNode(name, lastRevision);
+ if (!hasChildren) {
+ checkValidName(name);
+ return EmptyNodeState.MISSING_NODE;
+ }
+ String p = PathUtils.concat(getPath(), name);
+ DocumentNodeState child = store.getNode(p, lastRevision);
+ if (child == null) {
+ checkValidName(name);
+ return EmptyNodeState.MISSING_NODE;
+ } else {
+ return child.withRootRevision(rootRevision);
+ }
}
@Override
@@ -271,23 +332,6 @@ public class DocumentNodeState extends A
return super.compareAgainstBaseState(base, diff);
}
- @Nonnull
- NodeState getChildNode(@Nonnull String name,
- @Nonnull Revision revision) {
- if (!hasChildren) {
- checkValidName(name);
- return EmptyNodeState.MISSING_NODE;
- }
- String p = PathUtils.concat(getPath(), name);
- DocumentNodeState child = store.getNode(p, checkNotNull(revision));
- if (child == null) {
- checkValidName(name);
- return EmptyNodeState.MISSING_NODE;
- } else {
- return child;
- }
- }
-
void setProperty(String propertyName, String value) {
if (value == null) {
properties.remove(propertyName);
@@ -379,7 +423,7 @@ public class DocumentNodeState extends A
@Override
public int getMemory() {
- int size = 180 + path.length() * 2;
+ int size = 212 + path.length() * 2;
// rough approximation for properties
for (Map.Entry<String, PropertyState> entry : properties.entrySet()) {
// name
@@ -442,7 +486,7 @@ public class DocumentNodeState extends A
@Nonnull
@Override
public NodeState getNodeState() {
- return input;
+ return input.withRootRevision(rootRevision);
}
};
}
@@ -529,9 +573,12 @@ public class DocumentNodeState extends A
@Override
public int getMemory() {
if (cachedMemory == 0) {
- int size = 114;
- for (String c : children) {
- size += c.length() * 2 + 56;
+ int size = 48;
+ if (!children.isEmpty()) {
+ size = 114;
+ for (String c : children) {
+ size += c.length() * 2 + 56;
+ }
}
cachedMemory = size;
}
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStore.java Tue Jun 9 11:08:25 2015
@@ -81,8 +81,6 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoBlobReferenceIterator;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
import org.apache.jackrabbit.oak.plugins.document.persistentCache.PersistentCache;
-import org.apache.jackrabbit.oak.plugins.observation.ContentChangeInfo;
-import org.apache.jackrabbit.oak.plugins.observation.ContentChangeInfoProvider;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
import org.apache.jackrabbit.oak.commons.json.JsopStream;
import org.apache.jackrabbit.oak.commons.json.JsopWriter;
@@ -321,8 +319,6 @@ public final class DocumentNodeStore
*/
private final DiffCache diffCache;
- private final LocalDiffCache localDiffCache;
-
/**
* The blob store.
*/
@@ -429,7 +425,6 @@ public final class DocumentNodeStore
builder.getWeigher(), builder.getDocChildrenCacheSize());
diffCache = builder.getDiffCache();
- localDiffCache = builder.getLocalDiffCache();
checkpoints = new Checkpoints(this);
// check if root node exists
@@ -696,6 +691,11 @@ public final class DocumentNodeStore
return docChildrenCacheStats;
}
+ @Nonnull
+ public Iterable<CacheStats> getDiffCacheStats() {
+ return diffCache.getStats();
+ }
+
void invalidateDocChildrenCache() {
docChildrenCache.invalidateAll();
}
@@ -1343,53 +1343,14 @@ public final class DocumentNodeStore
if (node.hasNoChildren() && base.hasNoChildren()) {
return true;
}
- String jsop = getJsopDiffIfLocalChange(diff, node);
-
- boolean useReadRevision = true;
- if (jsop == null) {
- // first lookup with read revisions of nodes and without loader
- jsop = diffCache.getChanges(base.getRevision(),
- node.getRevision(), node.getPath(), null);
- if (jsop == null) {
- useReadRevision = false;
- // fall back to last revisions with loader, this
- // guarantees we get a diff
- jsop = diffCache.getChanges(base.getLastRevision(),
- node.getLastRevision(), node.getPath(),
- new DiffCache.Loader() {
- @Override
- public String call() {
- return diffImpl(base, node);
- }
- });
- }
- }
- return dispatch(jsop, node, base, diff, useReadRevision);
- }
-
- @CheckForNull
- private String getJsopDiffIfLocalChange(NodeStateDiff diff, DocumentNodeState nodeState) {
- if (localDiffCache == null){
- //Local diff cache support not enabled
- return null;
- }
-
- if (diff instanceof ContentChangeInfoProvider){
- ContentChangeInfo info = ((ContentChangeInfoProvider) diff).getChangeInfo();
- if (info.isLocalChange() && info.getAfter() instanceof DocumentNodeState){
- DocumentNodeState rootAfterState = (DocumentNodeState) info.getAfter();
- DocumentNodeState rootBeforeState = (DocumentNodeState) info.getBefore();
- String jsopDiff = localDiffCache.getChanges(rootBeforeState.getRevision(),
- rootAfterState.getRevision(),
- nodeState.getPath(),
- null);
- if (jsopDiff != null){
- LOG.trace("Got diff from local cache for path {}", nodeState.getPath());
- return jsopDiff;
- }
- }
- }
- return null;
+ return dispatch(diffCache.getChanges(base.getRootRevision(),
+ node.getRootRevision(), node.getPath(),
+ new DiffCache.Loader() {
+ @Override
+ public String call() {
+ return diffImpl(base, node);
+ }
+ }), node, base, diff);
}
String diff(@Nonnull final String fromRevisionId,
@@ -1944,13 +1905,10 @@ public final class DocumentNodeStore
private boolean dispatch(@Nonnull String jsonDiff,
@Nonnull DocumentNodeState node,
@Nonnull DocumentNodeState base,
- @Nonnull NodeStateDiff diff,
- boolean useReadRevision) {
+ @Nonnull NodeStateDiff diff) {
if (jsonDiff.trim().isEmpty()) {
return true;
}
- Revision nodeRev = useReadRevision ? node.getRevision() : node.getLastRevision();
- Revision baseRev = useReadRevision ? base.getRevision() : base.getLastRevision();
JsopTokenizer t = new JsopTokenizer(jsonDiff);
boolean continueComparison = true;
while (continueComparison) {
@@ -1967,13 +1925,13 @@ public final class DocumentNodeStore
// skip properties
}
continueComparison = diff.childNodeAdded(name,
- node.getChildNode(name, nodeRev));
+ node.getChildNode(name));
break;
}
case '-': {
String name = unshareString(t.readString());
continueComparison = diff.childNodeDeleted(name,
- base.getChildNode(name, baseRev));
+ base.getChildNode(name));
break;
}
case '^': {
@@ -1982,8 +1940,8 @@ public final class DocumentNodeStore
if (t.matches('{')) {
t.read('}');
continueComparison = diff.childNodeChanged(name,
- base.getChildNode(name, baseRev),
- node.getChildNode(name, nodeRev));
+ base.getChildNode(name),
+ node.getChildNode(name));
} else if (t.matches('[')) {
// ignore multi valued property
while (t.read() != ']') {
@@ -2084,29 +2042,32 @@ public final class DocumentNodeStore
final long getChildrenDoneIn = debug ? now() : 0;
String diffAlgo;
+ Revision fromRev = from.getLastRevision();
+ Revision toRev = to.getLastRevision();
if (!fromChildren.hasMore && !toChildren.hasMore) {
diffAlgo = "diffFewChildren";
diffFewChildren(w, from.getPath(), fromChildren,
- from.getLastRevision(), toChildren, to.getLastRevision());
+ fromRev, toChildren, toRev);
} else {
if (FAST_DIFF) {
diffAlgo = "diffManyChildren";
- diffManyChildren(w, from.getPath(),
- from.getLastRevision(), to.getLastRevision());
+ fromRev = from.getRootRevision();
+ toRev = to.getRootRevision();
+ diffManyChildren(w, from.getPath(), fromRev, toRev);
} else {
diffAlgo = "diffAllChildren";
max = Integer.MAX_VALUE;
fromChildren = getChildren(from, null, max);
toChildren = getChildren(to, null, max);
diffFewChildren(w, from.getPath(), fromChildren,
- from.getLastRevision(), toChildren, to.getLastRevision());
+ fromRev, toChildren, toRev);
}
}
if (debug) {
long end = now();
LOG.debug("Diff performed via '{}' at [{}] between revisions [{}] => [{}] took {} ms ({} ms)",
- diffAlgo, from.getPath(), from.getLastRevision(), to.getLastRevision(),
+ diffAlgo, from.getPath(), fromRev, toRev,
end - start, getChildrenDoneIn - start);
}
return w.toString();
@@ -2501,13 +2462,6 @@ public final class DocumentNodeStore
return diffCache;
}
- public DiffCache getLocalDiffCache(){
- if (localDiffCache != null){
- return localDiffCache;
- }
- return diffCache;
- }
-
public Clock getClock() {
return clock;
}
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreService.java Tue Jun 9 11:08:25 2015
@@ -56,6 +56,7 @@ import org.apache.felix.scr.annotations.
import org.apache.felix.scr.annotations.ReferencePolicy;
import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean;
import org.apache.jackrabbit.oak.api.jmx.CheckpointMBean;
+import org.apache.jackrabbit.oak.cache.CacheStats;
import org.apache.jackrabbit.oak.commons.PropertiesUtil;
import org.apache.jackrabbit.oak.osgi.ObserverTracker;
import org.apache.jackrabbit.oak.osgi.OsgiWhiteboard;
@@ -543,6 +544,23 @@ public class DocumentNodeStoreService {
CacheStatsMBean.TYPE,
store.getDocChildrenCacheStats().getName())
);
+ for (CacheStats cs : store.getDiffCacheStats()) {
+ registrations.add(
+ registerMBean(whiteboard,
+ CacheStatsMBean.class, cs,
+ CacheStatsMBean.TYPE, cs.getName()));
+ }
+ DocumentStore ds = store.getDocumentStore();
+ if (ds.getCacheStats() != null) {
+ registrations.add(
+ registerMBean(whiteboard,
+ CacheStatsMBean.class,
+ ds.getCacheStats(),
+ CacheStatsMBean.TYPE,
+ ds.getCacheStats().getName())
+ );
+ }
+
registrations.add(
registerMBean(whiteboard,
CheckpointMBean.class,
@@ -559,39 +577,6 @@ public class DocumentNodeStoreService {
"Document node store management")
);
- DiffCache cl = store.getDiffCache();
- if (cl instanceof MemoryDiffCache) {
- MemoryDiffCache mcl = (MemoryDiffCache) cl;
- registrations.add(
- registerMBean(whiteboard,
- CacheStatsMBean.class,
- mcl.getDiffCacheStats(),
- CacheStatsMBean.TYPE,
- mcl.getDiffCacheStats().getName()));
- }
-
- DiffCache localCache = store.getLocalDiffCache();
- if (localCache instanceof LocalDiffCache) {
- LocalDiffCache mcl = (LocalDiffCache) localCache;
- registrations.add(
- registerMBean(whiteboard,
- CacheStatsMBean.class,
- mcl.getDiffCacheStats(),
- CacheStatsMBean.TYPE,
- mcl.getDiffCacheStats().getName()));
- }
-
- DocumentStore ds = store.getDocumentStore();
- if (ds.getCacheStats() != null) {
- registrations.add(
- registerMBean(whiteboard,
- CacheStatsMBean.class,
- ds.getCacheStats(),
- CacheStatsMBean.TYPE,
- ds.getCacheStats().getName())
- );
- }
-
if (store.getBlobStore() instanceof GarbageCollectableBlobStore) {
BlobGarbageCollector gc = new BlobGarbageCollector() {
@Override
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LocalDiffCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LocalDiffCache.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LocalDiffCache.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/LocalDiffCache.java Tue Jun 9 11:08:25 2015
@@ -1,22 +1,19 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.jackrabbit.oak.plugins.document;
import java.util.Collections;
@@ -25,31 +22,35 @@ import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-import com.google.common.base.Joiner;
-import com.google.common.base.Splitter;
import com.google.common.cache.Cache;
import com.google.common.collect.Maps;
+
import org.apache.jackrabbit.oak.cache.CacheStats;
import org.apache.jackrabbit.oak.cache.CacheValue;
+import org.apache.jackrabbit.oak.commons.json.JsopBuilder;
+import org.apache.jackrabbit.oak.commons.json.JsopReader;
+import org.apache.jackrabbit.oak.commons.json.JsopTokenizer;
+import org.apache.jackrabbit.oak.plugins.document.util.RevisionsKey;
import org.apache.jackrabbit.oak.plugins.document.util.StringValue;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+/**
+ * A diff cache, which is pro-actively filled after a commit.
+ */
public class LocalDiffCache implements DiffCache {
+
/**
* Limit is arbitrary for now i.e. 16 MB. Same as in MongoDiffCache
*/
private static int MAX_ENTRY_SIZE = 16 * 1024 * 1024;
- private static final String NO_DIFF = "";
- private final Logger log = LoggerFactory.getLogger(getClass());
- private final Cache<StringValue, ConsolidatedDiff> diffCache;
+
+ private final Cache<RevisionsKey, Diff> diffCache;
private final CacheStats diffCacheStats;
- public LocalDiffCache(DocumentMK.Builder builder) {
- diffCache = builder.buildConsolidatedDiffCache();
- diffCacheStats = new CacheStats(diffCache, "Document-Diff2",
- builder.getWeigher(), builder.getDiffCacheSize());
+ LocalDiffCache(DocumentMK.Builder builder) {
+ this.diffCache = builder.buildLocalDiffCache();
+ this.diffCacheStats = new CacheStats(diffCache,
+ "Document-LocalDiff",
+ builder.getWeigher(), builder.getLocalDiffCacheSize());
}
@Override
@@ -57,27 +58,22 @@ public class LocalDiffCache implements D
@Nonnull Revision to,
@Nonnull String path,
@Nullable Loader loader) {
- ConsolidatedDiff diff = diffCache.getIfPresent(new StringValue(to.toString()));
- if (diff != null){
+ RevisionsKey key = new RevisionsKey(from, to);
+ Diff diff = diffCache.getIfPresent(key);
+ if (diff != null) {
String result = diff.get(path);
- if (result == null){
- return NO_DIFF;
- }
- return result;
- } else {
- log.debug("Did not got the diff for local change in the cache for change {} => {} ", from, to);
+ return result != null ? result : "";
+ }
+ if (loader != null) {
+ return loader.call();
}
return null;
}
- ConsolidatedDiff getDiff(@Nonnull Revision from,
- @Nonnull Revision to){
- return diffCache.getIfPresent(new StringValue(to.toString()));
- }
-
@Nonnull
@Override
- public Entry newEntry(@Nonnull Revision from, final @Nonnull Revision to) {
+ public Entry newEntry(final @Nonnull Revision from,
+ final @Nonnull Revision to) {
return new Entry() {
private final Map<String, String> changesPerPath = Maps.newHashMap();
private int size;
@@ -95,7 +91,8 @@ public class LocalDiffCache implements D
if (exceedsSize()){
return false;
}
- diffCache.put(new StringValue(to.toString()), new ConsolidatedDiff(changesPerPath, size));
+ diffCache.put(new RevisionsKey(from, to),
+ new Diff(changesPerPath, size));
return true;
}
@@ -105,33 +102,55 @@ public class LocalDiffCache implements D
};
}
- public CacheStats getDiffCacheStats() {
- return diffCacheStats;
+ @Nonnull
+ @Override
+ public Iterable<CacheStats> getStats() {
+ return Collections.singleton(diffCacheStats);
}
- public static final class ConsolidatedDiff implements CacheValue{
- //TODO need to come up with better serialization strategy as changes are json themselves
- //cannot use JSON. '/' and '*' are considered invalid chars so would not
- //cause issue
- static final Joiner.MapJoiner mapJoiner = Joiner.on("//").withKeyValueSeparator("**");
- static final Splitter.MapSplitter splitter = Splitter.on("//").withKeyValueSeparator("**");
+ //-----------------------------< internal >---------------------------------
+
+
+ public static final class Diff implements CacheValue {
+
private final Map<String, String> changes;
private int memory;
- public ConsolidatedDiff(Map<String, String> changes, int memory) {
+ public Diff(Map<String, String> changes, int memory) {
this.changes = changes;
this.memory = memory;
}
- public static ConsolidatedDiff fromString(String value){
- if (value.isEmpty()){
- return new ConsolidatedDiff(Collections.<String, String>emptyMap(), 0);
+ public static Diff fromString(String value) {
+ Map<String, String> map = Maps.newHashMap();
+ JsopReader reader = new JsopTokenizer(value);
+ while (true) {
+ if (reader.matches(JsopReader.END)) {
+ break;
+ }
+ String k = reader.readString();
+ reader.read(':');
+ String v = reader.readString();
+ map.put(k, v);
+ if (reader.matches(JsopReader.END)) {
+ break;
+ }
+ reader.read(',');
}
- return new ConsolidatedDiff(splitter.split(value), 0);
+ return new Diff(map, 0);
}
public String asString(){
- return mapJoiner.join(changes);
+ JsopBuilder builder = new JsopBuilder();
+ for (Map.Entry<String, String> entry : changes.entrySet()) {
+ builder.key(entry.getKey());
+ builder.value(entry.getValue());
+ }
+ return builder.toString();
+ }
+
+ public Map<String, String> getChanges() {
+ return Collections.unmodifiableMap(changes);
}
@Override
@@ -146,38 +165,29 @@ public class LocalDiffCache implements D
return memory;
}
- @Override
- public String toString() {
- return changes.toString();
- }
-
String get(String path) {
return changes.get(path);
}
- @SuppressWarnings("RedundantIfStatement")
@Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- ConsolidatedDiff that = (ConsolidatedDiff) o;
-
- if (!changes.equals(that.changes)) return false;
-
- return true;
+ public String toString() {
+ return asString();
}
@Override
- public int hashCode() {
- return changes.hashCode();
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (obj instanceof Diff) {
+ Diff other = (Diff) obj;
+ return changes.equals(other.changes);
+ }
+ return false;
}
}
private static int size(String s){
- //Taken from StringValue
- return 16 // shallow size
- + 40 + s.length() * 2;
+ return StringValue.getMemory(s);
}
-
}
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCache.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCache.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/MemoryDiffCache.java Tue Jun 9 11:08:25 2015
@@ -16,6 +16,7 @@
*/
package org.apache.jackrabbit.oak.plugins.document;
+import java.util.Collections;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
@@ -45,9 +46,9 @@ public class MemoryDiffCache implements
protected MemoryDiffCache(DocumentMK.Builder builder) {
- diffCache = builder.buildDiffCache();
- diffCacheStats = new CacheStats(diffCache, "Document-Diff",
- builder.getWeigher(), builder.getDiffCacheSize());
+ diffCache = builder.buildMemoryDiffCache();
+ diffCacheStats = new CacheStats(diffCache, "Document-MemoryDiff",
+ builder.getWeigher(), builder.getMemoryDiffCacheSize());
}
@CheckForNull
@@ -83,8 +84,10 @@ public class MemoryDiffCache implements
return new MemoryEntry(from, to);
}
- public CacheStats getDiffCacheStats() {
- return diffCacheStats;
+ @Nonnull
+ @Override
+ public Iterable<CacheStats> getStats() {
+ return Collections.singleton(diffCacheStats);
}
protected class MemoryEntry implements Entry {
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheType.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheType.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheType.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/CacheType.java Tue Jun 9 11:08:25 2015
@@ -22,6 +22,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.DocumentStore;
import org.apache.jackrabbit.oak.plugins.document.NodeDocument;
import org.apache.jackrabbit.oak.plugins.document.PathRev;
+import org.apache.jackrabbit.oak.plugins.document.util.RevisionsKey;
import org.apache.jackrabbit.oak.plugins.document.util.StringValue;
public enum CacheType {
@@ -104,7 +105,7 @@ public enum CacheType {
}
},
- CONSOLIDATED_DIFF {
+ DOC_CHILDREN {
@Override
public <K> String keyToString(K key) {
return ((StringValue) key).asString();
@@ -117,20 +118,20 @@ public enum CacheType {
@Override
public <K> int compareKeys(K a, K b) {
return ((StringValue) a).asString().compareTo(((StringValue) b).asString());
- }
+ }
@Override
public <V> String valueToString(V value) {
- return ((LocalDiffCache.ConsolidatedDiff) value).asString();
+ return ((NodeDocument.Children) value).asString();
}
@SuppressWarnings("unchecked")
@Override
public <V> V valueFromString(
DocumentNodeStore store, DocumentStore docStore, String value) {
- return (V) LocalDiffCache.ConsolidatedDiff.fromString(value);
+ return (V) NodeDocument.Children.fromString(value);
}
- },
+ },
- DOC_CHILDREN {
+ DOCUMENT {
@Override
public <K> String keyToString(K key) {
return ((StringValue) key).asString();
@@ -146,42 +147,42 @@ public enum CacheType {
}
@Override
public <V> String valueToString(V value) {
- return ((NodeDocument.Children) value).asString();
+ return ((NodeDocument) value).asString();
}
@SuppressWarnings("unchecked")
@Override
public <V> V valueFromString(
DocumentNodeStore store, DocumentStore docStore, String value) {
- return (V) NodeDocument.Children.fromString(value);
+ return (V) NodeDocument.fromString(docStore, value);
}
- },
-
- DOCUMENT {
+ },
+
+ LOCAL_DIFF {
@Override
public <K> String keyToString(K key) {
- return ((StringValue) key).asString();
+ return ((RevisionsKey) key).asString();
}
@SuppressWarnings("unchecked")
@Override
public <K> K keyFromString(String key) {
- return (K) StringValue.fromString(key);
+ return (K) RevisionsKey.fromString(key);
}
@Override
public <K> int compareKeys(K a, K b) {
- return ((StringValue) a).asString().compareTo(((StringValue) b).asString());
- }
+ return ((RevisionsKey) a).compareTo((RevisionsKey) b);
+ }
@Override
public <V> String valueToString(V value) {
- return ((NodeDocument) value).asString();
+ return ((LocalDiffCache.Diff) value).asString();
}
@SuppressWarnings("unchecked")
@Override
public <V> V valueFromString(
DocumentNodeStore store, DocumentStore docStore, String value) {
- return (V) NodeDocument.fromString(docStore, value);
+ return (V) LocalDiffCache.Diff.fromString(value);
}
- };
-
+ };
+
public abstract <K> String keyToString(K key);
public abstract <K> K keyFromString(String key);
public abstract <K> int compareKeys(K a, K b);
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/persistentCache/PersistentCache.java Tue Jun 9 11:08:25 2015
@@ -49,6 +49,7 @@ public class PersistentCache {
private boolean cacheNodes = true;
private boolean cacheChildren = true;
private boolean cacheDiff = true;
+ private boolean cacheLocalDiff = true;
private boolean cacheDocs;
private boolean cacheDocChildren;
private boolean compactOnClose;
@@ -84,6 +85,8 @@ public class PersistentCache {
cacheChildren = false;
} else if (p.equals("-diff")) {
cacheDiff = false;
+ } else if (p.equals("-localDiff")) {
+ cacheLocalDiff = false;
} else if (p.equals("+all")) {
cacheDocs = true;
cacheDocChildren = true;
@@ -316,8 +319,8 @@ public class PersistentCache {
case DIFF:
wrap = cacheDiff;
break;
- case CONSOLIDATED_DIFF:
- wrap = cacheDiff;
+ case LOCAL_DIFF:
+ wrap = cacheLocalDiff;
break;
case DOC_CHILDREN:
wrap = cacheDocChildren;
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/StringValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/StringValue.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/StringValue.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/util/StringValue.java Tue Jun 9 11:08:25 2015
@@ -37,8 +37,12 @@ public final class StringValue implement
@Override
public int getMemory() {
+ return getMemory(value);
+ }
+
+ public static int getMemory(@Nonnull String s) {
return 16 // shallow size
- + 40 + value.length() * 2; // value
+ + 40 + s.length() * 2; // value
}
@Override
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventGenerator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventGenerator.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventGenerator.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/EventGenerator.java Tue Jun 9 11:08:25 2015
@@ -76,25 +76,18 @@ public class EventGenerator {
private final LinkedList<Continuation> continuations = newLinkedList();
- private final ContentChangeInfo changeInfo;
-
/**
* Creates a new generator instance. Changes to process need to be added
* through {@link #addHandler(NodeState, NodeState, EventHandler)}
- * @param changeInfo
*/
- public EventGenerator(ContentChangeInfo changeInfo) {
- this.changeInfo = changeInfo;
- }
+ public EventGenerator() {}
/**
* Creates a new generator instance for processing the given changes.
*/
public EventGenerator(
@Nonnull NodeState before, @Nonnull NodeState after,
- @Nonnull ContentChangeInfo changeInfo,
@Nonnull EventHandler handler) {
- this(changeInfo);
continuations.addFirst(new Continuation(handler, before, after, 0));
}
@@ -127,7 +120,7 @@ public class EventGenerator {
}
}
- private class Continuation implements NodeStateDiff, Runnable, ContentChangeInfoProvider {
+ private class Continuation implements NodeStateDiff, Runnable {
/**
* Filtered handler of detected content changes.
@@ -183,13 +176,6 @@ public class EventGenerator {
}
}
- //-------------------------------------------------< ContentChangeInfoProvider >--
-
- @Override
- public ContentChangeInfo getChangeInfo() {
- return changeInfo;
- }
-
//-------------------------------------------------< NodeStateDiff >--
@Override
Modified: jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/NodeObserver.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/NodeObserver.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/NodeObserver.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation/NodeObserver.java Tue Jun 9 11:08:25 2015
@@ -157,8 +157,7 @@ public abstract class NodeObserver imple
handler = handler.getChildHandler(oakName, before, after);
}
- ContentChangeInfo changeInfo = new ContentChangeInfo(before, after, info);
- EventGenerator generator = new EventGenerator(before, after, changeInfo, handler);
+ EventGenerator generator = new EventGenerator(before, after, handler);
while (!generator.isDone()) {
generator.generate();
}
Modified: jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AbstractMongoConnectionTest.java Tue Jun 9 11:08:25 2015
@@ -16,7 +16,6 @@
*/
package org.apache.jackrabbit.oak.plugins.document;
-import com.mongodb.DB;
import org.apache.jackrabbit.mk.api.MicroKernel;
import org.apache.jackrabbit.oak.plugins.document.util.MongoConnection;
import org.apache.jackrabbit.oak.stats.Clock;
@@ -45,17 +44,13 @@ public abstract class AbstractMongoConne
mongoConnection = MongoUtils.getConnection();
MongoUtils.dropCollections(mongoConnection.getDB());
Revision.setClock(getTestClock());
- mk = prepare(new DocumentMK.Builder().clock(getTestClock()),mongoConnection.getDB()).open();
+ mk = new DocumentMK.Builder().clock(getTestClock()).setMongoDB(mongoConnection.getDB()).open();
}
protected Clock getTestClock() throws InterruptedException {
return Clock.SIMPLE;
}
- protected DocumentMK.Builder prepare(DocumentMK.Builder builder, DB db){
- return builder.setMongoDB(db);
- }
-
@After
public void tearDownConnection() throws Exception {
mk.dispose();
Modified: jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AmnesiaDiffCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AmnesiaDiffCache.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AmnesiaDiffCache.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/AmnesiaDiffCache.java Tue Jun 9 11:08:25 2015
@@ -16,9 +16,13 @@
*/
package org.apache.jackrabbit.oak.plugins.document;
+import java.util.Collections;
+
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
+import org.apache.jackrabbit.oak.cache.CacheStats;
+
/**
* A diff cache implementation, which immediately forgets the diff.
*/
@@ -55,4 +59,10 @@ class AmnesiaDiffCache implements DiffCa
}
};
}
+
+ @Nonnull
+ @Override
+ public Iterable<CacheStats> getStats() {
+ return Collections.emptyList();
+ }
}
Modified: jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreDiffTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreDiffTest.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreDiffTest.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreDiffTest.java Tue Jun 9 11:08:25 2015
@@ -64,18 +64,16 @@ public class DocumentNodeStoreDiffTest e
merge(store, builder);
}
- CacheStats stats = ((MemoryDiffCache) store.getDiffCache()).getDiffCacheStats();
- stats.resetStats();
+ Iterable<CacheStats> stats = store.getDiffCacheStats();
+ for (CacheStats cs : stats) {
+ cs.resetStats();
+ }
// must not cause cache misses
Diff.perform(before, after);
- assertEquals(0, stats.getMissCount());
- }
-
- @Override
- protected DocumentMK.Builder prepare(DocumentMK.Builder builder, DB db) {
- builder.setDisableLocalDiffCache(true);
- return super.prepare(builder, db);
+ for (CacheStats cs : stats) {
+ assertEquals(0, cs.getMissCount());
+ }
}
@Override
Modified: jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/DocumentNodeStoreTest.java Tue Jun 9 11:08:25 2015
@@ -1672,6 +1672,90 @@ public class DocumentNodeStoreTest {
ns.dispose();
}
+ @Test
+ public void rootRevision() throws Exception {
+ DocumentNodeStore ns = new DocumentMK.Builder().getNodeStore();
+
+ NodeBuilder builder = ns.getRoot().builder();
+ builder.child("foo").child("child");
+ builder.child("bar").child("child");
+ merge(ns, builder);
+
+ builder = ns.getRoot().builder();
+ builder.child("foo").child("child").child("node");
+ merge(ns, builder);
+
+ Revision head = ns.getHeadRevision();
+ NodeState child = ns.getRoot().getChildNode("bar").getChildNode("child");
+ assertTrue(child instanceof DocumentNodeState);
+ DocumentNodeState state = (DocumentNodeState) child;
+ assertEquals(head, state.getRootRevision());
+
+ ns.dispose();
+ }
+
+ @Test
+ public void diffCache() throws Exception {
+ final AtomicInteger numQueries = new AtomicInteger();
+ MemoryDocumentStore store = new MemoryDocumentStore() {
+ @Nonnull
+ @Override
+ public <T extends Document> List<T> query(Collection<T> collection,
+ String fromKey,
+ String toKey,
+ int limit) {
+ numQueries.incrementAndGet();
+ return super.query(collection, fromKey, toKey, limit);
+ }
+ };
+ DocumentNodeStore ns = new DocumentMK.Builder()
+ .setDocumentStore(store).setAsyncDelay(0).getNodeStore();
+
+ NodeBuilder builder = ns.getRoot().builder();
+ builder.child("foo").child("child");
+ merge(ns, builder);
+
+ builder = ns.getRoot().builder();
+ builder.child("bar");
+ merge(ns, builder);
+
+ DocumentNodeState before = ns.getRoot();
+
+ builder = ns.getRoot().builder();
+ builder.child("foo").child("child").child("node");
+ merge(ns, builder);
+
+ DocumentNodeState after = ns.getRoot();
+
+ numQueries.set(0);
+ final List<String> added = Lists.newArrayList();
+ ns.compare(asDocumentNodeState(after.getChildNode("foo").getChildNode("child")),
+ asDocumentNodeState(before.getChildNode("foo").getChildNode("child")),
+ new DefaultNodeStateDiff() {
+ @Override
+ public boolean childNodeAdded(String name,
+ NodeState after) {
+ added.add(name);
+ return super.childNodeAdded(name, after);
+ }
+ });
+
+
+ assertEquals(1, added.size());
+ assertEquals("node", added.get(0));
+ assertEquals("must not run queries", 0, numQueries.get());
+
+ ns.dispose();
+
+ }
+
+ private static DocumentNodeState asDocumentNodeState(NodeState state) {
+ if (!(state instanceof DocumentNodeState)) {
+ throw new IllegalArgumentException("Not a DocumentNodeState");
+ }
+ return (DocumentNodeState) state;
+ }
+
private void doSomeChange(NodeStore ns) throws CommitFailedException {
NodeBuilder b = ns.getRoot().builder();
b.setProperty("count", System.currentTimeMillis());
Modified: jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/LocalDiffCacheTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/LocalDiffCacheTest.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/LocalDiffCacheTest.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/LocalDiffCacheTest.java Tue Jun 9 11:08:25 2015
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.jackrabbit.oak.plugins.document;
import java.util.HashMap;
@@ -25,15 +24,18 @@ import java.util.Set;
import javax.annotation.Nonnull;
+import com.google.common.collect.Maps;
+
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.cache.CacheStats;
-import org.apache.jackrabbit.oak.plugins.document.LocalDiffCache.ConsolidatedDiff;
+import org.apache.jackrabbit.oak.plugins.document.LocalDiffCache.Diff;
import org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore;
import org.apache.jackrabbit.oak.plugins.observation.NodeObserver;
import org.apache.jackrabbit.oak.spi.commit.CommitInfo;
import org.apache.jackrabbit.oak.spi.commit.EmptyHook;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
import org.apache.jackrabbit.oak.spi.state.NodeStore;
+import org.junit.After;
import org.junit.Test;
import static com.google.common.collect.Maps.newHashMap;
@@ -45,59 +47,67 @@ public class LocalDiffCacheTest {
DocumentNodeStore store;
+ @After
+ public void dispose() {
+ if (store != null) {
+ store.dispose();
+ store = null;
+ }
+ }
+
@Test
public void simpleDiff() throws Exception{
TestNodeObserver o = new TestNodeObserver("/");
- store = createMK().getNodeStore();
+ store = createMK().getNodeStore();
store.addObserver(o);
o.reset();
- LocalDiffCache cache = getLocalDiffCache();
- CacheStats stats = cache.getDiffCacheStats();
+ DiffCache cache = store.getDiffCache();
+ Iterable<CacheStats> stats = cache.getStats();
- DocumentNodeState beforeState = store.getRoot();
NodeBuilder builder = store.getRoot().builder();
builder.child("a").child("a2").setProperty("foo", "bar");
builder.child("b");
- DocumentNodeState afterState = merge(store, builder);
+ merge(store, builder);
- assertTrue(stats.getHitCount() > 0);
- assertEquals(0, stats.getMissCount());
+ assertTrue(getHitCount(stats) > 0);
+ assertEquals(0, getMissCount(stats));
assertEquals(3, o.added.size());
- ConsolidatedDiff diff = cache.getDiff(beforeState.getRevision(), afterState.getRevision());
- String serailized = diff.asString();
- ConsolidatedDiff diff2 = ConsolidatedDiff.fromString(serailized);
- assertEquals(diff, diff2);
-
builder = store.getRoot().builder();
builder.child("a").child("a2").removeProperty("foo");
o.reset();
- stats.resetStats();
+ resetStats(stats);
merge(store, builder);
- assertTrue(stats.getHitCount() > 0);
- assertEquals(0, stats.getMissCount());
+ assertTrue(getHitCount(stats) > 0);
+ assertEquals(0, getMissCount(stats));
assertEquals(1, o.changed.size());
+ }
+
+ @Test
+ public void diffFromAsString() {
+ Map<String, String> changes = Maps.newHashMap();
+ changes.put("/", "+\"foo\":{}^\"bar\":{}-\"baz\"");
+ changes.put("/foo", "");
+ changes.put("/bar", "+\"qux\"");
+ changes.put("/bar/qux", "");
+ Diff diff = new Diff(changes, 0);
- store.dispose();
+ assertEquals(changes, Diff.fromString(diff.asString()).getChanges());
}
@Test
public void emptyDiff() throws Exception{
Map<String, String> changes = new HashMap<String, String>();
- ConsolidatedDiff diff = new ConsolidatedDiff(changes, 100);
+ Diff diff = new Diff(changes, 100);
String asString = diff.asString();
- ConsolidatedDiff diff2 = ConsolidatedDiff.fromString(asString);
+ Diff diff2 = Diff.fromString(asString);
assertEquals(diff, diff2);
}
- private LocalDiffCache getLocalDiffCache(){
- return (LocalDiffCache) store.getLocalDiffCache();
- }
-
private static DocumentNodeState merge(NodeStore store, NodeBuilder builder)
throws CommitFailedException {
return (DocumentNodeState) store.merge(builder, EmptyHook.INSTANCE, CommitInfo.EMPTY);
@@ -116,6 +126,28 @@ public class LocalDiffCacheTest {
.open();
}
+ private static long getHitCount(Iterable<CacheStats> stats) {
+ long hitCount = 0;
+ for (CacheStats cs : stats) {
+ hitCount += cs.getHitCount();
+ }
+ return hitCount;
+ }
+
+ private static long getMissCount(Iterable<CacheStats> stats) {
+ long missCount = 0;
+ for (CacheStats cs : stats) {
+ missCount += cs.getMissCount();
+ }
+ return missCount;
+ }
+
+ private static void resetStats(Iterable<CacheStats> stats) {
+ for (CacheStats cs : stats) {
+ cs.resetStats();
+ }
+ }
+
//------------------------------------------------------------< TestNodeObserver >---
private static class TestNodeObserver extends NodeObserver {
Modified: jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MeasureMemory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MeasureMemory.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MeasureMemory.java (original)
+++ jackrabbit/oak/branches/1.2/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/MeasureMemory.java Tue Jun 9 11:08:25 2015
@@ -23,6 +23,8 @@ import java.util.LinkedList;
import java.util.concurrent.Callable;
import com.mongodb.BasicDBObject;
+
+import org.apache.jackrabbit.oak.plugins.document.util.RevisionsKey;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.junit.Test;
@@ -125,6 +127,18 @@ public class MeasureMemory {
}
});
}
+
+ @Test
+ public void revisionsKey() throws Exception {
+ measureMemory(new Callable<Object[]>() {
+ @Override
+ public Object[] call() {
+ RevisionsKey k = new RevisionsKey(
+ Revision.newRevision(0), Revision.newRevision(0));
+ return new Object[]{k, k.getMemory() + OVERHEAD};
+ }
+ });
+ }
private static void measureMemory(Callable<Object[]> c) throws Exception {
LinkedList<Object> list = new LinkedList<Object>();
Modified: jackrabbit/oak/branches/1.2/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventQueue.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.2/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventQueue.java?rev=1684378&r1=1684377&r2=1684378&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.2/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventQueue.java (original)
+++ jackrabbit/oak/branches/1.2/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/observation/EventQueue.java Tue Jun 9 11:08:25 2015
@@ -29,7 +29,6 @@ import javax.jcr.observation.EventIterat
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
-import org.apache.jackrabbit.oak.plugins.observation.ContentChangeInfo;
import org.apache.jackrabbit.oak.plugins.observation.EventGenerator;
import org.apache.jackrabbit.oak.plugins.observation.EventHandler;
import org.apache.jackrabbit.oak.plugins.observation.FilteredHandler;
@@ -52,7 +51,7 @@ class EventQueue implements EventIterato
@Nonnull NamePathMapper mapper, CommitInfo info,
@Nonnull NodeState before, @Nonnull NodeState after,
@Nonnull Iterable<String> basePaths, @Nonnull EventFilter filter) {
- this.generator = new EventGenerator(new ContentChangeInfo(before, after, info));
+ this.generator = new EventGenerator();
EventFactory factory = new EventFactory(mapper, info);
EventHandler handler = new FilteredHandler(
filter, new QueueingHandler(this, factory, before, after));