svn commit: r1604363 - in /ofbiz/trunk/framework/service: entitydef/entitymodel.xml src/org/ofbiz/service/ServiceDispatcher.java src/org/ofbiz/service/semaphore/ServiceSemaphore.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r1604363 - in /ofbiz/trunk/framework/service: entitydef/entitymodel.xml src/org/ofbiz/service/ServiceDispatcher.java src/org/ofbiz/service/semaphore/ServiceSemaphore.java

jleroux@apache.org
Author: jleroux
Date: Sat Jun 21 13:27:20 2014
New Revision: 1604363

URL: http://svn.apache.org/r1604363
Log:
A patch from Leon for "No lock can be acquired after ofbiz application crashes." https://issues.apache.org/jira/browse/OFBIZ-5626

We have a service which semaphore set to "fail". Someday, while it was running, the whole ofbiz crashed.
After the restart, the service is unable to run anymore since the lock file (database record in ServiceSemaphore entity) is already there.


Modified:
    ofbiz/trunk/framework/service/entitydef/entitymodel.xml
    ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
    ofbiz/trunk/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java

Modified: ofbiz/trunk/framework/service/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/entitydef/entitymodel.xml?rev=1604363&r1=1604362&r2=1604363&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/framework/service/entitydef/entitymodel.xml Sat Jun 21 13:27:20 2014
@@ -192,6 +192,7 @@ under the License.
     <entity entity-name="ServiceSemaphore" package-name="org.ofbiz.service.semaphore" title="Semaphore Lock Entity"
             sequence-bank-size="100">
         <field name="serviceName" type="name"></field>
+        <field name="lockedByInstanceId" type="id"></field>
         <field name="lockThread" type="name"></field>
         <field name="lockTime" type="date-time"></field>
         <prim-key field="serviceName"/>

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=1604363&r1=1604362&r2=1604363&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Sat Jun 21 13:27:20 2014
@@ -105,6 +105,18 @@ public class ServiceDispatcher {
             }
         }
 
+        // clean up the service semaphores of same instance
+        if (delegator != null) {
+            try {
+                int rn = delegator.removeByAnd("ServiceSemaphore", "lockedByInstanceId", JobManager.instanceId);
+                if (rn > 0) {
+                    Debug.logInfo("[ServiceDispatcher.init] : Clean up " + rn + " service semaphors." , module);
+                }
+            } catch (GenericEntityException e) {
+                Debug.logError(e, module);
+            }
+        }
+        
         // job manager needs to always be running, but the poller thread does not
         try {
             Delegator origDelegator = this.delegator;

Modified: ofbiz/trunk/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java?rev=1604363&r1=1604362&r2=1604363&view=diff
==============================================================================
--- ofbiz/trunk/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java (original)
+++ ofbiz/trunk/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java Sat Jun 21 13:27:20 2014
@@ -30,6 +30,7 @@ import org.ofbiz.entity.GenericValue;
 import org.ofbiz.entity.transaction.GenericTransactionException;
 import org.ofbiz.entity.transaction.TransactionUtil;
 import org.ofbiz.service.ModelService;
+import org.ofbiz.service.job.JobManager;
 
 /**
  * ServiceSemaphore
@@ -72,7 +73,9 @@ public class ServiceSemaphore {
         if (mode == SEMAPHORE_MODE_NONE) return;
 
         // remove the lock file
-        dbWrite(lock, true);
+        if (lock != null) {
+            dbWrite(lock, true);
+        }
     }
 
     private void waitOrFail() throws SemaphoreWaitException, SemaphoreFailException {
@@ -123,7 +126,7 @@ public class ServiceSemaphore {
         }
 
         if (semaphore == null) {
-            semaphore = delegator.makeValue("ServiceSemaphore", "serviceName", model.name, "lockThread", threadName, "lockTime", lockTime);
+            semaphore = delegator.makeValue("ServiceSemaphore", "serviceName", model.name, "lockedByInstanceId", JobManager.instanceId, "lockThread", threadName, "lockTime", lockTime);
 
             // use the special method below so we can reuse the unqiue tx functions
             dbWrite(semaphore, false);