Skip to content

Commit eb77841

Browse files
committed
JBTM-3911 Replace synchronized in favor of Reentrant Lock
in LRAService joinLRA method
1 parent 6798bcc commit eb77841

File tree

7 files changed

+517
-303
lines changed

7 files changed

+517
-303
lines changed

rts/lra/coordinator/src/main/java/io/narayana/lra/coordinator/domain/model/LongRunningAction.java

+23-14
Original file line numberDiff line numberDiff line change
@@ -726,23 +726,32 @@ protected LRAStatus toLRAStatus(int atomicActionStatus) {
726726

727727
public LRAParticipantRecord enlistParticipant(URI coordinatorUrl, String participantUrl, String recoveryUrlBase,
728728
long timeLimit, String compensatorData) throws UnsupportedEncodingException {
729-
LRAParticipantRecord participant = findLRAParticipant(participantUrl, false);
730-
731-
if (participant != null) {
732-
participant.setCompensatorData(compensatorData);
733-
return participant; // must have already been enlisted
729+
ReentrantLock lock = tryLockTransaction();
730+
if (lock == null) {
731+
LRALogger.i18nLogger.warn_enlistment();
732+
return null;
734733
}
735-
736-
participant = doEnlistParticipant(coordinatorUrl, participantUrl, recoveryUrlBase,
737-
timeLimit, compensatorData);
738-
739-
if (participant != null) {
740-
// need to remember that there is a new participant
741-
deactivate(); // if it fails the superclass will have logged a warning
742-
savedIntentionList = true; // need this clean up if the LRA times out
734+
else {
735+
try {
736+
LRAParticipantRecord participant = findLRAParticipant(participantUrl, false);
737+
if (participant != null) {
738+
participant.setCompensatorData(compensatorData);
739+
return participant; // must have already been enlisted
740+
}
741+
participant = doEnlistParticipant(coordinatorUrl, participantUrl, recoveryUrlBase, timeLimit,
742+
compensatorData);
743+
if (participant != null) {
744+
// need to remember that there is a new participant
745+
deactivate(); // if it fails the superclass will have logged a warning
746+
savedIntentionList = true; // need this clean up if the LRA times out
747+
}
748+
return participant;
749+
}
750+
finally {
751+
lock.unlock();
752+
}
743753
}
744754

745-
return participant;
746755
}
747756

748757
private LRAParticipantRecord doEnlistParticipant(URI coordinatorUrl, String participantUrl, String recoveryUrlBase,

rts/lra/coordinator/src/main/java/io/narayana/lra/coordinator/domain/service/LRAService.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public int leave(URI lraId, String compensatorUrl) {
328328
}
329329
}
330330

331-
public synchronized int joinLRA(StringBuilder recoveryUrl, URI lra, long timeLimit,
331+
public int joinLRA(StringBuilder recoveryUrl, URI lra, long timeLimit,
332332
String compensatorUrl, String linkHeader, String recoveryUrlBase,
333333
StringBuilder compensatorData) {
334334
if (lra == null) {

0 commit comments

Comments
 (0)