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: metadata errors refactor #1170

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

muzarski
Copy link
Contributor

@muzarski muzarski commented Jan 16, 2025

Ref: #519

Motivation

The goal of this PR is to purge metadata.rs of QueryError, and replace it with MetadataError. Thanks to that metadata related functions are now independent of QueryError.

I tried to split this PR into commits, so each commit handles one function/method from metadata module. New error variants are introduced where necessary.

When it comes to public API - after this PR Session::refresh_metadata() will now return MetadataError.

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.

@muzarski muzarski marked this pull request as draft January 16, 2025 17:45
@muzarski muzarski force-pushed the topology-errors-refactor branch from 3e1aa4e to 6283bee Compare January 16, 2025 17:46
@muzarski muzarski self-assigned this Jan 16, 2025
@muzarski muzarski added this to the 0.16.0 milestone Jan 16, 2025
@muzarski muzarski added the API-stability Part of the effort to stabilize the API label Jan 16, 2025
@github-actions github-actions bot added the semver-checks-breaking cargo-semver-checks reports that this PR introduces breaking API changes label Jan 16, 2025
Copy link

github-actions bot commented Jan 16, 2025

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

See the following report for details:

cargo semver-checks output
./scripts/semver-checks.sh --baseline-rev d40e1846961f9e6116c5f719c13d4ffbb681e6da
+ cargo semver-checks -p scylla -p scylla-cql --baseline-rev d40e1846961f9e6116c5f719c13d4ffbb681e6da
     Cloning d40e1846961f9e6116c5f719c13d4ffbb681e6da
    Building scylla v0.15.0 (current)
       Built [  24.134s] (current)
     Parsing scylla v0.15.0 (current)
      Parsed [   0.059s] (current)
    Building scylla v0.15.0 (baseline)
       Built [  22.372s] (baseline)
     Parsing scylla v0.15.0 (baseline)
      Parsed [   0.050s] (baseline)
    Checking scylla v0.15.0 -> v0.15.0 (no change)
     Checked [   0.110s] 107 checks: 106 pass, 1 fail, 0 warn, 0 skip

--- 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 ProtocolError::InvalidCqlType, previously in file /home/runner/work/scylla-rust-driver/scylla-rust-driver/target/semver-checks/git-d40e1846961f9e6116c5f719c13d4ffbb681e6da/f203671dfa2c3e0c818ba852f967e3e3e1c39a50/scylla/src/errors.rs:335

     Summary semver requires new major version: 1 major and 0 minor checks failed
    Finished [  47.808s] scylla
    Building scylla-cql v0.4.0 (current)
       Built [  10.834s] (current)
     Parsing scylla-cql v0.4.0 (current)
      Parsed [   0.034s] (current)
    Building scylla-cql v0.4.0 (baseline)
       Built [  11.129s] (baseline)
     Parsing scylla-cql v0.4.0 (baseline)
      Parsed [   0.034s] (baseline)
    Checking scylla-cql v0.4.0 -> v0.4.0 (no change)
     Checked [   0.108s] 107 checks: 107 pass, 0 skip
     Summary no semver update required
    Finished [  22.709s] scylla-cql
make: *** [Makefile:61: semver-rev] Error 1

This also allows us to remove the FIXME regarding DbError returned
from cassandra clusters during metadata fetch.
I introduced a utility trait which converts multiple lower-level errors
to a specific error type that provides more context.

The function is now generic over the trait implementations.

After this commit, there is an outdated comment next to nested
`make_keyspace_filtered_query_pager` function. It will be addressed
in the following commit.
The inner function was made generic after changes from previous commit.
There is no point in having a separate function. Converted it to an async
block.
@muzarski muzarski force-pushed the topology-errors-refactor branch from 6283bee to 54f07fb Compare January 24, 2025 12:10
@muzarski muzarski force-pushed the topology-errors-refactor branch from 54f07fb to 898b1f8 Compare January 24, 2025 12:32
@muzarski muzarski marked this pull request as ready for review January 24, 2025 12:32
Comment on lines 987 to 990
// This function is extracted to reduce monomorphisation penalty:
// query_filter_keyspace_name() is going to be monomorphised into 5 distinct functions,
// so it's better to extract the common part.
async fn make_keyspace_filtered_query_pager(
async fn make_keyspace_filtered_query_pager<E>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 (EDIT: I see it's mentioned in the commit message) As you make make_keyspace_filtered_query_pager a generic method, the comment is no longer valid.

❓ Is it feasible to keep the common part nongeneric and only add generics as a wrapper over it?

Comment on lines 1014 to 1016

let fut = async move {
let pager =
make_keyspace_filtered_query_pager::<E>(conn, query_str, keyspaces_to_fetch).await?;
let pager: QueryPager = pager_fut.await?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ I feel that inlining the pager_fut here (making the code flow linear) could be more readable here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API-stability Part of the effort to stabilize the API 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.

2 participants