From 990c35239ade5ba8a0801c4d49b627468b957af9 Mon Sep 17 00:00:00 2001 From: April Shen Date: Fri, 27 Sep 2024 13:03:09 +0100 Subject: [PATCH 1/3] set all transactions in block service to be serializable --- .../jpa/monotonic/service/ContiguousIdBlockService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/monotonic/service/ContiguousIdBlockService.java b/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/monotonic/service/ContiguousIdBlockService.java index 5f86d4e0..37a456d3 100644 --- a/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/monotonic/service/ContiguousIdBlockService.java +++ b/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/monotonic/service/ContiguousIdBlockService.java @@ -69,7 +69,7 @@ public ContiguousIdBlockService(ContiguousIdBlockRepository repository, Map blocks) { // release block if full blocks.forEach(block -> {if (block.isFull()) {block.releaseReserved();}}); @@ -77,7 +77,7 @@ public void save(Iterable blocks) { entityManager.flush(); } - @Transactional + @Transactional(isolation = Isolation.SERIALIZABLE) public void save(ContiguousIdBlock block) { // release block if full if (block.isFull()) { From a3f9b663dcb42cb6b820dc3529a6fe0a8f66b785 Mon Sep 17 00:00:00 2001 From: April Shen Date: Mon, 30 Sep 2024 10:29:41 +0100 Subject: [PATCH 2/3] add comment explaining isolation level requirement --- .../jpa/monotonic/service/ContiguousIdBlockService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/monotonic/service/ContiguousIdBlockService.java b/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/monotonic/service/ContiguousIdBlockService.java index 37a456d3..cb83a396 100644 --- a/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/monotonic/service/ContiguousIdBlockService.java +++ b/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/monotonic/service/ContiguousIdBlockService.java @@ -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, 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 { From 6784fc270d9cdcbaad305c472029d72669f03b00 Mon Sep 17 00:00:00 2001 From: April Shen Date: Mon, 30 Sep 2024 11:06:19 +0100 Subject: [PATCH 3/3] modify comment --- .../jpa/monotonic/service/ContiguousIdBlockService.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/monotonic/service/ContiguousIdBlockService.java b/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/monotonic/service/ContiguousIdBlockService.java index cb83a396..df355838 100644 --- a/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/monotonic/service/ContiguousIdBlockService.java +++ b/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/persistence/jpa/monotonic/service/ContiguousIdBlockService.java @@ -53,8 +53,8 @@ * Also, when saving the blocks, we need to check for the block's last committed value. * If its last committed value is same as last value, we should release the block in DB. * - * To guarantee safe multiprocessing, all methods in ContiguousIdBlockService that access the DB must use the - * SERIALIZABLE transaction isolation level. + * 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 * */