From 46bb136ee8d80fdcf02fb3f6bc09c96e8fb5adc8 Mon Sep 17 00:00:00 2001 From: Wu Huocheng Date: Fri, 20 Dec 2024 11:52:51 +0800 Subject: [PATCH] chore(master): update the codes according to review comments.#22834621 Signed-off-by: Wu Huocheng --- master/api_service.go | 10 +++++----- master/const.go | 2 +- master/vol.go | 16 +--------------- metanode/const.go | 2 ++ metanode/manager_op.go | 2 +- 5 files changed, 10 insertions(+), 22 deletions(-) diff --git a/master/api_service.go b/master/api_service.go index 53e91393b..488405614 100644 --- a/master/api_service.go +++ b/master/api_service.go @@ -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 } diff --git a/master/const.go b/master/const.go index 2f5c7cbd7..10f425382 100644 --- a/master/const.go +++ b/master/const.go @@ -249,7 +249,7 @@ const ( unusedFlashNodeFlashGroupID = 0 defaultFlashGroupSlotsCount = 32 - ReserveEmptyMetaPartition = 2 + RsvEmptyMetaPartitionCnt = 2 ) const ( diff --git a/master/vol.go b/master/vol.go index ce619360c..43d3eedfc 100644 --- a/master/vol.go +++ b/master/vol.go @@ -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 } diff --git a/metanode/const.go b/metanode/const.go index a9368103b..5606b7125 100644 --- a/metanode/const.go +++ b/metanode/const.go @@ -285,3 +285,5 @@ var ( _ = (*metaPartition).fsmDelVerExtents _ = (*TransactionResource).copyGetTxRbInode ) + +const DelMetaPartitionHdr = "del_partition_" diff --git a/metanode/manager_op.go b/metanode/manager_op.go index 62851f83d..842195d91 100644 --- a/metanode/manager_op.go +++ b/metanode/manager_op.go @@ -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) }