Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errors: iterator API errors refactor #1160

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from

Conversation

muzarski
Copy link
Contributor

Pre-review checklist

  • I have split my patch into logically separate commits.
  • All commit messages clearly explain what they change and why.
  • I added relevant tests for new features and bug fixes.
  • All commits compile, pass static checks and pass test.
  • PR description sums up the changes and reasons why they should be introduced.
  • I have provided docstrings for the public items that I want to introduce.
  • I have adjusted the documentation in ./docs/source/.
  • I added appropriate Fixes: annotations to PR description.

The name is more fitting, because this function is generic over
CQL request kinds. Query is a name for a specific CQL request.

Updated the names of variables, and some types that are directly
used by this function. Adjusted the documentation of the function.
Again, query would suggest that we want to execute a CQL QUERY request.
New name also clearly tells the user that provided closure can be potentially executed
multiple (based on plan and retry session).
Documented the function. Renamed ExecuteQueryContext -> ExecuteRequestContext
This is to prevent some unwanted implicit conversions.
This is then converted to `ProtocolError` in UserRequestError::into_query_error().
Adjusted, so the callers now convert QueryResponse to QueryResult.
Notice that into_query_result returns QueryError, and not
UserRequestError (as into_non_error_query_response).

It's then converted to QueryResult later. This change is required
to prepare for further changes (i.e. narrowing the return type
of errors passed to LBP, retry policy etc.).
In the next commit, I want to narrow the error type of `do_query` closure
to UserRequestError.
`do_query` closure for `query` method serializes the values after preparation.
Thanks to that, we will be able to pass the narrower error type to
LBP::on_query_failure. Currently, QueryError is passed, but not all of
its variants could even be constructed at this stage.
This error will be passed to LoadBalancingPolicy::on_query_failure
and to RetrySession::decide_should_retry.
This narrows the error type passed to this function. Thanks to that,
we do not have to match against the variants that could not ever be passed
there (which was the case for QueryError).
Request is a more fitting name here.
Same as for LBP::on_query_failure, it narrows the type.
Introduced new error type and adjusted session.rs, speculative_execution
module and iterator module to this type.
Introduced:
- RequestTimeout(std::time::Duration) - for requests that timed out with provided
  client timeout
- SchemaAgreementTimeout(std::time::Duration) - for schema agreement timeouts
This represents either a request failure, or a request timeout.

It's created to narrow the type passed to history listener.
- `log_attempt_error` will now accept an error representing a single
   request failure - namely `UserRequestError`
- `log_query_error` will now accept an error representing a timeoutable
   request run failure. Compared to `UserRequestError`, it additionally
   can contain information about an empty plan error, timeout error etc.
I marked `PartitionKeyError` as non_exhaustive. Narrowed the return type
of remaining funtions that returned `QueryError` to `PartitionKeyError`.
Added an explicit conversion function PartitionKeyError -> QueryError.
The `RequestTimeout` can only be constructed in analogous session.rs
code. Thus, to narrow the error type (later in this PR) even more in iterator API,
we convert it safely back to RetriableRequestError (after it was passed
to HistoryListener).
Narrowed the error types in multiple places in internal API of
iterator module. Now the error type we manipulate on mainly is
`NextPageError` (instead of `QueryError`).

I did not change the return type of public methods yet.
I want to do it in a separate commit.
@muzarski muzarski marked this pull request as draft December 27, 2024 07:23
@muzarski muzarski self-assigned this Dec 27, 2024
Copy link

github-actions bot commented Dec 27, 2024

cargo semver-checks detected some API incompatibilities in this PR.
Checked commit: c4b17fe

See the following report for details:

cargo semver-checks output
./scripts/semver-checks.sh --baseline-rev 847e44d61e65eccb6205bd586ccaa808e57a6c19
+ cargo semver-checks -p scylla -p scylla-cql --baseline-rev 847e44d61e65eccb6205bd586ccaa808e57a6c19
     Cloning 847e44d61e65eccb6205bd586ccaa808e57a6c19
    Building scylla v0.15.0 (current)
       Built [  24.223s] (current)
     Parsing scylla v0.15.0 (current)
      Parsed [   0.055s] (current)
    Building scylla v0.15.0 (baseline)
       Built [  22.867s] (baseline)
     Parsing scylla v0.15.0 (baseline)
      Parsed [   0.053s] (baseline)
    Checking scylla v0.15.0 -> v0.15.0 (no change)
     Checked [   0.119s] 107 checks: 98 pass, 9 fail, 0 warn, 0 skip

--- failure constructible_struct_adds_field: externally-constructible struct adds field ---

Description:
A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.
        ref: https://doc.rust-lang.org/reference/expressions/struct-expr.html
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.38.0/src/lints/constructible_struct_adds_field.ron

Failed in:
  field StructuredHistory.requests in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/history.rs:257

--- failure enum_marked_non_exhaustive: enum marked #[non_exhaustive] ---

Description:
A public enum has been marked #[non_exhaustive]. Pattern-matching on it outside of its crate must now include a wildcard pattern like `_`, or it will fail to compile.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#attr-adding-non-exhaustive
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.38.0/src/lints/enum_marked_non_exhaustive.ron

Failed in:
  enum PartitionKeyError in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/statement/prepared_statement.rs:482
  enum PartitionKeyError in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/statement/prepared_statement.rs:482

--- failure enum_missing: pub enum removed or renamed ---

Description:
A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.38.0/src/lints/enum_missing.ron

Failed in:
  enum scylla::history::QueryHistoryResult, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/history.rs:264

--- failure enum_variant_added: enum variant added on exhaustive enum ---

Description:
A publicly-visible enum without #[non_exhaustive] has a new variant.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#enum-variant-new
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.38.0/src/lints/enum_variant_added.ron

Failed in:
  variant HistoryEvent:NewRequest in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/history.rs:92
  variant HistoryEvent:RequestSuccess in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/history.rs:93
  variant HistoryEvent:RequestError in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/history.rs:94
  variant LegacyNextRowError:NextRowError in /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/transport/iterator.rs:1186

--- failure enum_variant_missing: pub enum variant removed or renamed ---

Description:
A publicly-visible enum has at least one variant that is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.38.0/src/lints/enum_variant_missing.ron

Failed in:
  variant LegacyNextRowError::QueryError, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/transport/iterator.rs:1165
  variant HistoryEvent::NewQuery, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/history.rs:89
  variant HistoryEvent::QuerySuccess, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/history.rs:90
  variant HistoryEvent::QueryError, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/history.rs:91

--- failure struct_missing: pub struct removed or renamed ---

Description:
A publicly-visible struct cannot be imported by its prior path. A `pub use` may have been removed, or the struct itself may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.38.0/src/lints/struct_missing.ron

Failed in:
  struct scylla::history::QueryId, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/history.rs:17
  struct scylla::history::QueryHistory, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/history.rs:256
  struct scylla::transport::retry_policy::QueryInfo, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/transport/retry_policy.rs:9
  struct scylla::retry_policy::QueryInfo, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/transport/retry_policy.rs:9

--- failure struct_pub_field_missing: pub struct's pub field removed or renamed ---

Description:
A publicly-visible struct has at least one public field that is no longer available under its prior name. It may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#item-remove
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.38.0/src/lints/struct_pub_field_missing.ron

Failed in:
  field queries of struct StructuredHistory, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/history.rs:252

--- failure trait_method_added: pub trait method added ---

Description:
A non-sealed public trait added a new method without a default implementation, which breaks downstream implementations of the trait
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-item-no-default
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.38.0/src/lints/trait_method_added.ron

Failed in:
  trait method scylla::history::HistoryListener::log_request_start in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/history.rs:42
  trait method scylla::history::HistoryListener::log_request_success in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/history.rs:45
  trait method scylla::history::HistoryListener::log_request_error in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/scylla/src/history.rs:48

--- failure trait_method_missing: pub trait method removed or renamed ---

Description:
A trait method is no longer callable, and may have been renamed or removed entirely.
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#major-any-change-to-trait-item-signatures
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.38.0/src/lints/trait_method_missing.ron

Failed in:
  method log_query_start of trait HistoryListener, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/history.rs:39
  method log_query_success of trait HistoryListener, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/history.rs:42
  method log_query_error of trait HistoryListener, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/history.rs:45
  method on_query_success of trait LoadBalancingPolicy, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/transport/load_balancing/mod.rs:83
  method on_query_failure of trait LoadBalancingPolicy, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/transport/load_balancing/mod.rs:86
  method on_query_success of trait LoadBalancingPolicy, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/transport/load_balancing/mod.rs:83
  method on_query_failure of trait LoadBalancingPolicy, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-847e44d61e65eccb6205bd586ccaa808e57a6c19/389a3366a0a28da0298589ce4c12e851cb8631c2/scylla/src/transport/load_balancing/mod.rs:86

     Summary semver requires new major version: 9 major and 0 minor checks failed
    Finished [  48.434s] scylla
    Building scylla-cql v0.4.0 (current)
       Built [  11.002s] (current)
     Parsing scylla-cql v0.4.0 (current)
      Parsed [   0.037s] (current)
    Building scylla-cql v0.4.0 (baseline)
       Built [  11.062s] (baseline)
     Parsing scylla-cql v0.4.0 (baseline)
      Parsed [   0.036s] (baseline)
    Checking scylla-cql v0.4.0 -> v0.4.0 (no change)
     Checked [   0.116s] 107 checks: 107 pass, 0 skip
     Summary no semver update required
    Finished [  22.824s] scylla-cql
make: *** [Makefile:61: semver-rev] Error 1

@github-actions github-actions bot added the semver-checks-breaking cargo-semver-checks reports that this PR introduces breaking API changes label Dec 27, 2024
@muzarski muzarski force-pushed the iterator-errors-refactor branch from 4a964ef to c4b17fe Compare December 27, 2024 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-checks-breaking cargo-semver-checks reports that this PR introduces breaking API changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant