refactor(master): refactor the code of vol struct and cluster struct

:

Signed-off-by: leonrayang <chl696@sina.com>
This commit is contained in:
leonrayang 2024-06-20 11:37:09 +08:00 committed by AmazingChi
parent c551e5dbc2
commit 1b9b48f846
3 changed files with 169 additions and 126 deletions

View File

@ -42,72 +42,95 @@ import (
"github.com/cubefs/cubefs/util/log"
)
// Cluster stores all the cluster-level information.
type Cluster struct {
Name string
CreateTime int64
vols map[string]*Vol
delayDeleteVolsInfo []*delayDeleteVolInfo
stopc chan bool
dataNodes sync.Map
metaNodes sync.Map
volMutex sync.RWMutex // volume mutex
createVolMutex sync.RWMutex // create volume mutex
deleteVolMutex sync.RWMutex // delete volume mutex
mnMutex sync.RWMutex // meta node mutex
dnMutex sync.RWMutex // data node mutex
nsMutex sync.RWMutex // nodeset mutex
badPartitionMutex sync.RWMutex // BadDataPartitionIds and BadMetaPartitionIds operate mutex
leaderInfo *LeaderInfo
cfg *clusterConfig
metaReady bool
retainLogs uint64
idAlloc *IDAllocator
t *topology
dataNodeStatInfo *nodeStatInfo
metaNodeStatInfo *nodeStatInfo
zoneStatInfos map[string]*proto.ZoneStat
volStatInfo sync.Map
domainManager *DomainManager
BadDataPartitionIds *sync.Map
BadMetaPartitionIds *sync.Map
DisableAutoAllocate bool
ForbidMpDecommission bool
type ClusterVolSubItem struct {
vols map[string]*Vol
delayDeleteVolsInfo []*delayDeleteVolInfo
volMutex sync.RWMutex // volume mutex
createVolMutex sync.RWMutex // create volume mutex
deleteVolMutex sync.RWMutex // delete volume mutex
}
type ClusterTopoSubItem struct {
dataNodes sync.Map
metaNodes sync.Map
lcNodes sync.Map
idAlloc *IDAllocator
t *topology
dataNodeStatInfo *nodeStatInfo
metaNodeStatInfo *nodeStatInfo
zoneStatInfos map[string]*proto.ZoneStat
volStatInfo sync.Map
zoneIdxMux sync.Mutex //
zoneList []string
lastZoneIdxForNode int
checkAutoCreateDataPartition bool
FaultDomain bool
needFaultDomain bool // FaultDomain is true and normal zone aleady used up
fsm *MetadataFsm
partition raftstore.Partition
MasterSecretKey []byte
lastZoneIdxForNode int
zoneIdxMux sync.Mutex //
followerReadManager *followerReadManager
diskQosEnable bool
QosAcceptLimit *rate.Limiter
apiLimiter *ApiLimiter
DecommissionDisks sync.Map
DecommissionLimit uint64
EnableAutoDecommissionDisk atomicutil.Bool
AutoDecommissionInterval atomicutil.Int64
AutoDecommissionDiskMux sync.Mutex
checkAutoCreateDataPartition bool
masterClient *masterSDK.MasterClient
checkDataReplicasEnable bool
fileStatsEnable bool
clusterUuid string
clusterUuidEnable bool
inodeCountNotEqualMP *sync.Map
maxInodeNotEqualMP *sync.Map
dentryCountNotEqualMP *sync.Map
ac *authSDK.AuthClient
authenticate bool
lcNodes sync.Map
lcMgr *lifecycleManager
snapshotMgr *snapshotDelManager
DecommissionDiskLimit uint32
S3ApiQosQuota *sync.Map // (api,uid,limtType) -> limitQuota
MarkDiskBrokenThreshold atomicutil.Float64
EnableAutoDpMetaRepair atomicutil.Bool
AutoDpMetaRepairParallelCnt atomicutil.Uint32
domainManager *DomainManager
inodeCountNotEqualMP *sync.Map
maxInodeNotEqualMP *sync.Map
dentryCountNotEqualMP *sync.Map
mnMutex sync.RWMutex // meta node mutex
dnMutex sync.RWMutex // data node mutex
nsMutex sync.RWMutex // nodeset mutex
}
type ClusterDecommission struct {
BadDataPartitionIds *sync.Map
BadMetaPartitionIds *sync.Map
DecommissionDisks sync.Map
DecommissionLimit uint64
AutoDecommissionDiskMux sync.Mutex
DecommissionDiskLimit uint32
MarkDiskBrokenThreshold atomicutil.Float64
badPartitionMutex sync.RWMutex // BadDataPartitionIds and BadMetaPartitionIds operate mutex
ForbidMpDecommission bool
EnableAutoDpMetaRepair atomicutil.Bool
EnableAutoDecommissionDisk atomicutil.Bool
AutoDecommissionInterval atomicutil.Int64
AutoDpMetaRepairParallelCnt atomicutil.Uint32
}
// Cluster stores all the cluster-level information.
type Cluster struct {
Name string
CreateTime int64
clusterUuid string
leaderInfo *LeaderInfo
cfg *clusterConfig
fsm *MetadataFsm
partition raftstore.Partition
MasterSecretKey []byte
retainLogs uint64
stopc chan bool
ClusterVolSubItem
ClusterTopoSubItem
ClusterDecommission
metaReady bool
DisableAutoAllocate bool
diskQosEnable bool
checkDataReplicasEnable bool
fileStatsEnable bool
clusterUuidEnable bool
authenticate bool
S3ApiQosQuota *sync.Map // (api,uid,limtType) -> limitQuota
QosAcceptLimit *rate.Limiter
apiLimiter *ApiLimiter
followerReadManager *followerReadManager
lcMgr *lifecycleManager
snapshotMgr *snapshotDelManager
ac *authSDK.AuthClient
masterClient *masterSDK.MasterClient
}
type delayDeleteVolInfo struct {

View File

@ -362,8 +362,8 @@ func TestBalanceMetaPartition(t *testing.T) {
func TestMasterClientLeaderChange(t *testing.T) {
cluster := &Cluster{
masterClient: masterSDK.NewMasterClient(nil, false),
t: newTopology(),
}
cluster.t = newTopology()
server := &Server{
cluster: cluster,
leaderInfo: &LeaderInfo{

View File

@ -56,22 +56,7 @@ type VolVarargs struct {
enableAutoDpMetaRepair bool
}
// Vol represents a set of meta partitionMap and data partitionMap
type Vol struct {
ID uint64
Name string
Owner string
OSSAccessKey string
OSSSecretKey string
dpReplicaNum uint8
mpReplicaNum uint8
Status uint8
Deleting bool
threshold float32
dataPartitionSize uint64 // byte
Capacity uint64 // GB
VolType int
type CacheSubItem struct {
EbsBlkSize int
CacheCapacity uint64
CacheAction int
@ -81,59 +66,94 @@ type Vol struct {
CacheLowWater int
CacheLRUInterval int
CacheRule string
PreloadCacheOn bool
preloadCapacity uint64
}
PreloadCacheOn bool
NeedToLowerReplica bool
FollowerRead bool
authenticate bool
crossZone bool
domainOn bool
defaultPriority bool // old default zone first
enablePosixAcl bool
enableTransaction proto.TxOpMask
type TxSubItem struct {
txTimeout int64
txConflictRetryNum int64
txConflictRetryInterval int64
txOpLimit int
zoneName string
MetaPartitions map[uint64]*MetaPartition `graphql:"-"`
dataPartitions *DataPartitionMap
mpsCache []byte
viewCache []byte
createDpMutex sync.RWMutex
createMpMutex sync.RWMutex
createTime int64
DeleteLockTime int64
description string
dpSelectorName string
dpSelectorParm string
domainId uint64
qosManager *QosCtrlManager
DpReadOnlyWhenVolFull bool // only if this switch is on, all dp becomes readonly when vol is full
ReadOnlyForVolFull bool // only if the switch DpReadOnlyWhenVolFull is on, mark vol is readonly when is full
aclMgr AclManager
uidSpaceManager *UidSpaceManager
volLock sync.RWMutex
quotaManager *MasterQuotaManager
enableQuota bool
TrashInterval int64
DisableAuditLog bool
VersionMgr *VolVersionManager
Forbidden bool
mpsLock *mpsLockManager
preloadCapacity uint64
authKey string
DeleteExecTime time.Time
user *User
dpRepairBlockSize uint64
EnableAutoMetaRepair atomicutil.Bool
enableTransaction proto.TxOpMask
}
type TopoSubItem struct {
crossZone bool
domainOn bool
dpSelectorName string
dpSelectorParm string
domainId uint64
defaultPriority bool // old default zone first
createDpMutex sync.RWMutex
createMpMutex sync.RWMutex
}
type AuthenticSubItem struct {
OSSAccessKey string
OSSSecretKey string
authenticate bool
enablePosixAcl bool
authKey string
}
type VolDeletionSubItem struct {
Deleting bool
DeleteLockTime int64
Forbidden bool
DeleteExecTime time.Time
}
// Vol represents a set of meta partitionMap and data partitionMap
type Vol struct {
ID uint64
Name string
Owner string
Status uint8
VolType int
zoneName string
user *User
createTime int64
description string
TrashInterval int64
dpReplicaNum uint8
mpReplicaNum uint8
dataPartitionSize uint64 // byte
Capacity uint64 // GB
dpRepairBlockSize uint64
MetaPartitions map[uint64]*MetaPartition `graphql:"-"`
dataPartitions *DataPartitionMap
mpsCache []byte
viewCache []byte
NeedToLowerReplica bool
FollowerRead bool
enableQuota bool
DisableAuditLog bool
DpReadOnlyWhenVolFull bool // only if this switch is on, all dp becomes readonly when vol is full
ReadOnlyForVolFull bool // only if the switch DpReadOnlyWhenVolFull is on, mark vol is readonly when is full
EnableAutoMetaRepair atomicutil.Bool
TopoSubItem
CacheSubItem
TxSubItem
AuthenticSubItem
VolDeletionSubItem
qosManager *QosCtrlManager
aclMgr AclManager
uidSpaceManager *UidSpaceManager
quotaManager *MasterQuotaManager
VersionMgr *VolVersionManager
mpsLock *mpsLockManager
volLock sync.RWMutex
}
func newVol(vv volValue) (vol *Vol) {
vol = &Vol{ID: vv.ID, Name: vv.Name, MetaPartitions: make(map[uint64]*MetaPartition)}
if vol.threshold <= 0 {
vol.threshold = defaultMetaPartitionMemUsageThreshold
}
vol = &Vol{ID: vv.ID, Name: vv.Name, MetaPartitions: make(map[uint64]*MetaPartition, 0)}
vol.dataPartitions = newDataPartitionMap(vv.Name)
vol.VersionMgr = newVersionMgr(vol)