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

pump/* add a api to get binlog by ts #449

Merged
merged 2 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
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