incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1190271 - in /incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database: DBInterfaceDerby.java DBInterfacePostgreSQL.java Database.java
Date Fri, 28 Oct 2011 12:25:21 GMT
Author: kwright
Date: Fri Oct 28 12:25:21 2011
New Revision: 1190271

URL: http://svn.apache.org/viewvc?rev=1190271&view=rev
Log:
Take steps to prohibit noteModification calls from taking place within transactions.  This
is the cause of at least one of the CONNECTORS-279 hangs.

Modified:
    incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
    incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
    incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java

Modified: incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java?rev=1190271&r1=1190270&r2=1190271&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
(original)
+++ incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfaceDerby.java
Fri Oct 28 12:25:21 2011
@@ -1197,7 +1197,8 @@ public class DBInterfaceDerby extends Da
   *@param modifyCount is the number of updates.
   *@param deleteCount is the number of deletions.
   */
-  public void noteModifications(String tableName, int insertCount, int modifyCount, int deleteCount)
+  @Override
+  protected void noteModificationsNoTransactions(String tableName, int insertCount, int modifyCount,
int deleteCount)
     throws ManifoldCFException
   {
     String tableStatisticsLock;

Modified: incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java?rev=1190271&r1=1190270&r2=1190271&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
(original)
+++ incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/DBInterfacePostgreSQL.java
Fri Oct 28 12:25:21 2011
@@ -1309,7 +1309,8 @@ public class DBInterfacePostgreSQL exten
   *@param modifyCount is the number of updates.
   *@param deleteCount is the number of deletions.
   */
-  public void noteModifications(String tableName, int insertCount, int modifyCount, int deleteCount)
+  @Override
+  protected void noteModificationsNoTransactions(String tableName, int insertCount, int modifyCount,
int deleteCount)
     throws ManifoldCFException
   {
     String tableStatisticsLock;

Modified: incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java?rev=1190271&r1=1190270&r2=1190271&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
(original)
+++ incubator/lcf/branches/CONNECTORS-284/framework/core/src/main/java/org/apache/manifoldcf/core/database/Database.java
Fri Oct 28 12:25:21 2011
@@ -48,6 +48,9 @@ public class Database
   protected Connection connection = null;
   protected boolean doRollback = false;
   protected int delayedTransactionDepth = 0;
+  protected Map<String,Modifications> modificationsSet = new HashMap<String,Modifications>();
+
+  protected static Random random = new Random();
 
   protected final static String _TRANSACTION_ = "_TRANSACTION_";
 
@@ -340,10 +343,31 @@ public class Database
       else
         cacheManager.commitTransaction(th.getTransactionID());
       th = parentTransaction;
+      if (th == null)
+      {
+        if (doRollback)
+          modificationsSet.clear();
+        else
+          playbackModifications();
+      }
     }
 
   }
 
+  /** Playback modifications */
+  private void playbackModifications()
+    throws ManifoldCFException
+  {
+    Iterator<String> modIterator = modificationsSet.keySet().iterator();
+    while (modIterator.hasNext())
+    {
+      String tableName = modIterator.next();
+      Modifications c = modificationsSet.get(tableName);
+      noteModificationsNoTransactions(tableName,c.getInsertCount(),c.getModifyCount(),c.getDeleteCount());
+    }
+    modificationsSet.clear();
+  }
+
   /** Note a number of inserts, modifications, or deletions to a specific table.  This is
so we can decide when to do appropriate maintenance.
   *@param tableName is the name of the table being modified.
   *@param insertCount is the number of inserts.
@@ -353,10 +377,29 @@ public class Database
   public void noteModifications(String tableName, int insertCount, int modifyCount, int deleteCount)
     throws ManifoldCFException
   {
+    if (th != null)
+    {
+      // In a transaction; record for later
+      Modifications c = modificationsSet.get(tableName);
+      if (c == null)
+      {
+        c = new Modifications();
+        modificationsSet.put(tableName,c);
+      }
+      c.update(insertCount,modifyCount,deleteCount);
+    }
+    else
+      noteModificationsNoTransactions(tableName,insertCount,modifyCount,deleteCount);
   }
 
-  protected static Random random = new Random();
-
+  /** Protected method for receiving information about inserts, modifications, or deletions
OUTSIDE of all transactions.
+  */
+  protected void noteModificationsNoTransactions(String tableName, int insertCount, int modifyCount,
int deleteCount)
+    throws ManifoldCFException
+  {
+  }
+  
+      
   /** Sleep a random amount of time after a transaction abort.
   */
   public long getSleepAmt()
@@ -383,6 +426,41 @@ public class Database
     }
   }
 
+  /** Class to keep track of modifications while we're in a transaction.
+  */
+  protected static class Modifications
+  {
+    protected int insertCount = 0;
+    protected int modifyCount = 0;
+    protected int deleteCount = 0;
+    
+    public Modifications()
+    {
+    }
+    
+    public void update(int insertCount, int modifyCount, int deleteCount)
+    {
+      this.insertCount += insertCount;
+      this.modifyCount += modifyCount;
+      this.deleteCount += deleteCount;
+    }
+    
+    public int getInsertCount()
+    {
+      return insertCount;
+    }
+    
+    public int getModifyCount()
+    {
+      return modifyCount;
+    }
+    
+    public int getDeleteCount()
+    {
+      return deleteCount;
+    }
+  }
+  
   /** Thread used to execute queries.  An instance of this thread is spun up every time a
query is executed.  This is necessary because JDBC does not
   * guarantee interruptability, and the Postgresql JDBC driver unfortunately eats all thread
interrupts.  So, we fire up a thread to do each interaction with
   * the database server, thus insuring that the owning thread remains interruptable and will
therefore not block shutdown.



Mime
View raw message