Skip to content

Commit

Permalink
*: move kv to pkg (#5773)
Browse files Browse the repository at this point in the history
ref #5766

Signed-off-by: Ryan Leung <rleungx@gmail.com>

Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
  • Loading branch information
rleungx and ti-chi-bot authored Dec 12, 2022
1 parent a2016de commit 7ab1c9c
Show file tree
Hide file tree
Showing 26 changed files with 24 additions and 44 deletions.
2 changes: 1 addition & 1 deletion pkg/election/leadership.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 0 additions & 20 deletions server/storage/kv/levedb_kv.go → pkg/storage/kv/levedb_kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion server/api/hot_status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server/gc/safepoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion server/grpc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion server/id/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
2 changes: 1 addition & 1 deletion server/keyspace/keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion server/member/member.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion server/region_syncer/history_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion server/region_syncer/history_buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion server/region_syncer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion server/storage/endpoint/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/storage/etcd_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion server/storage/hot_region_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
2 changes: 1 addition & 1 deletion server/storage/leveldb_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion server/storage/memory_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
4 changes: 2 additions & 2 deletions server/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion server/tso/allocator_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions tests/server/cluster/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down

0 comments on commit 7ab1c9c

Please sign in to comment.