From dbbc69e22936cdfe44796c5987778ba3e04984cd Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 2 Jun 2022 16:57:30 +0200 Subject: [PATCH] mitigated client connection update concurrency --- .../dao/impl/ClientConnectionDAOImpl.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientConnectionDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientConnectionDAOImpl.java index 009fae8a..42892b07 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientConnectionDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ClientConnectionDAOImpl.java @@ -328,6 +328,11 @@ public class ClientConnectionDAOImpl implements ClientConnectionDAO { return Result.tryCatch(() -> { final long millisecondsNow = Utils.getMillisecondsNow(); + // NOTE: we use nanoseconds here to get a better precision to better avoid + // same value of real concurrent calls on distributed systems + // TODO: Better solution for the future would be to count this value and + // isolation is done via DB transaction + final long nanosecondsNow = System.nanoTime(); final ClientConnectionRecord newRecord = new ClientConnectionRecord( null, data.institutionId, @@ -340,7 +345,7 @@ public class ClientConnectionDAOImpl implements ClientConnectionDAO { BooleanUtils.toInteger(data.vdi, 1, 0, 0), data.vdiPairToken, millisecondsNow, - millisecondsNow, + nanosecondsNow, data.remoteProctoringRoomId, null, Utils.truncateText(data.sebMachineName, 255), @@ -359,7 +364,11 @@ public class ClientConnectionDAOImpl implements ClientConnectionDAO { public Result save(final ClientConnection data) { return Result.tryCatch(() -> { - final long millisecondsNow = Utils.getMillisecondsNow(); + // NOTE: we use nanoseconds here to get a better precision to better avoid + // same value of real concurrent calls on distributed systems + // TODO: Better solution for the future would be to count this value and + // isolation is done via DB transaction + final long nanosecondsNow = System.nanoTime(); final ClientConnectionRecord updateRecord = new ClientConnectionRecord( data.id, null, @@ -372,7 +381,7 @@ public class ClientConnectionDAOImpl implements ClientConnectionDAO { BooleanUtils.toInteger(data.vdi, 1, 0, 0), data.vdiPairToken, null, - millisecondsNow, + nanosecondsNow, null, null, Utils.truncateText(data.sebMachineName, 255),