Skip to content

Commit

Permalink
add status
Browse files Browse the repository at this point in the history
Signed-off-by: Shuaipeng Yu <jackysp@gmail.com>
  • Loading branch information
jackysp committed Dec 2, 2019
1 parent 259d4fd commit 33bb6a2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
10 changes: 6 additions & 4 deletions server/http_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -674,11 +674,13 @@ func (h configReloadHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
// ServeHTTP recovers binlog service.
func (h binlogRecover) ServeHTTP(w http.ResponseWriter, req *http.Request) {
op := req.FormValue(qOperation)
if op == "reset" {
switch op {
case "reset":
binloginfo.ResetSkippedCommitterCounter()
} else if op == "nowait" {
case "nowait":
binloginfo.DisableSkipBinlogFlag()
} else {
case "status":
default:
sec, err := strconv.ParseInt(req.FormValue(qSeconds), 10, 64)
if sec <= 0 || err != nil {
sec = 1800
Expand All @@ -691,7 +693,7 @@ func (h binlogRecover) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}
}
writeData(w, "success!")
writeData(w, binloginfo.GetBinlogStatus())
}

type tableFlashReplicaInfo struct {
Expand Down
5 changes: 5 additions & 0 deletions server/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ func (ts *HTTPHandlerTestSuite) TestBinlogRecover(c *C) {
defer resp.Body.Close()
c.Assert(resp.StatusCode, Equals, http.StatusOK)
c.Assert(binloginfo.IsBinlogSkipped(), Equals, false)

resp, err = http.Get(fmt.Sprintf("http://127.0.0.1:10090/binlog/recover?op=status"))
c.Assert(err, IsNil)
defer resp.Body.Close()
c.Assert(resp.StatusCode, Equals, http.StatusOK)
}

func (ts *HTTPHandlerTestSuite) TestRegionsFromMeta(c *C) {
Expand Down
15 changes: 14 additions & 1 deletion sessionctx/binloginfo/binloginfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,20 @@ func IsBinlogSkipped() bool {
return atomic.LoadUint32(&skipBinlog) > 0
}

// BinlogRecoverStatus is used for display the binlog recovered status after some operations.
type BinlogRecoverStatus struct {
Skipped bool
SkippedCommitterCounter int32
}

// GetBinlogStatus returns the binlog recovered status.
func GetBinlogStatus() *BinlogRecoverStatus {
return &BinlogRecoverStatus{
Skipped: IsBinlogSkipped(),
SkippedCommitterCounter: SkippedCommitterCount(),
}
}

var skippedCommitterCounter int32

// WaitBinlogRecover returns when all committing transaction finished.
Expand All @@ -155,7 +169,6 @@ func WaitBinlogRecover(timeout time.Duration) error {
}

// SkippedCommitterCount returns the number of alive committers whick skipped the binlog writing.
// NOTE: it is used *ONLY* for test.
func SkippedCommitterCount() int32 {
return atomic.LoadInt32(&skippedCommitterCounter)
}
Expand Down

0 comments on commit 33bb6a2

Please sign in to comment.