Skip to content
Merged
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: go run github.com/rhysd/actionlint/cmd/actionlint@v1.7.12
- name: Rebuild packaged binaries
env:
VERSION: v0.3.1
VERSION: v0.3.2
run: scripts/build-dist.sh
- name: Verify packaged binaries are reproducible
run: git diff --exit-code -- dist
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ go vet ./...
go run honnef.co/go/tools/cmd/staticcheck@v0.7.0 ./...
go run golang.org/x/vuln/cmd/govulncheck@v1.6.0 ./...
node --test action/*.test.js
VERSION=v0.3.1 scripts/build-dist.sh
VERSION=v0.3.2 scripts/build-dist.sh
git diff --exit-code -- dist
(cd dist && sha256sum --check SHA256SUMS)
```
Expand Down
4 changes: 2 additions & 2 deletions dist/SHA256SUMS
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
9b7e9b76bfa605420a0c5498ff6b40864ecaffef3d2ef16203502a1786cf7e93 cache-server-linux-amd64
08d858dfb6c528c79667c06d14d35575b9f32d05720656f4c13b6f1f39de4f91 cache-server-linux-arm64
f78d1caf02f9211eaf6e680e9dd5692b1a03355365505f617a5ad3fd254af0f0 cache-server-linux-amd64
f6881c1ecefc1aa070bfe62ee567c45508e187da5af09fb1529bb00709a7ba30 cache-server-linux-arm64
Binary file modified dist/cache-server-linux-amd64
Binary file not shown.
Binary file modified dist/cache-server-linux-arm64
Binary file not shown.
16 changes: 13 additions & 3 deletions internal/server/pack_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/cre4ture/bazel-github-actions-cache-v2/internal/cache"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
carv2 "github.com/ipld/go-car/v2"
"github.com/ipld/go-car/v2/blockstore"
)

Expand Down Expand Up @@ -221,7 +222,7 @@ func (p *packStore) resolve(ctx context.Context, key, kind, digest string) (obje
if err != nil {
return object{}, false, err
}
data, err := readCARBlock(ctx, path, contentCID)
data, err := readCARBlock(ctx, path, contentCID, p.server.cfg.MaxBlobSize)
if err != nil {
return object{}, false, err
}
Expand Down Expand Up @@ -725,8 +726,17 @@ func parseManifestKey(prefix, key string) (string, bool) {
return id, validCID(id)
}

func readCARBlock(ctx context.Context, path, contentCID string) ([]byte, error) {
store, err := blockstore.OpenReadOnly(path, blockstore.UseWholeCIDs(true))
const rawCIDSectionOverheadBytes = 64

func readCARBlock(ctx context.Context, path, contentCID string, maxBlobSize int64) ([]byte, error) {
// CAR sections include the block CID as well as the payload. Packs use
// CIDv1/raw/SHA-256 CIDs, so a small fixed allowance above the configured
// payload limit safely admits every block this cache is allowed to store.
store, err := blockstore.OpenReadOnly(
path,
blockstore.UseWholeCIDs(true),
carv2.MaxAllowedSectionSize(uint64(maxBlobSize+rawCIDSectionOverheadBytes)),
)
if err != nil {
return nil, fmt.Errorf("open CARv2 pack: %w", err)
}
Expand Down
29 changes: 29 additions & 0 deletions internal/server/pack_store_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package server

import (
"bytes"
"context"
"net/http"
"sort"
Expand Down Expand Up @@ -34,10 +35,15 @@ func (c memoryCatalog) List(_ context.Context, prefix string, limit int) ([]stri
var _ cache.Catalog = memoryCatalog{}

func testPackedServer(t *testing.T, backend *memoryBackend) *Server {
return testPackedServerWithMaxBlob(t, backend, 1024)
}

func testPackedServerWithMaxBlob(t *testing.T, backend *memoryBackend, maxBlobSize int64) *Server {
t.Helper()
return testServer(t, backend, func(cfg *Config) {
cfg.StorageMode = "packs"
cfg.Catalog = memoryCatalog{backend: backend}
cfg.MaxBlobSize = maxBlobSize
cfg.PackSize = 1024
cfg.PackFlushInterval = time.Hour
cfg.MaxManifests = 100
Expand Down Expand Up @@ -86,6 +92,29 @@ func TestPackedStoreRoundTripCommitsPackBeforeManifest(t *testing.T) {
}
}

func TestPackedStoreRestoresCASLargerThanCARDefaultSectionLimit(t *testing.T) {
const payloadSize = (8 << 20) + 1
const maxBlobSize = payloadSize + 1024
backend := newMemoryBackend()
seed := testPackedServerWithMaxBlob(t, backend, maxBlobSize)
payload := bytes.Repeat([]byte{0xa5}, payloadSize)
digest := digest(payload)
if response := putCacheObject(seed, "/cas/"+digest, payload); response.Code != http.StatusNoContent {
t.Fatalf("CAS PUT = %d, body = %s", response.Code, response.Body.String())
}
closePackedServer(t, seed)

restore := testPackedServerWithMaxBlob(t, backend, maxBlobSize)
defer closePackedServer(t, restore)
response := readCacheObject(restore, "/cas/"+digest)
if response.Code != http.StatusOK {
t.Fatalf("CAS GET = %d, body = %s", response.Code, response.Body.String())
}
if !bytes.Equal(response.Body.Bytes(), payload) {
t.Fatal("restored CAS payload differs from the published payload")
}
}

func TestPackedStoreMergesConcurrentManifestHeads(t *testing.T) {
backend := newMemoryBackend()
writerA := testPackedServer(t, backend)
Expand Down
Loading