Skip to content

Commit

Permalink
spanconfig: move FullTranslate back under pkg/spanconfig
Browse files Browse the repository at this point in the history
Release note: None
  • Loading branch information
irfansharif committed Dec 6, 2021
1 parent 7a3bf64 commit 8bfbe7f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ go_test(
"//pkg/security/securitytest",
"//pkg/server",
"//pkg/spanconfig",
"//pkg/spanconfig/spanconfigsqltranslator",
"//pkg/spanconfig/spanconfigtestutils",
"//pkg/spanconfig/spanconfigtestutils/spanconfigtestcluster",
"//pkg/sql/catalog/descpb",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/cockroachdb/cockroach/pkg/config/zonepb"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/spanconfig"
"github.com/cockroachdb/cockroach/pkg/spanconfig/spanconfigsqltranslator"
"github.com/cockroachdb/cockroach/pkg/spanconfig/spanconfigtestutils"
"github.com/cockroachdb/cockroach/pkg/spanconfig/spanconfigtestutils/spanconfigtestcluster"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
Expand Down Expand Up @@ -156,7 +155,7 @@ func TestDataDriven(t *testing.T) {

case "full-translate":
sqlTranslator := tenant.SpanConfigSQLTranslator().(spanconfig.SQLTranslator)
entries, _, err := spanconfigsqltranslator.FullTranslate(ctx, sqlTranslator)
entries, _, err := spanconfig.FullTranslate(ctx, sqlTranslator)
require.NoError(t, err)

sort.Slice(entries, func(i, j int) bool {
Expand Down
1 change: 1 addition & 0 deletions pkg/spanconfig/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/base",
"//pkg/keys",
"//pkg/roachpb:with-mocks",
"//pkg/sql/catalog",
"//pkg/sql/catalog/descpb",
Expand Down
13 changes: 13 additions & 0 deletions pkg/spanconfig/spanconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package spanconfig
import (
"context"

"github.com/cockroachdb/cockroach/pkg/keys"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
"github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb"
Expand Down Expand Up @@ -105,6 +106,18 @@ type SQLTranslator interface {
Translate(ctx context.Context, ids descpb.IDs) ([]roachpb.SpanConfigEntry, hlc.Timestamp, error)
}

// FullTranslate translates the entire SQL zone configuration state to the span
// configuration state. The timestamp at which such a translation is valid is
// also returned.
func FullTranslate(
ctx context.Context, s SQLTranslator,
) ([]roachpb.SpanConfigEntry, hlc.Timestamp, error) {
// As RANGE DEFAULT is the root of all zone configurations (including other
// named zones for the system tenant), we can construct the entire span
// configuration state by starting from RANGE DEFAULT.
return s.Translate(ctx, descpb.IDs{keys.RootNamespaceID})
}

// SQLWatcher watches for events on system.zones and system.descriptors.
type SQLWatcher interface {
// WatchForSQLUpdates watches for updates to zones and descriptors starting
Expand Down
12 changes: 0 additions & 12 deletions pkg/spanconfig/spanconfigsqltranslator/sqltranslator.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,3 @@ func (s *SQLTranslator) findDescendantLeafIDsForNamedZone(
}
return descendantIDs, nil
}

// FullTranslate translates the entire SQL zone configuration state to the
// span configuration state. The timestamp at which such a translation is valid
// is also returned.
func FullTranslate(
ctx context.Context, s spanconfig.SQLTranslator,
) ([]roachpb.SpanConfigEntry, hlc.Timestamp, error) {
// As RANGE DEFAULT is the root of all zone configurations (including
// other named zones for the system tenant), we can construct the entire
// span configuration state by starting from RANGE DEFAULT.
return s.Translate(ctx, descpb.IDs{keys.RootNamespaceID})
}

0 comments on commit 8bfbe7f

Please sign in to comment.