The recipient shard fetches changes to the documents in the range being migrated by continuously running the _transferMods command against the donor shard. The donor shard has the changes buffer in memory.
The termination condition for when the recipient shard stops attempting to fetch changes from the donor shard is when both of the following conditions are satisfied:
- The recipient shard has run at least one _transferMods command after the _recvChunkCommit was received.
- The _transferMods command returned an empty result set or none of the changes returned by the _transferMods command are in the range being migrated.
However it is possible even when none of the changes returned by the _transferMods commands are in the range being migrated for there to still be a pending batch on the donor shard which would have changes in the range being migrated. In particular, transactions are not filtering out changes which are unrelated to range being migrated and can lead to an entire _transferMods command having changes which are wholly unrelated to the range being migrated (SERVER-78415).