Skip to content

Commit e69b610

Browse files
changed the places of lock operations
Signed-off-by: Xiaoxuan Wang <[email protected]>
1 parent e7f7d34 commit e69b610

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

internal/graph/memory.go

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ func (m *Memory) index(ctx context.Context, node ocispec.Descriptor, successors
123123
if len(successors) == 0 {
124124
return
125125
}
126+
126127
predecessorKey := descriptor.FromOCI(node)
127128
for _, successor := range successors {
128129
successorKey := descriptor.FromOCI(successor)

internal/graph/memoryWithDelete.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ func (m *MemoryWithDelete) Index(ctx context.Context, fetcher content.Fetcher, n
5353
return err
5454
}
5555

56+
m.lock.Lock()
57+
defer m.lock.Unlock()
5658
m.index(ctx, node, successors)
5759
return nil
5860
}
@@ -96,6 +98,8 @@ func (m *MemoryWithDelete) IndexAll(ctx context.Context, fetcher content.Fetcher
9698
}
9799
return nil
98100
}
101+
m.lock.Lock()
102+
defer m.lock.Unlock()
99103
return syncutil.Go(ctx, nil, fn, node)
100104
}
101105

@@ -120,9 +124,9 @@ func (m *MemoryWithDelete) Predecessors(_ context.Context, node ocispec.Descript
120124

121125
// Remove removes the node from its predecessors and successors.
122126
func (m *MemoryWithDelete) Remove(ctx context.Context, node ocispec.Descriptor) error {
127+
nodeKey := descriptor.FromOCI(node)
123128
m.lock.Lock()
124129
defer m.lock.Unlock()
125-
nodeKey := descriptor.FromOCI(node)
126130
// remove the node from its successors' predecessor list
127131
for successorKey := range m.successors[nodeKey] {
128132
delete(m.predecessors[successorKey], nodeKey)
@@ -135,8 +139,6 @@ func (m *MemoryWithDelete) Remove(ctx context.Context, node ocispec.Descriptor)
135139
// There is no data consistency issue as long as deletion is not implemented
136140
// for the underlying storage.
137141
func (m *MemoryWithDelete) index(ctx context.Context, node ocispec.Descriptor, successors []ocispec.Descriptor) {
138-
m.lock.Lock()
139-
defer m.lock.Unlock()
140142
m.createEntriesInMaps(ctx, node)
141143
if len(successors) == 0 {
142144
return

0 commit comments

Comments
 (0)