Skip to content

Commit

Permalink
schemachanger: add old zone config in zone config logs in DSC
Browse files Browse the repository at this point in the history
This patch fills the `ResolvedOldConfig` field in
`eventpb.SetZoneConfig` to log the old zone configuration
in the declarative schema changer.

Informs: #127176

Release note: None
  • Loading branch information
annrpom committed Oct 17, 2024
1 parent 2ce1047 commit d9bd326
Show file tree
Hide file tree
Showing 27 changed files with 193 additions and 68 deletions.
3 changes: 3 additions & 0 deletions docs/generated/eventlog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3380,6 +3380,9 @@ An event of type `remove_zone_config` is recorded when a zone config is removed.
An event of type `set_zone_config` is recorded when a zone config is changed.


| Field | Description | Sensitive |
|--|--|--|
| `ResolvedOldConfig` | The string representation of the resolved old zone config. This is not necessarily the same as the zone config that was previously set -- as it includes the resolved values of the zone config options. In other words, a zone config that hasn't been properly "set" yet (and inherits from its parent) will have a resolved_old_config that has details of the values it inherits from its parent. This is particularly useful to get a proper diff between the old and new zone config. | yes |


#### Common fields
Expand Down
7 changes: 7 additions & 0 deletions pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/ccl/logictestccl/tests/fakedist-disk/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/ccl/logictestccl/tests/fakedist-vec-off/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/ccl/logictestccl/tests/fakedist/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/ccl/logictestccl/tests/local-mixed-24.1/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/ccl/logictestccl/tests/local-mixed-24.2/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/ccl/logictestccl/tests/local-vec-off/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/ccl/logictestccl/tests/local/generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ ALTER INDEX t@foo CONFIGURE ZONE USING num_replicas = 7, gc.ttlseconds = 10000;
begin transaction #1
# begin StatementPhase
checking for feature: CONFIGURE ZONE
write *eventpb.AlterTable to event log:
mutationId: 1
write *eventpb.SetZoneConfig to event log:
config:
options:
- '"gc.ttlseconds" = 10000'
- num_replicas = 7
target: INDEX defaultdb.public.t@foo
resolvedOldConfig: 'range_min_bytes:134217728 range_max_bytes:536870912 gc:<ttl_seconds:14400 > num_replicas:5 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false '
sql:
descriptorId: 104
statement: ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹foo› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›
tag: CONFIGURE ZONE
user: root
tableName: defaultdb.public.t
## StatementPhase stage 1 of 1 with 1 MutationType op
upsert zone config for #104
# end StatementPhase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,36 +13,45 @@ ALTER INDEX t@foo CONFIGURE ZONE USING num_replicas = 10;
begin transaction #1
# begin StatementPhase
checking for feature: CONFIGURE ZONE
write *eventpb.AlterTable to event log:
mutationId: 1
write *eventpb.SetZoneConfig to event log:
config:
options:
- num_replicas = 7
target: INDEX defaultdb.public.t@foo
resolvedOldConfig: 'range_min_bytes:134217728 range_max_bytes:536870912 gc:<ttl_seconds:14400 > num_replicas:5 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false '
sql:
descriptorId: 104
statement: ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹foo› CONFIGURE ZONE USING ‹num_replicas› = ‹7›
tag: CONFIGURE ZONE
user: root
tableName: defaultdb.public.t
## StatementPhase stage 1 of 1 with 1 MutationType op
upsert zone config for #104
checking for feature: CONFIGURE ZONE
write *eventpb.AlterTable to event log:
mutationId: 1
write *eventpb.SetZoneConfig to event log:
config:
options:
- '"gc.ttlseconds" = 10000'
target: INDEX defaultdb.public.t@foo
resolvedOldConfig: 'range_min_bytes:134217728 range_max_bytes:536870912 gc:<ttl_seconds:14400 > num_replicas:7 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false '
sql:
descriptorId: 104
statement: ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹foo› CONFIGURE ZONE USING ‹"gc.ttlseconds"› = ‹10000›
tag: CONFIGURE ZONE
user: root
tableName: defaultdb.public.t
## StatementPhase stage 1 of 1 with 1 MutationType op
upsert zone config for #104
checking for feature: CONFIGURE ZONE
write *eventpb.AlterTable to event log:
mutationId: 1
write *eventpb.SetZoneConfig to event log:
config:
options:
- num_replicas = 10
target: INDEX defaultdb.public.t@foo
resolvedOldConfig: 'range_min_bytes:134217728 range_max_bytes:536870912 gc:<ttl_seconds:10000 > num_replicas:7 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false '
sql:
descriptorId: 104
statement: ALTER INDEX ‹defaultdb›.‹public›.‹t›@‹foo› CONFIGURE ZONE USING ‹num_replicas› = ‹10›
tag: CONFIGURE ZONE
user: root
tableName: defaultdb.public.t
## StatementPhase stage 1 of 1 with 1 MutationType op
upsert zone config for #104
# end StatementPhase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ ALTER PARTITION p1 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 7, gc.t
begin transaction #1
# begin StatementPhase
checking for feature: CONFIGURE ZONE
write *eventpb.AlterTable to event log:
mutationId: 1
write *eventpb.SetZoneConfig to event log:
config:
options:
- '"gc.ttlseconds" = 10000'
- num_replicas = 7
target: PARTITION p1 OF INDEX defaultdb.public.t@t_pkey
resolvedOldConfig: 'inherited_constraints:false null_voter_constraints_is_empty:false inherited_lease_preferences:false '
sql:
descriptorId: 104
statement: ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹7›, ‹"gc.ttlseconds"› = ‹10000›
tag: CONFIGURE ZONE
user: root
tableName: defaultdb.public.t
## StatementPhase stage 1 of 1 with 1 MutationType op
upsert zone config for #104
# end StatementPhase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,59 @@ ALTER PARTITION p3 OF INDEX t@t_pkey CONFIGURE ZONE USING num_replicas = 10;
begin transaction #1
# begin StatementPhase
checking for feature: CONFIGURE ZONE
write *eventpb.AlterTable to event log:
mutationId: 1
write *eventpb.SetZoneConfig to event log:
config:
options:
- num_replicas = 7
target: PARTITION p3 OF INDEX defaultdb.public.t@t_pkey
resolvedOldConfig: 'inherited_constraints:false null_voter_constraints_is_empty:false inherited_lease_preferences:false '
sql:
descriptorId: 104
statement: ALTER PARTITION ‹p3› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹7›
tag: CONFIGURE ZONE
user: root
tableName: defaultdb.public.t
## StatementPhase stage 1 of 1 with 1 MutationType op
upsert zone config for #104
checking for feature: CONFIGURE ZONE
write *eventpb.AlterTable to event log:
mutationId: 1
write *eventpb.SetZoneConfig to event log:
config:
options:
- '"gc.ttlseconds" = 10000'
target: PARTITION p3 OF INDEX defaultdb.public.t@t_pkey
resolvedOldConfig: 'inherited_constraints:false null_voter_constraints_is_empty:false inherited_lease_preferences:false '
sql:
descriptorId: 104
statement: ALTER PARTITION ‹p3› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹"gc.ttlseconds"› = ‹10000›
tag: CONFIGURE ZONE
user: root
tableName: defaultdb.public.t
## StatementPhase stage 1 of 1 with 1 MutationType op
upsert zone config for #104
checking for feature: CONFIGURE ZONE
write *eventpb.AlterTable to event log:
mutationId: 1
write *eventpb.SetZoneConfig to event log:
config:
options:
- '"gc.ttlseconds" = 12000'
target: PARTITION p1 OF INDEX defaultdb.public.t@idx
resolvedOldConfig: 'inherited_constraints:false null_voter_constraints_is_empty:false inherited_lease_preferences:false '
sql:
descriptorId: 104
statement: ALTER PARTITION ‹p1› OF INDEX ‹defaultdb›.‹public›.‹t›@‹idx› CONFIGURE ZONE USING ‹"gc.ttlseconds"› = ‹12000›
tag: CONFIGURE ZONE
user: root
tableName: defaultdb.public.t
## StatementPhase stage 1 of 1 with 1 MutationType op
upsert zone config for #104
checking for feature: CONFIGURE ZONE
write *eventpb.AlterTable to event log:
mutationId: 1
write *eventpb.SetZoneConfig to event log:
config:
options:
- num_replicas = 10
target: PARTITION p3 OF INDEX defaultdb.public.t@t_pkey
resolvedOldConfig: 'inherited_constraints:false null_voter_constraints_is_empty:false inherited_lease_preferences:false '
sql:
descriptorId: 104
statement: ALTER PARTITION ‹p3› OF INDEX ‹defaultdb›.‹public›.‹t›@‹t_pkey› CONFIGURE ZONE USING ‹num_replicas› = ‹10›
tag: CONFIGURE ZONE
user: root
tableName: defaultdb.public.t
## StatementPhase stage 1 of 1 with 1 MutationType op
upsert zone config for #104
# end StatementPhase
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/logictest/testdata/logic_test/event_log
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,10 @@ ORDER BY "timestamp", info
1 {"ApplicationName": "$ internal-set-SQLStatsTables-TTL", "EventType": "set_zone_config", "Options": ["\"gc.ttlseconds\" = 3600"], "PlaceholderValues": ["3600"], "ResolvedOldConfig": "range_min_bytes:134217728 range_max_bytes:536870912 gc:<ttl_seconds:14400 > num_replicas:5 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ", "Tag": "CONFIGURE ZONE", "Target": "TABLE system.public.transaction_statistics", "User": "node"}
1 {"ApplicationName": "$ internal-set-SQLStatsTables-TTL", "EventType": "set_zone_config", "Options": ["\"gc.ttlseconds\" = 3600"], "PlaceholderValues": ["3600"], "ResolvedOldConfig": "range_min_bytes:134217728 range_max_bytes:536870912 gc:<ttl_seconds:14400 > num_replicas:5 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ", "Tag": "CONFIGURE ZONE", "Target": "TABLE system.public.statement_activity", "User": "node"}
1 {"ApplicationName": "$ internal-set-SQLStatsTables-TTL", "EventType": "set_zone_config", "Options": ["\"gc.ttlseconds\" = 3600"], "PlaceholderValues": ["3600"], "ResolvedOldConfig": "range_min_bytes:134217728 range_max_bytes:536870912 gc:<ttl_seconds:14400 > num_replicas:5 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ", "Tag": "CONFIGURE ZONE", "Target": "TABLE system.public.transaction_activity", "User": "node"}
1 {"EventType": "set_zone_config", "Options": ["range_max_bytes = 67108865", "range_min_bytes = 16777216"], "Tag": "CONFIGURE ZONE", "Target": "DATABASE test", "User": "root"}
1 {"EventType": "set_zone_config", "Options": ["range_max_bytes = 67108865", "range_min_bytes = 16777216"], "Tag": "CONFIGURE ZONE", "Target": "TABLE test.public.a", "User": "root"}
1 {"EventType": "set_zone_config", "Options": ["\"gc.ttlseconds\" = 13000"], "Tag": "CONFIGURE ZONE", "Target": "INDEX test.public.a@a_pkey", "User": "root"}
1 {"EventType": "set_zone_config", "Options": ["\"gc.ttlseconds\" = 15000"], "Tag": "CONFIGURE ZONE", "Target": "INDEX test.public.a@bar", "User": "root"}
1 {"EventType": "set_zone_config", "Options": ["range_max_bytes = 67108865", "range_min_bytes = 16777216"], "ResolvedOldConfig": "range_min_bytes:134217728 range_max_bytes:536870912 gc:<ttl_seconds:14400 > num_replicas:3 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ", "Tag": "CONFIGURE ZONE", "Target": "DATABASE test", "User": "root"}
1 {"EventType": "set_zone_config", "Options": ["range_max_bytes = 67108865", "range_min_bytes = 16777216"], "ResolvedOldConfig": "range_min_bytes:134217728 range_max_bytes:536870912 gc:<ttl_seconds:14400 > num_replicas:3 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ", "Tag": "CONFIGURE ZONE", "Target": "TABLE test.public.a", "User": "root"}
1 {"EventType": "set_zone_config", "Options": ["\"gc.ttlseconds\" = 13000"], "ResolvedOldConfig": "range_min_bytes:134217728 range_max_bytes:536870912 gc:<ttl_seconds:14400 > num_replicas:3 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ", "Tag": "CONFIGURE ZONE", "Target": "INDEX test.public.a@a_pkey", "User": "root"}
1 {"EventType": "set_zone_config", "Options": ["\"gc.ttlseconds\" = 15000"], "ResolvedOldConfig": "range_min_bytes:134217728 range_max_bytes:536870912 gc:<ttl_seconds:14400 > num_replicas:3 inherited_constraints:false null_voter_constraints_is_empty:true inherited_lease_preferences:false ", "Tag": "CONFIGURE ZONE", "Target": "INDEX test.public.a@bar", "User": "root"}

skipif config 3node-tenant-default-configs
query IT
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/schemachanger/scbuild/event_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,15 +465,18 @@ func (pb payloadBuilder) build(b buildCtx) logpb.EventPayload {
*scpb.PartitionZoneConfig:
if pb.TargetStatus == scpb.Status_PUBLIC {
var zcDetails eventpb.CommonZoneConfigDetails
var oldConfig string
if pb.maybePayload != nil {
payload := pb.maybePayload.(*eventpb.SetZoneConfig)
zcDetails = eventpb.CommonZoneConfigDetails{
Target: payload.Target,
Options: payload.Options,
}
oldConfig = payload.ResolvedOldConfig
}
return &eventpb.SetZoneConfig{
CommonZoneConfigDetails: zcDetails,
ResolvedOldConfig: oldConfig,
}
}
case *scpb.Trigger:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ func SetZoneConfig(b BuildCtx, n *tree.SetZoneConfig) {
sqltelemetry.SchemaChangeAlterCounterWithExtra(zs.TelemetryName(), "configure_zone"),
)

if err = zco.applyZoneConfig(b, n, copyFromParentList, setters); err != nil {
oldZone, err := zco.applyZoneConfig(b, n, copyFromParentList, setters)
if err != nil {
panic(err)
}

Expand All @@ -87,7 +88,8 @@ func SetZoneConfig(b BuildCtx, n *tree.SetZoneConfig) {
Target: tree.AsString(&n.ZoneSpecifier),
Options: optionsStr,
}
info := &eventpb.SetZoneConfig{CommonZoneConfigDetails: eventDetails}
info := &eventpb.SetZoneConfig{CommonZoneConfigDetails: eventDetails,
ResolvedOldConfig: oldZone.String()}
b.LogEventForExistingPayload(elem, info)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ func (dzo *databaseZoneConfigObj) applyZoneConfig(
n *tree.SetZoneConfig,
copyFromParentList []tree.Name,
setters []func(c *zonepb.ZoneConfig),
) error {
partialZone, err := prepareZoneConfig(b, n, copyFromParentList, setters, dzo)
) (*zonepb.ZoneConfig, error) {
oldZone, partialZone, err := prepareZoneConfig(b, n, copyFromParentList, setters, dzo)
dzo.setZoneConfigToWrite(partialZone)
return err
return oldZone, err
}
Loading

0 comments on commit d9bd326

Please sign in to comment.