Skip to content

Commit 6bd3146

Browse files
committed
revert "sql: store bundle when TestStreamerTightBudget fails"
This reverts commit 48f11d2. The test hasn't failed in like year and a half and the captured stmt bundle didn't actually give any more insight into why it rarely failed. Release note: None
1 parent 3a397eb commit 6bd3146

File tree

2 files changed

+9
-52
lines changed

2 files changed

+9
-52
lines changed

pkg/sql/explain_bundle_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,21 +1053,18 @@ func findBundleDownloadURL(t *testing.T, runner *sqlutils.SQLRunner, id int) str
10531053
return urlTemplate[:prefixLength] + "/" + strconv.Itoa(id)
10541054
}
10551055

1056-
func downloadBundle(t *testing.T, url string, dest io.Writer) {
1056+
func downloadAndUnzipBundle(t *testing.T, url string) *zip.Reader {
1057+
1058+
// Download the zip to a BytesBuffer.
10571059
httpClient := httputil.NewClientWithTimeout(30 * time.Second)
10581060
// Download the zip to a BytesBuffer.
10591061
resp, err := httpClient.Get(context.Background(), url)
10601062
if err != nil {
10611063
t.Fatal(err)
10621064
}
10631065
defer resp.Body.Close()
1064-
_, _ = io.Copy(dest, resp.Body)
1065-
}
1066-
1067-
func downloadAndUnzipBundle(t *testing.T, url string) *zip.Reader {
1068-
// Download the zip to a BytesBuffer.
10691066
var buf bytes.Buffer
1070-
downloadBundle(t, url, &buf)
1067+
_, _ = io.Copy(&buf, resp.Body)
10711068

10721069
unzip, err := zip.NewReader(bytes.NewReader(buf.Bytes()), int64(buf.Len()))
10731070
if err != nil {

pkg/sql/mem_limit_test.go

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ package sql
88
import (
99
"context"
1010
"fmt"
11-
"os"
12-
"path/filepath"
1311
"regexp"
1412
"strconv"
1513
"strings"
@@ -19,7 +17,6 @@ import (
1917
"github.com/cockroachdb/cockroach/pkg/base"
2018
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
2119
"github.com/cockroachdb/cockroach/pkg/testutils"
22-
"github.com/cockroachdb/cockroach/pkg/testutils/datapathutils"
2320
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
2421
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
2522
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
@@ -159,7 +156,6 @@ func TestStreamerTightBudget(t *testing.T) {
159156
// Streamer isn't hitting the root budget exceeded error.
160157
s, db, _ := serverutils.StartServer(t, base.TestServerArgs{
161158
SQLMemoryPoolSize: 1 << 30, /* 1GiB */
162-
Insecure: true,
163159
})
164160
defer s.Stopper().Stop(context.Background())
165161
sqlDB := sqlutils.MakeSQLRunner(db)
@@ -184,9 +180,9 @@ func TestStreamerTightBudget(t *testing.T) {
184180
sqlDB.Exec(t, fmt.Sprintf("SET distsql_workmem = '%dB'", blobSize))
185181

186182
// Perform an index join to read the blobs.
187-
query := "SELECT sum(length(blob)) FROM t@t_k_idx WHERE k = 1"
183+
query := "EXPLAIN ANALYZE SELECT sum(length(blob)) FROM t@t_k_idx WHERE k = 1"
188184
maximumMemoryUsageRegex := regexp.MustCompile(`maximum memory usage: (\d+\.\d+) MiB`)
189-
rows := sqlDB.QueryStr(t, "EXPLAIN ANALYZE (VERBOSE) "+query)
185+
rows := sqlDB.QueryStr(t, query)
190186
// Build pretty output for an error message in case we need it.
191187
var sb strings.Builder
192188
for _, row := range rows {
@@ -201,45 +197,9 @@ func TestStreamerTightBudget(t *testing.T) {
201197
// by the ColIndexJoin when the blob is copied into the columnar
202198
// batch). We allow for 0.1MiB for other memory usage in the query.
203199
maxAllowed := 2.1
204-
if maxAllowed >= usage {
205-
return
206-
}
207-
// Get a stmt bundle for this query that might help in debugging the
208-
// failure.
209-
rows = sqlDB.QueryStr(t, "EXPLAIN ANALYZE (DEBUG) "+query)
210-
url := getBundleDownloadURL(t, fmt.Sprint(rows))
211-
// First check whether the bundle experienced the elevated memory
212-
// usage too.
213-
unzip := downloadAndUnzipBundle(t, url)
214-
for _, f := range unzip.File {
215-
switch f.Name {
216-
case "plan.txt":
217-
contents := readUnzippedFile(t, f)
218-
sb.WriteString("\n\n\nbundle plan.txt:\n\n\n")
219-
sb.WriteString(contents)
220-
// Check that the memory usage is still elevated.
221-
if matches := maximumMemoryUsageRegex.FindStringSubmatch(contents); len(matches) == 0 {
222-
t.Fatalf("unexpectedly didn't find a match for maximum memory usage\n%s", sb.String())
223-
} else {
224-
bundleUsage, err := strconv.ParseFloat(matches[1], 64)
225-
require.NoError(t, err)
226-
if maxAllowed >= bundleUsage {
227-
// Memory usage is as expected in the bundle - do
228-
// not fail the test since we don't have any
229-
// information to help in understanding the original
230-
// high memory usage.
231-
return
232-
}
233-
}
234-
}
235-
}
236-
// NB: we're not using t.TempDir() because we want these to survive
237-
// on failure.
238-
f, err := os.Create(filepath.Join(datapathutils.DebuggableTempDir(), "bundle.zip"))
239-
require.NoError(t, err)
240-
downloadBundle(t, url, f)
241-
t.Fatalf("unexpectedly high memory usage\n----\n%s", sb.String())
200+
require.GreaterOrEqualf(t, maxAllowed, usage, "unexpectedly high memory usage\n----\n%s", sb.String())
201+
return
242202
}
243203
}
244-
t.Fatalf("unexpectedly didn't find a match for maximum memory usage\n%s", sb.String())
204+
t.Fatal("unexpectedly didn't find a match for maximum memory usage")
245205
}

0 commit comments

Comments
 (0)