You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2014/06/21 15:28:22 UTC

svn commit: r1604365 - in /ofbiz/branches/release12.04: ./ framework/service/entitydef/entitymodel.xml framework/service/src/org/ofbiz/service/ServiceDispatcher.java framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java

Author: jleroux
Date: Sat Jun 21 13:28:21 2014
New Revision: 1604365

URL: http://svn.apache.org/r1604365
Log:
"Applied fix from trunk for revision: 1604363  " 
------------------------------------------------------------------------
r1604363 | jleroux | 2014-06-21 15:27:20 +0200 (sam. 21 juin 2014) | 6 lignes

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/branches/release12.04/   (props changed)
    ofbiz/branches/release12.04/framework/service/entitydef/entitymodel.xml
    ofbiz/branches/release12.04/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
    ofbiz/branches/release12.04/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java

Propchange: ofbiz/branches/release12.04/
------------------------------------------------------------------------------
  Merged /ofbiz/trunk:r1604363

Modified: ofbiz/branches/release12.04/framework/service/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/service/entitydef/entitymodel.xml?rev=1604365&r1=1604364&r2=1604365&view=diff
==============================================================================
--- ofbiz/branches/release12.04/framework/service/entitydef/entitymodel.xml (original)
+++ ofbiz/branches/release12.04/framework/service/entitydef/entitymodel.xml Sat Jun 21 13:28:21 2014
@@ -190,6 +190,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/branches/release12.04/framework/service/src/org/ofbiz/service/ServiceDispatcher.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=1604365&r1=1604364&r2=1604365&view=diff
==============================================================================
--- ofbiz/branches/release12.04/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original)
+++ ofbiz/branches/release12.04/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Sat Jun 21 13:28:21 2014
@@ -104,6 +104,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/branches/release12.04/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java?rev=1604365&r1=1604364&r2=1604365&view=diff
==============================================================================
--- ofbiz/branches/release12.04/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java (original)
+++ ofbiz/branches/release12.04/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java Sat Jun 21 13:28:21 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);