Failed Manifest Pushes Due to Layer Linking Errors May Succeed On Retry and Leave Layers Unlinked

Context

During manifest pushes for the new code path, the manifest is first created, then the layers are linked to the manifest. It's possible, to have an error while linking the layers, which leaves behind a manifest whose layers are at least partially unlinked.

Pulls will error out since the layers will not be found, while subsequent pushes will apparently succeed, but only due to the fact that if the manifest is found on the database, it is assumed to be in a healthy state.

Solution

Transaction

We should investigate using a transaction here. While this is a typical usecase for transactions, we have had issues with race conditions when two of the same manifest are pushed with different tags. We should ensure the transaction doesn't create a new issue during this case.