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

Return Query Error for non existent DC #825

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

Conversation

samuelorji
Copy link
Contributor

Return query error when there are no known nodes found during query planning

Fixes: #747

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.

@@ -1653,7 +1653,8 @@ impl Session {
QueryFut: Future<Output = Result<ResT, QueryError>>,
ResT: AllowedRunQueryResTType,
{
let mut last_error: Option<QueryError> = None;
// set default error as no known found as the query plan returns an empty iterator if there are no nodes in the plan
let mut last_error: Option<QueryError> = Some(QueryError::NoKnownNodeFoundError("Please confirm the supplied datacenters exists".to_string()));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The query_plan is an iterator that provides a Node, but this iterator can be empty due to the inability to find/pick a node which is mostly caused here.

There could be other reasons why the iterator could be empty, but I can't see any yet

@samuelorji
Copy link
Contributor Author

@Lorak-mmk. I can see that the Cassandra tests are failing on CI, but they work locally for me. Thoughts?

scylla/src/transport/session.rs Outdated Show resolved Hide resolved
scylla/src/transport/session.rs Outdated Show resolved Hide resolved
scylla-cql/src/errors.rs Outdated Show resolved Hide resolved
…d when there are no known nodes found during query plan and avoid ambiguity
@@ -1666,7 +1666,10 @@ impl Session {
.consistency_set_on_statement
.unwrap_or(execution_profile.consistency);

let mut query_plan_is_empty = true;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wanted to do a peekable check to ensure the iterator is not empty like:

query_plan.peekable()

but it caused this lifetime error:

error: higher-ranked lifetime error
   --> scylla/src/transport/session_test.rs:409:5
    |
409 | /     tokio::spawn(async move {
410 | |         let values = (
411 | |             (1_i32, 2_i32, "abc"),
412 | |             (),
...   |
415 | |         session_clone.batch(&batch, values).await.unwrap();
416 | |     })
    | |______^
    |
    = note: could not prove `[async block@scylla/src/transport/session_test.rs:409:18: 416:6]: std::marker::Send`
    ```
    So, I just defaulted to doing this more simple check

async fn test_non_existent_dc_return_correct_error() {
let ks = "iot";

let host = "127.0.0.1";
Copy link
Collaborator

Choose a reason for hiding this comment

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

The tests fail because they run Scylla on different IP. Please take a look at other tests in this file - they use create_new_session_builder() to get a session builder with correct IP. You can then call

        .default_execution_profile_handle(handle)
        .build()
        .await
        .expect("cannot create session");

on resulting builder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks


#[tokio::test]
async fn test_non_existent_dc_return_correct_error() {
let ks = "iot";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, please use unique_keyspace_name(); to prevent future conflicts with other tests. I know that the query is supposed to fail, but if we introduce a regression and it doesn't fail, it may cause other tests to fail, making it harder to understand and fix.

@Lorak-mmk Lorak-mmk requested a review from piodul October 19, 2023 13:13
Copy link
Collaborator

@piodul piodul left a comment

Choose a reason for hiding this comment

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

Notice that execute_query returns None in case there were no nodes tried. The None is converted into QueryError::ProtocolError("Empty query plan - driver bug!") at some point - look those places up by grepping on the error message. I don't like the modifications made to execute_query because now

  • The function never returns None, but it has Option in its return type,
  • The new behavior will break speculative execution (look at speculative_execution.rs).

I don't think that execute_query needs to be touched at all, it's just that the error message needs to be changed. You should go over the places where Empty query plan - driver bug! is returned, change it to the new error variant you introduced and that should be it.

@Lorak-mmk Lorak-mmk added the waiting-on-author Waiting for a response from issue/PR author label Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting-on-author Waiting for a response from issue/PR author
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Misleading error when using nonexistent DC
3 participants