diff --git a/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/uingenerator/repository/UinRepository.java b/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/uingenerator/repository/UinRepository.java index 9798700f638..8376a161e84 100644 --- a/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/uingenerator/repository/UinRepository.java +++ b/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/uingenerator/repository/UinRepository.java @@ -50,12 +50,12 @@ public interface UinRepository extends JpaRepository { public UinEntity findByUin(String uin); @Modifying - @Query(value = "UPDATE kernel.uin SET uin_status=:status, upd_by=:contextUser, upd_dtimes=:uptimes where uin=:uin", nativeQuery = true) + @Query(value = "UPDATE kernel.uin SET uin_status=:status, upd_by=:contextUser, upd_dtimes=:uptimes where uin=:uin for update", nativeQuery = true) public void updateStatus(@Param("status") String status, @Param("contextUser") String contextUser, @Param("uptimes") LocalDateTime uptimes, @Param("uin") String uin); - @Query(value = "select uu.uin, uu.cr_by, uu.cr_dtimes, uu.del_dtimes, uu.is_deleted, uu.upd_by, uu.upd_dtimes, uu.uin_status from kernel.uin uu where uu.uin_status=?", nativeQuery = true) - public List findByStatus(String status); + @Query(value = "select uu.uin, uu.cr_by, uu.cr_dtimes, uu.del_dtimes, uu.is_deleted, uu.upd_by, uu.upd_dtimes, uu.uin_status from kernel.uin uu where uu.uin_status=:status limit :limit ", nativeQuery = true) + public List findByStatus(@Param("status") String status, @Param("limit") int limit); long countByStatusAndIsDeletedFalse(String status); } \ No newline at end of file diff --git a/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/uingenerator/service/impl/UinServiceImpl.java b/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/uingenerator/service/impl/UinServiceImpl.java index b0975f6e29b..ef2c3710e0a 100644 --- a/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/uingenerator/service/impl/UinServiceImpl.java +++ b/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/uingenerator/service/impl/UinServiceImpl.java @@ -9,7 +9,7 @@ import org.modelmapper.ModelMapper; import org.modelmapper.TypeToken; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -41,9 +41,11 @@ */ @Component public class UinServiceImpl implements UinService { - + private Logger LOGGER = LoggerFactory.getLogger(UinServiceImpl.class); + @Value("${mosip.kernel.uin-transfer-limit:20000}") + private int uinTransferLimit; /** * Field for {@link #uinRepository} */ @@ -128,7 +130,7 @@ public UinStatusUpdateReponseDto updateUinStatus(UinEntity uinAck, RoutingContex @Transactional(transactionManager = "transactionManager") @Override public void transferUin() { - List uinEntities=uinRepository.findByStatus(UinGeneratorConstant.ASSIGNED); + List uinEntities=uinRepository.findByStatus(UinGeneratorConstant.ASSIGNED,uinTransferLimit); List uinEntitiesAssined = modelMapper.map(uinEntities, new TypeToken>() {}.getType()); uinRepositoryAssigned.saveAll(uinEntitiesAssined); uinRepository.deleteAll(uinEntities); diff --git a/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/vidgenerator/repository/VidAssignedRepository.java b/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/vidgenerator/repository/VidAssignedRepository.java index fb4f3ce5d65..23e99c1ce77 100644 --- a/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/vidgenerator/repository/VidAssignedRepository.java +++ b/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/vidgenerator/repository/VidAssignedRepository.java @@ -3,11 +3,14 @@ import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import io.mosip.kernel.vidgenerator.entity.VidAssignedEntity; public interface VidAssignedRepository extends JpaRepository { - List findByStatusAndIsDeletedFalse(String status); + @Query(value = "select v.vid, v.cr_by, v.cr_dtimes, v.del_dtimes, v.is_deleted, v.upd_by, v.upd_dtimes, v.vid_status from kernel.vid_assigned v where v.vid_status=:status limit :limit ", nativeQuery = true) + List findByStatusAndIsDeletedFalse(@Param("status") String status, @Param("limit") int limit); } \ No newline at end of file diff --git a/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/vidgenerator/repository/VidRepository.java b/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/vidgenerator/repository/VidRepository.java index 232b5e919b3..88a473747d0 100644 --- a/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/vidgenerator/repository/VidRepository.java +++ b/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/vidgenerator/repository/VidRepository.java @@ -17,7 +17,8 @@ public interface VidRepository extends JpaRepository { long countByStatusAndIsDeletedFalse(String status); - List findByStatusAndIsDeletedFalse(String status); + @Query(value = "select v.vid,v.vid_status,v.expiry_dtimes,v.cr_by, v.cr_dtimes, v.del_dtimes, v.is_deleted, v.upd_by, v.upd_dtimes from kernel.vid v where v.vid_status=:status limit :limit FOR UPDATE", nativeQuery = true) + List findByStatusAndIsDeletedFalse(@Param("status") String status, @Param("limit") int limit); @Modifying @Query(value = "UPDATE kernel.vid SET vid_status=:status, upd_by=:contextUser, upd_dtimes=:uptimes where vid=:vid", nativeQuery = true) diff --git a/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/vidgenerator/service/impl/VidServiceImpl.java b/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/vidgenerator/service/impl/VidServiceImpl.java index 7caa71b5183..ef5e70b4b6c 100644 --- a/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/vidgenerator/service/impl/VidServiceImpl.java +++ b/kernel/kernel-idgenerator-service/src/main/java/io/mosip/kernel/vidgenerator/service/impl/VidServiceImpl.java @@ -36,6 +36,17 @@ public class VidServiceImpl implements VidService { @Value("${mosip.kernel.vid.time-to-release-after-expiry}") private long timeToRelaseAfterExpiry; + + + @Value("${mosip.kernel.vid-expire-limit:20000}") + private int vidExpireLimit; + + @Value("${mosip.kernel.vid-release-limit:20000}") + private int vidReleaseLimit; + + + @Value("${mosip.kernel.vid-isolate-limit:20000}") + private int vidIsolateLimit; @Autowired private VidRepository vidRepository; @@ -122,14 +133,14 @@ public void expireAndRelease() { private void expireEligibleVids() { List vidAssignedEntities = vidAssignedRepository - .findByStatusAndIsDeletedFalse(VidLifecycleStatus.ASSIGNED); + .findByStatusAndIsDeletedFalse(VidLifecycleStatus.ASSIGNED,vidExpireLimit); vidAssignedEntities.forEach(this::expireIfEligible); vidAssignedRepository.saveAll(vidAssignedEntities); } private void releaseEligibleVids() { List vidExpiredEntities = vidAssignedRepository - .findByStatusAndIsDeletedFalse(VidLifecycleStatus.EXPIRED); + .findByStatusAndIsDeletedFalse(VidLifecycleStatus.EXPIRED,vidReleaseLimit); List releasableVidAssignedEntities = new ArrayList(); vidExpiredEntities.forEach(entity -> { if(isEligibleToRelease(entity)) { @@ -186,7 +197,7 @@ public boolean saveVID(VidEntity vid) { @Transactional(transactionManager = "transactionManager") @Override public void isolateAssignedVids() { - List vidEntities = vidRepository.findByStatusAndIsDeletedFalse(VidLifecycleStatus.ASSIGNED); + List vidEntities = vidRepository.findByStatusAndIsDeletedFalse(VidLifecycleStatus.ASSIGNED,vidIsolateLimit); LOGGER.info("isolateAssignedVids called for entity count {} ", vidEntities.size()); List vidEntitiesAssined = modelMapper.map(vidEntities, new TypeToken>() {}.getType()); diff --git a/kernel/kernel-idgenerator-service/src/test/java/io/mosip/kernel/vidgenerator/test/service/VidGeneratorServiceTest.java b/kernel/kernel-idgenerator-service/src/test/java/io/mosip/kernel/vidgenerator/test/service/VidGeneratorServiceTest.java index 02ec5d019a4..eb445ae5c7b 100644 --- a/kernel/kernel-idgenerator-service/src/test/java/io/mosip/kernel/vidgenerator/test/service/VidGeneratorServiceTest.java +++ b/kernel/kernel-idgenerator-service/src/test/java/io/mosip/kernel/vidgenerator/test/service/VidGeneratorServiceTest.java @@ -233,21 +233,21 @@ public void fetchVidCountTest() { @Test public void expireOrReleaseDataAccessExceptionTest() { - Mockito.when(vidRepository.findByStatusAndIsDeletedFalse(VidLifecycleStatus.ASSIGNED)) + Mockito.when(vidRepository.findByStatusAndIsDeletedFalse(VidLifecycleStatus.ASSIGNED,20000)) .thenThrow(new DataRetrievalFailureException("DataBase error occur")); vidService.expireAndRelease(); } @Test public void expireOrReleaseExceptionTest() { - Mockito.when(vidRepository.findByStatusAndIsDeletedFalse(VidLifecycleStatus.ASSIGNED)) + Mockito.when(vidRepository.findByStatusAndIsDeletedFalse(VidLifecycleStatus.ASSIGNED,20000)) .thenThrow(new RuntimeException("DataBase error occur")); vidService.expireAndRelease(); } @Test public void expireOrReleaseTest() { - Mockito.when(vidAssignedRepository.findByStatusAndIsDeletedFalse(VidLifecycleStatus.ASSIGNED)) + Mockito.when(vidAssignedRepository.findByStatusAndIsDeletedFalse(VidLifecycleStatus.ASSIGNED,20000)) .thenReturn(Stream.of(expiredButAssignedStatusVAEntities, notExpiredButAssignedStatusVAEntities) .flatMap(Collection::stream) .collect(Collectors.toList())); @@ -256,7 +256,7 @@ public void expireOrReleaseTest() { (List) i.getArguments()[0]).spliterator(), false) .collect(Collectors.toList())); - Mockito.when(vidAssignedRepository.findByStatusAndIsDeletedFalse(VidLifecycleStatus.EXPIRED)) + Mockito.when(vidAssignedRepository.findByStatusAndIsDeletedFalse(VidLifecycleStatus.EXPIRED,20000)) .thenReturn(Stream.of(releasableButExpiredStatusVAEntities, nonReleasableButExpiredStatusVAEntities) .flatMap(Collection::stream) .collect(Collectors.toList())); @@ -326,7 +326,7 @@ public void isolateAssignedVidTest() { Stream.of(nonExpiredButAssignedStatusEntities, expiredButAssignedStatusEntities) .flatMap(Collection::stream) .collect(Collectors.toList()); - Mockito.when(vidRepository.findByStatusAndIsDeletedFalse(VidLifecycleStatus.ASSIGNED)) + Mockito.when(vidRepository.findByStatusAndIsDeletedFalse(VidLifecycleStatus.ASSIGNED,20000)) .thenReturn(validTranserEntities); Mockito.when(vidAssignedRepository.saveAll(vidAssignedEntityListCaptor.capture())) .thenAnswer(i -> StreamSupport.stream((