Skip to content
Merged
Show file tree
Hide file tree
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 @@ -84,7 +84,6 @@ public ResponseEntity<RepresentationModel> 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<PagedModel<AccountModel>> listAccounts(
@PageableDefault(size = 5, direction = Sort.Direction.ASC) Pageable page) {
return ResponseEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
/**
* The main account repository, notice there's no implementation needed since its auto-proxied by
* spring-data.
* <p>
* Should have extended PagingAndSortingRepository in normal cases.
*/
@Repository
@Transactional(propagation = MANDATORY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions roach-data-jdbc/src/main/java/io/roach/data/jdbc/TimeTravel.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
}
}