Skip to content

Commit

Permalink
fix: stop and cleanup on dup collection
Browse files Browse the repository at this point in the history
  • Loading branch information
notanatol committed Jan 27, 2024
1 parent 9218d6d commit 13ab69e
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions pkg/storer/internal/pinning/pinning.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,6 @@ func (c *collectionPutter) Put(ctx context.Context, st internal.Storage, writer
return nil
}

rootCollection := &pinCollectionItem{Addr: ch.Address()}
has, err := st.IndexStore().Has(rootCollection)
if err != nil {
return fmt.Errorf("pin store: check previous root: %w", err)
}
if has {
// duplicate PUT of the same root address
return nil
}

err = writer.Put(collectionChunk)
if err != nil {
return fmt.Errorf("pin store: failed putting collection chunk: %w", err)
Expand All @@ -276,17 +266,20 @@ func (c *collectionPutter) Close(st internal.Storage, writer storage.Writer, roo

collection := &pinCollectionItem{Addr: root}
has, err := st.IndexStore().Has(collection)

if err != nil {
return fmt.Errorf("pin store: check previous root: %w", err)
}

if !has {
// Save the root pin reference.
c.collection.Addr = root
err := writer.Put(c.collection)
if err != nil {
return fmt.Errorf("pin store: failed updating collection: %w", err)
}
if has {
return fmt.Errorf("pin store: duplicate collection: %w", err) // will trigger the Cleanup
}

// Save the root pin reference.
c.collection.Addr = root
err = writer.Put(c.collection)
if err != nil {
return fmt.Errorf("pin store: failed updating collection: %w", err)
}

err = writer.Delete(&dirtyCollection{UUID: c.collection.UUID})
Expand Down

0 comments on commit 13ab69e

Please sign in to comment.