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 2016/06/23 13:48:20 UTC
svn commit: r1749890 - in /jackrabbit/oak/branches/1.4: ./
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/
oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/
oak-core/src/test/java/org/apache/jackrabbit/oa...
Author: mreutegg
Date: Thu Jun 23 13:48:20 2016
New Revision: 1749890
URL: http://svn.apache.org/viewvc?rev=1749890&view=rev
Log:
OAK-4494: Stale documents after revision GC in cluster
Merged revision 1749875 from trunk
Added:
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/ModificationStamp.java
- copied unchanged from r1749875, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/ModificationStamp.java
Modified:
jackrabbit/oak/branches/1.4/ (props changed)
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java
jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ResurrectNodeAfterRevisionGCTest.java
Propchange: jackrabbit/oak/branches/1.4/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jun 23 13:48:20 2016
@@ -1,3 +1,3 @@
/jackrabbit/oak/branches/1.0:1665962
-/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738775,1738795,1738833,1738950,1738957,1738963,1739894,1740116,1740625-1740626,1740971,1741032,1741339,1741343,1742520,1742888,1742916,1743097,1743172,1743343,1744265,1744959,1745038,1745197,1745368,1746086,1746117,1746342,1746345,1746696,1746981,1747341-1747342,1747492,1747512,1748505,1748553,1748870,1749275,1749350,1749464,1749475,1749645,1749662,1749815,1749872
+/jackrabbit/oak/trunk:1733615,1733875,1733913,1733929,1734230,1734254,1734279,1734941,1735052,1735405,1735484,1735549,1735564,1735588,1735622,1735638,1735919,1735983,1736176,1737309-1737310,1737334,1737349,1737998,1738004,1738775,1738795,1738833,1738950,1738957,1738963,1739894,1740116,1740625-1740626,1740971,1741032,1741339,1741343,1742520,1742888,1742916,1743097,1743172,1743343,1744265,1744959,1745038,1745197,1745368,1746086,1746117,1746342,1746345,1746696,1746981,1747341-1747342,1747492,1747512,1748505,1748553,1748870,1749275,1749350,1749464,1749475,1749645,1749662,1749815,1749872,1749875
/jackrabbit/trunk:1345480
Modified: jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java?rev=1749890&r1=1749889&r2=1749890&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/cache/NodeDocumentCache.java Thu Jun 23 13:48:20 2016
@@ -92,23 +92,25 @@ public class NodeDocumentCache implement
}
/**
- * Invalidate document with given keys iff their mod counts are different as
- * passed in the map.
+ * Invalidate document with given keys iff their modification stamps are
+ * different as passed in the map.
*
- * @param modCounts map where key is the document id and the value is the mod count
+ * @param modStamps map where key is the document id and the value is the
+ * modification stamps.
* @return number of invalidated entries
*/
@Nonnegative
- public int invalidateOutdated(@Nonnull Map<String, Long> modCounts) {
+ public int invalidateOutdated(@Nonnull Map<String, ModificationStamp> modStamps) {
int invalidatedCount = 0;
- for (Entry<String, Long> e : modCounts.entrySet()) {
+ for (Entry<String, ModificationStamp> e : modStamps.entrySet()) {
String id = e.getKey();
- Long modCount = e.getValue();
+ ModificationStamp stamp = e.getValue();
NodeDocument doc = getIfPresent(id);
if (doc == null) {
continue;
}
- if (!Objects.equal(modCount, doc.getModCount())) {
+ if (!Objects.equal(stamp.modCount, doc.getModCount())
+ || !Objects.equal(stamp.modified, doc.getModified())) {
invalidate(id);
invalidatedCount++;
}
Modified: jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java?rev=1749890&r1=1749889&r2=1749890&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/document/mongo/MongoDocumentStore.java Thu Jun 23 13:48:20 2016
@@ -69,6 +69,7 @@ import org.apache.jackrabbit.oak.plugins
import org.apache.jackrabbit.oak.plugins.document.UpdateOp.Operation;
import org.apache.jackrabbit.oak.plugins.document.UpdateUtils;
import org.apache.jackrabbit.oak.plugins.document.cache.CacheInvalidationStats;
+import org.apache.jackrabbit.oak.plugins.document.cache.ModificationStamp;
import org.apache.jackrabbit.oak.plugins.document.cache.NodeDocumentCache;
import org.apache.jackrabbit.oak.plugins.document.locks.TreeNodeDocumentLocks;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
@@ -310,11 +311,11 @@ public class MongoDocumentStore implemen
ids.size(), size);
}
- Map<String, Long> modCounts = getModCounts(ids);
+ Map<String, ModificationStamp> modStamps = getModStamps(ids);
result.queryCount++;
- int invalidated = nodesCache.invalidateOutdated(modCounts);
- for (String id : filter(ids, not(in(modCounts.keySet())))) {
+ int invalidated = nodesCache.invalidateOutdated(modStamps);
+ for (String id : filter(ids, not(in(modStamps.keySet())))) {
nodesCache.invalidate(id);
invalidated++;
}
@@ -1153,17 +1154,17 @@ public class MongoDocumentStore implemen
try {
dbCollection.update(query.get(), update, false, true);
if (collection == Collection.NODES) {
- Map<String, Long> modCounts = getModCounts(filterValues(cachedDocs, notNull()).keySet());
+ Map<String, ModificationStamp> modCounts = getModStamps(filterValues(cachedDocs, notNull()).keySet());
// update cache
for (Entry<String, NodeDocument> entry : cachedDocs.entrySet()) {
// the cachedDocs is not empty, so the collection = NODES
Lock lock = nodeLocks.acquire(entry.getKey());
try {
- Long postUpdateModCount = modCounts.get(entry.getKey());
- if (postUpdateModCount != null
+ ModificationStamp postUpdateModStamp = modCounts.get(entry.getKey());
+ if (postUpdateModStamp != null
&& entry.getValue() != null
&& entry.getValue() != NodeDocument.NULL
- && Long.valueOf(postUpdateModCount - 1).equals(entry.getValue().getModCount())) {
+ && Long.valueOf(postUpdateModStamp.modCount - 1).equals(entry.getValue().getModCount())) {
// post update modCount is one higher than
// what we currently see in the cache. we can
// replace the cached document
@@ -1193,30 +1194,40 @@ public class MongoDocumentStore implemen
}
/**
- * Returns the {@link Document#MOD_COUNT} value of the documents with the
+ * Returns the {@link Document#MOD_COUNT} and
+ * {@link NodeDocument#MODIFIED_IN_SECS} values of the documents with the
* given {@code keys}. The returned map will only contain entries for
- * existing documents.
+ * existing documents. The default value is -1 if the document does not have
+ * a modCount field. The same applies to the modified field.
*
* @param keys the keys of the documents.
- * @return map with key to {@link Document#MOD_COUNT} value mapping.
+ * @return map with key to modification stamp mapping.
* @throws MongoException if the call fails
*/
@Nonnull
- private Map<String, Long> getModCounts(Iterable<String> keys)
+ private Map<String, ModificationStamp> getModStamps(Iterable<String> keys)
throws MongoException {
QueryBuilder query = QueryBuilder.start(Document.ID).in(keys);
// Fetch only the modCount and id
final BasicDBObject fields = new BasicDBObject(Document.ID, 1);
fields.put(Document.MOD_COUNT, 1);
+ fields.put(NodeDocument.MODIFIED_IN_SECS, 1);
DBCursor cursor = nodes.find(query.get(), fields);
cursor.setReadPreference(ReadPreference.primary());
- Map<String, Long> modCounts = Maps.newHashMap();
+ Map<String, ModificationStamp> modCounts = Maps.newHashMap();
for (DBObject obj : cursor) {
String id = (String) obj.get(Document.ID);
Long modCount = Utils.asLong((Number) obj.get(Document.MOD_COUNT));
- modCounts.put(id, modCount);
+ if (modCount == null) {
+ modCount = -1L;
+ }
+ Long modified = Utils.asLong((Number) obj.get(NodeDocument.MODIFIED_IN_SECS));
+ if (modified == null) {
+ modified = -1L;
+ }
+ modCounts.put(id, new ModificationStamp(modCount, modified));
}
return modCounts;
}
Modified: jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ResurrectNodeAfterRevisionGCTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ResurrectNodeAfterRevisionGCTest.java?rev=1749890&r1=1749889&r2=1749890&view=diff
==============================================================================
--- jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ResurrectNodeAfterRevisionGCTest.java (original)
+++ jackrabbit/oak/branches/1.4/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/document/ResurrectNodeAfterRevisionGCTest.java Thu Jun 23 13:48:20 2016
@@ -30,7 +30,6 @@ import org.apache.jackrabbit.oak.spi.sta
import org.apache.jackrabbit.oak.stats.Clock;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import static org.apache.jackrabbit.oak.plugins.document.util.Utils.getIdFromPath;
@@ -39,8 +38,8 @@ import static org.junit.Assert.assertFal
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeFalse;
-@Ignore
public class ResurrectNodeAfterRevisionGCTest
extends AbstractMultiDocumentStoreTest {
@@ -50,6 +49,7 @@ public class ResurrectNodeAfterRevisionG
public ResurrectNodeAfterRevisionGCTest(DocumentStoreFixture dsf) {
super(dsf);
+ assumeFalse(dsf instanceof DocumentStoreFixture.RDBFixture);
}
@Before
@@ -66,6 +66,7 @@ public class ResurrectNodeAfterRevisionG
}
c = new Clock.Virtual();
c.waitUntil(System.currentTimeMillis());
+ Revision.setClock(c);
ns1 = new DocumentMK.Builder().setAsyncDelay(0)
.clock(c).setClusterId(1).setDocumentStore(ds1).getNodeStore();
ns2 = new DocumentMK.Builder().setAsyncDelay(0)
@@ -76,6 +77,7 @@ public class ResurrectNodeAfterRevisionG
public void disposeNodeStores() {
ns1.dispose();
ns2.dispose();
+ Revision.resetClockToDefault();
}
@Test