Skip to content

Commit

Permalink
session: fix unsecessfully set the isolation read engines (pingcap#17258
Browse files Browse the repository at this point in the history
  • Loading branch information
sre-bot authored and lzmhhh123 committed Oct 21, 2020
1 parent beae9ef commit 1930573
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
12 changes: 11 additions & 1 deletion sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ func NewSessionVars() *SessionVars {
AllowRemoveAutoInc: DefTiDBAllowRemoveAutoInc,
UsePlanBaselines: DefTiDBUsePlanBaselines,
EvolvePlanBaselines: DefTiDBEvolvePlanBaselines,
IsolationReadEngines: map[kv.StoreType]struct{}{kv.TiKV: {}, kv.TiFlash: {}, kv.TiDB: {}},
IsolationReadEngines: make(map[kv.StoreType]struct{}),
LockWaitTimeout: DefInnodbLockWaitTimeout * 1000,
MetricSchemaStep: DefTiDBMetricSchemaStep,
MetricSchemaRangeDuration: DefTiDBMetricSchemaRangeDuration,
Expand Down Expand Up @@ -733,6 +733,16 @@ func NewSessionVars() *SessionVars {
enableChunkRPC = "0"
}
terror.Log(vars.SetSystemVar(TiDBEnableChunkRPC, enableChunkRPC))
for _, engine := range config.GetGlobalConfig().IsolationRead.Engines {
switch engine {
case kv.TiFlash.Name():
vars.IsolationReadEngines[kv.TiFlash] = struct{}{}
case kv.TiKV.Name():
vars.IsolationReadEngines[kv.TiKV] = struct{}{}
case kv.TiDB.Name():
vars.IsolationReadEngines[kv.TiDB] = struct{}{}
}
}
return vars
}

Expand Down
19 changes: 18 additions & 1 deletion sessionctx/variable/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ import (
. "github.com/pingcap/check"
"github.com/pingcap/parser"
"github.com/pingcap/parser/auth"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/sessionctx/stmtctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/execdetails"
"github.com/pingcap/tidb/util/mock"
)

var _ = Suite(&testSessionSuite{})
var _ = SerialSuites(&testSessionSuite{})

type testSessionSuite struct {
}
Expand Down Expand Up @@ -214,3 +216,18 @@ select * from t;`
})
c.Assert(logString, Equals, resultString)
}

func (*testSessionSuite) TestIsolationRead(c *C) {
originIsolationEngines := config.GetGlobalConfig().IsolationRead.Engines
defer func() {
config.GetGlobalConfig().IsolationRead.Engines = originIsolationEngines
}()
config.GetGlobalConfig().IsolationRead.Engines = []string{"tiflash", "tidb"}
sessVars := variable.NewSessionVars()
_, ok := sessVars.IsolationReadEngines[kv.TiDB]
c.Assert(ok, Equals, true)
_, ok = sessVars.IsolationReadEngines[kv.TiKV]
c.Assert(ok, Equals, false)
_, ok = sessVars.IsolationReadEngines[kv.TiFlash]
c.Assert(ok, Equals, true)
}

0 comments on commit 1930573

Please sign in to comment.