diff --git a/private/testplanet/run.go b/private/testplanet/run.go index 66976b80b2d7..a69faec8a718 100644 --- a/private/testplanet/run.go +++ b/private/testplanet/run.go @@ -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" @@ -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) - } - } }) }) } diff --git a/satellite/metabase/metabasetest/run.go b/satellite/metabase/metabasetest/run.go index 4e5d4bbd2b29..20532fcf25b3 100644 --- a/satellite/metabase/metabasetest/run.go +++ b/satellite/metabase/metabasetest/run.go @@ -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" @@ -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) - } }) } } @@ -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() -} diff --git a/satellite/satellitedb/satellitedbtest/run.go b/satellite/satellitedb/satellitedbtest/run.go index f0a82cfeed70..4906b99e671e 100644 --- a/satellite/satellitedb/satellitedbtest/run.go +++ b/satellite/satellitedb/satellitedbtest/run.go @@ -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" @@ -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) - } - } }) } } @@ -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 -}