Skip to content

Commit

Permalink
catkv: remove system objects from datadriven tet output
Browse files Browse the repository at this point in the history
Including the system tables in the output of the scan_all test case makes
the output hard to understand and causes very large test diffs when a
new system table is introduced.

Now we just summarize how many system objects there are, which should
reduce the chance of making mistakes when reviewing test changes.

Release note: None
  • Loading branch information
rafiss committed Dec 29, 2024
1 parent f9df57e commit 2f56c73
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 385 deletions.
1 change: 1 addition & 0 deletions pkg/sql/catalog/internal/catkv/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ go_test(
deps = [
":catkv",
"//pkg/base",
"//pkg/keys",
"//pkg/kv",
"//pkg/roachpb",
"//pkg/security/securityassets",
Expand Down
17 changes: 17 additions & 0 deletions pkg/sql/catalog/internal/catkv/catalog_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"testing"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/kv"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql"
Expand Down Expand Up @@ -430,13 +431,26 @@ func (h testHelper) catalogToYaml(c nstree.Catalog) interface{} {
ids.Add(id)
}
y := make(map[string]interface{})

var systemDatabaseEntry map[string]interface{}
var numSystemObjects int
for _, id := range ids.Ordered() {
j := m[id]
jm := make(map[string]interface{})
if id == keys.SystemDatabaseID {
systemDatabaseEntry = jm
}
if j.d != nil {
jm["descriptor"] = j.d.DescriptorType()
}
if j.ns != nil {
if j.ns.ParentID == keys.SystemDatabaseID {
if systemDatabaseEntry != nil {
// Skip this entry, it will be aggregated into the systemEntry.
numSystemObjects++
continue
}
}
jm["namespace"] = fmt.Sprintf("(%d, %d, %q)",
j.ns.ParentID, j.ns.ParentSchemaID, j.ns.Name)
}
Expand All @@ -460,6 +474,9 @@ func (h testHelper) catalogToYaml(c nstree.Catalog) interface{} {
}
y[fmt.Sprintf("%03d", id)] = jm
}
if systemDatabaseEntry != nil {
systemDatabaseEntry["num_objects"] = numSystemObjects
}
return y
}

Expand Down
191 changes: 3 additions & 188 deletions pkg/sql/catalog/internal/catkv/testdata/testdata_app
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ scan_namespace_for_databases
catalog:
"001":
namespace: (0, 0, "system")
num_objects: 0
"100":
namespace: (0, 0, "defaultdb")
"102":
Expand Down Expand Up @@ -221,194 +222,7 @@ catalog:
"001":
descriptor: database
namespace: (0, 0, "system")
"003":
descriptor: relation
namespace: (1, 29, "descriptor")
"004":
descriptor: relation
namespace: (1, 29, "users")
"005":
descriptor: relation
namespace: (1, 29, "zones")
"006":
descriptor: relation
namespace: (1, 29, "settings")
"007":
descriptor: relation
namespace: (1, 29, "descriptor_id_seq")
"008":
descriptor: relation
namespace: (1, 29, "tenants")
"009":
descriptor: relation
namespace: (1, 29, "region_liveness")
"011":
descriptor: relation
namespace: (1, 29, "lease")
"012":
descriptor: relation
namespace: (1, 29, "eventlog")
"013":
descriptor: relation
namespace: (1, 29, "rangelog")
"014":
descriptor: relation
namespace: (1, 29, "ui")
"015":
descriptor: relation
namespace: (1, 29, "jobs")
"019":
descriptor: relation
namespace: (1, 29, "web_sessions")
"020":
descriptor: relation
namespace: (1, 29, "table_statistics")
"021":
descriptor: relation
namespace: (1, 29, "locations")
"023":
descriptor: relation
namespace: (1, 29, "role_members")
"024":
descriptor: relation
namespace: (1, 29, "comments")
"025":
descriptor: relation
namespace: (1, 29, "replication_constraint_stats")
"026":
descriptor: relation
namespace: (1, 29, "replication_critical_localities")
"027":
descriptor: relation
namespace: (1, 29, "replication_stats")
"028":
descriptor: relation
namespace: (1, 29, "reports_meta")
"029":
namespace: (1, 0, "public")
"030":
descriptor: relation
namespace: (1, 29, "namespace")
"031":
descriptor: relation
namespace: (1, 29, "protected_ts_meta")
"032":
descriptor: relation
namespace: (1, 29, "protected_ts_records")
"033":
descriptor: relation
namespace: (1, 29, "role_options")
"034":
descriptor: relation
namespace: (1, 29, "statement_bundle_chunks")
"035":
descriptor: relation
namespace: (1, 29, "statement_diagnostics_requests")
"036":
descriptor: relation
namespace: (1, 29, "statement_diagnostics")
"037":
descriptor: relation
namespace: (1, 29, "scheduled_jobs")
"039":
descriptor: relation
namespace: (1, 29, "sqlliveness")
"040":
descriptor: relation
namespace: (1, 29, "migrations")
"041":
descriptor: relation
namespace: (1, 29, "join_tokens")
"042":
descriptor: relation
namespace: (1, 29, "statement_statistics")
"043":
descriptor: relation
namespace: (1, 29, "transaction_statistics")
"044":
descriptor: relation
namespace: (1, 29, "database_role_settings")
"045":
descriptor: relation
namespace: (1, 29, "tenant_usage")
"046":
descriptor: relation
namespace: (1, 29, "sql_instances")
"047":
descriptor: relation
namespace: (1, 29, "span_configurations")
"048":
descriptor: relation
namespace: (1, 29, "role_id_seq")
"050":
descriptor: relation
namespace: (1, 29, "tenant_settings")
"051":
descriptor: relation
namespace: (1, 29, "span_count")
"052":
descriptor: relation
namespace: (1, 29, "privileges")
"053":
descriptor: relation
namespace: (1, 29, "external_connections")
"054":
descriptor: relation
namespace: (1, 29, "job_info")
"055":
descriptor: relation
namespace: (1, 29, "span_stats_unique_keys")
"056":
descriptor: relation
namespace: (1, 29, "span_stats_buckets")
"057":
descriptor: relation
namespace: (1, 29, "span_stats_samples")
"058":
descriptor: relation
namespace: (1, 29, "span_stats_tenant_boundaries")
"059":
descriptor: relation
namespace: (1, 29, "task_payloads")
"060":
descriptor: relation
namespace: (1, 29, "tenant_tasks")
"061":
descriptor: relation
namespace: (1, 29, "statement_activity")
"062":
descriptor: relation
namespace: (1, 29, "transaction_activity")
"063":
descriptor: relation
namespace: (1, 29, "tenant_id_seq")
"064":
descriptor: relation
namespace: (1, 29, "mvcc_statistics")
"065":
descriptor: relation
namespace: (1, 29, "transaction_execution_insights")
"066":
descriptor: relation
namespace: (1, 29, "statement_execution_insights")
"067":
descriptor: relation
namespace: (1, 29, "table_metadata")
"068":
descriptor: relation
namespace: (1, 29, "job_progress")
"069":
descriptor: relation
namespace: (1, 29, "job_progress_history")
"070":
descriptor: relation
namespace: (1, 29, "job_status")
"071":
descriptor: relation
namespace: (1, 29, "job_message")
"072":
descriptor: relation
namespace: (1, 29, "prepared_transactions")
num_objects: 63
"100":
comments:
database: this is the default database
Expand Down Expand Up @@ -569,6 +383,7 @@ scan_all_comments_nil_db
catalog:
"001":
namespace: (0, 0, "system")
num_objects: 0
"100":
comments:
database: this is the default database
Expand Down
Loading

0 comments on commit 2f56c73

Please sign in to comment.