From: <sp...@us...> - 2012-01-27 06:37:34
|
Revision: 8634 http://geonetwork.svn.sourceforge.net/geonetwork/?rev=8634&view=rev Author: sppigot Date: 2012-01-27 06:37:27 +0000 (Fri, 27 Jan 2012) Log Message: ----------- Allow configuration of transaction isolation in dbcp config Modified Paths: -------------- trunk/docs/eng/users/source/admin/advanced-configuration/index.rst trunk/jeeves/src/main/java/jeeves/constants/Jeeves.java trunk/jeeves/src/main/java/jeeves/resources/dbms/AbstractDbmsPool.java trunk/jeeves/src/main/java/jeeves/resources/dbms/ApacheDBCPool.java Modified: trunk/docs/eng/users/source/admin/advanced-configuration/index.rst =================================================================== --- trunk/docs/eng/users/source/admin/advanced-configuration/index.rst 2012-01-27 01:58:02 UTC (rev 8633) +++ trunk/docs/eng/users/source/admin/advanced-configuration/index.rst 2012-01-27 06:37:27 UTC (rev 8634) @@ -36,9 +36,9 @@ The parameters that can be specified to control the Apache Database Connection Pool are described at http://commons.apache.org/dbcp/configuration.html. You can configure a subset of these parameters in your resource element. The parameters that can be specified are: -=================================== ===================================================================== ================================ +=================================== ===================================================================== ========================================= Parameter Description Default -=================================== ===================================================================== ================================ +=================================== ===================================================================== ========================================= maxActive pool size/maximum number of active connections 10 maxIdle maximum number of idle connections maxActive minIdle minimum number of idle connections 0 @@ -48,8 +48,8 @@ testWhileIdle test connections when idle false minEvictableIdleTimeMillis idle time before connection can be evicted 30 x 60 x 1000 msecs numTestsPerEvictionRun number of connections tested per eviction run 3 -defaultTransactionIsolation see http://en.wikipedia.org/wiki/Isolation_%28database_systems%29 SERIALIZABLE (except for Oracle) -=================================== ===================================================================== ================================ +defaultTransactionIsolation see http://en.wikipedia.org/wiki/Isolation_%28database_systems%29 SERIALIZABLE (for Oracle READ_COMMITTED) +=================================== ===================================================================== ========================================= The following parameters are set by GeoNetwork and cannot be configured by the user: @@ -75,7 +75,7 @@ **Note:** - When GeoNetwork manages the database connection pool, PostGIS database is the only database that can hold the spatial index in the database. All other database choices hold the spatial index as a shapefile. If using PostGIS, two pools of database connections are created. The first is managed and configured using parameters in this section, the second is created by GeoTools and cannot be configured. If you want to use the database to hold the spatial index you should use the JNDI configuration described in the next section because it uses a single, configurable database pool through GeoTools. -- The Oracle database should not be configured to use SERIALIZABLE as the transaction isolation level (use READ_COMMITTED instead) - SERIALIZABLE seems to cause a lot of failed Oracle transactions. +- advanced: if you are using the subversion metadata history/versioning feature, you should set the default transaction isolation to SERIALIZED ie. you should have `<defaultTransactionIsolation>SERIALIZABLE</defaultTransactionIsolation>` in your database config. The reason for this is that prior to a commit the current state of a versioned metadata record and its properties (privileges, status, owner, categories) is read and stored in the subversion repository. If transactions are not serialized then there is a small chance that another transaction may commit other/more changes before the changes to the metadata state in the current transaction are recorded. The exception to this rule is ORACLE which appears to fail to serialize transactions that other systems serialize without issues. Do not use SERIALIZABLE with Oracle, instead use READ_COMMITTED. For more on transaction isolation see http://en.wikipedia.org/wiki/Isolation_%28database_systems%29. Database connection pool managed by the container Modified: trunk/jeeves/src/main/java/jeeves/constants/Jeeves.java =================================================================== --- trunk/jeeves/src/main/java/jeeves/constants/Jeeves.java 2012-01-27 01:58:02 UTC (rev 8633) +++ trunk/jeeves/src/main/java/jeeves/constants/Jeeves.java 2012-01-27 06:37:27 UTC (rev 8634) @@ -258,6 +258,10 @@ public static final String CONTEXT = "context"; public static final String RESOURCE_NAME = "resourceName"; public static final String PROVIDE_DATA_STORE = "provideDataStore"; + public static final String TRANSACTION_ISOLATION = "defaultTransactionIsolation"; + public static final String TRANSACTION_ISOLATION_READ_COMMITTED = "READ_COMMITTED"; + public static final String TRANSACTION_ISOLATION_SERIALIZABLE = "SERIALIZABLE"; + public static final String TRANSACTION_ISOLATION_REPEATABLE_READ = "REPEATABLE_READ"; } } Modified: trunk/jeeves/src/main/java/jeeves/resources/dbms/AbstractDbmsPool.java =================================================================== --- trunk/jeeves/src/main/java/jeeves/resources/dbms/AbstractDbmsPool.java 2012-01-27 01:58:02 UTC (rev 8633) +++ trunk/jeeves/src/main/java/jeeves/resources/dbms/AbstractDbmsPool.java 2012-01-27 06:37:27 UTC (rev 8634) @@ -233,6 +233,12 @@ //--------------------------------------------------------------------------- + protected void warning(String message) { + Log.warning(Log.DBMSPOOL, message); + } + + //--------------------------------------------------------------------------- + } // ============================================================================= Modified: trunk/jeeves/src/main/java/jeeves/resources/dbms/ApacheDBCPool.java =================================================================== --- trunk/jeeves/src/main/java/jeeves/resources/dbms/ApacheDBCPool.java 2012-01-27 01:58:02 UTC (rev 8633) +++ trunk/jeeves/src/main/java/jeeves/resources/dbms/ApacheDBCPool.java 2012-01-27 06:37:27 UTC (rev 8634) @@ -24,7 +24,9 @@ package jeeves.resources.dbms; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; import java.sql.Connection; import javax.sql.DataSource; @@ -67,16 +69,6 @@ parseJeevesDBConfig(config); - if (!basicDataSource.getUrl().toUpperCase().contains("ORACLE")) { - // Use TRANSACTION_SERIALIZABLE for everything as we don't want - // commits coming in whilst doing reads esp during audit trail changes - // collected for subversion - basicDataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE); - } else { - // except for ORACLE because it returns unable to serialize a lot - basicDataSource.setDefaultTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED); - } - setDataSource((DataSource)basicDataSource); setDataStore(createDataStore()); debug(toString()); @@ -101,6 +93,24 @@ String minEvictableIdleTimeMillisStr = config.getChildText(Jeeves.Res.Pool.MIN_EVICTABLE_IDLE_TIME_MILLIS); String numTestsPerEvictionRunStr = config.getChildText(Jeeves.Res.Pool.NUM_TESTS_PER_EVICTION_RUN); String validationQuery = config.getChildText(Jeeves.Res.Pool.VALIDATION_QUERY); + String transactionIsolation = config.getChildText(Jeeves.Res.Pool.TRANSACTION_ISOLATION); + if (transactionIsolation == null) { + // use SERIALIZABLE for everything by default except ORACLE which + // returns way too many cannot SERIALIZE errors - use READ_COMMITTED + // for that + transactionIsolation = Jeeves.Res.Pool.TRANSACTION_ISOLATION_SERIALIZABLE; + if (url.toUpperCase().contains("ORACLE")) transactionIsolation = Jeeves.Res.Pool.TRANSACTION_ISOLATION_READ_COMMITTED; + } else { + Set<String> isolations = new HashSet<String>(); + isolations.add(Jeeves.Res.Pool.TRANSACTION_ISOLATION_SERIALIZABLE); + isolations.add(Jeeves.Res.Pool.TRANSACTION_ISOLATION_READ_COMMITTED); + isolations.add(Jeeves.Res.Pool.TRANSACTION_ISOLATION_REPEATABLE_READ); + + if (!isolations.contains(transactionIsolation.toUpperCase())) { + throw new IllegalArgumentException("Invalid "+Jeeves.Res.Pool.TRANSACTION_ISOLATION+" parameter value: "+transactionIsolation+". Should be one of "+isolations.toString()); + } + } + warning("Using transaction isolation setting "+transactionIsolation); this.name = url; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |