feat: Enable MongoDB collection sharding #760
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Following aneoconsulting/ArmoniK.Infra#168, this PR aims to enable the deployment of a sharded MongoDB as ArmoniK's database.
A more complete motivation is provided in AEP 004 (aneoconsulting/ArmoniK.Community#48). This PR is meant to treat a previsible bottleneck on ArmoniK's database by enabling a sharded architecture to it.
For now, when a sharded database is specified, the following collections will be sharded :
Description
This PR adds :
ShardCollectionAsync
to theIMongoDataModelMapping
interface.MongoOptions
: a stringAuthSource
and a booleanSharding
.ShardingExt
containing an extension methodshardCollection
for theIClientSessionHandle
interface.When the
MongoOption
Sharding
is true, theMongoCollectionProvider
callsShardCollectionAsync
. Then the implementation depends on whether the collection is wanted to be sharded :shardCollection
extension method will be called.Task
.The new
MongoOption
AuthSource
is required because theMongoClient
has to authenticate as an administrator to be able to shard a collection.Testing
It has been tested manually. Since these developments are very coupled with ArmoniK's database, it is difficult to write unit tests. Anyhow, it is still possible to have automatized integration tests that would verify in a first time if a deployment of ArmoniK using these developments succeeds, and in a second time if sharding is indeed enabled on the right collections. Workflows testing a deployment of ArmoniK with a sharded MongoDB are currently being studied.
Impact
In the end, it is expected to enhance ArmoniK's strong scalability.
Additional Information
To better understand how MongoDB sharding works see MongoDB's documentation.
To understand why this new MongoOption is required, see : MongoDB's documentation on the shardCollection database command and on connection string's authSource option
Checklist