From f7f48e3586b339a582833191e9df902e1d11c4ff Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Thu, 26 Nov 2020 13:43:22 +0800 Subject: [PATCH] infosync: omit the 404 error when /config/placement-rule is not existed (#21247) Signed-off-by: Ryan Leung --- domain/domain.go | 7 ------- domain/domain_test.go | 4 ++-- domain/infosync/info.go | 9 +++++++-- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/domain/domain.go b/domain/domain.go index 419e3fc44096a..d944d26021366 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -34,7 +34,6 @@ import ( "github.com/pingcap/tidb/bindinfo" "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/ddl" - "github.com/pingcap/tidb/ddl/placement" ddlutil "github.com/pingcap/tidb/ddl/util" "github.com/pingcap/tidb/domain/infosync" "github.com/pingcap/tidb/errno" @@ -150,12 +149,6 @@ func (do *Domain) loadInfoSchema(handle *infoschema.Handle, usedSchemaVersion in } bundles, err := infosync.GetAllRuleBundles(nil) - failpoint.Inject("FailPlacement", func(val failpoint.Value) { - if val.(bool) { - bundles = []*placement.Bundle{} - err = nil - } - }) if err != nil { return 0, nil, fullLoad, err } diff --git a/domain/domain_test.go b/domain/domain_test.go index 4c0a23611ad6a..17c9e81d31624 100644 --- a/domain/domain_test.go +++ b/domain/domain_test.go @@ -89,7 +89,7 @@ func unixSocketAvailable() bool { } func TestInfo(t *testing.T) { - err := failpoint.Enable("github.com/pingcap/tidb/domain/FailPlacement", `return(true)`) + err := failpoint.Enable("github.com/pingcap/tidb/domain/infosync/FailPlacement", `return(true)`) if err != nil { t.Fatal(err) } @@ -230,7 +230,7 @@ func TestInfo(t *testing.T) { t.Fatalf("dom.refreshServerIDTTL err %v", err) } - err = failpoint.Disable("github.com/pingcap/tidb/domain/FailPlacement") + err = failpoint.Disable("github.com/pingcap/tidb/domain/infosync/FailPlacement") if err != nil { t.Fatal(err) } diff --git a/domain/infosync/info.go b/domain/infosync/info.go index 0d72abc5817f1..1d3ade702db6a 100644 --- a/domain/infosync/info.go +++ b/domain/infosync/info.go @@ -330,6 +330,12 @@ func doRequest(ctx context.Context, addrs []string, route, method string, body i } res, err = util2.InternalHTTPClient().Do(req) + failpoint.Inject("FailPlacement", func(val failpoint.Value) { + if val.(bool) { + res = &http.Response{StatusCode: http.StatusNotFound, Body: http.NoBody} + err = nil + } + }) if err == nil { bodyBytes, err := ioutil.ReadAll(res.Body) if err != nil { @@ -337,8 +343,7 @@ func doRequest(ctx context.Context, addrs []string, route, method string, body i } if res.StatusCode != http.StatusOK { err = errors.Errorf("%s", bodyBytes) - // ignore if placement rules feature is not enabled - if strings.HasPrefix(err.Error(), `"placement rules feature is disabled"`) { + if res.StatusCode == http.StatusNotFound || res.StatusCode == http.StatusPreconditionFailed { err = nil bodyBytes = nil }