File tree Expand file tree Collapse file tree
pkg/storage/object/existenceprecondition Expand file tree Collapse file tree Original file line number Diff line number Diff 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" ,
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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" ,
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff line change 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+ )
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments