Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relaxes race condition with autosetup a little #1952

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/main/java/sirius/biz/process/Processes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -326,21 +326,24 @@ 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<String> tenantNameSupplier) {
String lockName = LOCK_CREATE_STANDBY_PROCESS + "-" + type + "-" + tenantId;
if (!locks.tryLock(lockName, Duration.ofSeconds(30))) {
throw Exceptions.handle()
.withSystemErrorMessage(
"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();
}
Expand All @@ -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);
}
Expand Down