Skip to content

Commit

Permalink
Merge pull request #89 from apriltuesday/EVA-3670
Browse files Browse the repository at this point in the history
EVA-3670 - Set all transactions in block service to be serializable
  • Loading branch information
apriltuesday authored Sep 30, 2024
2 parents 8dad551 + 6784fc2 commit c19c71f
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@
* (see method @reserveNewBlock)
*
* Also, when saving the blocks, we need to check for the block's last committed value.
* If it's last committed value is same as last value, we should release the block in DB
* If its last committed value is same as last value, we should release the block in DB.
*
* To guarantee safe multiprocessing in PostgreSQL, all methods in ContiguousIdBlockService that access the DB must use
* the SERIALIZABLE transaction isolation level.
* See here for details: https://wiki.postgresql.org/wiki/Serializable#PostgreSQL_Implementation
*
*/
public class ContiguousIdBlockService {
Expand All @@ -69,15 +73,15 @@ public ContiguousIdBlockService(ContiguousIdBlockRepository repository, Map<Stri
this.categoryBlockInitializations = categoryBlockInitializations;
}

@Transactional
@Transactional(isolation = Isolation.SERIALIZABLE)
public void save(Iterable<ContiguousIdBlock> blocks) {
// release block if full
blocks.forEach(block -> {if (block.isFull()) {block.releaseReserved();}});
repository.saveAll(blocks);
entityManager.flush();
}

@Transactional
@Transactional(isolation = Isolation.SERIALIZABLE)
public void save(ContiguousIdBlock block) {
// release block if full
if (block.isFull()) {
Expand Down

0 comments on commit c19c71f

Please sign in to comment.