From 0395bdea7854e354e61586386f831999303207b3 Mon Sep 17 00:00:00 2001 From: Angelo Caporaso <56113767+cap-ang@users.noreply.github.com> Date: Wed, 30 Oct 2024 15:08:43 +0100 Subject: [PATCH] [PAGOPA-2282] fix(delete-by-index): Add smallrye-fault-tolerance --- README.md | 5 +++++ performance-test/python-test/main.py | 4 ++-- pom.xml | 4 ++++ .../fdr/repository/fdr/FdrPaymentInsertEntity.java | 10 ++++------ .../it/gov/pagopa/fdr/service/psps/PspsService.java | 6 +++--- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index c4128509..37f9a7ac 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,11 @@ You can run your application in dev mode that enables live coding using: ```shell script ./mvnw compile quarkus:dev ``` +Otherwise, with quarkus CLI: +``` +brew install quarkusio/tap/quarkus +quarkus dev -DskipTests=true +``` > **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only > at http://localhost:8080/q/dev/. diff --git a/performance-test/python-test/main.py b/performance-test/python-test/main.py index ee087c97..4929a35f 100644 --- a/performance-test/python-test/main.py +++ b/performance-test/python-test/main.py @@ -3,8 +3,8 @@ import methods -NUMBER_OF_PAYMENTS = 30000 -MAX_PAYMENTS_PER_ADD_OPERATION = 1000 +NUMBER_OF_PAYMENTS = 300 +MAX_PAYMENTS_PER_ADD_OPERATION = 100 def main(URL, subkey): logging.basicConfig(level=logging.INFO) diff --git a/pom.xml b/pom.xml index 7622e3f8..cb8408c5 100644 --- a/pom.xml +++ b/pom.xml @@ -131,6 +131,10 @@ 1.0.0 provided + + io.quarkus + quarkus-smallrye-fault-tolerance + org.testcontainers junit-jupiter diff --git a/src/main/java/it/gov/pagopa/fdr/repository/fdr/FdrPaymentInsertEntity.java b/src/main/java/it/gov/pagopa/fdr/repository/fdr/FdrPaymentInsertEntity.java index fffc5c97..16e581d4 100644 --- a/src/main/java/it/gov/pagopa/fdr/repository/fdr/FdrPaymentInsertEntity.java +++ b/src/main/java/it/gov/pagopa/fdr/repository/fdr/FdrPaymentInsertEntity.java @@ -8,11 +8,13 @@ import io.quarkus.panache.common.Sort; import it.gov.pagopa.fdr.repository.fdr.model.PaymentStatusEnumEntity; import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.List; import lombok.Data; import lombok.EqualsAndHashCode; import org.bson.codecs.pojo.annotations.BsonProperty; import org.bson.types.ObjectId; +import org.eclipse.microprofile.faulttolerance.Retry; @Data @EqualsAndHashCode(callSuper = true) @@ -67,12 +69,8 @@ public static PanacheQuery findByFdrAndPspId(String fdr, Parameters.with("fdr", fdr).and("pspId", pspId).map()); } - public static void deleteByFdrAndIds(String fdr, List objectIds) { - delete( - "ref_fdr = :fdr and _id in :objectIds", - Parameters.with("fdr", fdr).and("ids", objectIds).map()); - } - + // https://quarkus.io/guides/smallrye-fault-tolerance + @Retry(delay = 500, delayUnit = ChronoUnit.MILLIS) public static long deleteByFdrAndIndexes(String fdr, List indexList) { return delete( "ref_fdr = :fdr and index in :indexes", diff --git a/src/main/java/it/gov/pagopa/fdr/service/psps/PspsService.java b/src/main/java/it/gov/pagopa/fdr/service/psps/PspsService.java index 0157b9bc..44838ff9 100644 --- a/src/main/java/it/gov/pagopa/fdr/service/psps/PspsService.java +++ b/src/main/java/it/gov/pagopa/fdr/service/psps/PspsService.java @@ -341,8 +341,8 @@ public void publishByFdr(String action, String pspId, String fdr, boolean intern // queue this.addToConversionQueue(internalPublish, fdrEntity); // delete - fdrEntity.delete(); this.batchDelete(fdr, paymentInsertEntities); + fdrEntity.delete(); log.infof("Deleted FdrPaymentInsertEntity by fdr[%s], pspId[%s]", fdr, sanitize(pspId)); // re this.rePublish(fdr, pspId, fdrPublishEntity); @@ -362,8 +362,8 @@ private void batchDelete(String fdr, List paymentInsertE .toList(); // sequential stream batches.forEach(batch -> { - List objectIds = paymentInsertEntities.stream().map(entity -> entity.id).toList(); - FdrPaymentInsertEntity.deleteByFdrAndIds(fdr, objectIds); + List indexes = paymentInsertEntities.stream().map(FdrPaymentInsertEntity::getIndex).toList(); + FdrPaymentInsertEntity.deleteByFdrAndIndexes(fdr, indexes); }); }