You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@fineract.apache.org by "oleksii-novikov-onix (via GitHub)" <gi...@apache.org> on 2026/05/18 18:53:35 UTC
[PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
oleksii-novikov-onix opened a new pull request, #5858:
URL: https://github.com/apache/fineract/pull/5858
## Description
Describe the changes made and why they were made. (Ignore if these details are present on the associated Apache Fineract JIRA ticket.)
## Checklist
Please make sure these boxes are checked before submitting your pull request - thanks!
- [ ] Write the commit message as per [our guidelines](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#pull-requests)
- [ ] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.
- [ ] Create/update [unit or integration tests](https://fineract.apache.org/docs/current/#_testing) for verifying the changes made.
- [ ] Follow our [coding conventions](https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions).
- [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes
- [ ] [This PR must not be a "code dump"](https://cwiki.apache.org/confluence/display/FINERACT/Pull+Request+Size+Limit). Large changes can be made in a branch, with assistance. Ask for help on the [developer mailing list](https://fineract.apache.org/#contribute).
Your assigned reviewer(s) will follow our [guidelines for code reviews](https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #5858:
URL: https://github.com/apache/fineract/pull/5858#discussion_r3266029862
##########
fineract-cob/src/main/java/org/apache/fineract/cob/service/AbstractAccountLockService.java:
##########
@@ -59,8 +62,13 @@ public boolean isLockOverrulable(Long loanId) {
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateCobAndRemoveLocks() {
customLoanAccountLockRepository.updateLoanFromAccountLocks();
- loanAccountLockRepository.removeByLockOwnerInAndErrorIsNotNullAndLockPlacedOnCobBusinessDateIsNotNull(
- List.of(LockOwner.LOAN_COB_CHUNK_PROCESSING, LockOwner.LOAN_INLINE_COB_PROCESSING));
+ loanAccountLockRepository.removeByLockOwnerInAndErrorIsNotNullAndLockPlacedOnCobBusinessDateIsNotNull(COB_LOCK_OWNERS);
+ }
+
+ @Override
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
Review Comment:
I dont think we need to do it in a new transaction, or i am mistaken?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #5858:
URL: https://github.com/apache/fineract/pull/5858#discussion_r3266029862
##########
fineract-cob/src/main/java/org/apache/fineract/cob/service/AbstractAccountLockService.java:
##########
@@ -59,8 +62,13 @@ public boolean isLockOverrulable(Long loanId) {
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateCobAndRemoveLocks() {
customLoanAccountLockRepository.updateLoanFromAccountLocks();
- loanAccountLockRepository.removeByLockOwnerInAndErrorIsNotNullAndLockPlacedOnCobBusinessDateIsNotNull(
- List.of(LockOwner.LOAN_COB_CHUNK_PROCESSING, LockOwner.LOAN_INLINE_COB_PROCESSING));
+ loanAccountLockRepository.removeByLockOwnerInAndErrorIsNotNullAndLockPlacedOnCobBusinessDateIsNotNull(COB_LOCK_OWNERS);
+ }
+
+ @Override
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
Review Comment:
I dont think we need to do it in a new transaction, or do we?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy merged PR #5858:
URL: https://github.com/apache/fineract/pull/5858
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "AshharAhmadKhan (via GitHub)" <gi...@apache.org>.
AshharAhmadKhan commented on PR #5858:
URL: https://github.com/apache/fineract/pull/5858#issuecomment-4488882366
@oleksii-novikov-onix @adamsaghy
The approach here is solid. A few thoughts on the open review comments:
`@Transactional(propagation = REQUIRES_NEW)` on `removeOrphanedLocksForProcessedAccounts()` isn't needed. Spring Batch already wraps each tasklet in its own transaction and all prior steps have committed by the time this runs, so default `REQUIRED` is fine.
`nullCobBusinessDate` in `LockRequest` is there so tests can place a lock with a null cob date through the API, which is needed to cover the `lock_placed_on_cob_business_date IS NOT NULL` filter in the delete query. Without it there's no way to test that edge case.
Also agree on `log.info`, `log.debug` makes more sense since this runs on every COB execution.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "oleksii-novikov-onix (via GitHub)" <gi...@apache.org>.
oleksii-novikov-onix commented on code in PR #5858:
URL: https://github.com/apache/fineract/pull/5858#discussion_r3272312279
##########
fineract-cob/src/main/java/org/apache/fineract/cob/api/LockRequest.java:
##########
@@ -18,10 +18,13 @@
*/
package org.apache.fineract.cob.api;
+import java.time.LocalDate;
import lombok.Data;
@Data
public class LockRequest {
private String error;
+ private LocalDate cobBusinessDate;
+ private Boolean nullCobBusinessDate;
Review Comment:
LockRequest was added only for the internal API, specifically for testing locks. I decided to extend it to also simulate "stale" lock records.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #5858:
URL: https://github.com/apache/fineract/pull/5858#discussion_r3266029862
##########
fineract-cob/src/main/java/org/apache/fineract/cob/service/AbstractAccountLockService.java:
##########
@@ -59,8 +62,13 @@ public boolean isLockOverrulable(Long loanId) {
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateCobAndRemoveLocks() {
customLoanAccountLockRepository.updateLoanFromAccountLocks();
- loanAccountLockRepository.removeByLockOwnerInAndErrorIsNotNullAndLockPlacedOnCobBusinessDateIsNotNull(
- List.of(LockOwner.LOAN_COB_CHUNK_PROCESSING, LockOwner.LOAN_INLINE_COB_PROCESSING));
+ loanAccountLockRepository.removeByLockOwnerInAndErrorIsNotNullAndLockPlacedOnCobBusinessDateIsNotNull(COB_LOCK_OWNERS);
+ }
+
+ @Override
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
Review Comment:
Do we need to start a new transaction for this?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "oleksii-novikov-onix (via GitHub)" <gi...@apache.org>.
oleksii-novikov-onix commented on PR #5858:
URL: https://github.com/apache/fineract/pull/5858#issuecomment-4496017004
@AshharAhmadKhan Thank you for participating in the discussion
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #5858:
URL: https://github.com/apache/fineract/pull/5858#discussion_r3266029862
##########
fineract-cob/src/main/java/org/apache/fineract/cob/service/AbstractAccountLockService.java:
##########
@@ -59,8 +62,13 @@ public boolean isLockOverrulable(Long loanId) {
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateCobAndRemoveLocks() {
customLoanAccountLockRepository.updateLoanFromAccountLocks();
- loanAccountLockRepository.removeByLockOwnerInAndErrorIsNotNullAndLockPlacedOnCobBusinessDateIsNotNull(
- List.of(LockOwner.LOAN_COB_CHUNK_PROCESSING, LockOwner.LOAN_INLINE_COB_PROCESSING));
+ loanAccountLockRepository.removeByLockOwnerInAndErrorIsNotNullAndLockPlacedOnCobBusinessDateIsNotNull(COB_LOCK_OWNERS);
+ }
+
+ @Override
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
Review Comment:
I dont think we need to do it in a new transaction, no?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "oleksii-novikov-onix (via GitHub)" <gi...@apache.org>.
oleksii-novikov-onix commented on code in PR #5858:
URL: https://github.com/apache/fineract/pull/5858#discussion_r3272362943
##########
fineract-cob/src/main/java/org/apache/fineract/cob/api/LockRequest.java:
##########
@@ -18,10 +18,13 @@
*/
package org.apache.fineract.cob.api;
+import java.time.LocalDate;
import lombok.Data;
@Data
public class LockRequest {
private String error;
+ private LocalDate cobBusinessDate;
+ private Boolean nullCobBusinessDate;
Review Comment:
JSON does not allow distinguishing three states:
1. {} - field is not provided, so COB date should be taken from ThreadLocal as default
2. {"cobBusinessDate": "2026-05-20"} - an explicit date is provided
3. {"cobBusinessDate": null} - explicitly store NULL in the database
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #5858:
URL: https://github.com/apache/fineract/pull/5858#discussion_r3265991446
##########
fineract-cob/src/main/java/org/apache/fineract/cob/tasklet/UnlockProcessedAccountsTasklet.java:
##########
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cob.tasklet;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.cob.domain.AccountLock;
+import org.apache.fineract.cob.service.AccountLockService;
+import org.springframework.batch.core.StepContribution;
+import org.springframework.batch.core.scope.context.ChunkContext;
+import org.springframework.batch.core.step.tasklet.Tasklet;
+import org.springframework.batch.repeat.RepeatStatus;
+import org.springframework.lang.NonNull;
+
+/**
+ * Tasklet that unlocks accounts which were successfully processed during COB but whose locks were not removed.
+ *
+ * An account is considered successfully processed when its {@code last_closed_business_date} matches the
+ * {@code lock_placed_on_cob_business_date} on the lock record, proving all COB business steps completed. If the lock
+ * still exists with no error, it is orphaned and should be removed.
+ */
+@Slf4j
+@RequiredArgsConstructor
+public abstract class UnlockProcessedAccountsTasklet<T extends AccountLock> implements Tasklet {
+
+ private final AccountLockService<T> accountLockService;
+
+ @Override
+ public RepeatStatus execute(@NonNull final StepContribution contribution, @NonNull final ChunkContext chunkContext) throws Exception {
+ final int removedCount = accountLockService.removeOrphanedLocksForProcessedAccounts();
+ if (removedCount > 0) {
+ log.info("Unlocked {} account(s) that completed COB processing but remained locked", removedCount);
Review Comment:
use debug level logging please...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "oleksii-novikov-onix (via GitHub)" <gi...@apache.org>.
oleksii-novikov-onix commented on code in PR #5858:
URL: https://github.com/apache/fineract/pull/5858#discussion_r3272137961
##########
fineract-cob/src/main/java/org/apache/fineract/cob/tasklet/UnlockProcessedAccountsTasklet.java:
##########
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.cob.tasklet;
+
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.fineract.cob.domain.AccountLock;
+import org.apache.fineract.cob.service.AccountLockService;
+import org.springframework.batch.core.StepContribution;
+import org.springframework.batch.core.scope.context.ChunkContext;
+import org.springframework.batch.core.step.tasklet.Tasklet;
+import org.springframework.batch.repeat.RepeatStatus;
+import org.springframework.lang.NonNull;
+
+/**
+ * Tasklet that unlocks accounts which were successfully processed during COB but whose locks were not removed.
+ *
+ * An account is considered successfully processed when its {@code last_closed_business_date} matches the
+ * {@code lock_placed_on_cob_business_date} on the lock record, proving all COB business steps completed. If the lock
+ * still exists with no error, it is orphaned and should be removed.
+ */
+@Slf4j
+@RequiredArgsConstructor
+public abstract class UnlockProcessedAccountsTasklet<T extends AccountLock> implements Tasklet {
+
+ private final AccountLockService<T> accountLockService;
+
+ @Override
+ public RepeatStatus execute(@NonNull final StepContribution contribution, @NonNull final ChunkContext chunkContext) throws Exception {
+ final int removedCount = accountLockService.removeOrphanedLocksForProcessedAccounts();
+ if (removedCount > 0) {
+ log.info("Unlocked {} account(s) that completed COB processing but remained locked", removedCount);
Review Comment:
Fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "oleksii-novikov-onix (via GitHub)" <gi...@apache.org>.
oleksii-novikov-onix commented on code in PR #5858:
URL: https://github.com/apache/fineract/pull/5858#discussion_r3272188518
##########
fineract-cob/src/main/java/org/apache/fineract/cob/service/AbstractAccountLockService.java:
##########
@@ -59,8 +62,13 @@ public boolean isLockOverrulable(Long loanId) {
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateCobAndRemoveLocks() {
customLoanAccountLockRepository.updateLoanFromAccountLocks();
- loanAccountLockRepository.removeByLockOwnerInAndErrorIsNotNullAndLockPlacedOnCobBusinessDateIsNotNull(
- List.of(LockOwner.LOAN_COB_CHUNK_PROCESSING, LockOwner.LOAN_INLINE_COB_PROCESSING));
+ loanAccountLockRepository.removeByLockOwnerInAndErrorIsNotNullAndLockPlacedOnCobBusinessDateIsNotNull(COB_LOCK_OWNERS);
+ }
+
+ @Override
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
Review Comment:
Right, we do not need REQUIRES_NEW here. This method is invoked only from UnlockProcessedAccountsTasklet.execute().
##########
fineract-cob/src/main/java/org/apache/fineract/cob/service/AbstractAccountLockService.java:
##########
@@ -59,8 +62,13 @@ public boolean isLockOverrulable(Long loanId) {
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void updateCobAndRemoveLocks() {
customLoanAccountLockRepository.updateLoanFromAccountLocks();
- loanAccountLockRepository.removeByLockOwnerInAndErrorIsNotNullAndLockPlacedOnCobBusinessDateIsNotNull(
- List.of(LockOwner.LOAN_COB_CHUNK_PROCESSING, LockOwner.LOAN_INLINE_COB_PROCESSING));
+ loanAccountLockRepository.removeByLockOwnerInAndErrorIsNotNullAndLockPlacedOnCobBusinessDateIsNotNull(COB_LOCK_OWNERS);
+ }
+
+ @Override
+ @Transactional(propagation = Propagation.REQUIRES_NEW)
Review Comment:
Removed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "oleksii-novikov-onix (via GitHub)" <gi...@apache.org>.
oleksii-novikov-onix commented on code in PR #5858:
URL: https://github.com/apache/fineract/pull/5858#discussion_r3272362943
##########
fineract-cob/src/main/java/org/apache/fineract/cob/api/LockRequest.java:
##########
@@ -18,10 +18,13 @@
*/
package org.apache.fineract.cob.api;
+import java.time.LocalDate;
import lombok.Data;
@Data
public class LockRequest {
private String error;
+ private LocalDate cobBusinessDate;
+ private Boolean nullCobBusinessDate;
Review Comment:
JSON does not allow distinguishing three states:
1. {} - field is not provided, so COB date should be taken from ThreadLocal as default
2. {"cobBusinessDate": "2026-05-20"} - an explicit date is provided
3. {"cobBusinessDate": null} - explicitly store NULL in the database
After deserialization, states 1 and 3 look identical
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] FINERACT-2602: Remove orphaned COB locks after job completion [fineract]
Posted by "adamsaghy (via GitHub)" <gi...@apache.org>.
adamsaghy commented on code in PR #5858:
URL: https://github.com/apache/fineract/pull/5858#discussion_r3265927258
##########
fineract-cob/src/main/java/org/apache/fineract/cob/api/LockRequest.java:
##########
@@ -18,10 +18,13 @@
*/
package org.apache.fineract.cob.api;
+import java.time.LocalDate;
import lombok.Data;
@Data
public class LockRequest {
private String error;
+ private LocalDate cobBusinessDate;
+ private Boolean nullCobBusinessDate;
Review Comment:
what is this field for?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@fineract.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org