mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: selectAndRemoveKmsLock tryLock fixed
parent
e647b286c6
commit
aecb0095b3
|
@ -88,6 +88,7 @@ public class KurentoSessionManager extends SessionManager {
|
||||||
/* Protected by Session.closingLock.readLock */
|
/* Protected by Session.closingLock.readLock */
|
||||||
public synchronized void joinRoom(Participant participant, String sessionId, Integer transactionId) {
|
public synchronized void joinRoom(Participant participant, String sessionId, Integer transactionId) {
|
||||||
Set<Participant> existingParticipants = null;
|
Set<Participant> existingParticipants = null;
|
||||||
|
boolean lockAcquired = false;
|
||||||
try {
|
try {
|
||||||
|
|
||||||
KurentoSession kSession = (KurentoSession) sessions.get(sessionId);
|
KurentoSession kSession = (KurentoSession) sessions.get(sessionId);
|
||||||
|
@ -107,24 +108,21 @@ public class KurentoSessionManager extends SessionManager {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (KmsManager.selectAndRemoveKmsLock.tryLock(MS_MAX_LOCK_WAIT, TimeUnit.SECONDS)) {
|
if (KmsManager.selectAndRemoveKmsLock.tryLock(MS_MAX_LOCK_WAIT, TimeUnit.SECONDS)) {
|
||||||
|
lockAcquired = true;
|
||||||
|
Kms lessLoadedKms = null;
|
||||||
try {
|
try {
|
||||||
Kms lessLoadedKms = null;
|
lessLoadedKms = this.kmsManager.getLessLoadedAndRunningKms();
|
||||||
try {
|
} catch (NoSuchElementException e) {
|
||||||
lessLoadedKms = this.kmsManager.getLessLoadedAndRunningKms();
|
// Restore session not active
|
||||||
} catch (NoSuchElementException e) {
|
this.cleanCollections(sessionId);
|
||||||
// Restore session not active
|
this.storeSessionNotActive(sessionNotActive);
|
||||||
this.cleanCollections(sessionId);
|
throw new OpenViduException(Code.ROOM_CANNOT_BE_CREATED_ERROR_CODE,
|
||||||
this.storeSessionNotActive(sessionNotActive);
|
"There is no available Media Node where to initialize session '" + sessionId + "'");
|
||||||
throw new OpenViduException(Code.ROOM_CANNOT_BE_CREATED_ERROR_CODE,
|
|
||||||
"There is no available Media Node where to initialize session '" + sessionId
|
|
||||||
+ "'");
|
|
||||||
}
|
|
||||||
log.info("KMS less loaded is {} with a load of {}", lessLoadedKms.getUri(),
|
|
||||||
lessLoadedKms.getLoad());
|
|
||||||
kSession = createSession(sessionNotActive, lessLoadedKms);
|
|
||||||
} finally {
|
|
||||||
KmsManager.selectAndRemoveKmsLock.unlock();
|
|
||||||
}
|
}
|
||||||
|
log.info("KMS less loaded is {} with a load of {}", lessLoadedKms.getUri(),
|
||||||
|
lessLoadedKms.getLoad());
|
||||||
|
kSession = createSession(sessionNotActive, lessLoadedKms);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String error = "Timeout of " + MS_MAX_LOCK_WAIT + " seconds waiting to acquire lock";
|
String error = "Timeout of " + MS_MAX_LOCK_WAIT + " seconds waiting to acquire lock";
|
||||||
log.error(error);
|
log.error(error);
|
||||||
|
@ -153,6 +151,10 @@ public class KurentoSessionManager extends SessionManager {
|
||||||
log.warn("PARTICIPANT {}: Error joining/creating session {}", participant.getParticipantPublicId(),
|
log.warn("PARTICIPANT {}: Error joining/creating session {}", participant.getParticipantPublicId(),
|
||||||
sessionId, e);
|
sessionId, e);
|
||||||
sessionEventsHandler.onParticipantJoined(participant, sessionId, null, transactionId, e);
|
sessionEventsHandler.onParticipantJoined(participant, sessionId, null, transactionId, e);
|
||||||
|
} finally {
|
||||||
|
if (lockAcquired) {
|
||||||
|
KmsManager.selectAndRemoveKmsLock.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (existingParticipants != null) {
|
if (existingParticipants != null) {
|
||||||
sessionEventsHandler.onParticipantJoined(participant, sessionId, existingParticipants, transactionId, null);
|
sessionEventsHandler.onParticipantJoined(participant, sessionId, existingParticipants, transactionId, null);
|
||||||
|
|
Loading…
Reference in New Issue