incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1004915 - /incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
Date Wed, 06 Oct 2010 07:30:19 GMT
Author: kwright
Date: Wed Oct  6 07:30:19 2010
New Revision: 1004915

URL: http://svn.apache.org/viewvc?rev=1004915&view=rev
Log:
Try to deal with Derby's unique ability to deadlock without a transaction, by retrying modification
statements that seem to generate internal deadlocks.  Part of CONNECTORS-111.

Modified:
    incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java

Modified: incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java?rev=1004915&r1=1004914&r2=1004915&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
(original)
+++ incubator/lcf/trunk/modules/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
Wed Oct  6 07:30:19 2010
@@ -611,7 +611,7 @@ public class DBInterfaceDerby extends Da
     // Note well: We also have to treat 'duplicate key' as a transaction abort, since this
is what you get when two threads attempt to
     // insert the same row.  (Everything only works, then, as long as there is a unique constraint
corresponding to every bad insert that
     // one could make.)
-    if (sqlState != null && sqlState.equals("23505"))
+    if (sqlState != null && sqlState.equals("23505") && inTransaction)
       return new ManifoldCFException(message,e,ManifoldCFException.DATABASE_TRANSACTION_ABORT);
     // Deadlock also aborts.
     if (sqlState != null && sqlState.equals("40001"))
@@ -629,13 +629,42 @@ public class DBInterfaceDerby extends Da
   public void performModification(String query, ArrayList params, StringSet invalidateKeys)
     throws ManifoldCFException
   {
-    try
-    {
-      executeQuery(query,params,null,invalidateKeys,null,false,0,null,null);
-    }
-    catch (ManifoldCFException e)
+    while (true)
     {
-      throw reinterpretException(e);
+      try
+      {
+        try
+        {
+          executeQuery(query,params,null,invalidateKeys,null,false,0,null,null);
+          return;
+        }
+        catch (ManifoldCFException e)
+        {
+          throw reinterpretException(e);
+        }
+      }
+      catch (ManifoldCFException e)
+      {
+        // If this is a transaction abort, and we are NOT in a transaction, then repeat the
request after
+        // a delay.  This is because Derby is perfectly capable of deadlocking itself even
without any involved transactions, but
+        // ManifoldCF doesn't expect deadlocks to arise in any way other than through a transaction.
 See CONNECTORS-111.
+        if (e.getErrorCode() != ManifoldCFException.DATABASE_TRANSACTION_ABORT)
+          throw e;
+        // Check if we are in a transaction
+        if (inTransaction)
+          throw e;
+        // Unique key constraints generate transaction abort signals only when they are in
a transaction, so we are safe in
+        // assuming the exception is the result of internal deadlock alone.
+        // Wait a short time.
+        try
+        {
+          ManifoldCF.sleep(1000L);
+        }
+        catch (InterruptedException e2)
+        {
+          throw new ManifoldCFException(e.getMessage(),e,ManifoldCFException.INTERRUPTED);
+        }
+      }
     }
   }
 



Mime
View raw message