Skip to content

Commit

Permalink
pump/* add a api to get binlog by ts (#449) (#455)
Browse files Browse the repository at this point in the history
* pump/* add a api to get binlog by ts
  • Loading branch information
july2993 authored Jan 24, 2019
1 parent 4ff2707 commit fe4317d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pump/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"net/http"
"net/url"
"strconv"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -400,6 +401,7 @@ func (s *Server) Start() error {
router.HandleFunc("/status", s.Status).Methods("GET")
router.HandleFunc("/state/{nodeID}/{action}", s.ApplyAction).Methods("PUT")
router.HandleFunc("/drainers", s.AllDrainers).Methods("GET")
router.HandleFunc("/debug/binlog/{ts}", s.BinlogByTS).Methods("GET")
http.Handle("/", router)
prometheus.DefaultGatherer = registry
http.Handle("/metrics", prometheus.Handler())
Expand Down Expand Up @@ -593,6 +595,31 @@ func (s *Server) Status(w http.ResponseWriter, r *http.Request) {
s.PumpStatus().Status(w, r)
}

// BinlogByTS exposes api get get binlog by ts
func (s *Server) BinlogByTS(w http.ResponseWriter, r *http.Request) {
tsStr := mux.Vars(r)["ts"]
ts, err := strconv.ParseInt(tsStr, 10, 64)
if err != nil {
w.Write([]byte(fmt.Sprintf("invalid parameter ts: %s", tsStr)))
return
}

binlog, err := s.storage.GetBinlog(ts)
if err != nil {
w.Write([]byte(err.Error()))
return
}

w.Write([]byte(binlog.String()))
if len(binlog.PrewriteValue) > 0 {
prewriteValue := new(pb.PrewriteValue)
prewriteValue.Unmarshal(binlog.PrewriteValue)

w.Write([]byte("\n\n PrewriteValue: \n"))
w.Write([]byte(prewriteValue.String()))
}
}

// PumpStatus returns all pumps' status.
func (s *Server) PumpStatus() *HTTPStatus {
status, err := s.node.NodesStatus(s.ctx)
Expand Down
7 changes: 7 additions & 0 deletions pump/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type Storage interface {

MaxCommitTS() int64

// GetBinlog return the binlog of ts
GetBinlog(ts int64) (binlog *pb.Binlog, err error)

// PullCommitBinlog return the chan to consume the binlog
PullCommitBinlog(ctx context.Context, last int64) <-chan []byte

Expand Down Expand Up @@ -427,6 +430,10 @@ func (a *Append) resolve(startTS int64) bool {
return false
}

func (a *Append) GetBinlog(ts int64) (*pb.Binlog, error) {
return a.readBinlogByTS(ts)
}

func (a *Append) readBinlogByTS(ts int64) (*pb.Binlog, error) {
var vp valuePointer

Expand Down

0 comments on commit fe4317d

Please sign in to comment.