Skip to content

Commit

Permalink
SEBSP-116 fixes and better group handling (TODOs for performance impr…
Browse files Browse the repository at this point in the history
…ovements)
  • Loading branch information
anhefti committed Nov 14, 2024
1 parent 7cfc327 commit 21e2ec0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,6 @@ public void updateGroupSize(
final Integer totalCount) {

try {

UpdateDSL
.updateWithMapper(
this.screenProctoringGroopRecordMapper::update,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.function.Predicate;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -81,8 +83,6 @@ public class ExamSessionServiceImpl implements ExamSessionService {
private final boolean distributedSetup;
private final long distributedConnectionUpdate;

private long lastConnectionTokenCacheUpdate = 0;

protected ExamSessionServiceImpl(
final ExamSessionCacheService examSessionCacheService,
final ExamDAO examDAO,
Expand Down Expand Up @@ -600,15 +600,24 @@ public Result<Exam> flushCache(final Exam exam) {
// If we are in a distributed setup the active connection token cache get flushed
// in specified time interval. This allows caching over multiple monitoring requests but
// ensure an update every now and then for new incoming connections
private long lastConnectionTokenCacheUpdate = 0;
private final Set<Long> examIds = ConcurrentHashMap.newKeySet();
private void updateClientConnections(final Long examId) {
try {
if (!this.distributedSetup) {
return;
}

final long currentTimeMillis = System.currentTimeMillis();
if (this.distributedSetup &&
currentTimeMillis - this.lastConnectionTokenCacheUpdate > this.distributedConnectionUpdate) {
if (currentTimeMillis - this.lastConnectionTokenCacheUpdate > this.distributedConnectionUpdate) {
examIds.clear();
this.lastConnectionTokenCacheUpdate = currentTimeMillis;
}

if (!examIds.contains(examId)) {

// go through all client connection and update the ones that not up to date
this.clientConnectionDAO.evictConnectionTokenCache(examId);

final Set<Long> timestamps = this.clientConnectionDAO
.getConnectionTokens(examId)
.getOrThrow()
Expand All @@ -622,7 +631,7 @@ private void updateClientConnections(final Long examId) {
.getOrElse(Collections::emptySet)
.forEach(this.examSessionCacheService::evictClientConnection);

this.lastConnectionTokenCacheUpdate = currentTimeMillis;
examIds.add(examId);
}
} catch (final Exception e) {
log.error("Unexpected error while trying to update client connections: ", e);
Expand Down

0 comments on commit 21e2ec0

Please sign in to comment.