summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaspar De Groot2011-04-04 05:07:30 (EDT)
committerCaspar De Groot2011-04-04 05:07:30 (EDT)
commit21506966c051b2c1b1cebd0258d0ef4e719ebe3c (patch)
tree369381a999aa8317ae0892b0fb0881a8ee425f06
parentcd3e3f4641eac18c87c7e63ef45ecb1a62accb5a (diff)
downloadcdo-21506966c051b2c1b1cebd0258d0ef4e719ebe3c.zip
cdo-21506966c051b2c1b1cebd0258d0ef4e719ebe3c.tar.gz
cdo-21506966c051b2c1b1cebd0258d0ef4e719ebe3c.tar.bz2
[Bug 338894] [DB][Mysql] Exception when CDO is idle for a while
https://bugs.eclipse.org/bugs/show_bug.cgi?id=338894
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java38
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java36
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java12
10 files changed, 91 insertions, 37 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java
index fab364d..03e947a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java
@@ -56,4 +56,12 @@ public interface IDBStore extends IStore, IDBConnectionProvider
* @since 2.0
*/
public IDBStoreAccessor getWriter(ITransaction transaction);
+
+ /**
+ * @since 4.0
+ */
+ public interface Props
+ {
+ public static final String CONNECTION_KEEPALIVE_PERIOD = "connectionKeepAlivePeriod"; //$NON-NLS-1$
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
index cbbedc9..317f844 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
@@ -92,6 +92,8 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
private boolean firstTime;
+ private Map<String, String> properties;
+
// private IIDHandler idHandler = new StringIDHandler(this);
private IIDHandler idHandler = new LongIDHandler(this);
@@ -153,14 +155,24 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
return dbAdapter;
}
- public IIDHandler getIDHandler()
+ public void setDBAdapter(IDBAdapter dbAdapter)
{
- return idHandler;
+ this.dbAdapter = dbAdapter;
}
- public void setDBAdapter(IDBAdapter dbAdapter)
+ public void setProperties(Map<String, String> properties)
{
- this.dbAdapter = dbAdapter;
+ this.properties = properties;
+ }
+
+ public Map<String, String> getProperties()
+ {
+ return properties;
+ }
+
+ public IIDHandler getIDHandler()
+ {
+ return idHandler;
}
public Connection getConnection()
@@ -224,7 +236,7 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
return dbSchema;
}
- public Map<String, String> getPropertyValues(Set<String> names)
+ public Map<String, String> getPersistentProperties(Set<String> names)
{
Connection connection = null;
PreparedStatement selectStmt = null;
@@ -294,7 +306,7 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
}
}
- public void setPropertyValues(Map<String, String> properties)
+ public void setPersistentProperties(Map<String, String> properties)
{
Connection connection = null;
PreparedStatement deleteStmt = null;
@@ -337,7 +349,7 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
}
}
- public void removePropertyValues(Set<String> names)
+ public void removePersistentProperties(Set<String> names)
{
Connection connection = null;
PreparedStatement deleteStmt = null;
@@ -461,7 +473,7 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
Map<String, String> map = new HashMap<String, String>();
map.put(PROP_REPOSITORY_CREATED, Long.toString(creationTime));
- setPropertyValues(map);
+ setPersistentProperties(map);
}
public boolean isFirstStart()
@@ -543,7 +555,7 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
map.put(PROP_LAST_LOCAL_BRANCHID, Integer.toString(getLastLocalBranchID()));
map.put(PROP_LAST_COMMITTIME, Long.toString(getLastCommitTime()));
map.put(PROP_LAST_NONLOCAL_COMMITTIME, Long.toString(getLastNonLocalCommitTime()));
- setPropertyValues(map);
+ setPersistentProperties(map);
readerPool.dispose();
writerPool.dispose();
@@ -563,7 +575,7 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
Set<String> names = new HashSet<String>();
names.add(PROP_REPOSITORY_CREATED);
- Map<String, String> map = getPropertyValues(names);
+ Map<String, String> map = getPersistentProperties(names);
return map.get(PROP_REPOSITORY_CREATED) == null;
}
@@ -581,7 +593,7 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
names.add(PROP_REPOSITORY_CREATED);
names.add(PROP_GRACEFULLY_SHUT_DOWN);
- Map<String, String> map = getPropertyValues(names);
+ Map<String, String> map = getPersistentProperties(names);
creationTime = Long.valueOf(map.get(PROP_REPOSITORY_CREATED));
if (map.containsKey(PROP_GRACEFULLY_SHUT_DOWN))
@@ -593,7 +605,7 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
names.add(PROP_LAST_LOCAL_BRANCHID);
names.add(PROP_LAST_COMMITTIME);
names.add(PROP_LAST_NONLOCAL_COMMITTIME);
- map = getPropertyValues(names);
+ map = getPersistentProperties(names);
idHandler.setNextLocalObjectID(Store.stringToID(map.get(PROP_NEXT_LOCAL_CDOID)));
idHandler.setLastObjectID(Store.stringToID(map.get(PROP_LAST_CDOID)));
@@ -607,7 +619,7 @@ public class DBStore extends Store implements IDBStore, CDOAllRevisionsProvider
repairAfterCrash();
}
- removePropertyValues(Collections.singleton(PROP_GRACEFULLY_SHUT_DOWN));
+ removePersistentProperties(Collections.singleton(PROP_GRACEFULLY_SHUT_DOWN));
}
protected void repairAfterCrash()
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 77fcdec..0d57afc 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
@@ -10,6 +10,7 @@
* Stefan Winkler - bug 259402
* Stefan Winkler - 271444: [DB] Multiple refactorings bug 271444
* Andre Dietisheim - bug 256649
+ * Caspar De Groot - maintenance
*/
package org.eclipse.emf.cdo.server.internal.db;
@@ -36,6 +37,7 @@ import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IStoreAccessor;
import org.eclipse.emf.cdo.server.ITransaction;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
+import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IIDHandler;
import org.eclipse.emf.cdo.server.db.IMetaDataManager;
@@ -95,6 +97,7 @@ import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.TimerTask;
@@ -744,10 +747,22 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
@Override
protected void doActivate() throws Exception
{
- connection = getStore().getConnection();
+ DBStore store = getStore();
+ connection = store.getConnection();
connectionKeepAliveTask = new ConnectionKeepAliveTask();
- getStore().getConnectionKeepAliveTimer().schedule(connectionKeepAliveTask,
- ConnectionKeepAliveTask.EXECUTION_PERIOD, ConnectionKeepAliveTask.EXECUTION_PERIOD);
+
+ long keepAlivePeriod = ConnectionKeepAliveTask.EXECUTION_PERIOD;
+ Map<String, String> storeProps = store.getProperties();
+ if (storeProps != null)
+ {
+ String value = storeProps.get(IDBStore.Props.CONNECTION_KEEPALIVE_PERIOD);
+ if (value != null)
+ {
+ keepAlivePeriod = Long.parseLong(value) * 60L * 1000L;
+ }
+ }
+
+ store.getConnectionKeepAliveTimer().schedule(connectionKeepAliveTask, keepAlivePeriod, keepAlivePeriod);
// TODO - make this configurable?
statementCache = CDODBUtil.createStatementCache();
@@ -1284,6 +1299,21 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
stmt = connection.createStatement();
stmt.executeQuery("SELECT 1 FROM " + CDODBSchema.PROPERTIES); //$NON-NLS-1$
}
+ catch (java.sql.SQLException ex)
+ {
+ OM.LOG.error("DB connection keep-alive failed", ex); //$NON-NLS-1$
+
+ // Assume the connection has failed.
+ try
+ {
+ LifecycleUtil.deactivate(DBStoreAccessor.this);
+ LifecycleUtil.activate(DBStoreAccessor.this);
+ }
+ catch (Exception ex2)
+ {
+ OM.LOG.error("DB connection reconnect failed", ex2); //$NON-NLS-1$
+ }
+ }
catch (Exception ex) // Important: Do not throw any unchecked exceptions to the TimerThread!!!
{
OM.LOG.error("DB connection keep-alive failed", ex); //$NON-NLS-1$
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java
index f18f89d..2290289 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java
@@ -7,7 +7,8 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - 271444: [DB] Multiple refactorings bug 271444
+ * Stefan Winkler - 271444: [DB] Multiple refactorings bug 271444
+ * Caspar De Groot - maintenance
*/
package org.eclipse.emf.cdo.server.internal.db;
@@ -57,6 +58,9 @@ public class DBStoreFactory implements IStoreFactory
store.setDBAdapter(dbAdapter);
store.setDbConnectionProvider(connectionProvider);
+ Map<String, String> storeProperties = RepositoryConfigurator.getProperties(storeConfig, 1);
+ store.setProperties(storeProperties);
+
return store;
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
index 61a809f..1a91229 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
@@ -452,7 +452,7 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
if (resultSet.next())
{
CDOID id = idHandler.getCDOID(resultSet, 1);
- if (idHandler.compare(id, min) < 0)
+ if (id != null && idHandler.compare(id, min) < 0)
{
min = id;
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java
index 1ca20eb..901ee7a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java
@@ -105,7 +105,7 @@ public class DB4OStore extends LongIDStore implements IDB4OStore
return getServerInfo().isFirstTime();
}
- public Map<String, String> getPropertyValues(Set<String> names)
+ public Map<String, String> getPersistentProperties(Set<String> names)
{
if (names == null || names.isEmpty())
{
@@ -125,14 +125,14 @@ public class DB4OStore extends LongIDStore implements IDB4OStore
return result;
}
- public void setPropertyValues(Map<String, String> properties)
+ public void setPersistentProperties(Map<String, String> properties)
{
ServerInfo serverInfo = getServerInfo();
serverInfo.getProperties().putAll(properties);
commitServerInfo(null);
}
- public void removePropertyValues(Set<String> names)
+ public void removePersistentProperties(Set<String> names)
{
ServerInfo serverInfo = getServerInfo();
Map<String, String> properties = serverInfo.getProperties();
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java
index c6c8b62..ca873d6 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate/src/org/eclipse/emf/cdo/server/internal/hibernate/HibernateStore.java
@@ -350,17 +350,17 @@ public class HibernateStore extends Store implements IHibernateStore
return new HibernateStoreAccessor(this, transaction);
}
- public Map<String, String> getPropertyValues(Set<String> names)
+ public Map<String, String> getPersistentProperties(Set<String> names)
{
return packageHandler.getSystemProperties();
}
- public void setPropertyValues(Map<String, String> properties)
+ public void setPersistentProperties(Map<String, String> properties)
{
packageHandler.setSystemProperties(properties);
}
- public void removePropertyValues(Set<String> names)
+ public void removePersistentProperties(Set<String> names)
{
// TODO: implement HibernateStore.removePropertyValues(names)
throw new UnsupportedOperationException();
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java
index d750f09..3143f3a 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/mem/MEMStore.java
@@ -126,7 +126,7 @@ public class MEMStore extends LongIDStore implements IMEMStore, BranchLoader
this(UNLIMITED);
}
- public synchronized Map<String, String> getPropertyValues(Set<String> names)
+ public synchronized Map<String, String> getPersistentProperties(Set<String> names)
{
if (names == null || names.isEmpty())
{
@@ -146,12 +146,12 @@ public class MEMStore extends LongIDStore implements IMEMStore, BranchLoader
return result;
}
- public synchronized void setPropertyValues(Map<String, String> properties)
+ public synchronized void setPersistentProperties(Map<String, String> properties)
{
this.properties.putAll(properties);
}
- public synchronized void removePropertyValues(Set<String> names)
+ public synchronized void removePersistentProperties(Set<String> names)
{
for (String name : names)
{
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java
index ae3ba3f..6cb74c5 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/syncing/SynchronizableRepository.java
@@ -344,7 +344,7 @@ public abstract class SynchronizableRepository extends Repository.Default implem
InternalStore store = getStore();
if (!store.isFirstStart())
{
- Map<String, String> map = store.getPropertyValues(Collections.singleton(PROP_GRACEFULLY_SHUT_DOWN));
+ Map<String, String> map = store.getPersistentProperties(Collections.singleton(PROP_GRACEFULLY_SHUT_DOWN));
if (!map.containsKey(PROP_GRACEFULLY_SHUT_DOWN))
{
setReplicationCountersToLatest();
@@ -355,13 +355,13 @@ public abstract class SynchronizableRepository extends Repository.Default implem
names.add(PROP_LAST_REPLICATED_BRANCH_ID);
names.add(PROP_LAST_REPLICATED_COMMIT_TIME);
- map = store.getPropertyValues(names);
+ map = store.getPersistentProperties(names);
setLastReplicatedBranchID(Integer.valueOf(map.get(PROP_LAST_REPLICATED_BRANCH_ID)));
setLastReplicatedCommitTime(Long.valueOf(map.get(PROP_LAST_REPLICATED_COMMIT_TIME)));
}
}
- store.removePropertyValues(Collections.singleton(PROP_GRACEFULLY_SHUT_DOWN));
+ store.removePersistentProperties(Collections.singleton(PROP_GRACEFULLY_SHUT_DOWN));
if (getType() != MASTER)
{
@@ -380,7 +380,7 @@ public abstract class SynchronizableRepository extends Repository.Default implem
map.put(PROP_GRACEFULLY_SHUT_DOWN, Boolean.TRUE.toString());
InternalStore store = getStore();
- store.setPropertyValues(map);
+ store.setPersistentProperties(map);
super.doDeactivate();
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
index b47bffd..5b747cb 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStore.java
@@ -115,19 +115,19 @@ public interface IStore
* Returns a map filled with the property entries for the requested property <code>names</code> if names is not
* <code>null</code> and not {@link Collection#isEmpty() empty}, all existing property entries otherwise.
*
- * @since 3.0
+ * @since 4.0
*/
- public Map<String, String> getPropertyValues(Set<String> names);
+ public Map<String, String> getPersistentProperties(Set<String> names);
/**
- * @since 3.0
+ * @since 4.0
*/
- public void setPropertyValues(Map<String, String> properties);
+ public void setPersistentProperties(Map<String, String> properties);
/**
- * @since 3.0
+ * @since 4.0
*/
- public void removePropertyValues(Set<String> names);
+ public void removePersistentProperties(Set<String> names);
/**
* Returns a reader that can be used to read from this store in the context of the given session.