-
Notifications
You must be signed in to change notification settings - Fork 240
feat: Add MongoDB distributed locks Implementation #256
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
base: master
Are you sure you want to change the base?
Conversation
Added the DistributedLock.MongoDB project, providing a MongoDB-based distributed lock implementation that supports both synchronous and asynchronous lock operations. Added core classes `MongoDistributedLock`, `MongoDistributedLockHandle`, `MongoDistributedSynchronizationOptionsBuilder`, and `MongoDistributedSynchronizationProvider` to implement lock acquisition, release, automatic renewal, and configuration functions. Updated project configuration, added dependency on `MongoDB.Driver`, and supported multiple target frameworks (.NET 8, .NET Standard 2.1, .NET Framework 4.7.2). Added usage instructions and code examples in `README.md`. Added comprehensive test coverage, including basic functionality, competition scenarios, lock loss handling, and support for custom collection names, ensuring the reliability of the functionality. Updated dependency versions and optimized internal access configuration for the test project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds MongoDB-based distributed lock support to the DistributedLock library. It introduces a new DistributedLock.MongoDB project that implements distributed locking using MongoDB as the backing store, supporting both synchronous and asynchronous operations with automatic lock renewal.
Key changes:
- New MongoDB lock implementation with automatic extension and expiry mechanisms
- Support for multiple target frameworks (.NET 8, .NET Standard 2.1, .NET Framework 4.7.2)
- Comprehensive test coverage including contention scenarios and lock loss handling
Reviewed Changes
Copilot reviewed 26 out of 27 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/DistributedLock.MongoDB/MongoDistributedLock.cs | Core lock implementation with acquisition logic and MongoDB operations |
| src/DistributedLock.MongoDB/MongoDistributedLockHandle.cs | Handle class managing lock lifecycle, extension, and release |
| src/DistributedLock.MongoDB/MongoDistributedSynchronizationProvider.cs | Provider implementation for creating MongoDB locks |
| src/DistributedLock.MongoDB/MongoDistributedSynchronizationOptionsBuilder.cs | Options builder for configuring lock behavior (expiry, extension cadence, busy wait) |
| src/DistributedLock.MongoDB/MongoLockDocument.cs | MongoDB document model for storing lock state |
| src/DistributedLock.MongoDB/README.md | Usage documentation and examples |
| src/DistributedLock.Tests/Tests/MongoDB/* | Test suite covering basic functionality, contention, and edge cases |
| src/Directory.Packages.props | Added MongoDB.Driver package dependency |
| src/DistributedLock.sln | Added MongoDB project to solution |
| src/DistributedLock/packages.lock.json | Updated with MongoDB dependencies (DnsClient, SharpCompress, Snappier, ZstdSharp.Port) |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
将字段和构造函数的访问修饰符从 internal 修改为 private,以增强封装性。修复注释中的拼写错误并优化格式,提升代码的可读性和维护性。
在 `AssemblyAttributes.cs` 文件中,新增了对 `DistributedLock.MongoDB` 的 `InternalsVisibleTo` 特性声明。 此更改允许 `DistributedLock.MongoDB` 程序集访问当前程序集的内部成员。 其他现有的 `InternalsVisibleTo` 特性未受影响。
在 `PublicAPI.Unshipped.txt` 文件中,删除了 `Medallion.Threading.MongoDB.MongoDistributedLock+#nullable enable` 行。这意味着不再启用该文件中的可空引用类型功能,可能会影响到代码的可空性检查和相关的编译器警告。
…nchronizationStrategyTest
在 `MongoDistributedLock.IDistributedLock.cs` 文件中,`MongoDistributedLock` 类实现了 `IDistributedLock` 接口的 `TryAcquire` 方法,新增了自动生成的方法以支持分布式锁的获取。此外,更新了文档注释,修正了异步获取锁的代码示例格式。
|
Let me know when you're ready for me to take a look @joesdu ! |
Yes, it is ready now. |
Added the DistributedLock.MongoDB project, providing a MongoDB-based distributed lock implementation that supports both synchronous and asynchronous lock operations. Added core classes
MongoDistributedLock,MongoDistributedLockHandle,MongoDistributedSynchronizationOptionsBuilder, andMongoDistributedSynchronizationProviderto implement lock acquisition, release, automatic renewal, and configuration functions.Updated project configuration, added dependency on
MongoDB.Driver, and supported multiple target frameworks (.NET 8, .NET Standard 2.1, .NET Framework 4.7.2). Added usage instructions and code examples inREADME.md.Added comprehensive test coverage, including basic functionality, competition scenarios, lock loss handling, and support for custom collection names, ensuring the reliability of the functionality. Updated dependency versions and optimized internal access configuration for the test project.