diff --git a/pkg/cmd/roachtest/registry/owners.go b/pkg/cmd/roachtest/registry/owners.go index 2c0021a24dae..68606b66d921 100644 --- a/pkg/cmd/roachtest/registry/owners.go +++ b/pkg/cmd/roachtest/registry/owners.go @@ -16,7 +16,7 @@ type Owner string // The allowable values of Owner. const ( - OwnerSQLExperience Owner = `sql-sessions` + OwnerSQLSessions Owner = `sql-sessions` OwnerDisasterRecovery Owner = `disaster-recovery` OwnerCDC Owner = `cdc` OwnerKV Owner = `kv` diff --git a/pkg/cmd/roachtest/tests/activerecord.go b/pkg/cmd/roachtest/tests/activerecord.go index d1084b69c62b..bbf0af03f363 100644 --- a/pkg/cmd/roachtest/tests/activerecord.go +++ b/pkg/cmd/roachtest/tests/activerecord.go @@ -242,7 +242,7 @@ func registerActiveRecord(r registry.Registry) { r.Add(registry.TestSpec{ Name: "activerecord", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), NativeLibs: registry.LibGEOS, Tags: []string{`default`, `orm`}, diff --git a/pkg/cmd/roachtest/tests/asyncpg.go b/pkg/cmd/roachtest/tests/asyncpg.go index 4406cd643425..4558afab5f68 100644 --- a/pkg/cmd/roachtest/tests/asyncpg.go +++ b/pkg/cmd/roachtest/tests/asyncpg.go @@ -139,7 +139,7 @@ func registerAsyncpg(r registry.Registry) { r.Add(registry.TestSpec{ Name: "asyncpg", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1, spec.CPU(16)), Tags: []string{`default`, `orm`}, Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { diff --git a/pkg/cmd/roachtest/tests/awsdms.go b/pkg/cmd/roachtest/tests/awsdms.go index 87984c081fdc..6477a16ea2d8 100644 --- a/pkg/cmd/roachtest/tests/awsdms.go +++ b/pkg/cmd/roachtest/tests/awsdms.go @@ -184,7 +184,7 @@ func dmsDescribeTasksInput( func registerAWSDMS(r registry.Registry) { r.Add(registry.TestSpec{ Name: "awsdms", - Owner: registry.OwnerSQLExperience, // TODO(otan): add a migrations OWNERS team + Owner: registry.OwnerSQLSessions, // TODO(otan): add a migrations OWNERS team Cluster: r.MakeClusterSpec(1), Tags: []string{`default`, `awsdms`}, Run: runAWSDMS, diff --git a/pkg/cmd/roachtest/tests/connection_latency.go b/pkg/cmd/roachtest/tests/connection_latency.go index d09c41b607c5..259edfe87203 100644 --- a/pkg/cmd/roachtest/tests/connection_latency.go +++ b/pkg/cmd/roachtest/tests/connection_latency.go @@ -119,7 +119,7 @@ func registerConnectionLatencyTest(r registry.Registry) { numNodes := 3 r.Add(registry.TestSpec{ Name: fmt.Sprintf("connection_latency/nodes=%d/certs", numNodes), - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, // Add one more node for load node. Cluster: r.MakeClusterSpec(numNodes+1, spec.Zones(regionUsCentral)), Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { @@ -135,7 +135,7 @@ func registerConnectionLatencyTest(r registry.Registry) { r.Add(registry.TestSpec{ Name: fmt.Sprintf("connection_latency/nodes=%d/multiregion/certs", numMultiRegionNodes), - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(numMultiRegionNodes+loadNodes, spec.Geo(), spec.Zones(geoZonesStr)), Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { runConnectionLatencyTest(ctx, t, c, numMultiRegionNodes, numZones, false /*password*/) @@ -144,7 +144,7 @@ func registerConnectionLatencyTest(r registry.Registry) { r.Add(registry.TestSpec{ Name: fmt.Sprintf("connection_latency/nodes=%d/multiregion/password", numMultiRegionNodes), - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(numMultiRegionNodes+loadNodes, spec.Geo(), spec.Zones(geoZonesStr)), Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { runConnectionLatencyTest(ctx, t, c, numMultiRegionNodes, numZones, true /*password*/) diff --git a/pkg/cmd/roachtest/tests/django.go b/pkg/cmd/roachtest/tests/django.go index 67e0d8b59264..fca75928bb92 100644 --- a/pkg/cmd/roachtest/tests/django.go +++ b/pkg/cmd/roachtest/tests/django.go @@ -215,7 +215,7 @@ func registerDjango(r registry.Registry) { r.Add(registry.TestSpec{ Name: "django", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1, spec.CPU(16)), Tags: []string{`default`, `orm`}, Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { diff --git a/pkg/cmd/roachtest/tests/drain.go b/pkg/cmd/roachtest/tests/drain.go index 203ff63e073a..265b8bad0ddc 100644 --- a/pkg/cmd/roachtest/tests/drain.go +++ b/pkg/cmd/roachtest/tests/drain.go @@ -32,7 +32,7 @@ func registerDrain(r registry.Registry) { { r.Add(registry.TestSpec{ Name: "drain/early-exit-conn-wait", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { runEarlyExitInConnectionWait(ctx, t, c) @@ -41,7 +41,7 @@ func registerDrain(r registry.Registry) { r.Add(registry.TestSpec{ Name: "drain/warn-conn-wait-timeout", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { runTestWarningForConnWait(ctx, t, c) diff --git a/pkg/cmd/roachtest/tests/flowable.go b/pkg/cmd/roachtest/tests/flowable.go index 81f63f904dc5..44ac76413ae8 100644 --- a/pkg/cmd/roachtest/tests/flowable.go +++ b/pkg/cmd/roachtest/tests/flowable.go @@ -104,7 +104,7 @@ func registerFlowable(r registry.Registry) { r.Add(registry.TestSpec{ Name: "flowable", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { runFlowable(ctx, t, c) diff --git a/pkg/cmd/roachtest/tests/gopg.go b/pkg/cmd/roachtest/tests/gopg.go index 1424536cda3f..99780981f4ed 100644 --- a/pkg/cmd/roachtest/tests/gopg.go +++ b/pkg/cmd/roachtest/tests/gopg.go @@ -164,7 +164,7 @@ func registerGopg(r registry.Registry) { r.Add(registry.TestSpec{ Name: "gopg", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Tags: []string{`default`, `orm`}, Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { diff --git a/pkg/cmd/roachtest/tests/gorm.go b/pkg/cmd/roachtest/tests/gorm.go index f689f6e28e3c..f86ce7504fcc 100644 --- a/pkg/cmd/roachtest/tests/gorm.go +++ b/pkg/cmd/roachtest/tests/gorm.go @@ -134,7 +134,7 @@ func registerGORM(r registry.Registry) { r.Add(registry.TestSpec{ Name: "gorm", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Tags: []string{`default`, `orm`}, Run: runGORM, diff --git a/pkg/cmd/roachtest/tests/hibernate.go b/pkg/cmd/roachtest/tests/hibernate.go index 84f0ee9ce144..737bd6321a57 100644 --- a/pkg/cmd/roachtest/tests/hibernate.go +++ b/pkg/cmd/roachtest/tests/hibernate.go @@ -235,7 +235,7 @@ func registerHibernate(r registry.Registry, opt hibernateOptions) { r.Add(registry.TestSpec{ Name: opt.testName, - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), NativeLibs: registry.LibGEOS, Tags: []string{`default`, `orm`}, diff --git a/pkg/cmd/roachtest/tests/import.go b/pkg/cmd/roachtest/tests/import.go index d5634bdcdccf..76a520ad7f17 100644 --- a/pkg/cmd/roachtest/tests/import.go +++ b/pkg/cmd/roachtest/tests/import.go @@ -85,7 +85,7 @@ func registerImportNodeShutdown(r registry.Registry) { r.Add(registry.TestSpec{ Name: "import/nodeShutdown/worker", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(4), Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { c.Put(ctx, t.Cockroach(), "./cockroach") @@ -99,7 +99,7 @@ func registerImportNodeShutdown(r registry.Registry) { }) r.Add(registry.TestSpec{ Name: "import/nodeShutdown/coordinator", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(4), Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { c.Put(ctx, t.Cockroach(), "./cockroach") @@ -162,7 +162,7 @@ func registerImportTPCC(r registry.Registry) { timeout := 5 * time.Hour r.Add(registry.TestSpec{ Name: testName, - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(numNodes), Timeout: timeout, EncryptionSupport: registry.EncryptionMetamorphic, @@ -175,7 +175,7 @@ func registerImportTPCC(r registry.Registry) { const geoZones = "europe-west2-b,europe-west4-b,asia-northeast1-b,us-west1-b" r.Add(registry.TestSpec{ Name: fmt.Sprintf("import/tpcc/warehouses=%d/geo", geoWarehouses), - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(8, spec.CPU(16), spec.Geo(), spec.Zones(geoZones)), Timeout: 5 * time.Hour, EncryptionSupport: registry.EncryptionMetamorphic, @@ -207,7 +207,7 @@ func registerImportTPCH(r registry.Registry) { item := item r.Add(registry.TestSpec{ Name: fmt.Sprintf(`import/tpch/nodes=%d`, item.nodes), - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(item.nodes), Timeout: item.timeout, EncryptionSupport: registry.EncryptionMetamorphic, @@ -347,7 +347,7 @@ func runImportMixedVersion( func registerImportMixedVersion(r registry.Registry) { r.Add(registry.TestSpec{ Name: "import/mixed-versions", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, // Mixed-version support was added in 21.1. Cluster: r.MakeClusterSpec(4), Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { @@ -394,7 +394,7 @@ func registerImportDecommissioned(r registry.Registry) { r.Add(registry.TestSpec{ Name: "import/decommissioned", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(4), Run: runImportDecommissioned, }) diff --git a/pkg/cmd/roachtest/tests/jasyncsql.go b/pkg/cmd/roachtest/tests/jasyncsql.go index f5051cc34325..e5c84a8540a7 100644 --- a/pkg/cmd/roachtest/tests/jasyncsql.go +++ b/pkg/cmd/roachtest/tests/jasyncsql.go @@ -148,7 +148,7 @@ func registerJasyncSQL(r registry.Registry) { r.Add(registry.TestSpec{ Name: "jasync", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Tags: []string{`default`, `orm`}, Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { diff --git a/pkg/cmd/roachtest/tests/knex.go b/pkg/cmd/roachtest/tests/knex.go index 11994c6aad79..85e055ea29d6 100644 --- a/pkg/cmd/roachtest/tests/knex.go +++ b/pkg/cmd/roachtest/tests/knex.go @@ -128,7 +128,7 @@ func registerKnex(r registry.Registry) { r.Add(registry.TestSpec{ Name: "knex", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), NativeLibs: registry.LibGEOS, Tags: []string{`default`, `orm`}, diff --git a/pkg/cmd/roachtest/tests/libpq.go b/pkg/cmd/roachtest/tests/libpq.go index 17eb126f482d..20c2b8d05e87 100644 --- a/pkg/cmd/roachtest/tests/libpq.go +++ b/pkg/cmd/roachtest/tests/libpq.go @@ -140,7 +140,7 @@ func registerLibPQ(r registry.Registry) { r.Add(registry.TestSpec{ Name: "lib/pq", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Tags: []string{`default`, `driver`}, Run: runLibPQ, diff --git a/pkg/cmd/roachtest/tests/liquibase.go b/pkg/cmd/roachtest/tests/liquibase.go index 1085cbe86cfe..5ed047ce222d 100644 --- a/pkg/cmd/roachtest/tests/liquibase.go +++ b/pkg/cmd/roachtest/tests/liquibase.go @@ -132,7 +132,7 @@ func registerLiquibase(r registry.Registry) { r.Add(registry.TestSpec{ Name: "liquibase", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Tags: []string{`default`, `tool`}, Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { diff --git a/pkg/cmd/roachtest/tests/nodejs_postgres.go b/pkg/cmd/roachtest/tests/nodejs_postgres.go index 9065511956aa..1ee93c60871c 100644 --- a/pkg/cmd/roachtest/tests/nodejs_postgres.go +++ b/pkg/cmd/roachtest/tests/nodejs_postgres.go @@ -168,7 +168,7 @@ PGSSLCERT=$HOME/certs/client.%s.crt PGSSLKEY=$HOME/certs/client.%s.key PGSSLROOT r.Add(registry.TestSpec{ Name: "node-postgres", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Tags: []string{`default`, `driver`}, Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { diff --git a/pkg/cmd/roachtest/tests/pgjdbc.go b/pkg/cmd/roachtest/tests/pgjdbc.go index a2472fdd9f2b..c837dba12dda 100644 --- a/pkg/cmd/roachtest/tests/pgjdbc.go +++ b/pkg/cmd/roachtest/tests/pgjdbc.go @@ -211,7 +211,7 @@ func registerPgjdbc(r registry.Registry) { r.Add(registry.TestSpec{ Name: "pgjdbc", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Tags: []string{`default`, `driver`}, Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { diff --git a/pkg/cmd/roachtest/tests/pgx.go b/pkg/cmd/roachtest/tests/pgx.go index c59b6954d2aa..dcee382abd7b 100644 --- a/pkg/cmd/roachtest/tests/pgx.go +++ b/pkg/cmd/roachtest/tests/pgx.go @@ -140,7 +140,7 @@ func registerPgx(r registry.Registry) { r.Add(registry.TestSpec{ Name: "pgx", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Tags: []string{`default`, `driver`}, Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { diff --git a/pkg/cmd/roachtest/tests/pop.go b/pkg/cmd/roachtest/tests/pop.go index 5c0bd2580aa7..1cf98dae36f5 100644 --- a/pkg/cmd/roachtest/tests/pop.go +++ b/pkg/cmd/roachtest/tests/pop.go @@ -100,7 +100,7 @@ func registerPop(r registry.Registry) { r.Add(registry.TestSpec{ Name: "pop", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Tags: []string{`default`, `orm`}, Run: runPop, diff --git a/pkg/cmd/roachtest/tests/psycopg.go b/pkg/cmd/roachtest/tests/psycopg.go index b9de3e7ca68f..c7a5333dc342 100644 --- a/pkg/cmd/roachtest/tests/psycopg.go +++ b/pkg/cmd/roachtest/tests/psycopg.go @@ -81,15 +81,15 @@ func registerPsycopg(r registry.Registry) { // TODO(rafi): When psycopg 2.9.4 is released and tagged, // use the tag version instead of the commit. - //if err := repeatGitCloneE( + // if err := repeatGitCloneE( // ctx, t, c, // "https://github.com/psycopg/psycopg2.git", // "/mnt/data1/psycopg", // supportedPsycopgTag, // node, - //); err != nil { + // ); err != nil { // t.Fatal(err) - //} + // } if err = c.RunE(ctx, node, "git clone https://github.com/psycopg/psycopg2.git /mnt/data1/psycopg"); err != nil { t.Fatal(err) } @@ -148,7 +148,7 @@ func registerPsycopg(r registry.Registry) { r.Add(registry.TestSpec{ Name: "psycopg", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Tags: []string{`default`, `driver`}, Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { diff --git a/pkg/cmd/roachtest/tests/ruby_pg.go b/pkg/cmd/roachtest/tests/ruby_pg.go index a53d62168d56..58924dd99eff 100644 --- a/pkg/cmd/roachtest/tests/ruby_pg.go +++ b/pkg/cmd/roachtest/tests/ruby_pg.go @@ -227,7 +227,7 @@ func registerRubyPG(r registry.Registry) { r.Add(registry.TestSpec{ Name: "ruby-pg", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), NativeLibs: registry.LibGEOS, Tags: []string{`default`, `orm`}, diff --git a/pkg/cmd/roachtest/tests/rust_postgres.go b/pkg/cmd/roachtest/tests/rust_postgres.go index fa5512b1f692..db23d83e8d06 100644 --- a/pkg/cmd/roachtest/tests/rust_postgres.go +++ b/pkg/cmd/roachtest/tests/rust_postgres.go @@ -163,7 +163,7 @@ func registerRustPostgres(r registry.Registry) { r.Add(registry.TestSpec{ Name: "rust-postgres", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1, spec.CPU(16)), Tags: []string{`default`, `orm`}, Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { diff --git a/pkg/cmd/roachtest/tests/sequelize.go b/pkg/cmd/roachtest/tests/sequelize.go index a7d3f99c6cd6..f6929a4dba63 100644 --- a/pkg/cmd/roachtest/tests/sequelize.go +++ b/pkg/cmd/roachtest/tests/sequelize.go @@ -151,7 +151,7 @@ func registerSequelize(r registry.Registry) { r.Add(registry.TestSpec{ Name: "sequelize", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), NativeLibs: registry.LibGEOS, Tags: []string{`default`, `orm`}, diff --git a/pkg/cmd/roachtest/tests/sqlalchemy.go b/pkg/cmd/roachtest/tests/sqlalchemy.go index 8dc6f1646fdc..6fa629a1a5a9 100644 --- a/pkg/cmd/roachtest/tests/sqlalchemy.go +++ b/pkg/cmd/roachtest/tests/sqlalchemy.go @@ -37,7 +37,7 @@ var supportedSQLAlchemyTag = "2.0.2" func registerSQLAlchemy(r registry.Registry) { r.Add(registry.TestSpec{ Name: "sqlalchemy", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Tags: []string{`default`, `orm`}, Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { diff --git a/pkg/cmd/roachtest/tests/typeorm.go b/pkg/cmd/roachtest/tests/typeorm.go index 1fd16942a933..26bf448de716 100644 --- a/pkg/cmd/roachtest/tests/typeorm.go +++ b/pkg/cmd/roachtest/tests/typeorm.go @@ -180,7 +180,7 @@ func registerTypeORM(r registry.Registry) { r.Add(registry.TestSpec{ Name: "typeorm", - Owner: registry.OwnerSQLExperience, + Owner: registry.OwnerSQLSessions, Cluster: r.MakeClusterSpec(1), Tags: []string{`default`, `orm`}, Run: func(ctx context.Context, t test.Test, c cluster.Cluster) { diff --git a/pkg/sql/cacheutil/cache.go b/pkg/sql/cacheutil/cache.go index e3ead6ebb9c4..2355bbb12c3a 100644 --- a/pkg/sql/cacheutil/cache.go +++ b/pkg/sql/cacheutil/cache.go @@ -12,7 +12,6 @@ package cacheutil import ( "context" - "unsafe" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" "github.com/cockroachdb/cockroach/pkg/util/log" @@ -79,12 +78,16 @@ func (c *Cache) LoadValueOutsideOfCacheSingleFlight( // MaybeWriteBackToCache tries to put the key, value into the // cache, and returns true if it succeeded. If the underlying system // tables have been modified since they were read, the cache is not -// updated. +// updated. The entrySize should be the size in bytes of the key and value. // Note that reading from system tables may give us data from a newer table // version than the one we pass in here, that is okay since the cache will // be invalidated upon the next read. func (c *Cache) MaybeWriteBackToCache( - ctx context.Context, tableVersions []descpb.DescriptorVersion, key interface{}, entry interface{}, + ctx context.Context, + tableVersions []descpb.DescriptorVersion, + key interface{}, + value interface{}, + entrySize int64, ) bool { c.Lock() defer c.Unlock() @@ -98,14 +101,13 @@ func (c *Cache) MaybeWriteBackToCache( } } // Table version remains the same: update map, unlock, return. - const sizeOfEntry = int(unsafe.Sizeof(entry)) - if err := c.boundAccount.Grow(ctx, int64(sizeOfEntry)); err != nil { + if err := c.boundAccount.Grow(ctx, entrySize); err != nil { // If there is no memory available to cache the entry, we can still // proceed with authentication so that users are not locked out of // the database. log.Ops.Warningf(ctx, "no memory available to cache info: %v", err) } else { - c.cache[key] = entry + c.cache[key] = value } return true } diff --git a/pkg/sql/cacheutil/cache_test.go b/pkg/sql/cacheutil/cache_test.go index b34fbe272912..92141b9e8060 100644 --- a/pkg/sql/cacheutil/cache_test.go +++ b/pkg/sql/cacheutil/cache_test.go @@ -66,13 +66,13 @@ func TestCache(t *testing.T) { }() } - wrote := cache.MaybeWriteBackToCache(ctx, []descpb.DescriptorVersion{2, 2}, "test", "val") + wrote := cache.MaybeWriteBackToCache(ctx, []descpb.DescriptorVersion{2, 2}, "test", "val", int64(len("test")+len("val"))) require.Equal(t, wrote, true) - wrote = cache.MaybeWriteBackToCache(ctx, []descpb.DescriptorVersion{0, 2}, "test", "val") + wrote = cache.MaybeWriteBackToCache(ctx, []descpb.DescriptorVersion{0, 2}, "test", "val", int64(len("test")+len("val"))) require.Equal(t, wrote, false) - wrote = cache.MaybeWriteBackToCache(ctx, []descpb.DescriptorVersion{2, 0}, "test", "val") + wrote = cache.MaybeWriteBackToCache(ctx, []descpb.DescriptorVersion{2, 0}, "test", "val", int64(len("test")+len("val"))) require.Equal(t, wrote, false) val, ok := cache.GetValueLocked("test") diff --git a/pkg/sql/logictest/testdata/logic_test/builtin_function b/pkg/sql/logictest/testdata/logic_test/builtin_function index 041cd72bbdd5..07366eef4a77 100644 --- a/pkg/sql/logictest/testdata/logic_test/builtin_function +++ b/pkg/sql/logictest/testdata/logic_test/builtin_function @@ -3751,6 +3751,18 @@ SELECT crdb_internal.hide_sql_constants(NULL) ---- NULL +query T +SELECT crdb_internal.hide_sql_constants('not a sql stmt') +---- +· + + +query T +select crdb_internal.hide_sql_constants(e'\r'); +---- +· + + query T SELECT crdb_internal.hide_sql_constants(create_statement) from crdb_internal.create_statements where descriptor_name = 'foo' ---- diff --git a/pkg/sql/sem/builtins/builtins.go b/pkg/sql/sem/builtins/builtins.go index 566f938e7dcf..cf223461b476 100644 --- a/pkg/sql/sem/builtins/builtins.go +++ b/pkg/sql/sem/builtins/builtins.go @@ -7712,7 +7712,10 @@ expires until the statement bundle is collected`, parsed, err := parser.ParseOne(sql) if err != nil { - return nil, err + // If parsing is unsuccessful, we shouldn't return an error, however + // we can't return the original stmt since this function is used to + // hide sensitive information. + return tree.NewDString(""), nil //nolint:returnerrcheck } sqlNoConstants := tree.AsStringWithFlags(parsed.AST, tree.FmtHideConstants) return tree.NewDString(sqlNoConstants), nil @@ -7743,7 +7746,7 @@ expires until the statement bundle is collected`, if len(sql) != 0 { parsed, err := parser.ParseOne(sql) if err != nil { - return nil, err + return tree.NewDString(sqlNoConstants), nil //nolint:returnerrcheck } sqlNoConstants = tree.AsStringWithFlags(parsed.AST, tree.FmtHideConstants) diff --git a/pkg/sql/syntheticprivilegecache/cache.go b/pkg/sql/syntheticprivilegecache/cache.go index 7f95736d2c28..274ccee842a9 100644 --- a/pkg/sql/syntheticprivilegecache/cache.go +++ b/pkg/sql/syntheticprivilegecache/cache.go @@ -13,6 +13,7 @@ package syntheticprivilegecache import ( "context" "fmt" + "unsafe" "github.com/cockroachdb/cockroach/pkg/clusterversion" "github.com/cockroachdb/cockroach/pkg/kv" @@ -96,9 +97,9 @@ func (c *Cache) Get( return nil, err } privDesc := val.(*catpb.PrivilegeDescriptor) - // Only write back to the cache if the table version is - // committed. - c.c.MaybeWriteBackToCache(ctx, []descpb.DescriptorVersion{desc.GetVersion()}, spo.GetPath(), *privDesc) + entrySize := int64(len(spo.GetPath())) + computePrivDescSize(privDesc) + // Only write back to the cache if the table version is committed. + c.c.MaybeWriteBackToCache(ctx, []descpb.DescriptorVersion{desc.GetVersion()}, spo.GetPath(), *privDesc, entrySize) return privDesc, nil } @@ -278,7 +279,8 @@ func (c *Cache) start(ctx context.Context) error { if accum, ok := vtablePathToPrivilegeAccumulator[vtablePriv.GetPath()]; ok { privDesc = accum.finish() } - c.c.MaybeWriteBackToCache(ctx, tableVersions, vtablePriv.GetPath(), *privDesc) + entrySize := int64(len(vtablePriv.GetPath())) + computePrivDescSize(privDesc) + c.c.MaybeWriteBackToCache(ctx, tableVersions, vtablePriv.GetPath(), *privDesc, entrySize) }) } return nil @@ -292,3 +294,15 @@ func (c *Cache) waitForWarmed(ctx context.Context) error { return ctx.Err() } } + +// computePrivDescSize computes the size in bytes required by the data in this +// descriptor. +func computePrivDescSize(privDesc *catpb.PrivilegeDescriptor) int64 { + privDescSize := int(unsafe.Sizeof(*privDesc)) + privDescSize += len(privDesc.OwnerProto) + for _, u := range privDesc.Users { + privDescSize += int(unsafe.Sizeof(u)) + privDescSize += len(u.UserProto) + } + return int64(privDescSize) +}