Skip to content

Commit

Permalink
bootstrap: unify tenant and sys tables
Browse files Browse the repository at this point in the history
We want to be able to replicate a system tenant into a non-system tenant
but this requires that they have the same set of system tables so that
when the non-system tenant starts executing, it finds all the same tables
that it expects to exist, regardless of whether it was created via PCR of
a system tenant or bootstrap of a secondary tenant.

Release note: none.
Epic: none.
  • Loading branch information
dt committed Apr 10, 2024
1 parent 911f1ce commit 6036490
Show file tree
Hide file tree
Showing 100 changed files with 1,419 additions and 1,110 deletions.
20 changes: 4 additions & 16 deletions pkg/ccl/backupccl/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11101,14 +11101,7 @@ $$;
udfID, err = strconv.Atoi(rows[0][0])
require.NoError(t, err)

isSystemTenant := tgtCluster.ApplicationLayer(0).Codec().ForSystemTenant()

// System tenant restores the system.tenant_settings while the secondary
// tenant does not.
startingDescID := 122
if isSystemTenant {
startingDescID = 123
}
const startingDescID = 123
err = sql.TestingDescsTxn(ctx, tgtServer, func(ctx context.Context, txn isql.Txn, col *descs.Collection) error {
dbDesc, err := col.ByNameWithLeased(txn.KV()).Get().Database(ctx, "db1")
require.NoError(t, err)
Expand Down Expand Up @@ -11142,14 +11135,9 @@ $$;
require.Equal(t, fmt.Sprintf("SELECT a FROM db1.sc1.tbl1;\nSELECT nextval(%d:::REGCLASS);",
startingDescID+6), fnDesc.GetFunctionBody())

expectedOID := 100126
dependsOn := []descpb.ID{125, 128}
dependsOnTypes := []descpb.ID{126, 127}
if isSystemTenant {
expectedOID = 100127
dependsOn = []descpb.ID{126, 129}
dependsOnTypes = []descpb.ID{127, 128}
}
expectedOID := 100127
dependsOn := []descpb.ID{126, 129}
dependsOnTypes := []descpb.ID{127, 128}
require.Equal(t, expectedOID, int(fnDesc.GetParams()[0].Type.Oid()))
require.Equal(t, dependsOn, fnDesc.GetDependsOn())
require.Equal(t, dependsOnTypes, fnDesc.GetDependsOnTypes())
Expand Down
123 changes: 40 additions & 83 deletions pkg/ccl/backupccl/full_cluster_backup_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -708,48 +708,26 @@ func TestClusterRestoreFailCleanup(t *testing.T) {
// Verify the failed RESTORE added some DROP tables.
// Note that the system tables here correspond to the temporary tables
// imported, not the system tables themselves.
if isBackupOfSystemTenant {
sqlDBRestore.CheckQueryResults(t,
`SELECT name FROM system.crdb_internal.tables WHERE state = 'DROP' ORDER BY name`,
[][]string{
{"bank"},
{"comments"},
{"database_role_settings"},
{"external_connections"},
{"locations"},
{"privileges"},
{"role_id_seq"},
{"role_members"},
{"role_options"},
{"scheduled_jobs"},
{"settings"},
{"tenant_settings"},
{"ui"},
{"users"},
{"zones"},
},
)
} else {
sqlDBRestore.CheckQueryResults(t,
`SELECT name FROM system.crdb_internal.tables WHERE state = 'DROP' ORDER BY name`,
[][]string{
{"bank"},
{"comments"},
{"database_role_settings"},
{"external_connections"},
{"locations"},
{"privileges"},
{"role_id_seq"},
{"role_members"},
{"role_options"},
{"scheduled_jobs"},
{"settings"},
{"ui"},
{"users"},
{"zones"},
},
)
}
sqlDBRestore.CheckQueryResults(t,
`SELECT name FROM system.crdb_internal.tables WHERE state = 'DROP' ORDER BY name`,
[][]string{
{"bank"},
{"comments"},
{"database_role_settings"},
{"external_connections"},
{"locations"},
{"privileges"},
{"role_id_seq"},
{"role_members"},
{"role_options"},
{"scheduled_jobs"},
{"settings"},
{"tenant_settings"},
{"ui"},
{"users"},
{"zones"},
},
)
})

// This test retries the job (by injected a retry error) after restoring a
Expand Down Expand Up @@ -824,47 +802,26 @@ func TestClusterRestoreFailCleanup(t *testing.T) {
// Verify the failed RESTORE added some DROP tables.
// Note that the system tables here correspond to the temporary tables
// imported, not the system tables themselves.
if isBackupOfSystemTenant {
sqlDBRestore.CheckQueryResults(t,
`SELECT name FROM system.crdb_internal.tables WHERE state = 'DROP' ORDER BY name`,
[][]string{
{"bank"},
{"comments"},
{"database_role_settings"},
{"external_connections"},
{"locations"},
{"privileges"},
{"role_id_seq"},
{"role_members"},
{"role_options"},
{"scheduled_jobs"},
{"settings"},
{"tenant_settings"},
{"ui"},
{"users"},
{"zones"},
},
)
} else {
sqlDBRestore.CheckQueryResults(t,
`SELECT name FROM system.crdb_internal.tables WHERE state = 'DROP' ORDER BY name`,
[][]string{
{"bank"},
{"comments"},
{"database_role_settings"},
{"external_connections"},
{"locations"},
{"privileges"},
{"role_id_seq"},
{"role_members"},
{"role_options"},
{"scheduled_jobs"},
{"settings"},
{"ui"},
{"users"},
{"zones"},
})
}
sqlDBRestore.CheckQueryResults(t,
`SELECT name FROM system.crdb_internal.tables WHERE state = 'DROP' ORDER BY name`,
[][]string{
{"bank"},
{"comments"},
{"database_role_settings"},
{"external_connections"},
{"locations"},
{"privileges"},
{"role_id_seq"},
{"role_members"},
{"role_options"},
{"scheduled_jobs"},
{"settings"},
{"tenant_settings"},
{"ui"},
{"users"},
{"zones"},
},
)
})

t.Run("after offline tables", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant
Original file line number Diff line number Diff line change
Expand Up @@ -356,12 +356,12 @@ txn_id txn_fingerprint_id query implicit_txn session_id start_time end_tim
query ITTI
SELECT range_id, start_pretty, end_pretty, lease_holder FROM crdb_internal.ranges
----
68 /Tenant/10 /Tenant/11 1
69 /Tenant/10 /Tenant/11 1

query ITT
SELECT range_id, start_pretty, end_pretty FROM crdb_internal.ranges_no_leases
----
68 /Tenant/10 /Tenant/11
69 /Tenant/10 /Tenant/11

query IT
SELECT zone_id, target FROM crdb_internal.zones ORDER BY 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ skipif config multiregion-9node-3region-3azs-vec-off
query I retry
SELECT DISTINCT range_id FROM [SHOW RANGES FROM TABLE messages_rbr]
----
70
71

# Update does not fail when accessing all rows in messages_rbr because lookup
# join does not error out the lookup table in phase 1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ query T rowsort
SELECT message FROM [SHOW KV TRACE FOR SESSION]
WHERE message LIKE '%batch%' AND message LIKE '%Scan%'
----
r67: sending batch 4 Scan to (n1,s1):1
r68: sending batch 4 Scan to (n1,s1):1

# Regression test for #115377.
statement ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ ap-southeast-2 23
query TT
SELECT start_key, end_key FROM [SHOW RANGE FROM TABLE regional_by_row_table FOR ROW ('ap-southeast-2', 1)]
----
<before:/Table/65> …
<before:/Table/66> …

query TIIII
SELECT crdb_region, pk, pk2, a, b FROM regional_by_row_table
Expand Down Expand Up @@ -402,7 +402,7 @@ SELECT start_key, end_key, replicas, lease_holder FROM [SHOW RANGES FROM INDEX r
ORDER BY 1
----
start_key end_key replicas lease_holder
<before:/Table/65> …/"\x80"/0 {1} 1
<before:/Table/66> …/"\x80"/0 {1} 1
…/"\x80"/0 …/"\xc0"/0 {4} 4
…/"\xc0"/0 <after:/Table/110/5> {7} 7

Expand Down
7 changes: 7 additions & 0 deletions pkg/ccl/multiregionccl/multiregion_system_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func TestMrSystemDatabase(t *testing.T) {
{"TABLE system.public.replication_stats"},
{"TABLE system.public.reports_meta"},
{"TABLE system.public.scheduled_jobs"},
{"TABLE system.public.span_configurations"},
{"TABLE system.public.span_count"},
{"TABLE system.public.span_stats_buckets"},
{"TABLE system.public.span_stats_samples"},
Expand All @@ -294,6 +295,11 @@ func TestMrSystemDatabase(t *testing.T) {
{"TABLE system.public.statement_diagnostics_requests"},
{"TABLE system.public.statement_execution_insights"},
{"TABLE system.public.statement_statistics"},
{"TABLE system.public.task_payloads"},
{"TABLE system.public.tenant_settings"},
{"TABLE system.public.tenant_tasks"},
{"TABLE system.public.tenant_usage"},
{"TABLE system.public.tenants"},
{"TABLE system.public.transaction_activity"},
{"TABLE system.public.transaction_execution_insights"},
{"TABLE system.public.transaction_statistics"},
Expand All @@ -319,6 +325,7 @@ func TestMrSystemDatabase(t *testing.T) {
{"TABLE system.public.reports_meta"},
{"TABLE system.public.scheduled_jobs"},
{"TABLE system.public.span_configurations"},
{"TABLE system.public.span_count"},
{"TABLE system.public.span_stats_buckets"},
{"TABLE system.public.span_stats_samples"},
{"TABLE system.public.span_stats_tenant_boundaries"},
Expand Down
28 changes: 16 additions & 12 deletions pkg/ccl/spanconfigccl/spanconfigreconcilerccl/testdata/basic
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ upsert /Table/5{3-4} database system (host)
upsert /Table/5{4-5} database system (host)
upsert /Table/5{5-6} database system (host)
upsert /Table/5{6-7} database system (host)
upsert /Table/5{7-8} ttl_seconds=3600 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
upsert /Table/5{8-9} database system (host)
upsert /Table/5{7-8} database system (host)
upsert /Table/5{8-9} ttl_seconds=3600 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
upsert /Table/{59-60} database system (host)
upsert /Table/6{0-1} ttl_seconds=3600 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
upsert /Table/6{0-1} database system (host)
upsert /Table/6{1-2} ttl_seconds=3600 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
upsert /Table/6{2-3} database system (host)
upsert /Table/6{2-3} ttl_seconds=3600 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
upsert /Table/6{3-4} database system (host)
upsert /Table/6{4-5} database system (host)
upsert /Table/6{5-6} database system (host)
upsert /Table/6{6-7} database system (host)

exec-sql
CREATE DATABASE db;
Expand Down Expand Up @@ -119,15 +120,16 @@ state offset=47
/Table/5{4-5} database system (host)
/Table/5{5-6} database system (host)
/Table/5{6-7} database system (host)
/Table/5{7-8} ttl_seconds=3600 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
/Table/5{8-9} database system (host)
/Table/5{7-8} database system (host)
/Table/5{8-9} ttl_seconds=3600 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
/Table/{59-60} database system (host)
/Table/6{0-1} ttl_seconds=3600 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
/Table/6{0-1} database system (host)
/Table/6{1-2} ttl_seconds=3600 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
/Table/6{2-3} database system (host)
/Table/6{2-3} ttl_seconds=3600 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
/Table/6{3-4} database system (host)
/Table/6{4-5} database system (host)
/Table/6{5-6} database system (host)
/Table/6{6-7} database system (host)
/Table/10{6-7} num_replicas=7 num_voters=5
/Table/10{7-8} num_replicas=7
/Table/11{2-3} num_replicas=7
Expand Down Expand Up @@ -231,18 +233,20 @@ delete /Table/5{5-6}
upsert /Table/5{5-6} ttl_seconds=100 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
delete /Table/5{6-7}
upsert /Table/5{6-7} ttl_seconds=100 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
delete /Table/5{8-9}
upsert /Table/5{8-9} ttl_seconds=100 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
delete /Table/5{7-8}
upsert /Table/5{7-8} ttl_seconds=100 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
delete /Table/{59-60}
upsert /Table/{59-60} ttl_seconds=100 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
delete /Table/6{2-3}
upsert /Table/6{2-3} ttl_seconds=100 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
delete /Table/6{0-1}
upsert /Table/6{0-1} ttl_seconds=100 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
delete /Table/6{3-4}
upsert /Table/6{3-4} ttl_seconds=100 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
delete /Table/6{4-5}
upsert /Table/6{4-5} ttl_seconds=100 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
delete /Table/6{5-6}
upsert /Table/6{5-6} ttl_seconds=100 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true
delete /Table/6{6-7}
upsert /Table/6{6-7} ttl_seconds=100 ignore_strict_gc=true num_replicas=5 rangefeed_enabled=true

state offset=5 limit=42
----
Expand Down
Loading

0 comments on commit 6036490

Please sign in to comment.