Skip to content

Support shared distributed locks for PostgreSQL #14

@Side-Cloud

Description

@Side-Cloud

Proposal: adding support for shared distributed locks to the EntityFrameworkCore.Locking.PostgreSQL provider.

In many scenarios we need to allow multiple concurrent readers while keeping writers exclusive – the classic shared/exclusive lock pattern. PostgreSQL advisory locks natively support this via shared locks (e.g., pg_advisory_lock_shared).

Currently there is no way to request a shared distributed lock. I'd like to propose adding support for shared locks.

Here are two proposals:

Proposal 1 – Add a separate AcquireSharedDistributedLock method

public static IDistributedLockHandle AcquireSharedDistributedLock(
    this DatabaseFacade database,
    string key,
    TimeSpan? timeout = null)

Proposal 2 – Introduce a DistributedLockMode enum and overload the existing method

public enum DistributedLockMode
{
    Exclusive,
    Shared
}

public static IDistributedLockHandle AcquireDistributedLock(
    this DatabaseFacade database,
    string key,
    TimeSpan? timeout = null,
    DistributedLockMode mode = DistributedLockMode.Exclusive)

Both proposals only affect the PostgreSQL provider; other providers could implement shared locks according to their own capabilities, or simply ignore the mode and always use exclusive locks, or throw NotSupportedException()

Would you consider adding shared advisory lock support via either of these approaches?

Thanks for your consideration!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions