Skip to content

Conversation

@joesdu
Copy link

@joesdu joesdu commented Oct 21, 2025

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.

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.
Copilot AI review requested due to automatic review settings October 21, 2025 09:36
Copy link

Copilot AI left a 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` 行。这意味着不再启用该文件中的可空引用类型功能,可能会影响到代码的可空性检查和相关的编译器警告。
@joesdu joesdu changed the title feat: Added support for MongoDB distributed locks feat: Add MongoDB distributed locks Implementation Oct 22, 2025
在 `MongoDistributedLock.IDistributedLock.cs` 文件中,`MongoDistributedLock` 类实现了 `IDistributedLock` 接口的 `TryAcquire` 方法,新增了自动生成的方法以支持分布式锁的获取。此外,更新了文档注释,修正了异步获取锁的代码示例格式。
@madelson
Copy link
Owner

Let me know when you're ready for me to take a look @joesdu !

@joesdu
Copy link
Author

joesdu commented Oct 28, 2025

Let me know when you're ready for me to take a look @joesdu !

Yes, it is ready now.

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