Skip to content

Commit a3f4a21

Browse files
author
Eric Harmeling
authored
Merge pull request #1 from ericharmeling/no-follower-reads
[JDBC] No follower reads + other changes
2 parents e5ee92b + d25c00a commit a3f4a21

File tree

6 files changed

+3
-48
lines changed

6 files changed

+3
-48
lines changed

roach-data-jdbc/src/main/java/io/roach/data/jdbc/AccountController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public ResponseEntity<RepresentationModel> index() {
8484
*/
8585
@GetMapping("/account")
8686
@Transactional(propagation = REQUIRES_NEW)
87-
@TimeTravel // We dont need the result to be authoritative, so any follower replica can service the read
8887
public HttpEntity<PagedModel<AccountModel>> listAccounts(
8988
@PageableDefault(size = 5, direction = Sort.Direction.ASC) Pageable page) {
9089
return ResponseEntity

roach-data-jdbc/src/main/java/io/roach/data/jdbc/AccountRepository.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
/**
1515
* The main account repository, notice there's no implementation needed since its auto-proxied by
1616
* spring-data.
17-
* <p>
18-
* Should have extended PagingAndSortingRepository in normal cases.
1917
*/
2018
@Repository
2119
@Transactional(propagation = MANDATORY)

roach-data-jdbc/src/main/java/io/roach/data/jdbc/JdbcApplication.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
1414
import org.slf4j.LoggerFactory;
1515
import org.springframework.boot.CommandLineRunner;
1616
import org.springframework.boot.WebApplicationType;
17-
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
17+
import org.springframework.boot.autoconfigure.SpringBootApplication;
1818
import org.springframework.boot.builder.SpringApplicationBuilder;
19-
import org.springframework.context.annotation.ComponentScan;
20-
import org.springframework.context.annotation.Configuration;
2119
import org.springframework.context.annotation.EnableAspectJAutoProxy;
2220
import org.springframework.core.Ordered;
2321
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
24-
import org.springframework.data.web.config.EnableSpringDataWebSupport;
2522
import org.springframework.hateoas.Link;
2623
import org.springframework.hateoas.config.EnableHypermediaSupport;
2724
import org.springframework.http.HttpEntity;
@@ -33,14 +30,11 @@
3330
/**
3431
* Spring boot server application using spring-data-jdbc for data access.
3532
*/
36-
@EnableAutoConfiguration
3733
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
3834
@EnableJdbcRepositories
3935
@EnableAspectJAutoProxy(proxyTargetClass = true)
40-
@EnableSpringDataWebSupport
4136
@EnableTransactionManagement(order = Ordered.LOWEST_PRECEDENCE - 1) // Bump up one level to enable extra advisors
42-
@Configuration
43-
@ComponentScan
37+
@SpringBootApplication
4438
public class JdbcApplication implements CommandLineRunner {
4539
protected static final Logger logger = LoggerFactory.getLogger(JdbcApplication.class);
4640

roach-data-jdbc/src/main/java/io/roach/data/jdbc/PagedAccountRepositoryImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import static org.springframework.transaction.annotation.Propagation.MANDATORY;
1111

1212
@Repository
13-
// @Transactional is not needed but here for clarity since we want repos to always be called from a tx context
13+
// @Transactional annotation here to emphasise that repositories should always be called within an existing transaction context
1414
@Transactional(propagation = MANDATORY)
1515
public class PagedAccountRepositoryImpl implements PagedAccountRepository {
1616
@Autowired

roach-data-jdbc/src/main/java/io/roach/data/jdbc/TimeTravel.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

roach-data-jdbc/src/main/java/io/roach/data/jdbc/TransactionHintsAspect.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ public class TransactionHintsAspect {
3838
public void anyTransactionBoundaryOperation(Transactional transactional) {
3939
}
4040

41-
@Pointcut("execution(* io.roach..*(..)) && @annotation(followerRead)")
42-
public void anyFollowerReadOperation(TimeTravel followerRead) {
43-
}
44-
4541
@Around(value = "anyTransactionBoundaryOperation(transactional)",
4642
argNames = "pjp,transactional")
4743
public Object setTransactionAttributes(ProceedingJoinPoint pjp, Transactional transactional)
@@ -64,21 +60,4 @@ public Object setTransactionAttributes(ProceedingJoinPoint pjp, Transactional tr
6460

6561
return pjp.proceed();
6662
}
67-
68-
@Around(value = "anyFollowerReadOperation(timeTravel)",
69-
argNames = "pjp,timeTravel")
70-
public Object setTimeTravelAttributes(ProceedingJoinPoint pjp, TimeTravel timeTravel)
71-
throws Throwable {
72-
Assert.isTrue(TransactionSynchronizationManager.isActualTransactionActive(), "TX not active");
73-
74-
logger.info("Providing {} via follower read", pjp.getSignature().toShortString());
75-
76-
if (timeTravel.value() >= 0) {
77-
jdbcTemplate.update("SET TRANSACTION AS OF SYSTEM TIME INTERVAL '" + timeTravel.value() + "'");
78-
} else {
79-
jdbcTemplate.execute("SET TRANSACTION AS OF SYSTEM TIME experimental_follower_read_timestamp()");
80-
}
81-
82-
return pjp.proceed();
83-
}
8463
}

0 commit comments

Comments
 (0)