Skip to content

Commit

Permalink
DT-1184: update db retry catch to use new exception class
Browse files Browse the repository at this point in the history
  • Loading branch information
pshapiro4broad committed Jan 27, 2025
1 parent de7b190 commit 731142a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.CannotSerializeTransactionException;
import org.springframework.dao.TransientDataAccessException;

public class CreateDatasetMetadataStep implements Step {

private DatasetDao datasetDao;
private DatasetRequestModel datasetRequest;
private final DatasetDao datasetDao;
private final DatasetRequestModel datasetRequest;

private static Logger logger = LoggerFactory.getLogger(CreateDatasetMetadataStep.class);
private static final Logger logger = LoggerFactory.getLogger(CreateDatasetMetadataStep.class);

public CreateDatasetMetadataStep(DatasetDao datasetDao, DatasetRequestModel datasetRequest) {
this.datasetDao = datasetDao;
Expand All @@ -46,7 +46,7 @@ public StepResult doStep(FlightContext context) {
return StepResult.getStepResultSuccess();
} catch (InvalidDatasetException idEx) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, idEx);
} catch (CannotSerializeTransactionException ex) {
} catch (TransientDataAccessException ex) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, ex);
} catch (Exception ex) {
return new StepResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.CannotSerializeTransactionException;
import org.springframework.dao.TransientDataAccessException;
import org.springframework.transaction.TransactionSystemException;

public class CountSnapshotTableRowsStep implements Step {
Expand All @@ -39,8 +39,8 @@ public StepResult doStep(FlightContext flightContext)
Map<String, Long> tableRowCounts = bigQuerySnapshotPdao.getSnapshotTableRowCounts(snapshot);
try {
snapshotDao.updateSnapshotTableRowCounts(snapshot, tableRowCounts);
} catch (CannotSerializeTransactionException | TransactionSystemException ex) {
logger.error("Could not serialize the transaction. Retrying.", ex);
} catch (TransientDataAccessException | TransactionSystemException ex) {
logger.error("Transaction failed due to a transient error. Retrying.", ex);
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, ex);
}
return StepResult.getStepResultSuccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import bio.terra.stairway.StepResult;
import bio.terra.stairway.StepStatus;
import bio.terra.stairway.exception.RetryException;
import java.util.HashMap;
import com.fasterxml.jackson.core.type.TypeReference;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.CannotSerializeTransactionException;
import org.springframework.dao.TransientDataAccessException;
import org.springframework.transaction.TransactionSystemException;

public class CreateSnapshotCountTableRowsAzureStep implements Step {
Expand All @@ -37,11 +37,11 @@ public StepResult doStep(FlightContext flightContext)
FlightMap workingMap = flightContext.getWorkingMap();
Snapshot snapshot = snapshotDao.retrieveSnapshotByName(snapshotReq.getName());
Map<String, Long> tableRowCounts =
workingMap.get(SnapshotWorkingMapKeys.TABLE_ROW_COUNT_MAP, HashMap.class);
workingMap.get(SnapshotWorkingMapKeys.TABLE_ROW_COUNT_MAP, new TypeReference<>() {});
try {
snapshotDao.updateSnapshotTableRowCounts(snapshot, tableRowCounts);
} catch (CannotSerializeTransactionException | TransactionSystemException ex) {
logger.error("Could not serialize the transaction. Retrying.", ex);
} catch (TransientDataAccessException | TransactionSystemException ex) {
logger.error("Transaction failed due to a transient error. Retrying.", ex);
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, ex);
}
return StepResult.getStepResultSuccess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.CannotSerializeTransactionException;
import org.springframework.dao.TransientDataAccessException;
import org.springframework.http.HttpStatus;
import org.springframework.transaction.TransactionSystemException;

Expand Down Expand Up @@ -71,8 +71,8 @@ public StepResult doStep(FlightContext context) {
} catch (SnapshotNotFoundException ex) {
FlightUtils.setErrorResponse(context, ex.toString(), HttpStatus.BAD_REQUEST);
return new StepResult(StepStatus.STEP_RESULT_FAILURE_FATAL, ex);
} catch (CannotSerializeTransactionException | TransactionSystemException ex) {
logger.error("Could not serialize the transaction. Retrying.", ex);
} catch (TransientDataAccessException | TransactionSystemException ex) {
logger.error("Transaction failed due to a transient error. Retrying.", ex);
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, ex);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import bio.terra.stairway.StepResult;
import bio.terra.stairway.StepStatus;
import java.util.UUID;
import org.springframework.dao.CannotSerializeTransactionException;
import org.springframework.dao.TransientDataAccessException;
import org.springframework.http.HttpStatus;

public class DeleteSnapshotMetadataStep implements Step {
Expand All @@ -32,7 +32,7 @@ public StepResult doStep(FlightContext context) {
: DeleteResponseModel.ObjectStateEnum.NOT_FOUND;
} catch (SnapshotNotFoundException ex) {
stateEnum = DeleteResponseModel.ObjectStateEnum.NOT_FOUND;
} catch (CannotSerializeTransactionException ex) {
} catch (TransientDataAccessException ex) {
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, ex);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.dao.CannotSerializeTransactionException;
import org.springframework.dao.CannotAcquireLockException;

@ExtendWith(MockitoExtension.class)
@Tag(Unit.TAG)
Expand Down Expand Up @@ -58,7 +58,7 @@ void testDoStep() throws InterruptedException {
@Test
void testDoStepRetry() throws InterruptedException {
step = new CountSnapshotTableRowsStep(bigQuerySnapshotPdao, snapshotDao, snapshotReq);
doThrow(CannotSerializeTransactionException.class)
doThrow(CannotAcquireLockException.class)
.when(snapshotDao)
.updateSnapshotTableRowCounts(SNAPSHOT, tableRowCounts);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.dao.CannotSerializeTransactionException;
import org.springframework.dao.CannotAcquireLockException;

@ExtendWith(MockitoExtension.class)
@Tag(Unit.TAG)
Expand All @@ -31,23 +31,21 @@ class CreateSnapshotCountTableRowsAzureStepTest {
@Mock private SnapshotDao snapshotDao;
@Mock private FlightContext flightContext;

private FlightMap workingMap;

private static final UUID SNAPSHOT_ID = UUID.randomUUID();
private static final Snapshot SNAPSHOT =
new Snapshot().id(SNAPSHOT_ID).name("Snapshot-" + SNAPSHOT_ID);

private static final SnapshotRequestModel snapshotReq =
new SnapshotRequestModel().name(SNAPSHOT.getName());

private HashMap<String, Long> tableRowCounts = new HashMap<>();
private final HashMap<String, Long> tableRowCounts = new HashMap<>();
private CreateSnapshotCountTableRowsAzureStep step;

@BeforeEach
void setup() {
when(snapshotDao.retrieveSnapshotByName(SNAPSHOT.getName())).thenReturn(SNAPSHOT);
tableRowCounts.put("table", (long) 5);
workingMap = new FlightMap();
tableRowCounts.put("table", 5L);
FlightMap workingMap = new FlightMap();
workingMap.put(SnapshotWorkingMapKeys.TABLE_ROW_COUNT_MAP, tableRowCounts);
when(flightContext.getWorkingMap()).thenReturn(workingMap);
}
Expand All @@ -62,7 +60,7 @@ void testDoStep() throws InterruptedException {
@Test
void testDoStepRetry() throws InterruptedException {
step = new CreateSnapshotCountTableRowsAzureStep(snapshotDao, snapshotReq);
doThrow(CannotSerializeTransactionException.class)
doThrow(CannotAcquireLockException.class)
.when(snapshotDao)
.updateSnapshotTableRowCounts(SNAPSHOT, tableRowCounts);

Expand Down

0 comments on commit 731142a

Please sign in to comment.