Skip to content

Commit

Permalink
testsuite: drop full table scan detection
Browse files Browse the repository at this point in the history
Turns out that this check have significant impact on tests duration.

Change-Id: I2eec5e2d9ad4b83e856db0910cb7f88fe336d824
  • Loading branch information
mniewrzal authored and Storj Robot committed Apr 4, 2024
1 parent 047554d commit 139e061
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 150 deletions.
28 changes: 0 additions & 28 deletions private/testplanet/run.go
Expand Up @@ -8,14 +8,10 @@ import (
"runtime/pprof"
"testing"

"github.com/google/go-cmp/cmp"
"go.uber.org/zap"

"storj.io/common/context2"
"storj.io/common/dbutil"
"storj.io/common/dbutil/pgtest"
"storj.io/common/dbutil/pgutil"
"storj.io/common/tagsql"
"storj.io/common/testcontext"
"storj.io/storj/private/testmonkit"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
Expand Down Expand Up @@ -68,31 +64,7 @@ func Run(t *testing.T, config Config, test func(t *testing.T, ctx *testcontext.C

planet.Start(ctx)

var rawDB tagsql.DB
var queriesBefore []string
if len(planet.Satellites) > 0 && satelliteDB.Name == "Cockroach" {
rawDB = planet.Satellites[0].DB.Testing().RawDB()

var err error
queriesBefore, err = satellitedbtest.FullTableScanQueries(ctx, rawDB, dbutil.Cockroach, planetConfig.applicationName)
if err != nil {
t.Fatalf("%+v", err)
}
}

test(t, ctx, planet)

if rawDB != nil {
queriesAfter, err := satellitedbtest.FullTableScanQueries(context2.WithoutCancellation(ctx), rawDB, dbutil.Cockroach, planetConfig.applicationName)
if err != nil {
t.Fatalf("%+v", err)
}

diff := cmp.Diff(queriesBefore, queriesAfter)
if diff != "" {
log.Sugar().Warnf("FULL TABLE SCAN DETECTED\n%s", diff)
}
}
})
})
}
Expand Down
56 changes: 0 additions & 56 deletions satellite/metabase/metabasetest/run.go
Expand Up @@ -5,12 +5,9 @@ package metabasetest

import (
"context"
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/spf13/pflag"
"github.com/zeebo/errs"
"go.uber.org/zap/zaptest"

"storj.io/common/cfgstruct"
Expand Down Expand Up @@ -56,22 +53,7 @@ func RunWithConfigAndMigration(t *testing.T, config metabase.Config, fn func(ctx
t.Fatal(err)
}

fullScansBefore, err := fullTableScanQueries(ctx, db, config.ApplicationName)
if err != nil {
t.Fatal(err)
}

fn(ctx, t, db)

fullScansAfter, err := fullTableScanQueries(ctx, db, config.ApplicationName)
if err != nil {
t.Fatal(err)
}

diff := cmp.Diff(fullScansBefore, fullScansAfter)
if diff != "" {
t.Fatal(diff)
}
})
}
}
Expand Down Expand Up @@ -126,41 +108,3 @@ func Bench(b *testing.B, fn func(ctx *testcontext.Context, b *testing.B, db *met
})
}
}

func fullTableScanQueries(ctx context.Context, db *metabase.DB, applicationName string) (_ map[string]int, err error) {
if db.Implementation().String() != "cockroach" {
return nil, nil
}

rows, err := db.UnderlyingTagSQL().QueryContext(ctx,
"SELECT key, count FROM crdb_internal.node_statement_statistics WHERE full_scan = TRUE AND application_name = $1 ORDER BY count DESC",
applicationName,
)
if err != nil {
return nil, err
}
defer func() {
err = errs.Combine(err, rows.Close())
}()

result := map[string]int{}
for rows.Next() {
var query string
var count int
err := rows.Scan(&query, &count)
if err != nil {
return nil, err
}

switch {
case strings.Contains(query, "WITH ignore_full_scan_for_test AS (SELECT _)"):
continue
case !strings.Contains(strings.ToUpper(query), "WHERE"): // find smarter way to ignore known full table scan queries
continue
}

result[query] += count
}

return result, rows.Err()
}
66 changes: 0 additions & 66 deletions satellite/satellitedb/satellitedbtest/run.go
Expand Up @@ -15,7 +15,6 @@ import (
"strings"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/zeebo/errs"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
Expand Down Expand Up @@ -223,28 +222,7 @@ func Run(t *testing.T, test func(ctx *testcontext.Context, t *testing.T, db sate
t.Fatal(err)
}

var fullScansBefore []string
tempMasterDB, ok := db.(*tempMasterDB)
if ok {
fullScansBefore, err = FullTableScanQueries(ctx, tempMasterDB.tempDB.DB, tempMasterDB.tempDB.Implementation, applicationName)
if err != nil {
t.Fatal(err)
}
}

test(ctx, t, db)

if ok {
fullScansAfter, err := FullTableScanQueries(ctx, tempMasterDB.tempDB.DB, tempMasterDB.tempDB.Implementation, applicationName)
if err != nil {
t.Fatal(err)
}

diff := cmp.Diff(fullScansBefore, fullScansAfter)
if diff != "" {
logger.Sugar().Warnf("FULL TABLE SCAN DETECTED\n%s", diff)
}
}
})
}
}
Expand Down Expand Up @@ -283,47 +261,3 @@ func Bench(b *testing.B, bench func(b *testing.B, db satellite.DB)) {
})
}
}

// FullTableScanQueries is a helper method to list all queries which performed full table scan recently. It works only for cockroach db.
func FullTableScanQueries(ctx context.Context, db tagsql.DB, implementation dbutil.Implementation, applicationName string) (queries []string, err error) {
if implementation != dbutil.Cockroach {
return nil, nil
}

rows, err := db.QueryContext(ctx,
"SELECT key FROM crdb_internal.node_statement_statistics WHERE full_scan = TRUE AND application_name = $1 ORDER BY count DESC",
applicationName,
)
if err != nil {
return nil, err
}
defer func() {
err = errs.Combine(err, rows.Close())
}()

result := map[string]struct{}{}
for rows.Next() {
var query string
err := rows.Scan(&query)
if err != nil {
return nil, err
}

// find smarter way to ignore known full table scan queries
if !strings.Contains(strings.ToUpper(query), "WHERE") {
continue
}

result[query] = struct{}{}
}

if rows.Err() != nil {
return nil, rows.Err()
}

for query := range result {
queries = append(queries, query)
}

return queries, nil
}

0 comments on commit 139e061

Please sign in to comment.