-
Notifications
You must be signed in to change notification settings - Fork 131
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/: Accelerat transaction status queries throught GetMvccByEncodeKey #632
Changes from 3 commits
af5fec9
c2365a5
0e49478
a35361d
c9daf89
d4c3fa0
3218d24
403eca6
808a4f9
268497f
02b586c
83ecb8b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ import ( | |
"github.com/pingcap/tidb-binlog/pkg/node" | ||
"github.com/pingcap/tidb-binlog/pkg/util" | ||
"github.com/pingcap/tidb-binlog/pump/storage" | ||
"github.com/pingcap/tidb/kv" | ||
"github.com/pingcap/tidb/session" | ||
"github.com/pingcap/tidb/store/tikv" | ||
"github.com/pingcap/tidb/store/tikv/oracle" | ||
|
@@ -81,6 +82,7 @@ type Server struct { | |
lastWriteBinlogUnixNano int64 | ||
pdCli pd.Client | ||
cfg *Config | ||
tiStore kv.Storage | ||
|
||
writeBinlogCount int64 | ||
alivePullerCount int64 | ||
|
@@ -166,6 +168,7 @@ func NewServer(cfg *Config) (*Server, error) { | |
ctx: ctx, | ||
cancel: cancel, | ||
metrics: metrics, | ||
tiStore: tiStore, | ||
gcDuration: time.Duration(cfg.GC) * 24 * time.Hour, | ||
pdCli: pdCli, | ||
cfg: cfg, | ||
|
@@ -597,6 +600,23 @@ func (s *Server) BinlogByTS(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprint(w, "\n\n PrewriteValue: \n") | ||
fmt.Fprint(w, prewriteValue.String()) | ||
} | ||
|
||
if len(binlog.PrewriteKey) > 0 { | ||
tikvStorage := s.tiStore.(tikv.Storage) | ||
healper := storage.Helper{ | ||
july2993 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Store: tikvStorage, | ||
RegionCache: tikvStorage.GetRegionCache(), | ||
} | ||
|
||
resp, err := healper.GetMvccByEncodedKey(binlog.PrewriteKey) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can extract one function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for debug just keep all info? |
||
if err != nil { | ||
fmt.Fprintf(w, "GetMvccByEncodedKey failed: %s", err.Error()) | ||
return | ||
} | ||
|
||
fmt.Fprint(w, "\n\n GetMvccByEncodedKey: \n") | ||
fmt.Fprint(w, resp.String()) | ||
} | ||
} | ||
|
||
// PumpStatus returns all pumps' status. | ||
|
@@ -782,6 +802,11 @@ func (s *Server) Close() { | |
s.pdCli.Close() | ||
} | ||
log.Info("has closed pdCli") | ||
|
||
if s.tiStore != nil { | ||
s.tiStore.Close() | ||
} | ||
log.Info("has closed tiStore") | ||
suzaku marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
func (s *Server) waitUntilCommitTSSaved(ctx context.Context, ts int64, checkInterval time.Duration) error { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,60 @@ | ||||||
// Copyright 2019 PingCAP, Inc. | ||||||
// | ||||||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
// you may not use this file except in compliance with the License. | ||||||
// You may obtain a copy of the License at | ||||||
// | ||||||
// http://www.apache.org/licenses/LICENSE-2.0 | ||||||
// | ||||||
// Unless required by applicable law or agreed to in writing, software | ||||||
// distributed under the License is distributed on an "AS IS" BASIS, | ||||||
// See the License for the specific language governing permissions and | ||||||
// limitations under the License. | ||||||
|
||||||
package storage | ||||||
|
||||||
import ( | ||||||
"context" | ||||||
"time" | ||||||
|
||||||
"github.com/pingcap/errors" | ||||||
"github.com/pingcap/kvproto/pkg/kvrpcpb" | ||||||
"github.com/pingcap/log" | ||||||
"github.com/pingcap/tidb/kv" | ||||||
"github.com/pingcap/tidb/store/tikv" | ||||||
"github.com/pingcap/tidb/store/tikv/tikvrpc" | ||||||
"go.uber.org/zap" | ||||||
) | ||||||
|
||||||
// Helper is a middleware to get some information from tikv/pd. | ||||||
type Helper struct { | ||||||
Store tikv.Storage | ||||||
RegionCache *tikv.RegionCache | ||||||
} | ||||||
|
||||||
// GetMvccByEncodedKey get the MVCC value by the specific encoded key. | ||||||
func (h *Helper) GetMvccByEncodedKey(encodedKey kv.Key) (*kvrpcpb.MvccGetByKeyResponse, error) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about just define a function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // Copy from https://github.com/pingcap/tidb/blob/71def9c7263432c0dfa6a5960f6db824775177c9/store/helper/helper.go#L47 add comment in helper.go |
||||||
keyLocation, err := h.RegionCache.LocateKey(tikv.NewBackoffer(context.Background(), 500), encodedKey) | ||||||
if err != nil { | ||||||
return nil, errors.Trace(err) | ||||||
} | ||||||
|
||||||
tikvReq := &tikvrpc.Request{ | ||||||
Type: tikvrpc.CmdMvccGetByKey, | ||||||
MvccGetByKey: &kvrpcpb.MvccGetByKeyRequest{ | ||||||
Key: encodedKey, | ||||||
}, | ||||||
} | ||||||
kvResp, err := h.Store.SendReq(tikv.NewBackoffer(context.Background(), 500), tikvReq, keyLocation.Region, time.Minute) | ||||||
if err != nil { | ||||||
log.Info("get MVCC by encoded key failed", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
zap.Binary("encodeKey", encodedKey), | ||||||
zap.Reflect("region", keyLocation.Region), | ||||||
zap.Binary("startKey", keyLocation.StartKey), | ||||||
zap.Binary("endKey", keyLocation.EndKey), | ||||||
zap.Reflect("kvResp", kvResp), | ||||||
zap.Error(err)) | ||||||
return nil, errors.Trace(err) | ||||||
} | ||||||
return kvResp.MvccGetByKey, nil | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not one
Helper
instance?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no performance cost and only use here so I think better just construct here, don't make Server struct complicate