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

Handle table not found error during begin txn #162

Merged
merged 1 commit into from
Sep 11, 2024
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
33 changes: 23 additions & 10 deletions pkg/ccr/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,13 @@
}
log.Debugf("resp: %v", beginTxnResp)
if beginTxnResp.GetStatus().GetStatusCode() != tstatus.TStatusCode_OK {
return xerror.Errorf(xerror.Normal, "begin txn failed, status: %v", beginTxnResp.GetStatus())
if isTableNotFound(beginTxnResp.GetStatus()) {
// The IngestBinlog and CommitTxn will rollback and retry, so the "table not found"
// error will be triggered at the BeginTxn stage, now force a new snapshot progress.
return xerror.Errorf(xerror.Meta, "begin txn failed, table is not found, status: %v", beginTxnResp.GetStatus())
} else {
return xerror.Errorf(xerror.Normal, "begin txn failed, status: %v", beginTxnResp.GetStatus())
}
}
txnId := beginTxnResp.GetTxnId()
log.Debugf("TxnId: %d, DbId: %d", txnId, beginTxnResp.GetDbId())
Expand Down Expand Up @@ -1441,7 +1447,7 @@
return err
}

j.srcMeta.GetTables()

Check failure on line 1450 in pkg/ccr/job.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `j.srcMeta.GetTables` is not checked (errcheck)

// don't support rename table when table sync
var destTableName string
Expand All @@ -1462,7 +1468,7 @@
err = j.IDest.RenameTable(destTableName, renameTable)

if err == nil {
j.destMeta.GetTables()

Check failure on line 1471 in pkg/ccr/job.go

View workflow job for this annotation

GitHub Actions / lint

Error return value of `j.destMeta.GetTables` is not checked (errcheck)
}
}

Expand Down Expand Up @@ -2142,13 +2148,7 @@
}

func isTxnCommitted(status *tstatus.TStatus) bool {
errMessages := status.GetErrorMsgs()
for _, errMessage := range errMessages {
if strings.Contains(errMessage, "is already COMMITTED") {
return true
}
}
return false
return isStatusContainsAny(status, "is already COMMITTED")
}

func isTxnNotFound(status *tstatus.TStatus) bool {
Expand All @@ -2164,10 +2164,23 @@
}

func isTxnAborted(status *tstatus.TStatus) bool {
return isStatusContainsAny(status, "is already aborted")
}

func isTableNotFound(status *tstatus.TStatus) bool {
// 1. FE FrontendServiceImpl.beginTxnImpl
// 2. FE FrontendServiceImpl.commitTxnImpl
// 3. FE Table.tryWriteLockOrMetaException
return isStatusContainsAny(status, "can't find table id:", "table not found", "unknown table")
}

func isStatusContainsAny(status *tstatus.TStatus, patterns ...string) bool {
errMessages := status.GetErrorMsgs()
for _, errMessage := range errMessages {
if strings.Contains(errMessage, "is already aborted") {
return true
for _, substr := range patterns {
if strings.Contains(errMessage, substr) {
return true
}
}
}
return false
Expand Down
Loading