Skip to content

Commit 1a491fa

Browse files
committed
internal/sourcecache: increase x/website size limit to 200 MB
The x/website repository is unusually large due to having content from x/blog, and as of CL 365135 also from x/talks. Increase its limit to 200 MB, but leave other repositories as they were. Updates golang/go#46379. Change-Id: Ib18766cb5903e602899c1777f1fba7d7cb2a5767 Reviewed-on: https://go-review.googlesource.com/c/build/+/366135 Trust: Dmitri Shuralyov <[email protected]> Run-TryBot: Dmitri Shuralyov <[email protected]> Reviewed-by: Russ Cox <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent b52e3d6 commit 1a491fa

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

cmd/coordinator/buildstatus.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ func (st *buildStatus) runSubrepoTests() (remoteErr, err error) {
10261026
// can find go.mod files and run tests in it.
10271027
{
10281028
tgz, err := sourcecache.GetSourceTgz(st, st.SubName, st.SubRev)
1029-
if errors.Is(err, sourcecache.ErrTooBig) {
1029+
if errors.As(err, new(sourcecache.TooBigError)) {
10301030
// Source being too big is a non-retryable error.
10311031
return err, nil
10321032
} else if err != nil {
@@ -1214,7 +1214,7 @@ func (st *buildStatus) runBenchmarkTests() (remoteErr, err error) {
12141214
// can run scripts from the repo.
12151215
{
12161216
tgz, err := sourcecache.GetSourceTgz(st, st.SubName, st.SubRev)
1217-
if errors.Is(err, sourcecache.ErrTooBig) {
1217+
if errors.As(err, new(sourcecache.TooBigError)) {
12181218
// Source being too big is a non-retryable error.
12191219
return err, nil
12201220
} else if err != nil {

internal/sourcecache/source.go

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ type source struct {
4040
// repo is go.googlesource.com repo ("go", "net", and so on).
4141
// rev is git revision.
4242
//
43-
// ErrTooBig is returned if the response size exceeds a size that on 2021-05-25
44-
// was deemed to be enough to meet expected legitimate future needs for a while.
43+
// An error of type TooBigError is returned if the compressed tarball exceeds a size that
44+
// on 2021-11-22 was deemed to be enough to meet expected legitimate future needs for a while.
45+
// See golang.org/issue/46379.
4546
func GetSourceTgz(sl spanlog.Logger, repo, rev string) (tgz io.Reader, err error) {
4647
sp := sl.CreateSpan("get_source", repo+"@"+rev)
4748
defer func() { sp.Done(err) }()
@@ -77,13 +78,22 @@ func GetSourceTgz(sl spanlog.Logger, repo, rev string) (tgz io.Reader, err error
7778
return nil, err
7879
}
7980
if v.(source).TooBig {
80-
return nil, ErrTooBig
81+
return nil, TooBigError{Repo: repo, Rev: rev, Limit: maxSize(repo)}
8182
}
8283
return bytes.NewReader(v.(source).Tgz), nil
8384
}
8485

85-
// ErrTooBig is the error returned when the source is considered too big.
86-
var ErrTooBig = fmt.Errorf("rejected because compressed tarball exceeded a limit of %d MB; see golang.org/issue/46379", maxSize/1024/1024)
86+
// TooBigError is the error returned when the source revision is considered too big.
87+
type TooBigError struct {
88+
Repo string
89+
Rev string
90+
Limit int64 // Max size in bytes.
91+
}
92+
93+
func (e TooBigError) Error() string {
94+
return fmt.Sprintf("rejected because compressed tarball of repository go.googlesource.com/%s at revision %s exceeded a limit of %d MB; see golang.org/issue/46379",
95+
e.Repo, e.Rev, e.Limit/1024/1024)
96+
}
8797

8898
var gitMirrorClient *http.Client
8999

@@ -139,8 +149,8 @@ func getSourceTgzFromURL(hc *http.Client, service, repo, rev, url string) (sourc
139149
return source{}, fmt.Errorf("fetching %s/%s from %s: %v; body: %s", repo, rev, service, res.Status, slurp)
140150
}
141151
// See golang.org/issue/11224 for a discussion on tree filtering.
142-
b, err := ioutil.ReadAll(io.LimitReader(res.Body, maxSize+1))
143-
if len(b) > maxSize && err == nil {
152+
b, err := ioutil.ReadAll(io.LimitReader(res.Body, maxSize(repo)+1))
153+
if int64(len(b)) > maxSize(repo) && err == nil {
144154
return source{TooBig: true}, nil
145155
}
146156
if err != nil {
@@ -149,9 +159,24 @@ func getSourceTgzFromURL(hc *http.Client, service, repo, rev, url string) (sourc
149159
return source{Tgz: b}, nil
150160
}
151161

152-
// maxSize is an artificial limit on how big of a source tarball this package is
153-
// is willing to accept. It's expected humans may need to manage it every couple
154-
// of years for the evolving needs of the Go project, and ideally not more often.
162+
// maxSize controls artificial limits on how big of a compressed source tarball
163+
// this package is willing to accept. It's expected humans may need to manage
164+
// these limits every couple of years for the evolving needs of the Go project,
165+
// and ideally not much more often.
155166
//
156-
// As of 2021-05-25, a compressed tarball of x/website is 55 MB; Go source is 22 MB.
157-
const maxSize = 100 << 20
167+
// repo is a go.googlesource.com repo ("go", "net", and so on).
168+
func maxSize(repo string) int64 {
169+
switch repo {
170+
default:
171+
// As of 2021-11-22, a compressed tarball of Go source is 23 MB,
172+
// x/net is 1.2 MB,
173+
// x/build is 1.1 MB,
174+
// x/tools is 2.9 MB.
175+
return 100 << 20
176+
case "website":
177+
// In 2021, all content in x/blog (52 MB) and x/talks (74 MB) moved
178+
// to x/website. This makes x/website an outlier, with a compressed
179+
// tarball size of 135 MB. Give it some room to grow from there.
180+
return 200 << 20
181+
}
182+
}

0 commit comments

Comments
 (0)