Skip to content

sql: add support for erroring out if follower read cannot be served by replica in local region #97512

@rytaft

Description

@rytaft

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, 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-sql-queriesSQL Queries Team

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions