Avoid race condition on writing cache contents to files
Avoid race condition on writing cache contents to files

Recently, we are seeing warning logs from cache about failure of committing
cache contents to files. This is because multiple goroutines simultaneously try
to commit the same cache contents to the same file.

This commit solves this by adding a per-key named lock which also helps avoid
duplication of works by ensuring only one goroutine runs per key.

Signed-off-by: Kohei Tokunaga <72a466a7d91579e23b8af87d6766ee221241ce87@gmail.com>

containerd/stargz-snapshotter,containerd/stargz-snapshotter,containerd/stargz-snapshotter,containerd/stargz-snapshotter