Skip to content

Commit

Permalink
Merge branch 'master' into fix-help-message
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Nov 3, 2021
2 parents 120310f + 59ec446 commit da45914
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
5 changes: 4 additions & 1 deletion server/kv/etcd_kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/log"
"github.com/tikv/pd/pkg/errs"
"github.com/tikv/pd/pkg/etcdutil"
Expand Down Expand Up @@ -85,8 +86,10 @@ func (kv *etcdKVBase) LoadRange(key, endKey string, limit int) ([]string, []stri
}

func (kv *etcdKVBase) Save(key, value string) error {
failpoint.Inject("etcdSaveFailed", func() {
failpoint.Return(errors.New("save failed"))
})
key = path.Join(kv.rootPath, key)

txn := NewSlowLogTxn(kv.client)
resp, err := txn.Then(clientv3.OpPut(key, value)).Commit()
if err != nil {
Expand Down
18 changes: 4 additions & 14 deletions tests/server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (

"github.com/coreos/go-semver/semver"
. "github.com/pingcap/check"
"github.com/pingcap/errors"
"github.com/pingcap/failpoint"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/pingcap/kvproto/pkg/pdpb"
Expand Down Expand Up @@ -72,14 +71,6 @@ func (s *clusterTestSuite) TearDownSuite(c *C) {
s.cancel()
}

type testErrorKV struct {
kv.Base
}

func (kv *testErrorKV) Save(key, value string) error {
return errors.New("save failed")
}

func (s *clusterTestSuite) TestBootstrap(c *C) {
tc, err := tests.NewTestCluster(s.ctx, 1)
defer tc.Destroy()
Expand Down Expand Up @@ -615,8 +606,7 @@ func (s *clusterTestSuite) TestSetScheduleOpt(c *C) {
c.Assert(persistOptions.GetLabelPropertyConfig()[typ], HasLen, 0)

// PUT GET failed
oldStorage := svr.GetStorage()
svr.SetStorage(core.NewStorage(&testErrorKV{}))
c.Assert(failpoint.Enable("github.com/tikv/pd/server/kv/etcdSaveFailed", `return(true)`), IsNil)
replicationCfg.MaxReplicas = 7
scheduleCfg.MaxSnapshotCount = 20
pdServerCfg.UseRegionStorage = false
Expand All @@ -632,15 +622,15 @@ func (s *clusterTestSuite) TestSetScheduleOpt(c *C) {
c.Assert(persistOptions.GetLabelPropertyConfig()[typ], HasLen, 0)

// DELETE failed
svr.SetStorage(oldStorage)
c.Assert(failpoint.Disable("github.com/tikv/pd/server/kv/etcdSaveFailed"), IsNil)
c.Assert(svr.SetReplicationConfig(*replicationCfg), IsNil)

svr.SetStorage(core.NewStorage(&testErrorKV{}))
c.Assert(failpoint.Enable("github.com/tikv/pd/server/kv/etcdSaveFailed", `return(true)`), IsNil)
c.Assert(svr.DeleteLabelProperty(typ, labelKey, labelValue), NotNil)

c.Assert(persistOptions.GetLabelPropertyConfig()[typ][0].Key, Equals, "testKey")
c.Assert(persistOptions.GetLabelPropertyConfig()[typ][0].Value, Equals, "testValue")
svr.SetStorage(oldStorage)
c.Assert(failpoint.Disable("github.com/tikv/pd/server/kv/etcdSaveFailed"), IsNil)
}

func (s *clusterTestSuite) TestLoadClusterInfo(c *C) {
Expand Down

0 comments on commit da45914

Please sign in to comment.