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 <[email protected]>
  • Loading branch information
wangxiaoxuan273 committed Sep 7, 2023
1 parent e7f7d34 commit e69b610
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions internal/graph/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (m *Memory) index(ctx context.Context, node ocispec.Descriptor, successors
if len(successors) == 0 {
return
}

predecessorKey := descriptor.FromOCI(node)
for _, successor := range successors {
successorKey := descriptor.FromOCI(successor)
Expand Down
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 e69b610

Please sign in to comment.