summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2009-12-28 03:45:51 (EST)
committerCaspar De Groot2009-12-28 03:45:51 (EST)
commite5014f1f36217ff68e5fc942167a056f7ac96c7e (patch)
tree26660a001da97f90efb1fe5c74d2dd2f34f2efeb
parente749fd8dc69fbdd6f91c7fd20054fff6ee431359 (diff)
downloadcdo-e5014f1f36217ff68e5fc942167a056f7ac96c7e.zip
cdo-e5014f1f36217ff68e5fc942167a056f7ac96c7e.tar.gz
cdo-e5014f1f36217ff68e5fc942167a056f7ac96c7e.tar.bz2
[297708] TwoLevelCache fails to revise revisions kept in L2
https://bugs.eclipse.org/bugs/show_bug.cgi?id=297708
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/cache/two/TwoLevelRevisionCache.java25
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_292372_Test.java57
3 files changed, 83 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/cache/two/TwoLevelRevisionCache.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/cache/two/TwoLevelRevisionCache.java
index 443111b..907cc9c 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/cache/two/TwoLevelRevisionCache.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/cache/two/TwoLevelRevisionCache.java
@@ -16,6 +16,7 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.cache.CDORevisionCache;
import org.eclipse.emf.cdo.internal.common.bundle.OM;
+import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.util.CheckUtil;
import org.eclipse.net4j.util.event.IEvent;
@@ -119,7 +120,29 @@ public class TwoLevelRevisionCache extends Lifecycle implements CDORevisionCache
public boolean addRevision(CDORevision revision)
{
CheckUtil.checkArg(revision, "revision");
- return level1.addRevision(revision);
+ boolean added = level1.addRevision(revision);
+
+ // Bugzilla 292372: If a new current revision was added to level1, we must check whether
+ // level2 contains a stale current revision, and revise that revision if possible
+ if (added && revision.isCurrent())
+ {
+ CDOID id = revision.getID();
+ CDORevision revisionInLevel2 = level2.getRevision(id);
+ if (revisionInLevel2 != null && revisionInLevel2.isCurrent())
+ {
+ // We can only revise if the revisions are consecutive
+ if (revision.getVersion() == revisionInLevel2.getVersion() + 1)
+ {
+ ((InternalCDORevision)revisionInLevel2).setRevised(revision.getCreated() - 1);
+ }
+ else
+ {
+ level2.removeRevision(id, revisionInLevel2.getVersion());
+ }
+ }
+ }
+
+ return added;
}
public void removeRevision(CDORevision revision)
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
index d78e190..970965a 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsAllConfigs.java
@@ -59,6 +59,7 @@ import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_283985_CDOTest2;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_283985_SavePointTest;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_289932_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_289984_Test;
+import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_292372_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_294850_Test;
import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_294859_Test;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
@@ -174,6 +175,7 @@ public abstract class AllTestsAllConfigs extends ConfigTestSuite
testClasses.add(Bugzilla_283985_SavePointTest.class);
testClasses.add(Bugzilla_294850_Test.class);
testClasses.add(Bugzilla_294859_Test.class);
+ testClasses.add(Bugzilla_292372_Test.class);
// TODO testClasses.add(NonCDOResourceTest.class);
// TODO testClasses.add(GeneratedEcoreTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_292372_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_292372_Test.java
new file mode 100644
index 0000000..bda2d46
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_292372_Test.java
@@ -0,0 +1,57 @@
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.internal.common.revision.cache.lru.LRURevisionCache;
+import org.eclipse.emf.cdo.internal.common.revision.cache.mem.MEMRevisionCache;
+import org.eclipse.emf.cdo.internal.common.revision.cache.two.TwoLevelRevisionCache;
+import org.eclipse.emf.cdo.tests.AbstractCDOTest;
+import org.eclipse.emf.cdo.tests.RevisionHolderTest.TestRevision;
+
+public class Bugzilla_292372_Test extends AbstractCDOTest
+{
+ public void test()
+ {
+ LRURevisionCache lruCache = new LRURevisionCache();
+ lruCache.setCapacityCurrent(2);
+ lruCache.setCapacityRevised(2);
+
+ MEMRevisionCache memCache = new MEMRevisionCache();
+
+ TwoLevelRevisionCache twoLevelCache = new TwoLevelRevisionCache();
+ twoLevelCache.setLevel1(lruCache);
+ twoLevelCache.setLevel2(memCache);
+ twoLevelCache.activate();
+
+ TestRevision r1v1 = new TestRevision(9, 1, 10);
+
+ TestRevision r2v1 = new TestRevision(1, 1, 10);
+ TestRevision r2v2 = new TestRevision(1, 2, 20);
+ TestRevision r2v3 = new TestRevision(1, 3, 30);
+ TestRevision r2v4 = new TestRevision(1, 4, 40);
+
+ // First we add the revision that will cause the problem later
+ twoLevelCache.addRevision(r1v1);
+
+ // Then we push other revisions to force r1v1 into the level-2 cache
+ twoLevelCache.addRevision(r2v1);
+ assertTrue(r2v1.isCurrent());
+ twoLevelCache.addRevision(r2v2);
+ assertFalse(r2v1.isCurrent());
+ assertTrue(r2v2.isCurrent());
+ twoLevelCache.addRevision(r2v3);
+ assertFalse(r2v2.isCurrent());
+ assertTrue(r2v3.isCurrent());
+ twoLevelCache.addRevision(r2v4);
+ assertFalse(r2v3.isCurrent());
+ assertTrue(r2v4.isCurrent());
+
+ // Now we add a revision r1v2 that SHOULD cause r1v1.revised to get set
+ TestRevision r1v2 = new TestRevision(9, 2, 20);
+ twoLevelCache.addRevision(r1v2); // Into L1 cache
+ CDORevision r1v = twoLevelCache.getRevisionByVersion(r1v1.getID(), 1); // From L2 cache
+
+ // But it doesn't, cause twoLevelCache forgot to delegate to the L2,
+ // so this will fail:
+ assertFalse(r1v.isCurrent());
+ }
+}