Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
lzmhhh123 committed Jan 8, 2020
1 parent 96296a1 commit 1f41051
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 27 deletions.
24 changes: 2 additions & 22 deletions distsql/request_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ package distsql

import (
"math"
"reflect"

"github.com/pingcap/parser/mysql"
"github.com/pingcap/parser/terror"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/structure"
"github.com/pingcap/tidb/tablecodec"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/codec"
Expand Down Expand Up @@ -141,25 +138,8 @@ func (builder *RequestBuilder) SetStoreType(storeType kv.StoreType) *RequestBuil
}

// SetSchemaVer sets "SchemaVer" for "kv.Request".
func (builder *RequestBuilder) SetSchemaVer(txn kv.Transaction) *RequestBuilder {
// Avoid panic by situation:
// struct wrapTxn {
// kv.Transaction
// }
// And the `Transaction` is nil in `wrapTxn`
if txn == nil {
return builder
}
if txnField, hasTxn := reflect.TypeOf(txn).Elem().FieldByName("Transaction"); hasTxn && reflect.ValueOf(txn).Elem().Field(txnField.Index[0]).IsNil() {
return builder
}

txnStruct := structure.NewStructure(txn, txn, []byte("m"))
var err error
builder.Request.SchemaVar, err = txnStruct.GetInt64([]byte("SchemaVersionKey"))
if err != nil {
terror.Log(err)
}
func (builder *RequestBuilder) SetSchemaVer(schemaVer int64) *RequestBuilder {
builder.Request.SchemaVar = schemaVer
return builder
}

Expand Down
6 changes: 1 addition & 5 deletions executor/table_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,6 @@ func (e *TableReaderExecutor) Close() error {
// to fetch all results.
func (e *TableReaderExecutor) buildResp(ctx context.Context, ranges []*ranger.Range) (distsql.SelectResult, error) {
var builder distsql.RequestBuilder
txn, err := e.ctx.Txn(false)
if err != nil {
return nil, err
}
kvReq, err := builder.SetTableRanges(getPhysicalTableID(e.table), ranges, e.feedback).
SetDAGRequest(e.dagPB).
SetStartTS(e.startTS).
Expand All @@ -219,7 +215,7 @@ func (e *TableReaderExecutor) buildResp(ctx context.Context, ranges []*ranger.Ra
SetFromSessionVars(e.ctx.GetSessionVars()).
SetMemTracker(e.memTracker).
SetStoreType(e.storeType).
SetSchemaVer(txn).
SetSchemaVer(e.ctx.GetSessionVars().TxnCtx.SchemaVersion).
Build()
if err != nil {
return nil, err
Expand Down

0 comments on commit 1f41051

Please sign in to comment.