Cleanup logging

This commit is contained in:
jamesagnew 2021-07-04 15:31:10 -04:00
parent 3bafdd7de1
commit 6bb5cbf764
2 changed files with 22 additions and 3 deletions

View File

@ -55,4 +55,15 @@ public class ResourceVersionConflictException extends BaseServerResponseExceptio
super(STATUS_CODE, theMessage, theOperationOutcome);
}
/**
* Constructor
*
* @param theMessage
* The message
* @param theOperationOutcome The OperationOutcome resource to return to the client
*/
public ResourceVersionConflictException(String theMessage, Throwable theCause, IBaseOperationOutcome theOperationOutcome) {
super(STATUS_CODE, theMessage, theCause, theOperationOutcome);
}
}

View File

@ -32,6 +32,7 @@ import ca.uhn.fhir.rest.server.exceptions.ResourceVersionConflictException;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.rest.server.util.CompositeInterceptorBroadcaster;
import com.google.common.annotations.VisibleForTesting;
import org.hl7.fhir.instance.model.api.IBaseOperationOutcome;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -115,19 +116,26 @@ public class HapiTransactionService {
theTransactionDetails.clearResolvedItems();
theTransactionDetails.clearUserData(BaseHapiFhirDao.XACT_USERDATA_KEY_RESOLVED_TAG_DEFINITIONS);
theTransactionDetails.clearUserData(BaseHapiFhirDao.XACT_USERDATA_KEY_EXISTING_SEARCH_PARAMS);
sleepAtLeast(250, false);
double sleepAmount = (250.0d * i) * Math.random();
long sleepAmountLong = (long) sleepAmount;
sleepAtLeast(sleepAmountLong, false);
ourLog.info("About to start a transaction retry due to conflict or constraint error");
ourLog.info("About to start a transaction retry due to conflict or constraint error. Sleeping {}ms first.", sleepAmountLong);
continue;
}
IBaseOperationOutcome oo = null;
if (e instanceof ResourceVersionConflictException) {
oo = ((ResourceVersionConflictException) e).getOperationOutcome();
}
if (maxRetries > 0) {
String msg = "Max retries (" + maxRetries + ") exceeded for version conflict: " + e.getMessage();
ourLog.info(msg, maxRetries);
throw new ResourceVersionConflictException(msg);
}
throw e;
throw new ResourceVersionConflictException(e.getMessage(), e, oo);
}
}