Skip to content

Commit

Permalink
[release-18.0] Rename Foreign Key enum values in VSchema and drop `FK…
Browse files Browse the repository at this point in the history
…_` prefix (#14274) (#14299)

Signed-off-by: Manan Gupta <[email protected]>
Co-authored-by: Manan Gupta <[email protected]>
Co-authored-by: Manan Gupta <[email protected]>
  • Loading branch information
3 people authored Oct 18, 2023
1 parent fe27a3f commit e0f96d3
Show file tree
Hide file tree
Showing 23 changed files with 186 additions and 186 deletions.
6 changes: 3 additions & 3 deletions changelog/18.0/18.0.0/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ It is disabled by default.
A new field `foreignKeyMode` has been added to the VSchema. This field can be provided for each keyspace. The VTGate flag `--foreign_key_mode` has been deprecated in favour of this field.

There are 3 foreign key modes now supported in Vitess -
1. `FK_UNMANAGED` -
1. `unmanaged` -
This mode represents the default behaviour in Vitess, where it does not manage foreign keys column references. Users are responsible for configuring foreign keys in MySQL in such a way that related rows, as determined by foreign keys, reside within the same shard.
2. `FK_MANAGED` [EXPERIMENTAL] -
2. `managed` [EXPERIMENTAL] -
In this experimental mode, Vitess is fully aware of foreign key relationships and actively tracks foreign key constraints using the schema tracker. Vitess takes charge of handling DML operations with foreign keys cascading updates, deletes and verifying restrict. It will also validate parent row existence.
This ensures that all the operations are logged in binary logs, unlike MySQL implementation of foreign keys.
This enables seamless integration of VReplication with foreign keys.
For more details on what operations Vitess takes please refer to the [design document for foreign keys](https://github.com/vitessio/vitess/issues/12967).
3. `FK_DISALLOW` -
3. `disallow` -
In this mode Vitess explicitly disallows any DDL statements that try to create a foreign key constraint. This mode is equivalent to running VTGate with the flag `--foreign_key_mode=disallow`.

#### Upgrade process
Expand Down
6 changes: 3 additions & 3 deletions changelog/18.0/18.0.0/summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ It is disabled by default.
A new field `foreignKeyMode` has been added to the VSchema. This field can be provided for each keyspace. The VTGate flag `--foreign_key_mode` has been deprecated in favour of this field.

There are 3 foreign key modes now supported in Vitess -
1. `FK_UNMANAGED` -
1. `unmanaged` -
This mode represents the default behaviour in Vitess, where it does not manage foreign keys column references. Users are responsible for configuring foreign keys in MySQL in such a way that related rows, as determined by foreign keys, reside within the same shard.
2. `FK_MANAGED` [EXPERIMENTAL] -
2. `managed` [EXPERIMENTAL] -
In this experimental mode, Vitess is fully aware of foreign key relationships and actively tracks foreign key constraints using the schema tracker. Vitess takes charge of handling DML operations with foreign keys cascading updates, deletes and verifying restrict. It will also validate parent row existence.
This ensures that all the operations are logged in binary logs, unlike MySQL implementation of foreign keys.
This enables seamless integration of VReplication with foreign keys.
For more details on what operations Vitess takes please refer to the [design document for foreign keys](https://github.com/vitessio/vitess/issues/12967).
3. `FK_DISALLOW` -
3. `disallow` -
In this mode Vitess explicitly disallows any DDL statements that try to create a foreign key constraint. This mode is equivalent to running VTGate with the flag `--foreign_key_mode=disallow`.

#### Upgrade process
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/vtgate/foreignkey/sharded_vschema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sharded": true,
"foreignKeyMode": "FK_MANAGED",
"foreignKeyMode": "managed",
"vindexes": {
"xxhash": {
"type": "xxhash"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func TestMain(m *testing.M) {
Name: keyspaceName,
VSchema: `{
"sharded": false,
"foreignKeyMode": "FK_MANAGED"
"foreignKeyMode": "managed"
}`,
}

Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/vtgate/foreignkey/unsharded_vschema.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sharded": false,
"foreignKeyMode": "FK_MANAGED",
"foreignKeyMode": "managed",
"tables": {
"u_t1": {},
"u_t2": {},
Expand Down
4 changes: 2 additions & 2 deletions go/test/vschemawrapper/vschema_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func (vw *VSchemaWrapper) PlannerWarning(_ string) {
}

func (vw *VSchemaWrapper) ForeignKeyMode(keyspace string) (vschemapb.Keyspace_ForeignKeyMode, error) {
defaultFkMode := vschemapb.Keyspace_FK_UNMANAGED
if vw.V.Keyspaces[keyspace] != nil && vw.V.Keyspaces[keyspace].ForeignKeyMode != vschemapb.Keyspace_FK_DEFAULT {
defaultFkMode := vschemapb.Keyspace_unmanaged
if vw.V.Keyspaces[keyspace] != nil && vw.V.Keyspaces[keyspace].ForeignKeyMode != vschemapb.Keyspace_unspecified {
return vw.V.Keyspaces[keyspace].ForeignKeyMode, nil
}
return defaultFkMode, nil
Expand Down
192 changes: 96 additions & 96 deletions go/vt/proto/vschema/vschema.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func checkFKError(vschema plancontext.VSchema, ddlStatement sqlparser.DDLStateme
if err != nil {
return err
}
if fkMode == vschemapb.Keyspace_FK_DISALLOW {
if fkMode == vschemapb.Keyspace_disallow {
fk := &fkContraint{}
_ = sqlparser.Walk(fk.FkWalk, ddlStatement)
if fk.found {
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func fkManagementNotRequired(ctx *plancontext.PlanningContext, vschema planconte
if err != nil {
return false
}
if ksMode != vschemapb.Keyspace_FK_MANAGED {
if ksMode != vschemapb.Keyspace_managed {
continue
}
childFks := vTable.ChildFKsNeedsHandling(ctx.VerifyAllFKs, vindexes.DeleteAction)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func errOutIfPlanCannotBeConstructed(ctx *plancontext.PlanningContext, vTbl *vin
// TODO: Handle all this in semantic analysis.
func fkManagementRequiredForInsert(ctx *plancontext.PlanningContext, vTbl *vindexes.Table, updateExprs sqlparser.UpdateExprs, replace bool) bool {
ksMode, err := ctx.VSchema.ForeignKeyMode(vTbl.Keyspace.Name)
if err != nil || ksMode != vschemapb.Keyspace_FK_MANAGED {
if err != nil || ksMode != vschemapb.Keyspace_managed {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func createOperatorFromDelete(ctx *plancontext.PlanningContext, deleteStmt *sqlp
}

// Unmanaged foreign-key-mode, we don't need to do anything.
if ksMode != vschemapb.Keyspace_FK_MANAGED {
if ksMode != vschemapb.Keyspace_managed {
return delOp, nil
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func createOperatorFromInsert(ctx *plancontext.PlanningContext, ins *sqlparser.I
if err != nil {
return nil, err
}
if ksMode != vschemapb.Keyspace_FK_MANAGED {
if ksMode != vschemapb.Keyspace_managed {
return insOp, nil
}

Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/operators/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func createOperatorFromUpdate(ctx *plancontext.PlanningContext, updStmt *sqlpars
return nil, err
}
// Unmanaged foreign-key-mode, we don't need to do anything.
if ksMode != vschemapb.Keyspace_FK_MANAGED {
if ksMode != vschemapb.Keyspace_managed {
return updOp, nil
}

Expand Down
4 changes: 2 additions & 2 deletions go/vt/vtgate/planbuilder/testdata/vschemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@
},
"sharded_fk_allow": {
"sharded": true,
"foreignKeyMode": "FK_MANAGED",
"foreignKeyMode": "managed",
"vindexes": {
"hash_vin": {
"type": "hash_test"
Expand Down Expand Up @@ -746,7 +746,7 @@
}
},
"unsharded_fk_allow": {
"foreignKeyMode": "FK_MANAGED",
"foreignKeyMode": "managed",
"tables": {
"u_tbl1": {},
"u_tbl2": {},
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func fkManagementNotRequiredForUpdate(ctx *plancontext.PlanningContext, vTables
if err != nil {
return false
}
if ksMode != vschemapb.Keyspace_FK_MANAGED {
if ksMode != vschemapb.Keyspace_managed {
continue
}
childFks := vTable.ChildFKsNeedsHandling(ctx.VerifyAllFKs, vindexes.UpdateAction)
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/vcursor_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ func (vc *vcursorImpl) PlannerWarning(message string) {
// ForeignKeyMode implements the VCursor interface
func (vc *vcursorImpl) ForeignKeyMode(keyspace string) (vschemapb.Keyspace_ForeignKeyMode, error) {
if strings.ToLower(foreignKeyMode) == "disallow" {
return vschemapb.Keyspace_FK_DISALLOW, nil
return vschemapb.Keyspace_disallow, nil
}
ks := vc.vschema.Keyspaces[keyspace]
if ks == nil {
Expand Down
10 changes: 5 additions & 5 deletions go/vt/vtgate/vindexes/vschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func buildKeyspaces(source *vschemapb.SrvVSchema, vschema *VSchema) {
Name: ksname,
Sharded: ks.Sharded,
},
ForeignKeyMode: replaceDefaultForeignKeyMode(ks.ForeignKeyMode),
ForeignKeyMode: replaceUnspecifiedForeignKeyMode(ks.ForeignKeyMode),
Tables: make(map[string]*Table),
Vindexes: make(map[string]Vindex),
}
Expand All @@ -335,10 +335,10 @@ func buildKeyspaces(source *vschemapb.SrvVSchema, vschema *VSchema) {
}
}

// replaceDefaultForeignKeyMode replaces the default value of the foreign key mode enum with the default we want to keep.
func replaceDefaultForeignKeyMode(fkMode vschemapb.Keyspace_ForeignKeyMode) vschemapb.Keyspace_ForeignKeyMode {
if fkMode == vschemapb.Keyspace_FK_DEFAULT {
return vschemapb.Keyspace_FK_UNMANAGED
// replaceUnspecifiedForeignKeyMode replaces the default value of the foreign key mode enum with the default we want to keep.
func replaceUnspecifiedForeignKeyMode(fkMode vschemapb.Keyspace_ForeignKeyMode) vschemapb.Keyspace_ForeignKeyMode {
if fkMode == vschemapb.Keyspace_unspecified {
return vschemapb.Keyspace_unmanaged
}
return fkMode
}
Expand Down
Loading

0 comments on commit e0f96d3

Please sign in to comment.