Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EVA-3670 - Set all transactions in block service to be serializable #89

Merged
merged 3 commits into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading