What happens when a snapshot is being merged? [Hyper-V]

I would like to now take a little side road to look at what happens under the covers when you delete a snapshot and we need to merge the AVHD.  Imagine that you have a virtual machine with the following snapshots:

snapshot7

If you were to delete Snapshot 2, the AVHD would need to be merged. 

The problem is that we need to make sure that Snapshots 1 and 3 are still pointing to AVHDs which have the same properties and data as they did before Snapshot 2 was deleted. 

We will not want to merge Snapshot 2s AVHD into Snapshot 1s disks – as that would invalidated Snapshot 1.

What actually happens is that the AVHD that is used for Snapshot 3 is merged into the AVHD for Snapshot 2.  After this the original Snapshot 3 AVHD is deleted and Snapshot 3 is updated to point to the new merged AVHD – which now has all the data needed for Snapshot 3. 

After this the rest of the snapshot chain is “fixed up” to deal with this change in Snapshot 3’s AVHD.

When this is all complete you now only have one set of AVHDs for each snapshot, and each snapshot is still functional.

Cheers,
Ben