-
Notifications
You must be signed in to change notification settings - Fork 205
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
Postgres: consider constructor with NpgsqlDatasource #153
Comments
Hey @madelson, has there been any progress on this one? This would be very helpful for us as we use the distributed lock for some scenario where we want to avoid processes overlapping each other. |
@davidngjy for my knowledge, do Postgres locks actually work in that load balanced scenario? How does it synchronize across clusters? This issue should be pretty straightforward to implement, I just haven’t gotten around to it yet (and no one had explicitly asked for it). Basically we would just be using the data source as a connection factory. |
Hey @madelson, Sorry, I realised that load balancing is not correct term for it. We have a single primary with multiple read replicas. Specifically, we're using AWS Aurora with two clusters (one in each region), where only one instance across the entire cluster acts as the primary. We have a shared package leveraging your Following the Npgsql documentation and in combination with the provided DI package, we currently resolving the
While this works, the icky part is the line It would be nice to have the
Maybe even have the library to have the option for
Not sure if it's too opinionated but the lock must operate on the |
Hey @madelson, has any work been done on this one yet? |
Go for it @davidngjy ! as far as advice, if you follow the code flow for the connection string constructor you can see that on one path we pretty quickly get to creating a connection factory function which would be easy to create with the datasource’s create connection function as well. what would be trickier is if we want to support multiplexing in this configuration. That would require changes to the multiplexing infra in core. Up to you if you want to look into that; the first version could make the new constructor incompatible with multiplexing. as far as API, I would expect that the only change is a new constructor on the lock classes which takes DBDatasource instead off connection string. |
Hey @madelson, I made my first attempt at implementing support for One thing I'm unsure about is the Would my assumption be correct that we should manage the connection internally when a Also, I'm unsure about the merging strategy, please guide me through this. |
LGTM so far; left a couple comments on the PR so please take a look. A few more thoughts: isExternallyOwnedThis flag indicates who is owns the connection. A connection provided by a library user is externally owned so the library cannot close it and can only access it when the user specifically requests. In this case, the library is creating the connection via the data source so it is correct for DbDataSourceTo use |
Hey @madelson, Thanks for the explanation! I did encounter some build issues when referencing DbDataSource directly, but those go away when I add a conditional branch for net7 or higher. One issue I have is that when I add the if branch (see screenshot below), the whole block is greyed out, and I lose the analyzer. However, I can still write tests that target the specific constructor just fine. Most of our apps are on .NET 8 now, with just a few on .NET 7, so we are all good! Let me know if I made the changes correctly in the latest push. If so, the next step would be to add test coverage. I would appreciate any guidance on where to start or if there's a reference I could refer to! |
Hey @madelson, I made some updates to the PR. The I've added some tests, they're mainly checking the nullability and the multiplexing configuration. Not sure if there's anything else required. I keep getting the following errors
Didn't touch this method, not sure why it's showing up suddenly.
These are not a new overload to any existing methods, I can't seems to get rid of it even after a rebase. Please let me know how should I proceed with this, thanks! |
…Datasource GH-153 Add Support for NpgsqlDataSource
@davidngjy I merged your PR and published this as DistributedLock.Postgres 1.2. Thanks for contributing! |
Awesome thanks @madelson! |
No description provided.
The text was updated successfully, but these errors were encountered: