Skip to content

Commit

Permalink
Issue #2195 - Add additional logging
Browse files Browse the repository at this point in the history
Signed-off-by: Troy Biesterfeld <tbieste@us.ibm.com>
  • Loading branch information
tbieste committed Jul 12, 2021
1 parent 3928f09 commit a7c6fe2
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,7 @@ public int reindex(FHIRPersistenceContext context, OperationOutcome.Builder oper
log.entering(CLASSNAME, METHODNAME);

int result = 0;
ResourceIndexRecord rir = null;

if (log.isLoggable(Level.FINE)) {
log.fine("reindex tstamp=" + tstamp.toString());
Expand All @@ -2514,6 +2515,10 @@ public int reindex(FHIRPersistenceContext context, OperationOutcome.Builder oper
throw new FHIRPersistenceException("Reindex tstamp cannot be in the future");
}

if (indexIds != null) {
log.info("Reindex requested for index IDs " + indexIds);
}

try (Connection connection = openConnection()) {
ResourceDAO resourceDao = makeResourceDAO(connection);
ParameterDAO parameterDao = makeParameterDAO(connection);
Expand Down Expand Up @@ -2542,7 +2547,6 @@ public int reindex(FHIRPersistenceContext context, OperationOutcome.Builder oper

// If list of indexIds was specified, loop over those. Otherwise, since we skip over
// deleted resources we have to loop until we find something not deleted, or reach the end.
ResourceIndexRecord rir;
do {
long start = System.nanoTime();
rir = reindexDAO.getResourceToReindex(tstamp, indexIds != null ? indexIds.get(indexIdsProcessed++) : null, resourceTypeId, logicalId);
Expand All @@ -2556,7 +2560,9 @@ public int reindex(FHIRPersistenceContext context, OperationOutcome.Builder oper
if (rir != null) {

// This is important so we log it as info
log.info("Reindexing FHIR Resource '" + rir.getResourceType() + "/" + rir.getLogicalId() + "'");
if (log.isLoggable(Level.FINE)) {
log.fine("Reindexing FHIR Resource '" + rir.getResourceType() + "/" + rir.getLogicalId() + "'");
}

// Read the current resource
com.ibm.fhir.persistence.jdbc.dto.Resource existingResourceDTO = resourceDao.read(rir.getLogicalId(), rir.getResourceType());
Expand All @@ -2581,28 +2587,30 @@ public int reindex(FHIRPersistenceContext context, OperationOutcome.Builder oper

} catch(FHIRPersistenceFKVException e) {
getTransaction().setRollbackOnly();
log.log(Level.SEVERE, "Unexpected error while performing reindex" + (rir != null ? (" of FHIR Resource '" + rir.getResourceType() + "/" + rir.getLogicalId() + "'") : ""), e);
throw e;
} catch(FHIRPersistenceException e) {
getTransaction().setRollbackOnly();
log.log(Level.SEVERE, "Unexpected error while performing reindex" + (rir != null ? (" of FHIR Resource '" + rir.getResourceType() + "/" + rir.getLogicalId() + "'") : ""), e);
throw e;
} catch (DataAccessException dax) {
getTransaction().setRollbackOnly();

// It's possible this is a deadlock exception, in which case it could be considered retryable
if (dax.isTransactionRetryable()) {
log.log(Level.WARNING, "retryable error", dax);
log.log(Level.WARNING, "Retryable error while performing reindex" + (rir != null ? (" of FHIR Resource '" + rir.getResourceType() + "/" + rir.getLogicalId() + "'") : ""), dax);
FHIRPersistenceDataAccessException fpx = new FHIRPersistenceDataAccessException("Data access error while performing a reindex operation.");
fpx.setTransactionRetryable(true);
throw fpx;
} else {
log.log(Level.SEVERE, "non-retryable error", dax);
log.log(Level.SEVERE, "Non-retryable error while performing reindex" + (rir != null ? (" of FHIR Resource '" + rir.getResourceType() + "/" + rir.getLogicalId() + "'") : ""), dax);
throw new FHIRPersistenceDataAccessException("Data access error while performing a reindex operation.");
}
} catch(Throwable e) {
getTransaction().setRollbackOnly();
log.log(Level.SEVERE, "Unexpected error while performing a reindex" + (rir != null ? (" of FHIR Resource '" + rir.getResourceType() + "/" + rir.getLogicalId() + "'") : ""), e);
// don't chain the exception to avoid leaking secrets
FHIRPersistenceException fx = new FHIRPersistenceException("Unexpected error while performing a reindex operation.");
log.log(Level.SEVERE, fx.getMessage(), e);
throw fx;
} finally {
log.exiting(CLASSNAME, METHODNAME);
Expand Down

0 comments on commit a7c6fe2

Please sign in to comment.