Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2010-09-14 06:11:00 +0000
committerEike Stepper2010-09-14 06:11:00 +0000
commit75e83943dfd0b62f5ca4afcd070f060667fea945 (patch)
tree91dfdab4f114fc05e34121cf4ffe8c6303ec672b
parent85d7cb8285e99331860bf1907063c8320549db89 (diff)
downloadcdo-75e83943dfd0b62f5ca4afcd070f060667fea945.tar.gz
cdo-75e83943dfd0b62f5ca4afcd070f060667fea945.tar.xz
cdo-75e83943dfd0b62f5ca4afcd070f060667fea945.zip
[325097] Last object ID wrong in SynchronizableRepository.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=325097
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java33
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TransactionCommitContext.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/RepositorySynchronizer.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractSyncingTest.java13
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/FailoverTest.java13
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/OfflineRawTest.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_312879_Test.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_325097_Test.java131
9 files changed, 180 insertions, 32 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
index febf5d4128..84c34bb11c 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
@@ -20,6 +20,7 @@ import org.eclipse.emf.cdo.common.branch.CDOBranchVersion;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfo;
import org.eclipse.emf.cdo.common.commit.CDOCommitInfoHandler;
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
import org.eclipse.emf.cdo.common.model.CDOPackageRegistry;
import org.eclipse.emf.cdo.common.protocol.CDODataInput;
@@ -102,6 +103,8 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
private Set<CDOID> newObjects = new HashSet<CDOID>();
+ private long maxID;
+
public DBStoreAccessor(DBStore store, ISession session) throws DBException
{
super(store, session);
@@ -302,6 +305,16 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
{
CDOID id = revision.getID();
newObjects.add(id);
+
+ // Remember maxID because it may have to be adjusted if the repository is BACKUP or CLONE. See bug 325097.
+ if (!context.getBranchPoint().getBranch().isLocal())
+ {
+ long value = CDOIDUtil.getLong(id);
+ if (value > maxID)
+ {
+ maxID = value;
+ }
+ }
}
}
@@ -357,7 +370,8 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
protected void writeRevisionDelta(InternalCDORevisionDelta delta, long created, OMMonitor monitor)
{
- EClass eClass = getObjectType(delta.getID());
+ CDOID id = delta.getID();
+ EClass eClass = getObjectType(id);
IClassMappingDeltaSupport mapping = (IClassMappingDeltaSupport)getStore().getMappingStrategy().getClassMapping(
eClass);
mapping.writeRevisionDelta(this, delta, created, monitor);
@@ -456,6 +470,15 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
{
async = monitor.forkAsync();
getConnection().commit();
+
+ DBStore store = getStore();
+ if (maxID > store.getLastObjectID())
+ {
+ // See bug 325097
+ store.setLastObjectID(maxID);
+ }
+
+ maxID = 0L;
}
finally
{
@@ -834,8 +857,8 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
public void rawExport(CDODataOutput out, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime)
throws IOException
{
- Connection connection = getConnection();
DBStore store = getStore();
+ out.writeLong(store.getLastObjectID()); // See bug 325097
String where = " WHERE " + CDODBSchema.BRANCHES_ID + " BETWEEN " + fromBranchID + " AND " + toBranchID;
DBUtil.serializeTable(out, connection, CDODBSchema.BRANCHES, null, where);
@@ -856,7 +879,10 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
public void rawImport(CDODataInput in, int fromBranchID, int toBranchID, long fromCommitTime, long toCommitTime,
OMMonitor monitor) throws IOException
{
- IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
+ DBStore store = getStore();
+ store.setLastObjectID(in.readLong()); // See bug 325097
+
+ IMappingStrategy mappingStrategy = store.getMappingStrategy();
int size = mappingStrategy.getClassMappings().size();
int commitWork = 4;
monitor.begin(commitWork + size + commitWork);
@@ -871,6 +897,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
mappingStrategy.rawImport(this, in, monitor.fork(size));
Async async = monitor.forkAsync(commitWork);
+
try
{
connection.commit();
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TransactionCommitContext.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TransactionCommitContext.java
index 7e1014e46d..b00dac90bc 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TransactionCommitContext.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TransactionCommitContext.java
@@ -1052,7 +1052,7 @@ public class TransactionCommitContext implements InternalCommitContext
{
if (!revisionManager.addRevision(revision))
{
- throw new IllegalStateException("Revision was not registered: " + revision);
+ throw new IllegalStateException("Failed to register revision: " + revision);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/RepositorySynchronizer.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/RepositorySynchronizer.java
index df539c0cdd..d349a8526d 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/RepositorySynchronizer.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/RepositorySynchronizer.java
@@ -91,6 +91,7 @@ public class RepositorySynchronizer extends QueueRunner implements InternalRepos
public RepositorySynchronizer()
{
+ setDaemon(true);
}
public int getRetryInterval()
diff --git a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java
index ddf8e575a5..60c6e77af0 100644
--- a/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java
+++ b/plugins/org.eclipse.emf.cdo.tests.db/src/org/eclipse/emf/cdo/tests/db/AllTestsDBH2Offline.java
@@ -14,7 +14,7 @@ import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
-import org.eclipse.emf.cdo.tests.OfflineRawTest;
+import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_325097_Test;
import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
import org.eclipse.net4j.db.DBUtil;
@@ -71,8 +71,9 @@ public class AllTestsDBH2Offline extends DBConfigs
{
// super.initTestClasses(testClasses);
+ testClasses.add(Bugzilla_325097_Test.class);
// testClasses.add(Bugzilla_319552_Test.class);
- testClasses.add(OfflineRawTest.class);
+ // testClasses.add(OfflineRawTest.class);
// testClasses.add(OfflineDelayedTest.class);
// testClasses.add(OfflineTest.class);
// testClasses.add(FailoverTest.class);
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractSyncingTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractSyncingTest.java
index bdc6beb746..147c0114e9 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractSyncingTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractSyncingTest.java
@@ -23,6 +23,7 @@ import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.session.CDOSessionInvalidationEvent;
import org.eclipse.emf.cdo.spi.server.InternalRepository;
import org.eclipse.emf.cdo.spi.server.InternalStore;
+import org.eclipse.emf.cdo.spi.server.InternalSynchronizableRepository;
import org.eclipse.emf.cdo.tests.config.IRepositoryConfig;
import org.eclipse.emf.cdo.tests.config.impl.RepositoryConfig.OfflineConfig;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
@@ -57,6 +58,18 @@ public abstract class AbstractSyncingTest extends AbstractCDOTest
}
@Override
+ public InternalSynchronizableRepository getRepository()
+ {
+ return (InternalSynchronizableRepository)super.getRepository();
+ }
+
+ @Override
+ public InternalSynchronizableRepository getRepository(String name)
+ {
+ return (InternalSynchronizableRepository)super.getRepository(name);
+ }
+
+ @Override
public synchronized Map<String, Object> getTestProperties()
{
Map<String, Object> testProperties = super.getTestProperties();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/FailoverTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/FailoverTest.java
index b06e0726af..0c16b59c9d 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/FailoverTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/FailoverTest.java
@@ -14,7 +14,6 @@ import org.eclipse.emf.cdo.common.CDOCommonRepository;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.session.CDOSession;
import org.eclipse.emf.cdo.spi.server.InternalRepository;
-import org.eclipse.emf.cdo.spi.server.InternalSynchronizableRepository;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.transaction.CDOTransaction;
@@ -66,18 +65,6 @@ public class FailoverTest extends AbstractSyncingTest
return true;
}
- @Override
- public InternalSynchronizableRepository getRepository()
- {
- return (InternalSynchronizableRepository)super.getRepository();
- }
-
- @Override
- public InternalSynchronizableRepository getRepository(String name)
- {
- return (InternalSynchronizableRepository)super.getRepository(name);
- }
-
public void testMasterCommits_ArrivalInBackup() throws Exception
{
CDOSession session = openSession(getRepository().getName() + "_master");
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/OfflineRawTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/OfflineRawTest.java
index f44febc3a7..7e05569819 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/OfflineRawTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/OfflineRawTest.java
@@ -175,7 +175,7 @@ public class OfflineRawTest extends OfflineTest
*/
public void testSyncProgressEvents() throws Exception
{
- InternalSynchronizableRepository clone = (InternalSynchronizableRepository)getRepository();
+ InternalSynchronizableRepository clone = getRepository();
waitForOnline(clone);
CDOSession session = openSession();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_312879_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_312879_Test.java
index 73827f4a0f..219dfb4938 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_312879_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_312879_Test.java
@@ -68,18 +68,6 @@ public class Bugzilla_312879_Test extends AbstractSyncingTest
return true;
}
- @Override
- public InternalSynchronizableRepository getRepository()
- {
- return (InternalSynchronizableRepository)super.getRepository();
- }
-
- @Override
- public InternalSynchronizableRepository getRepository(String name)
- {
- return (InternalSynchronizableRepository)super.getRepository(name);
- }
-
public void testSwitchMasterAndCommit() throws Exception
{
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_325097_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_325097_Test.java
new file mode 100644
index 0000000000..38ae2427f8
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_325097_Test.java
@@ -0,0 +1,131 @@
+/**
+ * Copyright (c) 2004 - 2010 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.emf.cdo.tests.bugzilla;
+
+import org.eclipse.emf.cdo.common.CDOCommonRepository;
+import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.session.CDOSession;
+import org.eclipse.emf.cdo.spi.server.InternalSynchronizableRepository;
+import org.eclipse.emf.cdo.tests.AbstractSyncingTest;
+import org.eclipse.emf.cdo.tests.model1.Company;
+import org.eclipse.emf.cdo.transaction.CDOTransaction;
+
+import org.eclipse.net4j.acceptor.IAcceptor;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+
+/**
+ * @author Eike Stepper
+ */
+public class Bugzilla_325097_Test extends AbstractSyncingTest
+{
+ @Override
+ protected boolean isRawReplication()
+ {
+ return true;
+ }
+
+ @Override
+ protected boolean isFailover()
+ {
+ return true;
+ }
+
+ private IAcceptor backupAcceptor;
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+ stopBackupTransport();
+ }
+
+ protected void startBackupTransport()
+ {
+ if (backupAcceptor == null)
+ {
+ IOUtil.OUT().println();
+ IOUtil.OUT().println("startBackupTransport()");
+ IOUtil.OUT().println();
+ IManagedContainer container = getServerContainer();
+ backupAcceptor = (IAcceptor)container.getElement("org.eclipse.net4j.acceptors", "jvm", "backup");
+ }
+ }
+
+ protected void stopBackupTransport()
+ {
+ if (backupAcceptor != null)
+ {
+ IOUtil.OUT().println();
+ IOUtil.OUT().println("stopBackupTransport()");
+ IOUtil.OUT().println();
+ backupAcceptor.close();
+ backupAcceptor = null;
+ }
+ }
+
+ public void testNewObjectAfterSwitch() throws Exception
+ {
+ InternalSynchronizableRepository repo1_master = getRepository(getRepository().getName() + "_master");
+ InternalSynchronizableRepository repo1 = getRepository();
+
+ InternalSynchronizableRepository master = repo1_master;
+ InternalSynchronizableRepository backup = repo1;
+
+ CDOSession session = openSession(master.getName());
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.createResource("/my/resource");
+
+ Company company = getModel1Factory().createCompany();
+ company.setName("Test");
+
+ resource.getContents().add(company);
+ transaction.setCommitComment("Company created");
+ transaction.commit();
+
+ sleep(1000);
+
+ startBackupTransport();
+ repo1.setType(CDOCommonRepository.Type.MASTER);
+ repo1_master.setType(CDOCommonRepository.Type.BACKUP);
+
+ master = repo1;
+ backup = repo1_master;
+
+ assertEquals(CDOCommonRepository.Type.MASTER, master.getType());
+ assertEquals(CDOCommonRepository.Type.BACKUP, backup.getType());
+
+ // make sure the backup repository is in sync
+ waitForOnline(backup);
+
+ session.close();
+ session = openSession(master.getName());
+
+ // make sure we are running the session on the master
+ assertEquals(CDOCommonRepository.Type.MASTER, session.getRepositoryInfo().getType());
+ transaction = session.openTransaction();
+
+ resource = transaction.getResource("/my/resource");
+ company = (Company)resource.getContents().get(0);
+
+ // Create a new company
+ company = getModel1Factory().createCompany();
+ company.setName("Test2");
+
+ resource.getContents().add(company);
+ transaction.commit();
+
+ session.close();
+ LifecycleUtil.deactivate(backup);
+ LifecycleUtil.deactivate(master);
+ }
+}

Back to the top