Repository navigation
Add additive staleness to @FollowerRead and fail fast on negative - #3
Merged
Merged
Conversation
- hoursAgo/minutesAgo/secondsAgo compose to AS OF SYSTEM TIME '-Ns'; default follower_read_timestamp() - CrdbDispatcher resolves staleness; parts override staleness; IllegalStateException on negative - Add CHANGELOG and update README annotations/follower-reads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR: Add staleness controls to @FollowerRead + fail-fast (core)
Repo:
cockroachlabs/cockroachdb-java-libraryBranch:
fix/7-follower-reads→mainSuggested tag after merge:
v0.1.2(additive)Summary
Ports the follower-read contract from the Spring Boot starter to the core
annotation:
@FollowerReadcan now target a specific staleness and rejectsinvalid values instead of silently reading current data.
What changed
@FollowerReadgainshoursAgo,minutesAgo,secondsAgo(long, default 0).They add up and compose to
AS OF SYSTEM TIME '-Ns'; nothing set keepsfollower_read_timestamp().CrdbDispatcherresolves staleness through a new package-privatefollowerReadStaleness(...)(overflow-safeMath.addExact/multiplyExact;only validated integers are inlined into SQL). When any part is set, the composed
interval takes precedence over the default
stalenessstring.IllegalStateExceptionat annotation-processing time (parity withthe Spring starter's
asOfExpression).Breaking vs additive
Fully additive.
stalenessis retained; existing@FollowerReadand@FollowerRead(staleness=...)behave exactly as before. No change toCrdbContext/CrdbContextValues/TransactionTemplate.Testing (verified locally)
./gradlew :core:test→ BUILD SUCCESSFUL; 10 newFollowerReadStalenessTestcases (default, additive composition, raw-staleness fallback, parts-beat-raw,
negative → throws, plus end-to-end through the proxy into
CrdbContext)../gradlew test→ BUILD SUCCESSFUL across all modules against a localcockroachdb/cockroach:v26.3.3node.Known limitation
The core
@FollowerReadonly emitsAS OF SYSTEM TIMEwhen the annotated methodruns inside a
TransactionTemplate. Opening a dedicated read-only transaction for abare
@FollowerReadis the Spring Boot starter's responsibility (core = primitive,starter = framework glue). Worth a sentence in the core Javadoc.
Note for reviewers
Running the full suite against a cluster surfaced a pre-existing
:aiVectorStoreITsetup gap — its JDBC URL names databaseparity_java, which mustexist on the target cluster. Unrelated to this PR; flagging for test-harness
follow-up.