From 67bba625443689266e8449686adeeb44a392fa71 Mon Sep 17 00:00:00 2001 From: Victor1319 <834863182@qq.com> Date: Mon, 17 Jul 2023 07:40:17 +0800 Subject: [PATCH] refactor(master & authnode): split package rocksdb from raftstore to avoid import by other. Signed-off-by: Victor1319 <834863182@qq.com> --- authnode/keystore_fsm.go | 6 +++--- authnode/server.go | 5 +++-- master/id_allocator.go | 5 +++-- master/metadata_fsm.go | 2 +- master/server.go | 5 +++-- raftstore/{ => raftstore_db}/store_rocksdb.go | 2 +- 6 files changed, 14 insertions(+), 11 deletions(-) rename raftstore/{ => raftstore_db}/store_rocksdb.go (99%) diff --git a/authnode/keystore_fsm.go b/authnode/keystore_fsm.go index 4db956601..2323c829d 100644 --- a/authnode/keystore_fsm.go +++ b/authnode/keystore_fsm.go @@ -17,6 +17,7 @@ package authnode import ( "encoding/json" "fmt" + "github.com/cubefs/cubefs/raftstore/raftstore_db" "io" "strconv" "strings" @@ -24,7 +25,6 @@ import ( "github.com/cubefs/cubefs/depends/tiglabs/raft" "github.com/cubefs/cubefs/depends/tiglabs/raft/proto" - "github.com/cubefs/cubefs/raftstore" "github.com/cubefs/cubefs/util/keystore" "github.com/cubefs/cubefs/util/log" ) @@ -43,7 +43,7 @@ type raftApplySnapshotHandler func() // KeystoreFsm represents the finite state machine of a keystore type KeystoreFsm struct { - store *raftstore.RocksDBStore + store *raftstore_db.RocksDBStore rs *raft.RaftServer applied uint64 retainLogs uint64 @@ -59,7 +59,7 @@ type KeystoreFsm struct { id uint64 // current id of server } -func newKeystoreFsm(store *raftstore.RocksDBStore, retainsLog uint64, rs *raft.RaftServer) (fsm *KeystoreFsm) { +func newKeystoreFsm(store *raftstore_db.RocksDBStore, retainsLog uint64, rs *raft.RaftServer) (fsm *KeystoreFsm) { fsm = new(KeystoreFsm) fsm.store = store fsm.rs = rs diff --git a/authnode/server.go b/authnode/server.go index 988e56878..f9d47c69c 100644 --- a/authnode/server.go +++ b/authnode/server.go @@ -16,6 +16,7 @@ package authnode import ( "fmt" + "github.com/cubefs/cubefs/raftstore/raftstore_db" "io/ioutil" syslog "log" "net/http" @@ -61,7 +62,7 @@ type Server struct { leaderInfo *LeaderInfo config *clusterConfig cluster *Cluster - rocksDBStore *raftstore.RocksDBStore + rocksDBStore *raftstore_db.RocksDBStore raftStore raftstore.RaftStore fsm *KeystoreFsm partition raftstore.Partition @@ -191,7 +192,7 @@ func (m *Server) Start(cfg *config.Config) (err error) { log.LogError(errors.Stack(err)) return } - if m.rocksDBStore, err = raftstore.NewRocksDBStore(m.storeDir, LRUCacheSize, WriteBufferSize); err != nil { + if m.rocksDBStore, err = raftstore_db.NewRocksDBStore(m.storeDir, LRUCacheSize, WriteBufferSize); err != nil { log.LogErrorf("Start: init RocksDB fail: err(%v)", err) return } diff --git a/master/id_allocator.go b/master/id_allocator.go index 7f0c59f98..fe51fcdfd 100644 --- a/master/id_allocator.go +++ b/master/id_allocator.go @@ -22,6 +22,7 @@ import ( "sync/atomic" "github.com/cubefs/cubefs/raftstore" + "github.com/cubefs/cubefs/raftstore/raftstore_db" "github.com/cubefs/cubefs/util/log" ) @@ -32,7 +33,7 @@ type IDAllocator struct { commonID uint64 clientID uint64 quotaID uint32 - store *raftstore.RocksDBStore + store *raftstore_db.RocksDBStore partition raftstore.Partition dpIDLock sync.RWMutex mpIDLock sync.RWMutex @@ -40,7 +41,7 @@ type IDAllocator struct { qaIDLock sync.RWMutex } -func newIDAllocator(store *raftstore.RocksDBStore, partition raftstore.Partition) (alloc *IDAllocator) { +func newIDAllocator(store *raftstore_db.RocksDBStore, partition raftstore.Partition) (alloc *IDAllocator) { alloc = new(IDAllocator) alloc.store = store alloc.partition = partition diff --git a/master/metadata_fsm.go b/master/metadata_fsm.go index b2d549bab..4001ac915 100644 --- a/master/metadata_fsm.go +++ b/master/metadata_fsm.go @@ -22,7 +22,7 @@ import ( "github.com/cubefs/cubefs/depends/tiglabs/raft" "github.com/cubefs/cubefs/depends/tiglabs/raft/proto" - "github.com/cubefs/cubefs/raftstore" + raftstore "github.com/cubefs/cubefs/raftstore/raftstore_db" "github.com/cubefs/cubefs/util/log" "github.com/cubefs/cubefs/util/stat" ) diff --git a/master/server.go b/master/server.go index 107bc7dcf..b650727d8 100644 --- a/master/server.go +++ b/master/server.go @@ -17,6 +17,7 @@ package master import ( "context" "fmt" + "github.com/cubefs/cubefs/raftstore/raftstore_db" syslog "log" "net/http" "net/http/httputil" @@ -117,7 +118,7 @@ type Server struct { config *clusterConfig cluster *Cluster user *User - rocksDBStore *raftstore.RocksDBStore + rocksDBStore *raftstore_db.RocksDBStore raftStore raftstore.RaftStore fsm *MetadataFsm partition raftstore.Partition @@ -143,7 +144,7 @@ func (m *Server) Start(cfg *config.Config) (err error) { return } - if m.rocksDBStore, err = raftstore.NewRocksDBStore(m.storeDir, LRUCacheSize, WriteBufferSize); err != nil { + if m.rocksDBStore, err = raftstore_db.NewRocksDBStore(m.storeDir, LRUCacheSize, WriteBufferSize); err != nil { return } diff --git a/raftstore/store_rocksdb.go b/raftstore/raftstore_db/store_rocksdb.go similarity index 99% rename from raftstore/store_rocksdb.go rename to raftstore/raftstore_db/store_rocksdb.go index a69b9addc..b7428c61d 100644 --- a/raftstore/store_rocksdb.go +++ b/raftstore/raftstore_db/store_rocksdb.go @@ -12,7 +12,7 @@ // implied. See the License for the specific language governing // permissions and limitations under the License. -package raftstore +package raftstore_db import ( "fmt"