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

storage.go: Make query tikv for ddl too #757

Merged
merged 4 commits into from
Sep 30, 2019
Merged
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
66 changes: 46 additions & 20 deletions pump/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,33 +486,59 @@ func (a *Append) resolve(startTS int64) bool {

log.Warn("unknown commit stats", zap.Int64("start ts", startTS))

if pbinlog.GetDdlJobId() == 0 {
tikvQueryCount.Add(1.0)
primaryKey := pbinlog.GetPrewriteKey()
status, err := a.tiLockResolver.GetTxnStatus(uint64(pbinlog.StartTs), primaryKey)
if err != nil {
log.Error("GetTxnStatus failed", zap.Error(err))
tikvQueryCount.Add(1.0)
primaryKey := pbinlog.GetPrewriteKey()
status, err := a.tiLockResolver.GetTxnStatus(uint64(pbinlog.StartTs), primaryKey)
if err != nil {
log.Error("GetTxnStatus failed", zap.Error(err))
return false
}

// Write a commit binlog myself if the status is committed,
// otherwise we can just ignore it, we will not get the commit binlog while iterator the kv by ts
if status.IsCommitted() {
// write the commit binlog myself
cbinlog := new(pb.Binlog)
cbinlog.Tp = pb.BinlogType_Commit
cbinlog.StartTs = pbinlog.StartTs
cbinlog.CommitTs = int64(status.CommitTS())

req := a.writeBinlog(cbinlog)
if req.err != nil {
log.Error("write missing committed binlog failed",
zap.Int64("start ts", startTS),
zap.Uint64("commit ts", status.CommitTS()),
zap.Bool("isDDL", pbinlog.GetDdlJobId() > 0),
zap.Error(req.err))
return false
}

// Write a commit binlog myself if the status is committed,
// otherwise we can just ignore it, we will not get the commit binlog while iterator the kv by ts
if status.IsCommitted() {
err := a.writeCBinlog(pbinlog, int64(status.CommitTS()))
if err != nil {
log.Error("writeCBinlog failed", zap.Error(err))
return false
}
// when writeBinlog return success, the pointer will be write to kv async,
// but we need to make sure it has been write to kv when we return true in the func, then we can get this commit binlog when
// we update maxCommitTS
// write the ts -> pointer to KV here to make sure it.
pointer, err := req.valuePointer.MarshalBinary()
if err != nil {
panic(err)
}

log.Info("known txn is committed or rollback from tikv",
zap.Int64("start ts", startTS),
zap.Uint64("commit ts", status.CommitTS()))
return true
err = a.metadata.Put(encodeTSKey(req.ts()), pointer, nil)
if err != nil {
log.Error("put missing committed binlog into metadata failed",
zap.Int64("start ts", startTS),
zap.Uint64("commit ts", status.CommitTS()),
zap.Bool("isDDL", pbinlog.GetDdlJobId() > 0),
zap.Error(err))
return false
}
}

log.Error("some prewrite DDL items remain single after waiting for a long time", zap.Int64("startTS", startTS))
return false
log.Info("known txn is committed from tikv",
zap.Int64("start ts", startTS),
zap.Uint64("commit ts", status.CommitTS()),
zap.Bool("isDDL", pbinlog.GetDdlJobId() > 0))
return true

}

// GetBinlog gets binlog by ts
Expand Down