camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r937976 - in /camel/trunk/components/camel-hawtdb/src: main/java/org/apache/camel/component/hawtdb/ test/java/org/apache/camel/component/hawtdb/
Date Mon, 26 Apr 2010 09:19:22 GMT
Author: davsclaus
Date: Mon Apr 26 09:19:19 2010
New Revision: 937976

URL: http://svn.apache.org/viewvc?rev=937976&view=rev
Log:
Added retry when optimistic error in hawtdb.

Modified:
    camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBFile.java
    camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadAndRecoverTest.java
    camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadConcurrentTest.java
    camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadTest.java

Modified: camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBFile.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBFile.java?rev=937976&r1=937975&r2=937976&view=diff
==============================================================================
--- camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBFile.java
(original)
+++ camel/trunk/components/camel-hawtdb/src/main/java/org/apache/camel/component/hawtdb/HawtDBFile.java
Mon Apr 26 09:19:19 2010
@@ -21,6 +21,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.fusesource.hawtdb.api.BTreeIndexFactory;
 import org.fusesource.hawtdb.api.Index;
+import org.fusesource.hawtdb.api.OptimisticUpdateException;
 import org.fusesource.hawtdb.api.Transaction;
 import org.fusesource.hawtdb.api.TxPageFile;
 import org.fusesource.hawtdb.api.TxPageFileFactory;
@@ -104,17 +105,8 @@ public class HawtDBFile extends TxPageFi
             LOG.trace("Executing work +++ start +++ " + work);
         }
 
-        T answer;
         Transaction tx = pageFile.tx();
-        try {
-            answer = work.execute(tx);
-            tx.commit();
-            pageFile.flush();
-        } catch (RuntimeException e) {
-            LOG.warn("Error executing work " + work + " will do rollback.", e);
-            tx.rollback();
-            throw e;
-        }
+        T answer = doExecute(work, tx, pageFile);
 
         if (LOG.isTraceEnabled()) {
             LOG.trace("Executing work +++ done  +++ " + work);
@@ -154,4 +146,39 @@ public class HawtDBFile extends TxPageFi
         return answer;
     }
 
+    private static <T> T doExecute(Work<T> work, Transaction tx, TxPageFile page)
{
+        T answer = null;
+
+        boolean done = false;
+        int attempt = 0;
+        while (!done) {
+            try {
+                // only log at DEBUG level if we are retrying
+                if (attempt > 0 && LOG.isDebugEnabled()) {
+                    LOG.debug("Attempt " + attempt + " to execute work " + work);
+                }
+                attempt++;
+
+                answer = work.execute(tx);
+                // commit work
+                tx.commit();
+                // and flush so we ensure data is spooled to disk
+                page.flush();
+                // and we are done
+                done = true;
+            } catch (OptimisticUpdateException e) {
+                // retry as we hit an optimistic update error
+                LOG.warn("OptimisticUpdateException occurred at attempt " + attempt + " executing
work " + work + " will do rollback and retry.");
+                // no harm doing rollback before retry and no wait is needed
+                tx.rollback();
+            } catch (RuntimeException e) {
+                LOG.warn("Error executing work " + work + " will do rollback.", e);
+                tx.rollback();
+                throw e;
+            }
+        }
+
+        return answer;
+    }
+
 }

Modified: camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadAndRecoverTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadAndRecoverTest.java?rev=937976&r1=937975&r2=937976&view=diff
==============================================================================
--- camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadAndRecoverTest.java
(original)
+++ camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadAndRecoverTest.java
Mon Apr 26 09:19:19 2010
@@ -32,7 +32,6 @@ import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
-@Ignore("Test manually as its aggressive on the file system with sync each write")
 public class HawtDBAggregateLoadAndRecoverTest extends CamelTestSupport {
 
     private static final Log LOG = LogFactory.getLog(HawtDBAggregateLoadAndRecoverTest.class);

Modified: camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadConcurrentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadConcurrentTest.java?rev=937976&r1=937975&r2=937976&view=diff
==============================================================================
--- camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadConcurrentTest.java
(original)
+++ camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadConcurrentTest.java
Mon Apr 26 09:19:19 2010
@@ -31,7 +31,6 @@ import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
-@Ignore("Test manually as its aggressive on the file system with sync each write")
 public class HawtDBAggregateLoadConcurrentTest extends CamelTestSupport {
 
     private static final Log LOG = LogFactory.getLog(HawtDBAggregateLoadConcurrentTest.class);

Modified: camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadTest.java?rev=937976&r1=937975&r2=937976&view=diff
==============================================================================
--- camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadTest.java
(original)
+++ camel/trunk/components/camel-hawtdb/src/test/java/org/apache/camel/component/hawtdb/HawtDBAggregateLoadTest.java
Mon Apr 26 09:19:19 2010
@@ -27,7 +27,6 @@ import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
-@Ignore("Test manually as its aggressive on the file system with sync each write")
 public class HawtDBAggregateLoadTest extends CamelTestSupport {
 
     private static final Log LOG = LogFactory.getLog(HawtDBAggregateLoadTest.class);



Mime
View raw message