-
Notifications
You must be signed in to change notification settings - Fork 3
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
Allow providing Spanner client #6
Comments
Hi @iangudger What is the use case for providing an existing Spanner client? You can pass |
A common pattern in Go is creating clients in Is there a reason why it is beneficial for this library to have a dedicated Spanner client? |
The usage of Spanner client is different between normal transactional requests and change streams, so I designed the Go package to create a dedicated Spanner client for change streams. Specifically, change streams client tends to consume more Spanner sessions to read the change streams partitions in parallel. So if the same client is used in both transactional requests and change streams, it might be a problem. |
Thanks for explaining. It might be worth adding a comment in the code. |
I agree that change streams shouldn't use the main client, but this feels a little weird to me in applications that need multiple readers. Is it a deliberate choice that there's a new client for every reader in this case? In one application, have multiple discrete components that each care about certain tables. I have a change stream for each. I would have expected something like: client := changestreams.NewClient(projectID, instanceID, databaseID)
reader := client.NewReader(ctx, streamName)
go reader.Read(ctx, callback)
otherReader := client.NewReader(ctx, otherStreamName)
go otherReader.Read(ctx, callback) instead, every call to NewReader creates a new client. I don't know whether it's actually problematic, but it's certainly more things for the library to keep track of, keep open, and close down. Rather than restructuring the library like that, this could also be mitigated by providing |
Yeah that totally makes sense > multiple streams in one application. I'm open for pull request, so please feel free to add Probably we also need to modify |
thanks :) maybe a flag on reader like (otherwise, we have to create a common place where the shared client is stored, and keep track of how many readers are using it etc, which feels overly complex.) |
Yes, that sounds very reasonable to me! :) |
This library would be easier to integrate if it had an option to construct it with an existing Spanner client.
The text was updated successfully, but these errors were encountered: