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

distsql: Unify endian for Chunk encode format #13349

Merged
merged 18 commits into from
Nov 27, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 0 additions & 1 deletion ddl/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ func buildDescTableScanDAG(ctx sessionctx.Context, startTS uint64, tbl table.Phy
dagReq.Executors = append(dagReq.Executors, tblScanExec)
dagReq.Executors = append(dagReq.Executors, constructLimitPB(limit))
distsql.SetEncodeType(ctx, dagReq)
distsql.SetSystemEndian(dagReq)
return dagReq, nil
}

Expand Down
30 changes: 19 additions & 11 deletions distsql/distsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func SetEncodeType(ctx sessionctx.Context, dagReq *tipb.DAGRequest) {
} else {
dagReq.EncodeType = tipb.EncodeType_TypeDefault
}
SetSystemEndian(dagReq)
wshwsh12 marked this conversation as resolved.
Show resolved Hide resolved
}

func canUseChunkRPC(ctx sessionctx.Context) bool {
Expand All @@ -159,35 +160,42 @@ func canUseChunkRPC(ctx sessionctx.Context) bool {
if ctx.GetSessionVars().EnableStreaming {
return false
}
if !supportedAlignment() {
if !checkAlignment() {
return false
}
return true
}

// supportedAlignment checks the alignment in current system environment.
var supportedAlignment = !(unsafe.Sizeof(types.MysqlTime{}) != 16 ||
unsafe.Sizeof(types.Time{}) != 20 ||
unsafe.Sizeof(types.MyDecimal{}) != 40)

// checkAlignment checks the alignment in current system environment.
// The alignment is influenced by system, machine and Golang version.
// Using this function can guarantee the alignment is we want.
func supportedAlignment() bool {
if unsafe.Sizeof(types.MysqlTime{}) != 16 ||
unsafe.Sizeof(types.Time{}) != 20 ||
unsafe.Sizeof(types.MyDecimal{}) != 40 {
return false
}
return true
func checkAlignment() bool {
return supportedAlignment
}

// SetSystemEndian sets the system endian for the DAGRequest.
func SetSystemEndian(dagReq *tipb.DAGRequest) {
SunRunAway marked this conversation as resolved.
Show resolved Hide resolved
wshwsh12 marked this conversation as resolved.
Show resolved Hide resolved
dagReq.TidbSystemEndian = GetSystemEndian()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may check this when process starting and cache the result, instead of checking in each session.

}

var systemEndian *tipb.Endian

// GetSystemEndian gets the system endian.
func GetSystemEndian() tipb.Endian {
if systemEndian != nil {
SunRunAway marked this conversation as resolved.
Show resolved Hide resolved
return *systemEndian
}
systemEndian = new(tipb.Endian)
var i int = 0x0100
ptr := unsafe.Pointer(&i)
if 0x01 == *(*byte)(ptr) {
return tipb.Endian_BigEndian
*systemEndian = tipb.Endian_BigEndian
} else {
*systemEndian = tipb.Endian_LittleEndian
}
return tipb.Endian_LittleEndian
return *systemEndian
}
3 changes: 0 additions & 3 deletions executor/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func (e *CheckIndexRangeExec) buildDAGPB() (*tipb.DAGRequest, error) {
return nil, err
}
distsql.SetEncodeType(e.ctx, dagReq)
distsql.SetSystemEndian(dagReq)
return dagReq, nil
}

Expand Down Expand Up @@ -252,7 +251,6 @@ func (e *RecoverIndexExec) buildDAGPB(txn kv.Transaction, limitCnt uint64) (*tip
limitExec := e.constructLimitPB(limitCnt)
dagReq.Executors = append(dagReq.Executors, limitExec)
distsql.SetEncodeType(e.ctx, dagReq)
distsql.SetSystemEndian(dagReq)
return dagReq, nil
}

Expand Down Expand Up @@ -688,7 +686,6 @@ func (e *CleanupIndexExec) buildIdxDAGPB(txn kv.Transaction) (*tipb.DAGRequest,
limitExec := e.constructLimitPB()
dagReq.Executors = append(dagReq.Executors, limitExec)
distsql.SetEncodeType(e.ctx, dagReq)
distsql.SetSystemEndian(dagReq)
return dagReq, nil
}

Expand Down
1 change: 0 additions & 1 deletion executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,6 @@ func (b *executorBuilder) constructDAGReq(plans []plannercore.PhysicalPlan) (dag
dagReq.Executors, streaming, err = constructDistExec(b.ctx, plans)

distsql.SetEncodeType(b.ctx, dagReq)
distsql.SetSystemEndian(dagReq)
return dagReq, streaming, err
}

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,6 @@ require (

go 1.13

replace github.com/pingcap/tipb => github.com/wshwsh12/tipb v0.0.0-20191112090242-f12fde038340
replace github.com/pingcap/check => github.com/tiancaiamao/check v0.0.0-20191119042138-8e73d07b629d

replace github.com/pingcap/tipb => github.com/wshwsh12/tipb v0.0.0-20191126022620-fce96f6e0e24
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d h1:ggUgChAeyge4NZ4
github.com/unrolled/render v0.0.0-20180914162206-b9786414de4d/go.mod h1:tu82oB5W2ykJRVioYsB+IQKcft7ryBr7w12qMBUPyXg=
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/negroni v0.3.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/wshwsh12/tipb v0.0.0-20191112090242-f12fde038340 h1:qMaRfCDQ63NsQMMIg8uLXB0LlrzXogMhNglQgCsNuTA=
github.com/wshwsh12/tipb v0.0.0-20191112090242-f12fde038340/go.mod h1:UFKGXY+Ij4rifkYSXsZOrEQcV70dCog1faHm7QKJiWs=
github.com/wshwsh12/tipb v0.0.0-20191126022620-fce96f6e0e24 h1:GHqjILkzVElXbYgItjPVDsHVyLPhcqla71FFVE/iQfE=
github.com/wshwsh12/tipb v0.0.0-20191126022620-fce96f6e0e24/go.mod h1:UFKGXY+Ij4rifkYSXsZOrEQcV70dCog1faHm7QKJiWs=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/yookoala/realpath v1.0.0/go.mod h1:gJJMA9wuX7AcqLy1+ffPatSCySA1FQ2S8Ya9AIoYBpE=
Expand Down