Skip to content

Conversation

@akshah123
Copy link

This adds a complete locking mechanism for SQL Server, similar to the existing PostgreSQL implementation from PR #993.

Features:

  • Table-based locking using MERGE for atomic upserts
  • Session-based locking using sp_getapplock/sp_releaseapplock
  • Automatic lease renewal via heartbeat mechanism
  • Stale lock cleanup for expired leases

Implementation:

  • lock/internal/store/sqlserver.go: LockStore implementation
  • lock/sqlserver.go: Public API (NewSqlserverTableLocker, NewSqlserverSessionLocker)
  • internal/testing/testdb/sqlserver.go: Docker test helper
  • SQL Server specific test migrations
  • Comprehensive integration tests for both locking modes

The table-based locker uses SQL Server's MERGE statement with HOLDLOCK for atomic lock acquisition and SYSUTCDATETIME() for server-side time. The session-based locker uses SQL Server's built-in application lock stored procedures which provide session-level advisory locking.

This adds a complete locking mechanism for SQL Server, similar to
the existing PostgreSQL implementation from PR pressly#993.

Features:
- Table-based locking using MERGE for atomic upserts
- Session-based locking using sp_getapplock/sp_releaseapplock
- Automatic lease renewal via heartbeat mechanism
- Stale lock cleanup for expired leases

Implementation:
- lock/internal/store/sqlserver.go: LockStore implementation
- lock/sqlserver.go: Public API (NewSqlserverTableLocker, NewSqlserverSessionLocker)
- internal/testing/testdb/sqlserver.go: Docker test helper
- SQL Server specific test migrations
- Comprehensive integration tests for both locking modes

The table-based locker uses SQL Server's MERGE statement with HOLDLOCK
for atomic lock acquisition and SYSUTCDATETIME() for server-side time.
The session-based locker uses SQL Server's built-in application lock
stored procedures which provide session-level advisory locking.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants