1
1
// Copyright (c) Tailscale Inc & AUTHORS
2
2
// SPDX-License-Identifier: BSD-3-Clause
3
3
4
- // Package s3cache implements callbacks for a gocache.Server that store data
4
+ // Package gobuild implements callbacks for a gocache.Server that store data
5
5
// into an S3 bucket through a local directory.
6
- package s3cache
6
+ package gobuild
7
7
8
8
import (
9
9
"bytes"
@@ -26,7 +26,7 @@ import (
26
26
"github.com/tailscale/go-cache-plugin/lib/s3util"
27
27
)
28
28
29
- // Cache implements callbacks for a gocache.Server using an S3 bucket for
29
+ // S3Cache implements callbacks for a gocache.Server using an S3 bucket for
30
30
// backing store with a local directory for staging.
31
31
//
32
32
// # Remote Cache Layout
@@ -49,7 +49,7 @@ import (
49
49
//
50
50
// where the object ID is hex encoded and the timestamp is Unix nanoseconds.
51
51
// The object file contains just the binary data of the object.
52
- type Cache struct {
52
+ type S3Cache struct {
53
53
// Local is the local cache directory where actions and objects are staged.
54
54
// It must be non-nil. A local stage is required because the Go toolchain
55
55
// needs direct access to read the files reported by the cache.
@@ -88,14 +88,14 @@ type Cache struct {
88
88
putS3Error expvar.Int // count of errors writing to S3
89
89
}
90
90
91
- func (s * Cache ) init () {
91
+ func (s * S3Cache ) init () {
92
92
s .initOnce .Do (func () {
93
93
s .push , s .start = taskgroup .New (nil ).Limit (s .uploadConcurrency ())
94
94
})
95
95
}
96
96
97
97
// Get implements the corresponding callback of the cache protocol.
98
- func (s * Cache ) Get (ctx context.Context , actionID string ) (objectID , diskPath string , _ error ) {
98
+ func (s * S3Cache ) Get (ctx context.Context , actionID string ) (objectID , diskPath string , _ error ) {
99
99
s .init ()
100
100
101
101
objID , diskPath , err := s .Local .Get (ctx , actionID )
@@ -142,7 +142,7 @@ func (s *Cache) Get(ctx context.Context, actionID string) (objectID, diskPath st
142
142
}
143
143
144
144
// Put implements the corresponding callback of the cache protocol.
145
- func (s * Cache ) Put (ctx context.Context , obj gocache.Object ) (diskPath string , _ error ) {
145
+ func (s * S3Cache ) Put (ctx context.Context , obj gocache.Object ) (diskPath string , _ error ) {
146
146
s .init ()
147
147
148
148
// Compute an etag so we can do a conditional put on the object data.
@@ -187,7 +187,7 @@ func (s *Cache) Put(ctx context.Context, obj gocache.Object) (diskPath string, _
187
187
}
188
188
189
189
// Close implements the corresponding callback of the cache protocol.
190
- func (s * Cache ) Close (ctx context.Context ) error {
190
+ func (s * S3Cache ) Close (ctx context.Context ) error {
191
191
if s .push != nil {
192
192
gocache .Logf (ctx , "waiting for uploads..." )
193
193
wstart := time .Now ()
@@ -198,7 +198,7 @@ func (s *Cache) Close(ctx context.Context) error {
198
198
}
199
199
200
200
// SetMetrics implements the corresponding server callback.
201
- func (s * Cache ) SetMetrics (_ context.Context , m * expvar.Map ) {
201
+ func (s * S3Cache ) SetMetrics (_ context.Context , m * expvar.Map ) {
202
202
m .Set ("get_local_hit" , & s .getLocalHit )
203
203
m .Set ("get_fault_hit" , & s .getFaultHit )
204
204
m .Set ("get_fault_miss" , & s .getFaultMiss )
@@ -212,7 +212,7 @@ func (s *Cache) SetMetrics(_ context.Context, m *expvar.Map) {
212
212
// maybePutObject writes the specified object contents to S3 if there is not
213
213
// already a matching key with the same etag. It returns the modified time of
214
214
// the object file, whether or not it was sent to S3.
215
- func (s * Cache ) maybePutObject (ctx context.Context , objectID , diskPath , etag string ) (time.Time , error ) {
215
+ func (s * S3Cache ) maybePutObject (ctx context.Context , objectID , diskPath , etag string ) (time.Time , error ) {
216
216
f , err := os .Open (diskPath )
217
217
if err != nil {
218
218
gocache .Logf (ctx , "[s3] open local object %s: %v" , objectID , err )
@@ -240,14 +240,14 @@ func (s *Cache) maybePutObject(ctx context.Context, objectID, diskPath, etag str
240
240
241
241
// makeKey assembles a complete key from the specified parts, including the key
242
242
// prefix if one is defined.
243
- func (s * Cache ) makeKey (parts ... string ) string {
243
+ func (s * S3Cache ) makeKey (parts ... string ) string {
244
244
return path .Join (s .KeyPrefix , path .Join (parts ... ))
245
245
}
246
246
247
- func (s * Cache ) actionKey (id string ) string { return s .makeKey ("action" , id [:2 ], id ) }
248
- func (s * Cache ) objectKey (id string ) string { return s .makeKey ("object" , id [:2 ], id ) }
247
+ func (s * S3Cache ) actionKey (id string ) string { return s .makeKey ("action" , id [:2 ], id ) }
248
+ func (s * S3Cache ) objectKey (id string ) string { return s .makeKey ("object" , id [:2 ], id ) }
249
249
250
- func (s * Cache ) uploadConcurrency () int {
250
+ func (s * S3Cache ) uploadConcurrency () int {
251
251
if s .UploadConcurrency <= 0 {
252
252
return runtime .NumCPU ()
253
253
}
0 commit comments