Skip to content

Commit

Permalink
fix: returned uuid when inserting charm with same hash
Browse files Browse the repository at this point in the history
This fixes an issue presented when we tried to deploy the same charm
twice (or the same charm from charmhub and then from local). The error
was that in the case of a conflict in the hash, the same line in the db
was used for the object store metadata, but the returned UUID was still
a new one. Now the UUID corresponding to that line gets returned.
  • Loading branch information
nvinuesa committed Dec 27, 2024
1 parent 0db00f2 commit 34beff0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 6 additions & 0 deletions domain/objectstore/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ AND size = $dbMetadata.size`, dbMetadata, dbMetadataPath)
} else if err != nil {
return errors.Annotatef(err, "inserting metadata")
}
// At this point we need to update the uuid that we'll
// return back to be the one that was already in the db.
uuid, err = coreobjectstore.ParseUUID(dbMetadataPath.UUID)
if err != nil {
return errors.Annotatef(err, "parsing present uuid in metadata")
}
}

err = tx.Query(ctx, pathStmt, dbMetadataPath).Get(&outcome)
Expand Down
12 changes: 8 additions & 4 deletions domain/objectstore/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ func (s *stateSuite) TestPutMetadataWithSameSHA256AndSize(c *gc.C) {
Size: 666,
}

_, err := st.PutMetadata(context.Background(), metadata1)
uuid1, err := st.PutMetadata(context.Background(), metadata1)
c.Assert(err, jc.ErrorIsNil)

_, err = st.PutMetadata(context.Background(), metadata2)
uuid2, err := st.PutMetadata(context.Background(), metadata2)
c.Assert(err, jc.ErrorIsNil)

c.Check(uuid1, gc.Equals, uuid2)
}

func (s *stateSuite) TestPutMetadataWithSameSHA384AndSize(c *gc.C) {
Expand All @@ -214,11 +216,13 @@ func (s *stateSuite) TestPutMetadataWithSameSHA384AndSize(c *gc.C) {
Size: 666,
}

_, err := st.PutMetadata(context.Background(), metadata1)
uuid1, err := st.PutMetadata(context.Background(), metadata1)
c.Assert(err, jc.ErrorIsNil)

_, err = st.PutMetadata(context.Background(), metadata2)
uuid2, err := st.PutMetadata(context.Background(), metadata2)
c.Assert(err, jc.ErrorIsNil)

c.Check(uuid1, gc.Equals, uuid2)
}

func (s *stateSuite) TestPutMetadataWithSameHashDifferentSize(c *gc.C) {
Expand Down

0 comments on commit 34beff0

Please sign in to comment.