cockroachdb / cockroachdb/cockroach
sql: add support for erroring out if follower read cannot be served by replica in local region
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
**Is your feature request related to a problem? Please describe.**
Users have the option of enforcing that a read will only access the local region when using [bounded staleness reads](https://www.cockroachlabs.com/docs/stable/follower-reads.html#run-queries-that-use-bounded-staleness-follower-reads), by using the `nearest_only` parameter of the `with_min_timestamp` and `with_max_staleness` functions. If the local replica is not sufficiently up-to-date, queries using `nearest_only=true` will return an error.
With exact staleness reads, there is currently no such option. `AS OF SYSTEM TIME follower_read_timestamp()` will cause CockroachDB to make a best-effort attempt to use a local replica, but if the local replica is not sufficiently up-to-date, the query will be redirected to the leaseholder.
**Describe the solution you'd like**
We should add support for erroring with exact staleness reads if they cannot be served from a local replica. The error should look something like, `exact staleness read with timestamp XXX could not be satisfied by a local resolved timestamp of XXX`.
The UX for specifying `nearest_only` with exact staleness reads has not been determined yet, but one option is to make use of the `follower_read_timestamp()` function and add an optional `nearest_only` parameter. Alternatively, we could use a session setting or add new SQL syntax.
cc @nvanbenschoten @shralex
Jira issue: CRDB-24733
Contributor guide
Assessment
This issue has not been assessed yet.