From 4e42f4b89cbe60e0ca10394ed74aa4a459331540 Mon Sep 17 00:00:00 2001 From: Lynn Date: Fri, 13 Jul 2018 19:16:41 +0800 Subject: [PATCH 1/2] store: handle the error of "mismatch cluster id" --- store/tikv/backoff.go | 4 ++++ store/tikv/error.go | 2 ++ 2 files changed, 6 insertions(+) diff --git a/store/tikv/backoff.go b/store/tikv/backoff.go index b9e70af36094e..cac48ac43218e 100644 --- a/store/tikv/backoff.go +++ b/store/tikv/backoff.go @@ -17,6 +17,7 @@ import ( "fmt" "math" "math/rand" + "strings" "time" "github.com/juju/errors" @@ -233,6 +234,9 @@ func (b *Backoffer) Backoff(typ backoffType, err error) error { } } log.Warn(errMsg) + if strings.Contains(errMsg, ErrMismatchClusterID.Error()) { + log.Fatalf("critical error %v", err) + } // Use the first backoff type to generate a MySQL error. return b.types[0].TError() } diff --git a/store/tikv/error.go b/store/tikv/error.go index 54c48bfa2971e..473464d7e91b5 100644 --- a/store/tikv/error.go +++ b/store/tikv/error.go @@ -22,6 +22,8 @@ import ( var ( // ErrBodyMissing response body is missing error ErrBodyMissing = errors.New("response body is missing") + // ErrMismatchClusterID returns the error that the cluster ID of the PD client does not match the PD. + ErrMismatchClusterID = errors.New("mismatch cluster id") ) // TiDB decides whether to retry transaction by checking if error message contains From 5b4e36a30130932a61f96255d7f2a674423e6116 Mon Sep 17 00:00:00 2001 From: Lynn Date: Mon, 16 Jul 2018 11:16:30 +0800 Subject: [PATCH 2/2] store/tikv: address comments --- store/tikv/backoff.go | 6 +++--- store/tikv/error.go | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/store/tikv/backoff.go b/store/tikv/backoff.go index cac48ac43218e..84a4478fa0837 100644 --- a/store/tikv/backoff.go +++ b/store/tikv/backoff.go @@ -202,6 +202,9 @@ func (b *Backoffer) WithVars(vars *kv.Variables) *Backoffer { // Backoff sleeps a while base on the backoffType and records the error message. // It returns a retryable error if total sleep time exceeds maxSleep. func (b *Backoffer) Backoff(typ backoffType, err error) error { + if strings.Contains(err.Error(), mismatchClusterID) { + log.Fatalf("critical error %v", err) + } select { case <-b.ctx.Done(): return errors.Trace(err) @@ -234,9 +237,6 @@ func (b *Backoffer) Backoff(typ backoffType, err error) error { } } log.Warn(errMsg) - if strings.Contains(errMsg, ErrMismatchClusterID.Error()) { - log.Fatalf("critical error %v", err) - } // Use the first backoff type to generate a MySQL error. return b.types[0].TError() } diff --git a/store/tikv/error.go b/store/tikv/error.go index 473464d7e91b5..467d346d146fc 100644 --- a/store/tikv/error.go +++ b/store/tikv/error.go @@ -22,10 +22,11 @@ import ( var ( // ErrBodyMissing response body is missing error ErrBodyMissing = errors.New("response body is missing") - // ErrMismatchClusterID returns the error that the cluster ID of the PD client does not match the PD. - ErrMismatchClusterID = errors.New("mismatch cluster id") ) +// mismatchClusterID represents the message that the cluster ID of the PD client does not match the PD. +const mismatchClusterID = "mismatch cluster id" + // TiDB decides whether to retry transaction by checking if error message contains // string "try again later" literally. // In TiClient we use `errors.Annotate(err, txnRetryableMark)` to direct TiDB to