Comments (5)
Thank you for the quick response @madelson.
Yes, it is about running queries on the same transaction that holds the lock, and being able to use PgBouncer in such a case. In the critical path of the app, I acquire locks and then invoke several commands in Postgres (in a transaction) under the locks. Performance is very important in the critical path, so using the same transaction that holds the lock, instead of creating a new one seems reasonable. Moreover, this solution improves the integrity of the lock by using the same DB connection and transaction.
I understand your point regarding the API perspective, but if the API already allows the user to pass an external connection that is not under its control, then why not let the user who created the transaction have the responsibilty to end it?
Maybe another option could be to let the user configure whether the library or the user will be the responsible party of the transaction (via the PostgresConnectionOptionsBuilder class or when passing the DB connection to the API).
from distributedlock.
@Tzachi009 I think I can get behind the idea that in Postgres if you create a lock with an explicit transaction and then release the lock, it disposes the transaction. It's a little weird, but less weird than having release just noop. The user will be responsible for releasing the lock after committing the transaction.
Given those caveats, I do think it is worth thinking about what you are really getting from the library in this case vs. just issuing the same SQL commands yourself.
I'd be happy to have to you take a crack at this. Two implementation challenges I foresee:
- We'll need to figure out a plan for test coverage, since the main suite that most locks run against probably won't work under the "one time use" constraint described above
- PostgresAdvisoryLock.cs today makes use of save points and session variables to control the lock command; not sure how well any of that will behave with the added constraint of an external transation. I do think it is vital that we not pollute the transaction with overrides to session variables.
from distributedlock.
@Tzachi009 thanks for your interest in the library. IIRC, the issue is that Postgres transaction-scoped locks can’t be released without ending the transaction. So either we’re killing the users transaction for them or releasing the lock doesn’t work properly. I don’t like either of those options from an API perspective.
are you hoping to run queries on the same transaction that holds the lock or is it more just the convenience of injecting the connection in your setup?
from distributedlock.
Hi @madelson, may we continue discussing the suggestion or are you entirely opposed to the idea?
My team and I would really like to see this feature implemented, and I don't mind contributing to the library myself.
from distributedlock.
Thank you, I will start to look into it soon and will see how it goes.
Just a few points regarding what you said:
- The transactional advisory locks are released automatically when the transaction is commited or rollbacked (https://www.postgresql.org/docs/current/explicit-locking.html#ADVISORY-LOCKS), therefore that's the only the user will have to do in order to release the lock, while the library won't be able to do so.
- As a user, I can still see the advatange of using the library in such a case, since it still consolidates everything regarding the management of the lock.
- I need to get more familiar with the tests, but I will check how to test this specific scenario. I will also try to check what we can do regarding save points/session variables.
from distributedlock.
Related Issues (20)
- Consider updating Azure.Storage.Blobs to latest once linked issue is resolved
- Rename CopyPackageToPublishDirectory.targets to Directory.Build.targets
- Using UseTransaction for SqlServer locks requires explicitly disabling UseMultiplexing
- RedisDistributedLock Releases Lock Prematurely Before ParallelMethod Completes HOT 7
- Redis timeout on RedLockRelease HOT 3
- Too many UnobservedTaskException HOT 2
- IOException: directory already exists in Ubuntu
- Elaborate on ZooKeeper setup docs HOT 1
- Upgrade to NUnit 4 and leverage new features like Assert.ThatAsync and Assert.Multiple
- Use NUnit.Analyzers to prepare for migration to NUnit 4
- Add additional TFM so the dependency on System.Threading.AccessControl can be removed HOT 2
- Azure Semaphore implementation HOT 1
- Local development and CI using test containers HOT 5
- Dependency on Microsoft.Data.SqlClient 5.2.0 may be unnecessary HOT 3
- EventWaitHandle support for local namespace HOT 2
- Rare race condition with keepalive after upgrading to Npgsql 8.0.3
- Core Next Minor - normalize locking in DatabaseConnection.CreateCommand()
- Upgrade to Npgsql 8.0.3
- Take advantage of """ strings in various files
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from distributedlock.