chore(master): update the codes according to review comments.#22834621

Signed-off-by: Wu Huocheng <wuhuocheng@oppo.com>
This commit is contained in:
Wu Huocheng 2024-12-20 11:52:51 +08:00 committed by zhumingze1108
parent 242eedf13d
commit 46bb136ee8
5 changed files with 10 additions and 22 deletions

View File

@ -8487,7 +8487,7 @@ func (m *Server) getMetaPartitionEmptyStatus(w http.ResponseWriter, r *http.Requ
volStatus.MetaPartitions = append(volStatus.MetaPartitions, getMetaPartitionView(mp))
}
}
if volStatus.EmptyCount > ReserveEmptyMetaPartition {
if volStatus.EmptyCount > RsvEmptyMetaPartitionCnt {
mpsStatus = append(mpsStatus, volStatus)
}
}
@ -8521,9 +8521,9 @@ func (m *Server) freezeEmptyMetaPartition(w http.ResponseWriter, r *http.Request
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
}
if count < ReserveEmptyMetaPartition {
if count < RsvEmptyMetaPartitionCnt {
// reserve 2 empty mp at least, not include the last one.
count = ReserveEmptyMetaPartition
count = RsvEmptyMetaPartitionCnt
}
vol, err := m.cluster.getVol(name)
@ -8538,8 +8538,8 @@ func (m *Server) freezeEmptyMetaPartition(w http.ResponseWriter, r *http.Request
}
mps := vol.getSortMetaPartitions()
if len(mps) <= ReserveEmptyMetaPartition {
err = fmt.Errorf("the all meta partition number is less than %d", ReserveEmptyMetaPartition)
if len(mps) <= RsvEmptyMetaPartitionCnt {
err = fmt.Errorf("the all meta partition number is less than %d", RsvEmptyMetaPartitionCnt)
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
}

View File

@ -249,7 +249,7 @@ const (
unusedFlashNodeFlashGroupID = 0
defaultFlashGroupSlotsCount = 32
ReserveEmptyMetaPartition = 2
RsvEmptyMetaPartitionCnt = 2
)
const (

View File

@ -2082,20 +2082,6 @@ func (vol *Vol) isStorageClassInAllowed(storageClass uint32) (in bool) {
return in
}
type MetaPartitionSort []*MetaPartition
func (mps MetaPartitionSort) Len() int {
return len(mps)
}
func (mps MetaPartitionSort) Swap(i, j int) {
mps[i], mps[j] = mps[j], mps[i]
}
func (mps MetaPartitionSort) Less(i, j int) bool {
return mps[i].Start < mps[j].Start
}
func (vol *Vol) getSortMetaPartitions() (mps []*MetaPartition) {
vol.mpsLock.RLock()
mps = make([]*MetaPartition, 0, len(vol.MetaPartitions))
@ -2104,7 +2090,7 @@ func (vol *Vol) getSortMetaPartitions() (mps []*MetaPartition) {
}
vol.mpsLock.RUnlock()
sort.Sort(MetaPartitionSort(mps))
sort.Slice(mps, func(i, j int) bool { return mps[i].Start < mps[j].Start })
return
}

View File

@ -285,3 +285,5 @@ var (
_ = (*metaPartition).fsmDelVerExtents
_ = (*TransactionResource).copyGetTxRbInode
)
const DelMetaPartitionHdr = "del_partition_"

View File

@ -3063,7 +3063,7 @@ func (m *metadataManager) opRemoveEmptyMetaPartition(conn net.Conn, p *Packet,
}
for _, entry := range entries {
if entry.IsDir() && strings.HasPrefix(entry.Name(), "del_partition_") {
if entry.IsDir() && strings.HasPrefix(entry.Name(), DelMetaPartitionHdr) {
removeDir := path.Join(m.rootDir, entry.Name())
os.RemoveAll(removeDir)
}