Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opgen: added a bool field in struct opgen.transition #90719

Merged
merged 1 commit into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pkg/sql/schemachanger/scplan/internal/opgen/op_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,14 @@ func (r *registry) buildGraph(
// InitialStatus returns the status at the source of an op-edge path.
func InitialStatus(e scpb.Element, target scpb.Status) scpb.Status {
if t, found := findTarget(e, target); found {
return t.transitions[0].from
for _, tstn := range t.transitions {
if tstn.isEquiv {
continue
}
return tstn.from
}
// All transitions results from `equiv(xxx)` specs. Return `to` of the last transition.
return target
}
return scpb.Status_UNKNOWN
}
Expand Down
18 changes: 18 additions & 0 deletions pkg/sql/schemachanger/scplan/internal/opgen/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type transition struct {
canFail bool
ops opsFunc
opType scop.Type
isEquiv bool // True if this transition comes from a `equiv` spec.
}

func (t transition) OpType() scop.Type {
Expand Down Expand Up @@ -81,6 +82,20 @@ func makeTarget(e scpb.Element, spec targetSpec) (t target, err error) {
return t, nil
}

// makeTransitions constructs a slice of transitions from the transition spec, as specified in `opgen_xx.go` file.
// An example can nicely explain how it works.
// Example 1:
//
// Input: toAbsent(PUBLIC, equiv(VALIDATED), to(WRITE_ONLY), to(ABSENT))
// Output: [VALIDATED, PUBLIC], [PUBLIC, WRITE_ONLY], [WRITE_ONLY, ABSENT]
//
// Example 2:
//
// Input: toPublic(ABSENT, to(DELETE_ONLY), to(WRITE_ONLY), to(PUBLIC))
// Output: [ABSENT, DELETE_ONLY], [DELETE_ONLY, WRITE_ONLY], [WRITE_ONLY, PUBLIC].
//
// Right, nothing too surprising except that the trick we use for `equiv(s)` is to encode it
// as a transition from `s` to whatever the current status is.
func makeTransitions(e scpb.Element, spec targetSpec) (ret []transition, err error) {
tbs := makeTransitionBuildState(spec.from)

Expand All @@ -92,6 +107,7 @@ func makeTransitions(e scpb.Element, spec targetSpec) (ret []transition, err err
for i, s := range spec.transitionSpecs {
var t transition
if s.from == scpb.Status_UNKNOWN {
// Construct a transition `tbs.from --> s.to`, which comes from a `to(...)` spec.
t.from = tbs.from
t.to = s.to
if err := tbs.withTransition(s, i == 0 /* isFirst */); err != nil {
Expand All @@ -108,13 +124,15 @@ func makeTransitions(e scpb.Element, spec targetSpec) (ret []transition, err err
}
}
} else {
// Construct a transition `s.from --> tbs.from`, which comes from a `equiv(...)` spec.
t.from = s.from
t.to = tbs.from
if err := tbs.withEquivTransition(s); err != nil {
return nil, errors.Wrapf(
err, "invalid no-op transition %s -> %s", t.from, t.to,
)
}
t.isEquiv = true
}
t.revertible = tbs.isRevertible
if t.opType != scop.MutationType && t.opType != 0 {
Expand Down