Skip to content

Commit

Permalink
addressed review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal committed Dec 6, 2023
1 parent 2d0beef commit cf421cd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 28 deletions.
8 changes: 0 additions & 8 deletions go/vt/vtgate/engine/fake_vcursor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,6 @@ func (t *noopVCursor) SetAutocommit(context.Context, bool) error {
panic("implement me")
}

func (t *noopVCursor) SetSessionForeignKeyChecks(ctx context.Context, foreignKeyChecks bool) error {
panic("implement me")
}

func (t *noopVCursor) SetClientFoundRows(context.Context, bool) error {
panic("implement me")
}
Expand Down Expand Up @@ -747,10 +743,6 @@ func (f *loggingVCursor) SetAutocommit(context.Context, bool) error {
panic("implement me")
}

func (f *loggingVCursor) SetSessionForeignKeyChecks(ctx context.Context, foreignKeyChecks bool) error {
panic("implement me")
}

func (f *loggingVCursor) SetClientFoundRows(context.Context, bool) error {
panic("implement me")
}
Expand Down
1 change: 0 additions & 1 deletion go/vt/vtgate/engine/primitive.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ type (

SetAutocommit(ctx context.Context, autocommit bool) error
SetClientFoundRows(context.Context, bool) error
SetSessionForeignKeyChecks(ctx context.Context, autocommit bool) error
SetSkipQueryPlanCache(context.Context, bool) error
SetSQLSelectLimit(int64) error
SetTransactionMode(vtgatepb.TransactionMode)
Expand Down
12 changes: 5 additions & 7 deletions go/vt/vtgate/safe_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,25 +573,23 @@ func (session *SafeSession) TimeZone() *time.Location {
}

// ForeignKeyChecks returns the foreign_key_checks stored in system_variables map in the session.
func (session *SafeSession) ForeignKeyChecks() (*bool, *string) {
func (session *SafeSession) ForeignKeyChecks() *bool {
session.mu.Lock()
fkVal, ok := session.SystemVariables[sysvars.ForeignKeyChecks]
session.mu.Unlock()

if !ok {
return nil, nil
return nil
}
switch strings.ToLower(fkVal) {
case "off", "0":
fkCheckStr := "0"
fkCheckBool := false
return &fkCheckBool, &fkCheckStr
return &fkCheckBool
case "on", "1":
fkCheckStr := "1"
fkCheckBool := true
return &fkCheckBool, &fkCheckStr
return &fkCheckBool
}
return nil, nil
return nil
}

// SetOptions sets the options
Expand Down
13 changes: 1 addition & 12 deletions go/vt/vtgate/vcursor_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/srvtopo"
"vitess.io/vitess/go/vt/sysvars"
"vitess.io/vitess/go/vt/topo"
topoprotopb "vitess.io/vitess/go/vt/topo/topoproto"
"vitess.io/vitess/go/vt/topotools"
Expand Down Expand Up @@ -832,16 +831,6 @@ func (vc *vcursorImpl) SetAutocommit(ctx context.Context, autocommit bool) error
return nil
}

// SetSessionForeignKeyChecks implements the SessionActions interface
func (vc *vcursorImpl) SetSessionForeignKeyChecks(ctx context.Context, foreignKeyChecks bool) error {
if foreignKeyChecks {
vc.safeSession.SetSystemVariable(sysvars.ForeignKeyChecks, "1")
} else {
vc.safeSession.SetSystemVariable(sysvars.ForeignKeyChecks, "0")
}
return nil
}

// SetQueryTimeout implements the SessionActions interface
func (vc *vcursorImpl) SetQueryTimeout(maxExecutionTime int64) {
vc.safeSession.QueryTimeout = maxExecutionTime
Expand Down Expand Up @@ -1365,7 +1354,7 @@ func (vc *vcursorImpl) UpdateForeignKeyChecksState(fkStateFromQuery *bool) {
return
}
// If the query doesn't have anything, then we consult the session state.
vc.fkChecksState, _ = vc.safeSession.ForeignKeyChecks()
vc.fkChecksState = vc.safeSession.ForeignKeyChecks()
}

// GetForeignKeyChecksState gets the stored foreign key checks state in the vcursor.
Expand Down

0 comments on commit cf421cd

Please sign in to comment.