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

session: adjust naming in internal session functions #1156

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

Conversation

muzarski
Copy link
Contributor

@muzarski muzarski commented Dec 23, 2024

During error refactor, I found it hard to understand what which function does on a request execution path. Three different names were used:

  • run_query
  • execute_query
  • do_query

I renamed them (and all internal structures/traits related to these functions). The _query part is very misleading. It would suggest that we want to execute a CQL QUERY request, which is not true - these functions/closures are generic and allow to execute QUERY, EXECUTE and BATCH CQL requests.

Kind of related to #713

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.
@muzarski muzarski self-assigned this Dec 23, 2024
Copy link

github-actions bot commented Dec 23, 2024

cargo semver-checks found no API-breaking changes in this PR! 🎉🥳
Checked commit: a4e52f2

Copy link
Collaborator

@Lorak-mmk Lorak-mmk left a comment

Choose a reason for hiding this comment

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

"Request" is a good word here, but you still use "execute" which is also a CQL command. Maybe "do" / "perform" / "run" are better words than "execute"?

@muzarski
Copy link
Contributor Author

"Request" is a good word here, but you still use "execute" which is also a CQL command. Maybe "do" / "perform" / "run" are better words than "execute"?

That was one of my doubts. IMO, to execute a request fits the best, but I agree that it can suggest the EXECUTE CQL request. What I don't like about "run" is that we then would have a run_request function which then calls run_request_with_retries (or maybe I'm just overthinking, and that's totally fine). I don't really like "perform" that much. My picks would be "run_request_[with_retries/once]", "send_request_[with_retries/once]" or "do_request_[with_retries/once]" with a little bias towards "send".

@Lorak-mmk
Copy link
Collaborator

I don't really like "send" because we are not just sending request - we receive the response, we perform speculative execution, retries etc.
"send" would be a good word for some method in Connection that does just that.

What I don't like about "run" is that we then would have a run_request function which then calls run_request_with_retries (or maybe I'm just overthinking, and that's totally fine).

Now we have what? run_request that calls execute_request_with_retries?
I don't really see what is the difference between "running" a request and "executing" the request . Those names don't really say which layer is responsible for what, apart from "with_retries" telling us that the inner one will use retry policy.

I'm not sure what is the proper naming here tbh. Maybe this naming difficulty is a hint that the division of responsibilities between various functions should be different?

@muzarski
Copy link
Contributor Author

I'm not sure what is the proper naming here tbh. Maybe this naming difficulty is a hint that the division of responsibilities between various functions should be different?

Current division makes sense to me. run_request (previously run_query) takes speculative execution into account, and prepares the plan (either exclusive or shared) based on whether speculative execution applies for the statement. It also constructs the RetrySession from statement config. Then it calls (directly for standard path, or indirectly in speculative_execution::execute()) execute_request_with_retries (previously execute_query) providing it the plan and retry session. execute_request_with_retries iterates over the plan, executing the request on each target sequentially wrt. plan and retry decisions.

When it comes to naming, I'll rename all of the functions/closures to run_*. As you said, run and execute do not distinguish between the execution layers anyway.

@Lorak-mmk
Copy link
Collaborator

I'm not sure what is the proper naming here tbh. Maybe this naming difficulty is a hint that the division of responsibilities between various functions should be different?

Current division makes sense to me. run_request (previously run_query) takes speculative execution into account, and prepares the plan (either exclusive or shared) based on whether speculative execution applies for the statement. It also constructs the RetrySession from statement config. Then it calls (directly for standard path, or indirectly in speculative_execution::execute()) execute_request_with_retries (previously execute_query) providing it the plan and retry session. execute_request_with_retries iterates over the plan, executing the request on each target sequentially wrt. plan and retry decisions.

What do you think about utilizing "speculative fiber" terminology?
run_request_speculative_fiber does convey that speculative execution won't be utilized in the function and must be instead handled by the caller.

@muzarski
Copy link
Contributor Author

What do you think about utilizing "speculative fiber" terminology? run_request_speculative_fiber does convey that speculative execution won't be utilized in the function and must be instead handled by the caller.

Sounds good. I like it.

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
@muzarski muzarski force-pushed the rename-run-do-execute-query branch from 8429b53 to a4e52f2 Compare December 24, 2024 04:12
@muzarski muzarski requested a review from Lorak-mmk December 24, 2024 04:13
@muzarski
Copy link
Contributor Author

Flaky test_coalescing test failed:

'transport::connection::tests::test_coalescing' panicked at scylla/src/transport/connection.rs:2609:78:
called `Result::unwrap()` on an `Err` value: JoinError::Panic(Id(1184), "called `Result::unwrap()` on an `Err` value: DbError(Unprepared { statement_id: b\"\\xb7/\\x95\\xb8\\xd0\\\"\\x9dq\\xcfp]\\x1a\\x9f\\xa3e<\" }, \"Prepared query with ID b72f95b8d0229d71cf705d1a9fa3653c not found (either the query was not prepared on this host (maybe the host has been restarted?) or you have prepared too many queries and it has been evicted from the internal cache)\")", ...)

@Lorak-mmk
Copy link
Collaborator

Flaky test_coalescing test failed:

'transport::connection::tests::test_coalescing' panicked at scylla/src/transport/connection.rs:2609:78:
called `Result::unwrap()` on an `Err` value: JoinError::Panic(Id(1184), "called `Result::unwrap()` on an `Err` value: DbError(Unprepared { statement_id: b\"\\xb7/\\x95\\xb8\\xd0\\\"\\x9dq\\xcfp]\\x1a\\x9f\\xa3e<\" }, \"Prepared query with ID b72f95b8d0229d71cf705d1a9fa3653c not found (either the query was not prepared on this host (maybe the host has been restarted?) or you have prepared too many queries and it has been evicted from the internal cache)\")", ...)

Restarted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants