update: gofmt

Signed-off-by: leonrayang <chl696@sina.com>
This commit is contained in:
leonrayang 2022-04-12 10:37:16 +08:00 committed by Victor1319
parent c1adba0775
commit cc406ae931
24 changed files with 92 additions and 100 deletions

View File

@ -47,31 +47,31 @@ func setupCommands(cfg *cmd.Config) *cobra.Command {
var mc = master.NewMasterClient(cfg.MasterAddr, false)
mc.SetTimeout(cfg.Timeout)
cfsRootCmd := cmd.NewRootCmd(mc)
// var completionCmd = &cobra.Command{
// Use: "completion",
// Short: "Generate completion bash file",
// Long: `To use the completion, tool "bash-completion" is demanded,
//then execute the following command:
// $ ./cfs-cli completion
// # Bash completion file "cfs-cli.sh" will be generated under the present working directory
// $ echo 'source /usr/share/bash-completion/bash_completion' >> ~/.bashrc
// $ echo 'source {path of cfs-cli.sh}' >>~/.bashrc
// $ source ~/.bashrc
//`,
// Example: "cfs-cli completion",
// Run: func(cmd *cobra.Command, args []string) {
// if err := cfsRootCmd.CFSCmd.GenBashCompletionFile("cfs-cli.sh"); err != nil {
// _, _ = fmt.Fprintf(os.Stdout, "generate bash file failed")
// }
// _, _ = fmt.Fprintf(os.Stdout, `File "cfs-cli.sh" has been generated successfully under the present working directory,
//following command to execute:
// $ # install bash-completion
// $ echo 'source /usr/share/bash-completion/bash_completion' >> ~/.bashrc
// $ echo 'source {path of cfs-cli.sh}' >>~/.bashrc
// $ source ~/.bashrc
//`)
// },
// }
// var completionCmd = &cobra.Command{
// Use: "completion",
// Short: "Generate completion bash file",
// Long: `To use the completion, tool "bash-completion" is demanded,
//then execute the following command:
// $ ./cfs-cli completion
// # Bash completion file "cfs-cli.sh" will be generated under the present working directory
// $ echo 'source /usr/share/bash-completion/bash_completion' >> ~/.bashrc
// $ echo 'source {path of cfs-cli.sh}' >>~/.bashrc
// $ source ~/.bashrc
//`,
// Example: "cfs-cli completion",
// Run: func(cmd *cobra.Command, args []string) {
// if err := cfsRootCmd.CFSCmd.GenBashCompletionFile("cfs-cli.sh"); err != nil {
// _, _ = fmt.Fprintf(os.Stdout, "generate bash file failed")
// }
// _, _ = fmt.Fprintf(os.Stdout, `File "cfs-cli.sh" has been generated successfully under the present working directory,
//following command to execute:
// $ # install bash-completion
// $ echo 'source /usr/share/bash-completion/bash_completion' >> ~/.bashrc
// $ echo 'source {path of cfs-cli.sh}' >>~/.bashrc
// $ source ~/.bashrc
//`)
// },
// }
//cfsRootCmd.CFSCmd.AddCommand(completionCmd)

View File

@ -44,15 +44,15 @@ func (cmd *ChubaoFSCmd) newClusterCmd(client *master.MasterClient) *cobra.Comman
}
const (
cmdClusterInfoShort = "Show cluster summary information"
cmdClusterStatShort = "Show cluster status information"
cmdClusterFreezeShort = "Freeze cluster"
cmdClusterThresholdShort = "Set memory threshold of metanodes"
cmdClusterSetClusterInfoShort = "Set cluster parameters"
nodeDeleteBatchCountKey = "batchCount"
nodeMarkDeleteRateKey = "markDeleteRate"
nodeDeleteWorkerSleepMs = "deleteWorkerSleepMs"
nodeAutoRepairRateKey = "autoRepairRate"
cmdClusterInfoShort = "Show cluster summary information"
cmdClusterStatShort = "Show cluster status information"
cmdClusterFreezeShort = "Freeze cluster"
cmdClusterThresholdShort = "Set memory threshold of metanodes"
cmdClusterSetClusterInfoShort = "Set cluster parameters"
nodeDeleteBatchCountKey = "batchCount"
nodeMarkDeleteRateKey = "markDeleteRate"
nodeDeleteWorkerSleepMs = "deleteWorkerSleepMs"
nodeAutoRepairRateKey = "autoRepairRate"
)
func newClusterInfoCmd(client *master.MasterClient) *cobra.Command {
@ -204,7 +204,7 @@ func newClusterSetParasCmd(client *master.MasterClient) *cobra.Command {
}
}()
if err = client.AdminAPI().SetClusterParas(optDelBatchCount, optMarkDeleteRate, optDelWorkerSleepMs, optAutoRepairRate, optLoadFactor) ; err != nil {
if err = client.AdminAPI().SetClusterParas(optDelBatchCount, optMarkDeleteRate, optDelWorkerSleepMs, optAutoRepairRate, optLoadFactor); err != nil {
return
}
stdout("Cluster parameters has been set successfully. \n")

View File

@ -88,13 +88,13 @@ const (
CliFlagZoneName = "zone-name"
CliFlagDescription = "description"
CliFlagAutoRepairRate = "autoRepairRate"
CliFlagDelBatchCount = "batchCount"
CliFlagDelWorkerSleepMs = "deleteWorkerSleepMs"
CliFlagLoadFactor = "loadFactor"
CliFlagDelBatchCount = "batchCount"
CliFlagDelWorkerSleepMs = "deleteWorkerSleepMs"
CliFlagLoadFactor = "loadFactor"
CliFlagMarkDelRate = "markDeleteRate"
CliFlagCrossZone = "crossZone"
CliNormalZonesFirst = "normalZonesFirst"
CliFlagCount = "count"
CliNormalZonesFirst = "normalZonesFirst"
CliFlagCount = "count"
//CliFlagSetDataPartitionCount = "count" use dp-count instead

View File

@ -24,9 +24,9 @@ import (
)
const (
cmdDataNodeShort = "Manage data nodes"
cmdDataNodeShort = "Manage data nodes"
cmdDataNodeMigrateInfoShort = "Migrate partitions from a data node to the other node"
dpMigrateMax = 50
dpMigrateMax = 50
)
func newDataNodeCmd(client *master.MasterClient) *cobra.Command {
@ -174,7 +174,7 @@ func newDataNodeMigrateCmd(client *master.MasterClient) *cobra.Command {
}()
src = args[0]
dst = args[1]
if optCount > dpMigrateMax || optCount <= 0{
if optCount > dpMigrateMax || optCount <= 0 {
stdout("Migrate dp count should between [1-50]\n")
return
}

View File

@ -115,7 +115,7 @@ func formatSimpleVolView(svv *proto.SimpleVolView) string {
sb.WriteString(fmt.Sprintf(" Status : %v\n", formatVolumeStatus(svv.Status)))
sb.WriteString(fmt.Sprintf(" ZoneName : %v\n", svv.ZoneName))
sb.WriteString(fmt.Sprintf(" VolType : %v\n", svv.VolType))
if svv.VolType == 1{
if svv.VolType == 1 {
sb.WriteString(fmt.Sprintf(" ObjBlockSize : %v byte\n", svv.ObjBlockSize))
sb.WriteString(fmt.Sprintf(" CacheCapacity : %v G\n", svv.CacheCapacity))
sb.WriteString(fmt.Sprintf(" CacheAction : %v\n", svv.CacheAction))

View File

@ -26,7 +26,7 @@ import (
const (
cmdMetaNodeUse = "metanode [COMMAND]"
cmdMetaNodeShort = "Manage meta nodes"
mpMigrateMax = 15
mpMigrateMax = 15
)
func newMetaNodeCmd(client *master.MasterClient) *cobra.Command {
@ -173,7 +173,7 @@ func newMetaNodeMigrateCmd(client *master.MasterClient) *cobra.Command {
}()
src = args[0]
dst = args[1]
if optCount > mpMigrateMax || optCount <= 0{
if optCount > mpMigrateMax || optCount <= 0 {
stdout("Migrate mp count should between [1-15]\n")
return
}

View File

@ -144,9 +144,9 @@ func newVolCreateCmd(client *master.MasterClient) *cobra.Command {
errout("Error: %v", err)
}
}()
crossZone, _ :=strconv.ParseBool(optCrossZone)
followerRead, _ :=strconv.ParseBool(optFollowerRead)
normalZonesFirst, _ :=strconv.ParseBool(optNormalZonesFirst)
crossZone, _ := strconv.ParseBool(optCrossZone)
followerRead, _ := strconv.ParseBool(optFollowerRead)
normalZonesFirst, _ := strconv.ParseBool(optNormalZonesFirst)
// ask user for confirm
if !optYes {
stdout("Create a new volume:\n")
@ -330,7 +330,7 @@ func newVolUpdateCmd(client *master.MasterClient) *cobra.Command {
} else {
confirmString.WriteString(fmt.Sprintf(" CacheAction : %v \n", vv.CacheAction))
}
if optCacheRule != ""{
if optCacheRule != "" {
if vv.VolType == 0 {
err = fmt.Errorf("cache-rule not support in hot vol\n")
return

View File

@ -695,7 +695,7 @@ func parseMountOption(cfg *config.Config) (*proto.MountOptions, error) {
return nil, errors.New(fmt.Sprintf("invalid config file: lack of mandatory fields, mountPoint(%v), volName(%v), owner(%v), masterAddr(%v)", opt.MountPoint, opt.Volname, opt.Owner, opt.Master))
}
if opt.BuffersTotalLimit < 0 {
if opt.BuffersTotalLimit < 0 {
return nil, errors.New(fmt.Sprintf("invalid fields, BuffersTotalLimit(%v) must larger or equal than 0", opt.BuffersTotalLimit))
}
return opt, nil

View File

@ -757,11 +757,11 @@ func parseAndExtractSetNodeSetInfoParams(r *http.Request) (params map[string]int
return
}
params[idKey] = nodesetId
}else {
} else {
return nil, fmt.Errorf("not found %v", idKey)
}
log.LogInfof("action[parseAndExtractSetNodeSetInfoParams]%v,%v,%v",params[zoneNameKey], params[idKey], params[countKey])
log.LogInfof("action[parseAndExtractSetNodeSetInfoParams]%v,%v,%v", params[zoneNameKey], params[idKey], params[countKey])
return
}

View File

@ -16,14 +16,14 @@ func TestDataNode(t *testing.T) {
time.Sleep(5 * time.Second)
getDataNodeInfo(addr, t)
decommissionDataNode(addr, t)
for i:=0; i < 10; i++ { // decommission is async process
for i := 0; i < 10; i++ { // decommission is async process
_, err = server.cluster.dataNode(addr)
if err == nil {
time.Sleep(time.Second)
continue
}
break
}
}
if err == nil {
t.Errorf("decommission datanode [%v] failed", addr)
}

View File

@ -640,7 +640,7 @@ func (nsgm *DomainManager) getHostFromNodeSetGrp(domainId uint64, replicaNum uin
if loopCnt < len(nsg.nodeSets) {
loopCnt = len(nsg.nodeSets)
}
for i:= 0; i < loopCnt; i++ {
for i := 0; i < loopCnt; i++ {
ns := nsg.nodeSets[nsg.nsgInnerIndex]
log.LogInfof("action[getHostFromNodeSetGrp] nodesetid[%v],zonename[%v], datanode len[%v],metanode len[%v],capcity[%v]",
ns.ID, ns.zoneName, ns.dataNodeLen(), ns.metaNodeLen(), ns.Capacity)

View File

@ -246,7 +246,7 @@ func checkDataPartitionsWritableTest(vol *Vol, t *testing.T) {
if len(vol.dataPartitions.partitions) == 0 {
return
}
time.Sleep(time.Second*20)
time.Sleep(time.Second * 20)
partition := vol.dataPartitions.partitions[0]
if partition.Status != proto.ReadWrite {
t.Errorf("expect partition status[%v],real status[%v]\n", proto.ReadWrite, partition.Status)

View File

@ -56,7 +56,7 @@ func main() {
if buffersTotalLimit < 0 {
fmt.Println("buffersTotalLimit cannot less than 0")
os.Exit(1)
} else if buffersTotalLimit == 0{
} else if buffersTotalLimit == 0 {
buffersTotalLimit = int64(32768)
}
proto.InitBufferPool(buffersTotalLimit)
@ -89,7 +89,7 @@ func main() {
if action == "preload" {
if err := cli.PreloadDir(cfg.GetString("target"), int(replicaNum), uint64(ttl), cfg.GetString("zones")); err != nil {
total, succeed := cli.GetPreloadResult()
fmt.Printf("Preload failed:%v\n",err)
fmt.Printf("Preload failed:%v\n", err)
fmt.Printf("Result: total[%v], succeed[%v]\n", total, succeed)
} else {
fmt.Println("Preload succeed")

View File

@ -565,6 +565,6 @@ func (c *PreLoadClient) PreloadDir(target string, count int, ttl uint64, zones s
return c.preloadFile()
}
func (c *PreLoadClient) GetPreloadResult()(int64 , int64){
func (c *PreLoadClient) GetPreloadResult() (int64, int64) {
return c.preloadFileNumTotal, c.preloadFileNumSucceed
}

View File

@ -138,7 +138,7 @@ func InitMountOptions(opts []MountOption) {
opts[EnablePosixACL] = MountOption{"enablePosixACL", "enable posix ACL support", "", false}
opts[EnableSummary] = MountOption{"enableSummary", "enable content summary", "", false}
opts[MetaSendTimeout] = MountOption{"metaSendTimeout", "Meta send timeout", "", int64(600)}
opts[BuffersTotalLimit] = MountOption{"buffersTotalLimit", "Send/Receive packets memory limit", "", int64(32768)}//default 4G
opts[BuffersTotalLimit] = MountOption{"buffersTotalLimit", "Send/Receive packets memory limit", "", int64(32768)} //default 4G
for i := 0; i < MaxMountOption; i++ {
flag.StringVar(&opts[i].cmdlineValue, opts[i].keyword, "", opts[i].description)
@ -280,6 +280,6 @@ type MountOptions struct {
EnableSummary bool
EnableUnixPermission bool
NeedRestoreFuse bool
MetaSendTimeout int64
BuffersTotalLimit int64
MetaSendTimeout int64
BuffersTotalLimit int64
}

View File

@ -32,7 +32,7 @@ import (
var (
GRequestID = int64(1)
Buffers *buf.BufferPool
Buffers *buf.BufferPool
)
// GenerateRequestID generates the request ID.
@ -745,8 +745,8 @@ func (p *Packet) IsBatchDeleteExtents() bool {
return p.Opcode == OpBatchDeleteExtent
}
func InitBufferPool(bufLimit int64){
func InitBufferPool(bufLimit int64) {
buf.NormalBuffersTotalLimit = bufLimit
buf.HeadBuffersTotalLimit = bufLimit
Buffers = buf.NewBufferPool()
}
}

View File

@ -58,11 +58,9 @@ type Writer struct {
fileSize uint64
cacheThreshold int
dirty bool
blockPosition int
blockPosition int
}
func NewWriter(config ClientConfig) (writer *Writer) {
writer = new(Writer)
@ -186,7 +184,7 @@ func (writer *Writer) doBufferWrite(ctx context.Context, data []byte, offset int
freeSize = dataSize
}
log.LogDebugf("TRACE blobStore doBufferWrite: ino(%v) writer.fileSize(%v) writer.fileOffset(%v) writer.blockPosition(%v) position(%v) freeSize(%v)", writer.ino, writer.fileSize, writer.fileOffset, writer.blockPosition, position, freeSize)
copy(writer.buf[writer.blockPosition:], data[position:position + freeSize])
copy(writer.buf[writer.blockPosition:], data[position:position+freeSize])
log.LogDebugf("TRACE blobStore doBufferWrite:ino(%v) writer.buf.len(%v)", writer.ino, len(writer.buf))
position += freeSize
writer.blockPosition += freeSize
@ -200,7 +198,7 @@ func (writer *Writer) doBufferWrite(ctx context.Context, data []byte, offset int
err = writer.flush(writer.ino, ctx, false)
writer.Lock()
if err != nil {
writer.buf = writer.buf[:writer.blockPosition - freeSize]
writer.buf = writer.buf[:writer.blockPosition-freeSize]
writer.fileOffset -= freeSize
writer.blockPosition -= freeSize
return
@ -367,4 +365,3 @@ func (writer *Writer) FreeCache() {
func (writer *Writer) AllocateCache() {
writer.buf = buf.CachePool.Get()
}

View File

@ -109,11 +109,11 @@ type ExtentClient struct {
readLimiter *rate.Limiter
writeLimiter *rate.Limiter
volumeType int
volumeName string
bcacheEnable bool
BcacheHealth bool
preload bool
volumeType int
volumeName string
bcacheEnable bool
BcacheHealth bool
preload bool
dataWrapper *wrapper.Wrapper
appendExtentKey AppendExtentKeyFunc
getExtents GetExtentsFunc
@ -157,7 +157,7 @@ retry:
client.bcacheEnable = config.BcacheEnable
client.BcacheHealth = true
client.preload = config.Preload
var readLimit, writeLimit rate.Limit
if config.ReadRate <= 0 {
readLimit = defaultReadLimitRate
@ -474,6 +474,6 @@ func (client *ExtentClient) UpdateDataPartitionForColdVolume() error {
return client.dataWrapper.UpdateDataPartition()
}
func(client *ExtentClient) IsPreloadMode() bool {
func (client *ExtentClient) IsPreloadMode() bool {
return client.preload
}
}

View File

@ -409,7 +409,7 @@ func (s *Streamer) doWrite(data []byte, offset, size int, direct bool) (total in
)
if proto.IsCold(s.client.volumeType) {
if offset + size > s.tinySizeLimit() {
if offset+size > s.tinySizeLimit() {
storeMode = proto.NormalExtentType
} else {
storeMode = proto.TinyExtentType
@ -431,7 +431,7 @@ func (s *Streamer) doWrite(data []byte, offset, size int, direct bool) (total in
s.closeOpenHandler()
log.LogDebugf("doWrite: found ek in ExtentCache, offset(%v) size(%v), ekoffset(%v) eksize(%v)",
offset, size, currentEK.FileOffset, currentEK.Size)
offset, size, currentEK.FileOffset, currentEK.Size)
_, pidErr := s.client.dataWrapper.GetDataPartition(currentEK.PartitionId)
if pidErr == nil {
handler := NewExtentHandler(s, int(currentEK.FileOffset), storeMode, int(currentEK.Size))
@ -472,7 +472,7 @@ func (s *Streamer) doWrite(data []byte, offset, size int, direct bool) (total in
}
log.LogDebugf("doWrite handler write failed so close open handler: ino(%v) offset(%v) size(%v) storeMode(%v) err(%v)",
s.inode, offset, size, storeMode, err)
s.inode, offset, size, storeMode, err)
s.closeOpenHandler()
}
@ -488,7 +488,7 @@ func (s *Streamer) doWrite(data []byte, offset, size int, direct bool) (total in
}
log.LogDebugf("doWrite handler write failed so close open handler: ino(%v) offset(%v) size(%v) storeMode(%v) err(%v)",
s.inode, offset, size, storeMode, err)
s.inode, offset, size, storeMode, err)
err = s.closeOpenHandler()
}

View File

@ -213,7 +213,7 @@ func (w *Wrapper) updateDataPartitionByRsp(isInit bool, DataPartitions []*proto.
}
// isInit used to identify whether this call is caused by mount action
if isInit || (len(rwPartitionGroups) >= MinWriteAbleDataPartitionCnt || (proto.IsCold(w.volType) && (len(rwPartitionGroups) >= 1))){
if isInit || (len(rwPartitionGroups) >= MinWriteAbleDataPartitionCnt || (proto.IsCold(w.volType) && (len(rwPartitionGroups) >= 1))) {
w.refreshDpSelector(rwPartitionGroups)
} else {
err = errors.New("updateDataPartition: no writable data partition")

View File

@ -304,7 +304,7 @@ func (api *AdminAPI) VolExpand(volName string, capacity uint64, authKey string)
return
}
func (api *AdminAPI) CreateVolName(volName, owner string, capacity uint64, crossZone , normalZonesFirst bool, business string,
func (api *AdminAPI) CreateVolName(volName, owner string, capacity uint64, crossZone, normalZonesFirst bool, business string,
mpCount, replicaNum, size, volType int, followerRead bool, zoneName, cacheRuleKey string, ebsBlkSize,
cacheCapacity, cacheAction, cacheThreshold, cacheTTL, cacheHighWater, cacheLowWater, cacheLRUInterval int) (err error) {
var request = newAPIRequest(http.MethodGet, proto.AdminCreateVol)

View File

@ -143,11 +143,10 @@ func (api *NodeAPI) DataNodeMigrate(srcAddr, targetAddr string, count int) (err
var request = newAPIRequest(http.MethodGet, proto.MigrateDataNode)
request.addParam("srcAddr", srcAddr)
request.addParam("targetAddr", targetAddr)
request.addParam("count", strconv.Itoa(count))
request.addParam("count", strconv.Itoa(count))
request.addHeader("isTimeOut", "false")
if _, err = api.mc.serveRequest(request); err != nil {
return
}
return
}

View File

@ -12,7 +12,7 @@ import (
const (
HeaderBufferPoolSize = 8192
InvalidLimit = 0
InvalidLimit = 0
)
var tinyBuffersTotalLimit int64 = 4096
@ -27,7 +27,6 @@ var buffersRateLimit = rate.NewLimiter(rate.Limit(16), 16)
var normalBuffersRateLimit = rate.NewLimiter(rate.Limit(16), 16)
var headBuffersRateLimit = rate.NewLimiter(rate.Limit(16), 16)
func NewTinyBufferPool() *sync.Pool {
return &sync.Pool{
New: func() interface{} {
@ -64,13 +63,11 @@ func NewNormalBufferPool() *sync.Pool {
}
}
// BufferPool defines the struct of a buffered pool with 4 objects.
type BufferPool struct {
pools [2]chan []byte
tinyPool *sync.Pool
headPool *sync.Pool
pools [2]chan []byte
tinyPool *sync.Pool
headPool *sync.Pool
normalPool *sync.Pool
}

View File

@ -1,11 +1,11 @@
package buf
import (
"golang.org/x/time/rate"
"github.com/cubefs/cubefs/util"
"golang.org/x/net/context"
"golang.org/x/time/rate"
"sync"
"sync/atomic"
"github.com/cubefs/cubefs/util"
)
var cacheTotalLimit int64
@ -29,7 +29,6 @@ type FileCachePool struct {
pool *sync.Pool
}
func InitCachePool(blockSize int) {
if blockSize == 0 {
return
@ -39,7 +38,7 @@ func InitCachePool(blockSize int) {
CachePool.pool = newWriterCachePool(blockSize)
}
func (fileCachePool *FileCachePool) Get() []byte{
func (fileCachePool *FileCachePool) Get() []byte {
atomic.AddInt64(&cacheCount, 1)
return fileCachePool.pool.Get().([]byte)
}
@ -47,4 +46,4 @@ func (fileCachePool *FileCachePool) Get() []byte{
func (fileCachePool *FileCachePool) Put(data []byte) {
atomic.AddInt64(&cacheCount, -1)
fileCachePool.pool.Put(data)
}
}