Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

server: initialize DBContext with correct instance ID #97467

Merged
merged 2 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion pkg/server/tenant.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,11 @@ func makeTenantSQLServerArgs(
},
ds,
)
db := kv.NewDB(baseCfg.AmbientCtx, tcsFactory, clock, stopper)

dbCtx := kv.DefaultDBContext(stopper)
dbCtx.NodeID = instanceIDContainer
db := kv.NewDBWithContext(baseCfg.AmbientCtx, tcsFactory, clock, dbCtx)

rangeFeedKnobs, _ := baseCfg.TestingKnobs.RangeFeed.(*rangefeed.TestingKnobs)
rangeFeedFactory, err := rangefeed.NewFactory(stopper, db, st, rangeFeedKnobs)
if err != nil {
Expand Down
49 changes: 40 additions & 9 deletions pkg/sql/crdb_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,38 @@ func TestTxnContentionEventsTable(t *testing.T) {
defer tc.Stopper().Stop(ctx)
conn := tc.ServerConn(0)
sqlDB := sqlutils.MakeSQLRunner(tc.ServerConn(0))
testTxnContentionEventsTableHelper(t, ctx, conn, sqlDB)
}

func TestTxnContentionEventsTableMultiTenant(t *testing.T) {
defer leaktest.AfterTest(t)()
defer log.Scope(t).Close(t)

ctx := context.Background()
tc := testcluster.StartTestCluster(t, 1,
base.TestClusterArgs{
ServerArgs: base.TestServerArgs{
// Test is designed to run with explicit tenants. No need to
// implicitly create a tenant.
DisableDefaultTestTenant: true,
},
})
defer tc.Stopper().Stop(ctx)
_, tSQL := serverutils.StartTenant(t, tc.Server(0), base.TestTenantArgs{
TenantID: roachpb.MustMakeTenantID(10),
})

conn, err := tSQL.Conn(ctx)
require.NoError(t, err)
sqlDB := sqlutils.MakeSQLRunner(conn)
defer tSQL.Close()

testTxnContentionEventsTableHelper(t, ctx, tSQL, sqlDB)
}

func testTxnContentionEventsTableHelper(
t *testing.T, ctx context.Context, conn *gosql.DB, sqlDB *sqlutils.SQLRunner,
) {
sqlDB.Exec(
t,
`SET CLUSTER SETTING sql.metrics.statement_details.plan_collection.enabled = false;`)
Expand Down Expand Up @@ -977,8 +1008,8 @@ func TestTxnContentionEventsTable(t *testing.T) {
// This ensures the event is the one caused in the test and not by some other
// internal workflow.
testutils.SucceedsWithin(t, func() error {
rows, errVerify := conn.QueryContext(ctx, `SELECT
blocking_txn_id,
rows, errVerify := conn.QueryContext(ctx, `SELECT
blocking_txn_id,
waiting_txn_id,
waiting_stmt_id,
encode(
Expand All @@ -989,14 +1020,14 @@ func TestTxnContentionEventsTable(t *testing.T) {
schema_name,
table_name,
index_name
FROM crdb_internal.transaction_contention_events tce
inner join (
FROM crdb_internal.transaction_contention_events tce
inner join (
select
fingerprint_id,
transaction_fingerprint_id,
metadata->'query' as query
from crdb_internal.statement_statistics t
where metadata->>'query' like 'UPDATE t SET %') stats
transaction_fingerprint_id,
metadata->'query' as query
from crdb_internal.statement_statistics t
where metadata->>'query' like 'UPDATE t SET %') stats
on stats.transaction_fingerprint_id = tce.waiting_txn_fingerprint_id
and stats.fingerprint_id = tce.waiting_stmt_fingerprint_id`)
if errVerify != nil {
Expand Down Expand Up @@ -1188,7 +1219,7 @@ func TestInternalSystemJobsTableMirrorsSystemJobsTable(t *testing.T) {
res := tdb.QueryStr(t, "SELECT * FROM system.jobs ORDER BY id")
tdb.CheckQueryResults(t, `SELECT * FROM crdb_internal.system_jobs ORDER BY id`, res)
tdb.CheckQueryResults(t, `
SELECT id, status, created, payload, progress, created_by_type, created_by_id, claim_session_id,
SELECT id, status, created, payload, progress, created_by_type, created_by_id, claim_session_id,
claim_instance_id, num_runs, last_run, job_type
FROM crdb_internal.system_jobs ORDER BY id`,
res,
Expand Down