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

Go: Implement connect #136

Closed
wants to merge 11 commits into from

Conversation

aaron-congo
Copy link

  • adds lib.rs and Go logic to establish standalone and cluster connections
  • adds integration test logic to setup/teardown redis servers
  • adds integration tests for connect workflows

go/api/base_client.go Show resolved Hide resolved
go/api/base_client.go Outdated Show resolved Hide resolved
@aaron-congo aaron-congo reopened this Mar 13, 2024
Copy link

@SanHalacogluImproving SanHalacogluImproving left a comment

Choose a reason for hiding this comment

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

Seems like this PR is too big to go to upstream why not push lib.rs first get the review on it and then push the go code?

go/api/base_client.go Show resolved Hide resolved
go/api/base_client.go Outdated Show resolved Hide resolved
go/api/base_client.go Outdated Show resolved Hide resolved
return errors.New("close called on uninitialized or already closed client")
}

C.close_client(client.coreClient)

Choose a reason for hiding this comment

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

This is something in the future to think about but what happens when a client is closed and a command gets called? Assuming the pointer will be null we probably need to handle it on the rust or go side.

Copy link
Author

@aaron-congo aaron-congo Mar 14, 2024

Choose a reason for hiding this comment

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

Yeah the other clients check if the client is already closed before attempting to execute a command and throw a ClosingError if they are, so we should do something similar if coreClient is nil. Note that Shachar said ClosingError is only applicable to UDS clients (see here) so we'd return something different (probably DisconnectError)

Choose a reason for hiding this comment

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

valkey-io#1077 (comment) I think it should be a closing error.

Copy link

@Yury-Fridlyand Yury-Fridlyand Mar 18, 2024

Choose a reason for hiding this comment

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

What if client get closed while a command being executed? We should protect vs application crash in that case too.
My idea so far is to add one more argument to callbacks - client id. A callback submitted to rust would be a static function then, which can dispatch the response to a client if it is not closed yet or ignore vice versa.
TBD

go/integTest/error_handling_test.go Outdated Show resolved Hide resolved
@aaron-congo aaron-congo force-pushed the go/dev_acongo_connect branch from 3764973 to 0d52ffa Compare March 14, 2024 20:01
@aaron-congo
Copy link
Author

aaron-congo commented Mar 14, 2024

Seems like this PR is too big to go to upstream why not push lib.rs first get the review on it and then push the go code?

I think I brought up this idea before and IIRC Andrew thought they wouldn't want the lib.rs without any integration tests. The PR isn't small but it isn't massive either, I think I will just open it against upstream once this is approved and see if they ask me to split the lib.rs out

.github/workflows/go.yml Outdated Show resolved Hide resolved
.github/workflows/go.yml Outdated Show resolved Hide resolved
return errors.New("close called on uninitialized or already closed client")
}

C.close_client(client.coreClient)
Copy link

@Yury-Fridlyand Yury-Fridlyand Mar 18, 2024

Choose a reason for hiding this comment

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

What if client get closed while a command being executed? We should protect vs application crash in that case too.
My idea so far is to add one more argument to callbacks - client id. A callback submitted to rust would be a static function then, which can dispatch the response to a client if it is not closed yet or ignore vice versa.
TBD

go/integTest/setup_teardown_test.go Show resolved Hide resolved
clusterManagerOutput := runClusterManager(suite, []string{"start", "-r", "0"}, false)

suite.standalonePorts = extractPorts(suite, clusterManagerOutput)
suite.T().Logf("Standalone ports = %s", fmt.Sprint(suite.standalonePorts))

Choose a reason for hiding this comment

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

Sorry for stupid golang question - what does suite.T() do? Where it is defined?

Copy link
Author

@aaron-congo aaron-congo Mar 18, 2024

Choose a reason for hiding this comment

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

For tests that aren't part of a test suite, you need to pass a parameter of type testing.T which provides a test context and methods for printing and logging (more info here). Here we are using a test suite, and you access testing.T via suite.T() instead of as a direct parameter. This is mentioned in Testify's docs here

.github/workflows/go.yml Outdated Show resolved Hide resolved
go/integTest/connection_test.go Show resolved Hide resolved
go/src/lib.rs Outdated
@@ -1,9 +1,159 @@
#![deny(unsafe_op_in_unsafe_fn)]

Choose a reason for hiding this comment

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

Move this after license header

Copy link
Author

Choose a reason for hiding this comment

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

The Rust code exists in this PR to get tests passing but we are reviewing it under a separate PR here: https://github.com/aws/glide-for-redis/pull/1127/files

@aaron-congo aaron-congo force-pushed the go/dev_acongo_connect branch from 5b5add8 to 6fe92fb Compare March 20, 2024 15:44
@@ -140,8 +140,7 @@ func (strategy *BackoffStrategy) toProtobuf() *protobuf.ConnectionRetryStrategy
}
}

// RedisClientConfiguration represents the configuration settings for a Standalone Redis client. baseClientConfiguration is an
// embedded struct that contains shared settings for standalone and cluster clients.
// RedisClientConfiguration represents the configuration settings for a Standalone Redis client.
Copy link
Author

Choose a reason for hiding this comment

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

I realized that the final documentation does not show the unexported fields, so it doesn't make sense to mention baseClientConfiguration here

}

// NewRedisClient creates a Redis client in standalone mode using the given [RedisClientConfiguration].
func NewRedisClient(config *RedisClientConfiguration) (*RedisClient, error) {
Copy link
Author

Choose a reason for hiding this comment

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

In Java this is called CreateClient, but in Go the idiom is that a function called NewRedisClient should be provided if users aren't supposed to initialize a RedisClient struct directly. Also, the Go docs normally will document exported symbols alphabetically but will place New functions immediately underneath the document for the associated struct. We lose this clarity if we call this CreateClient

@aaron-congo aaron-congo force-pushed the go/integ_acongo_connect branch from 033fe5d to c4daccd Compare March 21, 2024 00:05
@aaron-congo aaron-congo force-pushed the go/dev_acongo_connect branch from 4720d29 to d7f10e3 Compare March 21, 2024 00:08
@aaron-congo
Copy link
Author

Closing as this is superseded by another PR upstream (valkey-io#1937)

@aaron-congo aaron-congo deleted the go/dev_acongo_connect branch July 17, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants