Skip to content

Commit

Permalink
added logger statements
Browse files Browse the repository at this point in the history
  • Loading branch information
nitin-ebi committed May 10, 2024
1 parent ccad0fb commit cc2bfd7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package uk.ac.ebi.ampt2d.commons.accession.generators.monotonic;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.monotonic.entities.ContiguousIdBlock;
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.monotonic.service.ContiguousIdBlockService;
import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.monotonic.service.MonotonicDatabaseService;
Expand All @@ -8,8 +10,11 @@
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class MonotonicAccessionRecoveryAgent {
private final static Logger logger = LoggerFactory.getLogger(MonotonicAccessionRecoveryAgent.class);

private final ContiguousIdBlockService blockService;
private final MonotonicDatabaseService monotonicDatabaseService;

Expand All @@ -20,10 +25,14 @@ public MonotonicAccessionRecoveryAgent(ContiguousIdBlockService blockService,
}

public void runRecovery(String categoryId, String applicationInstanceId, LocalDateTime lastUpdatedTime) {
logger.info("Starting recovering of blocks for category " + categoryId);
List<ContiguousIdBlock> blocksToRecover = blockService.allBlocksForCategoryIdReservedBeforeTheGivenTimeFrame(categoryId, lastUpdatedTime);
logger.info("List of block ids to recover : " + blocksToRecover.stream().map(b -> Long.toString(b.getId()))
.collect(Collectors.joining(",")));
for (ContiguousIdBlock block : blocksToRecover) {
// if block is already complete, there is nothing to recover, just release the block
logger.info("Recovering Block: " + block);
if (block.getLastCommitted() == block.getLastValue()) {
logger.info("Block is already completely used, not need to run recovery. Releasing the block.");
setAppInstanceIdAndReleaseBlock(applicationInstanceId, block);
continue;
}
Expand All @@ -33,10 +42,12 @@ public void runRecovery(String categoryId, String applicationInstanceId, LocalDa

if (blockSet.isEmpty()) {
// if block's last committed is correctly set, BlockManager's recover method will return an empty set
// in this case, we just need to release the block
logger.info("Block's last committed is correct. No updates to last_committed. Releasing the block.");
setAppInstanceIdAndReleaseBlock(applicationInstanceId, block);
} else {
ContiguousIdBlock blockToUpdate = blockSet.iterator().next();
logger.info("Recovery ran successfully for block. Last committed updated to " + block.getLastCommitted()
+ ". Saving and releasing the block.");
setAppInstanceIdAndReleaseBlock(applicationInstanceId, blockToUpdate);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,18 @@ public int compareTo(ContiguousIdBlock contiguousIdBlock) {
protected void onUpdate() {
this.lastUpdatedTimestamp = LocalDateTime.now();
}

@Override
public String toString() {
return "ContiguousIdBlock{" +
"id=" + id +
", categoryId='" + categoryId + '\'' +
", applicationInstanceId='" + applicationInstanceId + '\'' +
", firstValue=" + firstValue +
", lastValue=" + lastValue +
", lastCommitted=" + lastCommitted +
", reserved=" + reserved +
", lastUpdatedTimestamp=" + lastUpdatedTimestamp +
'}';
}
}

0 comments on commit cc2bfd7

Please sign in to comment.