Author: jleroux
Date: Sat Jun 21 13:28:11 2014 New Revision: 1604364 URL: http://svn.apache.org/r1604364 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/release13.07/ (props changed) ofbiz/branches/release13.07/framework/service/entitydef/entitymodel.xml ofbiz/branches/release13.07/framework/service/src/org/ofbiz/service/ServiceDispatcher.java ofbiz/branches/release13.07/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java Propchange: ofbiz/branches/release13.07/ ------------------------------------------------------------------------------ Merged /ofbiz/trunk:r1604363 Modified: ofbiz/branches/release13.07/framework/service/entitydef/entitymodel.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/service/entitydef/entitymodel.xml?rev=1604364&r1=1604363&r2=1604364&view=diff ============================================================================== --- ofbiz/branches/release13.07/framework/service/entitydef/entitymodel.xml (original) +++ ofbiz/branches/release13.07/framework/service/entitydef/entitymodel.xml Sat Jun 21 13:28:11 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/branches/release13.07/framework/service/src/org/ofbiz/service/ServiceDispatcher.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/service/src/org/ofbiz/service/ServiceDispatcher.java?rev=1604364&r1=1604363&r2=1604364&view=diff ============================================================================== --- ofbiz/branches/release13.07/framework/service/src/org/ofbiz/service/ServiceDispatcher.java (original) +++ ofbiz/branches/release13.07/framework/service/src/org/ofbiz/service/ServiceDispatcher.java Sat Jun 21 13:28:11 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/branches/release13.07/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release13.07/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java?rev=1604364&r1=1604363&r2=1604364&view=diff ============================================================================== --- ofbiz/branches/release13.07/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java (original) +++ ofbiz/branches/release13.07/framework/service/src/org/ofbiz/service/semaphore/ServiceSemaphore.java Sat Jun 21 13:28:11 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); |
Free forum by Nabble | Edit this page |