diff --git a/pkg/election/leadership.go b/pkg/election/leadership.go index 3a242d62046..30485a863da 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 7f134709bd1..92dd05a7810 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/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 be18d2202da..11fa3e326aa 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 aebf8033dea..dd42745b3fe 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/grpc_service.go b/server/grpc_service.go index 75c1d081dbf..7939c1e0de1 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 8bb759d6dee..d0889717242 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/keyspace/keyspace_test.go b/server/keyspace/keyspace_test.go index 06155c613c7..ed9a30f735c 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/member/member.go b/server/member/member.go index 13c8ad00721..30a03922e98 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 1a3387b7f73..a8b07498458 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/history_buffer_test.go b/server/region_syncer/history_buffer_test.go index 26e6a113dad..e74e55220fc 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/region_syncer/server.go b/server/region_syncer/server.go index ddca35e433e..f8dbb8f1ab4 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 807044e87a9..1b2540aab29 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 d10c40e6b45..36267689848 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 18d67336d56..18f18f8f95a 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 6e9e5038d9a..67cf615adef 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 b9565cd3165..ec16831c75f 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 a648170a7a5..07b5279aa2e 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 3e4cf6c1a39..73ddcb6ab7b 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/storage/storage_test.go b/server/storage/storage_test.go index 342ad302d9c..32e994f2b73 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/server/tso/allocator_manager.go b/server/tso/allocator_manager.go index 7676357d3be..1d53ec7cd4e 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" diff --git a/tests/server/cluster/cluster_test.go b/tests/server/cluster/cluster_test.go index 42618f8bdc5..a4b0f6bfcdd 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) {