diff --git a/roach-data-jdbc/src/main/java/io/roach/data/jdbc/AccountController.java b/roach-data-jdbc/src/main/java/io/roach/data/jdbc/AccountController.java index c35e881..aa2d70b 100644 --- a/roach-data-jdbc/src/main/java/io/roach/data/jdbc/AccountController.java +++ b/roach-data-jdbc/src/main/java/io/roach/data/jdbc/AccountController.java @@ -84,7 +84,6 @@ public ResponseEntity index() { */ @GetMapping("/account") @Transactional(propagation = REQUIRES_NEW) - @TimeTravel // We dont need the result to be authoritative, so any follower replica can service the read public HttpEntity> listAccounts( @PageableDefault(size = 5, direction = Sort.Direction.ASC) Pageable page) { return ResponseEntity diff --git a/roach-data-jdbc/src/main/java/io/roach/data/jdbc/AccountRepository.java b/roach-data-jdbc/src/main/java/io/roach/data/jdbc/AccountRepository.java index d2b0584..b8f3f0e 100644 --- a/roach-data-jdbc/src/main/java/io/roach/data/jdbc/AccountRepository.java +++ b/roach-data-jdbc/src/main/java/io/roach/data/jdbc/AccountRepository.java @@ -14,8 +14,6 @@ /** * The main account repository, notice there's no implementation needed since its auto-proxied by * spring-data. - *

- * Should have extended PagingAndSortingRepository in normal cases. */ @Repository @Transactional(propagation = MANDATORY) diff --git a/roach-data-jdbc/src/main/java/io/roach/data/jdbc/JdbcApplication.java b/roach-data-jdbc/src/main/java/io/roach/data/jdbc/JdbcApplication.java index 1e3168d..29d9bed 100644 --- a/roach-data-jdbc/src/main/java/io/roach/data/jdbc/JdbcApplication.java +++ b/roach-data-jdbc/src/main/java/io/roach/data/jdbc/JdbcApplication.java @@ -14,14 +14,11 @@ import org.slf4j.LoggerFactory; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.WebApplicationType; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.core.Ordered; import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories; -import org.springframework.data.web.config.EnableSpringDataWebSupport; import org.springframework.hateoas.Link; import org.springframework.hateoas.config.EnableHypermediaSupport; import org.springframework.http.HttpEntity; @@ -33,14 +30,11 @@ /** * Spring boot server application using spring-data-jdbc for data access. */ -@EnableAutoConfiguration @EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL) @EnableJdbcRepositories @EnableAspectJAutoProxy(proxyTargetClass = true) -@EnableSpringDataWebSupport @EnableTransactionManagement(order = Ordered.LOWEST_PRECEDENCE - 1) // Bump up one level to enable extra advisors -@Configuration -@ComponentScan +@SpringBootApplication public class JdbcApplication implements CommandLineRunner { protected static final Logger logger = LoggerFactory.getLogger(JdbcApplication.class); diff --git a/roach-data-jdbc/src/main/java/io/roach/data/jdbc/PagedAccountRepositoryImpl.java b/roach-data-jdbc/src/main/java/io/roach/data/jdbc/PagedAccountRepositoryImpl.java index 0e49a2a..51279a1 100644 --- a/roach-data-jdbc/src/main/java/io/roach/data/jdbc/PagedAccountRepositoryImpl.java +++ b/roach-data-jdbc/src/main/java/io/roach/data/jdbc/PagedAccountRepositoryImpl.java @@ -10,7 +10,7 @@ import static org.springframework.transaction.annotation.Propagation.MANDATORY; @Repository -// @Transactional is not needed but here for clarity since we want repos to always be called from a tx context +// @Transactional annotation here to emphasise that repositories should always be called within an existing transaction context @Transactional(propagation = MANDATORY) public class PagedAccountRepositoryImpl implements PagedAccountRepository { @Autowired diff --git a/roach-data-jdbc/src/main/java/io/roach/data/jdbc/TimeTravel.java b/roach-data-jdbc/src/main/java/io/roach/data/jdbc/TimeTravel.java deleted file mode 100644 index 243f18f..0000000 --- a/roach-data-jdbc/src/main/java/io/roach/data/jdbc/TimeTravel.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.roach.data.jdbc; - -import java.lang.annotation.*; - -/** - * Annotation marking a transaction boundary to use follower reads (time travel). - * See https://www.cockroachlabs.com/docs/stable/follower-reads.html - */ -@Inherited -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD}) -public @interface TimeTravel { - int value() default -1; // Non-zero denotes follower read -} diff --git a/roach-data-jdbc/src/main/java/io/roach/data/jdbc/TransactionHintsAspect.java b/roach-data-jdbc/src/main/java/io/roach/data/jdbc/TransactionHintsAspect.java index dcb285e..0eae2cb 100644 --- a/roach-data-jdbc/src/main/java/io/roach/data/jdbc/TransactionHintsAspect.java +++ b/roach-data-jdbc/src/main/java/io/roach/data/jdbc/TransactionHintsAspect.java @@ -38,10 +38,6 @@ public class TransactionHintsAspect { public void anyTransactionBoundaryOperation(Transactional transactional) { } - @Pointcut("execution(* io.roach..*(..)) && @annotation(followerRead)") - public void anyFollowerReadOperation(TimeTravel followerRead) { - } - @Around(value = "anyTransactionBoundaryOperation(transactional)", argNames = "pjp,transactional") public Object setTransactionAttributes(ProceedingJoinPoint pjp, Transactional transactional) @@ -64,21 +60,4 @@ public Object setTransactionAttributes(ProceedingJoinPoint pjp, Transactional tr return pjp.proceed(); } - - @Around(value = "anyFollowerReadOperation(timeTravel)", - argNames = "pjp,timeTravel") - public Object setTimeTravelAttributes(ProceedingJoinPoint pjp, TimeTravel timeTravel) - throws Throwable { - Assert.isTrue(TransactionSynchronizationManager.isActualTransactionActive(), "TX not active"); - - logger.info("Providing {} via follower read", pjp.getSignature().toShortString()); - - if (timeTravel.value() >= 0) { - jdbcTemplate.update("SET TRANSACTION AS OF SYSTEM TIME INTERVAL '" + timeTravel.value() + "'"); - } else { - jdbcTemplate.execute("SET TRANSACTION AS OF SYSTEM TIME experimental_follower_read_timestamp()"); - } - - return pjp.proceed(); - } }