Repository navigation
Description
like the issue #2367
when the registry as proxy ,sometimes the client will retry .
what i see in the registry log:

GET this blob return 0 size.
i try to debug:the layer blob data don't at the machine path,but the linkblob still existed.(the linkblob refer to _layers/sha256/xxx).
so i read the code.
normally when the blob of the layer isn't the machine,the registy will to pull the blob from the remote registry first.
but in this case ,the mirror didn't trigger that.
let's see the code:
when a pull request comes to the mirror ,it will go to serverblob:
if the "served" is true ,it will not to pull the blob from the remote registry.

at my log ,i see served is true (i print it) but blob data.

then will check this layer whether in the cache Descriptor map .

at the gc time ,if many images share one layer ,it will not check whether other layer using this layer ,delete layer blob directly and clear this map. but the map is not a global Descriptor map.
at this time ,when another try to get blob data ,it will check the map ,the map show this layer is existed because the linkbob of this image is existed(but in fact the blob data is not existed) ,so it starts read and return 0 size file(because the blobdata is deleted).
when the registry restarts , the Descriptor map disappear and become an empty map.
when a pull request come, how the registry do is to check whether the linkblob is existed to call SetDescriptor map

the question comes, the blob of the layer may be deleted by another image's gc time.
so the cause of this bug is the registy only check the linkblob but doesn't check the blob whether existed . so registy will not trigger to pull layer from remote registry
why the registry this design is

so at this design we can't directly check the blob ... so what should we do to ensure to trigger pulling from remote registry
when the linkblob is existed and blobdata is deleted by another image at gc time?
if some understanding is not fully correct , weclome to point it .


Activity
docwhat commentedon Oct 20, 2020
Awesome detective work!
docwhat commentedon Oct 27, 2020
So... disabling the
cachesettings should be a workaround for this? i.e. removing theSTORAGE_CACHE_BLOBDESCRIPTORoption altogether?zhipengzuo commentedon Oct 27, 2020
at that situation, how could mirror to judge one layer whether between creation and population。if by the link , the problem is also existed.
https://github.com/docker/distribution/blob/2800ab02245e2eafc10e338939511dd1aeb5e135/registry/proxy/proxyblobstore.go#L70
docwhat commentedon Oct 27, 2020
I'm having a hard time figuring out how the storage cache is setup and/or disabled; I apologize if I got this wrong.
My assumption is that without the cache
Stat()queries the storage directly. Storage wouldn't have any time between creation and population: either it exists or doesn't.It is the cache that allows the inconsistency between the descriptor (in cache) and blob (in storage).
zhipengzuo commentedon Oct 27, 2020
ok . maybe have a try and add some debug message .
docwhat commentedon Dec 1, 2020
We've been using it over a month with zero problems, so it looks like the cache should be disabled for local file store.
zhipengzuo commentedon Jan 15, 2021
@docwhat hello can you offer a pr to disable cache as default when as mirror ?
docwhat commentedon Jan 19, 2021
I think that's the default already.
I think the memory caching should be disabled unconditionally when using a local file store.
fix(proxy): ref-count shared blobs and refresh TTL on cache hit
fix(proxy): ref-count shared blobs and refresh TTL on cache hit
fix(proxy): ref-count shared blobs and refresh TTL on cache hit
fix(proxy): ref-count shared blobs and refresh TTL on cache hit