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

server: add HTTP API to enable/disable async commit and 1PC #23115

Merged
merged 4 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 15 additions & 0 deletions docs/tidb_http_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,18 @@ timezone.*
* op=nowait: return after binlog status is recoverd, do not wait until the skipped-binlog transactions are committed.
* op=reset: reset `SkippedCommitterCounter` to 0 to avoid the problem that `SkippedCommitterCounter` is not cleared due to some unusual cases.
* op=status: Get the current status of binlog recovery.

1. Enable/disable async commit feature
jackysp marked this conversation as resolved.
Show resolved Hide resolved

```shell
curl -X POST -d "tidb_enable_async_commit=1" http://{TiDBIP}:10080/settings
curl -X POST -d "tidb_enable_async_commit=0" http://{TiDBIP}:10080/settings
```

1. Enable/disable one-phase commit feature

```shell
curl -X POST -d "tidb_enable_1pc=1" http://{TiDBIP}:10080/settings
curl -X POST -d "tidb_enable_1pc=0" http://{TiDBIP}:10080/settings
```

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ require (
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0
gopkg.in/yaml.v2 v2.3.0 // indirect
honnef.co/go/tools v0.1.1 // indirect
honnef.co/go/tools v0.1.2 // indirect
sourcegraph.com/sourcegraph/appdash v0.0.0-20190731080439-ebfcffb1b5c0
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -848,8 +848,8 @@ honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
honnef.co/go/tools v0.1.1 h1:EVDuO03OCZwpV2t/tLLxPmPiomagMoBOgfPt0FM+4IY=
honnef.co/go/tools v0.1.1/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
honnef.co/go/tools v0.1.2 h1:SMdYLJl312RXuxXziCCHhRsp/tvct9cGKey0yv95tZM=
honnef.co/go/tools v0.1.2/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
Expand Down
41 changes: 41 additions & 0 deletions server/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ func (t *tikvHandlerTool) handleMvccGetByHex(params map[string]string) (*mvccKV,

// settingsHandler is the handler for list tidb server settings.
type settingsHandler struct {
*tikvHandlerTool
}

// binlogRecover is used to recover binlog service.
Expand Down Expand Up @@ -720,6 +721,46 @@ func (h settingsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}
}
if asyncCommit := req.Form.Get("tidb_enable_async_commit"); asyncCommit != "" {
s, err := session.CreateSession(h.Store.(kv.Storage))
ekexium marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
writeError(w, err)
return
}
switch asyncCommit {
case "0":
err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(variable.TiDBEnableAsyncCommit, variable.BoolOff)
case "1":
err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(variable.TiDBEnableAsyncCommit, variable.BoolOn)
default:
writeError(w, errors.New("illegal argument"))
return
}
if err != nil {
writeError(w, err)
return
}
}
if onePC := req.Form.Get("tidb_enable_1pc"); onePC != "" {
s, err := session.CreateSession(h.Store.(kv.Storage))
if err != nil {
writeError(w, err)
return
}
switch onePC {
case "0":
err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(variable.TiDBEnable1PC, variable.BoolOff)
case "1":
err = s.GetSessionVars().GlobalVarsAccessor.SetGlobalSysVar(variable.TiDBEnable1PC, variable.BoolOn)
default:
writeError(w, errors.New("illegal argument"))
return
}
if err != nil {
writeError(w, err)
return
}
}
if ddlSlowThreshold := req.Form.Get("ddl_slow_threshold"); ddlSlowThreshold != "" {
threshold, err1 := strconv.Atoi(ddlSlowThreshold)
if err1 != nil {
Expand Down
20 changes: 20 additions & 0 deletions server/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1104,26 +1104,46 @@ func (ts *HTTPHandlerTestSuite) TestPostSettings(c *C) {
ts.startServer(c)
ts.prepareData(c)
defer ts.stopServer(c)
se, err := session.CreateSession(ts.store.(kv.Storage))
c.Assert(err, IsNil)

form := make(url.Values)
form.Set("log_level", "error")
form.Set("tidb_general_log", "1")
form.Set("tidb_enable_async_commit", "1")
form.Set("tidb_enable_1pc", "1")
resp, err := ts.formStatus("/settings", form)
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
c.Assert(log.GetLevel(), Equals, log.ErrorLevel)
c.Assert(zaplog.GetLevel(), Equals, zap.ErrorLevel)
c.Assert(config.GetGlobalConfig().Log.Level, Equals, "error")
c.Assert(variable.ProcessGeneralLog.Load(), IsTrue)
val, err := variable.GetGlobalSystemVar(se.GetSessionVars(), variable.TiDBEnableAsyncCommit)
c.Assert(err, IsNil)
c.Assert(val, Equals, variable.BoolOn)
val, err = variable.GetGlobalSystemVar(se.GetSessionVars(), variable.TiDBEnable1PC)
c.Assert(err, IsNil)
c.Assert(val, Equals, variable.BoolOn)

form = make(url.Values)
form.Set("log_level", "fatal")
form.Set("tidb_general_log", "0")
form.Set("tidb_enable_async_commit", "0")
form.Set("tidb_enable_1pc", "0")
resp, err = ts.formStatus("/settings", form)
c.Assert(err, IsNil)
c.Assert(resp.StatusCode, Equals, http.StatusOK)
c.Assert(variable.ProcessGeneralLog.Load(), IsFalse)
c.Assert(log.GetLevel(), Equals, log.FatalLevel)
c.Assert(zaplog.GetLevel(), Equals, zap.FatalLevel)
c.Assert(config.GetGlobalConfig().Log.Level, Equals, "fatal")
val, err = variable.GetGlobalSystemVar(se.GetSessionVars(), variable.TiDBEnableAsyncCommit)
c.Assert(err, IsNil)
c.Assert(val, Equals, variable.BoolOff)
val, err = variable.GetGlobalSystemVar(se.GetSessionVars(), variable.TiDBEnable1PC)
c.Assert(err, IsNil)
c.Assert(val, Equals, variable.BoolOff)
form.Set("log_level", os.Getenv("log_level"))

// test ddl_slow_threshold
Expand Down
4 changes: 2 additions & 2 deletions server/http_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ func (s *Server) startHTTPServer() {
router.Handle("/stats/dump/{db}/{table}", s.newStatsHandler()).Name("StatsDump")
router.Handle("/stats/dump/{db}/{table}/{snapshot}", s.newStatsHistoryHandler()).Name("StatsHistoryDump")

router.Handle("/settings", settingsHandler{}).Name("Settings")
tikvHandlerTool := s.newTikvHandlerTool()
router.Handle("/settings", settingsHandler{tikvHandlerTool}).Name("Settings")
router.Handle("/binlog/recover", binlogRecover{}).Name("BinlogRecover")

tikvHandlerTool := s.newTikvHandlerTool()
router.Handle("/schema", schemaHandler{tikvHandlerTool}).Name("Schema")
router.Handle("/schema/{db}", schemaHandler{tikvHandlerTool})
router.Handle("/schema/{db}/{table}", schemaHandler{tikvHandlerTool})
Expand Down