Skip to content

Commit

Permalink
sqlerrors: move gloval var errNoZoneConfigApplies into sqlerrors package
Browse files Browse the repository at this point in the history
This commit is a mechnical change that moves the gloval variable
`errNoZoneConfigApplies` from package `sql` to package `sqlerrors`, as
it will be used by the DSC when we support zone config in it.

Informs: cockroachdb#117574
Release note: None
  • Loading branch information
Xiang-Gu authored and annrpom committed May 15, 2024
1 parent 28bce06 commit 2906783
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions pkg/sql/set_zone_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,16 +467,16 @@ func (n *setZoneConfigNode) startExec(params runParams) error {
// default (whichever applies -- a database if targetID is a table,
// default if targetID is a database, etc.). For this, we use the last
// parameter getInheritedDefault to GetZoneConfigInTxn().
// These zones are only used for validations. The merged zone is will
// These zones are only used for validations. The merged zone will
// not be written.
_, completeZone, completeSubzone, err := GetZoneConfigInTxn(
params.ctx, params.p.txn, params.p.Descriptors(), targetID, index, partition, n.setDefault,
)

if errors.Is(err, errNoZoneConfigApplies) {
if errors.Is(err, sqlerrors.ErrNoZoneConfigApplies) {
// No zone config yet.
//
// GetZoneConfigInTxn will fail with errNoZoneConfigApplies when
// GetZoneConfigInTxn will fail with ErrNoZoneConfigApplies when
// the target ID is not a database object, i.e. one of the system
// ranges (liveness, meta, etc.), and did not have a zone config
// already.
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/show_zone_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
"github.com/cockroachdb/cockroach/pkg/sql/lexbase"
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
"github.com/cockroachdb/cockroach/pkg/sql/sqlerrors"
"github.com/cockroachdb/cockroach/pkg/sql/types"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/errors"
Expand Down Expand Up @@ -126,7 +127,7 @@ func getShowZoneConfigRow(
zoneID, zone, subzone, err := GetZoneConfigInTxn(
ctx, p.txn, p.Descriptors(), targetID, index, partition, false, /* getInheritedDefault */
)
if errors.Is(err, errNoZoneConfigApplies) {
if errors.Is(err, sqlerrors.ErrNoZoneConfigApplies) {
// TODO(benesch): This shouldn't be the caller's responsibility;
// GetZoneConfigInTxn should just return the default zone config if no zone
// config applies.
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/sqlerrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -479,3 +479,5 @@ var (
ErrNoFunction = pgerror.New(pgcode.InvalidName, "no function specified")
ErrNoMatch = pgerror.New(pgcode.UndefinedObject, "no object matched")
)

var ErrNoZoneConfigApplies = errors.New("no zone config applies")
6 changes: 2 additions & 4 deletions pkg/sql/zone_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ func init() {
config.ZoneConfigHook = zoneConfigHook
}

var errNoZoneConfigApplies = errors.New("no zone config applies")

// getZoneConfig recursively looks up entries in system.zones until an
// entry that applies to the object with the specified id is
// found. Returns the ID of the matching zone, its zone config, and an
Expand Down Expand Up @@ -119,7 +117,7 @@ func getZoneConfig(
}

// No descriptor or not a table.
return 0, nil, 0, nil, errNoZoneConfigApplies
return 0, nil, 0, nil, sqlerrors.ErrNoZoneConfigApplies
}

// completeZoneConfig takes a zone config pointer and fills in the
Expand Down Expand Up @@ -184,7 +182,7 @@ func zoneConfigHook(
false, /* getInheritedDefault */
mayBeTable,
)
if errors.Is(err, errNoZoneConfigApplies) {
if errors.Is(err, sqlerrors.ErrNoZoneConfigApplies) {
return nil, nil, true, nil
} else if err != nil {
return nil, nil, false, err
Expand Down

0 comments on commit 2906783

Please sign in to comment.