Skip to content

Commit

Permalink
[PAGOPA-2282] fix(delete-by-index): Add smallrye-fault-tolerance
Browse files Browse the repository at this point in the history
  • Loading branch information
cap-ang committed Oct 30, 2024
1 parent 581d965 commit 0395bde
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/.
Expand Down
4 changes: 2 additions & 2 deletions performance-test/python-test/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-fault-tolerance</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -67,12 +69,8 @@ public static PanacheQuery<PanacheMongoEntityBase> findByFdrAndPspId(String fdr,
Parameters.with("fdr", fdr).and("pspId", pspId).map());
}

public static void deleteByFdrAndIds(String fdr, List<ObjectId> 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<Long> indexList) {
return delete(
"ref_fdr = :fdr and index in :indexes",
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/it/gov/pagopa/fdr/service/psps/PspsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.

Check failure

Code scanning / CodeQL

Log Injection High

This log entry depends on a
user-provided value
.
This log entry depends on a
user-provided value
.
// re
this.rePublish(fdr, pspId, fdrPublishEntity);
Expand All @@ -362,8 +362,8 @@ private void batchDelete(String fdr, List<FdrPaymentInsertEntity> paymentInsertE
.toList();
// sequential stream
batches.forEach(batch -> {
List<ObjectId> objectIds = paymentInsertEntities.stream().map(entity -> entity.id).toList();
FdrPaymentInsertEntity.deleteByFdrAndIds(fdr, objectIds);
List<Long> indexes = paymentInsertEntities.stream().map(FdrPaymentInsertEntity::getIndex).toList();
FdrPaymentInsertEntity.deleteByFdrAndIndexes(fdr, indexes);
});
}

Expand Down

0 comments on commit 0395bde

Please sign in to comment.