From 31bc59f04b115c50500621cd6f5bdfcab08a403a Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang Date: Thu, 7 Sep 2023 09:51:04 +0000 Subject: [PATCH] changed the places of lock operations Signed-off-by: Xiaoxuan Wang --- internal/graph/memoryWithDelete.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/graph/memoryWithDelete.go b/internal/graph/memoryWithDelete.go index 84b69428..02c190cd 100644 --- a/internal/graph/memoryWithDelete.go +++ b/internal/graph/memoryWithDelete.go @@ -53,6 +53,8 @@ func (m *MemoryWithDelete) Index(ctx context.Context, fetcher content.Fetcher, n return err } + m.lock.Lock() + defer m.lock.Unlock() m.index(ctx, node, successors) return nil } @@ -96,6 +98,8 @@ func (m *MemoryWithDelete) IndexAll(ctx context.Context, fetcher content.Fetcher } return nil } + m.lock.Lock() + defer m.lock.Unlock() return syncutil.Go(ctx, nil, fn, node) } @@ -120,9 +124,9 @@ func (m *MemoryWithDelete) Predecessors(_ context.Context, node ocispec.Descript // Remove removes the node from its predecessors and successors. func (m *MemoryWithDelete) Remove(ctx context.Context, node ocispec.Descriptor) error { + nodeKey := descriptor.FromOCI(node) m.lock.Lock() defer m.lock.Unlock() - nodeKey := descriptor.FromOCI(node) // remove the node from its successors' predecessor list for successorKey := range m.successors[nodeKey] { delete(m.predecessors[successorKey], nodeKey) @@ -135,8 +139,6 @@ func (m *MemoryWithDelete) Remove(ctx context.Context, node ocispec.Descriptor) // There is no data consistency issue as long as deletion is not implemented // for the underlying storage. func (m *MemoryWithDelete) index(ctx context.Context, node ocispec.Descriptor, successors []ocispec.Descriptor) { - m.lock.Lock() - defer m.lock.Unlock() m.createEntriesInMaps(ctx, node) if len(successors) == 0 { return