jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From marti...@apache.org
Subject svn commit: r814597 - in /jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: data/db/ fs/db/ journal/ persistence/bundle/ util/db/
Date Mon, 14 Sep 2009 12:05:28 GMT
Author: martijnh
Date: Mon Sep 14 12:05:28 2009
New Revision: 814597

URL: http://svn.apache.org/viewvc?rev=814597&view=rev
Log:
JCR-1456 Database connection pooling

* Handle DB connection loss

Modified:
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DerbyDataStore.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystem.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/OracleDatabaseJournal.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DerbyConnectionHelper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/Oracle10R1ConnectionHelper.java
    jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/OracleConnectionHelper.java

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DbDataStore.java
Mon Sep 14 12:05:28 2009
@@ -584,7 +584,7 @@
      * @throws Exception on error
      */
     protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
-        return new ConnectionHelper(dataSrc);
+        return new ConnectionHelper(dataSrc, false);
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DerbyDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DerbyDataStore.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DerbyDataStore.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/DerbyDataStore.java
Mon Sep 14 12:05:28 2009
@@ -35,7 +35,7 @@
      */
     @Override
     protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
-        return new DerbyConnectionHelper(dataSrc);
+        return new DerbyConnectionHelper(dataSrc, false);
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
Mon Sep 14 12:05:28 2009
@@ -227,7 +227,7 @@
      * @throws Exception on error
      */
     protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
-        return new ConnectionHelper(dataSrc);
+        return new ConnectionHelper(dataSrc, false);
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystem.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystem.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DerbyFileSystem.java
Mon Sep 14 12:05:28 2009
@@ -91,7 +91,7 @@
      */
     @Override
     protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
-        return new DerbyConnectionHelper(dataSrc);
+        return new DerbyConnectionHelper(dataSrc, false);
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java
Mon Sep 14 12:05:28 2009
@@ -96,7 +96,7 @@
      */
     @Override
     protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
-        Oracle10R1ConnectionHelper helper = new Oracle10R1ConnectionHelper(dataSrc);
+        Oracle10R1ConnectionHelper helper = new Oracle10R1ConnectionHelper(dataSrc, false);
         helper.init();
         return helper;
     }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/DatabaseJournal.java
Mon Sep 14 12:05:28 2009
@@ -284,7 +284,7 @@
      * @throws Exception on error
      */
     protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
-        return new ConnectionHelper(dataSrc);
+        return new ConnectionHelper(dataSrc, false);
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/OracleDatabaseJournal.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/OracleDatabaseJournal.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/OracleDatabaseJournal.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/OracleDatabaseJournal.java
Mon Sep 14 12:05:28 2009
@@ -42,7 +42,7 @@
      */
     @Override
     protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
-        OracleConnectionHelper helper = new OracleConnectionHelper(dataSrc);
+        OracleConnectionHelper helper = new OracleConnectionHelper(dataSrc, false);
         helper.init();
         return helper;
     }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/BundleDbPersistenceManager.java
Mon Sep 14 12:05:28 2009
@@ -411,16 +411,10 @@
         return errorHandling.toString();
     }
 
-    /**
-     * @deprecated
-     */
     public void setBlockOnConnectionLoss(String block) {
         this.blockOnConnectionLoss = Boolean.valueOf(block).booleanValue();
     }
 
-    /**
-     * @deprecated
-     */
     public String getBlockOnConnectionLoss() {
         return Boolean.toString(blockOnConnectionLoss);
     }
@@ -549,7 +543,7 @@
      * @throws Exception on error
      */
     protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
-        return new ConnectionHelper(dataSrc);
+        return new ConnectionHelper(dataSrc, blockOnConnectionLoss);
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/DerbyPersistenceManager.java
Mon Sep 14 12:05:28 2009
@@ -268,7 +268,7 @@
      */
     @Override
     protected ConnectionHelper createConnectionHelper(DataSource dataSrc) {
-        return new DerbyConnectionHelper(dataSrc);
+        return new DerbyConnectionHelper(dataSrc, blockOnConnectionLoss);
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java
Mon Sep 14 12:05:28 2009
@@ -44,7 +44,7 @@
      */
     @Override
     protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
-        Oracle10R1ConnectionHelper helper = new Oracle10R1ConnectionHelper(dataSrc);
+        Oracle10R1ConnectionHelper helper = new Oracle10R1ConnectionHelper(dataSrc, blockOnConnectionLoss);
         helper.init();
         return helper;
     }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/OraclePersistenceManager.java
Mon Sep 14 12:05:28 2009
@@ -111,7 +111,7 @@
      */
     @Override
     protected ConnectionHelper createConnectionHelper(DataSource dataSrc) throws Exception
{
-        OracleConnectionHelper helper = new OracleConnectionHelper(dataSrc);
+        OracleConnectionHelper helper = new OracleConnectionHelper(dataSrc, blockOnConnectionLoss);
         helper.init();
         return helper;
     }

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/ConnectionHelper.java
Mon Sep 14 12:05:28 2009
@@ -34,6 +34,8 @@
 
     private static final int RETRIES = 1;
 
+    private final boolean blockOnConnectionLoss;
+
     private final boolean checkTablesWithUserName;
 
     protected final DataSource dataSource;
@@ -43,24 +45,25 @@
     private Connection batchConnection = null;
 
     /**
-     * Constructor.
-     * 
      * @param dataSrc the {@link DataSource} on which this instance acts
+     * @param block whether the helper should transparantly block on DB connection loss (otherwise
it retries
+     *            once and if that fails throws exception)
      */
-    public ConnectionHelper(DataSource dataSrc) {
+    public ConnectionHelper(DataSource dataSrc, boolean block) {
         dataSource = dataSrc;
         checkTablesWithUserName = false;
+        blockOnConnectionLoss = block;
     }
 
     /**
-     * Constructor, typically used for Oracle subtypes.
-     * 
      * @param dataSrc the {@link DataSource} on which this instance acts
      * @param checkWithUserName whether the username is to be used for the {@link #tableExists(String)}
method
+     * @param block whether the helper should transparantly block on DB connection loss (otherwise
it throws exceptions)
      */
-    protected ConnectionHelper(DataSource dataSrc, boolean checkWithUserName) {
+    protected ConnectionHelper(DataSource dataSrc, boolean checkWithUserName, boolean block)
{
         dataSource = dataSrc;
         checkTablesWithUserName = checkWithUserName;
+        blockOnConnectionLoss = block;
     }
     
     /**
@@ -163,7 +166,6 @@
         if (inBatchMode) {
             throw new IllegalStateException("already in batch mode");
         }
-        // Invariant: inBatchMode == false && batchConnection == null
         try {
             batchConnection = getConnection();
             batchConnection.setAutoCommit(false);
@@ -341,7 +343,7 @@
         if (inBatchMode) {
             return batchConnection;
         } else {
-            Connection con = dataSource.getConnection();
+            Connection con = getConnectionFromDS();
             // JCR-1013: Setter may fail unnecessarily on a managed connection
             if (!con.getAutoCommit()) {
                 con.setAutoCommit(true);
@@ -351,6 +353,35 @@
     }
 
     /**
+     * This method retries if {@code dataSource.getConnection()} throws an SQLException and
sleeping
+     * is not interrupted. This can happen when the database server is down.
+     * 
+     * @return a {@code Connection}
+     * @throws SQLException on error
+     */
+    private Connection getConnectionFromDS() throws SQLException {
+        Connection con = null;
+        SQLException lastException = null;
+        boolean sleepInterrupted = false;
+        int failures = 0;
+        while (con == null && !sleepInterrupted && (blockOnConnectionLoss
|| failures <= RETRIES)) {
+            try {
+                return dataSource.getConnection();
+            } catch (SQLException e) {
+                failures++;
+                lastException = e;
+                try {
+                    Thread.sleep(100);
+                } catch (InterruptedException e1) {
+                    Thread.currentThread().interrupt();
+                    sleepInterrupted = true;
+                }
+            }
+        }
+        throw lastException; // guaranteed to be non-null
+    }
+
+    /**
      * Closes the given resources given the {@code batchMode} state.
      * 
      * @param con the {@code Connection} obtained through the {@link #getConnection()} method

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DerbyConnectionHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DerbyConnectionHelper.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DerbyConnectionHelper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/DerbyConnectionHelper.java
Mon Sep 14 12:05:28 2009
@@ -37,9 +37,10 @@
 
     /**
      * @param dataSrc the {@link DataSource} on which this helper acts
+     * @param block
      */
-    public DerbyConnectionHelper(DataSource dataSrc) {
-        super(dataSrc);
+    public DerbyConnectionHelper(DataSource dataSrc, boolean block) {
+        super(dataSrc, block);
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/Oracle10R1ConnectionHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/Oracle10R1ConnectionHelper.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/Oracle10R1ConnectionHelper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/Oracle10R1ConnectionHelper.java
Mon Sep 14 12:05:28 2009
@@ -51,9 +51,10 @@
 
     /**
      * @param dataSrc
+     * @param block
      */
-    public Oracle10R1ConnectionHelper(DataSource dataSrc) {
-        super(dataSrc);
+    public Oracle10R1ConnectionHelper(DataSource dataSrc, boolean block) {
+        super(dataSrc, block);
     }
 
     /**

Modified: jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/OracleConnectionHelper.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/OracleConnectionHelper.java?rev=814597&r1=814596&r2=814597&view=diff
==============================================================================
--- jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/OracleConnectionHelper.java
(original)
+++ jackrabbit/sandbox/JCR-1456/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/util/db/OracleConnectionHelper.java
Mon Sep 14 12:05:28 2009
@@ -37,9 +37,10 @@
 
     /**
      * @param dataSrc
+     * @param block
      */
-    public OracleConnectionHelper(DataSource dataSrc) {
-        super(dataSrc, true);
+    public OracleConnectionHelper(DataSource dataSrc, boolean block) {
+        super(dataSrc, true, block);
     }
 
     public void init() throws Exception {



Mime
View raw message