Repository: tikv/pd
Pull request #5773 (2022-12-12 07:52:08)

*: move kv to pkg
Signed-off-by: Ryan Leung <rleungx@gmail.com>

<!--
Thank you for working on PD! Please read PD's [CONTRIBUTING](https://github.com/tikv/pd/blob/master/CONTRIBUTING.md) document **BEFORE** filing this PR.
PR Title Format:
1. pkg [, pkg2, pkg3]: what's changed
2. *: what's changed
-->

### What problem does this PR solve?

<!--

Please create an issue first to describe the problem.
There MUST be one line starting with "Issue Number:  " and 
linking the relevant issues via the "close" or "ref".
For more info, check https://github.com/tikv/pd/blob/master/CONTRIBUTING.md#linking-issues.

-->
Issue Number: Ref #5766.

### What is changed and how does it work?

This PR moves `kv` package from `server` to `pkg` so that tso logic won't rely on the server.

<!--

You could use the "commit message" code block to add more description to the final commit message.
For more info, check https://github.com/tikv/pd/blob/master/CONTRIBUTING.md#format-of-the-commit-message.

-->

```commit-message
```

### Check List

<!-- Remove the items that are not applicable. -->

Tests

<!-- At least one of these tests must be included. -->

- Unit test
### Release note

<!-- A bugfix or a new feature needs a release note. If there is no need release note, just uncomment the below line. -->

```release-note
None
```


ti-chi-bot: [REVIEW NOTIFICATION]

This pull request has not been approved.


To complete the [pull request process](https://book.prow.tidb.net/#/en/workflows/pr), please ask the reviewers in the [list](https://prow.tidb.net/tichi/repos/tikv/pd/pulls/5773/owners) to review by filling `/cc @reviewer` in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the [list](https://prow.tidb.net/tichi/repos/tikv/pd/pulls/5773/owners) by filling  `/assign @committer` in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found [here](https://prow.tidb.net/command-help?repo=tikv%2Fpd).

<details>

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.
</details>

<!--Review Notification Identifier-->
codecov[bot]: # [Codecov](https://codecov.io/gh/tikv/pd/pull/5773?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv) Report
Base: **75.61**% // Head: **75.63**% // Increases project coverage by **`+0.02%`** :tada:
> Coverage data is based on head [(`68ddc9a`)](https://codecov.io/gh/tikv/pd/pull/5773?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv) compared to base [(`776003b`)](https://codecov.io/gh/tikv/pd/commit/776003b3c41c5dd8e79882310d6d96a3e467350c?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv).
> Patch has no changes to coverable lines.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #5773      +/-   ##
==========================================
+ Coverage   75.61%   75.63%   +0.02%     
==========================================
  Files         329      329              
  Lines       32965    32957       -8     
==========================================
+ Hits        24925    24926       +1     
+ Misses       5896     5881      -15     
- Partials     2144     2150       +6     
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `75.63% <ø> (+0.02%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/tikv/pd/pull/5773?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv) | Coverage Δ | |
|---|---|---|
| [pkg/election/leadership.go](https://codecov.io/gh/tikv/pd/pull/5773/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv#diff-cGtnL2VsZWN0aW9uL2xlYWRlcnNoaXAuZ28=) | `78.35% <ø> (+3.09%)` | :arrow_up: |
| [pkg/storage/kv/etcd\_kv.go](https://codecov.io/gh/tikv/pd/pull/5773/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv#diff-cGtnL3N0b3JhZ2Uva3YvZXRjZF9rdi5nbw==) | `79.71% <ø> (ø)` | |
| [pkg/storage/kv/levedb\_kv.go](https://codecov.io/gh/tikv/pd/pull/5773/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv#diff-cGtnL3N0b3JhZ2Uva3YvbGV2ZWRiX2t2Lmdv) | `86.95% <ø> (ø)` | |
| [pkg/storage/kv/mem\_kv.go](https://codecov.io/gh/tikv/pd/pull/5773/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv#diff-cGtnL3N0b3JhZ2Uva3YvbWVtX2t2Lmdv) | `100.00% <ø> (ø)` | |
| [pkg/storage/kv/metrics.go](https://codecov.io/gh/tikv/pd/pull/5773/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv#diff-cGtnL3N0b3JhZ2Uva3YvbWV0cmljcy5nbw==) | `100.00% <ø> (ø)` | |
| [server/grpc\_service.go](https://codecov.io/gh/tikv/pd/pull/5773/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv#diff-c2VydmVyL2dycGNfc2VydmljZS5nbw==) | `49.79% <ø> (+0.16%)` | :arrow_up: |
| [server/id/id.go](https://codecov.io/gh/tikv/pd/pull/5773/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv#diff-c2VydmVyL2lkL2lkLmdv) | `83.05% <ø> (ø)` | |
| [server/member/member.go](https://codecov.io/gh/tikv/pd/pull/5773/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv#diff-c2VydmVyL21lbWJlci9tZW1iZXIuZ28=) | `62.10% <ø> (-3.69%)` | :arrow_down: |
| [server/region\_syncer/history\_buffer.go](https://codecov.io/gh/tikv/pd/pull/5773/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv#diff-c2VydmVyL3JlZ2lvbl9zeW5jZXIvaGlzdG9yeV9idWZmZXIuZ28=) | `78.46% <ø> (ø)` | |
| [server/region\_syncer/server.go](https://codecov.io/gh/tikv/pd/pull/5773/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv#diff-c2VydmVyL3JlZ2lvbl9zeW5jZXIvc2VydmVyLmdv) | `82.96% <ø> (ø)` | |
| ... and [32 more](https://codecov.io/gh/tikv/pd/pull/5773/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv) | |

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv)

</details>

[:umbrella: View full report at Codecov](https://codecov.io/gh/tikv/pd/pull/5773?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv).   
:loudspeaker: Do you have feedback about the report comment? [Let us know in this issue](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=tikv).

nolouch: /merge
ti-chi-bot: @nolouch: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests


<details>

Instructions for interacting with me using PR comments are available [here](https://prow.tidb.net/command-help).  If you have questions or suggestions related to my behavior, please file an issue against the [ti-community-infra/tichi](https://github.com/ti-community-infra/tichi/issues/new?title=Prow%20issue:) repository.
</details>
ti-chi-bot: This pull request has been accepted and is ready to merge. <details>Commit hash: 68ddc9a30262b0e41a014e3600408be70cd1b4cc</details>
ti-chi-bot: @rleungx: Your PR was out of date, I have automatically updated it for you.

If the CI test fails, you just re-trigger the test that failed and the bot will merge the PR for you after the CI passes.


<details>

Instructions for interacting with me using PR comments are available [here](https://prow.tidb.net/command-help).  If you have questions or suggestions related to my behavior, please file an issue against the [ti-community-infra/tichi](https://github.com/ti-community-infra/tichi/issues/new?title=Prow%20issue:) repository.
</details>

Patch:
diff --git a/pkg/election/leadership.go b/pkg/election/leadership.go
index 3a242d620..30485a863 100644
--- a/pkg/election/leadership.go
+++ b/pkg/election/leadership.go
@@ -22,8 +22,8 @@ import (
 	"github.com/pingcap/kvproto/pkg/pdpb"
 	"github.com/pingcap/log"
 	"github.com/tikv/pd/pkg/errs"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/pkg/utils/etcdutil"
-	"github.com/tikv/pd/server/storage/kv"
 	"go.etcd.io/etcd/clientv3"
 	"go.etcd.io/etcd/mvcc/mvccpb"
 	"go.uber.org/zap"
diff --git a/server/storage/kv/etcd_kv.go b/pkg/storage/kv/etcd_kv.go
similarity index 100%
rename from server/storage/kv/etcd_kv.go
rename to pkg/storage/kv/etcd_kv.go
diff --git a/server/storage/kv/kv.go b/pkg/storage/kv/kv.go
similarity index 100%
rename from server/storage/kv/kv.go
rename to pkg/storage/kv/kv.go
diff --git a/server/storage/kv/kv_test.go b/pkg/storage/kv/kv_test.go
similarity index 100%
rename from server/storage/kv/kv_test.go
rename to pkg/storage/kv/kv_test.go
diff --git a/server/storage/kv/levedb_kv.go b/pkg/storage/kv/levedb_kv.go
similarity index 80%
rename from server/storage/kv/levedb_kv.go
rename to pkg/storage/kv/levedb_kv.go
index 7f134709b..92dd05a78 100644
--- a/server/storage/kv/levedb_kv.go
+++ b/pkg/storage/kv/levedb_kv.go
@@ -15,9 +15,7 @@
 package kv
 
 import (
-	"github.com/gogo/protobuf/proto"
 	"github.com/pingcap/errors"
-	"github.com/pingcap/kvproto/pkg/metapb"
 	"github.com/syndtr/goleveldb/leveldb"
 	"github.com/syndtr/goleveldb/leveldb/util"
 	"github.com/tikv/pd/pkg/errs"
@@ -76,21 +74,3 @@ func (kv *LevelDBKV) Save(key, value string) error {
 func (kv *LevelDBKV) Remove(key string) error {
 	return errors.WithStack(kv.Delete([]byte(key), nil))
 }
-
-// SaveRegions stores some regions.
-func (kv *LevelDBKV) SaveRegions(regions map[string]*metapb.Region) error {
-	batch := new(leveldb.Batch)
-
-	for key, r := range regions {
-		value, err := proto.Marshal(r)
-		if err != nil {
-			return errs.ErrProtoMarshal.Wrap(err).GenWithStackByCause()
-		}
-		batch.Put([]byte(key), value)
-	}
-
-	if err := kv.Write(batch, nil); err != nil {
-		return errs.ErrLevelDBWrite.Wrap(err).GenWithStackByCause()
-	}
-	return nil
-}
diff --git a/server/grpc_service.go b/server/grpc_service.go
index 75c1d081d..7939c1e0d 100644
--- a/server/grpc_service.go
+++ b/server/grpc_service.go
@@ -28,13 +28,13 @@ import (
 	"github.com/pingcap/kvproto/pkg/pdpb"
 	"github.com/pingcap/log"
 	"github.com/tikv/pd/pkg/errs"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/pkg/utils/grpcutil"
 	"github.com/tikv/pd/pkg/utils/logutil"
 	"github.com/tikv/pd/pkg/utils/tsoutil"
 	"github.com/tikv/pd/server/cluster"
 	"github.com/tikv/pd/server/core"
 	"github.com/tikv/pd/server/storage/endpoint"
-	"github.com/tikv/pd/server/storage/kv"
 	"github.com/tikv/pd/server/tso"
 	"github.com/tikv/pd/server/versioninfo"
 	"go.etcd.io/etcd/clientv3"
diff --git a/server/id/id.go b/server/id/id.go
index 8bb759d6d..d08897172 100644
--- a/server/id/id.go
+++ b/server/id/id.go
@@ -20,10 +20,10 @@ import (
 	"github.com/pingcap/log"
 	"github.com/prometheus/client_golang/prometheus"
 	"github.com/tikv/pd/pkg/errs"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/pkg/utils/etcdutil"
 	"github.com/tikv/pd/pkg/utils/syncutil"
 	"github.com/tikv/pd/pkg/utils/typeutil"
-	"github.com/tikv/pd/server/storage/kv"
 	"go.etcd.io/etcd/clientv3"
 	"go.uber.org/zap"
 )
diff --git a/server/member/member.go b/server/member/member.go
index 13c8ad007..30a03922e 100644
--- a/server/member/member.go
+++ b/server/member/member.go
@@ -31,9 +31,9 @@ import (
 	"github.com/pingcap/log"
 	"github.com/tikv/pd/pkg/election"
 	"github.com/tikv/pd/pkg/errs"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/pkg/utils/etcdutil"
 	"github.com/tikv/pd/server/config"
-	"github.com/tikv/pd/server/storage/kv"
 	"go.etcd.io/etcd/clientv3"
 	"go.etcd.io/etcd/embed"
 	"go.uber.org/zap"
diff --git a/server/region_syncer/history_buffer.go b/server/region_syncer/history_buffer.go
index 1a3387b7f..a8b074984 100644
--- a/server/region_syncer/history_buffer.go
+++ b/server/region_syncer/history_buffer.go
@@ -19,9 +19,9 @@ import (
 
 	"github.com/pingcap/log"
 	"github.com/tikv/pd/pkg/errs"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/pkg/utils/syncutil"
 	"github.com/tikv/pd/server/core"
-	"github.com/tikv/pd/server/storage/kv"
 	"go.uber.org/zap"
 )
 
diff --git a/server/region_syncer/server.go b/server/region_syncer/server.go
index ddca35e43..f8dbb8f1a 100644
--- a/server/region_syncer/server.go
+++ b/server/region_syncer/server.go
@@ -28,11 +28,11 @@ import (
 	"github.com/pingcap/log"
 	"github.com/tikv/pd/pkg/errs"
 	"github.com/tikv/pd/pkg/ratelimit"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/pkg/utils/grpcutil"
 	"github.com/tikv/pd/pkg/utils/syncutil"
 	"github.com/tikv/pd/server/core"
 	"github.com/tikv/pd/server/storage"
-	"github.com/tikv/pd/server/storage/kv"
 	"go.uber.org/zap"
 	"google.golang.org/grpc/codes"
 	"google.golang.org/grpc/status"
diff --git a/server/server.go b/server/server.go
index 807044e87..1b2540aab 100644
--- a/server/server.go
+++ b/server/server.go
@@ -42,6 +42,7 @@ import (
 	"github.com/tikv/pd/pkg/audit"
 	"github.com/tikv/pd/pkg/errs"
 	"github.com/tikv/pd/pkg/ratelimit"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/pkg/systimemon"
 	"github.com/tikv/pd/pkg/utils/apiutil"
 	"github.com/tikv/pd/pkg/utils/etcdutil"
@@ -64,7 +65,6 @@ import (
 	"github.com/tikv/pd/server/schedule/placement"
 	"github.com/tikv/pd/server/storage"
 	"github.com/tikv/pd/server/storage/endpoint"
-	"github.com/tikv/pd/server/storage/kv"
 	"github.com/tikv/pd/server/tso"
 	"github.com/tikv/pd/server/versioninfo"
 	"github.com/urfave/negroni"
diff --git a/server/storage/endpoint/endpoint.go b/server/storage/endpoint/endpoint.go
index d10c40e6b..362676898 100644
--- a/server/storage/endpoint/endpoint.go
+++ b/server/storage/endpoint/endpoint.go
@@ -15,8 +15,8 @@
 package endpoint
 
 import (
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/server/encryptionkm"
-	"github.com/tikv/pd/server/storage/kv"
 )
 
 // StorageEndpoint is the base underlying storage endpoint for all other upper
diff --git a/server/storage/etcd_backend.go b/server/storage/etcd_backend.go
index 18d67336d..18f18f8f9 100644
--- a/server/storage/etcd_backend.go
+++ b/server/storage/etcd_backend.go
@@ -15,8 +15,8 @@
 package storage
 
 import (
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/server/storage/endpoint"
-	"github.com/tikv/pd/server/storage/kv"
 	"go.etcd.io/etcd/clientv3"
 )
 
diff --git a/server/storage/hot_region_storage.go b/server/storage/hot_region_storage.go
index 6e9e5038d..67cf615ad 100644
--- a/server/storage/hot_region_storage.go
+++ b/server/storage/hot_region_storage.go
@@ -32,10 +32,10 @@ import (
 	"github.com/syndtr/goleveldb/leveldb/util"
 	"github.com/tikv/pd/pkg/encryption"
 	"github.com/tikv/pd/pkg/errs"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/pkg/utils/syncutil"
 	"github.com/tikv/pd/server/core"
 	"github.com/tikv/pd/server/encryptionkm"
-	"github.com/tikv/pd/server/storage/kv"
 	"go.uber.org/zap"
 )
 
diff --git a/server/storage/leveldb_backend.go b/server/storage/leveldb_backend.go
index b9565cd31..ec16831c7 100644
--- a/server/storage/leveldb_backend.go
+++ b/server/storage/leveldb_backend.go
@@ -25,10 +25,10 @@ import (
 	"github.com/syndtr/goleveldb/leveldb"
 	"github.com/tikv/pd/pkg/encryption"
 	"github.com/tikv/pd/pkg/errs"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/pkg/utils/syncutil"
 	"github.com/tikv/pd/server/encryptionkm"
 	"github.com/tikv/pd/server/storage/endpoint"
-	"github.com/tikv/pd/server/storage/kv"
 )
 
 const (
diff --git a/server/storage/memory_backend.go b/server/storage/memory_backend.go
index a648170a7..07b5279aa 100644
--- a/server/storage/memory_backend.go
+++ b/server/storage/memory_backend.go
@@ -15,8 +15,8 @@
 package storage
 
 import (
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/server/storage/endpoint"
-	"github.com/tikv/pd/server/storage/kv"
 )
 
 // memoryStorage is a storage that stores data in a memory B-Tree without any locks,
diff --git a/server/storage/storage.go b/server/storage/storage.go
index 3e4cf6c1a..73ddcb6ab 100644
--- a/server/storage/storage.go
+++ b/server/storage/storage.go
@@ -19,11 +19,11 @@ import (
 	"sync/atomic"
 
 	"github.com/pingcap/kvproto/pkg/metapb"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/pkg/utils/syncutil"
 	"github.com/tikv/pd/server/core"
 	"github.com/tikv/pd/server/encryptionkm"
 	"github.com/tikv/pd/server/storage/endpoint"
-	"github.com/tikv/pd/server/storage/kv"
 	"go.etcd.io/etcd/clientv3"
 )
 
diff --git a/server/tso/allocator_manager.go b/server/tso/allocator_manager.go
index 7676357d3..1d53ec7cd 100644
--- a/server/tso/allocator_manager.go
+++ b/server/tso/allocator_manager.go
@@ -31,12 +31,12 @@ import (
 	"github.com/tikv/pd/pkg/election"
 	"github.com/tikv/pd/pkg/errs"
 	"github.com/tikv/pd/pkg/slice"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/pkg/utils/etcdutil"
 	"github.com/tikv/pd/pkg/utils/grpcutil"
 	"github.com/tikv/pd/pkg/utils/syncutil"
 	"github.com/tikv/pd/server/config"
 	"github.com/tikv/pd/server/member"
-	"github.com/tikv/pd/server/storage/kv"
 	"go.etcd.io/etcd/clientv3"
 	"go.uber.org/zap"
 	"google.golang.org/grpc"


Test patch:
diff --git a/server/storage/kv/mem_kv.go b/pkg/storage/kv/mem_kv.go
similarity index 100%
rename from server/storage/kv/mem_kv.go
rename to pkg/storage/kv/mem_kv.go
diff --git a/server/storage/kv/metrics.go b/pkg/storage/kv/metrics.go
similarity index 100%
rename from server/storage/kv/metrics.go
rename to pkg/storage/kv/metrics.go
diff --git a/server/api/hot_status_test.go b/server/api/hot_status_test.go
index be18d2202..11fa3e326 100644
--- a/server/api/hot_status_test.go
+++ b/server/api/hot_status_test.go
@@ -22,11 +22,11 @@ import (
 
 	"github.com/stretchr/testify/suite"
 	"github.com/syndtr/goleveldb/leveldb"
+	"github.com/tikv/pd/pkg/storage/kv"
 	tu "github.com/tikv/pd/pkg/utils/testutil"
 	"github.com/tikv/pd/server"
 	_ "github.com/tikv/pd/server/schedulers"
 	"github.com/tikv/pd/server/storage"
-	"github.com/tikv/pd/server/storage/kv"
 )
 
 type hotStatusTestSuite struct {
diff --git a/server/gc/safepoint_test.go b/server/gc/safepoint_test.go
index aebf8033d..dd42745b3 100644
--- a/server/gc/safepoint_test.go
+++ b/server/gc/safepoint_test.go
@@ -21,8 +21,8 @@ import (
 	"time"
 
 	"github.com/stretchr/testify/require"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/server/storage/endpoint"
-	"github.com/tikv/pd/server/storage/kv"
 )
 
 func newGCStorage() endpoint.GCSafePointStorage {
diff --git a/server/keyspace/keyspace_test.go b/server/keyspace/keyspace_test.go
index 06155c613..ed9a30f73 100644
--- a/server/keyspace/keyspace_test.go
+++ b/server/keyspace/keyspace_test.go
@@ -25,8 +25,8 @@ import (
 	"github.com/pingcap/kvproto/pkg/keyspacepb"
 	"github.com/stretchr/testify/require"
 	"github.com/tikv/pd/pkg/mock/mockid"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/server/storage/endpoint"
-	"github.com/tikv/pd/server/storage/kv"
 )
 
 const (
diff --git a/server/region_syncer/history_buffer_test.go b/server/region_syncer/history_buffer_test.go
index 26e6a113d..e74e55220 100644
--- a/server/region_syncer/history_buffer_test.go
+++ b/server/region_syncer/history_buffer_test.go
@@ -19,8 +19,8 @@ import (
 
 	"github.com/pingcap/kvproto/pkg/metapb"
 	"github.com/stretchr/testify/require"
+	"github.com/tikv/pd/pkg/storage/kv"
 	"github.com/tikv/pd/server/core"
-	"github.com/tikv/pd/server/storage/kv"
 )
 
 func TestBufferSize(t *testing.T) {
diff --git a/server/storage/storage_test.go b/server/storage/storage_test.go
index 342ad302d..32e994f2b 100644
--- a/server/storage/storage_test.go
+++ b/server/storage/storage_test.go
@@ -268,7 +268,7 @@ func TestLoadRegionsToCache(t *testing.T) {
 
 func TestLoadRegionsExceedRangeLimit(t *testing.T) {
 	re := require.New(t)
-	re.NoError(failpoint.Enable("github.com/tikv/pd/server/storage/kv/withRangeLimit", "return(500)"))
+	re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/storage/kv/withRangeLimit", "return(500)"))
 	storage := NewStorageWithMemoryBackend()
 	cache := core.NewBasicCluster()
 
@@ -279,7 +279,7 @@ func TestLoadRegionsExceedRangeLimit(t *testing.T) {
 	for _, region := range cache.GetMetaRegions() {
 		re.Equal(regions[region.GetId()], region)
 	}
-	re.NoError(failpoint.Disable("github.com/tikv/pd/server/storage/kv/withRangeLimit"))
+	re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/storage/kv/withRangeLimit"))
 }
 
 func TestTrySwitchRegionStorage(t *testing.T) {
diff --git a/tests/server/cluster/cluster_test.go b/tests/server/cluster/cluster_test.go
index 42618f8bd..a4b0f6bfc 100644
--- a/tests/server/cluster/cluster_test.go
+++ b/tests/server/cluster/cluster_test.go
@@ -773,7 +773,7 @@ func TestSetScheduleOpt(t *testing.T) {
 	re.Empty(persistOptions.GetLabelPropertyConfig()[typ])
 
 	// PUT GET failed
-	re.NoError(failpoint.Enable("github.com/tikv/pd/server/storage/kv/etcdSaveFailed", `return(true)`))
+	re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/storage/kv/etcdSaveFailed", `return(true)`))
 	replicationCfg.MaxReplicas = 7
 	scheduleCfg.MaxSnapshotCount = 20
 	pdServerCfg.UseRegionStorage = false
@@ -787,13 +787,13 @@ func TestSetScheduleOpt(t *testing.T) {
 	re.Empty(persistOptions.GetLabelPropertyConfig()[typ])
 
 	// DELETE failed
-	re.NoError(failpoint.Disable("github.com/tikv/pd/server/storage/kv/etcdSaveFailed"))
+	re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/storage/kv/etcdSaveFailed"))
 	re.NoError(svr.SetReplicationConfig(*replicationCfg))
-	re.NoError(failpoint.Enable("github.com/tikv/pd/server/storage/kv/etcdSaveFailed", `return(true)`))
+	re.NoError(failpoint.Enable("github.com/tikv/pd/pkg/storage/kv/etcdSaveFailed", `return(true)`))
 	re.Error(svr.DeleteLabelProperty(typ, labelKey, labelValue))
 	re.Equal("testKey", persistOptions.GetLabelPropertyConfig()[typ][0].Key)
 	re.Equal("testValue", persistOptions.GetLabelPropertyConfig()[typ][0].Value)
-	re.NoError(failpoint.Disable("github.com/tikv/pd/server/storage/kv/etcdSaveFailed"))
+	re.NoError(failpoint.Disable("github.com/tikv/pd/pkg/storage/kv/etcdSaveFailed"))
 }
 
 func TestLoadClusterInfo(t *testing.T) {