Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add replication for missing blobs in readFallbackBlobAccess #174

Merged
merged 3 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/blobstore/readfallback/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ go_library(
"//pkg/util",
"@org_golang_google_grpc//codes",
"@org_golang_google_grpc//status",
"@org_golang_x_sync//errgroup",
],
)

Expand Down
19 changes: 19 additions & 0 deletions pkg/blobstore/readfallback/read_fallback_blob_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/buildbarn/bb-storage/pkg/digest"
"github.com/buildbarn/bb-storage/pkg/util"

"golang.org/x/sync/errgroup"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -90,5 +91,23 @@ func (ba *readFallbackBlobAccess) FindMissing(ctx context.Context, digests diges
if err != nil {
return digest.EmptySet, util.StatusWrap(err, "Secondary")
}

// Replicate the blobs that are present only in the secondary backend to primary
annapst marked this conversation as resolved.
Show resolved Hide resolved
if ba.replicator != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if-statement can be removed. The Buildbarn codebase tries to follow the null object pattern where possible. So if you specify a 'noop' blob replicator, it's actually an instance of this type:

https://github.com/buildbarn/bb-storage/blob/master/pkg/blobstore/replication/noop_blob_replicator.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added this check because of the description of a previous pull request touching this file, mentioning backwards compatibility (47ea975) and because there is a nil check in other places in this file.
Is this still safe to remove with this info?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still safe to remove it. What's in the commit message likely applied to the initial version of the PR. See this comment in the PR, where I requested the same thing:

#79 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for clarifying! Let me update!

presentOnlyInSecondary, _, _ := digest.GetDifferenceAndIntersection(missingInPrimary, missingInBoth)
replicateGroup, replicateCtx := errgroup.WithContext(ctx)
annapst marked this conversation as resolved.
Show resolved Hide resolved
replicateGroup.Go(func() error {
if err := ba.replicator.ReplicateMultiple(replicateCtx, presentOnlyInSecondary); err != nil {
if status.Code(err) == codes.NotFound {
return util.StatusWrapWithCode(err, codes.Internal, "Backend secondary returned inconsistent results while synchronizing")
}
return util.StatusWrap(err, "Failed to synchronize from backend secondary to backend primary")
}
return nil
})
if err := replicateGroup.Wait(); err != nil {
return digest.EmptySet, err
}
}
return missingInBoth, nil
}
30 changes: 29 additions & 1 deletion pkg/blobstore/readfallback/read_fallback_blob_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ func TestReadFallbackBlobAccessFindMissing(t *testing.T) {

primary := mock.NewMockBlobAccess(ctrl)
secondary := mock.NewMockBlobAccess(ctrl)
blobAccess := readfallback.NewReadFallbackBlobAccess(primary, secondary, nil)
replicator := mock.NewMockBlobReplicator(ctrl)
blobAccess := readfallback.NewReadFallbackBlobAccess(primary, secondary, replicator)

allDigests := digest.NewSetBuilder().
Add(digest.MustNewDigest("instance", remoteexecution.DigestFunction_MD5, "00000000000000000000000000000000", 100)).
Expand All @@ -171,6 +172,7 @@ func TestReadFallbackBlobAccessFindMissing(t *testing.T) {
Add(digest.MustNewDigest("instance", remoteexecution.DigestFunction_MD5, "00000000000000000000000000000001", 101)).
Build()
missingFromBoth := digest.MustNewDigest("instance", remoteexecution.DigestFunction_MD5, "00000000000000000000000000000000", 100).ToSingletonSet()
presentOnlyInSecondary := digest.MustNewDigest("instance", remoteexecution.DigestFunction_MD5, "00000000000000000000000000000001", 101).ToSingletonSet()

t.Run("Success", func(t *testing.T) {
// Both backends should be queried. Only the missing
Expand All @@ -181,6 +183,8 @@ func TestReadFallbackBlobAccessFindMissing(t *testing.T) {
Return(missingFromPrimary, nil)
secondary.EXPECT().FindMissing(ctx, missingFromPrimary).
Return(missingFromBoth, nil)
replicator.EXPECT().ReplicateMultiple(gomock.Any(), presentOnlyInSecondary).
Return(nil)
annapst marked this conversation as resolved.
Show resolved Hide resolved

missing, err := blobAccess.FindMissing(ctx, allDigests)
require.NoError(t, err)
Expand All @@ -204,4 +208,28 @@ func TestReadFallbackBlobAccessFindMissing(t *testing.T) {
_, err := blobAccess.FindMissing(ctx, allDigests)
testutil.RequireEqualStatus(t, status.Error(codes.Internal, "Secondary: I/O error"), err)
})

t.Run("ReplicateError", func(t *testing.T) {
primary.EXPECT().FindMissing(ctx, allDigests).
Return(missingFromPrimary, nil)
secondary.EXPECT().FindMissing(ctx, missingFromPrimary).
Return(missingFromBoth, nil)
replicator.EXPECT().ReplicateMultiple(gomock.Any(), presentOnlyInSecondary).
Return(status.Error(codes.Internal, "Server on fire"))

_, err := blobAccess.FindMissing(ctx, allDigests)
testutil.RequireEqualStatus(t, status.Error(codes.Internal, "Failed to synchronize from backend secondary to backend primary: Server on fire"), err)
})

t.Run("InconsistentBackendSecondary", func(t *testing.T) {
primary.EXPECT().FindMissing(ctx, allDigests).
Return(missingFromPrimary, nil)
secondary.EXPECT().FindMissing(ctx, missingFromPrimary).
Return(missingFromBoth, nil)
replicator.EXPECT().ReplicateMultiple(gomock.Any(), presentOnlyInSecondary).
Return(status.Error(codes.NotFound, "Object 00000000000000000000000000000001 not found"))

_, err := blobAccess.FindMissing(ctx, allDigests)
testutil.RequireEqualStatus(t, status.Error(codes.Internal, "Backend secondary returned inconsistent results while synchronizing: Object 00000000000000000000000000000001 not found"), err)
})
}