Skip to content

Commit

Permalink
feat(master): The original single directory limit is changed to dirLi…
Browse files Browse the repository at this point in the history
…mit instead of dirQuota

close: cubefs#2255

Signed-off-by: baijiaruo <[email protected]>
  • Loading branch information
baijiaruo1 committed Jul 20, 2023
1 parent 30d6d6d commit 3468bbd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 17 deletions.
20 changes: 13 additions & 7 deletions master/api_args_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -987,21 +987,27 @@ func extractCrossZone(r *http.Request) (crossZone bool, err error) {
return
}

func parseAndExtractDirQuota(r *http.Request) (quota uint32, err error) {
func parseAndExtractDirLimit(r *http.Request) (limit uint32, err error) {
if err = r.ParseForm(); err != nil {
return
}
var value string
if value = r.FormValue(dirQuotaKey); value == "" {
err = keyNotFound(dirQuotaKey)
return

value = r.FormValue(dirLimitKey)
if value == "" {
value = r.FormValue(dirQuotaKey)
if value == "" {
err = keyNotFound(dirLimitKey)
return
}
}
var tmpQuota uint64
if tmpQuota, err = strconv.ParseUint(value, 10, 32); err != nil {

var tmpLimit uint64
if tmpLimit, err = strconv.ParseUint(value, 10, 32); err != nil {
return
}

quota = uint32(tmpQuota)
limit = uint32(tmpLimit)
return
}

Expand Down
16 changes: 8 additions & 8 deletions master/api_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,27 @@ type badPartitionView = proto.BadPartitionView

func (m *Server) setClusterInfo(w http.ResponseWriter, r *http.Request) {
var (
quota uint32
err error
dirLimit uint32
err error
)
metric := exporter.NewTPCnt(apiToMetricsName(proto.AdminSetClusterInfo))
defer func() {
doStatAndMetric(proto.AdminSetClusterInfo, metric, err, nil)
}()

if quota, err = parseAndExtractDirQuota(r); err != nil {
if dirLimit, err = parseAndExtractDirLimit(r); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
}
if quota < proto.MinDirChildrenNumLimit {
quota = proto.MinDirChildrenNumLimit
if dirLimit < proto.MinDirChildrenNumLimit {
dirLimit = proto.MinDirChildrenNumLimit
}
if err = m.cluster.setClusterInfo(quota); err != nil {
if err = m.cluster.setClusterInfo(dirLimit); err != nil {
sendErrReply(w, r, newErrHTTPReply(err))
return
}
sendOkReply(w, r, newSuccessHTTPReply(fmt.Sprintf("set dir quota(min:%v, max:%v) to %v successfully",
proto.MinDirChildrenNumLimit, math.MaxUint32, quota)))
sendOkReply(w, r, newSuccessHTTPReply(fmt.Sprintf("set dir limit(min:%v, max:%v) to %v successfully",
proto.MinDirChildrenNumLimit, math.MaxUint32, dirLimit)))
}

// Set the threshold of the memory usage on each meta node.
Expand Down
4 changes: 2 additions & 2 deletions master/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -3258,9 +3258,9 @@ func (c *Cluster) getMetaPartitionCount() (count int) {
return count
}

func (c *Cluster) setClusterInfo(quota uint32) (err error) {
func (c *Cluster) setClusterInfo(dirLimit uint32) (err error) {
oldLimit := c.cfg.DirChildrenNumLimit
atomic.StoreUint32(&c.cfg.DirChildrenNumLimit, quota)
atomic.StoreUint32(&c.cfg.DirChildrenNumLimit, dirLimit)
if err = c.syncPutCluster(); err != nil {
log.LogErrorf("action[setClusterInfo] err[%v]", err)
atomic.StoreUint32(&c.cfg.DirChildrenNumLimit, oldLimit)
Expand Down
1 change: 1 addition & 0 deletions master/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
enableKey = "enable"
thresholdKey = "threshold"
dirQuotaKey = "dirQuota"
dirLimitKey = "dirSizeLimit"
dataPartitionSizeKey = "size"
metaPartitionCountKey = "mpCount"
volCapacityKey = "capacity"
Expand Down

0 comments on commit 3468bbd

Please sign in to comment.