Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion enterprise/server/ociregistry/ociregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func fetchFromCacheWriteToResponse(ctx context.Context, w http.ResponseWriter, b
if !writeBody {
return nil
}
return ocicache.FetchBlobFromCache(ctx, w, bsClient, hash, blobMetadata.GetContentLength())
return ocicache.FetchBlobFromCache(ctx, w, bsClient, hash)
}

func isDigest(identifier string) bool {
Expand Down
3 changes: 1 addition & 2 deletions enterprise/server/util/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ func (l *layerFromDigest) MediaType() (types.MediaType, error) {
}

func (l *layerFromDigest) fetchLayerFromCache() (io.ReadCloser, error) {
metadata, err := ocicache.FetchBlobMetadataFromCache(
_, err := ocicache.FetchBlobMetadataFromCache(
l.image.ctx,
l.image.bsClient,
l.image.acClient,
Expand All @@ -954,7 +954,6 @@ func (l *layerFromDigest) fetchLayerFromCache() (io.ReadCloser, error) {
pw,
l.image.bsClient,
l.digest,
metadata.GetContentLength(),
)
if err != nil {
log.Warningf("Error fetching blob from cache: %s", err)
Expand Down
11 changes: 9 additions & 2 deletions enterprise/server/util/ocicache/ocicache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"io"
"math"

"github.com/buildbuddy-io/buildbuddy/server/interfaces"
"github.com/buildbuddy-io/buildbuddy/server/metrics"
Expand Down Expand Up @@ -38,6 +39,12 @@ const (
maxManifestSize = 10000000

cacheDigestFunction = repb.DigestFunction_SHA256

// unknownBlobSize is used as a dummy size value for CAS read operations
// when the actual blob size is not known. The CAS uses hash-only lookups,
// so any positive size value works. math.MaxInt64 provides optimal buffer
// allocation (clamped to 256 KiB) without affecting blob retrieval.
unknownBlobSize = math.MaxInt64
)

func WriteManifestToAC(ctx context.Context, raw []byte, acClient repb.ActionCacheClient, repo gcrname.Repository, hash gcr.Hash, contentType string, originalRef gcrname.Reference) error {
Expand Down Expand Up @@ -229,10 +236,10 @@ func blobHit(ctx context.Context) {
updateCacheEventMetric(metrics.OCIBlobResourceTypeLabel, metrics.HitStatusLabel)
}

func FetchBlobFromCache(ctx context.Context, w io.Writer, bsClient bspb.ByteStreamClient, hash gcr.Hash, contentLength int64) error {
func FetchBlobFromCache(ctx context.Context, w io.Writer, bsClient bspb.ByteStreamClient, hash gcr.Hash) error {
blobCASDigest := &repb.Digest{
Hash: hash.Hex,
SizeBytes: contentLength,
SizeBytes: unknownBlobSize,
}
blobRN := digest.NewCASResourceName(
blobCASDigest,
Expand Down
4 changes: 2 additions & 2 deletions enterprise/server/util/ocicache/ocicache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func blobDoesNotExist(t *testing.T, ctx context.Context, te *testenv.TestEnv, re
require.Nil(t, metadata)

out := &bytes.Buffer{}
err = ocicache.FetchBlobFromCache(ctx, out, bsClient, hash, contentLength)
err = ocicache.FetchBlobFromCache(ctx, out, bsClient, hash)
require.Error(t, err)
}

Expand Down Expand Up @@ -390,7 +390,7 @@ func fetchAndCheckBlob(t *testing.T, te *testenv.TestEnv, layerBuf []byte, repo
require.Equal(t, contentLength, metadata.GetContentLength())

out := &bytes.Buffer{}
err = ocicache.FetchBlobFromCache(ctx, out, bsClient, hash, contentLength)
err = ocicache.FetchBlobFromCache(ctx, out, bsClient, hash)
require.NoError(t, err)
require.Empty(t, cmp.Diff(layerBuf, out.Bytes()))
}
2 changes: 1 addition & 1 deletion enterprise/tools/replay_action/replay_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ func (r *Replayer) copyCachedContainerImage(ctx, srcCtx, targetCtx context.Conte
defer pr.Close()
go func() {
defer pw.Close()
if err := ocicache.FetchBlobFromCache(srcCtx, pw, r.sourceBSClient, hash, contentLength); err != nil {
if err := ocicache.FetchBlobFromCache(srcCtx, pw, r.sourceBSClient, hash); err != nil {
pw.CloseWithError(fmt.Errorf("read image %s blob %s from source cache: %s", label, hash, err))
}
}()
Expand Down
Loading