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

[Refactor][GCS] Merge RedisAsioClient into RedisAsyncContext #49000

Conversation

MortalHappiness
Copy link
Member

@MortalHappiness MortalHappiness commented Nov 30, 2024

Why are these changes needed?

While working on #48781, we found that RedisAsioClient and RedisAsyncContext strongly depends on each other, and it is a 1-1 mapping. Therefore, we decide to merge the implementation of RedisAsioClient into RedisAsyncContext to make it self-contained.

The class diagram before this PR:

image

Note: redisAsyncContext implicitly uses RedisAsioClient via the callback function.

The class diagram after this PR:

image

Related issue number

N/A

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run scripts/format.sh to lint the changes in this PR.
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

@MortalHappiness MortalHappiness added the go add ONLY when ready to merge, run all tests label Nov 30, 2024
@MortalHappiness MortalHappiness marked this pull request as ready for review November 30, 2024 12:09
@MortalHappiness MortalHappiness requested a review from a team as a code owner November 30, 2024 12:09
// A write is currently in progress
bool write_in_progress_{false};

void operate();
Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance for documentation? operate, cleanup, and most of the function names are confusing without inspecting the code, please add some documentations, thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Acutally I just copy them from the original asio.h. There is also no comment there. But I'll try to add some comments.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you!

void RedisAsyncContext::operate() {
if (read_requested_ && !read_in_progress_) {
read_in_progress_ = true;
socket_.async_read_some(boost::asio::null_buffers(),
Copy link
Contributor

@dentiny dentiny Nov 30, 2024

Choose a reason for hiding this comment

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

I'm curious about the logic:

  • From doc, the bytes read is passed to callback
  • How do we know all bytes have been read from socket?
  • LL145 shows we directly mark ongoing read/write operation as false

Copy link
Member Author

Choose a reason for hiding this comment

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

Good question. This might be due to a historical reason. We can ask other team members why we don't use async_read here.

Copy link
Member Author

Choose a reason for hiding this comment

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

cc @jjyao

@@ -92,8 +104,34 @@ class RedisAsyncContext {
/// should be minimum.
std::mutex mutex_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually I'm not quite sure we should use mutex and multi-threading here.
The only operation which might involve multi-threaded operation is operate invoked from another thread, all other operations are posted into io_service; curious why do we need concurrent operate calls?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, I don't know either. But I suspect that the predecessors decided to use a mutex because they saw this: https://github.com/redis/hiredis/blob/8d8703ee6149ffd3b38cebedd71ad8d1fac63cc7/README.md?plain=1#L152.

Copy link
Member Author

Choose a reason for hiding this comment

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

They want to make redisAsyncContext thread-safe.

@MortalHappiness MortalHappiness force-pushed the feature/merge-redisasioclient-asynccontext branch from bef27a1 to 334dfe6 Compare November 30, 2024 13:26
Copy link
Collaborator

@jjyao jjyao left a comment

Choose a reason for hiding this comment

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

LG. There is merge conflict.


void RedisAsyncContext::DelWrite() { write_requested_ = false; }

void RedisAsyncContext::Cleanup() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This used to be empty, is it intentional change?

Copy link
Member Author

@MortalHappiness MortalHappiness Dec 4, 2024

Choose a reason for hiding this comment

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

@MortalHappiness MortalHappiness force-pushed the feature/merge-redisasioclient-asynccontext branch from 334dfe6 to 3be9873 Compare December 4, 2024 23:04
@jjyao jjyao merged commit 54050c9 into ray-project:master Dec 5, 2024
5 checks passed
@@ -32,6 +36,12 @@ typedef void redisCallbackFn(struct redisAsyncContext *, void *, void *);

namespace ray {
namespace gcs {
// Adaptor callback functions for hiredis redis_async_context->ev
void CallbackAddRead(void *);
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need to place it in header file...

ujjawal-khare pushed a commit to ujjawal-khare-27/ray that referenced this pull request Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants