Details
Description
The balancer is going to write every active migrations to the config.migrations collection so that this collection can be used for migration recovery on balancer startup after a stepdown/crash.
config.migrations should have fields to identify the specific chunk as well as a version and toShard field
{
|
name
|
ns
|
min
|
max
|
toShard
|
chunkVersion
|
collectionVersion
|
}
|
This collection should have an index on (ns, min, max) so that duplicate migrations cannot be scheduled – this would fail anyway.
The version field is necessary so that on recovery that balancer will not try to schedule a migration that managed to both succeed and be moved back to the original source shard. This can only happen if a v3.2 mongos is running and scheduling moveChunk commands directly to the shards rather than through the balancer – in v3.4, all moveChunks go through the balancer, i.e. a v3.4 mongos routes moveChunk commands to the balancer.
------------------------------------------------
Create a ScopedMigrationRequest RAII object class that will write to config.migrations on creation and destruction, to add and remove an entry, respectively.
Create a static method that:
instantiates the scoped object after a local insert is successful.
waits for majority write concern, and returns an error on failure
The destructor does a local delete – don't need to worry about majority because if majority fails and we stepdown/crash, recovery will just safely check the migration.