Skip to content

Commit e2b1a2f

Browse files
committed
Let workers translate DownloadObject() NOT_FOUND to FAILED_PRECONDITION
This is something that Buildbarn already does for REv2, but it looks like we're going to need this as well. For our fetching worker we don't want to return NOT_FOUND in case any object referenced by its action does not exist. We want to limit that return code to just 404s.
1 parent a89c8a6 commit e2b1a2f

6 files changed

Lines changed: 61 additions & 4 deletions

File tree

cmd/bonanza_builder/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ go_library(
3030
"//pkg/remoteworker",
3131
"//pkg/storage/dag",
3232
"//pkg/storage/object",
33+
"//pkg/storage/object/existenceprecondition",
3334
"//pkg/storage/object/grpc",
3435
"//pkg/storage/object/namespacemapping",
3536
"@com_github_buildbarn_bb_remote_execution//pkg/filesystem/pool",

cmd/bonanza_builder/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"bonanza.build/pkg/remoteworker"
3636
"bonanza.build/pkg/storage/dag"
3737
"bonanza.build/pkg/storage/object"
38+
object_existenceprecondition "bonanza.build/pkg/storage/object/existenceprecondition"
3839
object_grpc "bonanza.build/pkg/storage/object/grpc"
3940
object_namespacemapping "bonanza.build/pkg/storage/object/namespacemapping"
4041

@@ -74,8 +75,10 @@ func main() {
7475
if err != nil {
7576
return util.StatusWrap(err, "Failed to create storage gRPC client")
7677
}
77-
objectDownloader := object_grpc.NewGRPCDownloader(
78-
object_pb.NewDownloaderClient(storageGRPCClient),
78+
objectDownloader := object_existenceprecondition.NewDownloader(
79+
object_grpc.NewGRPCDownloader(
80+
object_pb.NewDownloaderClient(storageGRPCClient),
81+
),
7982
)
8083
parsedObjectPool, err := model_parser.NewParsedObjectPoolFromConfiguration(configuration.ParsedObjectPool)
8184
if err != nil {

cmd/bonanza_worker/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ go_library(
1616
"//pkg/proto/storage/dag",
1717
"//pkg/proto/storage/object",
1818
"//pkg/remoteworker",
19+
"//pkg/storage/object/existenceprecondition",
1920
"//pkg/storage/object/grpc",
2021
"@com_github_buildbarn_bb_remote_execution//pkg/clock",
2122
"@com_github_buildbarn_bb_remote_execution//pkg/filesystem/pool",

cmd/bonanza_worker/main.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
dag_pb "bonanza.build/pkg/proto/storage/dag"
2222
object_pb "bonanza.build/pkg/proto/storage/object"
2323
"bonanza.build/pkg/remoteworker"
24+
object_existenceprecondition "bonanza.build/pkg/storage/object/existenceprecondition"
2425
object_grpc "bonanza.build/pkg/storage/object/grpc"
2526

2627
re_clock "github.com/buildbarn/bb-remote-execution/pkg/clock"
@@ -59,8 +60,10 @@ func main() {
5960
if err != nil {
6061
return util.StatusWrap(err, "Failed to create storage gRPC client")
6162
}
62-
objectDownloader := object_grpc.NewGRPCDownloader(
63-
object_pb.NewDownloaderClient(storageGRPCClient),
63+
objectDownloader := object_existenceprecondition.NewDownloader(
64+
object_grpc.NewGRPCDownloader(
65+
object_pb.NewDownloaderClient(storageGRPCClient),
66+
),
6467
)
6568
parsedObjectPool, err := model_parser.NewParsedObjectPoolFromConfiguration(configuration.ParsedObjectPool)
6669
if err != nil {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
load("@rules_go//go:def.bzl", "go_library")
2+
3+
go_library(
4+
name = "existenceprecondition",
5+
srcs = ["downloader.go"],
6+
importpath = "bonanza.build/pkg/storage/object/existenceprecondition",
7+
visibility = ["//visibility:public"],
8+
deps = [
9+
"//pkg/storage/object",
10+
"@org_golang_google_grpc//codes",
11+
"@org_golang_google_grpc//status",
12+
],
13+
)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package existenceprecondition
2+
3+
import (
4+
"context"
5+
6+
"bonanza.build/pkg/storage/object"
7+
8+
"google.golang.org/grpc/codes"
9+
"google.golang.org/grpc/status"
10+
)
11+
12+
type downloader[TReference any] struct {
13+
base object.Downloader[TReference]
14+
}
15+
16+
// NewDownloader creates a decorator for object.Downloader that causes
17+
// all NOT_FOUND errors returned by DownloadObject() to be translated to
18+
// FAILED_PRECONDITION.
19+
//
20+
// This decorator can be used on workers that expect that all objects
21+
// references by actions that they receive are present in storage. If
22+
// objects cannot be read from storage, it's not desirable to let the
23+
// execution of the action itself fail with NOT_FOUND.
24+
func NewDownloader[TReference any](base object.Downloader[TReference]) object.Downloader[TReference] {
25+
return &downloader[TReference]{
26+
base: base,
27+
}
28+
}
29+
30+
func (d *downloader[TReference]) DownloadObject(ctx context.Context, reference TReference) (*object.Contents, error) {
31+
contents, err := d.base.DownloadObject(ctx, reference)
32+
if s := status.Convert(err); s.Code() == codes.NotFound {
33+
return nil, status.Error(codes.FailedPrecondition, s.Message())
34+
}
35+
return contents, err
36+
}

0 commit comments

Comments
 (0)