Skip to content

Commit

Permalink
changed the places of lock operations
Browse files Browse the repository at this point in the history
Signed-off-by: Xiaoxuan Wang <wangxiaoxuan119@gmail.com>
  • Loading branch information
wangxiaoxuan273 committed Sep 7, 2023
1 parent e7f7d34 commit 31bc59f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/graph/memoryWithDelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 31bc59f

Please sign in to comment.