Skip to content

Commit cee475f

Browse files
committed
sql: change SetZoneConfig to return type Ack
This commit changes the return type for `tree.SetZoneConfig` to `Ack` from `RowsAffected`. This mirrors similar statements, and the row count has been broken (always zero) ever since this statement was implemented in the declarative schema changer, anyway. Removing the need to track row count allows a few related functions to be simplified. Epic: None Release note: None
1 parent 70ad6fb commit cee475f

File tree

8 files changed

+25
-44
lines changed

8 files changed

+25
-44
lines changed

pkg/cli/interactive_tests/test_missing_log_output.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ interrupt_and_wait
5656
# Disable replication so as to avoid spurious purgatory errors.
5757
start_server $argv
5858
send "$argv sql --insecure -e \"ALTER RANGE default CONFIGURE ZONE USING num_replicas = 1\"\r"
59-
eexpect {CONFIGURE ZONE [0-9]}
59+
eexpect "CONFIGURE ZONE"
6060
eexpect ":/# "
6161
stop_server $argv
6262

pkg/sql/database_region_change_finalizer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (r *databaseRegionChangeFinalizer) preDrop(ctx context.Context, txn descs.T
115115
return err
116116
}
117117
for _, update := range zoneConfigUpdates {
118-
if _, err := writeZoneConfigUpdate(
118+
if err = writeZoneConfigUpdate(
119119
ctx, txn,
120120
r.localPlanner.ExtendedEvalContext().Tracing.KVTracingEnabled(),
121121
update,

pkg/sql/plan.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ var _ planNode = &zeroNode{}
272272
var _ planNodeFastPath = &deleteRangeNode{}
273273
var _ planNodeFastPath = &rowCountNode{}
274274
var _ planNodeFastPath = &serializeNode{}
275-
var _ planNodeFastPath = &setZoneConfigNode{}
276275
var _ planNodeFastPath = &controlJobsNode{}
277276
var _ planNodeFastPath = &controlSchedulesNode{}
278277

pkg/sql/region_util.go

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -534,8 +534,7 @@ func ApplyZoneConfigForMultiRegionTable(
534534
if update == nil || err != nil {
535535
return err
536536
}
537-
_, err = writeZoneConfigUpdate(ctx, txn, kvTrace, update)
538-
return err
537+
return writeZoneConfigUpdate(ctx, txn, kvTrace, update)
539538
}
540539

541540
// generateAndValidateZoneConfigForMultiRegionDatabase returns a validated
@@ -654,15 +653,14 @@ func applyZoneConfigForMultiRegionDatabase(
654653
)
655654
// If the new zone config is the same as a blank zone config, delete it.
656655
if newZoneConfig.Equal(zonepb.NewZoneConfig()) {
657-
_, err = writeZoneConfigUpdate(
656+
return writeZoneConfigUpdate(
658657
ctx,
659658
txn,
660659
kvTrace,
661660
&zoneConfigUpdate{id: dbID, zoneConfig: nil},
662661
)
663-
return err
664662
}
665-
if _, err := writeZoneConfig(
663+
return writeZoneConfig(
666664
ctx,
667665
txn,
668666
dbID,
@@ -672,10 +670,7 @@ func applyZoneConfigForMultiRegionDatabase(
672670
execConfig,
673671
false, /* hasNewSubzones */
674672
kvTrace,
675-
); err != nil {
676-
return err
677-
}
678-
return nil
673+
)
679674
}
680675

681676
type refreshZoneConfigOptions struct {
@@ -787,7 +782,7 @@ func (p *planner) refreshZoneConfigsForTablesWithValidation(
787782
// TODO(janexing): if any write failed, do we roll back? Same question to the
788783
// original p.forEachMutableTableInDatabase().
789784
for _, update := range zoneConfigUpdates {
790-
if _, err := writeZoneConfigUpdate(
785+
if err = writeZoneConfigUpdate(
791786
ctx,
792787
p.InternalSQLTxn(),
793788
p.ExtendedEvalContext().Tracing.KVTracingEnabled(),

pkg/sql/schema_changer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2256,7 +2256,7 @@ func maybeUpdateZoneConfigsForPKChange(
22562256

22572257
// Write the zone back. This call regenerates the index spans that apply
22582258
// to each partition in the index.
2259-
_, err = writeZoneConfig(
2259+
err = writeZoneConfig(
22602260
ctx, txn, table.ID, table,
22612261
zoneWithRaw.ZoneConfigProto(), zoneWithRaw.GetRawBytesInStorage(),
22622262
execCfg, false, kvTrace,

pkg/sql/sem/tree/stmt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1690,7 +1690,7 @@ func (*SetTracing) StatementTag() string { return "SET TRACING" }
16901690
func (*SetTracing) observerStatement() {}
16911691

16921692
// StatementReturnType implements the Statement interface.
1693-
func (*SetZoneConfig) StatementReturnType() StatementReturnType { return RowsAffected }
1693+
func (*SetZoneConfig) StatementReturnType() StatementReturnType { return Ack }
16941694

16951695
// StatementType implements the Statement interface.
16961696
func (*SetZoneConfig) StatementType() StatementType { return TypeDCL }

pkg/sql/set_zone_config.go

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ type setZoneConfigNode struct {
4444
yamlConfig tree.TypedExpr
4545
options map[tree.Name]zone.OptionValue
4646
setDefault bool
47-
48-
run setZoneConfigRun
4947
}
5048

5149
func (p *planner) getUpdatedZoneConfigYamlConfig(
@@ -230,11 +228,6 @@ func checkPrivilegeForSetZoneConfig(ctx context.Context, p *planner, zs tree.Zon
230228
[]privilege.Kind{privilege.ZONECONFIG, privilege.CREATE}, string(tableDesc.DescriptorType()), tableDesc.GetName())
231229
}
232230

233-
// setZoneConfigRun contains the run-time state of setZoneConfigNode during local execution.
234-
type setZoneConfigRun struct {
235-
numAffected int
236-
}
237-
238231
// ReadingOwnWrites implements the planNodeReadingOwnWrites interface.
239232
// This is because CONFIGURE ZONE performs multiple KV operations on descriptors
240233
// and expects to see its own writes.
@@ -747,7 +740,7 @@ func (n *setZoneConfigNode) startExec(params runParams) error {
747740
zoneToWrite := partialZone
748741
// TODO(ajwerner): This is extremely fragile because we accept a nil table
749742
// all the way down here.
750-
n.run.numAffected, err = writeZoneConfig(
743+
err = writeZoneConfig(
751744
params.ctx,
752745
params.p.InternalSQLTxn(),
753746
targetID,
@@ -796,8 +789,6 @@ func (n *setZoneConfigNode) Next(runParams) (bool, error) { return false, nil }
796789
func (n *setZoneConfigNode) Values() tree.Datums { return nil }
797790
func (*setZoneConfigNode) Close(context.Context) {}
798791

799-
func (n *setZoneConfigNode) FastPathResults() (int, bool) { return n.run.numAffected, true }
800-
801792
type nodeGetter func(context.Context, *serverpb.NodesRequest) (*serverpb.NodesResponse, error)
802793
type regionsGetter func(context.Context) (*serverpb.RegionsResponse, error)
803794

@@ -1058,41 +1049,38 @@ func writeZoneConfig(
10581049
execCfg *ExecutorConfig,
10591050
hasNewSubzones bool,
10601051
kvTrace bool,
1061-
) (numAffected int, err error) {
1052+
) error {
10621053
update, err := prepareZoneConfigWrites(ctx, execCfg, targetID, table, zone, expectedExistingRawBytes, hasNewSubzones)
10631054
if err != nil {
1064-
return 0, err
1055+
return err
10651056
}
10661057
return writeZoneConfigUpdate(ctx, txn, kvTrace, update)
10671058
}
10681059

10691060
func writeZoneConfigUpdate(
10701061
ctx context.Context, txn descs.Txn, kvTrace bool, update *zoneConfigUpdate,
1071-
) (numAffected int, err error) {
1062+
) error {
10721063
b := txn.KV().NewBatch()
10731064
if update.zoneConfig == nil {
1074-
err = txn.Descriptors().DeleteZoneConfigInBatch(ctx, kvTrace, b, update.id)
1065+
err := txn.Descriptors().DeleteZoneConfigInBatch(ctx, kvTrace, b, update.id)
1066+
if err != nil {
1067+
return err
1068+
}
10751069
} else {
1076-
numAffected = 1
1077-
err = txn.Descriptors().WriteZoneConfigToBatch(ctx, kvTrace, b, update.id, update.zoneConfig)
1078-
}
1079-
if err != nil {
1080-
return 0, err
1070+
err := txn.Descriptors().WriteZoneConfigToBatch(ctx, kvTrace, b, update.id, update.zoneConfig)
1071+
if err != nil {
1072+
return err
1073+
}
10811074
}
10821075

10831076
if err := txn.KV().Run(ctx, b); err != nil {
1084-
return 0, err
1077+
return err
10851078
}
10861079
r := b.Results[0]
10871080
if r.Err != nil {
10881081
panic("run succeeded even through the result has an error")
10891082
}
1090-
// We don't really care how many keys are affected since this function always
1091-
// write one single zone config.
1092-
if len(r.Keys) > 0 {
1093-
numAffected = 1
1094-
}
1095-
return numAffected, err
1083+
return nil
10961084
}
10971085

10981086
// RemoveIndexZoneConfigs removes the zone configurations for some
@@ -1139,7 +1127,7 @@ func RemoveIndexZoneConfigs(
11391127

11401128
if zcRewriteNecessary {
11411129
// Ignore CCL required error to allow schema change to progress.
1142-
_, err = writeZoneConfig(
1130+
err = writeZoneConfig(
11431131
ctx, txn, tableDesc.GetID(), tableDesc, zone,
11441132
zoneWithRaw.GetRawBytesInStorage(), execCfg,
11451133
false /* hasNewSubzones */, kvTrace,

pkg/sql/zone_config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,5 @@ func deleteRemovedPartitionZoneConfigs(
512512
if update == nil || err != nil {
513513
return err
514514
}
515-
_, err = writeZoneConfigUpdate(ctx, txn, kvTrace, update)
516-
return err
515+
return writeZoneConfigUpdate(ctx, txn, kvTrace, update)
517516
}

0 commit comments

Comments
 (0)