You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -141,6 +141,8 @@ Contributions are welcome! If you are interested in contributing towards a new o
141
141
Setup steps for working with the repository locally are documented [here](docs/Developing%20DistributedLock.md).
142
142
143
143
## Release notes
144
+
- 2.6
145
+
- Add support for acquiring transaction-scoped Postgres locks using externally-owned transactions. Thanks [@Tzachi009](https://github.com/Tzachi009) for implementing! ([#213](https://github.com/madelson/DistributedLock/issues/213), DistributedLock.Postgres 1.3)
144
146
- 2.5.1
145
147
- Increase efficiency of Azure blob locks when the blob does not exist. Thanks [@richardkooiman](https://github.com/richardkooiman) for implementing! ([#227](https://github.com/madelson/DistributedLock/pull/227), DistributedLock.Azure 1.0.2)
146
148
- Improve error handling in race condition scenarios for Azure blobs. Thanks [@MartinDembergerR9](https://github.com/MartinDembergerR9) for implementing! ([#228](https://github.com/madelson/DistributedLock/pull/228), DistributedLock.Azure 1.0.2)
Copy file name to clipboardExpand all lines: docs/DistributedLock.Postgres.md
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,17 @@ await using (await @lock.AcquireAsync())
18
18
- The `PostgresDistributedReaderWriterLock` class implements the `IDistributedReaderWriterLock` interface.
19
19
- The `PostgresDistributedSynchronizationProvider` class implements the `IDistributedLockProvider` and `IDistributedReaderWriterLockProvider` interfaces.
20
20
21
+
As of version 1.3, an additional set of static APIs on `PostgresDistributedLock` allows you to leverage transaction-scoped locking with an existing `IDbTransaction` instance. Since Postgres offers no way to explicitly release transaction-scoped locks and the caller controls the transaction, these locks are acquire-only and do not need a using block. For example:
22
+
```C#
23
+
using (vartransaction=connection.BeginTransaction())
24
+
{
25
+
...
26
+
// acquires the lock; it will be held until the transaction ends
Under the hood, [Postgres advisory locks can be based on either one 64-bit integer value or a pair of 32-bit integer values](https://www.postgresql.org/docs/12/functions-admin.html#FUNCTIONS-ADVISORY-LOCKS). Because of this, rather than taking in a name the lock constructors take a `PostgresAdvisoryLockKey` object which can be constructed in several ways:
// For transaction scoped locks, we can't roll back the save point on success because that will roll
128
-
// back our hold on the lock. It's ok to "leak" the savepoint in that case because it's an internally-owned
129
-
// transaction/connection and the savepoint will be cleaned up with the disposal of the transaction.
141
+
if(needsSavePoint
142
+
// For transaction scoped locks, we can't roll back the save point on success because that will roll back our hold on the lock.
143
+
// It's ok to "leak" the savepoint because if it's an internally-owned transaction then the savepoint will be cleaned up with the disposal of the transaction.
144
+
// If it's an externally-owned transaction then we must "leak" it or we will lose the lock. Also, we can't avoid using a save point in this case
145
+
// because otherwise if an exception had occurred the extrenally-owned transaction will be aborted and become completely unusable.
// If the connection is externally-owned with an established transaction,
231
+
// it means that the connection came through the transactional locking APIs (see PostgresDistributedLock.Transactions.cs).
187
232
if(connection.HasTransaction){returntrue;}
188
-
if(!connection.IsExernallyOwned){returnfalse;}
189
233
190
-
// If the connection is externally owned, then it might be part of a transaction that we can't
191
-
// see. In that case, the only real way to detect it is to begin a new one
234
+
// The externally-owned connection might still be part of a transaction that we can't see.
235
+
// This can only be the case if the externally-owned connection didn't came through the transactional locking APIs (see PostgresDistributedLock.Transactions.cs).
236
+
// In that case, the only real way to detect the transaction is to begin a new one.
0 commit comments