Skip to content

Commit

Permalink
Avoid optimistic locking exceptions in clusters (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanpelikan committed Sep 30, 2024
1 parent cd8138f commit b301c75
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
5 changes: 5 additions & 0 deletions spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
<artifactId>spring-tx</artifactId>
<version>6.1.3</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>6.1.10</version>
</dependency>
<dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.time.OffsetDateTime;
import java.util.List;
import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.orm.ObjectOptimisticLockingFailureException;
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
Expand All @@ -30,7 +31,7 @@ public DeploymentService(

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Retryable(
retryFor = OptimisticLockingFailureException.class,
retryFor = { OptimisticLockingFailureException.class, ObjectOptimisticLockingFailureException.class },
maxAttempts = 100,
backoff = @Backoff(delay = 100, maxDelay = 500))
public DeployedBpmn addBpmn(
Expand Down Expand Up @@ -62,16 +63,37 @@ public DeployedBpmn recoverAddBpmn(
final int fileId,
final String resourceName) {

return recoverAddBpmn(exception, model, fileId, resourceName);

}

@Recover
public DeployedBpmn recoverAddBpmn(
final ObjectOptimisticLockingFailureException exception,
final BpmnModelInstance model,
final int fileId,
final String resourceName) {

return recoverAddBpmn(exception, model, fileId, resourceName);

}

private DeployedBpmn recoverAddBpmn(
final Exception exception,
final BpmnModelInstance model,
final int fileId,
final String resourceName) {

throw new RuntimeException(
"Could not save BPMN '"
+ resourceName
+ "' in local DB due to stale OptimisticLockingFailureException", exception);
+ resourceName
+ "' in local DB due to stale OptimisticLockingFailureException", exception);

}

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Retryable(
retryFor = OptimisticLockingFailureException.class,
retryFor = { OptimisticLockingFailureException.class, ObjectOptimisticLockingFailureException.class },
maxAttempts = 100,
backoff = @Backoff(delay = 100, maxDelay = 500))
public DeployedProcess addProcess(
Expand Down Expand Up @@ -107,6 +129,27 @@ public DeployedProcess recoverAddProcess(
final Process camunda8DeployedProcess,
final DeployedBpmn bpmn) {

return recoverAddProcess(exception, packageId, camunda8DeployedProcess, bpmn);

}

@Recover
public DeployedProcess recoverAddProcess(
final ObjectOptimisticLockingFailureException exception,
final int packageId,
final Process camunda8DeployedProcess,
final DeployedBpmn bpmn) {

return recoverAddProcess(exception, packageId, camunda8DeployedProcess, bpmn);

}

private DeployedProcess recoverAddProcess(
final Exception exception,
final int packageId,
final Process camunda8DeployedProcess,
final DeployedBpmn bpmn) {

throw new RuntimeException(
"Could not save Process '"
+ camunda8DeployedProcess.getBpmnProcessId()
Expand Down

0 comments on commit b301c75

Please sign in to comment.