Skip to content

Commit

Permalink
FINERACT-2066: Remove parallelization of external event status update
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsaghy committed Apr 17, 2024
1 parent 457be1a commit 6777612
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@
import org.apache.fineract.avro.MessageV1;
import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService;
import org.apache.fineract.infrastructure.core.config.FineractProperties;
import org.apache.fineract.infrastructure.core.domain.FineractContext;
import org.apache.fineract.infrastructure.core.service.DateUtils;
import org.apache.fineract.infrastructure.core.service.ThreadLocalContextUtil;
import org.apache.fineract.infrastructure.event.external.producer.ExternalEventProducer;
import org.apache.fineract.infrastructure.event.external.repository.ExternalEventRepository;
import org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEventStatus;
Expand Down Expand Up @@ -106,14 +104,10 @@ private void markEventsAsSent(List<Long> eventIds) {
// Partitioning dataset to avoid exception: PreparedStatement can have at most 65,535 parameters
final int partitionSize = fineractProperties.getEvents().getExternal().getPartitionSize();
List<List<Long>> partitions = Lists.partition(eventIds, partitionSize);
FineractContext context = ThreadLocalContextUtil.getContext();
partitions.stream() //
.parallel() //
partitions //
.forEach(partitionedEventIds -> {
measure(() -> {
ThreadLocalContextUtil.init(context);
repository.markEventsSent(partitionedEventIds, sentAt);
ThreadLocalContextUtil.reset();
}, timeTaken -> {
log.debug("Took {}ms to update {} events", timeTaken.toMillis(), partitionedEventIds.size());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.apache.fineract.infrastructure.event.external.repository;

import jakarta.transaction.Transactional;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.util.List;
Expand All @@ -41,7 +40,6 @@ public interface ExternalEventRepository extends JpaRepository<ExternalEvent, Lo
void deleteOlderEventsWithSentStatus(@Param("status") ExternalEventStatus status,
@Param("dateForPurgeCriteria") LocalDate dateForPurgeCriteria);

@Transactional
@Modifying
@Query("UPDATE ExternalEvent e SET e.status = org.apache.fineract.infrastructure.event.external.repository.domain.ExternalEventStatus.SENT, e.sentAt = :sentAt WHERE e.id IN :ids")
void markEventsSent(@Param("ids") List<Long> ids, @Param("sentAt") OffsetDateTime sentAt);
Expand Down

0 comments on commit 6777612

Please sign in to comment.