From 2935b92474dae228c2c9b28a3e273e0f025630fa Mon Sep 17 00:00:00 2001 From: Matthias Keck Date: Wed, 13 Mar 2024 15:10:45 +0100 Subject: [PATCH] Relaxes race condition with autosetup a little - when running on an empty db, autosetup might create a system tenant - we require the tenant's name at process creation, so wait a little longer before evaluating the supplier - this might be relevant in test scenarios where empty databases are used frequently Fixes: SIRI-939 --- .../java/sirius/biz/process/Processes.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/sirius/biz/process/Processes.java b/src/main/java/sirius/biz/process/Processes.java index 09d16da54..e2bbe3320 100644 --- a/src/main/java/sirius/biz/process/Processes.java +++ b/src/main/java/sirius/biz/process/Processes.java @@ -287,7 +287,7 @@ public void executeInStandbyProcess(String type, if (process != null) { modify(process.getId(), p -> p.getState() == ProcessState.STANDBY, p -> p.setStarted(LocalDateTime.now())); } else { - process = fetchStandbyProcessInLock(type, titleSupplier.get(), tenantId, tenantNameSupplier.get()); + process = fetchStandbyProcessInLock(type, titleSupplier.get(), tenantId, tenantNameSupplier); } partiallyExecute(process.getId(), task); @@ -326,13 +326,16 @@ private Process fetchStandbyProcess(String type, String tenantId) { /** * Tries to fetch the appropriate standby process while holding a lock and also after waiting an appropriate amount of time. * - * @param type the type of the standby process to find or create - * @param title the title of the process - * @param tenantId the id of the tenant used to find the appropriate process - * @param tenantName the name of the tenant + * @param type the type of the standby process to find or create + * @param title the title of the process + * @param tenantId the id of the tenant used to find the appropriate process + * @param tenantNameSupplier a supplier which yields the name of the tenant if the process has to be created * @return the process which was either resolved after waiting an appropriate amount of time or created */ - private Process fetchStandbyProcessInLock(String type, String title, String tenantId, String tenantName) { + private Process fetchStandbyProcessInLock(String type, + String title, + String tenantId, + Supplier tenantNameSupplier) { String lockName = LOCK_CREATE_STANDBY_PROCESS + "-" + type + "-" + tenantId; if (!locks.tryLock(lockName, Duration.ofSeconds(30))) { throw Exceptions.handle() @@ -340,7 +343,7 @@ private Process fetchStandbyProcessInLock(String type, String title, String tena "Cannot acquire a lock (%s} to create or fetch a standby process of type %s for %s (%s)", lockName, type, - tenantName, + tenantNameSupplier.get(), tenantId) .handle(); } @@ -358,7 +361,7 @@ private Process fetchStandbyProcessInLock(String type, String title, String tena Wait.millis(300); } - return createStandbyProcessInLock(type, title, tenantId, tenantName); + return createStandbyProcessInLock(type, title, tenantId, tenantNameSupplier.get()); } finally { locks.unlock(lockName); }