Skip to content

DT-1184: update db retry catch to use new exception class #1895

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

Merged
merged 4 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
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.transaction.TransactionSystemException;

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 +47,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 | TransactionSystemException 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,10 @@
import bio.terra.stairway.StepResult;
import bio.terra.stairway.StepStatus;
import bio.terra.stairway.exception.RetryException;
import java.util.HashMap;
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 +36,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, Map.class);
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,8 +9,9 @@
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;
import org.springframework.transaction.TransactionSystemException;

public class DeleteSnapshotMetadataStep implements Step {

Expand All @@ -32,7 +33,7 @@ public StepResult doStep(FlightContext context) {
: DeleteResponseModel.ObjectStateEnum.NOT_FOUND;
} catch (SnapshotNotFoundException ex) {
stateEnum = DeleteResponseModel.ObjectStateEnum.NOT_FOUND;
} catch (CannotSerializeTransactionException ex) {
} catch (TransientDataAccessException | TransactionSystemException 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 All @@ -30,7 +30,7 @@ class CountSnapshotTableRowsStepTest {
@Mock private BigQuerySnapshotPdao bigQuerySnapshotPdao;
@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);
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 @@ -15,14 +15,15 @@
import bio.terra.stairway.StepResult;
import bio.terra.stairway.StepStatus;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
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 +32,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 Map<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 +61,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
Loading