From 41a1d0ad5f82023c3d1317eec2da424c8631bc42 Mon Sep 17 00:00:00 2001 From: Ken Stevens Date: Wed, 19 Jul 2023 20:31:47 -0400 Subject: [PATCH] add extra logging to troubleshoot partition creation (#5108) Co-authored-by: Ken Stevens --- .../jpa/partition/PartitionLookupSvcImpl.java | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/partition/PartitionLookupSvcImpl.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/partition/PartitionLookupSvcImpl.java index 473cf6145f7..d7c9a371a18 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/partition/PartitionLookupSvcImpl.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/partition/PartitionLookupSvcImpl.java @@ -53,6 +53,7 @@ import java.util.Optional; import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; +import java.util.stream.Collectors; import javax.annotation.Nonnull; import javax.annotation.PostConstruct; @@ -270,12 +271,21 @@ public class PartitionLookupSvcImpl implements IPartitionLookupSvc { } private PartitionEntity lookupPartitionById(@Nonnull Integer theId) { - return executeInTransaction(() -> myPartitionDao.findById(theId)).orElseThrow(() -> { - String msg = myFhirCtx - .getLocalizer() - .getMessageSanitized(PartitionLookupSvcImpl.class, "unknownPartitionId", theId); - return new ResourceNotFoundException(msg); - }); + try { + return executeInTransaction(() -> myPartitionDao.findById(theId)).orElseThrow(() -> { + String msg = myFhirCtx + .getLocalizer() + .getMessageSanitized(PartitionLookupSvcImpl.class, "unknownPartitionId", theId); + return new ResourceNotFoundException(msg); + }); + } catch (ResourceNotFoundException e) { + List allPartitions = executeInTransaction(() -> myPartitionDao.findAll()); + String allPartitionsString = allPartitions.stream() + .map(t -> t.getId() + "/" + t.getName()) + .collect(Collectors.joining(", ")); + ourLog.warn("Failed to find partition with ID {}. Current partitions: {}", theId, allPartitionsString); + throw e; + } } protected T executeInTransaction(ICallable theCallable) {