-
Notifications
You must be signed in to change notification settings - Fork 0
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
Go: Implement connection logic in lib.rs #119
Go: Implement connection logic in lib.rs #119
Conversation
go/glide/glide.go
Outdated
C.command(glideRedisClient.coreClient, C.uintptr_t(resultChannelPtr), requestType, C.uintptr_t(1), &cArgs[0]) | ||
resultPayload := <-resultChannel | ||
|
||
return resultPayload.value, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return resultPayload.value, nil | |
return resultPayload.value, resultPayload.errMessage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will deal with this later when we add command logic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's merge this PR with Aaron's glide.go PR.
Add IT tests for connection.
Remove the set/get/ping/info content for a follow-up PR.
go/examples/main.go
Outdated
request.Addresses, | ||
&protobuf.NodeAddress{Host: "localhost", Port: uint32(6379)}, | ||
) | ||
err := client.ConnectToRedis(request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if a user calls client.set() before they call ConnectToRedis?
go/glide/lib.h
Outdated
/** | ||
* Failure callback that is called when a Redis command fails. | ||
*/ | ||
typedef void (*FailureCallback)(uintptr_t channel_address, const struct RedisErrorFFI *error); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ease marshalling it is better to have
typedef void (*FailureCallback)(uintptr_t channel_address, const struct RedisErrorFFI *error); | |
typedef void (*FailureCallback)(uintptr_t channel_address, ErrorType error_type, const char *message); |
Otherwise we have to deal with memory allocations/deallocations for that struct pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've already implemented the proper functions for freeing this struct and the string within. We can do this, but it goes against what's in the design doc and we'll have to make sure Aaron's work is aligned with this API change as well. I think we should discuss this first with the rest of the team before changing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is ok to adjust the design doc now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it? @aaron-congo are you aware of these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't aware. We need the RedisErrorFFI and a mechanism to free it for the connection request, since we are not using a callback and C functions can only return a single result. If we need these things anyways, should we just use it in the failure callback as planned?
|
||
func (glideRedisClient *GlideRedisClient) CloseClient() error { | ||
if glideRedisClient.coreClient == nil { | ||
return fmt.Errorf("Cannot close glide client before it has been created.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... or already closed
if glideRedisClient.coreClient == nil { | ||
return fmt.Errorf("Cannot close glide client before it has been created.") | ||
} | ||
C.close_client(glideRedisClient.coreClient) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C.close_client(glideRedisClient.coreClient) | |
C.close_client(glideRedisClient.coreClient) | |
glideRedisClient.coreClient = nil |
go/src/lib.rs
Outdated
} | ||
|
||
/// FFI compatible version of the ErrorType enum defined in protobuf. | ||
// TODO: Update when command errors are implemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add valkey-io#1077 reference for TODO
We will remove this enum after valkey-io#1077
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1077 merged, you can update your code and remove TODO
go/src/lib.rs
Outdated
let msg = CString::new(err.to_string()).unwrap(); | ||
RedisErrorFFI { | ||
message: msg.into_raw(), | ||
error_type: ErrorType::ConnectionError, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to make a function for this? You repeat it 3 times
go/glide/lib.h
Outdated
typedef void (*FailureCallback)(uintptr_t channel_address, const struct RedisErrorFFI *error); | ||
|
||
/** | ||
* Creates a new client to the given address. The success callback needs to copy the given string synchronously, since it will be dropped by Rust once the callback returns. All callbacks should be offloaded to separate threads in order not to exhaust the client's thread pool. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the given string you are referring to here? Would it make sense to move the success callback sentence here to be above the SuccessCallback doc instead of the create_client doc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to remember where I copied this doc comment from originally. I think it was the C# implementation? I can still move it if you like.
@@ -10,6 +10,7 @@ require ( | |||
|
|||
require ( | |||
github.com/BurntSushi/toml v1.2.1 // indirect | |||
github.com/golang/protobuf v1.5.3 // indirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know why this is added? On my connect branch it is not needed since protobuf is already listed on line 7. If you do go mod tidy
does this get removed?
Co-authored-by: Aaron <[email protected]>
Co-authored-by: Aaron <[email protected]>
Co-authored-by: Yury-Fridlyand <[email protected]>
Co-authored-by: Aaron <[email protected]>
Ok(client) => ConnectionResponse { | ||
conn_ptr: Box::into_raw(Box::new(client)) as *const c_void, | ||
error_message: std::ptr::null(), | ||
error_type: RequestErrorType::Unspecified, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we ash Shachar to define NoError
enum variant? (later)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice. We'll see what he thinks though.
CI is red |
go/src/lib.rs
Outdated
|
||
/// Deallocates a `ConnectionResponse`. | ||
/// | ||
/// This function does not free the contained error, which needs to be freed separately using `free_error` afterwards to avoid memory leaks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this doc will have to get updated since it now frees the error
* * `error_msg_ptr` must be able to be safely casted to a valid `CString` via `CString::from_raw`. See the safety documentation of [`std::ffi::CString::from_raw`](https://doc.rust-lang.org/std/ffi/struct.CString.html#method.from_raw). | ||
* * `error_msg_ptr` must not be null. | ||
*/ | ||
void free_error(const char *error_msg_ptr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why re-expose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assumed that the failure callback would use it for the error it gets for commands. Not relevant for connection logic though, so I guess it can be reverted. Up to you, since you have all the changes in your branch now.
Closing as all relevant changes are integrated into other branches now. |
No description provided.