diff --git a/authnode/api_service.go b/authnode/api_service.go
index 5fdb012bd..dcba2fd80 100644
--- a/authnode/api_service.go
+++ b/authnode/api_service.go
@@ -16,6 +16,7 @@ package authnode
import (
"encoding/json"
+ "fmt"
"net/http"
"strconv"
"time"
@@ -26,8 +27,6 @@ import (
"github.com/cubefs/cubefs/util/iputil"
"github.com/cubefs/cubefs/util/keystore"
"github.com/cubefs/cubefs/util/log"
-
- "fmt"
)
const (
@@ -337,9 +336,7 @@ func (m *Server) handleGetCaps(keyInfo *keystore.KeyInfo) (res *keystore.KeyInfo
}
func (m *Server) extractClientReqInfo(r *http.Request) (plaintext []byte, err error) {
- var (
- message string
- )
+ var message string
if err = r.ParseForm(); err != nil {
return
}
@@ -456,9 +453,7 @@ func (m *Server) genTicket(key []byte, serviceID string, IP string, caps []byte)
}
func (m *Server) getSecretKey(id string) (key []byte, err error) {
- var (
- keyInfo *keystore.KeyInfo
- )
+ var keyInfo *keystore.KeyInfo
if keyInfo, err = m.getSecretKeyInfo(id); err != nil {
return
}
diff --git a/authnode/cluster.go b/authnode/cluster.go
index c03c8d70d..091118845 100644
--- a/authnode/cluster.go
+++ b/authnode/cluster.go
@@ -17,11 +17,11 @@ package authnode
import (
"encoding/json"
"fmt"
- "github.com/cubefs/cubefs/util"
"time"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/raftstore"
+ "github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/caps"
"github.com/cubefs/cubefs/util/cryptoutil"
"github.com/cubefs/cubefs/util/errors"
@@ -99,7 +99,7 @@ func (c *Cluster) CreateNewKey(id string, keyInfo *keystore.KeyInfo) (res *keyst
}
keyInfo.Ts = time.Now().Unix()
keyInfo.AuthKey = cryptoutil.GenSecretKey([]byte(c.AuthRootKey), keyInfo.Ts, id)
- //TODO check duplicate
+ // TODO check duplicate
keyInfo.AccessKey = util.RandomString(16, util.Numeric|util.LowerLetter|util.UpperLetter)
keyInfo.SecretKey = util.RandomString(32, util.Numeric|util.LowerLetter|util.UpperLetter)
if err = c.syncAddKey(keyInfo); err != nil {
diff --git a/authnode/config.go b/authnode/config.go
index de6536e55..2aaeeaf4c 100644
--- a/authnode/config.go
+++ b/authnode/config.go
@@ -24,7 +24,7 @@ import (
"github.com/cubefs/cubefs/raftstore"
)
-//config key
+// config key
const (
colonSplit = ":"
commaSplit = ","
@@ -34,7 +34,7 @@ const (
replicaPortKey = "replicaPort"
)
-//default value
+// default value
const (
defaultIntervalToCheckHeartbeat = 60
)
@@ -67,6 +67,7 @@ func parsePeerAddr(peerAddr string) (id uint64, ip string, port uint64, err erro
ip = peerStr[1]
return
}
+
func (cfg *clusterConfig) parsePeers(peerStr string) error {
peerArr := strings.Split(peerStr, commaSplit)
cfg.peerAddrs = peerArr
diff --git a/authnode/http_server.go b/authnode/http_server.go
index 490e5af41..3beb77b68 100644
--- a/authnode/http_server.go
+++ b/authnode/http_server.go
@@ -33,8 +33,8 @@ func (m *Server) startHTTPService() {
// Instead, we use client secret key for authentication
cfg := &tls.Config{
MinVersion: tls.VersionTLS12,
- //ClientAuth: tls.RequireAndVerifyClientCert,
- //ClientCAs: caCertPool,
+ // ClientAuth: tls.RequireAndVerifyClientCert,
+ // ClientCAs: caCertPool,
}
srv := &http.Server{
Addr: colonSplit + m.port,
@@ -71,7 +71,8 @@ func (m *Server) newAuthProxy() *AuthProxy {
Director: func(request *http.Request) {
request.URL.Scheme = "http"
request.URL.Host = m.leaderInfo.addr
- }}
+ },
+ }
}
return &authProxy
}
diff --git a/authnode/keystore_fsm.go b/authnode/keystore_fsm.go
index 2323c829d..5390e7b17 100644
--- a/authnode/keystore_fsm.go
+++ b/authnode/keystore_fsm.go
@@ -17,7 +17,6 @@ package authnode
import (
"encoding/json"
"fmt"
- "github.com/cubefs/cubefs/raftstore/raftstore_db"
"io"
"strconv"
"strings"
@@ -25,6 +24,7 @@ import (
"github.com/cubefs/cubefs/depends/tiglabs/raft"
"github.com/cubefs/cubefs/depends/tiglabs/raft/proto"
+ "github.com/cubefs/cubefs/raftstore/raftstore_db"
"github.com/cubefs/cubefs/util/keystore"
"github.com/cubefs/cubefs/util/log"
)
@@ -54,7 +54,7 @@ type KeystoreFsm struct {
keystore map[string]*keystore.KeyInfo
accessKeystore map[string]*keystore.AccessKeyInfo
ksMutex sync.RWMutex // keystore mutex
- aksMutex sync.RWMutex //accesskeystore mutex
+ aksMutex sync.RWMutex // accesskeystore mutex
opKeyMutex sync.RWMutex // operations on key mutex
id uint64 // current id of server
}
@@ -139,7 +139,7 @@ func (mf *KeystoreFsm) Apply(command []byte, index uint64) (resp interface{}, er
if err = mf.delKeyAndPutIndex(cmd.K, cmdMap); err != nil {
panic(err)
}
- //if mf.leader != mf.id {
+ // if mf.leader != mf.id {
// We don't use above statement to avoid "leader double-change of keystore cache"
// Because there may a race condition: before "Apply" raftlog, leader change happens
// so that cache changes may not happen in newly selected leader-node and "double-change"
@@ -156,7 +156,7 @@ func (mf *KeystoreFsm) Apply(command []byte, index uint64) (resp interface{}, er
if err = mf.batchPut(cmdMap); err != nil {
panic(err)
}
- //if mf.leader != mf.id {
+ // if mf.leader != mf.id {
// Same reasons as the description above
if mf.id != leader {
mf.PutKey(&keyInfo)
diff --git a/authnode/server.go b/authnode/server.go
index f9d47c69c..419aaafd0 100644
--- a/authnode/server.go
+++ b/authnode/server.go
@@ -16,25 +16,23 @@ package authnode
import (
"fmt"
- "github.com/cubefs/cubefs/raftstore/raftstore_db"
- "io/ioutil"
syslog "log"
"net/http"
"net/http/httputil"
+ "os"
"strconv"
"sync"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/raftstore"
+ "github.com/cubefs/cubefs/raftstore/raftstore_db"
"github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/config"
"github.com/cubefs/cubefs/util/cryptoutil"
-
"github.com/cubefs/cubefs/util/errors"
"github.com/cubefs/cubefs/util/log"
)
-//
const (
LRUCacheSize = 3 << 30
WriteBufferSize = 4 * util.MB
@@ -216,10 +214,10 @@ func (m *Server) Start(cfg *config.Config) (err error) {
if cfg.GetBool(EnableHTTPS) == true {
m.cluster.PKIKey.EnableHTTPS = true
- if m.cluster.PKIKey.AuthRootPublicKey, err = ioutil.ReadFile("/app/server.crt"); err != nil {
+ if m.cluster.PKIKey.AuthRootPublicKey, err = os.ReadFile("/app/server.crt"); err != nil {
return fmt.Errorf("action[Start] failed,err[%v]", err)
}
- if m.cluster.PKIKey.AuthRootPrivateKey, err = ioutil.ReadFile("/app/server.key"); err != nil {
+ if m.cluster.PKIKey.AuthRootPrivateKey, err = os.ReadFile("/app/server.key"); err != nil {
return fmt.Errorf("action[Start] failed,err[%v]", err)
}
// TODO: verify cert
diff --git a/authtool/authtool.go b/authtool/authtool.go
index 444d4686c..2701b8907 100644
--- a/authtool/authtool.go
+++ b/authtool/authtool.go
@@ -6,7 +6,6 @@ import (
"flag"
"fmt"
"io"
- "io/ioutil"
"log"
"net/http"
"os"
@@ -122,9 +121,7 @@ func (m *ticketFile) dumpJSONFile(filename string) {
}
func sendReqX(target string, data interface{}, cert *[]byte) (res []byte, err error) {
- var (
- client *http.Client
- )
+ var client *http.Client
target = HTTPS + target
client, err = cryptoutil.CreateClientX(cert)
if err != nil {
@@ -142,7 +139,6 @@ func sendReq(target string, data interface{}) (res []byte, err error) {
}
func getTicketFromAuth(keyring *keyRing) (ticketfile ticketFile) {
-
var (
err error
ts int64
@@ -409,7 +405,6 @@ func accessAuthServer() {
}
return
-
}
func accessAPI() {
@@ -423,7 +418,7 @@ func accessAPI() {
func loadCertfile(path string) (caCert []byte) {
var err error
- caCert, err = ioutil.ReadFile(path)
+ caCert, err = os.ReadFile(path)
if err != nil {
log.Fatal(err)
}
diff --git a/autofs/cfs.go b/autofs/cfs.go
index 64fac01a5..13478a3a9 100644
--- a/autofs/cfs.go
+++ b/autofs/cfs.go
@@ -2,15 +2,16 @@ package main
import (
"fmt"
- "golang.org/x/text/cases"
- "golang.org/x/text/language"
- "k8s.io/mount-utils"
"log"
"os"
"os/exec"
"reflect"
"strings"
"time"
+
+ "golang.org/x/text/cases"
+ "golang.org/x/text/language"
+ "k8s.io/mount-utils"
)
type cfsOption struct {
@@ -99,7 +100,6 @@ func (c *cfsOption) ConvertToCliOptions() (s []string) {
}
return s
-
}
// cfsParse Parse from string
@@ -150,7 +150,6 @@ func cfsIsMounted(mountPoint string) bool {
}
return false
-
}
// cfsMountPre exception handling
@@ -235,7 +234,6 @@ func cfsMountPost(mountPoint string) error {
}
return nil
-
}
func cfsUmount(mountPoint string) error {
diff --git a/autofs/cfs_test.go b/autofs/cfs_test.go
index f210041fb..1a6921c51 100644
--- a/autofs/cfs_test.go
+++ b/autofs/cfs_test.go
@@ -48,7 +48,6 @@ func TestUmount(t *testing.T) {
}
func TestCfsMount(t *testing.T) {
-
var err error
mountPoint := "/home/tmp"
@@ -56,5 +55,4 @@ func TestCfsMount(t *testing.T) {
err = cfsMount(mountPoint, options)
fmt.Println("err: ", err)
-
}
diff --git a/autofs/main.go b/autofs/main.go
index 6b4fd594a..1cd3f3f9c 100644
--- a/autofs/main.go
+++ b/autofs/main.go
@@ -2,13 +2,16 @@ package main
import (
"fmt"
- "github.com/spf13/cobra"
"log"
"os"
+
+ "github.com/spf13/cobra"
)
-var buildVersion = "DebugVersion"
-var buildDate = "BuildDate"
+var (
+ buildVersion = "DebugVersion"
+ buildDate = "BuildDate"
+)
var logFile *os.File
@@ -48,12 +51,10 @@ var rootCmd = &cobra.Command{
if err != nil {
log.Fatal("cfsMountErr, err: ", err)
}
-
},
}
func main() {
-
rootCmd.PersistentFlags().BoolP("no-mtab", "n", false, "Mount without writing in /etc/mtab")
rootCmd.PersistentFlags().StringP("options", "o", "", "Options, followed by a comma separated string of options")
rootCmd.PersistentFlags().BoolP("version", "V", false, "Output version")
@@ -66,7 +67,7 @@ func main() {
func init() {
// logFile
var err error
- logFile, err = os.OpenFile(getEnv(EnvLogFile, LogFile), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0664)
+ logFile, err = os.OpenFile(getEnv(EnvLogFile, LogFile), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o664)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
diff --git a/autofs/util.go b/autofs/util.go
index b586a1283..f0b8b7b7e 100644
--- a/autofs/util.go
+++ b/autofs/util.go
@@ -2,8 +2,10 @@ package main
import "os"
-const EnvLogFile = "CFSAUTO_LOG_FILE"
-const EnvCfsClientPath = "CFS_CLIENT_PATH"
+const (
+ EnvLogFile = "CFSAUTO_LOG_FILE"
+ EnvCfsClientPath = "CFS_CLIENT_PATH"
+)
const LogFile = "/var/log/cfsauto.log"
diff --git a/cli/cmd/config.go b/cli/cmd/config.go
index 92d57d5e3..67404a2c5 100644
--- a/cli/cmd/config.go
+++ b/cli/cmd/config.go
@@ -16,7 +16,6 @@ package cmd
import (
"encoding/json"
- "io/ioutil"
"math"
"os"
"path"
@@ -145,7 +144,7 @@ func setConfig(masterHosts string, timeout uint16) (err error) {
if configData, err = json.Marshal(config); err != nil {
return
}
- if err = ioutil.WriteFile(defaultConfigPath, configData, 0o600); err != nil {
+ if err = os.WriteFile(defaultConfigPath, configData, 0o600); err != nil {
return
}
return nil
@@ -154,11 +153,11 @@ func setConfig(masterHosts string, timeout uint16) (err error) {
func LoadConfig() (*Config, error) {
var err error
var configData []byte
- if configData, err = ioutil.ReadFile(defaultConfigPath); err != nil && !os.IsNotExist(err) {
+ if configData, err = os.ReadFile(defaultConfigPath); err != nil && !os.IsNotExist(err) {
return nil, err
}
if os.IsNotExist(err) {
- if err = ioutil.WriteFile(defaultConfigPath, defaultConfigData, 0o600); err != nil {
+ if err = os.WriteFile(defaultConfigPath, defaultConfigData, 0o600); err != nil {
return nil, err
}
configData = defaultConfigData
diff --git a/cli/cmd/gen_config.go b/cli/cmd/gen_config.go
index 3667f1ffc..c3292c827 100644
--- a/cli/cmd/gen_config.go
+++ b/cli/cmd/gen_config.go
@@ -18,7 +18,6 @@ import (
"encoding/json"
"errors"
"fmt"
- "io/ioutil"
"log"
"os"
"path"
@@ -132,7 +131,7 @@ func (cluster *ClusterConfig) updateNodeConfig(role, clusterName string, nodeCon
// load yaml config file from filePath
func loadYamlConfig(filePath string) (*RootConfig, error) {
- yamlFile, err := ioutil.ReadFile(filePath)
+ yamlFile, err := os.ReadFile(filePath)
if err != nil {
fmt.Fprintf(os.Stderr, "load yaml %v error: %v\n", filePath, err)
return nil, err
@@ -276,7 +275,7 @@ func storeConfig2Json(configPath string, config map[string]interface{}) error {
configData, _ := json.MarshalIndent(config, "", " ")
os.MkdirAll(path.Dir(configPath), 0o755)
- if err := ioutil.WriteFile(configPath, configData, 0o644); err != nil {
+ if err := os.WriteFile(configPath, configData, 0o644); err != nil {
fmt.Fprintf(os.Stderr, "store config %s err: %v", configPath, err)
return err
}
diff --git a/client/fs/const.go b/client/fs/const.go
index be5283964..dd4631887 100644
--- a/client/fs/const.go
+++ b/client/fs/const.go
@@ -19,7 +19,6 @@ import (
"time"
"github.com/cubefs/cubefs/depends/bazil.org/fuse"
-
"github.com/cubefs/cubefs/proto"
)
diff --git a/client/fs/dir.go b/client/fs/dir.go
index 1fd6a20df..f6aa5862e 100644
--- a/client/fs/dir.go
+++ b/client/fs/dir.go
@@ -499,8 +499,8 @@ func (d *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) {
}()
// transform ReadDirAll to ReadDirLimit_ll
- var noMore = false
- var from = ""
+ noMore := false
+ from := ""
var children []proto.Dentry
for !noMore {
batches, err := d.super.mw.ReadDirLimit_ll(d.info.Inode, from, DefaultReaddirLimit)
@@ -615,7 +615,7 @@ func (d *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDir fs.Nod
d.super.fslock.Unlock()
auditlog.LogClientOp("Rename", srcPath, dstPath, err, time.Since(start).Microseconds(), srcInode, dstInode)
}()
- //changePathMap := d.super.mw.GetChangeQuota(d.getCwd()+"/"+req.OldName, dstDir.getCwd()+"/"+req.NewName)
+ // changePathMap := d.super.mw.GetChangeQuota(d.getCwd()+"/"+req.OldName, dstDir.getCwd()+"/"+req.NewName)
if d.super.mw.EnableQuota {
if !d.canRenameByQuota(dstDir, req.OldName) {
return fuse.EPERM
diff --git a/client/fs/file.go b/client/fs/file.go
index 61330b9cf..42f5819f5 100644
--- a/client/fs/file.go
+++ b/client/fs/file.go
@@ -282,7 +282,6 @@ func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenR
// Release handles the release request.
func (f *File) Release(ctx context.Context, req *fuse.ReleaseRequest) (err error) {
-
ino := f.info.Inode
bgTime := stat.BeginStat()
@@ -463,7 +462,7 @@ func (f *File) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.Wri
log.LogErrorf("Write: ino(%v) offset(%v) len(%v) size(%v)", ino, req.Offset, reqlen, size)
}
- //only hot volType need to wait flush
+ // only hot volType need to wait flush
if waitForFlush {
err = f.super.ec.Flush(ino)
if err != nil {
diff --git a/client/fs/summarycache.go b/client/fs/summarycache.go
index 43255c689..51d212712 100644
--- a/client/fs/summarycache.go
+++ b/client/fs/summarycache.go
@@ -2,9 +2,10 @@ package fs
import (
"container/list"
- "github.com/cubefs/cubefs/sdk/meta"
"sync"
"time"
+
+ "github.com/cubefs/cubefs/sdk/meta"
)
const (
diff --git a/client/fs/super.go b/client/fs/super.go
index 83b26e690..66c3cb9c5 100644
--- a/client/fs/super.go
+++ b/client/fs/super.go
@@ -70,7 +70,7 @@ type Super struct {
sockaddr string
suspendCh chan interface{}
- //data lake
+ // data lake
volType int
ebsEndpoint string
CacheAction int
@@ -722,7 +722,7 @@ func (s *Super) Close() {
}
func (s *Super) SetTransaction(txMaskStr string, timeout int64, retryNum int64, retryInterval int64) {
- //maskStr := proto.GetMaskString(txMask)
+ // maskStr := proto.GetMaskString(txMask)
mask, err := proto.GetMaskFromString(txMaskStr)
if err != nil {
log.LogErrorf("SetTransaction: err[%v], op[%v], timeout[%v]", err, txMaskStr, timeout)
diff --git a/client/fuse.go b/client/fuse.go
index 6fc036cfe..1c190a3b1 100644
--- a/client/fuse.go
+++ b/client/fuse.go
@@ -23,7 +23,7 @@ package main
import (
"flag"
"fmt"
- "io/ioutil"
+ "io"
syslog "log"
"math"
"net"
@@ -40,24 +40,20 @@ import (
"time"
"github.com/cubefs/cubefs/blockcache/bcache"
- "github.com/cubefs/cubefs/util/auditlog"
-
- "github.com/cubefs/cubefs/util/buf"
-
- "github.com/cubefs/cubefs/sdk/master"
- "github.com/cubefs/cubefs/util"
-
- sysutil "github.com/cubefs/cubefs/util/sys"
-
cfs "github.com/cubefs/cubefs/client/fs"
"github.com/cubefs/cubefs/depends/bazil.org/fuse"
"github.com/cubefs/cubefs/depends/bazil.org/fuse/fs"
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/sdk/master"
+ "github.com/cubefs/cubefs/util"
+ "github.com/cubefs/cubefs/util/auditlog"
+ "github.com/cubefs/cubefs/util/buf"
"github.com/cubefs/cubefs/util/config"
"github.com/cubefs/cubefs/util/errors"
"github.com/cubefs/cubefs/util/exporter"
"github.com/cubefs/cubefs/util/log"
"github.com/cubefs/cubefs/util/stat"
+ sysutil "github.com/cubefs/cubefs/util/sys"
"github.com/cubefs/cubefs/util/ump"
"github.com/jacobsa/daemonize"
_ "go.uber.org/automaxprocs"
@@ -128,7 +124,7 @@ func createUDS(sockAddr string) (listener net.Listener, err error) {
return
}
- if err = os.Chmod(sockAddr, 0666); err != nil {
+ if err = os.Chmod(sockAddr, 0o666); err != nil {
log.LogErrorf("failed to chmod socket file: %v\n", err)
listener.Close()
return
@@ -193,7 +189,7 @@ func sendSuspendRequest(port string, udsListener net.Listener) (err error) {
}
defer resp.Body.Close()
- if data, err = ioutil.ReadAll(resp.Body); err != nil {
+ if data, err = io.ReadAll(resp.Body); err != nil {
log.LogErrorf("Failed to read response: %v\n", err)
return err
}
@@ -229,7 +225,7 @@ func sendResumeRequest(port string) (err error) {
}
defer resp.Body.Close()
- if data, err = ioutil.ReadAll(resp.Body); err != nil {
+ if data, err = io.ReadAll(resp.Body); err != nil {
log.LogErrorf("Failed to read response: %v\n", err)
return err
}
@@ -284,14 +280,13 @@ func main() {
cfg, _ := config.LoadConfigFile(*configFile)
opt, err := parseMountOption(cfg)
-
if err != nil {
err = errors.NewErrorf("parse mount opt failed: %v\n", err)
fmt.Println(err)
daemonize.SignalOutcome(err)
os.Exit(1)
}
- //load conf from master
+ // load conf from master
for retry := 0; retry < MasterRetrys; retry++ {
err = loadConfFromMaster(opt)
if err != nil {
@@ -310,7 +305,7 @@ func main() {
if opt.MaxCPUs > 0 {
runtime.GOMAXPROCS(int(opt.MaxCPUs))
}
- //use uber automaxprocs: get real cpu number to k8s pod"
+ // use uber automaxprocs: get real cpu number to k8s pod"
level := parseLogLevel(opt.Loglvl)
_, err = log.InitLog(opt.Logpath, opt.Volname, level, nil, log.DefaultLogLeftSpaceLimit)
@@ -359,7 +354,7 @@ func main() {
buf.InitbCachePool(bcache.MaxBlockSize)
}
outputFilePath := path.Join(opt.Logpath, LoggerPrefix, LoggerOutput)
- outputFile, err := os.OpenFile(outputFilePath, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
+ outputFile, err := os.OpenFile(outputFilePath, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0o666)
if err != nil {
err = errors.NewErrorf("Open output file failed: %v\n", err)
fmt.Println(err)
@@ -492,7 +487,7 @@ func main() {
}
func getPushAddrFromMaster(masterAddr string) (addr string, err error) {
- var mc = master.NewMasterClientFromString(masterAddr, false)
+ mc := master.NewMasterClientFromString(masterAddr, false)
addr, err = mc.AdminAPI().GetMonitorPushAddr()
return
}
@@ -614,7 +609,7 @@ func mount(opt *proto.MountOptions) (fsConn *fuse.Conn, super *cfs.Super, err er
http.HandleFunc(log.GetLogPath, log.GetLog)
http.HandleFunc(ControlCommandSuspend, super.SetSuspend)
http.HandleFunc(ControlCommandResume, super.SetResume)
- //auditlog
+ // auditlog
http.HandleFunc(auditlog.EnableAuditLogReqPath, super.EnableAuditLog)
http.HandleFunc(auditlog.DisableAuditLogReqPath, auditlog.DisableAuditLog)
http.HandleFunc(auditlog.SetAuditLogBufSizeReqPath, auditlog.ResetWriterBuffSize)
@@ -648,7 +643,7 @@ func mount(opt *proto.MountOptions) (fsConn *fuse.Conn, super *cfs.Super, err er
}
go func() {
- var mc = master.NewMasterClientFromString(opt.Master, false)
+ mc := master.NewMasterClientFromString(opt.Master, false)
t := time.NewTicker(UpdateConfInterval)
defer t.Stop()
for range t.C {
@@ -691,7 +686,8 @@ func mount(opt *proto.MountOptions) (fsConn *fuse.Conn, super *cfs.Super, err er
fuse.Subtype("cubefs"),
fuse.LocalVolume(),
fuse.VolumeName(opt.FileSystemName),
- fuse.RequestTimeout(opt.RequestTimeout)}
+ fuse.RequestTimeout(opt.RequestTimeout),
+ }
if opt.Rdonly {
options = append(options, fuse.ReadOnly())
@@ -785,7 +781,7 @@ func parseMountOption(cfg *config.Config) (*proto.MountOptions, error) {
opt.WriteThreads = GlobalMountOptions[proto.WriteThreads].GetInt64()
opt.BcacheDir = GlobalMountOptions[proto.BcacheDir].GetString()
- //opt.EnableBcache = GlobalMountOptions[proto.EnableBcache].GetBool()
+ // opt.EnableBcache = GlobalMountOptions[proto.EnableBcache].GetBool()
opt.BcacheFilterFiles = GlobalMountOptions[proto.BcacheFilterFiles].GetString()
opt.BcacheBatchCnt = GlobalMountOptions[proto.BcacheBatchCnt].GetInt64()
opt.BcacheCheckIntervalS = GlobalMountOptions[proto.BcacheCheckIntervalS].GetInt64()
@@ -829,7 +825,7 @@ func parseMountOption(cfg *config.Config) (*proto.MountOptions, error) {
}
func checkPermission(opt *proto.MountOptions) (err error) {
- var mc = master.NewMasterClientFromString(opt.Master, false)
+ mc := master.NewMasterClientFromString(opt.Master, false)
localIP, _ := ump.GetLocalIpAddr()
if info, err := mc.UserAPI().AclOperation(opt.Volname, localIP, util.AclCheckIP); err != nil || !info.OK {
syslog.Println(err)
@@ -845,7 +841,7 @@ func checkPermission(opt *proto.MountOptions) (err error) {
err = proto.ErrNoPermission
return
}
- var policy = userInfo.Policy
+ policy := userInfo.Policy
if policy.IsOwn(opt.Volname) {
return
}
@@ -896,7 +892,7 @@ func freeOSMemory(w http.ResponseWriter, r *http.Request) {
}
func loadConfFromMaster(opt *proto.MountOptions) (err error) {
- var mc = master.NewMasterClientFromString(opt.Master, false)
+ mc := master.NewMasterClientFromString(opt.Master, false)
var volumeInfo *proto.SimpleVolView
volumeInfo, err = mc.AdminAPI().GetVolumeSimpleInfo(opt.Volname)
if err != nil {
diff --git a/cmd/cmd.go b/cmd/cmd.go
index 128d58685..0d5052c88 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -29,26 +29,22 @@ import (
"strings"
"syscall"
- "github.com/cubefs/cubefs/util/auditlog"
- "github.com/cubefs/cubefs/util/errors"
- sysutil "github.com/cubefs/cubefs/util/sys"
-
- "github.com/cubefs/cubefs/console"
- "github.com/cubefs/cubefs/proto"
-
- "github.com/cubefs/cubefs/objectnode"
-
- "github.com/jacobsa/daemonize"
-
"github.com/cubefs/cubefs/authnode"
"github.com/cubefs/cubefs/cmd/common"
+ "github.com/cubefs/cubefs/console"
"github.com/cubefs/cubefs/datanode"
"github.com/cubefs/cubefs/lcnode"
"github.com/cubefs/cubefs/master"
"github.com/cubefs/cubefs/metanode"
+ "github.com/cubefs/cubefs/objectnode"
+ "github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/util/auditlog"
"github.com/cubefs/cubefs/util/config"
+ "github.com/cubefs/cubefs/util/errors"
"github.com/cubefs/cubefs/util/log"
+ sysutil "github.com/cubefs/cubefs/util/sys"
"github.com/cubefs/cubefs/util/ump"
+ "github.com/jacobsa/daemonize"
)
const (
@@ -254,7 +250,7 @@ func main() {
if *redirectSTD {
// Init output file
outputFilePath := path.Join(logDir, module, LoggerOutput)
- outputFile, err := os.OpenFile(outputFilePath, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
+ outputFile, err := os.OpenFile(outputFilePath, os.O_CREATE|os.O_RDWR|os.O_APPEND, 0o666)
if err != nil {
err = errors.NewErrorf("Fatal: failed to open output path - %v", err)
fmt.Println(err)
@@ -290,7 +286,7 @@ func main() {
os.Exit(1)
}
- //for multi-cpu scheduling
+ // for multi-cpu scheduling
runtime.GOMAXPROCS(runtime.NumCPU())
if err = ump.InitUmp(role, umpDatadir); err != nil {
log.LogFlush()
diff --git a/cmd/common/server.go b/cmd/common/server.go
index cdf1527d4..b22f30e1d 100644
--- a/cmd/common/server.go
+++ b/cmd/common/server.go
@@ -27,8 +27,10 @@ type Server interface {
Sync()
}
-type DoStartFunc func(s Server, cfg *config.Config) (err error)
-type DoShutdownFunc func(s Server)
+type (
+ DoStartFunc func(s Server, cfg *config.Config) (err error)
+ DoShutdownFunc func(s Server)
+)
func (c *Control) Start(s Server, cfg *config.Config, do DoStartFunc) (err error) {
if atomic.CompareAndSwapUint32(&c.state, StateStandby, StateStart) {
@@ -47,7 +49,6 @@ func (c *Control) Start(s Server, cfg *config.Config, do DoStartFunc) (err error
c.wg.Add(1)
}
return
-
}
func (c *Control) Shutdown(s Server, do DoShutdownFunc) {
@@ -56,7 +57,6 @@ func (c *Control) Shutdown(s Server, do DoShutdownFunc) {
c.wg.Done()
atomic.StoreUint32(&c.state, StateStopped)
}
-
}
func (c *Control) Sync() {
diff --git a/console/assets_generate_test.go b/console/assets_generate_test.go
index 856397228..6029e2e9f 100644
--- a/console/assets_generate_test.go
+++ b/console/assets_generate_test.go
@@ -1,8 +1,6 @@
package console
import (
- //"github.com/shurcooL/vfsgen"
- //"log"
"net/http"
"path"
"runtime"
@@ -10,8 +8,7 @@ import (
)
func TestMakeHtml2GoBin(t *testing.T) {
-
- //when you need rebuild html . please open it
+ // when you need rebuild html . please open it
return
/*
assets := getAssets()
diff --git a/console/cutil/cache.go b/console/cutil/cache.go
index c9aa1460d..b52737cbd 100644
--- a/console/cutil/cache.go
+++ b/console/cutil/cache.go
@@ -2,11 +2,12 @@ package cutil
import (
"fmt"
+ "sync"
+ "time"
+
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/sdk/graphql/client/user"
"github.com/google/uuid"
- "sync"
- "time"
)
var userTimeout int64 = 1200
@@ -19,7 +20,6 @@ type cacheEntity struct {
}
func TokenValidate(token string) (*user.UserInfo, error) {
-
if token == "" {
return nil, fmt.Errorf("the token not found in head:[%s] or url param:[%s]", proto.HeadAuthorized, proto.ParamAuthorized)
}
diff --git a/console/cutil/handler.go b/console/cutil/handler.go
index 63bd5e448..23d1171ed 100644
--- a/console/cutil/handler.go
+++ b/console/cutil/handler.go
@@ -60,7 +60,6 @@ type httpPostBody struct {
}
func writeResponse(w http.ResponseWriter, code int, value interface{}, err error) {
-
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, PATCH")
w.Header().Set("Access-Control-Allow-Headers", "Origin, Content-Type, Accept, X-Requested-With")
@@ -102,9 +101,8 @@ func writeResponse(w http.ResponseWriter, code int, value interface{}, err error
}
}
-//This code is borrowed https://github.com/samsarahq/thunder
+// This code is borrowed https://github.com/samsarahq/thunder
func (h *graphqlProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-
if r.Method != "POST" {
writeResponse(w, http.StatusMethodNotAllowed, nil, errors.New("request must be a POST"))
return
@@ -173,7 +171,6 @@ func HTTPHandlerWithExecutor(schema *graphql.Schema, executor graphql.ExecutorRu
}
func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
-
if r.Method != "POST" {
writeResponse(w, http.StatusMethodNotAllowed, nil, errors.New("request must be a POST"))
return
@@ -260,7 +257,6 @@ func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Variables: params.Variables,
})
current, err := output.Current, output.Error
-
if err != nil {
if graphql.ErrorCause(err) == context.Canceled {
return nil, err
@@ -295,7 +291,6 @@ func parseResponseNames(r *http.Request) ([]string, error) {
}
return list, nil
-
}
func IQLFun(writer http.ResponseWriter, request *http.Request) {
diff --git a/console/server.go b/console/server.go
index b343df4bc..7a33effad 100644
--- a/console/server.go
+++ b/console/server.go
@@ -60,9 +60,11 @@ func (c *ConsoleNode) Start(cfg *config.Config) error {
c.addHandle(proto.ConsoleFile, fileService.Schema(), fileService)
- indexPaths := []string{"overview", "login", "overview", "userDetails", "servers",
+ indexPaths := []string{
+ "overview", "login", "overview", "userDetails", "servers",
"serverList", "dashboard", "volumeList", "volumeDetail", "fileList", "operations",
- "alarm", "authorization"}
+ "alarm", "authorization",
+ }
for _, path := range indexPaths {
c.server.HandleFunc("/"+path, c.indexer).Methods("GET")
diff --git a/console/server_test.go b/console/server_test.go
index 421a2e12b..4bb522237 100644
--- a/console/server_test.go
+++ b/console/server_test.go
@@ -8,7 +8,6 @@ import (
)
func TestServer(t *testing.T) {
-
return
// if _, err := log.InitLog("/tmp", "console", log.DebugLevel, nil); err != nil {
@@ -61,6 +60,7 @@ func TestServer(t *testing.T) {
type graphErr struct {
Message string
}
+
type graphResponse struct {
Data interface{}
Errors []graphErr
diff --git a/console/service/file.go b/console/service/file.go
index 2b25ee61f..0c6d4fc6f 100644
--- a/console/service/file.go
+++ b/console/service/file.go
@@ -39,8 +39,8 @@ func NewFileService(objectNode string, masters []string, mc *client.MasterGClien
func (fs *FileService) empty(ctx context.Context, args struct {
Empty bool
-}) (bool, error) {
-
+}) (bool, error,
+) {
vol := "test"
userInfo, err := fs.userClient.GetUserInfoForLogin(ctx, "root")
@@ -59,7 +59,6 @@ func (fs *FileService) empty(ctx context.Context, args struct {
return false, fmt.Errorf("%v , [%v] , [%v] , [%v]", userInfo.Policy.Own_vols, userInfo.User_id, fs.userVolPerm(ctx, "root", "test"), v)
}
-
}
type ListFileInfo struct {
@@ -88,7 +87,6 @@ func (fs *FileService) listFile(ctx context.Context, args struct {
}
result, err := volume.ListFilesV1(&args.Request)
-
if err != nil {
return nil, err
}
@@ -104,8 +102,8 @@ func (fs *FileService) listFile(ctx context.Context, args struct {
func (fs *FileService) createDir(ctx context.Context, args struct {
VolName string
Path string
-}) (*FSFileInfo, error) {
-
+}) (*FSFileInfo, error,
+) {
userInfo, _, err := permissions(ctx, USER|ADMIN)
if err != nil {
return nil, err
@@ -130,8 +128,8 @@ func (fs *FileService) createDir(ctx context.Context, args struct {
func (fs *FileService) deleteDir(ctx context.Context, args struct {
VolName string
Path string
-}) (*proto.GeneralResp, error) {
-
+}) (*proto.GeneralResp, error,
+) {
userInfo, _, err := permissions(ctx, USER|ADMIN)
if err != nil {
return nil, err
@@ -197,14 +195,13 @@ func _deleteDir(ctx context.Context, volume *Volume, path string, marker string)
marker = result.NextMarker
}
-
}
func (fs *FileService) deleteFile(ctx context.Context, args struct {
VolName string
Path string
-}) (*proto.GeneralResp, error) {
-
+}) (*proto.GeneralResp, error,
+) {
userInfo, _, err := permissions(ctx, USER|ADMIN)
if err != nil {
return nil, err
@@ -229,8 +226,8 @@ func (fs *FileService) deleteFile(ctx context.Context, args struct {
func (fs *FileService) fileMeta(ctx context.Context, args struct {
VolName string
Path string
-}) (info *FSFileInfo, err error) {
-
+}) (info *FSFileInfo, err error,
+) {
userInfo, _, err := permissions(ctx, USER|ADMIN)
if err != nil {
return nil, err
@@ -268,7 +265,7 @@ func (fs *FileService) signURL(ctx context.Context, args struct {
}
sess := session.Must(session.NewSession())
- var ac = aws.NewConfig()
+ ac := aws.NewConfig()
ac.Endpoint = aws.String(fs.objectNode)
ac.DisableSSL = aws.Bool(true)
ac.Region = aws.String("default")
@@ -396,7 +393,6 @@ func (fs *FileService) UpLoadFile(writer http.ResponseWriter, request *http.Requ
Tagging: nil,
Metadata: nil,
})
-
if err != nil {
return fmt.Errorf("put to object has err:[%s]", err.Error())
}
@@ -446,9 +442,11 @@ func (fs *FileService) Schema() *graphql.Schema {
type volPerm int
-var none = volPerm(0)
-var read = volPerm(1)
-var write = volPerm(2)
+var (
+ none = volPerm(0)
+ read = volPerm(1)
+ write = volPerm(2)
+)
func (v volPerm) read() error {
if v < read {
@@ -465,7 +463,6 @@ func (v volPerm) write() error {
}
func (fs *FileService) userVolPerm(ctx context.Context, userID string, vol string) volPerm {
-
userInfo, err := fs.userClient.GetUserInfoForLogin(ctx, userID)
if err != nil {
log.LogErrorf("found user by id:[%s] has err:[%s]", userID, err.Error())
diff --git a/console/service/login.go b/console/service/login.go
index 7862f1718..765728832 100644
--- a/console/service/login.go
+++ b/console/service/login.go
@@ -3,6 +3,7 @@ package service
import (
"context"
"fmt"
+
"github.com/cubefs/cubefs/console/cutil"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/sdk/graphql/client"
@@ -63,8 +64,10 @@ func (ls *LoginService) Schema() *graphql.Schema {
type permissionMode int
-const ADMIN permissionMode = permissionMode(1)
-const USER permissionMode = permissionMode(2)
+const (
+ ADMIN permissionMode = permissionMode(1)
+ USER permissionMode = permissionMode(2)
+)
func permissions(ctx context.Context, mode permissionMode) (userInfo *user.UserInfo, perm permissionMode, err error) {
userInfo = ctx.Value(proto.UserInfoKey).(*user.UserInfo)
diff --git a/console/service/monitor.go b/console/service/monitor.go
index d5e687e09..10ae1b1a5 100644
--- a/console/service/monitor.go
+++ b/console/service/monitor.go
@@ -3,14 +3,15 @@ package service
import (
"context"
"encoding/json"
- "github.com/samsarahq/thunder/graphql"
- "github.com/samsarahq/thunder/graphql/schemabuilder"
- "io/ioutil"
+ "io"
"net/http"
"net/url"
"strconv"
"strings"
"time"
+
+ "github.com/samsarahq/thunder/graphql"
+ "github.com/samsarahq/thunder/graphql/schemabuilder"
)
type MonitorService struct {
@@ -44,8 +45,8 @@ func (ms *MonitorService) RangeQuery(ctx context.Context, args struct {
Start uint32
End uint32
Step uint32
-}) (string, error) {
-
+}) (string, error,
+) {
args.Query = strings.ReplaceAll(args.Query, "$app", ms.App)
args.Query = strings.ReplaceAll(args.Query, "$cluster", ms.Cluster)
@@ -56,12 +57,11 @@ func (ms *MonitorService) RangeQuery(ctx context.Context, args struct {
param.Set("step", strconv.Itoa(int(args.Step)))
resp, err := http.DefaultClient.Get(ms.Address + "/api/v1/query_range?" + param.Encode())
-
if err != nil {
return "", err
}
- b, err := ioutil.ReadAll(resp.Body)
+ b, err := io.ReadAll(resp.Body)
return string(b), nil
}
@@ -71,8 +71,8 @@ func (ms *MonitorService) RangeQueryURL(ctx context.Context, args struct {
Start uint32
End uint32
Step uint32
-}) (string, error) {
-
+}) (string, error,
+) {
_, _, err := permissions(ctx, ADMIN)
if err != nil {
return "", err
@@ -92,8 +92,8 @@ func (ms *MonitorService) RangeQueryURL(ctx context.Context, args struct {
func (ms *MonitorService) Query(ctx context.Context, args struct {
Query string
-}) (string, error) {
-
+}) (string, error,
+) {
_, _, err := permissions(ctx, ADMIN)
if err != nil {
return "", err
@@ -106,12 +106,11 @@ func (ms *MonitorService) Query(ctx context.Context, args struct {
param.Set("query", args.Query)
resp, err := http.DefaultClient.Get(ms.Address + "/api/v1/query?" + param.Encode())
-
if err != nil {
return "", err
}
- b, err := ioutil.ReadAll(resp.Body)
+ b, err := io.ReadAll(resp.Body)
return string(b), nil
}
@@ -134,7 +133,6 @@ type FuseRecord struct {
}
func (ms *MonitorService) FuseClientList(ctx context.Context, args struct{}) ([]*FuseRecord, error) {
-
_, _, err := permissions(ctx, ADMIN)
if err != nil {
return nil, err
@@ -153,7 +151,7 @@ func (ms *MonitorService) FuseClientList(ctx context.Context, args struct{}) ([]
return nil, err
}
- b, err := ioutil.ReadAll(resp.Body)
+ b, err := io.ReadAll(resp.Body)
result := struct {
Data struct {
diff --git a/datanode/data_partition_repair.go b/datanode/data_partition_repair.go
index bd8ed0875..dedfce500 100644
--- a/datanode/data_partition_repair.go
+++ b/datanode/data_partition_repair.go
@@ -528,9 +528,7 @@ func (dp *DataPartition) streamRepairExtent(remoteExtentInfo *storage.ExtentInfo
return
}
- var (
- hasRecoverySize uint64
- )
+ var hasRecoverySize uint64
var loopTimes uint64
for currFixOffset < dstOffset {
if currFixOffset >= dstOffset {
@@ -584,7 +582,7 @@ func (dp *DataPartition) streamRepairExtent(remoteExtentInfo *storage.ExtentInfo
if reply.ArgLen == TinyExtentRepairReadResponseArgLen {
remoteAvaliSize = binary.BigEndian.Uint64(reply.Arg[9:TinyExtentRepairReadResponseArgLen])
}
- if reply.Arg != nil { //compact v1.2.0 recovery
+ if reply.Arg != nil { // compact v1.2.0 recovery
isEmptyResponse = reply.Arg[0] == EmptyResponse
}
if isEmptyResponse {
@@ -602,7 +600,7 @@ func (dp *DataPartition) streamRepairExtent(remoteExtentInfo *storage.ExtentInfo
log.LogDebugf("streamRepairExtent reply size %v, currFixoffset %v, reply %v ", reply.Size, currFixOffset, reply)
_, err = store.Write(uint64(localExtentInfo.FileID), int64(currFixOffset), int64(reply.Size), reply.Data, reply.CRC, wType, BufferWrite)
}
- //log.LogDebugf("streamRepairExtent reply size %v, currFixoffset %v, reply %v err %v", reply.Size, currFixOffset, reply, err)
+ // log.LogDebugf("streamRepairExtent reply size %v, currFixoffset %v, reply %v err %v", reply.Size, currFixOffset, reply, err)
// write to the local extent file
if err != nil {
err = errors.Trace(err, "streamRepairExtent repair data error ")
diff --git a/datanode/disk.go b/datanode/disk.go
index f7567db9b..530d67a97 100644
--- a/datanode/disk.go
+++ b/datanode/disk.go
@@ -421,7 +421,7 @@ func (d *Disk) CheckDiskError(err error, rwFlag uint8) {
func (d *Disk) doDiskError() {
d.Status = proto.Unavailable
- //d.ForceExitRaftStore()
+ // d.ForceExitRaftStore()
}
func (d *Disk) triggerDiskError(rwFlag uint8, dpId uint64) {
@@ -462,7 +462,7 @@ func (d *Disk) updateSpaceInfo() (err error) {
mesg := fmt.Sprintf("disk path %v error on %v", d.Path, LocalIP)
log.LogErrorf(mesg)
exporter.Warning(mesg)
- //d.ForceExitRaftStore()
+ // d.ForceExitRaftStore()
} else if d.Available <= 0 {
d.Status = proto.ReadOnly
} else {
diff --git a/datanode/partition.go b/datanode/partition.go
index d0fdf7bb3..6a54eca37 100644
--- a/datanode/partition.go
+++ b/datanode/partition.go
@@ -18,7 +18,6 @@ import (
"encoding/json"
"fmt"
"hash/crc32"
- "io/ioutil"
"math"
"net"
"os"
@@ -131,7 +130,7 @@ type DataPartition struct {
verSeqPrepare uint64
verSeqCommitStatus int8
volVersionInfoList *proto.VolVersionInfoList
- decommissionRepairProgress float64 //record repair progress for decommission datapartition
+ decommissionRepairProgress float64 // record repair progress for decommission datapartition
stopRecover bool
recoverErrCnt uint64 // donot reset, if reach max err cnt, delete this dp
@@ -221,7 +220,7 @@ func (dp *DataPartition) ForceSetRaftRunning() {
// and creates the partition instance.
func LoadDataPartition(partitionDir string, disk *Disk) (dp *DataPartition, err error) {
var metaFileData []byte
- if metaFileData, err = ioutil.ReadFile(path.Join(partitionDir, DataPartitionMetadataFileName)); err != nil {
+ if metaFileData, err = os.ReadFile(path.Join(partitionDir, DataPartitionMetadataFileName)); err != nil {
return
}
meta := &DataPartitionMetadata{}
@@ -323,7 +322,7 @@ func newDataPartition(dpCfg *dataPartitionCfg, disk *Disk, isCreate bool) (dp *D
log.LogWarnf("action[newDataPartition] dp %v NewExtentStore failed %v", partitionID, err.Error())
return
}
- //store applyid
+ // store applyid
if err = partition.storeAppliedID(partition.appliedID); err != nil {
log.LogErrorf("action[newDataPartition] dp %v initial Apply [%v] failed: %v",
partition.partitionID, partition.appliedID, err)
@@ -602,7 +601,7 @@ func (dp *DataPartition) statusUpdate() {
log.LogInfof("action[statusUpdate] dp %v raft status %v dp.status %v, status %v, disk status %v",
dp.partitionID, dp.raftStatus, dp.Status(), status, float64(dp.disk.Status))
- //dp.partitionStatus = int(math.Min(float64(status), float64(dp.disk.Status)))
+ // dp.partitionStatus = int(math.Min(float64(status), float64(dp.disk.Status)))
dp.partitionStatus = status
}
@@ -632,7 +631,7 @@ func (dp *DataPartition) checkIsDiskError(err error, rwFlag uint8) {
dp.incDiskErrCnt()
dp.disk.triggerDiskError(rwFlag, dp.partitionID)
- //must after change disk.status
+ // must after change disk.status
dp.statusUpdate()
return
}
diff --git a/datanode/partition_op_by_raft.go b/datanode/partition_op_by_raft.go
index f87c86f58..36739dae3 100644
--- a/datanode/partition_op_by_raft.go
+++ b/datanode/partition_op_by_raft.go
@@ -198,9 +198,9 @@ func (si *ItemIterator) Close() {
// Next returns the next item in the iterator.
func (si *ItemIterator) Next() (data []byte, err error) {
- //appIDBuf := make([]byte, 8)
- //binary.BigEndian.PutUint64(appIDBuf, si.applyID)
- //data = appIDBuf[:]
+ // appIDBuf := make([]byte, 8)
+ // binary.BigEndian.PutUint64(appIDBuf, si.applyID)
+ // data = appIDBuf[:]
err = io.EOF
return
}
diff --git a/datanode/partition_raft.go b/datanode/partition_raft.go
index e2f3cd258..78b87d54d 100644
--- a/datanode/partition_raft.go
+++ b/datanode/partition_raft.go
@@ -18,7 +18,6 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
- "io/ioutil"
"net"
"os"
"path"
@@ -473,7 +472,7 @@ func (dp *DataPartition) LoadAppliedID() (err error) {
if _, err = os.Stat(filename); err != nil {
return
}
- data, err := ioutil.ReadFile(filename)
+ data, err := os.ReadFile(filename)
if err != nil {
err = errors.NewErrorf("[loadApplyIndex] OpenFile: %s", err.Error())
return
@@ -682,7 +681,6 @@ func (dp *DataPartition) getLeaderPartitionSize(maxExtentID uint64) (size uint64
}
func (dp *DataPartition) getMaxExtentIDAndPartitionSize(target string) (maxExtentID, PartitionSize uint64, err error) {
-
var conn *net.TCPConn
p := NewPacketToGetMaxExtentIDAndPartitionSIze(dp.partitionID)
diff --git a/datanode/wrap_post.go b/datanode/wrap_post.go
index ab57cc63d..87c5e9f3d 100644
--- a/datanode/wrap_post.go
+++ b/datanode/wrap_post.go
@@ -15,9 +15,9 @@
package datanode
import (
- "github.com/cubefs/cubefs/proto"
"sync/atomic"
+ "github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/repl"
"github.com/cubefs/cubefs/storage"
)
diff --git a/deploy/cmd/cluster.go b/deploy/cmd/cluster.go
index 2a5253b07..e6bc4eb96 100644
--- a/deploy/cmd/cluster.go
+++ b/deploy/cmd/cluster.go
@@ -61,7 +61,6 @@ var configCommand = &cobra.Command{
if err != nil {
log.Println(err)
}
-
},
}
@@ -80,9 +79,7 @@ func getCurrentIP() (string, error) {
for _, addr := range addrs {
if ipv4 := addr.To4(); ipv4 != nil {
-
return ipv4.String(), nil
-
}
}
@@ -167,8 +164,8 @@ func removeDuplicates(slice []string) []string {
return result
}
-func initCluster() {
+func initCluster() {
config, err := readConfig()
if err != nil {
log.Fatal(err)
@@ -227,9 +224,9 @@ func initCluster() {
log.Printf("Successfully pulled mirror % s on node % s", config.Global.ContainerImage, node)
}
- //create dir
+ // create dir
err = createRemoteFolder(RemoteUser, node, config.Global.DataDir)
- //check firewall
+ // check firewall
if err != nil {
log.Println(err)
}
@@ -241,9 +238,9 @@ func initCluster() {
if err != nil {
log.Println(err)
}
- //create conf dir
+ // create conf dir
err = createRemoteFolder(RemoteUser, node, config.Global.DataDir+"/conf")
- //check firewall
+ // check firewall
if err != nil {
log.Println(err)
}
@@ -278,7 +275,6 @@ func cleanContainerAndLogs() {
log.Fatalln(err)
}
}
-
}
func init() {
@@ -287,5 +283,4 @@ func init() {
ClusterCmd.AddCommand(clearCommand)
ClusterCmd.AddCommand(configCommand)
configCommand.PersistentFlags().StringVarP(&ConfigFileName, "file", "f", "", "Specify the location of the configuration file relative to cfs deploy")
-
}
diff --git a/deploy/cmd/config.go b/deploy/cmd/config.go
index 11cf8480b..bee55f6cb 100644
--- a/deploy/cmd/config.go
+++ b/deploy/cmd/config.go
@@ -1,8 +1,8 @@
package cmd
import (
- "io/ioutil"
"log"
+ "os"
"strconv"
"gopkg.in/yaml.v2"
@@ -67,8 +67,7 @@ type DiskInfo struct {
}
func readConfig() (*Config, error) {
-
- data, err := ioutil.ReadFile(ConfigFileName)
+ data, err := os.ReadFile(ConfigFileName)
if err != nil {
log.Println("Unable to read configuration file:", err)
return nil, err
@@ -81,7 +80,6 @@ func readConfig() (*Config, error) {
return nil, err
}
return config, nil
-
}
func convertToJosn() error {
diff --git a/deploy/cmd/datanode.go b/deploy/cmd/datanode.go
index e380c1f5c..4d2cf2dce 100644
--- a/deploy/cmd/datanode.go
+++ b/deploy/cmd/datanode.go
@@ -75,7 +75,7 @@ func writeDataNode(listen, prof, id, localIP string, masterAddrs, disks []string
return err
}
- err = ioutil.WriteFile(ConfDir+"/datanode"+id+".json", dataNodeData, 0644)
+ err = ioutil.WriteFile(ConfDir+"/datanode"+id+".json", dataNodeData, 0o644)
if err != nil {
log.Println("Unable to write to DataNode.json file:", err)
return err
@@ -93,7 +93,7 @@ func startAllDataNode() error {
diskMap := ""
for _, info := range node.Disk {
diskMap += " -v " + info.Path + ":/cfs" + info.Path
- //disksInfo = append(disksInfo, "/cfs"+info.Path+":"+info.Size)
+ // disksInfo = append(disksInfo, "/cfs"+info.Path+":"+info.Size)
}
disksInfo = append(disksInfo, diskMap)
}
@@ -133,7 +133,6 @@ func startAllDataNode() error {
index++
log.Println(status)
}
-
}
log.Println("start all datanode services")
@@ -141,7 +140,6 @@ func startAllDataNode() error {
}
func startDatanodeInSpecificNode(node string) error {
-
config, err := readConfig()
if err != nil {
return err
@@ -168,7 +166,6 @@ func startDatanodeInSpecificNode(node string) error {
diskMap := ""
for _, info := range n.Disk {
diskMap += " -v " + info.Path + ":/cfs" + info.Path
-
}
status, err := startDatanodeContainerOnNode(RemoteUser, node, DataNodeName+strconv.Itoa(id+1), dataDir, diskMap)
if err != nil {
@@ -205,7 +202,6 @@ func stopDatanodeInSpecificNode(node string) error {
}
func stopAllDataNode() error {
-
files, err := ioutil.ReadDir(ConfDir)
if err != nil {
return err
diff --git a/deploy/cmd/docker.go b/deploy/cmd/docker.go
index 6cf0f20f9..bd8804054 100644
--- a/deploy/cmd/docker.go
+++ b/deploy/cmd/docker.go
@@ -18,7 +18,6 @@ func stopContainerOnNode(nodeUser, node, containerName string) (string, error) {
return fmt.Sprintf("successful stop %s on node %s", containerName, node), nil
}
return fmt.Sprintf("%s on node %s already stopped", containerName, node), nil
-
}
func rmContainerOnNode(nodeUser, node, containerName string) (string, error) {
@@ -31,7 +30,6 @@ func rmContainerOnNode(nodeUser, node, containerName string) (string, error) {
return fmt.Sprintf("successful rm %s on node %s", containerName, node), nil
}
return fmt.Sprintf("%s on node %s already removed", containerName, node), nil
-
}
func startMasterContainerOnNode(nodeUser, node, containerName, dataDir string) (string, error) {
@@ -122,7 +120,7 @@ func checkAndInstallDocker(nodeUser, node string) error {
cmd := exec.Command("ssh", nodeUser+"@"+node, "docker --version")
output, err := cmd.Output()
if err == nil && strings.Contains(string(output), "Docker version") {
- //log.Println("Docker installed")
+ // log.Println("Docker installed")
return nil
}
@@ -140,7 +138,6 @@ func checkAndInstallDocker(nodeUser, node string) error {
}
return nil
-
}
// Check if the Docker service is started and started
@@ -194,7 +191,6 @@ func removeImageOnNode(nodeUser, node, imageName string) error {
}
func containerStatus(nodeUser, node, containerName string) (string, error) {
-
cmd := exec.Command("ssh", nodeUser+"@"+node, "docker inspect --format='{{.State.Status}}' "+containerName)
output, err := cmd.Output()
if err != nil {
@@ -202,5 +198,4 @@ func containerStatus(nodeUser, node, containerName string) (string, error) {
}
return string(output), nil
-
}
diff --git a/deploy/cmd/firewall.go b/deploy/cmd/firewall.go
index 780ea39be..8a7399803 100644
--- a/deploy/cmd/firewall.go
+++ b/deploy/cmd/firewall.go
@@ -53,14 +53,12 @@ import (
// }
func stopFirewall(nodeUser, node string) {
-
cmd := exec.Command("ssh", nodeUser+"@"+node, "systemctl", "stop firewalld")
err := cmd.Run()
if err != nil {
log.Println(err)
}
log.Println(cmd)
-
}
func checkPortStatus(nodeUser, node string, port string) (string, error) {
diff --git a/deploy/cmd/master.go b/deploy/cmd/master.go
index 8931b6eae..757dc3e76 100644
--- a/deploy/cmd/master.go
+++ b/deploy/cmd/master.go
@@ -39,7 +39,6 @@ func getMasterPeers(config *Config) string {
} else {
peers = peers + strconv.Itoa(id+1) + ":" + node + ":" + config.Master.Config.Listen
}
-
}
return peers
}
@@ -87,16 +86,14 @@ func writeMaster(clusterName, id, ip, listen, prof, peers string) error {
return fmt.Errorf("cannot be resolved to master.json %v", err)
}
fileName := ConfDir + "/master" + id + ".json"
- err = ioutil.WriteFile(fileName, masterData, 0644)
+ err = ioutil.WriteFile(fileName, masterData, 0o644)
if err != nil {
-
return fmt.Errorf("unable to write %s %v", fileName, err)
}
return nil
}
func startAllMaster() error {
-
config, err := readConfig()
if err != nil {
return err
@@ -120,7 +117,6 @@ func startAllMaster() error {
dataDir = config.Global.DataDir
} else {
dataDir = config.Master.Config.DataDir
-
}
err = transferConfigFileToRemote(confFilePath, dataDir+"/conf", RemoteUser, data.IP)
if err != nil {
@@ -137,13 +133,12 @@ func startAllMaster() error {
log.Println(status)
}
}
- //Detect successful deployment
+ // Detect successful deployment
log.Println("start all master services")
return nil
}
func stopAllMaster() error {
-
files, err := ioutil.ReadDir(ConfDir)
if err != nil {
return err
@@ -167,7 +162,6 @@ func stopAllMaster() error {
}
log.Println(status)
}
-
}
return nil
}
diff --git a/deploy/cmd/metanode.go b/deploy/cmd/metanode.go
index b5ce401a5..6c3a38841 100644
--- a/deploy/cmd/metanode.go
+++ b/deploy/cmd/metanode.go
@@ -63,16 +63,14 @@ func writeMetaNode(listen, prof, id, localIP string, masterAddrs []string) error
if err != nil {
return err
}
- err = ioutil.WriteFile(ConfDir+"/metanode"+id+".json", metaNodeData, 0644)
+ err = ioutil.WriteFile(ConfDir+"/metanode"+id+".json", metaNodeData, 0o644)
if err != nil {
return err
}
return nil
-
}
func stopMetanodeInSpecificNode(node string) error {
-
files, err := ioutil.ReadDir(ConfDir)
if err != nil {
return err
@@ -101,7 +99,6 @@ func stopMetanodeInSpecificNode(node string) error {
}
return nil
-
}
func startMetanodeInSpecificNode(node string) error {
@@ -127,7 +124,6 @@ func startMetanodeInSpecificNode(node string) error {
dataDir = config.Global.DataDir
} else {
dataDir = config.MetaNode.Config.DataDir
-
}
confFilePath := ConfDir + "/" + file.Name()
err = transferConfigFileToRemote(confFilePath, dataDir+"/conf", RemoteUser, node)
@@ -166,7 +162,6 @@ func getMasterAddrAndPort() ([]string, error) {
}
func startAllMetaNode() error {
-
config, err := readConfig()
if err != nil {
return err
@@ -190,7 +185,6 @@ func startAllMetaNode() error {
dataDir = config.Global.DataDir
} else {
dataDir = config.MetaNode.Config.DataDir
-
}
err = transferConfigFileToRemote(confFilePath, dataDir+"/conf", RemoteUser, data.LocalIP)
if err != nil {
@@ -208,13 +202,12 @@ func startAllMetaNode() error {
}
}
- //Detect successful deployment
+ // Detect successful deployment
log.Println("start all metanode services")
return nil
}
func stopAllMetaNode() error {
-
files, err := ioutil.ReadDir(ConfDir)
if err != nil {
return err
diff --git a/deploy/cmd/restart.go b/deploy/cmd/restart.go
index ec6df2f4a..e335b9f3c 100644
--- a/deploy/cmd/restart.go
+++ b/deploy/cmd/restart.go
@@ -53,7 +53,6 @@ var restartMasterCommand = &cobra.Command{
Short: "",
Long: "",
Run: func(cmd *cobra.Command, args []string) {
-
err := stopAllMaster()
if err != nil {
log.Println(err)
@@ -132,5 +131,4 @@ func init() {
RestartCmd.Flags().BoolVarP(&allRestart, "all", "a", false, "restart all services")
RestartCmd.PersistentFlags().StringVarP(&ip, "ip", "", "", "specify an IP address to start services")
restartDatanodeCommand.Flags().StringVarP(&datanodeDisk, "disk", "d", "", "specify the disk where datanode mount")
-
}
diff --git a/deploy/cmd/root.go b/deploy/cmd/root.go
index 65849839f..d21a182b6 100644
--- a/deploy/cmd/root.go
+++ b/deploy/cmd/root.go
@@ -7,17 +7,21 @@ import (
"github.com/spf13/cobra"
)
-var Version bool
-var CubeFSPath string
-var ConfDir string
-var ScriptDir string
-var BinDir string
-var ConfigFileName string
-var ImageName string
+var (
+ Version bool
+ CubeFSPath string
+ ConfDir string
+ ScriptDir string
+ BinDir string
+ ConfigFileName string
+ ImageName string
+)
-const envVar = "CUBEFS"
-const ClusterName = "cubeFS"
-const RemoteUser = "root"
+const (
+ envVar = "CUBEFS"
+ ClusterName = "cubeFS"
+ RemoteUser = "root"
+)
const BinVersion = "release-3.2.1"
@@ -66,7 +70,6 @@ var RootCmd = &cobra.Command{
Short: "CLI for managing CubeFS server and client using Docker",
Long: `cubefs is a CLI application for managing CubeFS, an open-source distributed file system, using Docker containers.`,
Run: func(cmd *cobra.Command, args []string) {
-
if Version {
fmt.Printf("deploy-cli version 0.0.1 cubefs version %s \n", BinVersion)
} else {
diff --git a/deploy/cmd/ssh.go b/deploy/cmd/ssh.go
index 89374efa9..bd381740f 100644
--- a/deploy/cmd/ssh.go
+++ b/deploy/cmd/ssh.go
@@ -11,7 +11,7 @@ import (
func generateSSHKey() error {
// Check if the private and public key files already exist
privateKeyPath := os.Getenv("HOME") + "/.ssh/id_rsa"
- //publicKeyPath := privateKeyPath + ".pub"
+ // publicKeyPath := privateKeyPath + ".pub"
if _, err := os.Stat(privateKeyPath); err == nil {
return fmt.Errorf("SSH key already exists")
}
@@ -30,7 +30,6 @@ func generateSSHKey() error {
// Establishing a secure connection
func establishSSHConnectionWithoutPassword(sourceNode, targetNodeUser, targetNode string) error {
-
// Check if the private and public key files already exist and generate an SSH key pairs
generateSSHKey()
diff --git a/deploy/cmd/start.go b/deploy/cmd/start.go
index 560de460c..3c28f0604 100644
--- a/deploy/cmd/start.go
+++ b/deploy/cmd/start.go
@@ -7,10 +7,12 @@ import (
"github.com/spf13/cobra"
)
-var ip string
-var allStart bool
-var datanodeDisk string
-var disk string
+var (
+ ip string
+ allStart bool
+ datanodeDisk string
+ disk string
+)
var StartCmd = &cobra.Command{
Use: "start",
@@ -37,7 +39,6 @@ var StartCmd = &cobra.Command{
} else {
fmt.Println(cmd.UsageString())
}
-
},
}
@@ -81,7 +82,6 @@ var startMetanodeCommand = &cobra.Command{
log.Println(err)
}
}
-
},
}
diff --git a/deploy/cmd/start_docker_compose.go b/deploy/cmd/start_docker_compose.go
index 4af5ac9ef..994b799ca 100644
--- a/deploy/cmd/start_docker_compose.go
+++ b/deploy/cmd/start_docker_compose.go
@@ -10,7 +10,7 @@ import (
func startALLFromDockerCompose(disk string) error {
scriptPath := CubeFSPath + "/docker/run_docker.sh"
args := []string{"-r", "-d", disk}
- err := os.Chmod(scriptPath, 0700)
+ err := os.Chmod(scriptPath, 0o700)
if err != nil {
log.Fatal(err)
}
@@ -23,7 +23,6 @@ func startALLFromDockerCompose(disk string) error {
}
func stopALLFromDockerCompose() error {
-
err := os.Chdir(CubeFSPath + "/docker")
if err != nil {
return err
diff --git a/deploy/cmd/stop.go b/deploy/cmd/stop.go
index ab704f19c..bad3a99aa 100644
--- a/deploy/cmd/stop.go
+++ b/deploy/cmd/stop.go
@@ -38,6 +38,7 @@ var StopCmd = &cobra.Command{
}
},
}
+
var stopFromDockerCompose = &cobra.Command{
Use: "test",
Short: "start test for on node",
@@ -114,5 +115,4 @@ func init() {
StopCmd.Flags().BoolVarP(&allStop, "all", "a", false, "stop all services")
StopCmd.PersistentFlags().StringVarP(&ip, "ip", "", "", "specify an IP address to start services")
stopDatanodeCommand.Flags().StringVarP(&datanodeDisk, "disk", "d", "", "specify the disk where datanode mount")
-
}
diff --git a/deploy/cmd/transform.go b/deploy/cmd/transform.go
index b4782f4e4..b6f399ecf 100644
--- a/deploy/cmd/transform.go
+++ b/deploy/cmd/transform.go
@@ -28,7 +28,6 @@ func transferConfigFileToRemote(localFilePath string, remoteFilePath string, rem
}
func transferDirectoryToRemote(localFilePath string, remoteFilePath string, remoteUser string, remoteHost string) error {
-
localFile, err := os.Open(localFilePath)
if err != nil {
return fmt.Errorf("failed to open local file: %s", err)
@@ -86,7 +85,6 @@ func copyFolder(sourcePath, destinationPath string) error {
return nil
})
-
if err != nil {
return err
}
@@ -102,12 +100,12 @@ func createRemoteFolder(nodeUser, node, folderPath string) error {
return err
}
return nil
-
}
+
func createFolder(folderPath string) error {
_, err := os.Stat(folderPath)
if os.IsNotExist(err) {
- err := os.MkdirAll(folderPath, 0755)
+ err := os.MkdirAll(folderPath, 0o755)
if err != nil {
return err
}
diff --git a/deploy/deploy_cli.go b/deploy/deploy_cli.go
index 08420b381..90b515c82 100644
--- a/deploy/deploy_cli.go
+++ b/deploy/deploy_cli.go
@@ -2,9 +2,10 @@ package main
import (
"fmt"
+ "os"
+
"github.com/cubefs/cubefs/deploy/cmd"
"github.com/cubefs/cubefs/util/log"
- "os"
)
func init() {
@@ -13,11 +14,9 @@ func init() {
cmd.RootCmd.AddCommand(cmd.StartCmd)
cmd.RootCmd.AddCommand(cmd.StopCmd)
cmd.RootCmd.AddCommand(cmd.RestartCmd)
-
}
func main() {
-
_, err := log.InitLog("/tmp/cfs", "deploy", log.DebugLevel, nil, log.DefaultLogLeftSpaceLimit)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
@@ -32,5 +31,4 @@ func main() {
log.LogFlush()
os.Exit(1)
}
-
}
diff --git a/docker/script/run_format.sh b/docker/script/run_format.sh
index 55d7ec16c..36d371a22 100755
--- a/docker/script/run_format.sh
+++ b/docker/script/run_format.sh
@@ -1,13 +1,16 @@
#!/bin/bash
CurrentPath=$(cd $(dirname ${BASH_SOURCE[0]}); pwd)
+gofmtFile=gofmt_results.diff
pushd ${CurrentPath}/../../
-find . -type f -name "*.go" | grep -v 'vendor' |grep -v 'depends'| xargs gofmt -l -d > gofmt_results.txt
-cat gofmt_results.txt
-if [ "$(cat gofmt_results.txt|wc -l)" -gt 0 ]; then
+find . -type f -name "*.go" | \
+ grep -v 'vendor'|grep -v 'depends'|grep -v ./sdk/graphql/client/ | \
+ xargs gofumpt -l -d > ${gofmtFile}
+cat ${gofmtFile}
+if [ "$(cat ${gofmtFile}|wc -l)" -gt 0 ]; then
popd
exit 1;
fi
-rm -f gofmt_results.txt
+rm -f ${gofmtFile}
popd
export PATH=$PATH:/go/bin
diff --git a/fdstore/fdstore.go b/fdstore/fdstore.go
index e7f527ba0..f0592e14b 100644
--- a/fdstore/fdstore.go
+++ b/fdstore/fdstore.go
@@ -18,7 +18,6 @@ import (
"flag"
"fmt"
"io"
- "io/ioutil"
"net"
"net/http"
"os"
@@ -65,7 +64,7 @@ func createUDS() (listener net.Listener, err error) {
return
}
- if err = os.Chmod(sockAddr, 0666); err != nil {
+ if err = os.Chmod(sockAddr, 0o666); err != nil {
fmt.Printf("failed to chmod socket file: %v\n", err)
listener.Close()
return
@@ -162,7 +161,7 @@ func SendSuspendRequest(port string, udsListener net.Listener) (err error) {
}
defer resp.Body.Close()
- if data, err = ioutil.ReadAll(resp.Body); err != nil {
+ if data, err = io.ReadAll(resp.Body); err != nil {
fmt.Fprintf(os.Stderr, "Failed to read response: %v\n", err)
return err
}
@@ -193,17 +192,17 @@ func doSuspend(port string) error {
defer destroyUDS(udsListener)
if err = SendSuspendRequest(port, udsListener); err != nil {
- //SendResumeRequest(port)
+ // SendResumeRequest(port)
return err
}
if fud, err = RecvFuseFdFromOldClient(udsListener); err != nil {
- //SendResumeRequest(port)
+ // SendResumeRequest(port)
return err
}
if err = SendFuseFdToNewClient(udsListener, fud); err != nil {
- //SendResumeRequest(port)
+ // SendResumeRequest(port)
return err
}
@@ -231,7 +230,7 @@ func SendResumeRequest(port string) (err error) {
}
defer resp.Body.Close()
- if data, err = ioutil.ReadAll(resp.Body); err != nil {
+ if data, err = io.ReadAll(resp.Body); err != nil {
fmt.Fprintf(os.Stderr, "Failed to read response: %v\n", err)
return err
}
@@ -255,7 +254,7 @@ func doDump(filePathes string) {
nodes := make([]*fs.ContextNode, 0)
handles := make([]*fs.ContextHandle, 0)
- nodeListFile, err := os.OpenFile(pathes[0], os.O_RDONLY, 0644)
+ nodeListFile, err := os.OpenFile(pathes[0], os.O_RDONLY, 0o644)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to open nodes list file: %v\n", err)
return
@@ -299,7 +298,7 @@ func doDump(filePathes string) {
i++
}
- handleListFile, err := os.OpenFile(pathes[1], os.O_RDONLY, 0644)
+ handleListFile, err := os.OpenFile(pathes[1], os.O_RDONLY, 0o644)
if err != nil {
err = fmt.Errorf("failed to open handles list file: %v\n", err)
return
diff --git a/fsck/cmd/check.go b/fsck/cmd/check.go
index 6de54810a..2075c1f52 100644
--- a/fsck/cmd/check.go
+++ b/fsck/cmd/check.go
@@ -33,7 +33,7 @@ const (
)
func newCheckCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "check",
Short: "check and verify specified volume",
Args: cobra.MinimumNArgs(0),
@@ -49,7 +49,7 @@ func newCheckCmd() *cobra.Command {
}
func newCheckInodeCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "inode",
Short: "check and verify inode",
Run: func(cmd *cobra.Command, args []string) {
@@ -63,7 +63,7 @@ func newCheckInodeCmd() *cobra.Command {
}
func newCheckDentryCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "dentry",
Short: "check and verify dentry",
Run: func(cmd *cobra.Command, args []string) {
@@ -77,7 +77,7 @@ func newCheckDentryCmd() *cobra.Command {
}
func newCheckBothCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "both",
Short: "check and verify both inode and dentry",
Run: func(cmd *cobra.Command, args []string) {
@@ -111,7 +111,7 @@ func Check(chkopt int) (err error) {
)
dirPath := fmt.Sprintf("_export_%s", VolName)
- if err = os.MkdirAll(dirPath, 0666); err != nil {
+ if err = os.MkdirAll(dirPath, 0o666); err != nil {
return
}
diff --git a/fsck/cmd/clean.go b/fsck/cmd/clean.go
index 35f549969..c8fc8e6e5 100644
--- a/fsck/cmd/clean.go
+++ b/fsck/cmd/clean.go
@@ -39,7 +39,7 @@ const (
var gMetaWrapper *meta.MetaWrapper
func newCleanCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "clean",
Short: "clean dirty inode or dentry according to some rules",
Args: cobra.MinimumNArgs(0),
@@ -55,7 +55,7 @@ func newCleanCmd() *cobra.Command {
}
func newCleanInodeCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "inode",
Short: "clean dirty inode",
Run: func(cmd *cobra.Command, args []string) {
@@ -69,7 +69,7 @@ func newCleanInodeCmd() *cobra.Command {
}
func newCleanDentryCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "dentry",
Short: "clean dirty dentry",
Run: func(cmd *cobra.Command, args []string) {
@@ -83,7 +83,7 @@ func newCleanDentryCmd() *cobra.Command {
}
func newEvictInodeCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "evict",
Short: "clean dirty dentry",
Run: func(cmd *cobra.Command, args []string) {
@@ -111,7 +111,7 @@ func Clean(opt string) error {
}
masters := strings.Split(MasterAddr, meta.HostsSeparator)
- var metaConfig = &meta.MetaConfig{
+ metaConfig := &meta.MetaConfig{
Volume: VolName,
Masters: masters,
}
@@ -193,6 +193,7 @@ func evictOnTime(wg *sync.WaitGroup, cmdline string) {
}
log.LogWritef("Done! Dealing with meta partition: %v", cmdline)
}
+
func cleanInodes() error {
filePath := fmt.Sprintf("_export_%s/%s", VolName, obsoleteInodeDumpFileName)
@@ -258,7 +259,7 @@ func doUnlinkInode(inode *Inode) error {
}
func cleanDentries() error {
- //filePath := fmt.Sprintf("_export_%s/%s", VolName, obsoleteDentryDumpFileName)
+ // filePath := fmt.Sprintf("_export_%s/%s", VolName, obsoleteDentryDumpFileName)
// TODO: send request to meta node directly with pino, name and ino.
return nil
}
diff --git a/fsck/cmd/getInfo.go b/fsck/cmd/getInfo.go
index 42bd1cc06..c89a2560b 100644
--- a/fsck/cmd/getInfo.go
+++ b/fsck/cmd/getInfo.go
@@ -44,7 +44,7 @@ type Summary struct {
}
func newInfoCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "get",
Short: "get info of specified inode",
Args: cobra.MinimumNArgs(0),
@@ -60,7 +60,7 @@ func newInfoCmd() *cobra.Command {
}
func newGetLocationsCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "locations",
Short: "get inode's locations",
Args: cobra.MinimumNArgs(0),
@@ -75,7 +75,7 @@ func newGetLocationsCmd() *cobra.Command {
}
func newGetPathCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "path",
Short: "get inode's path",
Args: cobra.MinimumNArgs(0),
@@ -90,7 +90,7 @@ func newGetPathCmd() *cobra.Command {
}
func newGetSummaryCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "summary",
Short: "get inode's summary",
Args: cobra.MinimumNArgs(0),
diff --git a/fsck/cmd/root.go b/fsck/cmd/root.go
index 1860a9d35..ae0cecc88 100644
--- a/fsck/cmd/root.go
+++ b/fsck/cmd/root.go
@@ -19,13 +19,14 @@ import (
"os"
"path"
- "github.com/cubefs/cubefs/proto"
"github.com/spf13/cobra"
+
+ "github.com/cubefs/cubefs/proto"
)
func NewRootCmd() *cobra.Command {
var optShowVersion bool
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: path.Base(os.Args[0]),
Short: "CubeFS fsck tool",
Args: cobra.MinimumNArgs(0),
diff --git a/libsdk/libsdk.go b/libsdk/libsdk.go
index 7d3d0fea5..a0a4c314a 100644
--- a/libsdk/libsdk.go
+++ b/libsdk/libsdk.go
@@ -201,7 +201,7 @@ type file struct {
// dir only
dirp *dirStream
- //rw
+ // rw
fileWriter *blobstore.Writer
fileReader *blobstore.Reader
@@ -414,13 +414,13 @@ func cfs_getattr(id C.int64_t, path *C.char, stat *C.struct_cfs_stat_info) C.int
}
// fill up the mode
if proto.IsRegular(info.Mode) {
- stat.mode = C.uint32_t(C.S_IFREG) | C.uint32_t(info.Mode&0777)
+ stat.mode = C.uint32_t(C.S_IFREG) | C.uint32_t(info.Mode&0o777)
} else if proto.IsDir(info.Mode) {
- stat.mode = C.uint32_t(C.S_IFDIR) | C.uint32_t(info.Mode&0777)
+ stat.mode = C.uint32_t(C.S_IFDIR) | C.uint32_t(info.Mode&0o777)
} else if proto.IsSymlink(info.Mode) {
- stat.mode = C.uint32_t(C.S_IFLNK) | C.uint32_t(info.Mode&0777)
+ stat.mode = C.uint32_t(C.S_IFLNK) | C.uint32_t(info.Mode&0o777)
} else {
- stat.mode = C.uint32_t(C.S_IFSOCK) | C.uint32_t(info.Mode&0777)
+ stat.mode = C.uint32_t(C.S_IFSOCK) | C.uint32_t(info.Mode&0o777)
}
// fill up the time struct
@@ -468,7 +468,7 @@ func cfs_open(id C.int64_t, path *C.char, flags C.int, mode C.mode_t) C.int {
}
start := time.Now()
- fuseMode := uint32(mode) & uint32(0777)
+ fuseMode := uint32(mode) & uint32(0o777)
fuseFlags := uint32(flags) &^ uint32(0x8000)
accFlags := fuseFlags & uint32(C.O_ACCMODE)
@@ -708,13 +708,13 @@ func cfs_batch_get_inodes(id C.int64_t, fd C.int, iids unsafe.Pointer, stats []C
// fill up the mode
if proto.IsRegular(infos[i].Mode) {
- stats[i].mode = C.uint32_t(C.S_IFREG) | C.uint32_t(infos[i].Mode&0777)
+ stats[i].mode = C.uint32_t(C.S_IFREG) | C.uint32_t(infos[i].Mode&0o777)
} else if proto.IsDir(infos[i].Mode) {
- stats[i].mode = C.uint32_t(C.S_IFDIR) | C.uint32_t(infos[i].Mode&0777)
+ stats[i].mode = C.uint32_t(C.S_IFDIR) | C.uint32_t(infos[i].Mode&0o777)
} else if proto.IsSymlink(infos[i].Mode) {
- stats[i].mode = C.uint32_t(C.S_IFLNK) | C.uint32_t(infos[i].Mode&0777)
+ stats[i].mode = C.uint32_t(C.S_IFLNK) | C.uint32_t(infos[i].Mode&0o777)
} else {
- stats[i].mode = C.uint32_t(C.S_IFSOCK) | C.uint32_t(infos[i].Mode&0777)
+ stats[i].mode = C.uint32_t(C.S_IFSOCK) | C.uint32_t(infos[i].Mode&0o777)
}
// fill up the time struct
@@ -882,13 +882,13 @@ func cfs_lsdir(id C.int64_t, fd C.int, direntsInfo []C.struct_cfs_dirent_info, c
// fill up the mode
if proto.IsRegular(infos[i].Mode) {
- direntsInfo[index].stat.mode = C.uint32_t(C.S_IFREG) | C.uint32_t(infos[i].Mode&0777)
+ direntsInfo[index].stat.mode = C.uint32_t(C.S_IFREG) | C.uint32_t(infos[i].Mode&0o777)
} else if proto.IsDir(infos[i].Mode) {
- direntsInfo[index].stat.mode = C.uint32_t(C.S_IFDIR) | C.uint32_t(infos[i].Mode&0777)
+ direntsInfo[index].stat.mode = C.uint32_t(C.S_IFDIR) | C.uint32_t(infos[i].Mode&0o777)
} else if proto.IsSymlink(infos[i].Mode) {
- direntsInfo[index].stat.mode = C.uint32_t(C.S_IFLNK) | C.uint32_t(infos[i].Mode&0777)
+ direntsInfo[index].stat.mode = C.uint32_t(C.S_IFLNK) | C.uint32_t(infos[i].Mode&0o777)
} else {
- direntsInfo[index].stat.mode = C.uint32_t(C.S_IFSOCK) | C.uint32_t(infos[i].Mode&0777)
+ direntsInfo[index].stat.mode = C.uint32_t(C.S_IFSOCK) | C.uint32_t(infos[i].Mode&0o777)
}
// fill up the time struct
@@ -901,7 +901,6 @@ func cfs_lsdir(id C.int64_t, fd C.int, direntsInfo []C.struct_cfs_dirent_info, c
direntsInfo[index].stat.mtime_nsec = C.uint32_t(t % 1e9)
}
return n
-
}
//export cfs_mkdirs
@@ -1146,7 +1145,7 @@ func (c *client) absPath(path string) string {
}
func (c *client) start() (err error) {
- var masters = strings.Split(c.masterAddr, ",")
+ masters := strings.Split(c.masterAddr, ",")
if c.logDir != "" {
if c.logLevel == "" {
c.logLevel = "WARN"
@@ -1242,7 +1241,7 @@ func (c *client) checkPermission() (err error) {
}
// checkPermission
- var mc = masterSDK.NewMasterClientFromString(c.masterAddr, false)
+ mc := masterSDK.NewMasterClientFromString(c.masterAddr, false)
var userInfo *proto.UserInfo
if userInfo, err = mc.UserAPI().GetAKInfo(c.accessKey); err != nil {
return
@@ -1251,7 +1250,7 @@ func (c *client) checkPermission() (err error) {
err = proto.ErrNoPermission
return
}
- var policy = userInfo.Policy
+ policy := userInfo.Policy
if policy.IsOwn(c.volName) {
return
}
@@ -1362,20 +1361,20 @@ func (c *client) lookupPath(path string) (*proto.InodeInfo, error) {
func (c *client) setattr(info *proto.InodeInfo, valid uint32, mode, uid, gid uint32, atime, mtime int64) error {
// Only rwx mode bit can be set
if valid&proto.AttrMode != 0 {
- fuseMode := mode & uint32(0777)
- mode = info.Mode &^ uint32(0777) // clear rwx mode bit
+ fuseMode := mode & uint32(0o777)
+ mode = info.Mode &^ uint32(0o777) // clear rwx mode bit
mode |= fuseMode
}
return c.mw.Setattr(info.Inode, valid, mode, uid, gid, atime, mtime)
}
func (c *client) create(pino uint64, name string, mode uint32, fullPath string) (info *proto.InodeInfo, err error) {
- fuseMode := mode & 0777
+ fuseMode := mode & 0o777
return c.mw.Create_ll(pino, name, fuseMode, 0, 0, nil, fullPath)
}
func (c *client) mkdir(pino uint64, name string, mode uint32, fullPath string) (info *proto.InodeInfo, err error) {
- fuseMode := mode & 0777
+ fuseMode := mode & 0o777
fuseMode |= uint32(os.ModeDir)
return c.mw.Create_ll(pino, name, fuseMode, 0, 0, nil, fullPath)
}
diff --git a/master/admin_task_manager.go b/master/admin_task_manager.go
index ecca2171f..b553528eb 100644
--- a/master/admin_task_manager.go
+++ b/master/admin_task_manager.go
@@ -16,11 +16,10 @@ package master
import (
"encoding/json"
- "sync"
- "time"
-
"fmt"
"net"
+ "sync"
+ "time"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util"
@@ -28,14 +27,14 @@ import (
"github.com/cubefs/cubefs/util/log"
)
-//const
+// const
const (
// the maximum number of tasks that can be handled each time
MaxTaskNum = 30
TaskWorkerInterval = time.Second * time.Duration(2)
- idleConnTimeout = 90 //seconds
- connectTimeout = 10 //seconds
+ idleConnTimeout = 90 // seconds
+ connectTimeout = 10 // seconds
)
// AdminTaskManager sends administration commands to the metaNode or dataNode.
@@ -49,7 +48,6 @@ type AdminTaskManager struct {
}
func newAdminTaskManager(targetAddr, clusterID string) (sender *AdminTaskManager) {
-
proto.InitBufferPool(int64(32768))
sender = &AdminTaskManager{
diff --git a/master/api_args_parse.go b/master/api_args_parse.go
index 50ed177b2..f348b340c 100644
--- a/master/api_args_parse.go
+++ b/master/api_args_parse.go
@@ -19,7 +19,7 @@ import (
"encoding/json"
"errors"
"fmt"
- "io/ioutil"
+ "io"
"math"
"net/http"
"strconv"
@@ -124,7 +124,6 @@ func hasTxParams(r *http.Request) bool {
}
func parseTxMask(r *http.Request, oldMask proto.TxOpMask) (mask proto.TxOpMask, err error) {
-
var maskStr string
if maskStr = r.FormValue(enableTxMaskKey); maskStr == "" {
mask = oldMask
@@ -200,6 +199,7 @@ func parseDecomDataNodeReq(r *http.Request) (nodeAddr string, err error) {
return
}
+
func parseAndExtractNodeAddr(r *http.Request) (nodeAddr string, err error) {
if err = r.ParseForm(); err != nil {
return
@@ -224,7 +224,7 @@ func parseRequestToGetTaskResponse(r *http.Request) (tr *proto.AdminTask, err er
if err = r.ParseForm(); err != nil {
return
}
- if body, err = ioutil.ReadAll(r.Body); err != nil {
+ if body, err = io.ReadAll(r.Body); err != nil {
return
}
tr = &proto.AdminTask{}
@@ -317,11 +317,9 @@ func parseRequestToDeleteVol(r *http.Request) (name, authKey string, force bool,
}
return
-
}
func extractUintWithDefault(r *http.Request, key string, def int) (val int, err error) {
-
var str string
if str = r.FormValue(key); str == "" {
return def, nil
@@ -335,7 +333,6 @@ func extractUintWithDefault(r *http.Request, key string, def int) (val int, err
}
func extractUint64WithDefault(r *http.Request, key string, def uint64) (val uint64, err error) {
-
var str string
if str = r.FormValue(key); str == "" {
return def, nil
@@ -349,7 +346,6 @@ func extractUint64WithDefault(r *http.Request, key string, def uint64) (val uint
}
func extractInt64WithDefault(r *http.Request, key string, def int64) (val int64, err error) {
-
var str string
if str = r.FormValue(key); str == "" {
return def, nil
@@ -363,7 +359,6 @@ func extractInt64WithDefault(r *http.Request, key string, def int64) (val int64,
}
func extractStrWithDefault(r *http.Request, key string, def string) (val string) {
-
if val = r.FormValue(key); val == "" {
return def
}
@@ -688,7 +683,6 @@ func checkCacheAction(action int) error {
}
func parseColdArgs(r *http.Request) (args coldVolArgs, err error) {
-
args.cacheRule = extractStr(r, cacheRuleKey)
if args.objBlockSize, err = extractUint(r, ebsBlkSizeKey); err != nil {
@@ -727,7 +721,6 @@ func parseColdArgs(r *http.Request) (args coldVolArgs, err error) {
}
func parseRequestToCreateVol(r *http.Request, req *createVolReq) (err error) {
-
if err = r.ParseForm(); err != nil {
return
}
@@ -1022,7 +1015,6 @@ func parseRequestToDecommissionMetaPartition(r *http.Request) (partitionID uint6
}
func parseAndExtractStatus(r *http.Request) (status bool, err error) {
-
if err = r.ParseForm(); err != nil {
return
}
@@ -1151,6 +1143,7 @@ func parseAndExtractThreshold(r *http.Request) (threshold float64, err error) {
}
return
}
+
func parseAndExtractSetNodeSetInfoParams(r *http.Request) (params map[string]interface{}, err error) {
if err = r.ParseForm(); err != nil {
return
@@ -1158,7 +1151,7 @@ func parseAndExtractSetNodeSetInfoParams(r *http.Request) (params map[string]int
var value string
params = make(map[string]interface{})
if value = r.FormValue(countKey); value != "" {
- var count = uint64(0)
+ count := uint64(0)
count, err = strconv.ParseUint(value, 10, 64)
if err != nil {
err = unmatchedKey(countKey)
@@ -1175,7 +1168,7 @@ func parseAndExtractSetNodeSetInfoParams(r *http.Request) (params map[string]int
params[zoneNameKey] = zoneName
if value = r.FormValue(idKey); value != "" {
- var nodesetId = uint64(0)
+ nodesetId := uint64(0)
nodesetId, err = strconv.ParseUint(value, 10, 64)
if err != nil {
err = unmatchedKey(idKey)
@@ -1191,6 +1184,7 @@ func parseAndExtractSetNodeSetInfoParams(r *http.Request) (params map[string]int
return
}
+
func parseAndExtractSetNodeInfoParams(r *http.Request) (params map[string]interface{}, err error) {
if err = r.ParseForm(); err != nil {
return
@@ -1200,7 +1194,7 @@ func parseAndExtractSetNodeInfoParams(r *http.Request) (params map[string]interf
params = make(map[string]interface{})
if value = r.FormValue(nodeDeleteBatchCountKey); value != "" {
noParams = false
- var batchCount = uint64(0)
+ batchCount := uint64(0)
batchCount, err = strconv.ParseUint(value, 10, 64)
if err != nil {
err = unmatchedKey(nodeDeleteBatchCountKey)
@@ -1211,7 +1205,7 @@ func parseAndExtractSetNodeInfoParams(r *http.Request) (params map[string]interf
if value = r.FormValue(nodeMarkDeleteRateKey); value != "" {
noParams = false
- var val = uint64(0)
+ val := uint64(0)
val, err = strconv.ParseUint(value, 10, 64)
if err != nil {
err = unmatchedKey(nodeMarkDeleteRateKey)
@@ -1222,7 +1216,7 @@ func parseAndExtractSetNodeInfoParams(r *http.Request) (params map[string]interf
if value = r.FormValue(nodeAutoRepairRateKey); value != "" {
noParams = false
- var val = uint64(0)
+ val := uint64(0)
val, err = strconv.ParseUint(value, 10, 64)
if err != nil {
err = unmatchedKey(nodeAutoRepairRateKey)
@@ -1233,7 +1227,7 @@ func parseAndExtractSetNodeInfoParams(r *http.Request) (params map[string]interf
if value = r.FormValue(nodeDeleteWorkerSleepMs); value != "" {
noParams = false
- var val = uint64(0)
+ val := uint64(0)
val, err = strconv.ParseUint(value, 10, 64)
if err != nil {
err = unmatchedKey(nodeMarkDeleteRateKey)
@@ -1255,7 +1249,7 @@ func parseAndExtractSetNodeInfoParams(r *http.Request) (params map[string]interf
if value = r.FormValue(maxDpCntLimitKey); value != "" {
noParams = false
- var val = uint64(0)
+ val := uint64(0)
val, err = strconv.ParseUint(value, 10, 64)
if err != nil {
err = unmatchedKey(maxDpCntLimitKey)
@@ -1266,7 +1260,7 @@ func parseAndExtractSetNodeInfoParams(r *http.Request) (params map[string]interf
if value = r.FormValue(nodeDpRepairTimeOutKey); value != "" {
noParams = false
- var val = uint64(0)
+ val := uint64(0)
val, err = strconv.ParseUint(value, 10, 64)
if err != nil {
err = unmatchedKey(nodeDpRepairTimeOutKey)
@@ -1277,7 +1271,7 @@ func parseAndExtractSetNodeInfoParams(r *http.Request) (params map[string]interf
if value = r.FormValue(nodeDpMaxRepairErrCntKey); value != "" {
noParams = false
- var val = uint64(0)
+ val := uint64(0)
val, err = strconv.ParseUint(value, 10, 64)
if err != nil {
err = unmatchedKey(nodeDpMaxRepairErrCntKey)
@@ -1392,7 +1386,7 @@ func parseVolStatReq(r *http.Request) (name string, ver int, byMeta bool, err er
func parseQosInfo(r *http.Request) (info *proto.ClientReportLimitInfo, err error) {
info = proto.NewClientReportLimitInfo()
var body []byte
- if body, err = ioutil.ReadAll(r.Body); err != nil {
+ if body, err = io.ReadAll(r.Body); err != nil {
return
}
// log.LogInfof("action[parseQosInfo] body len:[%v],crc:[%v]", len(body), crc32.ChecksumIEEE(body))
@@ -1488,7 +1482,6 @@ func extractPositiveUint64(r *http.Request, key string) (val uint64, err error)
}
func extractStr(r *http.Request, key string) (val string) {
-
return r.FormValue(key)
}
@@ -1505,9 +1498,7 @@ func extractOwner(r *http.Request) (owner string, err error) {
}
func parseAndCheckTicket(r *http.Request, key []byte, volName string) (jobj proto.APIAccessReq, ticket cryptoutil.Ticket, ts int64, err error) {
- var (
- plaintext []byte
- )
+ var plaintext []byte
if err = r.ParseForm(); err != nil {
return
@@ -1531,9 +1522,7 @@ func parseAndCheckTicket(r *http.Request, key []byte, volName string) (jobj prot
}
func extractClientReqInfo(r *http.Request) (plaintext []byte, err error) {
- var (
- message string
- )
+ var message string
if err = r.ParseForm(); err != nil {
return
}
@@ -1608,7 +1597,6 @@ func newErrHTTPReply(err error) *proto.HTTPReply {
}
func sendOkReply(w http.ResponseWriter, r *http.Request, httpReply *proto.HTTPReply) (err error) {
-
switch httpReply.Data.(type) {
case *DataPartition:
dp := httpReply.Data.(*DataPartition)
@@ -1689,7 +1677,6 @@ func parseRequestToUpdateDecommissionLimit(r *http.Request) (limit uint64, err e
}
func parseSetConfigParam(r *http.Request) (key string, value string, err error) {
-
if err = r.ParseForm(); err != nil {
return
}
@@ -1731,7 +1718,7 @@ func parserSetQuotaParam(r *http.Request, req *proto.SetMasterQuotaReuqest) (err
return
}
var body []byte
- if body, err = ioutil.ReadAll(r.Body); err != nil {
+ if body, err = io.ReadAll(r.Body); err != nil {
return
}
@@ -1840,7 +1827,7 @@ func parseRequestToUpdateDecommissionDiskFactor(r *http.Request) (factor float64
func parseS3QosReq(r *http.Request, req *proto.S3QosRequest) (err error) {
var body []byte
- if body, err = ioutil.ReadAll(r.Body); err != nil {
+ if body, err = io.ReadAll(r.Body); err != nil {
return
}
diff --git a/master/api_limiter.go b/master/api_limiter.go
index de9ff3289..3f0e67240 100644
--- a/master/api_limiter.go
+++ b/master/api_limiter.go
@@ -20,7 +20,7 @@ const (
type ApiLimitInfo struct {
ApiName string `json:"api_name"`
QueryPath string `json:"query_path"`
- Limit uint32 `json:"limit"` //qps
+ Limit uint32 `json:"limit"` // qps
LimiterTimeout uint32 `json:"limiter_timeout"`
Limiter *rate.Limiter `json:"-"`
}
@@ -95,7 +95,6 @@ func (l *ApiLimiter) RmLimiter(apiName string) (err error) {
}
func (l *ApiLimiter) Wait(qPath string) (err error) {
-
var lInfo *ApiLimitInfo
var ok bool
l.m.RLock()
diff --git a/master/api_service.go b/master/api_service.go
index 73d74ed6e..090e790b7 100644
--- a/master/api_service.go
+++ b/master/api_service.go
@@ -338,14 +338,18 @@ func (m *Server) getTopology(w http.ResponseWriter, r *http.Request) {
cv.NodeSet[ns.ID] = nsView
ns.dataNodes.Range(func(key, value interface{}) bool {
dataNode := value.(*DataNode)
- nsView.DataNodes = append(nsView.DataNodes, proto.NodeView{ID: dataNode.ID, Addr: dataNode.Addr,
- DomainAddr: dataNode.DomainAddr, Status: dataNode.isActive, IsWritable: dataNode.isWriteAble()})
+ nsView.DataNodes = append(nsView.DataNodes, proto.NodeView{
+ ID: dataNode.ID, Addr: dataNode.Addr,
+ DomainAddr: dataNode.DomainAddr, Status: dataNode.isActive, IsWritable: dataNode.isWriteAble(),
+ })
return true
})
ns.metaNodes.Range(func(key, value interface{}) bool {
metaNode := value.(*MetaNode)
- nsView.MetaNodes = append(nsView.MetaNodes, proto.NodeView{ID: metaNode.ID, Addr: metaNode.Addr,
- DomainAddr: metaNode.DomainAddr, Status: metaNode.IsActive, IsWritable: metaNode.isWritable()})
+ nsView.MetaNodes = append(nsView.MetaNodes, proto.NodeView{
+ ID: metaNode.ID, Addr: metaNode.Addr,
+ DomainAddr: metaNode.DomainAddr, Status: metaNode.IsActive, IsWritable: metaNode.isWritable(),
+ })
return true
})
}
@@ -810,7 +814,7 @@ func (m *Server) setApiQpsLimit(w http.ResponseWriter, r *http.Request) {
return
}
- //persist to rocksdb
+ // persist to rocksdb
var qPath string
if err, _, qPath = m.cluster.apiLimiter.IsApiNameValid(name); err != nil {
sendErrReply(w, r, newErrHTTPReply(err))
@@ -864,7 +868,7 @@ func (m *Server) rmApiQpsLimit(w http.ResponseWriter, r *http.Request) {
return
}
- //persist to rocksdb
+ // persist to rocksdb
var qPath string
if err, _, qPath = m.cluster.apiLimiter.IsApiNameValid(name); err != nil {
sendErrReply(w, r, newErrHTTPReply(err))
@@ -876,7 +880,6 @@ func (m *Server) rmApiQpsLimit(w http.ResponseWriter, r *http.Request) {
}
sendOkReply(w, r, newSuccessHTTPReply(fmt.Sprintf("rm api qps limit success: name: %v",
name)))
-
}
func (m *Server) getIPAddr(w http.ResponseWriter, r *http.Request) {
@@ -901,7 +904,7 @@ func (m *Server) getIPAddr(w http.ResponseWriter, r *http.Request) {
DataNodeAutoRepairLimitRate: autoRepairRate,
DpMaxRepairErrCnt: dpMaxRepairErrCnt,
DirChildrenNumLimit: dirChildrenNumLimit,
- //Ip: strings.Split(r.RemoteAddr, ":")[0],
+ // Ip: strings.Split(r.RemoteAddr, ":")[0],
Ip: iputil.RealIP(r),
EbsAddr: m.bStoreAddr,
ServicePath: m.servicePath,
@@ -963,7 +966,6 @@ func parsePreloadDpReq(r *http.Request, preload *DataPartitionPreLoad) (err erro
}
func (m *Server) createPreLoadDataPartition(w http.ResponseWriter, r *http.Request) {
-
var (
volName string
vol *Vol
@@ -1888,8 +1890,7 @@ func (m *Server) diagnoseDataPartition(w http.ResponseWriter, r *http.Request) {
return
}
- if lackReplicaDps, badReplicaDps, repFileCountDifferDps, repUsedSizeDifferDps, excessReplicaDPs, corruptDps, err =
- m.cluster.checkReplicaOfDataPartitions(ignoreDiscardDp); err != nil {
+ if lackReplicaDps, badReplicaDps, repFileCountDifferDps, repUsedSizeDifferDps, excessReplicaDPs, corruptDps, err = m.cluster.checkReplicaOfDataPartitions(ignoreDiscardDp); err != nil {
sendErrReply(w, r, newErrHTTPReply(err))
return
}
@@ -1912,7 +1913,7 @@ func (m *Server) diagnoseDataPartition(w http.ResponseWriter, r *http.Request) {
excessReplicaDpIDs = append(excessReplicaDpIDs, dp.PartitionID)
}
- //badDataPartitions = m.cluster.getBadDataPartitionsView()
+ // badDataPartitions = m.cluster.getBadDataPartitionsView()
badDataPartitionInfos = m.cluster.getBadDataPartitionsRepairView()
rstMsg = &proto.DataPartitionDiagnosis{
InactiveDataNodes: inactiveNodes,
@@ -2215,7 +2216,6 @@ func (m *Server) volShrink(w http.ResponseWriter, r *http.Request) {
}
func (m *Server) checkCreateReq(req *createVolReq) (err error) {
-
if !proto.IsHot(req.volType) && !proto.IsCold(req.volType) {
return fmt.Errorf("vol type %d is illegal", req.volType)
}
@@ -2304,11 +2304,9 @@ func (m *Server) checkCreateReq(req *createVolReq) (err error) {
req.coldArgs = args
return nil
-
}
func (m *Server) createVol(w http.ResponseWriter, r *http.Request) {
-
req := &createVolReq{}
vol := &Vol{}
@@ -2442,7 +2440,6 @@ func newSimpleView(vol *Vol) (view *proto.SimpleVolView) {
maxPartitionID := vol.maxPartitionID()
view = &proto.SimpleVolView{
-
ID: vol.ID,
Name: vol.Name,
Owner: vol.Owner,
@@ -2504,7 +2501,6 @@ func newSimpleView(vol *Vol) (view *proto.SimpleVolView) {
}
func checkIp(addr string) bool {
-
ip := strings.Trim(addr, " ")
regStr := `^(([1-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.)(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){2}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])`
if match, _ := regexp.MatchString(regStr, ip); match {
@@ -2589,7 +2585,7 @@ func (m *Server) getDataNode(w http.ResponseWriter, r *http.Request) {
}
log.LogDebugf("getDataNode. addr %v Total %v used %v", nodeAddr, dataNode.Total, dataNode.Used)
dataNode.PersistenceDataPartitions = m.cluster.getAllDataPartitionIDByDatanode(nodeAddr)
- //some dp maybe removed from this node but decommission failed
+ // some dp maybe removed from this node but decommission failed
dataNodeInfo = &proto.DataNodeInfo{
Total: dataNode.Total,
Used: dataNode.Used,
@@ -2854,20 +2850,20 @@ func (m *Server) setNodeInfoHandler(w http.ResponseWriter, r *http.Request) {
return
}
sendOkReply(w, r, newSuccessHTTPReply(fmt.Sprintf("set nodeinfo params %v successfully", params)))
-
}
-func (m *Server) updateDataUseRatio(ratio float64) (err error) {
+func (m *Server) updateDataUseRatio(ratio float64) (err error) {
m.cluster.domainManager.dataRatioLimit = ratio
err = m.cluster.putZoneDomain(false)
return
}
-func (m *Server) updateExcludeZoneUseRatio(ratio float64) (err error) {
+func (m *Server) updateExcludeZoneUseRatio(ratio float64) (err error) {
m.cluster.domainManager.excludeZoneUseRatio = ratio
err = m.cluster.putZoneDomain(false)
return
}
+
func (m *Server) updateNodesetId(zoneName string, destNodesetId uint64, nodeType uint64, addr string) (err error) {
var (
nsId uint64
@@ -3051,7 +3047,6 @@ func (m *Server) updateClusterSelector(dataNodesetSelector string, metaNodesetSe
}
func (m *Server) setDpRdOnly(partitionID uint64, rdOnly bool) (err error) {
-
var dp *DataPartition
if dp, err = m.cluster.getDataPartitionByID(partitionID); err != nil {
return fmt.Errorf("[setPartitionRdOnly] getDataPartitionByID err(%s)", err.Error())
@@ -3754,7 +3749,7 @@ func (m *Server) decommissionDisk(w http.ResponseWriter, r *http.Request) {
defer func() {
doStatAndMetric(proto.DecommissionDisk, metric, err, nil)
}()
- //default diskDisable is true
+ // default diskDisable is true
if offLineAddr, diskPath, diskDisable, limit, decommissionType, err = parseReqToDecoDisk(r); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
@@ -3911,9 +3906,7 @@ func (m *Server) queryDecommissionDiskDecoFailedDps(w http.ResponseWriter, r *ht
}
func (m *Server) queryAllDecommissionDisk(w http.ResponseWriter, r *http.Request) {
- var (
- err error
- )
+ var err error
metric := exporter.NewTPCnt("req_queryAllDecommissionDisk")
defer func() {
@@ -4794,10 +4787,10 @@ func (m *Server) getMetaPartition(w http.ResponseWriter, r *http.Request) {
return
}
- var toInfo = func(mp *MetaPartition) *proto.MetaPartitionInfo {
+ toInfo := func(mp *MetaPartition) *proto.MetaPartitionInfo {
mp.RLock()
defer mp.RUnlock()
- var replicas = make([]*proto.MetaReplicaInfo, len(mp.Replicas))
+ replicas := make([]*proto.MetaReplicaInfo, len(mp.Replicas))
zones := make([]string, len(mp.Hosts))
nodeSets := make([]uint64, len(mp.Hosts))
for idx, host := range mp.Hosts {
@@ -4827,7 +4820,7 @@ func (m *Server) getMetaPartition(w http.ResponseWriter, r *http.Request) {
} else {
log.LogErrorf("action[getMetaPartition]failed to get volume %v, err %v", mp.volName, err)
}
- var mpInfo = &proto.MetaPartitionInfo{
+ mpInfo := &proto.MetaPartitionInfo{
PartitionID: mp.PartitionID,
Start: mp.Start,
End: mp.End,
@@ -4887,9 +4880,7 @@ func (m *Server) listVols(w http.ResponseWriter, r *http.Request) {
}
func (m *Server) changeMasterLeader(w http.ResponseWriter, r *http.Request) {
- var (
- err error
- )
+ var err error
metric := exporter.NewTPCnt(apiToMetricsName(proto.AdminChangeMasterLeader))
defer func() {
doStatAndMetric(proto.AdminChangeMasterLeader, metric, err, nil)
@@ -5145,7 +5136,7 @@ func (m *Server) associateVolWithUser(userID, volName string) error {
if err == proto.ErrUserNotExists {
- var param = proto.UserCreateParam{
+ param := proto.UserCreateParam{
ID: userID,
Password: DefaultUserPassword,
Type: proto.UserTypeNormal,
@@ -5230,9 +5221,7 @@ func (m *Server) updateDecommissionDiskFactor(w http.ResponseWriter, r *http.Req
}
func (m *Server) queryDecommissionToken(w http.ResponseWriter, r *http.Request) {
- var (
- err error
- )
+ var err error
metric := exporter.NewTPCnt(apiToMetricsName(proto.AdminQueryDecommissionToken))
defer func() {
@@ -5266,9 +5255,7 @@ func (m *Server) queryDecommissionLimit(w http.ResponseWriter, r *http.Request)
}
func (m *Server) queryDecommissionDiskLimit(w http.ResponseWriter, r *http.Request) {
- var (
- resp proto.DecommissionDiskLimit
- )
+ var resp proto.DecommissionDiskLimit
metric := exporter.NewTPCnt("req_queryDecommissionDiskLimit")
defer func() {
metric.Set(nil)
@@ -5381,7 +5368,6 @@ func (m *Server) enableAutoDecommissionDisk(w http.ResponseWriter, r *http.Reque
}
func (m *Server) queryAutoDecommissionDisk(w http.ResponseWriter, r *http.Request) {
-
metric := exporter.NewTPCnt("req_queryAutoDecommissionDisk")
defer func() {
metric.Set(nil)
@@ -5634,7 +5620,6 @@ func (m *Server) setConfig(key string, value string) (err error) {
}
func (m *Server) getConfig(key string) (value string, err error) {
-
if key == cfgmetaPartitionInodeIdStep {
v := m.config.MetaPartitionInodeIdStep
value = strconv.FormatUint(v, 10)
@@ -5645,7 +5630,7 @@ func (m *Server) getConfig(key string) (value string, err error) {
}
func (m *Server) CreateQuota(w http.ResponseWriter, r *http.Request) {
- var req = &proto.SetMasterQuotaReuqest{}
+ req := &proto.SetMasterQuotaReuqest{}
var (
err error
vol *Vol
@@ -5683,7 +5668,7 @@ func (m *Server) CreateQuota(w http.ResponseWriter, r *http.Request) {
}
func (m *Server) UpdateQuota(w http.ResponseWriter, r *http.Request) {
- var req = &proto.UpdateMasterQuotaReuqest{}
+ req := &proto.UpdateMasterQuotaReuqest{}
var (
err error
vol *Vol
@@ -5888,7 +5873,6 @@ func parseSetDpDiscardParam(r *http.Request) (dpId uint64, rdOnly bool, err erro
}
func (m *Server) setDpDiscard(partitionID uint64, isDiscard bool) (err error) {
-
var dp *DataPartition
if dp, err = m.cluster.getDataPartitionByID(partitionID); err != nil {
return fmt.Errorf("[setDpDiacard] getDataPartitionByID err(%s)", err.Error())
@@ -5934,9 +5918,7 @@ func (m *Server) setDpDiscardHandler(w http.ResponseWriter, r *http.Request) {
}
func (m *Server) getDiscardDpHandler(w http.ResponseWriter, r *http.Request) {
- var (
- DiscardDpInfos = proto.DiscardDataPartitionInfos{}
- )
+ DiscardDpInfos := proto.DiscardDataPartitionInfos{}
metric := exporter.NewTPCnt(apiToMetricsName(proto.AdminGetDiscardDp))
defer func() {
@@ -6033,7 +6015,7 @@ func (m *Server) SetBucketLifecycle(w http.ResponseWriter, r *http.Request) {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
}
- var req = proto.LcConfiguration{}
+ req := proto.LcConfiguration{}
if err = json.Unmarshal(bytes, &req); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
@@ -6176,9 +6158,7 @@ func (m *Server) S3QosSet(w http.ResponseWriter, r *http.Request) {
}
func (m *Server) S3QosGet(w http.ResponseWriter, r *http.Request) {
- var (
- err error
- )
+ var err error
metric := exporter.NewTPCnt(apiToMetricsName(proto.S3QoSGet))
defer func() {
doStatAndMetric(proto.S3QoSGet, metric, err, nil)
@@ -6283,7 +6263,6 @@ func parseS3QoSKey(key string) (api, uid, limitType, nodes string, err error) {
}
func isS3QosConfigValid(param *proto.S3QosRequest) bool {
-
if param.Type != proto.FlowLimit && param.Type != proto.QPSLimit && param.Type != proto.ConcurrentLimit {
return false
}
diff --git a/master/api_service_test.go b/master/api_service_test.go
index 7c51d803a..d376df80d 100644
--- a/master/api_service_test.go
+++ b/master/api_service_test.go
@@ -68,9 +68,11 @@ const (
description = "testUser"
)
-var server = createDefaultMasterServerForTest()
-var commonVol *Vol
-var cfsUser *proto.UserInfo
+var (
+ server = createDefaultMasterServerForTest()
+ commonVol *Vol
+ cfsUser *proto.UserInfo
+)
var mockServerLock sync.Mutex
@@ -105,7 +107,6 @@ func rangeMockMetaServers(fun func(*mocktest.MockMetaServer) bool) (count int, p
}
func createDefaultMasterServerForTest() *Server {
-
cfgJSON := `{
"role": "master",
"ip": "127.0.0.1",
@@ -127,7 +128,7 @@ func createDefaultMasterServerForTest() *Server {
if err != nil {
panic(err)
}
- //add data node
+ // add data node
mockDataServers = make([]*mocktest.MockDataServer, 0)
mockDataServers = append(mockDataServers, addDataServer(mds1Addr, testZone1))
mockDataServers = append(mockDataServers, addDataServer(mds2Addr, testZone1))
@@ -217,8 +218,8 @@ func createMasterServer(cfgJSON string) (server *Server, err error) {
os.RemoveAll(logDir)
os.RemoveAll(walDir)
os.RemoveAll(storeDir)
- os.Mkdir(walDir, 0755)
- os.Mkdir(storeDir, 0755)
+ os.Mkdir(walDir, 0o755)
+ os.Mkdir(storeDir, 0o755)
logLevel := cfg.GetString(ConfigKeyLogLevel)
var level log.Level
switch strings.ToLower(logLevel) {
diff --git a/master/api_service_user.go b/master/api_service_user.go
index cf3f020e0..5ec04fbff 100644
--- a/master/api_service_user.go
+++ b/master/api_service_user.go
@@ -3,7 +3,7 @@ package master
import (
"encoding/json"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"github.com/cubefs/cubefs/proto"
@@ -23,11 +23,11 @@ func (m *Server) createUser(w http.ResponseWriter, r *http.Request) {
}()
var bytes []byte
- if bytes, err = ioutil.ReadAll(r.Body); err != nil {
+ if bytes, err = io.ReadAll(r.Body); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
}
- var param = proto.UserCreateParam{}
+ param := proto.UserCreateParam{}
if err = json.Unmarshal(bytes, ¶m); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
@@ -81,11 +81,11 @@ func (m *Server) updateUser(w http.ResponseWriter, r *http.Request) {
}()
var bytes []byte
- if bytes, err = ioutil.ReadAll(r.Body); err != nil {
+ if bytes, err = io.ReadAll(r.Body); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
}
- var param = proto.UserUpdateParam{}
+ param := proto.UserUpdateParam{}
if err = json.Unmarshal(bytes, ¶m); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
@@ -156,11 +156,11 @@ func (m *Server) updateUserPolicy(w http.ResponseWriter, r *http.Request) {
doStatAndMetric(proto.UserUpdatePolicy, metric, err, nil)
}()
- if bytes, err = ioutil.ReadAll(r.Body); err != nil {
+ if bytes, err = io.ReadAll(r.Body); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
}
- var param = proto.UserPermUpdateParam{}
+ param := proto.UserPermUpdateParam{}
if err = json.Unmarshal(bytes, ¶m); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
@@ -187,11 +187,11 @@ func (m *Server) removeUserPolicy(w http.ResponseWriter, r *http.Request) {
doStatAndMetric(proto.UserRemovePolicy, metric, err, nil)
}()
- if bytes, err = ioutil.ReadAll(r.Body); err != nil {
+ if bytes, err = io.ReadAll(r.Body); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
}
- var param = proto.UserPermRemoveParam{}
+ param := proto.UserPermRemoveParam{}
if err = json.Unmarshal(bytes, ¶m); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
@@ -243,11 +243,11 @@ func (m *Server) transferUserVol(w http.ResponseWriter, r *http.Request) {
doStatAndMetric(proto.UserTransferVol, metric, err, map[string]string{exporter.Vol: volName})
}()
- if bytes, err = ioutil.ReadAll(r.Body); err != nil {
+ if bytes, err = io.ReadAll(r.Body); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
}
- var param = proto.UserTransferVolParam{}
+ param := proto.UserTransferVolParam{}
if err = json.Unmarshal(bytes, ¶m); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return
diff --git a/master/cluster.go b/master/cluster.go
index 165df5ee4..31eb4a9f8 100644
--- a/master/cluster.go
+++ b/master/cluster.go
@@ -27,17 +27,16 @@ import (
"time"
"github.com/google/uuid"
-
- authSDK "github.com/cubefs/cubefs/sdk/auth"
- masterSDK "github.com/cubefs/cubefs/sdk/master"
+ "golang.org/x/time/rate"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/raftstore"
+ authSDK "github.com/cubefs/cubefs/sdk/auth"
+ masterSDK "github.com/cubefs/cubefs/sdk/master"
"github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/config"
"github.com/cubefs/cubefs/util/errors"
"github.com/cubefs/cubefs/util/log"
- "golang.org/x/time/rate"
)
// Cluster stores all the cluster-level information.
@@ -146,7 +145,7 @@ func (mgr *followerReadManager) getVolumeDpView() {
mgr.volViewMap[vv.Name] = vv
if _, ok := mgr.lastUpdateTick[vv.Name]; !ok {
- //record when first discovery the volume
+ // record when first discovery the volume
mgr.lastUpdateTick[vv.Name] = time.Now()
mgr.status[vv.Name] = false
}
@@ -177,9 +176,7 @@ func (mgr *followerReadManager) getVolumeDpView() {
}
func (mgr *followerReadManager) sendFollowerVolumeDpView() {
- var (
- err error
- )
+ var err error
vols := mgr.c.copyVols()
for _, vol := range vols {
log.LogDebugf("followerReadManager.getVolumeDpView %v", vol.Name)
@@ -211,7 +208,7 @@ func (mgr *followerReadManager) sendFollowerVolumeDpView() {
func (mgr *followerReadManager) isVolRecordObsolete(volName string) bool {
volView, ok := mgr.volViewMap[volName]
if !ok {
- //vol has been completely deleted
+ // vol has been completely deleted
return true
}
@@ -384,7 +381,6 @@ func (c *Cluster) scheduleToUpdateStatInfo() {
time.Sleep(2 * time.Minute)
}
}()
-
}
func (c *Cluster) addNodeSetGrp(ns *nodeSet, load bool) (err error) {
@@ -424,7 +420,6 @@ func (c *Cluster) scheduleToManageDp() {
// schedule delete dataPartition
go func() {
-
time.Sleep(2 * time.Minute)
for {
@@ -461,7 +456,7 @@ func (c *Cluster) scheduleToCheckDataPartitions() {
func (c *Cluster) scheduleToCheckVolStatus() {
go func() {
- //check vols after switching leader two minutes
+ // check vols after switching leader two minutes
for {
if c.partition.IsRaftLeader() {
vols := c.copyVols()
@@ -474,6 +469,7 @@ func (c *Cluster) scheduleToCheckVolStatus() {
}
}()
}
+
func (c *Cluster) scheduleToCheckFollowerReadCache() {
go func() {
for {
@@ -490,7 +486,7 @@ func (c *Cluster) scheduleToCheckFollowerReadCache() {
func (c *Cluster) scheduleToCheckVolQos() {
go func() {
- //check vols after switching leader two minutes
+ // check vols after switching leader two minutes
for {
if c.partition.IsRaftLeader() {
vols := c.copyVols()
@@ -630,6 +626,7 @@ func (c *Cluster) scheduleToCheckHeartbeat() {
}
}()
}
+
func (c *Cluster) passAclCheck(ip string) {
// do nothing
}
@@ -908,7 +905,7 @@ func (c *Cluster) updateDataNodeBaseInfo(nodeAddr string, id uint64) (err error)
if err = c.syncBatchCommitCmd(cmds); err != nil {
return
}
- //partitions := c.getAllMetaPartitionsByMetaNode(nodeAddr)
+ // partitions := c.getAllMetaPartitionsByMetaNode(nodeAddr)
return
}
@@ -939,7 +936,7 @@ func (c *Cluster) updateMetaNodeBaseInfo(nodeAddr string, id uint64) (err error)
if err = c.syncBatchCommitCmd(cmds); err != nil {
return
}
- //partitions := c.getAllMetaPartitionsByMetaNode(nodeAddr)
+ // partitions := c.getAllMetaPartitionsByMetaNode(nodeAddr)
return
}
@@ -1420,8 +1417,8 @@ func (c *Cluster) isFaultDomain(vol *Vol) bool {
(vol.defaultPriority && (c.needFaultDomain || len(c.t.domainExcludeZones) <= 1)))))
if !vol.domainOn && domainOn {
vol.domainOn = domainOn
- //todo:(leonchang). updateView used to update domainOn status in viewCache, use channel may be better or else lock may happend
- //vol.updateViewCache(c)
+ // todo:(leonchang). updateView used to update domainOn status in viewCache, use channel may be better or else lock may happend
+ // vol.updateViewCache(c)
c.syncUpdateVol(vol)
log.LogInfof("action[isFaultDomain] vol [%v] set domainOn", vol.Name)
}
@@ -1572,7 +1569,7 @@ func (c *Cluster) syncCreateDataPartitionToDataNode(host string, size uint64, dp
task := dp.createTaskToCreateDataPartition(host, size, peers, hosts, createType, partitionType, dataNode.getDecommissionedDisks())
var resp *proto.Packet
if resp, err = dataNode.TaskManager.syncSendAdminTask(task); err != nil {
- //data node is not alive or other process error
+ // data node is not alive or other process error
if needRollBack {
dp.DecommissionNeedRollback = true
c.syncUpdateDataPartition(dp)
@@ -1622,8 +1619,8 @@ func (c *Cluster) decideZoneNum(crossZone bool) (zoneNum int) {
}
func (c *Cluster) chooseZone2Plus1(zones []*Zone, excludeNodeSets []uint64, excludeHosts []string,
- nodeType uint32, replicaNum int) (hosts []string, peers []proto.Peer, err error) {
-
+ nodeType uint32, replicaNum int) (hosts []string, peers []proto.Peer, err error,
+) {
if replicaNum < 2 || replicaNum > 3 {
return nil, nil, fmt.Errorf("action[chooseZone2Plus1] replicaNum [%v]", replicaNum)
}
@@ -1695,15 +1692,15 @@ func (c *Cluster) chooseZoneNormal(zones []*Zone, excludeNodeSets []uint64, excl
func (c *Cluster) getHostFromNormalZone(nodeType uint32, excludeZones []string, excludeNodeSets []uint64,
excludeHosts []string, replicaNum int,
- zoneNum int, specifiedZone string) (hosts []string, peers []proto.Peer, err error) {
-
+ zoneNum int, specifiedZone string) (hosts []string, peers []proto.Peer, err error,
+) {
var zones []*Zone
zones = make([]*Zone, 0)
if replicaNum <= zoneNum {
zoneNum = replicaNum
}
// when creating vol,user specified a zone,we reset zoneNum to 1,to be created partition with specified zone,
- //if specified zone is not writable,we choose a zone randomly
+ // if specified zone is not writable,we choose a zone randomly
if specifiedZone != "" {
if err = c.checkNormalZoneName(specifiedZone); err != nil {
Warn(c.Name, fmt.Sprintf("cluster[%v],specified zone[%v]is found", c.Name, specifiedZone))
@@ -1902,7 +1899,7 @@ func (c *Cluster) decommissionDataNodeCancel(dataNode *DataNode) (err error, fai
return
}
dataNode.SetDecommissionStatus(DecommissionPause)
- //may cause progress confused for new allocated dp
+ // may cause progress confused for new allocated dp
dataNode.ToBeOffline = false
dataNode.DecommissionCompleteTime = time.Now().Unix()
if err = c.syncUpdateDataNode(dataNode); err != nil {
@@ -1932,7 +1929,7 @@ func (c *Cluster) decommissionDiskCancel(disk *DecommissionDisk) (err error, fai
return
}
disk.SetDecommissionStatus(DecommissionPause)
- //disk.DecommissionDpTotal = 0
+ // disk.DecommissionDpTotal = 0
if err = c.syncUpdateDecommissionDisk(disk); err != nil {
log.LogErrorf("action[decommissionDiskCancel] dataNode[%v] disk[%s] sync update failed[ %v]",
disk.SrcAddr, disk.SrcAddr, err.Error())
@@ -1998,13 +1995,13 @@ func (c *Cluster) decommissionSingleDp(dp *DataPartition, newAddr, offlineAddr s
defer func() {
ticker.Stop()
}()
- //1. add new replica first
+ // 1. add new replica first
if dp.GetSpecialReplicaDecommissionStep() == SpecialDecommissionEnter {
if err = c.addDataReplica(dp, newAddr); err != nil {
err = fmt.Errorf("action[decommissionSingleDp] dp %v addDataReplica fail err %v", dp.PartitionID, err)
goto ERR
}
- //if addDataReplica is success, can add to BadDataPartitionIds
+ // if addDataReplica is success, can add to BadDataPartitionIds
dp.SetSpecialReplicaDecommissionStep(SpecialDecommissionWaitAddRes)
dp.SetDecommissionStatus(DecommissionRunning)
dp.isRecover = true
@@ -2014,7 +2011,7 @@ func (c *Cluster) decommissionSingleDp(dp *DataPartition, newAddr, offlineAddr s
c.putBadDataPartitionIDsByDiskPath(dp.DecommissionSrcDiskPath, dp.DecommissionSrcAddr, dp.PartitionID)
log.LogWarnf("action[decommissionSingleDp] dp %v start wait add replica %v", dp.PartitionID, newAddr)
}
- //2. wait for repair
+ // 2. wait for repair
if dp.GetSpecialReplicaDecommissionStep() == SpecialDecommissionWaitAddRes {
for {
select {
@@ -2032,7 +2029,7 @@ func (c *Cluster) decommissionSingleDp(dp *DataPartition, newAddr, offlineAddr s
goto ERR
}
}
- //check new replica status
+ // check new replica status
liveReplicas := dp.getLiveReplicasFromHosts(c.cfg.DataPartitionTimeOutSec)
newReplica, err = dp.getReplica(newAddr)
if err != nil {
@@ -2044,17 +2041,17 @@ func (c *Cluster) decommissionSingleDp(dp *DataPartition, newAddr, offlineAddr s
if len(liveReplicas) == int(dp.ReplicaNum+1) {
log.LogInfof("action[decommissionSingleDp] dp %v replica[%v] status %v",
dp.PartitionID, newReplica.Addr, newReplica.Status)
- if newReplica.isRepairing() { //wait for repair
+ if newReplica.isRepairing() { // wait for repair
if time.Now().Sub(dp.RecoverStartTime) > c.GetDecommissionDataPartitionRecoverTimeOut() {
err = fmt.Errorf("action[decommissionSingleDp] dp %v new replica %v repair time out",
dp.PartitionID, newAddr)
dp.DecommissionNeedRollback = true
- newReplica.Status = proto.Unavailable //remove from data partition check
+ newReplica.Status = proto.Unavailable // remove from data partition check
log.LogWarnf("action[decommissionSingleDp] dp %v err:%v", dp.PartitionID, err)
goto ERR
}
continue
- } else if newReplica.isUnavailable() { //repair failed,need rollback
+ } else if newReplica.isUnavailable() { // repair failed,need rollback
err = fmt.Errorf("action[decommissionSingleDp] dp %v new replica %v is Unavailable",
dp.PartitionID, newAddr)
dp.DecommissionNeedRollback = true
@@ -2069,7 +2066,7 @@ func (c *Cluster) decommissionSingleDp(dp *DataPartition, newAddr, offlineAddr s
}
}
}
- //2. wait for leader
+ // 2. wait for leader
if dp.GetSpecialReplicaDecommissionStep() == SpecialDecommissionWaitAddResFin {
if !c.partition.IsRaftLeader() {
err = fmt.Errorf("action[decommissionSingleDp] dp %v wait addDataReplica result addr %v master leader changed", dp.PartitionID, newAddr)
@@ -2081,7 +2078,7 @@ func (c *Cluster) decommissionSingleDp(dp *DataPartition, newAddr, offlineAddr s
}
times := 0
for {
- //if leader is selected
+ // if leader is selected
if dp.getLeaderAddr() != "" {
break
}
@@ -2113,7 +2110,7 @@ func (c *Cluster) decommissionSingleDp(dp *DataPartition, newAddr, offlineAddr s
dp.SetSpecialReplicaDecommissionStep(SpecialDecommissionRemoveOld)
c.syncUpdateDataPartition(dp)
}
- //3.delete offline replica
+ // 3.delete offline replica
if dp.GetSpecialReplicaDecommissionStep() == SpecialDecommissionRemoveOld {
if err = c.removeDataReplica(dp, offlineAddr, false, false); err != nil {
err = fmt.Errorf("action[decommissionSingleDp] dp %v err %v", dp.PartitionID, err)
@@ -2379,7 +2376,6 @@ errHandler:
}
return
-
}
// Decommission a data partition.
@@ -2502,7 +2498,6 @@ func (c *Cluster) returnDataSize(addr string, dp *DataPartition) {
dataNode.LastUpdateTime = time.Now()
dataNode.AvailableSpace += leaderSize
-
}
func (c *Cluster) buildAddDataPartitionRaftMemberTaskAndSyncSendTask(dp *DataPartition, addPeer proto.Peer, leaderAddr string) (resp *proto.Packet, err error) {
@@ -2540,7 +2535,7 @@ func (c *Cluster) addDataPartitionRaftMember(dp *DataPartition, addPeer proto.Pe
)
if leaderAddr, candidateAddrs, err = dp.prepareAddRaftMember(addPeer); err != nil {
- //maybe already add success before(master has updated hosts)
+ // maybe already add success before(master has updated hosts)
return nil
}
@@ -2558,7 +2553,7 @@ func (c *Cluster) addDataPartitionRaftMember(dp *DataPartition, addPeer proto.Pe
dp.Unlock()
- //send task to leader addr first,if need to retry,then send to other addr
+ // send task to leader addr first,if need to retry,then send to other addr
for index, host := range candidateAddrs {
if leaderAddr == "" && len(candidateAddrs) < int(dp.ReplicaNum) {
time.Sleep(retrySendSyncTaskInternal)
@@ -2588,7 +2583,6 @@ func (c *Cluster) addDataPartitionRaftMember(dp *DataPartition, addPeer proto.Pe
}
return
-
}
func (c *Cluster) createDataReplica(dp *DataPartition, addPeer proto.Peer) (err error) {
@@ -2657,7 +2651,7 @@ func (c *Cluster) removeDataReplica(dp *DataPartition, addr string, validate boo
if err = c.deleteDataReplica(dp, dataNode); err != nil {
return
}
- //may already change leader during last decommission
+ // may already change leader during last decommission
leaderAddr := dp.getLeaderAddrWithLock()
if leaderAddr != addr {
return
@@ -2752,7 +2746,6 @@ func (c *Cluster) updateDataPartitionOfflinePeerIDWithLock(dp *DataPartition, pe
}
func (c *Cluster) deleteDataReplica(dp *DataPartition, dataNode *DataNode) (err error) {
-
dp.Lock()
// in case dataNode is unreachable,update meta first.
dp.removeReplicaByAddr(dataNode.Addr)
@@ -2847,6 +2840,7 @@ func in(target uint64, strArray []uint64) bool {
}
return false
}
+
func (c *Cluster) getBadDataPartitionsView() (bpvs []badPartitionView) {
c.badPartitionMutex.Lock()
defer c.badPartitionMutex.Unlock()
@@ -3090,8 +3084,8 @@ func (c *Cluster) checkZoneName(name string,
crossZone bool,
defaultPriority bool,
zoneName string,
- domainId uint64) (newZoneName string, err error) {
-
+ domainId uint64) (newZoneName string, err error,
+) {
zoneList := strings.Split(zoneName, ",")
newZoneName = zoneName
@@ -3152,9 +3146,7 @@ func (c *Cluster) createVol(req *createVolReq) (vol *Vol, err error) {
return nil, fmt.Errorf("the cluster is frozen, can not create volume")
}
- var (
- readWriteDataPartitions int
- )
+ var readWriteDataPartitions int
if req.zoneName, err = c.checkZoneName(req.name, req.crossZone, req.normalZonesFirst, req.zoneName, req.domainId); err != nil {
return
@@ -3234,7 +3226,7 @@ func (c *Cluster) doCreateVol(req *createVolReq) (vol *Vol, err error) {
c.createVolMutex.Lock()
defer c.createVolMutex.Unlock()
- var createTime = time.Now().Unix() // record unix seconds of volume create time
+ createTime := time.Now().Unix() // record unix seconds of volume create time
var dataPartitionSize uint64
if req.dpSize*util.GB == 0 {
@@ -3321,7 +3313,6 @@ errHandler:
// Update the upper bound of the inode ids in a meta partition.
func (c *Cluster) updateInodeIDRange(volName string, start uint64) (err error) {
-
var (
maxPartitionID uint64
vol *Vol
@@ -3397,8 +3388,10 @@ func (c *Cluster) allDataNodes() (dataNodes []proto.NodeView) {
dataNodes = make([]proto.NodeView, 0)
c.dataNodes.Range(func(addr, node interface{}) bool {
dataNode := node.(*DataNode)
- dataNodes = append(dataNodes, proto.NodeView{Addr: dataNode.Addr, DomainAddr: dataNode.DomainAddr,
- Status: dataNode.isActive, ID: dataNode.ID, IsWritable: dataNode.isWriteAble()})
+ dataNodes = append(dataNodes, proto.NodeView{
+ Addr: dataNode.Addr, DomainAddr: dataNode.DomainAddr,
+ Status: dataNode.isActive, ID: dataNode.ID, IsWritable: dataNode.isWriteAble(),
+ })
return true
})
return
@@ -3408,8 +3401,10 @@ func (c *Cluster) allMetaNodes() (metaNodes []proto.NodeView) {
metaNodes = make([]proto.NodeView, 0)
c.metaNodes.Range(func(addr, node interface{}) bool {
metaNode := node.(*MetaNode)
- metaNodes = append(metaNodes, proto.NodeView{ID: metaNode.ID, Addr: metaNode.Addr, DomainAddr: metaNode.DomainAddr,
- Status: metaNode.IsActive, IsWritable: metaNode.isWritable()})
+ metaNodes = append(metaNodes, proto.NodeView{
+ ID: metaNode.ID, Addr: metaNode.Addr, DomainAddr: metaNode.DomainAddr,
+ Status: metaNode.IsActive, IsWritable: metaNode.isWritable(),
+ })
return true
})
return
@@ -3788,7 +3783,7 @@ func (c *Cluster) scheduleToCheckDecommissionDataNode() {
}
func (c *Cluster) checkDecommissionDataNode() {
- //decommission datanode mark
+ // decommission datanode mark
c.dataNodes.Range(func(addr, node interface{}) bool {
dataNode := node.(*DataNode)
dataNode.updateDecommissionStatus(c, false)
@@ -3796,7 +3791,7 @@ func (c *Cluster) checkDecommissionDataNode() {
c.TryDecommissionDataNode(dataNode)
} else if dataNode.GetDecommissionStatus() == DecommissionSuccess {
partitions := c.getAllDataPartitionByDataNode(dataNode.Addr)
- //if only decommission part of data partitions, do not remove the datanode
+ // if only decommission part of data partitions, do not remove the datanode
if len(partitions) != 0 {
if time.Now().Sub(time.Unix(dataNode.DecommissionCompleteTime, 0)) > (20 * time.Minute) {
log.LogWarnf("action[checkDecommissionDataNode] dataNode %v decommission completed, "+
@@ -3833,11 +3828,11 @@ func (c *Cluster) TryDecommissionDataNode(dataNode *DataNode) {
}
c.syncUpdateDataNode(dataNode)
}()
- //recover from stop
+ // recover from stop
if len(dataNode.DecommissionDiskList) != 0 {
for _, disk := range dataNode.DecommissionDiskList {
key := fmt.Sprintf("%s_%s", dataNode.Addr, disk)
- //if not found, may already success, so only care running disk
+ // if not found, may already success, so only care running disk
if value, ok := c.DecommissionDisks.Load(key); ok {
dd := value.(*DecommissionDisk)
if dd.GetDecommissionStatus() == DecommissionPause {
@@ -3859,8 +3854,8 @@ func (c *Cluster) TryDecommissionDataNode(dataNode *DataNode) {
partitionsFromDisk := dataNode.badPartitions(disk, c)
partitions = append(partitions, partitionsFromDisk...)
}
- //may allocate new dp when dataNode cancel decommission before
- //partitions := c.getAllDataPartitionByDataNode(dataNode.Addr)
+ // may allocate new dp when dataNode cancel decommission before
+ // partitions := c.getAllDataPartitionByDataNode(dataNode.Addr)
if dataNode.DecommissionDstAddr != "" {
for _, dp := range partitions {
// two replica can't exist on same node
@@ -3881,7 +3876,7 @@ func (c *Cluster) TryDecommissionDataNode(dataNode *DataNode) {
return
}
- //check decommission dp last time
+ // check decommission dp last time
oldPartitions := c.getAllDecommissionDataPartitionByDataNode(dataNode.Addr)
if len(oldPartitions) != 0 {
@@ -3896,9 +3891,9 @@ func (c *Cluster) TryDecommissionDataNode(dataNode *DataNode) {
return
}
- //recode dp count in each disk
+ // recode dp count in each disk
dpToDecommissionByDisk := make(map[string]int)
- //find respond disk
+ // find respond disk
for _, dp := range toBeOffLinePartitions {
disk := dp.getReplicaDisk(dataNode.Addr)
if disk == "" {
@@ -3949,7 +3944,7 @@ func (c *Cluster) TryDecommissionDataNode(dataNode *DataNode) {
//}
//disk wait for decommission
dataNode.SetDecommissionStatus(DecommissionPrepare)
- //avoid alloc dp on this node
+ // avoid alloc dp on this node
dataNode.ToBeOffline = true
dataNode.DecommissionDiskList = decommissionDiskList
dataNode.DecommissionDpTotal = decommissionDpTotal
@@ -3981,7 +3976,7 @@ func (c *Cluster) migrateDisk(nodeAddr, diskPath, dstPath string, raftForce bool
c.DecommissionDisks.Store(disk.GenerateKey(), disk)
}
disk.Type = migrateType
- //disk should be decommission all the dp
+ // disk should be decommission all the dp
disk.markDecommission(dstPath, raftForce, limit)
if err = c.syncAddDecommissionDisk(disk); err != nil {
err = fmt.Errorf("action[addDecommissionDisk],clusterID[%v] dataNodeAddr:%v diskPath:%v err:%v ",
@@ -3990,7 +3985,7 @@ func (c *Cluster) migrateDisk(nodeAddr, diskPath, dstPath string, raftForce bool
c.delDecommissionDiskFromCache(disk)
return
}
- //add to the nodeset decommission list
+ // add to the nodeset decommission list
c.addDecommissionDiskToNodeset(disk)
log.LogInfof("action[addDecommissionDisk],clusterID[%v] dataNodeAddr:%v,diskPath[%v] raftForce [%v] "+
"limit [%v], diskDisable [%v], migrateType [%v] term [%v]",
@@ -4037,7 +4032,7 @@ func (c *Cluster) scheduleToCheckDecommissionDisk() {
}
func (c *Cluster) checkDecommissionDisk() {
- //decommission disk mark
+ // decommission disk mark
c.DecommissionDisks.Range(func(key, value interface{}) bool {
disk := value.(*DecommissionDisk)
status := disk.GetDecommissionStatus()
@@ -4107,7 +4102,7 @@ func (c *Cluster) TryDecommissionDisk(disk *DecommissionDisk) {
return
}
badPartitions = node.badPartitions(disk.DiskPath, c)
- //check decommission dp last time
+ // check decommission dp last time
lastBadPartitions := c.getAllDecommissionDataPartitionByDisk(disk.SrcAddr, disk.DiskPath)
badPartitions = mergeDataPartitionArr(badPartitions, lastBadPartitions)
if len(badPartitions) == 0 {
@@ -4121,10 +4116,10 @@ func (c *Cluster) TryDecommissionDisk(disk *DecommissionDisk) {
}
return
}
- //recover from pause
+ // recover from pause
if disk.DecommissionDpTotal != InvalidDecommissionDpCnt {
badPartitions = lastBadPartitions
- } else { //the first time for decommission
+ } else { // the first time for decommission
if disk.DecommissionDpCount == 0 || disk.DecommissionDpCount > len(badPartitions) {
disk.DecommissionDpTotal = len(badPartitions)
} else {
@@ -4146,7 +4141,7 @@ func (c *Cluster) TryDecommissionDisk(disk *DecommissionDisk) {
return
}
for _, dp := range badPartitions {
- //dp with decommission success cannot be reset during master load metadata
+ // dp with decommission success cannot be reset during master load metadata
if dp.IsDecommissionSuccess() && dp.DecommissionTerm == disk.DecommissionTerm {
log.LogInfof("action[TryDecommissionDisk] reset dp [%v] decommission status for disk %v:%v",
dp.PartitionID, disk.SrcAddr, disk.DiskPath)
@@ -4434,7 +4429,7 @@ func (c *Cluster) startLcScan() {
func (c *Cluster) scheduleToSnapshotDelVerScan() {
go c.snapshotMgr.process()
- //make sure resume all the processing ver deleting tasks before checking
+ // make sure resume all the processing ver deleting tasks before checking
waitTime := time.Second * defaultIntervalToCheck
waited := false
go func() {
@@ -4500,11 +4495,13 @@ func (c *Cluster) SetBucketLifecycle(req *proto.LcConfiguration) error {
log.LogInfof("action[SetS3BucketLifecycle],clusterID[%v] vol:%v", c.Name, lcConf.VolName)
return nil
}
+
func (c *Cluster) GetBucketLifecycle(VolName string) (lcConf *proto.LcConfiguration) {
lcConf = c.lcMgr.GetS3BucketLifecycle(VolName)
log.LogInfof("action[GetS3BucketLifecycle],clusterID[%v] vol:%v", c.Name, VolName)
return
}
+
func (c *Cluster) DelBucketLifecycle(VolName string) {
lcConf := &proto.LcConfiguration{
VolName: VolName,
diff --git a/master/cluster_stat.go b/master/cluster_stat.go
index cc059c420..ddefd48de 100644
--- a/master/cluster_stat.go
+++ b/master/cluster_stat.go
@@ -16,9 +16,8 @@ package master
import (
"fmt"
- "strconv"
-
"math"
+ "strconv"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util"
diff --git a/master/cluster_task.go b/master/cluster_task.go
index 165e3dd54..bbb901d05 100644
--- a/master/cluster_task.go
+++ b/master/cluster_task.go
@@ -44,7 +44,6 @@ func (c *Cluster) addDataNodeTask(task *proto.AdminTask) {
}
func (c *Cluster) addMetaNodeTasks(tasks []*proto.AdminTask) {
-
for _, t := range tasks {
if t == nil {
continue
@@ -71,7 +70,6 @@ func (c *Cluster) addLcNodeTasks(tasks []*proto.AdminTask) {
}
func (c *Cluster) waitForResponseToLoadDataPartition(partitions []*DataPartition) {
-
var wg sync.WaitGroup
for _, dp := range partitions {
wg.Add(1)
@@ -565,7 +563,6 @@ func (c *Cluster) buildAddMetaPartitionRaftMemberTaskAndSyncSend(mp *MetaPartiti
}
func (c *Cluster) addMetaPartitionRaftMember(partition *MetaPartition, addPeer proto.Peer) (err error) {
-
var (
candidateAddrs []string
leaderAddr string
@@ -586,9 +583,9 @@ func (c *Cluster) addMetaPartitionRaftMember(partition *MetaPartition, addPeer p
}
candidateAddrs = append(candidateAddrs, host)
}
- //send task to leader addr first,if need to retry,then send to other addr
+ // send task to leader addr first,if need to retry,then send to other addr
for index, host := range candidateAddrs {
- //wait for a new leader
+ // wait for a new leader
if leaderAddr == "" && len(candidateAddrs) < int(partition.ReplicaNum) {
time.Sleep(retrySendSyncTaskInternal)
}
@@ -690,9 +687,7 @@ func (c *Cluster) handleMetaNodeTaskResponse(nodeAddr string, task *proto.AdminT
return
}
log.LogDebugf(fmt.Sprintf("action[handleMetaNodeTaskResponse] receive Task response:%v from %v now:%v", task.IdString(), nodeAddr, time.Now().Unix()))
- var (
- metaNode *MetaNode
- )
+ var metaNode *MetaNode
if metaNode, err = c.metaNode(nodeAddr); err != nil {
goto errHandler
@@ -843,8 +838,8 @@ func (c *Cluster) dealMetaNodeHeartbeatResp(nodeAddr string, resp *proto.MetaNod
log.LogErrorf("action[dealMetaNodeHeartbeatResp],metaNode[%v] error[%v]", metaNode.Addr, err)
}
c.updateMetaNode(metaNode, resp.MetaPartitionReports, metaNode.reachesThreshold())
- //todo remove, this no need set metaNode.metaPartitionInfos = nil
- //metaNode.metaPartitionInfos = nil
+ // todo remove, this no need set metaNode.metaPartitionInfos = nil
+ // metaNode.metaPartitionInfos = nil
logMsg = fmt.Sprintf("action[dealMetaNodeHeartbeatResp],metaNode:%v,zone[%v], ReportTime:%v success", metaNode.Addr, metaNode.ZoneName, time.Now().Unix())
log.LogInfof(logMsg)
return
@@ -944,9 +939,7 @@ errHandler:
}
func (c *Cluster) dealDeleteDataPartitionResponse(nodeAddr string, resp *proto.DeleteDataPartitionResponse) (err error) {
- var (
- dp *DataPartition
- )
+ var dp *DataPartition
if resp.Status == proto.TaskSucceeds {
if dp, err = c.getDataPartitionByID(resp.PartitionId); err != nil {
return
@@ -992,7 +985,6 @@ func (c *Cluster) handleResponseToLoadDataPartition(nodeAddr string, resp *proto
}
func (c *Cluster) handleDataNodeHeartbeatResp(nodeAddr string, resp *proto.DataNodeHeartbeatResponse) (err error) {
-
var (
dataNode *DataNode
logMsg string
diff --git a/master/cluster_test.go b/master/cluster_test.go
index cdf643a50..fe1ba32a2 100644
--- a/master/cluster_test.go
+++ b/master/cluster_test.go
@@ -21,7 +21,7 @@ func buildPanicVol() *Vol {
if err != nil {
return nil
}
- var createTime = time.Now().Unix() // record create time of this volume
+ createTime := time.Now().Unix() // record create time of this volume
vv := volValue{
ID: id,
@@ -68,6 +68,7 @@ func TestPanicBackendLoadDataPartitions(t *testing.T) {
func TestCheckReleaseDataPartitions(t *testing.T) {
server.cluster.releaseDataPartitionAfterLoad()
}
+
func TestPanicCheckReleaseDataPartitions(t *testing.T) {
c := buildPanicCluster()
c.releaseDataPartitionAfterLoad()
@@ -112,7 +113,7 @@ func TestPanicCheckAvailSpace(t *testing.T) {
func TestCheckCreateDataPartitions(t *testing.T) {
server.cluster.scheduleToManageDp()
- //time.Sleep(150 * time.Second)
+ // time.Sleep(150 * time.Second)
}
func TestPanicCheckCreateDataPartitions(t *testing.T) {
@@ -138,7 +139,7 @@ func TestPanicCheckBadDiskRecovery(t *testing.T) {
func TestCheckBadDiskRecovery(t *testing.T) {
server.cluster.checkDataNodeHeartbeat()
time.Sleep(5 * time.Second)
- //clear
+ // clear
server.cluster.BadDataPartitionIds.Range(func(key, value interface{}) bool {
server.cluster.BadDataPartitionIds.Delete(key)
return true
@@ -182,7 +183,7 @@ func TestCheckBadDiskRecovery(t *testing.T) {
t.Errorf("expect bad partition num[%v],real num[%v]", dpsLen, count)
return
}
- //check recovery
+ // check recovery
server.cluster.checkDiskRecoveryProgress()
count = 0
@@ -214,7 +215,7 @@ func TestPanicCheckBadMetaPartitionRecovery(t *testing.T) {
func TestCheckBadMetaPartitionRecovery(t *testing.T) {
server.cluster.checkMetaNodeHeartbeat()
time.Sleep(5 * time.Second)
- //clear
+ // clear
server.cluster.BadMetaPartitionIds.Range(func(key, value interface{}) bool {
server.cluster.BadMetaPartitionIds.Delete(key)
return true
@@ -258,7 +259,7 @@ func TestCheckBadMetaPartitionRecovery(t *testing.T) {
t.Errorf("expect bad partition num[%v],real num[%v]", mpsLen, count)
return
}
- //check recovery
+ // check recovery
server.cluster.checkMetaPartitionRecoveryProgress()
count = 0
@@ -305,7 +306,6 @@ func TestUpdateInodeIDUpperBound(t *testing.T) {
if curMpLen == mpLen {
t.Errorf("split failed,oldMpLen[%v],curMpLen[%v]", mpLen, curMpLen)
}
-
}
func TestBalanceMetaPartition(t *testing.T) {
diff --git a/master/config.go b/master/config.go
index c609addea..42ff65579 100644
--- a/master/config.go
+++ b/master/config.go
@@ -75,7 +75,7 @@ const (
defaultPeriodToLoadAllDataPartitions = 60 * 60 * 4 // how long we need to load all the data partitions on the master every time
defaultNumberOfDataPartitionsToLoad = 50 // how many data partitions to load every time
defaultMetaPartitionTimeOutSec = 10 * defaultIntervalToCheckHeartbeat
- //DefaultMetaPartitionMissSec = 3600
+ // DefaultMetaPartitionMissSec = 3600
defaultIntervalToAlarmMissingMetaPartition = 10 * 60 // interval of checking if a replica is missing
defaultMetaPartitionMemUsageThreshold float32 = 0.75 // memory usage threshold on a meta partition
@@ -115,11 +115,11 @@ type clusterConfig struct {
nodeSetCapacity int
MetaNodeThreshold float32
ClusterLoadFactor float32
- MetaNodeDeleteBatchCount uint64 //metanode delete batch count
- DataNodeDeleteLimitRate uint64 //datanode delete limit rate
- MetaNodeDeleteWorkerSleepMs uint64 //metaNode delete worker sleep time with millisecond. if 0 for no sleep
- MaxDpCntLimit uint64 //datanode data partition limit
- DataNodeAutoRepairLimitRate uint64 //datanode autorepair limit rate
+ MetaNodeDeleteBatchCount uint64 // metanode delete batch count
+ DataNodeDeleteLimitRate uint64 // datanode delete limit rate
+ MetaNodeDeleteWorkerSleepMs uint64 // metaNode delete worker sleep time with millisecond. if 0 for no sleep
+ MaxDpCntLimit uint64 // datanode data partition limit
+ DataNodeAutoRepairLimitRate uint64 // datanode autorepair limit rate
DpMaxRepairErrCnt uint64
DpRepairTimeOut uint64
peers []raftstore.PeerAddress
diff --git a/master/data_node.go b/master/data_node.go
index 8273aa154..dc478a6a4 100644
--- a/master/data_node.go
+++ b/master/data_node.go
@@ -20,11 +20,10 @@ import (
"sync/atomic"
"time"
- "github.com/cubefs/cubefs/util/atomicutil"
- "github.com/cubefs/cubefs/util/log"
-
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util"
+ "github.com/cubefs/cubefs/util/atomicutil"
+ "github.com/cubefs/cubefs/util/log"
)
// DataNode stores all the information about a data node
@@ -49,8 +48,8 @@ type DataNode struct {
TotalPartitionSize uint64
NodeSetID uint64
PersistenceDataPartitions []uint64
- BadDisks []string //Keep this old field for compatibility
- BadDiskStats []proto.BadDiskStat //key: disk path
+ BadDisks []string // Keep this old field for compatibility
+ BadDiskStats []proto.BadDiskStat // key: disk path
DecommissionedDisks sync.Map
ToBeOffline bool
RdOnly bool
@@ -321,7 +320,7 @@ func (dataNode *DataNode) updateDecommissionStatus(c *Cluster, debug bool) (uint
defer func() {
c.syncUpdateDataNode(dataNode)
}()
- //not enter running status
+ // not enter running status
if dataNode.DecommissionRetry >= defaultDecommissionRetryLimit {
dataNode.markDecommissionFail()
return DecommissionFail, float64(0)
@@ -336,7 +335,7 @@ func (dataNode *DataNode) updateDecommissionStatus(c *Cluster, debug bool) (uint
}
for _, disk := range dataNode.DecommissionDiskList {
key := fmt.Sprintf("%s_%s", dataNode.Addr, disk)
- //if not found, may already success, so only care running disk
+ // if not found, may already success, so only care running disk
if value, ok := c.DecommissionDisks.Load(key); ok {
dd := value.(*DecommissionDisk)
status := dd.GetDecommissionStatus()
@@ -348,13 +347,13 @@ func (dataNode *DataNode) updateDecommissionStatus(c *Cluster, debug bool) (uint
_, diskProgress := dd.updateDecommissionStatus(c, debug)
progress += diskProgress
} else {
- successDiskNum++ //disk with DecommissionSuccess will be removed from cache
+ successDiskNum++ // disk with DecommissionSuccess will be removed from cache
progress += float64(1)
}
}
- //only care data node running/prepare/success
- //no disk get token
+ // only care data node running/prepare/success
+ // no disk get token
if markDiskNum == totalDisk {
dataNode.SetDecommissionStatus(DecommissionPrepare)
return DecommissionPrepare, float64(0)
@@ -364,9 +363,9 @@ func (dataNode *DataNode) updateDecommissionStatus(c *Cluster, debug bool) (uint
return DecommissionSuccess, float64(1)
}
}
- //update datanode or running status
+ // update datanode or running status
partitions := dataNode.GetLatestDecommissionDataPartition(c)
- //Get all dp on this dataNode
+ // Get all dp on this dataNode
failedNum := 0
runningNum := 0
prepareNum := 0
@@ -385,7 +384,7 @@ func (dataNode *DataNode) updateDecommissionStatus(c *Cluster, debug bool) (uint
prepareNum++
preparePartitionIds = append(preparePartitionIds, dp.PartitionID)
}
- //datanode may stop before and will be counted into partitions
+ // datanode may stop before and will be counted into partitions
if dp.GetDecommissionStatus() == DecommissionPause {
stopNum++
stopPartitionIds = append(stopPartitionIds, dp.PartitionID)
@@ -412,7 +411,7 @@ func (dataNode *DataNode) GetLatestDecommissionDataPartition(c *Cluster) (partit
log.LogDebugf("action[GetLatestDecommissionDataPartition]dataNode %v diskList %v", dataNode.Addr, dataNode.DecommissionDiskList)
for _, disk := range dataNode.DecommissionDiskList {
key := fmt.Sprintf("%s_%s", dataNode.Addr, disk)
- //if not found, may already success, so only care running disk
+ // if not found, may already success, so only care running disk
if value, ok := c.DecommissionDisks.Load(key); ok {
dd := value.(*DecommissionDisk)
dps := c.getAllDecommissionDataPartitionByDiskAndTerm(dd.SrcAddr, dd.DiskPath, dd.DecommissionTerm)
@@ -484,7 +483,7 @@ func (dataNode *DataNode) markDecommission(targetAddr string, raftForce bool, li
dataNode.SetDecommissionStatus(markDecommission)
dataNode.DecommissionRaftForce = raftForce
dataNode.DecommissionDstAddr = targetAddr
- //reset decommission status for failed once
+ // reset decommission status for failed once
dataNode.DecommissionRetry = 0
dataNode.DecommissionLimit = limit
dataNode.DecommissionDiskList = make([]string, 0)
@@ -498,7 +497,7 @@ func (dataNode *DataNode) canMarkDecommission() bool {
func (dataNode *DataNode) markDecommissionSuccess(c *Cluster) {
dataNode.SetDecommissionStatus(DecommissionSuccess)
partitions := c.getAllDataPartitionByDataNode(dataNode.Addr)
- //if only decommission part of data partitions, can alloc dp in future
+ // if only decommission part of data partitions, can alloc dp in future
if len(partitions) != 0 {
dataNode.ToBeOffline = false
}
@@ -507,8 +506,8 @@ func (dataNode *DataNode) markDecommissionSuccess(c *Cluster) {
func (dataNode *DataNode) markDecommissionFail() {
dataNode.SetDecommissionStatus(DecommissionFail)
- //dataNode.ToBeOffline = false
- //dataNode.DecommissionCompleteTime = time.Now().Unix()
+ // dataNode.ToBeOffline = false
+ // dataNode.DecommissionCompleteTime = time.Now().Unix()
}
func (dataNode *DataNode) resetDecommissionStatus() {
@@ -520,6 +519,7 @@ func (dataNode *DataNode) resetDecommissionStatus() {
dataNode.DecommissionCompleteTime = 0
dataNode.DecommissionDiskList = make([]string, 0)
}
+
func (dataNode *DataNode) createVersionTask(volume string, version uint64, op uint8, addr string, verList []*proto.VolVersionInfo) (task *proto.AdminTask) {
request := &proto.MultiVersionOpRequest{
VolumeID: volume,
diff --git a/master/data_partition.go b/master/data_partition.go
index 749e72bd0..085df5079 100644
--- a/master/data_partition.go
+++ b/master/data_partition.go
@@ -65,10 +65,10 @@ type DataPartition struct {
DecommissionRaftForce bool
DecommissionSrcDiskPath string
DecommissionTerm uint64
- DecommissionDstAddrSpecify bool //if DecommissionDstAddrSpecify is true, donot rollback when add replica fail
+ DecommissionDstAddrSpecify bool // if DecommissionDstAddrSpecify is true, donot rollback when add replica fail
DecommissionNeedRollback bool
DecommissionNeedRollbackTimes int
- SpecialReplicaDecommissionStop chan bool //used for stop
+ SpecialReplicaDecommissionStop chan bool // used for stop
SpecialReplicaDecommissionStep uint32
IsDiscard bool
VerSeq uint64
@@ -232,7 +232,6 @@ func (partition *DataPartition) createTaskToAddRaftMember(addPeer proto.Peer, le
}
func (partition *DataPartition) createTaskToRemoveRaftMember(c *Cluster, removePeer proto.Peer, force bool) (err error) {
-
doWork := func(leaderAddr string) error {
log.LogInfof("action[createTaskToRemoveRaftMember] vol[%v],data partition[%v] removePeer %v leaderAddr %v", partition.VolName, partition.PartitionID, removePeer, leaderAddr)
req := newRemoveDataPartitionRaftMemberRequest(partition.PartitionID, removePeer)
@@ -273,8 +272,8 @@ func (partition *DataPartition) createTaskToRemoveRaftMember(c *Cluster, removeP
}
func (partition *DataPartition) createTaskToCreateDataPartition(addr string, dataPartitionSize uint64,
- peers []proto.Peer, hosts []string, createType int, partitionType int, decommissionedDisks []string) (task *proto.AdminTask) {
-
+ peers []proto.Peer, hosts []string, createType int, partitionType int, decommissionedDisks []string) (task *proto.AdminTask,
+) {
leaderSize := 0
if createType == proto.DecommissionedCreateDataPartition {
leaderSize = int(partition.Replicas[0].Used)
@@ -404,7 +403,6 @@ func (partition *DataPartition) deleteReplicaByIndex(index int) {
}
func (partition *DataPartition) createLoadTasks() (tasks []*proto.AdminTask) {
-
partition.Lock()
defer partition.Unlock()
for _, addr := range partition.Hosts {
@@ -546,7 +544,6 @@ func (partition *DataPartition) releaseDataPartition() {
delete(partition.FilesWithMissingReplica, name)
}
}
-
}
func (partition *DataPartition) hasReplica(host string) (replica *DataReplica, ok bool) {
@@ -711,7 +708,6 @@ func (partition *DataPartition) update(action, volName string, newPeers []proto.
}
func (partition *DataPartition) updateMetric(vr *proto.DataPartitionReport, dataNode *DataNode, c *Cluster) {
-
if !partition.hasHost(dataNode.Addr) {
return
}
@@ -947,14 +943,14 @@ func (partition *DataPartition) buildDpInfo(c *Cluster) *proto.DataPartitionInfo
partition.RLock()
defer partition.RUnlock()
- var replicas = make([]*proto.DataReplica, len(partition.Replicas))
+ replicas := make([]*proto.DataReplica, len(partition.Replicas))
for i, replica := range partition.Replicas {
dataReplica := replica.DataReplica
dataReplica.DomainAddr = replica.dataNode.DomainAddr
replicas[i] = &dataReplica
}
- var fileInCoreMap = make(map[string]*proto.FileInCore)
+ fileInCoreMap := make(map[string]*proto.FileInCore)
for k, v := range partition.FileInCoreMap {
fileInCoreMap[k] = v.clone()
}
@@ -1005,7 +1001,7 @@ func (partition *DataPartition) buildDpInfo(c *Cluster) *proto.DataPartitionInfo
const (
DecommissionInitial uint32 = iota
markDecommission
- DecommissionPause //can only stop markDecommission
+ DecommissionPause // can only stop markDecommission
DecommissionPrepare
DecommissionRunning
DecommissionSuccess
@@ -1061,11 +1057,11 @@ func (partition *DataPartition) MarkDecommissionStatus(srcAddr, dstAddr, srcDisk
return false
}
partition.SetDecommissionStatus(markDecommission)
- //update decommissionTerm for next time query
+ // update decommissionTerm for next time query
partition.DecommissionTerm = term
return true
}
- //initial or failed restart
+ // initial or failed restart
partition.ResetDecommissionStatus()
partition.SetDecommissionStatus(markDecommission)
partition.DecommissionSrcAddr = srcAddr
@@ -1073,7 +1069,7 @@ func (partition *DataPartition) MarkDecommissionStatus(srcAddr, dstAddr, srcDisk
partition.DecommissionSrcDiskPath = srcDisk
partition.DecommissionRaftForce = raftForce
partition.DecommissionTerm = term
- //reset special replicas decommission status
+ // reset special replicas decommission status
partition.isRecover = false
partition.SetSpecialReplicaDecommissionStep(SpecialDecommissionInitial)
if partition.DecommissionSrcDiskPath == "" {
@@ -1213,14 +1209,14 @@ func (partition *DataPartition) Decommission(c *Cluster) bool {
goto errHandler
}
newReplica, _ := partition.getReplica(targetAddr)
- newReplica.Status = proto.Recovering //in case heartbeat response is not arrived
+ newReplica.Status = proto.Recovering // in case heartbeat response is not arrived
partition.isRecover = true
partition.Status = proto.ReadOnly
partition.SetDecommissionStatus(DecommissionRunning)
partition.RecoverStartTime = time.Now()
c.putBadDataPartitionIDsByDiskPath(partition.DecommissionSrcDiskPath, partition.DecommissionSrcAddr, partition.PartitionID)
}
- //only stop 3-replica,need to release token
+ // only stop 3-replica,need to release token
if partition.IsDecommissionPaused() {
log.LogInfof("action[decommissionDataPartition]clusterID[%v] partitionID:%v decommission paused", c.Name, partition.PartitionID)
if !partition.pauseReplicaRepair(partition.DecommissionDstAddr, true, c) {
@@ -1235,7 +1231,7 @@ func (partition *DataPartition) Decommission(c *Cluster) bool {
}
errHandler:
- //special replica num receive stop signal,donot reset SingleDecommissionStatus for decommission again
+ // special replica num receive stop signal,donot reset SingleDecommissionStatus for decommission again
if partition.GetDecommissionStatus() == DecommissionPause {
log.LogWarnf("action[decommissionDataPartition] partitionID:%v is stopped", partition.PartitionID)
return true
@@ -1245,10 +1241,10 @@ errHandler:
if partition.DecommissionRetry >= defaultDecommissionRetryLimit {
partition.SetDecommissionStatus(DecommissionFail)
} else {
- partition.SetDecommissionStatus(markDecommission) //retry again
+ partition.SetDecommissionStatus(markDecommission) // retry again
}
- //if need rollback, set to fail,reset DecommissionDstAddr
+ // if need rollback, set to fail,reset DecommissionDstAddr
if partition.DecommissionNeedRollback {
partition.SetDecommissionStatus(DecommissionFail)
}
@@ -1265,7 +1261,7 @@ errHandler:
func (partition *DataPartition) PauseDecommission(c *Cluster) bool {
status := partition.GetDecommissionStatus()
- //support retry pause if pause failed last time
+ // support retry pause if pause failed last time
if status == DecommissionInitial || status == DecommissionSuccess ||
status == DecommissionFail {
log.LogWarnf("action[PauseDecommission] dp[%v] cannot be stopped status[%v]", partition.PartitionID, status)
@@ -1319,7 +1315,7 @@ func (partition *DataPartition) ResetDecommissionStatus() {
}
func (partition *DataPartition) rollback(c *Cluster) {
- //del new add replica,may timeout, try rollback next time
+ // del new add replica,may timeout, try rollback next time
err := c.removeDataReplica(partition, partition.DecommissionDstAddr, false, false)
if err != nil {
log.LogWarnf("action[rollback]dp[%v] rollback to del replica[%v] failed:%v",
@@ -1330,9 +1326,9 @@ func (partition *DataPartition) rollback(c *Cluster) {
if err != nil {
return
}
- //release token first
+ // release token first
partition.ReleaseDecommissionToken(c)
- //reset status if rollback success
+ // reset status if rollback success
partition.DecommissionDstAddr = ""
partition.DecommissionRetry = 0
partition.isRecover = false
@@ -1390,7 +1386,7 @@ func (partition *DataPartition) checkConsumeToken() bool {
// only mark stop status or initial
func (partition *DataPartition) canMarkDecommission(term uint64) bool {
- //dp may not be reset decommission status from last decommission
+ // dp may not be reset decommission status from last decommission
if partition.DecommissionTerm != term {
return true
}
@@ -1427,7 +1423,7 @@ func (partition *DataPartition) pauseReplicaRepair(replicaAddr string, stop bool
index := partition.findReplica(replicaAddr)
if index == -1 {
log.LogWarnf("action[pauseReplicaRepair]dp[%v] can't find replica %v", partition.PartitionID, replicaAddr)
- //maybe paused from rollback[mark]
+ // maybe paused from rollback[mark]
return true
}
const RetryMax = 5
@@ -1543,7 +1539,7 @@ func (partition *DataPartition) TryAcquireDecommissionToken(c *Cluster) bool {
goto errHandler
}
}
- //get nodeset for target host
+ // get nodeset for target host
newAddr := targetHosts[0]
ns, zone, err = getTargetNodeset(newAddr, c)
if err != nil {
@@ -1552,7 +1548,7 @@ func (partition *DataPartition) TryAcquireDecommissionToken(c *Cluster) bool {
goto errHandler
}
}
- //only persist DecommissionDstAddr when get token
+ // only persist DecommissionDstAddr when get token
if ns.AcquireDecommissionToken(partition.PartitionID) {
partition.DecommissionDstAddr = targetHosts[0]
log.LogDebugf("action[TryAcquireDecommissionToken] dp %v get token from %v nodeset %v success",
@@ -1646,9 +1642,7 @@ func (partition *DataPartition) restoreReplicaMeta(c *Cluster) (err error) {
}
func getTargetNodeset(addr string, c *Cluster) (ns *nodeSet, zone *Zone, err error) {
- var (
- dataNode *DataNode
- )
+ var dataNode *DataNode
dataNode, err = c.dataNode(addr)
if err != nil {
log.LogWarnf("action[getTargetNodeset] find src %v data node failed:%v", addr, err.Error())
@@ -1669,11 +1663,11 @@ func getTargetNodeset(addr string, c *Cluster) (ns *nodeSet, zone *Zone, err err
func (partition *DataPartition) needRollback(c *Cluster) bool {
log.LogDebugf("action[needRollback]dp[%v]DecommissionNeedRollbackTimes[%v]", partition.PartitionID, partition.DecommissionNeedRollbackTimes)
- //failed by error except add replica or create dp or repair dp
+ // failed by error except add replica or create dp or repair dp
if !partition.DecommissionNeedRollback {
return false
}
- //specify dst addr do not need rollback
+ // specify dst addr do not need rollback
if partition.DecommissionDstAddrSpecify {
log.LogWarnf("action[needRollback]dp[%v] do not rollback for DecommissionDstAddrSpecify", partition.PartitionID)
return false
diff --git a/master/data_partition_check.go b/master/data_partition_check.go
index 53f0791d3..cc56380ab 100644
--- a/master/data_partition_check.go
+++ b/master/data_partition_check.go
@@ -69,7 +69,7 @@ func (partition *DataPartition) checkStatus(clusterName string, needLog bool, dp
default:
partition.Status = proto.ReadOnly
}
- //keep readonly if special replica is still decommission
+ // keep readonly if special replica is still decommission
if partition.isSpecialReplicaCnt() && partition.GetSpecialReplicaDecommissionStep() > 0 {
log.LogInfof("action[checkStatus] partition %v with Special replica cnt %v on decommison status %v, live replicacnt %v",
partition.PartitionID, partition.ReplicaNum, partition.Status, len(liveReplicas))
@@ -111,6 +111,7 @@ func (partition *DataPartition) checkReplicaNotHaveStatus(liveReplicas []*DataRe
return true
}
+
func (partition *DataPartition) checkReplicaEqualStatus(liveReplicas []*DataReplica, status int8) (equal bool) {
for _, replica := range liveReplicas {
if replica.Status != status {
@@ -183,9 +184,7 @@ func (partition *DataPartition) checkMissingReplicas(clusterID, leaderAddr strin
if partition.hasHost(replica.Addr) && replica.isMissing(dataPartitionMissSec) && !partition.IsDiscard {
if partition.needToAlarmMissingDataPartition(replica.Addr, dataPartitionWarnInterval) {
dataNode := replica.getReplicaNode()
- var (
- lastReportTime time.Time
- )
+ var lastReportTime time.Time
isActive := true
if dataNode != nil {
lastReportTime = dataNode.ReportTime
@@ -194,7 +193,7 @@ func (partition *DataPartition) checkMissingReplicas(clusterID, leaderAddr strin
msg := fmt.Sprintf("action[checkMissErr],clusterID[%v] paritionID:%v on node:%v "+
"miss time > %v lastRepostTime:%v dnodeLastReportTime:%v nodeisActive:%v So Migrate by manual",
clusterID, partition.PartitionID, replica.Addr, dataPartitionMissSec, replica.ReportTime, lastReportTime, isActive)
- //msg = msg + fmt.Sprintf(" decommissionDataPartitionURL is http://%v/dataPartition/decommission?id=%v&addr=%v", leaderAddr, partition.PartitionID, replica.Addr)
+ // msg = msg + fmt.Sprintf(" decommissionDataPartitionURL is http://%v/dataPartition/decommission?id=%v&addr=%v", leaderAddr, partition.PartitionID, replica.Addr)
Warn(clusterID, msg)
if WarnMetrics != nil {
WarnMetrics.WarnMissingDp(clusterID, replica.Addr, partition.PartitionID, true)
@@ -204,7 +203,6 @@ func (partition *DataPartition) checkMissingReplicas(clusterID, leaderAddr strin
if WarnMetrics != nil {
WarnMetrics.WarnMissingDp(clusterID, replica.Addr, partition.PartitionID, false)
}
-
}
}
if WarnMetrics != nil {
@@ -224,7 +222,7 @@ func (partition *DataPartition) checkMissingReplicas(clusterID, leaderAddr strin
replicaInfo.replicaNum = strconv.FormatUint(uint64(partition.ReplicaNum), 10)
replicaInfo.replicaAlive = strconv.FormatUint(uint64(dpReplicaAliveNum), 10)
WarnMetrics.dpMissingReplicaInfo[id] = replicaInfo
- for missingReplicaAddr, _ := range WarnMetrics.dpMissingReplicaInfo[id].addrs {
+ for missingReplicaAddr := range WarnMetrics.dpMissingReplicaInfo[id].addrs {
if oldDpReplicaAliveNum != "" {
WarnMetrics.missingDp.DeleteLabelValues(clusterID, id, missingReplicaAddr, oldDpReplicaAliveNum, replicaInfo.replicaNum)
}
diff --git a/master/data_partition_map.go b/master/data_partition_map.go
index 7ef70afbd..16962fb3e 100644
--- a/master/data_partition_map.go
+++ b/master/data_partition_map.go
@@ -236,7 +236,6 @@ func (dpMap *DataPartitionMap) freeMemOccupiedByDataPartitions(partitions []*Dat
}(dp)
}
wg.Wait()
-
}
func (dpMap *DataPartitionMap) getDataPartitionsToBeChecked(loadFrequencyTime int64) (partitions []*DataPartition, startIndex uint64) {
diff --git a/master/data_replica.go b/master/data_replica.go
index 248ffcd5f..fcb4ba112 100644
--- a/master/data_replica.go
+++ b/master/data_replica.go
@@ -15,10 +15,10 @@
package master
import (
- "github.com/cubefs/cubefs/util/log"
"time"
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/util/log"
)
// DataReplica represents the replica of a data partition
diff --git a/master/disk_manager.go b/master/disk_manager.go
index 26f66d8df..6d472b457 100644
--- a/master/disk_manager.go
+++ b/master/disk_manager.go
@@ -19,7 +19,6 @@ import (
"sync/atomic"
"time"
- //"github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/log"
)
@@ -57,7 +56,7 @@ func (c *Cluster) checkDiskRecoveryProgress() {
Warn(c.Name, fmt.Sprintf("checkDiskRecoveryProgress clusterID[%v],partitionID[%v] is not exist", c.Name, partitionID))
continue
}
- //do not update status if paused
+ // do not update status if paused
if partition.IsDecommissionPaused() {
continue
}
@@ -96,15 +95,15 @@ func (c *Cluster) checkDiskRecoveryProgress() {
}
} else {
if partition.isSpecialReplicaCnt() {
- continue //change dp decommission status in decommission function
+ continue // change dp decommission status in decommission function
}
- //do not add to BadDataPartitionIds
+ // do not add to BadDataPartitionIds
if newReplica.isUnavailable() {
partition.DecommissionNeedRollback = true
partition.SetDecommissionStatus(DecommissionFail)
Warn(c.Name, fmt.Sprintf("action[checkDiskRecoveryProgress]clusterID[%v],partitionID[%v] has recovered failed", c.Name, partitionID))
} else {
- partition.SetDecommissionStatus(DecommissionSuccess) //can be readonly or readwrite
+ partition.SetDecommissionStatus(DecommissionSuccess) // can be readonly or readwrite
Warn(c.Name, fmt.Sprintf("action[checkDiskRecoveryProgress]clusterID[%v],partitionID[%v] has recovered success", c.Name, partitionID))
}
partition.RLock()
@@ -160,7 +159,6 @@ func (c *Cluster) decommissionDisk(dataNode *DataNode, raftForce bool, badDiskPa
return
}
}(dp)
-
}
msg = fmt.Sprintf("action[decommissionDisk],clusterID[%v] node[%v] OffLine success",
c.Name, dataNode.Addr)
@@ -230,12 +228,12 @@ func (dd *DecommissionDisk) updateDecommissionStatus(c *Cluster, debug bool) (ui
dd.markDecommissionFailed()
return DecommissionFail, float64(0)
}
- //Get all dp on this disk
+ // Get all dp on this disk
failedNum := 0
runningNum := 0
prepareNum := 0
stopNum := 0
- //get the latest decommission result
+ // get the latest decommission result
partitions := c.getAllDecommissionDataPartitionByDiskAndTerm(dd.SrcAddr, dd.DiskPath, dd.DecommissionTerm)
if len(partitions) == 0 {
@@ -257,7 +255,7 @@ func (dd *DecommissionDisk) updateDecommissionStatus(c *Cluster, debug bool) (ui
prepareNum++
preparePartitionIds = append(preparePartitionIds, dp.PartitionID)
}
- //disk may stop before and will be counted into partitions
+ // disk may stop before and will be counted into partitions
if dp.GetDecommissionStatus() == DecommissionPause {
stopNum++
stopPartitionIds = append(stopPartitionIds, dp.PartitionID)
@@ -326,7 +324,7 @@ func (dd *DecommissionDisk) GetDecommissionFailedDP(c *Cluster) (error, []uint64
}
func (dd *DecommissionDisk) markDecommission(dstPath string, raftForce bool, limit int) {
- //if transfer from pause,do not change these attrs
+ // if transfer from pause,do not change these attrs
if dd.GetDecommissionStatus() != DecommissionPause {
dd.DecommissionDpTotal = InvalidDecommissionDpCnt
dd.DecommissionDpCount = limit
diff --git a/master/filecrc.go b/master/filecrc.go
index 6e088d1ff..84312a9d1 100644
--- a/master/filecrc.go
+++ b/master/filecrc.go
@@ -16,8 +16,9 @@ package master
import (
"fmt"
- "github.com/cubefs/cubefs/util/log"
"time"
+
+ "github.com/cubefs/cubefs/util/log"
)
// FileCrc defines the crc of a file
diff --git a/master/filemeta.go b/master/filemeta.go
index 9b95b23e5..6f87c78ff 100644
--- a/master/filemeta.go
+++ b/master/filemeta.go
@@ -16,6 +16,7 @@ package master
import (
"fmt"
+
"github.com/cubefs/cubefs/proto"
)
@@ -40,7 +41,7 @@ func (fm *FileMetadata) getFileCrc() (crc uint32) {
return fm.Crc
}
-//FileInCore define file in data partition
+// FileInCore define file in data partition
type FileInCore struct {
proto.FileInCore
MetadataArray []*FileMetadata
@@ -65,7 +66,7 @@ func newFileInCore(name string) (fc *FileInCore) {
}
func (fc FileInCore) clone() *proto.FileInCore {
- var metadataArray = make([]*proto.FileMetadata, len(fc.MetadataArray))
+ metadataArray := make([]*proto.FileMetadata, len(fc.MetadataArray))
for i, metadata := range fc.MetadataArray {
metadataArray[i] = &proto.FileMetadata{
Crc: metadata.Crc,
@@ -102,7 +103,6 @@ func (fc *FileInCore) updateFileInCore(volID uint64, vf *proto.File, volLoc *Dat
fm := newFileMetadata(vf.Crc, volLoc.Addr, volLocIndex, vf.Size, vf.ApplyID)
fc.MetadataArray = append(fc.MetadataArray, fm)
}
-
}
func (fc *FileInCore) getFileMetaByAddr(replica *DataReplica) (fm *FileMetadata, ok bool) {
diff --git a/master/gapi_cluster.go b/master/gapi_cluster.go
index 45bfc0e29..1dfb0ac25 100644
--- a/master/gapi_cluster.go
+++ b/master/gapi_cluster.go
@@ -5,7 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
- "io/ioutil"
+ "io"
"os"
"path/filepath"
"sort"
@@ -148,7 +148,6 @@ func (s *ClusterService) registerObject(schema *schemabuilder.Schema) {
object.FieldFunc("metaPartitionInfos", func(ctx context.Context, n *MetaNode) []*proto.MetaPartitionReport {
return n.metaPartitionInfos
})
-
}
func (s *ClusterService) registerQuery(schema *schemabuilder.Schema) {
@@ -182,8 +181,8 @@ func (s *ClusterService) registerMutation(schema *schemabuilder.Schema) {
func (m *ClusterService) decommissionDisk(ctx context.Context, args struct {
OffLineAddr string
DiskPath string
-}) (*proto.GeneralResp, error) {
-
+}) (*proto.GeneralResp, error,
+) {
node, err := m.cluster.dataNode(args.OffLineAddr)
if err != nil {
return nil, err
@@ -207,14 +206,13 @@ func (m *ClusterService) decommissionDisk(ctx context.Context, args struct {
Warn(m.cluster.Name, rstMsg)
return proto.Success("success"), nil
-
}
// Decommission a data node. This will decommission all the data partition on that node.
func (m *ClusterService) decommissionDataNode(ctx context.Context, args struct {
OffLineAddr string
-}) (*proto.GeneralResp, error) {
-
+}) (*proto.GeneralResp, error,
+) {
node, err := m.cluster.dataNode(args.OffLineAddr)
if err != nil {
return nil, err
@@ -535,7 +533,6 @@ func (m *ClusterService) alarmList(ctx context.Context, args struct {
}
f, err := os.Open(path)
-
if err != nil {
return nil, fmt.Errorf("open file has err:[%s]", err.Error())
}
@@ -554,7 +551,7 @@ func (m *ClusterService) alarmList(ctx context.Context, args struct {
buf := bufio.NewReader(f)
- all, err := ioutil.ReadAll(buf)
+ all, err := io.ReadAll(buf)
if err != nil {
return nil, fmt.Errorf("read file:[%s] size:[%d] has err:[%s]", path, stat.Size(), err.Error())
}
@@ -594,7 +591,7 @@ func (m *ClusterService) alarmList(ctx context.Context, args struct {
list = append(list, msg)
}
- //reverse slice
+ // reverse slice
l := len(list)
for i := 0; i < l/2; i++ {
list[i], list[l-i-1] = list[l-i-1], list[i]
diff --git a/master/gapi_user.go b/master/gapi_user.go
index 80d897746..a8cf48e24 100644
--- a/master/gapi_user.go
+++ b/master/gapi_user.go
@@ -5,11 +5,12 @@ import (
"crypto/sha256"
"encoding/hex"
"fmt"
+ "sort"
+
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/log"
"github.com/samsarahq/thunder/graphql"
"github.com/samsarahq/thunder/graphql/schemabuilder"
- "sort"
)
type UserService struct {
@@ -41,7 +42,6 @@ type AuthorizedVols struct {
}
func (s *UserService) registerObject(schema *schemabuilder.Schema) {
-
object := schema.Object("UserInfo", proto.UserInfo{})
object.FieldFunc("userStatistical", func(u *proto.UserInfo) (*UserStatistical, error) {
@@ -71,7 +71,6 @@ func (s *UserService) registerObject(schema *schemabuilder.Schema) {
}
return list
})
-
}
func (s *UserService) registerQuery(schema *schemabuilder.Schema) {
@@ -111,7 +110,6 @@ func (s *UserService) registerMutation(schema *schemabuilder.Schema) {
mutation.FieldFunc("updateUserPolicy", s.updateUserPolicy)
mutation.FieldFunc("removeUserPolicy", s.removeUserPolicy)
mutation.FieldFunc("transferUserVol", s.transferUserVol)
-
}
func (m *UserService) transferUserVol(ctx context.Context, args proto.UserTransferVolParam) (*proto.UserInfo, error) {
@@ -230,14 +228,13 @@ func (s *UserService) deleteUser(ctx context.Context, args struct {
return nil, err
}
- //TODO : make sure can delete self? can delete other admin ??
+ // TODO : make sure can delete self? can delete other admin ??
log.LogInfof("delete user:[%s] by admin:[%s]", args.UserID, uid)
if err := s.user.deleteKey(args.UserID); err != nil {
return nil, err
}
return proto.Success("del user ok"), nil
-
}
func (s *UserService) getUserInfo(ctx context.Context, args struct {
@@ -285,7 +282,6 @@ func (s *UserService) topNUser(ctx context.Context, args struct {
var err error
s.user.userStore.Range(func(_, ui interface{}) bool {
-
u := ui.(*proto.UserInfo)
us := &UserUseSpace{
@@ -330,7 +326,6 @@ func (s *UserService) topNUser(ctx context.Context, args struct {
} else {
u.Ratio = float32(u.Size) / float32(sum)
}
-
}
return list, nil
@@ -364,8 +359,10 @@ func (s *UserService) validatePassword(ctx context.Context, args struct {
type permissionMode int
-const ADMIN permissionMode = permissionMode(1)
-const USER permissionMode = permissionMode(2)
+const (
+ ADMIN permissionMode = permissionMode(1)
+ USER permissionMode = permissionMode(2)
+)
func permissions(ctx context.Context, mode permissionMode) (userID string, perm permissionMode, err error) {
userInfo := ctx.Value(proto.UserInfoKey).(*proto.UserInfo)
diff --git a/master/gapi_volume.go b/master/gapi_volume.go
index 17444c442..0dcb4676d 100644
--- a/master/gapi_volume.go
+++ b/master/gapi_volume.go
@@ -81,7 +81,6 @@ func (s *VolumeService) registerObject(schema *schemabuilder.Schema) {
}
return v.createTime, nil
})
-
}
func (s *VolumeService) registerQuery(schema *schemabuilder.Schema) {
@@ -98,7 +97,6 @@ func (s *VolumeService) registerMutation(schema *schemabuilder.Schema) {
mutation.FieldFunc("createVolume", s.createVolume)
// mutation.FieldFunc("deleteVolume", s.markDeleteVol)
mutation.FieldFunc("updateVolume", s.updateVolume)
-
}
type UserPermission struct {
@@ -110,7 +108,8 @@ type UserPermission struct {
func (s *VolumeService) volPermission(ctx context.Context, args struct {
VolName string
UserID *string
-}) ([]*UserPermission, error) {
+},
+) ([]*UserPermission, error) {
uid, perm, err := permissions(ctx, ADMIN|USER)
if err != nil {
return nil, err
@@ -178,7 +177,8 @@ func (s *VolumeService) createVolume(ctx context.Context, args struct {
Capacity, DataPartitionSize, MpCount, DpCount, DpReplicaNum uint64
FollowerRead, Authenticate, CrossZone, DefaultPriority bool
iopsRLimit, iopsWLimit, flowRlimit, flowWlimit uint64
-}) (*Vol, error) {
+},
+) (*Vol, error) {
uid, per, err := permissions(ctx, ADMIN|USER)
if err != nil {
return nil, err
@@ -216,19 +216,17 @@ func (s *VolumeService) createVolume(ctx context.Context, args struct {
description: args.Description,
}
vol, err := s.cluster.createVol(req)
-
if err != nil {
return nil, err
}
userInfo, err := s.user.getUserInfo(args.Owner)
-
if err != nil {
if err != proto.ErrUserNotExists {
return nil, err
}
- var param = proto.UserCreateParam{
+ param := proto.UserCreateParam{
ID: args.Owner,
Password: DefaultUserPassword,
Type: proto.UserTypeNormal,
@@ -247,7 +245,8 @@ func (s *VolumeService) createVolume(ctx context.Context, args struct {
func (s *VolumeService) markDeleteVol(ctx context.Context, args struct {
Name, AuthKey string
-}) (*proto.GeneralResp, error) {
+},
+) (*proto.GeneralResp, error) {
uid, perm, err := permissions(ctx, ADMIN|USER)
if err != nil {
return nil, err
@@ -281,7 +280,8 @@ func (s *VolumeService) updateVolume(ctx context.Context, args struct {
ZoneName, Description *string
Capacity, ReplicaNum *uint64
FollowerRead, Authenticate *bool
-}) (*Vol, error) {
+},
+) (*Vol, error) {
uid, perm, err := permissions(ctx, ADMIN|USER)
if err != nil {
return nil, err
@@ -345,7 +345,8 @@ func (s *VolumeService) updateVolume(ctx context.Context, args struct {
func (s *VolumeService) listVolume(ctx context.Context, args struct {
UserID *string
Keyword *string
-}) ([]*Vol, error) {
+},
+) ([]*Vol, error) {
uid, perm, err := permissions(ctx, ADMIN|USER)
if err != nil {
return nil, err
@@ -376,8 +377,9 @@ func (s *VolumeService) listVolume(ctx context.Context, args struct {
func (s *VolumeService) getVolume(ctx context.Context, args struct {
Name string
-}) (*Vol, error) {
-
+},
+) (*Vol, error,
+) {
uid, perm, err := permissions(ctx, ADMIN|USER)
if err != nil {
return nil, err
diff --git a/master/http_server.go b/master/http_server.go
index bdffbf716..b33cc1672 100644
--- a/master/http_server.go
+++ b/master/http_server.go
@@ -24,11 +24,10 @@ import (
"strings"
"time"
+ "github.com/gorilla/mux"
"github.com/samsarahq/thunder/graphql"
"github.com/samsarahq/thunder/graphql/introspection"
- "github.com/gorilla/mux"
-
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/config"
"github.com/cubefs/cubefs/util/exporter"
@@ -48,14 +47,14 @@ func (m *Server) startHTTPService(modulename string, cfg *config.Config) {
addr = fmt.Sprintf("%s:%s", m.ip, m.port)
}
- var server = &http.Server{
+ server := &http.Server{
Addr: addr,
Handler: router,
ReadTimeout: 5 * time.Minute,
WriteTimeout: 5 * time.Minute,
}
- var serveAPI = func() {
+ serveAPI := func() {
if err := server.ListenAndServe(); err != nil {
log.LogErrorf("serveAPI: serve http server failed: err(%v)", err)
return
@@ -151,7 +150,7 @@ func (m *Server) registerAPIMiddleware(route *mux.Router) {
// AuthenticationUri2MsgTypeMap define the mapping from authentication uri to message type
var AuthenticationUri2MsgTypeMap = map[string]proto.MsgType{
- //Master API cluster management
+ // Master API cluster management
proto.AdminClusterFreeze: proto.MsgMasterClusterFreezeReq,
proto.AddRaftNode: proto.MsgMasterAddRaftNodeReq,
proto.RemoveRaftNode: proto.MsgMasterRemoveRaftNodeReq,
@@ -240,15 +239,15 @@ func (m *Server) registerAuthenticationMiddleware(router *mux.Router) {
}
func (m *Server) registerAPIRoutes(router *mux.Router) {
- //graphql api for cluster
+ // graphql api for cluster
cs := &ClusterService{user: m.user, cluster: m.cluster, conf: m.config, leaderInfo: m.leaderInfo}
m.registerHandler(router, proto.AdminClusterAPI, cs.Schema())
us := &UserService{user: m.user, cluster: m.cluster}
m.registerHandler(router, proto.AdminUserAPI, us.Schema())
- //vs := &VolumeService{user: m.user, cluster: m.cluster}
- //m.registerHandler(router, proto.AdminVolumeAPI, vs.Schema())
+ // vs := &VolumeService{user: m.user, cluster: m.cluster}
+ // m.registerHandler(router, proto.AdminVolumeAPI, vs.Schema())
// cluster management APIs
router.NewRoute().Name(proto.AdminGetMasterApiList).
@@ -484,7 +483,7 @@ func (m *Server) registerAPIRoutes(router *mux.Router) {
router.NewRoute().Methods(http.MethodGet).
Path(proto.QosUpdateMasterLimit).
HandlerFunc(m.getQosUpdateMasterLimit)
- //router.NewRoute().Methods(http.MethodGet).
+ // router.NewRoute().Methods(http.MethodGet).
// Path(proto.QosUpdateMagnify).
// HandlerFunc(m.QosUpdateMagnify)
router.NewRoute().Methods(http.MethodGet).
@@ -773,6 +772,7 @@ func (m *Server) registerHandler(router *mux.Router, model string, schema *graph
gHandler.ServeHTTP(writer, request)
})
}
+
func ErrResponse(w http.ResponseWriter, err error) {
response := struct {
Errors []string `json:"errors"`
diff --git a/master/lifecycle_manager.go b/master/lifecycle_manager.go
index bc652fdb4..b4e94b8a6 100644
--- a/master/lifecycle_manager.go
+++ b/master/lifecycle_manager.go
@@ -216,7 +216,7 @@ func (ns *lcNodeStatus) GetIdleNode() (nodeAddr string) {
return
}
- var min = math.MaxInt
+ min := math.MaxInt
for n, c := range ns.WorkingCount {
if c <= min {
nodeAddr = n
diff --git a/master/lifecycle_node.go b/master/lifecycle_node.go
index bebe6ce45..cc0481080 100644
--- a/master/lifecycle_node.go
+++ b/master/lifecycle_node.go
@@ -76,7 +76,6 @@ func (lcNode *LcNode) createLcScanTask(masterAddr string, ruleTask *proto.RuleTa
}
func (lcNode *LcNode) createSnapshotVerDelTask(masterAddr string, sTask *proto.SnapshotVerDelTask) (task *proto.AdminTask) {
-
request := &proto.SnapshotVerDelTaskRequest{
MasterAddr: masterAddr,
LcNodeAddr: lcNode.Addr,
diff --git a/master/lifecycle_task.go b/master/lifecycle_task.go
index 2f6d336cb..27ab74524 100644
--- a/master/lifecycle_task.go
+++ b/master/lifecycle_task.go
@@ -67,9 +67,7 @@ errHandler:
}
func (c *Cluster) handleLcNodeHeartbeatResp(nodeAddr string, resp *proto.LcNodeHeartbeatResponse) (err error) {
- var (
- lcNode *LcNode
- )
+ var lcNode *LcNode
log.LogDebugf("action[handleLcNodeHeartbeatResp] clusterID[%v] receive lcNode[%v] heartbeat", c.Name, nodeAddr)
if resp.Status != proto.TaskSucceeds {
@@ -87,16 +85,16 @@ func (c *Cluster) handleLcNodeHeartbeatResp(nodeAddr string, resp *proto.LcNodeH
lcNode.ReportTime = time.Now()
lcNode.Unlock()
- //update lcNodeStatus
+ // update lcNodeStatus
log.LogInfof("action[handleLcNodeHeartbeatResp], lcNode[%v], LcScanningTasks[%v], SnapshotScanningTasks[%v]", nodeAddr, len(resp.LcScanningTasks), len(resp.SnapshotScanningTasks))
c.lcMgr.lcNodeStatus.UpdateNode(nodeAddr, len(resp.LcScanningTasks))
c.snapshotMgr.lcNodeStatus.UpdateNode(nodeAddr, len(resp.SnapshotScanningTasks))
- //handle LcScanningTasks
+ // handle LcScanningTasks
for _, taskRsp := range resp.LcScanningTasks {
c.lcMgr.lcRuleTaskStatus.Lock()
- //avoid updating TaskResults incorrectly when received handleLcNodeLcScanResp first and then handleLcNodeHeartbeatResp
+ // avoid updating TaskResults incorrectly when received handleLcNodeLcScanResp first and then handleLcNodeHeartbeatResp
if c.lcMgr.lcRuleTaskStatus.Results[taskRsp.ID] != nil && c.lcMgr.lcRuleTaskStatus.Results[taskRsp.ID].Done {
log.LogInfof("action[handleLcNodeHeartbeatResp], lcNode[%v] task[%v] already done", nodeAddr, taskRsp.ID)
} else {
@@ -113,11 +111,11 @@ func (c *Cluster) handleLcNodeHeartbeatResp(nodeAddr string, resp *proto.LcNodeH
c.lcMgr.notifyIdleLcNode()
}
- //handle SnapshotScanningTasks
+ // handle SnapshotScanningTasks
for _, taskRsp := range resp.SnapshotScanningTasks {
c.snapshotMgr.lcSnapshotTaskStatus.Lock()
- //avoid updating TaskResults incorrectly when received handleLcNodeLcScanResp first and then handleLcNodeHeartbeatResp
+ // avoid updating TaskResults incorrectly when received handleLcNodeLcScanResp first and then handleLcNodeHeartbeatResp
if c.snapshotMgr.lcSnapshotTaskStatus.TaskResults[taskRsp.ID] != nil && c.snapshotMgr.lcSnapshotTaskStatus.TaskResults[taskRsp.ID].Done {
log.LogInfof("action[handleLcNodeHeartbeatResp], lcNode[%v] snapshot task[%v] already done", nodeAddr, taskRsp.ID)
} else {
@@ -171,7 +169,7 @@ func (c *Cluster) handleLcNodeSnapshotScanResp(nodeAddr string, resp *proto.Snap
log.LogWarnf("action[handleLcNodeSnapshotScanResp] scanning failed, resp(%v), redo", resp)
return
case proto.TaskSucceeds:
- //1.mark done for VersionMgr
+ // 1.mark done for VersionMgr
var vol *Vol
vol, err = c.getVol(resp.VolName)
if err != nil {
@@ -181,7 +179,7 @@ func (c *Cluster) handleLcNodeSnapshotScanResp(nodeAddr string, resp *proto.Snap
_ = vol.VersionMgr.DelVer(resp.VerSeq)
}
- //2. mark done for snapshotMgr
+ // 2. mark done for snapshotMgr
c.snapshotMgr.lcSnapshotTaskStatus.AddResult(resp)
log.LogInfof("action[handleLcNodeSnapshotScanResp] scanning completed, resp(%v)", resp)
return
diff --git a/master/limiter.go b/master/limiter.go
index 376590bef..7e3665edf 100644
--- a/master/limiter.go
+++ b/master/limiter.go
@@ -187,7 +187,6 @@ func (uMgr *UidSpaceManager) volUidUpdate(report *proto.MetaPartitionReport) {
}
}
log.LogDebugf("volUidUpdate.mpID %v set uid %v. uid list size %v", id, report.UidInfo, len(uMgr.uidInfo))
-
}
type ServerFactorLimit struct {
@@ -319,7 +318,6 @@ func (qosManager *QosCtrlManager) getQosLimit(factorTYpe uint32) uint64 {
}
func (qosManager *QosCtrlManager) initClientQosInfo(clientID uint64, host string) (limitRsp2Client *proto.LimitRsp2Client, err error) {
-
log.QosWriteDebugf("action[initClientQosInfo] vol %v clientID %v Host %v", qosManager.vol.Name, clientID, host)
clientInitInfo := proto.NewClientReportLimitInfo()
cliCnt := qosManager.defaultClientCnt
@@ -446,7 +444,6 @@ func (serverLimit *ServerFactorLimit) dispatch() {
// handle client request and rsp with much more if buffer is enough according rules of allocate
func (serverLimit *ServerFactorLimit) updateLimitFactor(req interface{}) {
-
request := req.(*qosRequestArgs)
clientID := request.clientID
factorType := request.factorType
@@ -769,7 +766,6 @@ func (vol *Vol) checkQos() {
}
func (vol *Vol) getQosStatus(cluster *Cluster) interface{} {
-
type qosStatus struct {
ServerFactorLimitMap map[uint32]*ServerFactorLimit // vol qos data for iops w/r and flow w/r
QosEnable bool
diff --git a/master/master_manager.go b/master/master_manager.go
index e3c5eaa1c..ee07d9740 100644
--- a/master/master_manager.go
+++ b/master/master_manager.go
@@ -151,7 +151,7 @@ func (m *Server) loadMetadata() {
if m.cluster.FaultDomain {
log.LogInfof("action[FaultDomain] set")
- if !loadDomain { //first restart after domain item be added
+ if !loadDomain { // first restart after domain item be added
if err = m.cluster.putZoneDomain(true); err != nil {
log.LogInfof("action[putZoneDomain] err[%v]", err)
panic(err)
@@ -250,7 +250,7 @@ func (m *Server) clearMetadata() {
m.user.clearAKStore()
m.user.clearVolUsers()
m.cluster.t = newTopology()
- //m.cluster.apiLimiter.Clear()
+ // m.cluster.apiLimiter.Clear()
}
func (m *Server) refreshUser() (err error) {
@@ -289,7 +289,7 @@ func (m *Server) refreshUser() (err error) {
}
}*/
if _, err = m.user.getUserInfo(RootUserID); err != nil {
- var param = cfsProto.UserCreateParam{
+ param := cfsProto.UserCreateParam{
ID: RootUserID,
Password: DefaultRootPasswd,
Type: cfsProto.UserTypeRoot,
diff --git a/master/master_manager_test.go b/master/master_manager_test.go
index f76962824..267981456 100644
--- a/master/master_manager_test.go
+++ b/master/master_manager_test.go
@@ -172,7 +172,7 @@ func snapshotTest(t *testing.T) {
}
func addRaftServerTest(addRaftAddr string, id uint64, t *testing.T) {
- //don't pass id test
+ // don't pass id test
reqURL := fmt.Sprintf("%v%v?id=&addr=%v", hostAddr, proto.AddRaftNode, addRaftAddr)
mocktest.Println(reqURL)
resp, err := http.Get(reqURL)
diff --git a/master/master_quota_manager.go b/master/master_quota_manager.go
index e5be619d0..4a730c28d 100644
--- a/master/master_quota_manager.go
+++ b/master/master_quota_manager.go
@@ -23,7 +23,6 @@ import (
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/errors"
"github.com/cubefs/cubefs/util/log"
- //"github.com/cubefs/cubefs/blobstore/util/errors"
)
type MasterQuotaManager struct {
@@ -74,7 +73,7 @@ func (mqMgr *MasterQuotaManager) createQuota(req *proto.SetMasterQuotaReuqest) (
return
}
- var quotaInfo = &proto.QuotaInfo{
+ quotaInfo := &proto.QuotaInfo{
VolName: req.VolName,
QuotaId: quotaId,
CTime: time.Now().Unix(),
@@ -266,7 +265,7 @@ func (mqMgr *MasterQuotaManager) getQuotaHbInfos() (infos []*proto.QuotaHeartBea
mqMgr.RLock()
defer mqMgr.RUnlock()
for quotaId, quotaInfo := range mqMgr.IdQuotaInfoMap {
- var info = &proto.QuotaHeartBeatInfo{}
+ info := &proto.QuotaHeartBeatInfo{}
info.VolName = mqMgr.vol.Name
info.QuotaId = quotaId
info.LimitedInfo.LimitedFiles = quotaInfo.LimitedInfo.LimitedFiles
diff --git a/master/meta_node.go b/master/meta_node.go
index 008ec8beb..5e70a5e71 100644
--- a/master/meta_node.go
+++ b/master/meta_node.go
@@ -178,9 +178,11 @@ type sortLeaderMetaNode struct {
func (s *sortLeaderMetaNode) Less(i, j int) bool {
return len(s.nodes[i].metaPartitions) > len(s.nodes[j].metaPartitions)
}
+
func (s *sortLeaderMetaNode) Swap(i, j int) {
s.nodes[i], s.nodes[j] = s.nodes[j], s.nodes[i]
}
+
func (s *sortLeaderMetaNode) Len() int {
return len(s.nodes)
}
diff --git a/master/meta_partition.go b/master/meta_partition.go
index 16f90fa73..54d16d470 100644
--- a/master/meta_partition.go
+++ b/master/meta_partition.go
@@ -15,11 +15,10 @@
package master
import (
- "sync"
-
"fmt"
"math"
"strings"
+ "sync"
"time"
"github.com/cubefs/cubefs/proto"
@@ -187,10 +186,9 @@ func (mp *MetaPartition) canSplit(end uint64, metaPartitionInodeIdStep uint64, i
}
func (mp *MetaPartition) addUpdateMetaReplicaTask(c *Cluster) (err error) {
-
tasks := make([]*proto.AdminTask, 0)
t := mp.createTaskToUpdateMetaReplica(c.Name, mp.PartitionID, mp.End)
- //if no leader,don't update end
+ // if no leader,don't update end
if t == nil {
err = proto.ErrNoLeader
return
@@ -202,7 +200,6 @@ func (mp *MetaPartition) addUpdateMetaReplicaTask(c *Cluster) (err error) {
}
func (mp *MetaPartition) dataSize() uint64 {
-
maxSize := uint64(0)
for _, mr := range mp.Replicas {
if maxSize < mr.dataSize {
@@ -214,7 +211,6 @@ func (mp *MetaPartition) dataSize() uint64 {
}
func (mp *MetaPartition) checkEnd(c *Cluster, maxPartitionID uint64) {
-
if mp.PartitionID < maxPartitionID {
return
}
@@ -292,7 +288,6 @@ func (mp *MetaPartition) checkLeader(clusterID string) {
var report bool
if _, err := mp.getMetaReplicaLeader(); err != nil {
report = true
-
}
if WarnMetrics != nil {
WarnMetrics.WarnMpNoLeader(clusterID, mp.PartitionID, report)
@@ -407,7 +402,6 @@ func (mp *MetaPartition) missingReplicaAddrs() (lackAddrs []string) {
}
func (mp *MetaPartition) updateMetaPartition(mgr *proto.MetaPartitionReport, metaNode *MetaNode) {
-
if !contains(mp.Hosts, metaNode.Addr) {
return
}
@@ -535,7 +529,7 @@ func (mp *MetaPartition) shouldReportMissingReplica(addr string, interval int64)
mp.MissNodes[addr] = time.Now().Unix()
}
return isWarn
- //return false
+ // return false
}
func (mp *MetaPartition) reportMissingReplicas(clusterID, leaderAddr string, seconds, interval int64) {
@@ -546,9 +540,7 @@ func (mp *MetaPartition) reportMissingReplicas(clusterID, leaderAddr string, sec
if contains(mp.Hosts, replica.Addr) && replica.isMissing() {
if mp.shouldReportMissingReplica(replica.Addr, interval) {
metaNode := replica.metaNode
- var (
- lastReportTime time.Time
- )
+ var lastReportTime time.Time
isActive := true
if metaNode != nil {
lastReportTime = metaNode.ReportTime
@@ -558,13 +550,12 @@ func (mp *MetaPartition) reportMissingReplicas(clusterID, leaderAddr string, sec
"miss time > :%v vlocLastRepostTime:%v dnodeLastReportTime:%v nodeisActive:%v",
clusterID, mp.volName, mp.PartitionID, replica.Addr, seconds, replica.ReportTime, lastReportTime, isActive)
Warn(clusterID, msg)
- //msg = fmt.Sprintf("decommissionMetaPartitionURL is http://%v/dataPartition/decommission?id=%v&addr=%v", leaderAddr, mp.PartitionID, replica.Addr)
- //Warn(clusterID, msg)
+ // msg = fmt.Sprintf("decommissionMetaPartitionURL is http://%v/dataPartition/decommission?id=%v&addr=%v", leaderAddr, mp.PartitionID, replica.Addr)
+ // Warn(clusterID, msg)
if WarnMetrics != nil {
WarnMetrics.WarnMissingMp(clusterID, replica.Addr, mp.PartitionID, true)
}
}
-
} else {
if WarnMetrics != nil {
WarnMetrics.WarnMissingMp(clusterID, replica.Addr, mp.PartitionID, false)
@@ -744,6 +735,7 @@ func (mr *MetaReplica) createTaskToLoadMetaPartition(partitionID uint64) (t *pro
resetMetaPartitionTaskID(t, partitionID)
return
}
+
func (mr *MetaReplica) isMissing() (miss bool) {
return time.Now().Unix()-mr.ReportTime > defaultMetaPartitionTimeOutSec
}
diff --git a/master/metadata_fsm.go b/master/metadata_fsm.go
index 642f143b9..6e965b69b 100644
--- a/master/metadata_fsm.go
+++ b/master/metadata_fsm.go
@@ -88,7 +88,6 @@ func (mf *MetadataFsm) restore() {
}
func (mf *MetadataFsm) restoreApplied() {
-
value, err := mf.store.Get(applied)
if err != nil {
panic(fmt.Sprintf("Failed to restore applied err:%v", err.Error()))
diff --git a/master/metadata_fsm_op.go b/master/metadata_fsm_op.go
index d23bb968f..bc73c63a9 100644
--- a/master/metadata_fsm_op.go
+++ b/master/metadata_fsm_op.go
@@ -447,6 +447,7 @@ func newZoneDomainValue() (ev *zoneDomainValue) {
}
return
}
+
func newNodeSetValue(nset *nodeSet) (nsv *nodeSetValue) {
nsv = &nodeSetValue{
ID: nset.ID,
@@ -457,6 +458,7 @@ func newNodeSetValue(nset *nodeSet) (nsv *nodeSetValue) {
}
return
}
+
func newNodeSetGrpValue(nset *nodeSetGroup) (nsv *domainNodeSetGrpValue) {
nsv = &domainNodeSetGrpValue{
DomainId: nset.domainId,
@@ -561,7 +563,7 @@ func (c *Cluster) loadApiLimiterInfo() (err error) {
return err
}
for _, value := range result {
- //cv := &clusterValue{}
+ // cv := &clusterValue{}
limiterInfos := make(map[string]*ApiLimitInfo)
if err = json.Unmarshal(value, &limiterInfos); err != nil {
log.LogErrorf("action[loadApiLimiterInfo], unmarshal err:%v", err.Error())
@@ -574,7 +576,7 @@ func (c *Cluster) loadApiLimiterInfo() (err error) {
c.apiLimiter.m.Lock()
c.apiLimiter.limiterInfos = limiterInfos
c.apiLimiter.m.Unlock()
- //c.apiLimiter.Replace(limiterInfos)
+ // c.apiLimiter.Replace(limiterInfos)
log.LogInfof("action[loadApiLimiterInfo], limiter info[%v]", value)
}
return
@@ -1034,6 +1036,7 @@ func (c *Cluster) loadZoneValue() (err error) {
return
}
+
func (c *Cluster) updateMaxConcurrentLcNodes(val uint64) {
atomic.StoreUint64(&c.cfg.MaxConcurrentLcNodes, val)
}
@@ -1102,13 +1105,13 @@ func (c *Cluster) loadClusterValue() (err error) {
}
c.cfg.MetaNodeThreshold = cv.Threshold
- //c.cfg.DirChildrenNumLimit = cv.DirChildrenNumLimit
+ // c.cfg.DirChildrenNumLimit = cv.DirChildrenNumLimit
c.cfg.ClusterLoadFactor = cv.LoadFactor
c.DisableAutoAllocate = cv.DisableAutoAllocate
c.ForbidMpDecommission = cv.ForbidMpDecommission
c.diskQosEnable = cv.DiskQosEnable
c.cfg.QosMasterAcceptLimit = cv.QosLimitUpload
- c.DecommissionLimit = cv.DecommissionLimit //dont update nodesets limit for nodesets are not loaded
+ c.DecommissionLimit = cv.DecommissionLimit // dont update nodesets limit for nodesets are not loaded
c.fileStatsEnable = cv.FileStatsEnable
c.clusterUuid = cv.ClusterUuid
c.clusterUuidEnable = cv.ClusterUuidEnable
@@ -1231,6 +1234,7 @@ func (c *Cluster) putZoneDomain(init bool) (err error) {
}
return c.submit(metadata)
}
+
func (c *Cluster) loadZoneDomain() (ok bool, err error) {
log.LogInfof("action[loadZoneDomain]")
result, err := c.fsm.store.SeekForPrefix([]byte(DomainPrefix))
@@ -1537,7 +1541,7 @@ func (c *Cluster) loadDataPartitions() (err error) {
dp := dpv.Restore(c)
vol.dataPartitions.put(dp)
c.addBadDataPartitionIdMap(dp)
- //add to nodeset decommission list
+ // add to nodeset decommission list
go dp.addToDecommissionList(c)
log.LogInfof("action[loadDataPartitions],vol[%v],dp[%v] ", vol.Name, dp.PartitionID)
}
@@ -1558,7 +1562,6 @@ func (c *Cluster) loadQuota() (err error) {
// load s3api qos info to memory cache
func (c *Cluster) loadS3ApiQosInfo() (err error) {
-
keyPrefix := S3QoSPrefix
result, err := c.fsm.store.SeekForPrefix([]byte(keyPrefix))
if err != nil {
diff --git a/master/metadata_snapshot.go b/master/metadata_snapshot.go
index ded3796f6..b48564a5d 100644
--- a/master/metadata_snapshot.go
+++ b/master/metadata_snapshot.go
@@ -16,8 +16,9 @@ package master
import (
"fmt"
- "github.com/tecbot/gorocksdb"
"io"
+
+ "github.com/tecbot/gorocksdb"
)
// MetadataSnapshot represents the snapshot of a meta partition
diff --git a/master/mocktest/data_server.go b/master/mocktest/data_server.go
index 1fe64a83f..ab52fdfbf 100644
--- a/master/mocktest/data_server.go
+++ b/master/mocktest/data_server.go
@@ -39,8 +39,8 @@ type MockDataServer struct {
Total uint64
Used uint64
Available uint64
- CreatedPartitionWeights uint64 //dataPartitionCnt*dataPartitionSize
- RemainWeightsForCreatePartition uint64 //all-useddataPartitionsWieghts
+ CreatedPartitionWeights uint64 // dataPartitionCnt*dataPartitionSize
+ RemainWeightsForCreatePartition uint64 // all-useddataPartitionsWieghts
CreatedPartitionCnt uint64
MaxWeightsForCreatePartition uint64
partitions []*MockDataPartition
@@ -291,7 +291,7 @@ func (mds *MockDataServer) handleHeartbeats(conn net.Conn, pkg *proto.Packet, ta
DiskPath: "/cfs",
ExtentCount: 10,
NeedCompare: true,
- IsLeader: true, //todo
+ IsLeader: true, // todo
VolName: partition.VolName,
}
response.PartitionReports = append(response.PartitionReports, vr)
@@ -342,7 +342,7 @@ func (mds *MockDataServer) handleLoadDataPartition(conn net.Conn, pkg *proto.Pac
if partition == nil {
return
}
- //response.VolName = partition.VolName
+ // response.VolName = partition.VolName
task.Response = response
if err = mds.mc.NodeAPI().ResponseDataNodeTask(task); err != nil {
return
diff --git a/master/monitor_metrics.go b/master/monitor_metrics.go
index 827ca5f6e..f89175363 100644
--- a/master/monitor_metrics.go
+++ b/master/monitor_metrics.go
@@ -152,7 +152,8 @@ type monitorMetrics struct {
}
func newMonitorMetrics(c *Cluster) *monitorMetrics {
- return &monitorMetrics{cluster: c,
+ return &monitorMetrics{
+ cluster: c,
volNames: make(map[string]struct{}),
badDisks: make(map[string]string),
nodesetInactiveDataNodesCount: make(map[uint64]int64),
@@ -167,7 +168,7 @@ type voidType struct{}
var voidVal voidType
type addrSet struct {
- addrs map[string]voidType //empty value of map does not occupy memory
+ addrs map[string]voidType // empty value of map does not occupy memory
replicaNum string
replicaAlive string
}
@@ -272,10 +273,10 @@ func (m *warningMetrics) WarnMissingDp(clusterName, addr string, partitionID uin
return
}
- //m.missingDp.SetWithLabelValues(1, clusterName, id, addr)
+ // m.missingDp.SetWithLabelValues(1, clusterName, id, addr)
if _, ok := m.dpMissingReplicaInfo[id]; !ok {
m.dpMissingReplicaInfo[id] = addrSet{addrs: make(map[string]voidType)}
- //m.dpMissingReplicaInfo[id].addrs = make(addrSet)
+ // m.dpMissingReplicaInfo[id].addrs = make(addrSet)
}
m.dpMissingReplicaInfo[id].addrs[addr] = voidVal
}
@@ -369,7 +370,7 @@ func (m *warningMetrics) WarnMissingMp(clusterName, addr string, partitionID uin
m.missingMp.SetWithLabelValues(1, clusterName, id, addr)
if _, ok := m.mpMissingReplicaInfo[id]; !ok {
m.dpMissingReplicaInfo[id] = addrSet{addrs: make(map[string]voidType)}
- //m.mpMissingReplicaInfo[id] = make(addrSet)
+ // m.mpMissingReplicaInfo[id] = make(addrSet)
}
m.mpMissingReplicaInfo[id].addrs[addr] = voidVal
}
@@ -423,7 +424,6 @@ func (m *warningMetrics) WarnMpNoLeader(clusterName string, partitionID uint64,
m.mpNoLeader.SetWithLabelValues(1, clusterName, strconv.FormatUint(partitionID, 10))
m.mpNoLeaderInfo[partitionID] = now
}
-
}
func (mm *monitorMetrics) start() {
@@ -890,6 +890,7 @@ func (mm *monitorMetrics) setNotWritableDataNodesCount() {
})
mm.dataNodesNotWritable.Set(float64(notWritabelDataNodesCount))
}
+
func (mm *monitorMetrics) clearInconsistentMps() {
for k := range mm.inconsistentMps {
mm.dataNodesetInactiveCount.DeleteLabelValues(k)
@@ -1052,7 +1053,7 @@ func (mm *monitorMetrics) resetAllLeaderMetrics() {
mm.metaNodesTotal.Set(0)
mm.metaNodesUsed.Set(0)
mm.metaNodesIncreased.Set(0)
- //mm.diskError.Set(0)
+ // mm.diskError.Set(0)
mm.dataNodesInactive.Set(0)
mm.metaNodesInactive.Set(0)
diff --git a/master/multi_ver_snapshot.go b/master/multi_ver_snapshot.go
index ac8526c1e..70c2c10a0 100644
--- a/master/multi_ver_snapshot.go
+++ b/master/multi_ver_snapshot.go
@@ -3,11 +3,12 @@ package master
import (
"encoding/json"
"fmt"
- "github.com/cubefs/cubefs/proto"
- "github.com/cubefs/cubefs/util/log"
"sync"
"sync/atomic"
"time"
+
+ "github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/util/log"
)
type Ver2PhaseCommit struct {
@@ -69,10 +70,12 @@ func newVersionMgr(vol *Vol) (mgr *VolVersionManager) {
}
return
}
+
func (verMgr *VolVersionManager) String() string {
return fmt.Sprintf("mgr:{vol[%v],status[%v] verSeq [%v], prepareinfo [%v], verlist [%v]}",
verMgr.vol.Name, verMgr.status, verMgr.verSeq, verMgr.prepareCommit, verMgr.multiVersionList)
}
+
func (verMgr *VolVersionManager) Persist() (err error) {
persistInfo := &VolVersionPersist{
MultiVersionList: verMgr.multiVersionList,
@@ -296,7 +299,6 @@ const (
)
func (verMgr *VolVersionManager) handleTaskRsp(resp *proto.MultiVersionOpResponse, partitionType uint32) {
-
verMgr.RLock()
defer verMgr.RUnlock()
log.LogInfof("action[handleTaskRsp] vol %v node %v partitionType %v,op %v, inner op %v", verMgr.vol.Name,
@@ -361,8 +363,8 @@ func (verMgr *VolVersionManager) handleTaskRsp(resp *proto.MultiVersionOpRespons
if atomic.LoadUint32(&verMgr.prepareCommit.commitCnt) == verMgr.prepareCommit.nodeCnt && needCommit {
if verMgr.prepareCommit.op == proto.DeleteVersion {
verMgr.CommitVer()
- //verMgr.prepareCommit.reset()
- //verMgr.prepareCommit.prepareInfo.Status = proto.VersionWorkingFinished
+ // verMgr.prepareCommit.reset()
+ // verMgr.prepareCommit.prepareInfo.Status = proto.VersionWorkingFinished
log.LogWarnf("action[handleTaskRsp] vol %v do Del version finished, verMgr %v", verMgr.vol.Name, verMgr)
} else if verMgr.prepareCommit.op == proto.CreateVersionPrepare {
log.LogInfof("action[handleTaskRsp] vol %v ver update prepare sucess. op %v, verseq %v,commit cnt %v", verMgr.vol.Name,
@@ -378,9 +380,7 @@ func (verMgr *VolVersionManager) handleTaskRsp(resp *proto.MultiVersionOpRespons
}
func (verMgr *VolVersionManager) createTaskToDataNode(cluster *Cluster, verSeq uint64, op uint8, force bool) (err error) {
- var (
- dpHost sync.Map
- )
+ var dpHost sync.Map
log.LogWarnf("action[createTaskToDataNode] vol %v verMgr.status %v verSeq %v op %v force %v, prepareCommit.nodeCnt %v",
verMgr.vol.Name, verMgr.status, verSeq, op, force, verMgr.prepareCommit.nodeCnt)
@@ -566,11 +566,10 @@ func (verMgr *VolVersionManager) initVer2PhaseTask(verSeq uint64, op uint8) (ver
}
verMgr.prepareCommit.op = op
- verMgr.prepareCommit.prepareInfo =
- &proto.VolVersionInfo{
- Ver: verSeq,
- Status: proto.VersionWorking,
- }
+ verMgr.prepareCommit.prepareInfo = &proto.VolVersionInfo{
+ Ver: verSeq,
+ Status: proto.VersionWorking,
+ }
}
opRes = op
return
diff --git a/master/node_selector.go b/master/node_selector.go
index 43bb09847..765e8d9b8 100644
--- a/master/node_selector.go
+++ b/master/node_selector.go
@@ -50,7 +50,6 @@ func (ns *nodeSet) getNodes(nodeType NodeType) *sync.Map {
type NodeSelector interface {
GetName() string
-
Select(ns *nodeSet, excludeHosts []string, replicaNum int) (newHosts []string, peers []proto.Peer, err error)
}
@@ -189,7 +188,7 @@ func (s *CarryWeightNodeSelector) getCarryDataNodes(maxTotal uint64, excludeHost
dataNodes.Range(func(key, value interface{}) bool {
dataNode := value.(*DataNode)
if contains(excludeHosts, dataNode.Addr) {
- //log.LogDebugf("[getAvailCarryDataNodeTab] dataNode [%v] is excludeHosts", dataNode.Addr)
+ // log.LogDebugf("[getAvailCarryDataNodeTab] dataNode [%v] is excludeHosts", dataNode.Addr)
return true
}
if !dataNode.canAllocDp() {
@@ -537,7 +536,6 @@ func (s *StrawNodeSelector) selectOneNode(nodes []Node) (index int, maxNode Node
}
func (s *StrawNodeSelector) Select(ns *nodeSet, excludeHosts []string, replicaNum int) (newHosts []string, peers []proto.Peer, err error) {
-
nodes := make([]Node, 0)
ns.getNodes(s.nodeType).Range(func(key, value interface{}) bool {
node := asNodeWrap(value, s.nodeType)
diff --git a/master/nodeset_selector.go b/master/nodeset_selector.go
index 4b6727cf2..1fd8ab356 100644
--- a/master/nodeset_selector.go
+++ b/master/nodeset_selector.go
@@ -110,7 +110,6 @@ func (ns *nodeSet) getTotalAvailableSpaceOf(nodeType NodeType) uint64 {
type NodesetSelector interface {
GetName() string
-
Select(nsc nodeSetCollection, excludeNodeSets []uint64, replicaNum uint8) (ns *nodeSet, err error)
}
diff --git a/master/operate_util.go b/master/operate_util.go
index fcc851c4f..e198649aa 100644
--- a/master/operate_util.go
+++ b/master/operate_util.go
@@ -147,7 +147,6 @@ func contains(arr []string, element string) (ok bool) {
}
func containsID(arr []uint64, element uint64) bool {
-
if arr == nil || len(arr) == 0 {
return false
}
diff --git a/master/server.go b/master/server.go
index df6dcf03f..51058f9c5 100644
--- a/master/server.go
+++ b/master/server.go
@@ -24,17 +24,15 @@ import (
"strconv"
"sync"
- "github.com/cubefs/cubefs/raftstore/raftstore_db"
-
- "github.com/cubefs/cubefs/util/stat"
-
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/raftstore"
+ "github.com/cubefs/cubefs/raftstore/raftstore_db"
"github.com/cubefs/cubefs/util/config"
"github.com/cubefs/cubefs/util/cryptoutil"
"github.com/cubefs/cubefs/util/errors"
"github.com/cubefs/cubefs/util/exporter"
"github.com/cubefs/cubefs/util/log"
+ "github.com/cubefs/cubefs/util/stat"
)
// configuration keys
@@ -71,7 +69,7 @@ var (
volNameRegexp = regexp.MustCompile("^[a-zA-Z0-9][a-zA-Z0-9_.-]{1,61}[a-zA-Z0-9]$")
ownerRegexp = regexp.MustCompile("^[A-Za-z][A-Za-z0-9_]{0,20}$")
- useConnPool = true //for test
+ useConnPool = true // for test
gConfig *clusterConfig
)
@@ -99,9 +97,7 @@ func setOverSoldFactor(factor float32) {
}
}
-var (
- volNameErr = errors.New("name can only start and end with number or letters, and len can't less than 3")
-)
+var volNameErr = errors.New("name can only start and end with number or letters, and len can't less than 3")
// Server represents the server in a cluster
type Server struct {
@@ -212,7 +208,6 @@ func (m *Server) Sync() {
}
func (m *Server) checkConfig(cfg *config.Config) (err error) {
-
m.clusterName = cfg.GetString(ClusterName)
m.ip = cfg.GetString(IP)
m.bindIp = cfg.GetBool(proto.BindIpKey)
@@ -402,6 +397,7 @@ func (m *Server) createRaftServer(cfg *config.Config) (err error) {
}
return
}
+
func (m *Server) initFsm() {
m.fsm = newMetadataFsm(m.rocksDBStore, m.retainLogs, m.raftStore.RaftServer())
m.fsm.registerLeaderChangeHandler(m.handleLeaderChange)
@@ -417,7 +413,7 @@ func (m *Server) initCluster() {
m.cluster = newCluster(m.clusterName, m.leaderInfo, m.fsm, m.partition, m.config)
m.cluster.retainLogs = m.retainLogs
- //incase any limiter on follower
+ // incase any limiter on follower
log.LogInfo("action[loadApiLimiterInfo] begin")
m.cluster.loadApiLimiterInfo()
log.LogInfo("action[loadApiLimiterInfo] end")
diff --git a/master/topology.go b/master/topology.go
index 259ba0153..c36bc9ffb 100644
--- a/master/topology.go
+++ b/master/topology.go
@@ -114,7 +114,6 @@ func (t *topology) getZone(name string) (zone *Zone, err error) {
}
func (t *topology) putDataNode(dataNode *DataNode) (err error) {
-
if _, ok := t.dataNodes.Load(dataNode.Addr); ok {
return
}
@@ -193,7 +192,7 @@ func (nsc nodeSetCollection) Swap(i, j int) {
type nodeSetGroup struct {
ID uint64
domainId uint64
- nsgInnerIndex int //worked if alloc num of replica not equal with standard set num of nsg
+ nsgInnerIndex int // worked if alloc num of replica not equal with standard set num of nsg
nodeSets []*nodeSet
nodeSetsIds []uint64
status uint8
@@ -247,6 +246,7 @@ func newDomainNodeSetGrpManager() *DomainNodeSetGrpManager {
}
return ns
}
+
func newDomainManager(cls *Cluster) *DomainManager {
log.LogInfof("action[newDomainManager] construct")
ns := &DomainManager{
@@ -295,14 +295,13 @@ func (nsgm *DomainManager) createDomain(zoneName string) (err error) {
}
return
}
+
func (nsgm *DomainManager) checkExcludeZoneState() {
if len(nsgm.excludeZoneListDomain) == 0 {
log.LogInfof("action[checkExcludeZoneState] no excludeZoneList for Domain,size zero")
return
}
- var (
- excludeNeedDomain = true
- )
+ excludeNeedDomain := true
log.LogInfof("action[checkExcludeZoneState] excludeZoneList size[%v]", len(nsgm.excludeZoneListDomain))
for zoneNm := range nsgm.excludeZoneListDomain {
if value, ok := nsgm.c.t.zoneMap.Load(zoneNm); ok {
@@ -502,8 +501,8 @@ func (nsgm *DomainManager) buildNodeSetGrp(domainGrpManager *DomainNodeSetGrpMan
func (nsgm *DomainManager) getHostFromNodeSetGrpSpecific(domainGrpManager *DomainNodeSetGrpManager, replicaNum uint8, createType uint32) (
hosts []string,
peers []proto.Peer,
- err error) {
-
+ err error,
+) {
log.LogErrorf("action[getHostFromNodeSetGrpSpecific] replicaNum[%v],type[%v], nsg cnt[%v], nsg status[%v]",
replicaNum, createType, len(domainGrpManager.nodeSetGrpMap), domainGrpManager.status)
if len(domainGrpManager.nodeSetGrpMap) == 0 {
@@ -549,13 +548,13 @@ func (nsgm *DomainManager) getHostFromNodeSetGrpSpecific(domainGrpManager *Domai
if createType == TypeDataPartition {
if host, peer, err = ns.getAvailDataNodeHosts(nil, needNum); err != nil {
log.LogErrorf("action[getHostFromNodeSetGrpSpecific] ns[%v] zone[%v] TypeDataPartition err[%v]", ns.ID, ns.zoneName, err)
- //nsg.status = dataNodesUnAvailable
+ // nsg.status = dataNodesUnAvailable
continue
}
} else {
if host, peer, err = ns.getAvailMetaNodeHosts(nil, needNum); err != nil {
log.LogErrorf("action[getHostFromNodeSetGrpSpecific] ns[%v] zone[%v] TypeMetaPartition err[%v]", ns.ID, ns.zoneName, err)
- //nsg.status = metaNodesUnAvailable
+ // nsg.status = metaNodesUnAvailable
continue
}
}
@@ -653,7 +652,7 @@ func (nsgm *DomainManager) getHostFromNodeSetGrp(domainId uint64, replicaNum uin
}
if host, peer, err = ns.getAvailDataNodeHosts(hosts, 1); err != nil {
log.LogWarnf("action[getHostFromNodeSetGrp] ns[%v] zone[%v] TypeDataPartition err[%v]", ns.ID, ns.zoneName, err)
- //nsg.status = dataNodesUnAvailable
+ // nsg.status = dataNodesUnAvailable
continue
}
} else {
@@ -663,7 +662,7 @@ func (nsgm *DomainManager) getHostFromNodeSetGrp(domainId uint64, replicaNum uin
}
if host, peer, err = ns.getAvailMetaNodeHosts(hosts, 1); err != nil {
log.LogWarnf("action[getHostFromNodeSetGrp] ns[%v] zone[%v] TypeMetaPartition err[%v]", ns.ID, ns.zoneName, err)
- //nsg.status = metaNodesUnAvailable
+ // nsg.status = metaNodesUnAvailable
continue
}
}
@@ -800,6 +799,7 @@ func buildNodeSetGrp3Zone(nsgm *DomainManager, domainGrpManager *DomainNodeSetGr
nsgm.buildNodeSetGrpCommit(resList, domainGrpManager)
return nil
}
+
func buildNodeSetGrpOneZone(nsgm *DomainManager, domainGrpManager *DomainNodeSetGrpManager) (err error) {
nsgm.Lock()
defer nsgm.Unlock()
@@ -1120,6 +1120,7 @@ func (ns *nodeSet) AcquireDecommissionToken(id uint64) bool {
func (ns *nodeSet) ReleaseDecommissionToken(id uint64) {
ns.decommissionDataPartitionList.releaseDecommissionToken(id)
}
+
func (ns *nodeSet) AddDecommissionDisk(dd *DecommissionDisk) {
ns.DecommissionDisks.Store(dd.GenerateKey(), dd)
if dd.IsManualDecommissionDisk() {
@@ -1158,7 +1159,7 @@ func (ns *nodeSet) removeAutoDecommissionDisk(dd *DecommissionDisk) {
func (ns *nodeSet) traverseDecommissionDisk(c *Cluster) {
t := time.NewTicker(DecommissionInterval)
- //wait for loading all decommissionDisk when reload metadata
+ // wait for loading all decommissionDisk when reload metadata
log.LogInfof("action[traverseDecommissionDisk]wait %v", ns.ID)
<-ns.startDecommissionDiskListTraverse
log.LogInfof("action[traverseDecommissionDisk] traverseDecommissionDisk start %v", ns.ID)
@@ -1181,7 +1182,7 @@ func (ns *nodeSet) traverseDecommissionDisk(c *Cluster) {
if status == DecommissionRunning {
runningCnt++
} else if status == DecommissionSuccess || status == DecommissionFail || status == DecommissionPause {
- //remove from decommission disk list
+ // remove from decommission disk list
log.LogWarnf("traverseDecommissionDisk remove disk %v status %v",
disk.GenerateKey(), disk.GetDecommissionStatus())
ns.RemoveDecommissionDisk(disk)
@@ -1341,7 +1342,7 @@ func (t *topology) allocZonesForMetaNode(zoneNum, replicaNum int, excludeZone []
}
}
- //if across zone,candidateZones must be larger than or equal with 2,otherwise,must have a candidate zone
+ // if across zone,candidateZones must be larger than or equal with 2,otherwise,must have a candidate zone
if (zoneNum >= 2 && len(candidateZones) < 2) || len(candidateZones) < 1 {
log.LogError(fmt.Sprintf("action[allocZonesForMetaNode],reqZoneNum[%v],candidateZones[%v],demandWriteNodes[%v],err:%v",
zoneNum, len(candidateZones), demandWriteNodes, proto.ErrNoZoneToCreateMetaPartition))
@@ -1394,7 +1395,7 @@ func (t *topology) allocZonesForDataNode(zoneNum, replicaNum int, excludeZone []
}
}
- //if across zone,candidateZones must be larger than or equal with 2,otherwise,must have one candidate zone
+ // if across zone,candidateZones must be larger than or equal with 2,otherwise,must have one candidate zone
if (zoneNum >= 2 && len(candidateZones) < 2) || len(candidateZones) < 1 {
log.LogError(fmt.Sprintf("action[allocZonesForDataNode],reqZoneNum[%v],candidateZones[%v],demandWriteNodes[%v],err:%v",
zoneNum, len(candidateZones), demandWriteNodes, proto.ErrNoZoneToCreateDataPartition))
@@ -1432,6 +1433,7 @@ type Zone struct {
QosFlowWLimit uint64
sync.RWMutex
}
+
type zoneValue struct {
Name string
QosIopsRLimit uint64
@@ -1619,7 +1621,6 @@ func (zone *Zone) getAvailNodeSetForMetaNode() (nset *nodeSet) {
}
continue
}
-
}
return
}
@@ -1660,6 +1661,7 @@ func (zone *Zone) getDataNode(addr string) (dataNode *DataNode, err error) {
dataNode = value.(*DataNode)
return
}
+
func (zone *Zone) deleteDataNode(dataNode *DataNode) {
ns, err := zone.getNodeSet(dataNode.NodeSetID)
if err != nil {
@@ -1693,7 +1695,6 @@ func (zone *Zone) deleteMetaNode(metaNode *MetaNode) (err error) {
}
func (zone *Zone) allocNodeSetForDataNode(excludeNodeSets []uint64, replicaNum uint8) (ns *nodeSet, err error) {
-
nset := zone.getAllNodeSet()
if nset == nil {
return nil, errors.NewError(proto.ErrNoNodeSetToCreateDataPartition)
@@ -1757,6 +1758,7 @@ func (zone *Zone) canWriteForDataNode(replicaNum uint8) (can bool) {
log.LogInfof("canWriteForDataNode leastAlive[%v],replicaNum[%v],count[%v]\n", leastAlive, replicaNum, zone.dataNodeCount())
return
}
+
func (zone *Zone) isUsedRatio(ratio float64) (can bool) {
zone.RLock()
defer zone.RUnlock()
@@ -1951,7 +1953,6 @@ func (zone *Zone) updateDataNodeQosLimit(cluster *Cluster, qosParam *qosArgs) er
}
func (zone *Zone) loadDataNodeQosLimit() {
-
zone.dataNodes.Range(func(key, value interface{}) bool {
dataNode := value.(*DataNode)
if zone.QosFlowRLimit > 0 {
@@ -1971,7 +1972,6 @@ func (zone *Zone) loadDataNodeQosLimit() {
}
func (zone *Zone) dataNodeCount() (len int) {
-
zone.dataNodes.Range(func(key, value interface{}) bool {
len++
return true
@@ -2125,13 +2125,13 @@ func (l *DecommissionDataPartitionList) Put(id uint64, value *DataPartition, c *
log.LogWarnf("action[DecommissionDataPartitionListPut] ns[%v] cannot put nil value", id)
return
}
- //can only add running or mark or prepare
+ // can only add running or mark or prepare
if !value.canAddToDecommissionList() {
log.LogWarnf("action[DecommissionDataPartitionListPut] ns[%v] put wrong dp[%v] status[%v]",
id, value.PartitionID, value.GetDecommissionStatus())
return
}
- //prepare status reset to mark status to retry again
+ // prepare status reset to mark status to retry again
if value.GetDecommissionStatus() == DecommissionPrepare {
value.SetDecommissionStatus(markDecommission)
}
@@ -2144,7 +2144,7 @@ func (l *DecommissionDataPartitionList) Put(id uint64, value *DataPartition, c *
elm := l.decommissionList.PushBack(value)
l.cacheMap[value.PartitionID] = elm
l.mu.Unlock()
- //restore from rocksdb
+ // restore from rocksdb
if value.checkConsumeToken() {
value.TryAcquireDecommissionToken(c)
}
@@ -2226,7 +2226,7 @@ func (l *DecommissionDataPartitionList) startTraverse() {
func (l *DecommissionDataPartitionList) traverse(c *Cluster) {
t := time.NewTicker(DecommissionInterval)
- //wait for loading all ap when reload metadata
+ // wait for loading all ap when reload metadata
<-l.start
defer t.Stop()
for {
@@ -2255,14 +2255,14 @@ func (l *DecommissionDataPartitionList) traverse(c *Cluster) {
dp.PartitionID)
l.Remove(dp)
}
- //rollback fail/success need release token
+ // rollback fail/success need release token
dp.ReleaseDecommissionToken(c)
} else if dp.IsDecommissionPaused() {
log.LogDebugf("action[DecommissionListTraverse]Remove dp[%v] for paused ",
dp.PartitionID)
dp.ReleaseDecommissionToken(c)
l.Remove(dp)
- } else if dp.IsDecommissionInitial() { //fixed done ,not release token
+ } else if dp.IsDecommissionInitial() { // fixed done ,not release token
l.Remove(dp)
dp.ResetDecommissionStatus()
c.syncUpdateDataPartition(dp)
@@ -2270,7 +2270,7 @@ func (l *DecommissionDataPartitionList) traverse(c *Cluster) {
// TODO: decommission in here
go func(dp *DataPartition) {
if !dp.TryToDecommission(c) {
- //retry should release token
+ // retry should release token
if dp.IsMarkDecommission() {
dp.ReleaseDecommissionToken(c)
}
@@ -2301,7 +2301,7 @@ func (l *DecommissionDiskList) Put(nsId uint64, value *DecommissionDisk) {
log.LogWarnf("action[DecommissionDataPartitionListPut] ns[%v] cannot put nil value", nsId)
return
}
- //can only add running or mark
+ // can only add running or mark
if !value.canAddToDecommissionList() {
log.LogWarnf("action[DecommissionDataPartitionListPut] ns[%v] put wrong disk[%v] status[%v]",
nsId, value.GenerateKey(), value.GetDecommissionStatus())
diff --git a/master/topology_test.go b/master/topology_test.go
index b1c1ff7a5..e31b71323 100644
--- a/master/topology_test.go
+++ b/master/topology_test.go
@@ -38,7 +38,7 @@ func TestSingleZone(t *testing.T) {
return
}
replicaNum := 2
- //single zone exclude,if it is a single zone excludeZones don't take effect
+ // single zone exclude,if it is a single zone excludeZones don't take effect
excludeZones := make([]string, 0)
excludeZones = append(excludeZones, zoneName)
zones, err := topo.allocZonesForDataNode(replicaNum, replicaNum, excludeZones)
@@ -51,7 +51,7 @@ func TestSingleZone(t *testing.T) {
return
}
- //single zone normal
+ // single zone normal
zones, err = topo.allocZonesForDataNode(replicaNum, replicaNum, nil)
if err != nil {
t.Error(err)
@@ -70,7 +70,7 @@ func TestAllocZones(t *testing.T) {
topo := newTopology()
c := new(Cluster)
zoneCount := 3
- //add three zones
+ // add three zones
zoneName1 := testZone1
zone1 := newZone(zoneName1)
nodeSet1 := newNodeSet(c, 1, 6, zoneName1)
@@ -102,7 +102,7 @@ func TestAllocZones(t *testing.T) {
t.Errorf("expect zones num[%v],len(zones) is %v", zoneCount, len(zones))
return
}
- //only pass replica num
+ // only pass replica num
replicaNum := 2
zones, err := topo.allocZonesForDataNode(replicaNum, replicaNum, nil)
if err != nil {
@@ -119,14 +119,14 @@ func TestAllocZones(t *testing.T) {
cluster.t = topo
cluster.cfg = newClusterConfig()
- //don't cross zone
+ // don't cross zone
hosts, _, err := cluster.getHostFromNormalZone(TypeDataPartition, nil, nil, nil, replicaNum, 1, "")
if err != nil {
t.Error(err)
return
}
- //cross zone
+ // cross zone
hosts, _, err = cluster.getHostFromNormalZone(TypeDataPartition, nil, nil, nil, replicaNum, 2, "")
if err != nil {
t.Error(err)
diff --git a/master/user.go b/master/user.go
index 6a1c093f0..1db80c3c2 100644
--- a/master/user.go
+++ b/master/user.go
@@ -25,9 +25,9 @@ const (
type User struct {
fsm *MetadataFsm
partition raftstore.Partition
- userStore sync.Map //K: userID, V: UserInfo
- AKStore sync.Map //K: ak, V: userID
- volUser sync.Map //K: vol, V: userIDs
+ userStore sync.Map // K: userID, V: UserInfo
+ AKStore sync.Map // K: ak, V: userID
+ volUser sync.Map // K: vol, V: userIDs
userStoreMutex sync.RWMutex
AKStoreMutex sync.RWMutex
volUserMutex sync.RWMutex
@@ -55,12 +55,12 @@ func (u *User) createKey(param *proto.UserCreateParam) (userInfo *proto.UserInfo
return
}
- var userID = param.ID
- var password = param.Password
+ userID := param.ID
+ password := param.Password
if password == "" {
password = DefaultUserPassword
}
- var accessKey = param.AccessKey
+ accessKey := param.AccessKey
if accessKey == "" {
accessKey = util.RandomString(accessKeyLength, util.Numeric|util.LowerLetter|util.UpperLetter)
} else {
@@ -69,7 +69,7 @@ func (u *User) createKey(param *proto.UserCreateParam) (userInfo *proto.UserInfo
return
}
}
- var secretKey = param.SecretKey
+ secretKey := param.SecretKey
if secretKey == "" {
secretKey = util.RandomString(secretKeyLength, util.Numeric|util.LowerLetter|util.UpperLetter)
} else {
@@ -78,13 +78,13 @@ func (u *User) createKey(param *proto.UserCreateParam) (userInfo *proto.UserInfo
return
}
}
- var userType = param.Type
- var description = param.Description
+ userType := param.Type
+ description := param.Description
u.userStoreMutex.Lock()
defer u.userStoreMutex.Unlock()
u.AKStoreMutex.Lock()
defer u.AKStoreMutex.Unlock()
- //check duplicate
+ // check duplicate
if _, exist = u.userStore.Load(userID); exist {
err = proto.ErrDuplicateUserID
return
@@ -95,8 +95,10 @@ func (u *User) createKey(param *proto.UserCreateParam) (userInfo *proto.UserInfo
_, exist = u.AKStore.Load(accessKey)
}
userPolicy = proto.NewUserPolicy()
- userInfo = &proto.UserInfo{UserID: userID, AccessKey: accessKey, SecretKey: secretKey, Policy: userPolicy,
- UserType: userType, CreateTime: time.Unix(time.Now().Unix(), 0).Format(proto.TimeFormat), Description: description}
+ userInfo = &proto.UserInfo{
+ UserID: userID, AccessKey: accessKey, SecretKey: secretKey, Policy: userPolicy,
+ UserType: userType, CreateTime: time.Unix(time.Now().Unix(), 0).Format(proto.TimeFormat), Description: description,
+ }
AKUser = &proto.AKUser{AccessKey: accessKey, UserID: userID, Password: encodingPassword(password)}
if err = u.syncAddUserInfo(userInfo); err != nil {
return
@@ -177,7 +179,7 @@ func (u *User) updateKey(param *proto.UserUpdateParam) (userInfo *proto.UserInfo
err = proto.ErrNoPermission
return
}
- var formerAK = userInfo.AccessKey
+ formerAK := userInfo.AccessKey
var akMark, skMark, typeMark, describeMark int
if param.AccessKey != "" {
if !proto.IsValidAK(param.AccessKey) {
@@ -197,7 +199,7 @@ func (u *User) updateKey(param *proto.UserUpdateParam) (userInfo *proto.UserInfo
}
skMark = 1
}
- //Type == 0,do not modify type
+ // Type == 0,do not modify type
if param.Type != 0 {
if param.Type.Valid() {
typeMark = 1
@@ -363,8 +365,8 @@ func (u *User) deleteVolPolicy(volName string) (err error) {
volUser *proto.VolUser
userInfo *proto.UserInfo
)
- //delete policy
- var deletedUsers = make([]string, 0)
+ // delete policy
+ deletedUsers := make([]string, 0)
var userIDs []string
if userIDs, err = u.getUsersOfVol(volName); err != nil {
return
@@ -388,7 +390,7 @@ func (u *User) deleteVolPolicy(volName string) (err error) {
}
userInfo.Mu.Unlock()
}
- //delete volName index
+ // delete volName index
if value, exist := u.volUser.Load(volName); exist {
volUser = value.(*proto.VolUser)
} else {
@@ -415,7 +417,7 @@ func (u *User) transferVol(params *proto.UserTransferVolParam) (targetUserInfo *
return
}
if err == nil {
- var isOwned = userInfo.Policy.IsOwn(params.Volume)
+ isOwned := userInfo.Policy.IsOwn(params.Volume)
if !isOwned && !params.Force && params.UserSrc != params.UserDst {
err = proto.ErrHaveNoPolicy
return
@@ -477,9 +479,7 @@ func (u *User) getAKUser(ak string) (akUser *proto.AKUser, err error) {
func (u *User) addUserToVol(userID, volName string) (err error) {
u.volUserMutex.Lock()
defer u.volUserMutex.Unlock()
- var (
- volUser *proto.VolUser
- )
+ var volUser *proto.VolUser
if value, ok := u.volUser.Load(volName); ok {
volUser = value.(*proto.VolUser)
volUser.Mu.Lock()
@@ -498,10 +498,9 @@ func (u *User) addUserToVol(userID, volName string) (err error) {
}
return
}
+
func (u *User) removeUserFromVol(userID, volName string) (err error) {
- var (
- volUser *proto.VolUser
- )
+ var volUser *proto.VolUser
if value, ok := u.volUser.Load(volName); ok {
volUser = value.(*proto.VolUser)
volUser.Mu.Lock()
diff --git a/master/vol.go b/master/vol.go
index 5ace3dcec..f721dda73 100644
--- a/master/vol.go
+++ b/master/vol.go
@@ -32,8 +32,8 @@ import (
type VolVarargs struct {
zoneName string
description string
- capacity uint64 //GB
- deleteLockTime int64 //h
+ capacity uint64 // GB
+ deleteLockTime int64 // h
followerRead bool
authenticate bool
dpSelectorName string
@@ -116,7 +116,6 @@ type Vol struct {
}
func newVol(vv volValue) (vol *Vol) {
-
vol = &Vol{ID: vv.ID, Name: vv.Name, MetaPartitions: make(map[uint64]*MetaPartition, 0)}
if vol.threshold <= 0 {
@@ -218,8 +217,10 @@ type mpsLockManager struct {
enable int32 // only config debug log enable lock
}
-var lockCheckInterval = time.Second
-var lockExpireInterval = time.Minute
+var (
+ lockCheckInterval = time.Second
+ lockExpireInterval = time.Minute
+)
func newMpsLockManager(vol *Vol) *mpsLockManager {
lc := &mpsLockManager{vol: vol}
@@ -297,7 +298,7 @@ func (mpsLock *mpsLockManager) CheckExceptionLock(interval time.Duration, expire
}
func (vol *Vol) CheckStrategy(c *Cluster) {
- //make sure resume all the processing ver deleting tasks before checking
+ // make sure resume all the processing ver deleting tasks before checking
if !atomic.CompareAndSwapInt32(&vol.VersionMgr.checkStrategy, 0, 1) {
return
}
@@ -386,7 +387,6 @@ func (vol *Vol) initQosManager(limitArgs *qosArgs) {
}
go vol.qosManager.serverFactorLimitMap[arrType[i]].dispatch()
}
-
}
func (vol *Vol) refreshOSSSecure() (key, secret string) {
@@ -593,7 +593,6 @@ func (vol *Vol) tryUpdateDpReplicaNum(c *Cluster, partition *DataPartition) (err
}
func (vol *Vol) isOkUpdateRepCnt() (ok bool, rsp []uint64) {
-
if proto.IsCold(vol.VolType) {
return
}
@@ -789,7 +788,6 @@ func (vol *Vol) capacity() uint64 {
}
func (vol *Vol) autoDeleteDp(c *Cluster) {
-
if vol.dataPartitions == nil {
return
}
@@ -818,7 +816,6 @@ func (vol *Vol) autoDeleteDp(c *Cluster) {
}
func (vol *Vol) checkAutoDataPartitionCreation(c *Cluster) {
-
defer func() {
if r := recover(); r != nil {
log.LogWarnf("checkAutoDataPartitionCreation occurred panic,err[%v]", r)
@@ -860,7 +857,6 @@ func (vol *Vol) shouldInhibitWriteBySpaceFull() bool {
}
func (vol *Vol) needCreateDataPartition() (ok bool, err error) {
-
ok = false
if vol.status() == proto.VolStatusMarkDelete {
err = proto.ErrVolNotExists
@@ -893,7 +889,6 @@ func (vol *Vol) needCreateDataPartition() (ok bool, err error) {
}
func (vol *Vol) autoCreateDataPartitions(c *Cluster) {
-
if time.Since(vol.dataPartitions.lastAutoCreateTime) < time.Minute {
return
}
@@ -996,7 +991,6 @@ func (vol *Vol) sendViewCacheToFollower(c *Cluster) {
}
func (vol *Vol) ebsUsedSpace() uint64 {
-
size := uint64(0)
vol.mpsLock.RLock()
defer vol.mpsLock.RUnlock()
@@ -1021,8 +1015,8 @@ func (vol *Vol) updateViewCache(c *Cluster) {
return
}
vol.setMpsCache(mpsBody)
- //dpResps := vol.dataPartitions.getDataPartitionsView(0)
- //view.DataPartitions = dpResps
+ // dpResps := vol.dataPartitions.getDataPartitionsView(0)
+ // view.DataPartitions = dpResps
view.DomainOn = vol.domainOn
viewReply := newSuccessHTTPReply(view)
body, err := json.Marshal(viewReply)
@@ -1073,14 +1067,12 @@ func (vol *Vol) getViewCache() []byte {
}
func (vol *Vol) deleteDataPartition(c *Cluster, dp *DataPartition) {
-
var addrs []string
for _, replica := range dp.Replicas {
addrs = append(addrs, replica.Addr)
}
for _, addr := range addrs {
-
if err := vol.deleteDataPartitionFromDataNode(c, dp.createTaskToDeleteDataPartition(addr)); err != nil {
log.LogErrorf("[deleteDataPartitionFromDataNode] delete data replica from datanode fail, id %d, err %s", dp.PartitionID, err.Error())
}
@@ -1237,7 +1229,6 @@ func (vol *Vol) deleteDataPartitionsFromStore(c *Cluster) {
for _, dp := range vol.dataPartitions.partitions {
c.syncDeleteDataPartition(dp)
}
-
}
func (vol *Vol) getTasksToDeleteMetaPartitions() (tasks []*proto.AdminTask) {
@@ -1378,7 +1369,6 @@ func (vol *Vol) doCreateMetaPartition(c *Cluster, start, end uint64) (mp *MetaPa
log.LogErrorf("action[doCreateMetaPartition] getHostFromDomainZone err[%v]", err)
return nil, errors.NewError(err)
}
-
} else {
var excludeZone []string
zoneNum := c.decideZoneNum(vol.crossZone)
@@ -1482,7 +1472,6 @@ func setVolFromArgs(args *VolVarargs, vol *Vol) {
}
func getVolVarargs(vol *Vol) *VolVarargs {
-
args := &coldVolArgs{
objBlockSize: vol.EbsBlkSize,
cacheCap: vol.CacheCapacity,
@@ -1541,7 +1530,7 @@ func (vol *Vol) loadQuotaManager(c *Cluster) (err error) {
}
for _, value := range result {
- var quotaInfo = &proto.QuotaInfo{}
+ quotaInfo := &proto.QuotaInfo{}
if err = json.Unmarshal(value, quotaInfo); err != nil {
log.LogErrorf("loadQuotaManager Unmarshal fail err [%v]", err)
diff --git a/master/vol_test.go b/master/vol_test.go
index 994a10bd7..756b9cf81 100644
--- a/master/vol_test.go
+++ b/master/vol_test.go
@@ -51,11 +51,11 @@ func TestCheckVol(t *testing.T) {
func TestVol(t *testing.T) {
name := "test1"
createVol(map[string]interface{}{nameKey: name}, t)
- //report mp/dp info to master
+ // report mp/dp info to master
server.cluster.checkDataNodeHeartbeat()
server.cluster.checkDataNodeHeartbeat()
time.Sleep(5 * time.Second)
- //check status
+ // check status
server.cluster.checkMetaPartitions()
server.cluster.checkDataPartitions()
server.cluster.checkLoadMetaPartitions()
@@ -79,7 +79,6 @@ func TestVol(t *testing.T) {
}
func TestCreateColdVol(t *testing.T) {
-
volName := "coldVol"
req := map[string]interface{}{}
@@ -200,7 +199,6 @@ func buildUrl(host, op string, kv map[string]interface{}) string {
}
func checkWithDefault(kv map[string]interface{}, key string, val interface{}) {
-
if kv[key] != nil {
return
}
@@ -211,7 +209,6 @@ func checkWithDefault(kv map[string]interface{}, key string, val interface{}) {
const testOwner = "cfs"
func createVol(kv map[string]interface{}, t *testing.T) {
-
checkWithDefault(kv, volTypeKey, proto.VolumeTypeHot)
checkWithDefault(kv, volOwnerKey, testOwner)
checkWithDefault(kv, zoneNameKey, testZone2)
@@ -255,7 +252,7 @@ func checkDataPartitionsWritableTest(vol *Vol, t *testing.T) {
return
}
- //after check data partitions ,the status must be writable
+ // after check data partitions ,the status must be writable
vol.checkDataPartitions(server.cluster)
partition = vol.dataPartitions.partitions[0]
if partition.Status != proto.ReadWrite {
@@ -279,7 +276,7 @@ func checkMetaPartitionsWritableTest(vol *Vol, t *testing.T) {
maxPartitionID := vol.maxPartitionID()
maxMp := vol.MetaPartitions[maxPartitionID]
- //after check meta partitions ,the status must be writable
+ // after check meta partitions ,the status must be writable
maxMp.checkStatus(server.cluster.Name, false, int(vol.mpReplicaNum), maxPartitionID, 4194304, vol.Forbidden)
if maxMp.Status != proto.ReadWrite {
t.Errorf("expect partition status[%v],real status[%v]\n", proto.ReadWrite, maxMp.Status)
@@ -318,7 +315,7 @@ func statVol(name string, t *testing.T) {
func TestVolMpsLock(t *testing.T) {
name := "TestVolMpsLock"
var volID uint64 = 1
- var createTime = time.Now().Unix()
+ createTime := time.Now().Unix()
vv := volValue{
ID: volID,
@@ -374,7 +371,7 @@ func TestVolMpsLock(t *testing.T) {
func TestConcurrentReadWriteDataPartitionMap(t *testing.T) {
name := "TestConcurrentReadWriteDataPartitionMap"
var volID uint64 = 1
- var createTime = time.Now().Unix()
+ createTime := time.Now().Unix()
vv := volValue{
ID: volID,
@@ -397,7 +394,7 @@ func TestConcurrentReadWriteDataPartitionMap(t *testing.T) {
// unavailable mp
mp1 := newMetaPartition(1, 1, defaultMaxMetaPartitionInodeID, 3, name, volID, 0)
vol.addMetaPartition(mp1)
- //readonly mp
+ // readonly mp
mp2 := newMetaPartition(2, 1, defaultMaxMetaPartitionInodeID, 3, name, volID, 0)
mp2.Status = proto.ReadOnly
vol.addMetaPartition(mp2)
diff --git a/metanode/api_handler.go b/metanode/api_handler.go
index a7da435c5..588bd8640 100644
--- a/metanode/api_handler.go
+++ b/metanode/api_handler.go
@@ -297,7 +297,6 @@ func (m *MetaNode) getInodeHandler(w http.ResponseWriter, r *http.Request) {
defer func() {
data, _ := resp.Marshal()
if _, err := w.Write(data); err != nil {
-
log.LogErrorf("[getInodeHandler] response %s", err)
}
}()
@@ -576,6 +575,7 @@ func (m *MetaNode) getTxHandler(w http.ResponseWriter, r *http.Request) {
}
return
}
+
func (m *MetaNode) getRealVerSeq(w http.ResponseWriter, r *http.Request) (verSeq uint64, err error) {
if r.FormValue("verSeq") != "" {
var ver int64
@@ -589,6 +589,7 @@ func (m *MetaNode) getRealVerSeq(w http.ResponseWriter, r *http.Request) (verSeq
}
return
}
+
func (m *MetaNode) getAllDentriesHandler(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
resp := NewAPIResponse(http.StatusSeeOther, "")
@@ -746,6 +747,7 @@ func (m *MetaNode) getAllTxHandler(w http.ResponseWriter, r *http.Request) {
}
return
}
+
func (m *MetaNode) getDirectoryHandler(w http.ResponseWriter, r *http.Request) {
resp := NewAPIResponse(http.StatusBadRequest, "")
defer func() {
@@ -860,7 +862,7 @@ func (m *MetaNode) getSnapshotHandler(w http.ResponseWriter, r *http.Request, fi
err = errors.NewErrorf("[getInodeSnapshotHandler] Stat: %s", err.Error())
return
}
- fp, err := os.OpenFile(filename, os.O_RDONLY, 0644)
+ fp, err := os.OpenFile(filename, os.O_RDONLY, 0o644)
if err != nil {
err = errors.NewErrorf("[getInodeSnapshotHandler] OpenFile: %s", err.Error())
return
diff --git a/metanode/api_handler_test.go b/metanode/api_handler_test.go
index 77aa72ef7..d93ff15ca 100644
--- a/metanode/api_handler_test.go
+++ b/metanode/api_handler_test.go
@@ -5,7 +5,6 @@ import (
"encoding/hex"
"fmt"
"io"
- "io/ioutil"
"net/http"
"os"
"path"
@@ -102,7 +101,7 @@ func httpReqHandle(url string, t *testing.T) (data []byte) {
t.Errorf("status code[%v]", resp.StatusCode)
return
}
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
if err != nil {
t.Errorf("err is %v", err)
return
diff --git a/metanode/btree_test.go b/metanode/btree_test.go
index 5a42e8ed7..00aa32e48 100644
--- a/metanode/btree_test.go
+++ b/metanode/btree_test.go
@@ -28,6 +28,7 @@ func (t *testItem) Less(than BtreeItem) bool {
item, ok := than.(*testItem)
return ok && (t.data < item.data)
}
+
func (t *testItem) Copy() BtreeItem {
newItem := *t
return &newItem
diff --git a/metanode/const.go b/metanode/const.go
index d336e80e9..98e2009b2 100644
--- a/metanode/const.go
+++ b/metanode/const.go
@@ -123,7 +123,7 @@ const (
opFSMAppendMultipart = 24
opFSMSyncCursor = 25
- //supplement action
+ // supplement action
opFSMInternalDeleteInodeBatch = 26
opFSMDeleteDentryBatch = 27
opFSMUnlinkInodeBatch = 28
@@ -161,7 +161,7 @@ const (
opFSMTxRbInodeSnapshot = 53
opFSMTxRbDentrySnapshot = 54
- //quota
+ // quota
opFSMCreateInodeQuota = 55
opFSMSetInodeQuotaBatch = 56
opFSMDeleteInodeQuotaBatch = 57
@@ -189,9 +189,7 @@ const (
opFSMVerListSnapShot = 73
)
-var (
- exporterKey string
-)
+var exporterKey string
var (
ErrNoLeader = errors.New("no leader")
@@ -220,12 +218,12 @@ const (
cfgZoneName = "zoneName"
cfgTickInterval = "tickInterval"
cfgRaftRecvBufSize = "raftRecvBufSize"
- cfgSmuxPortShift = "smuxPortShift" //int
- cfgSmuxMaxConn = "smuxMaxConn" //int
- cfgSmuxStreamPerConn = "smuxStreamPerConn" //int
- cfgSmuxMaxBuffer = "smuxMaxBuffer" //int
- cfgRetainLogs = "retainLogs" //string, raft RetainLogs
- cfgRaftSyncSnapFormatVersion = "raftSyncSnapFormatVersion" //int, format version of snapshot that raft leader sent to follower
+ cfgSmuxPortShift = "smuxPortShift" // int
+ cfgSmuxMaxConn = "smuxMaxConn" // int
+ cfgSmuxStreamPerConn = "smuxStreamPerConn" // int
+ cfgSmuxMaxBuffer = "smuxMaxBuffer" // int
+ cfgRetainLogs = "retainLogs" // string, raft RetainLogs
+ cfgRaftSyncSnapFormatVersion = "raftSyncSnapFormatVersion" // int, format version of snapshot that raft leader sent to follower
cfgServiceIDKey = "serviceIDKey"
metaNodeDeleteBatchCountKey = "batchCount"
diff --git a/metanode/datapartition.go b/metanode/datapartition.go
index 54684f10f..485f25668 100644
--- a/metanode/datapartition.go
+++ b/metanode/datapartition.go
@@ -15,10 +15,11 @@
package metanode
import (
- "github.com/cubefs/cubefs/proto"
- "github.com/cubefs/cubefs/util/log"
"strings"
"sync"
+
+ "github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/util/log"
)
// DataPartition defines the struct of data partition that will be used on the meta node.
diff --git a/metanode/dentry.go b/metanode/dentry.go
index 58d8c376d..1232b1888 100644
--- a/metanode/dentry.go
+++ b/metanode/dentry.go
@@ -17,11 +17,11 @@ package metanode
import (
"bytes"
"encoding/binary"
-
"fmt"
+ "math"
+
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/log"
- "math"
)
// Dentry wraps necessary properties of the `dentry` information in file system.
@@ -54,7 +54,7 @@ type Dentry struct {
Name string // Name of the current dentry.
Inode uint64 // FileID value of the current inode.
Type uint32
- //snapshot
+ // snapshot
multiSnap *DentryMultiSnap
}
@@ -311,7 +311,7 @@ func (d *Dentry) deleteVerSnapshot(delVerSeq uint64, mpVerSeq uint64, verlist []
}
// if any alive snapshot in mp dimension exist in seq scope from den to next ascend neighbor, dio snapshot be keep or else drop
startSeq := den.getVerSeq()
- realIdx := idx - 1 //index in history list layer
+ realIdx := idx - 1 // index in history list layer
if realIdx == 0 {
endSeq = d.getVerSeq()
} else {
@@ -362,7 +362,7 @@ func (d *Dentry) String() string {
}
type TxDentry struct {
- //ParInode *Inode
+ // ParInode *Inode
Dentry *Dentry
TxInfo *proto.TransactionInfo
}
@@ -376,7 +376,7 @@ func NewTxDentry(parentID uint64, name string, ino uint64, mode uint32, parInode
}
txDentry := &TxDentry{
- //ParInode: parInode,
+ // ParInode: parInode,
Dentry: dentry,
TxInfo: txInfo,
}
@@ -763,7 +763,7 @@ func (d *Dentry) UnmarshalValue(val []byte) (err error) {
}
for i := 0; i < int(verCnt); i++ {
- //todo(leonchang) name and parentid should be removed to reduce space
+ // todo(leonchang) name and parentid should be removed to reduce space
den := &Dentry{
Name: d.Name,
ParentId: d.ParentId,
diff --git a/metanode/extend.go b/metanode/extend.go
index 0f89b7879..fc2693de2 100644
--- a/metanode/extend.go
+++ b/metanode/extend.go
@@ -27,6 +27,7 @@ type ExtentVal struct {
dataMap map[string][]byte
verSeq uint64
}
+
type Extend struct {
inode uint64
dataMap map[string][]byte
@@ -82,24 +83,24 @@ func NewExtend(inode uint64) *Extend {
func NewExtendFromBytes(raw []byte) (*Extend, error) {
var err error
- var buffer = bytes.NewBuffer(raw)
+ buffer := bytes.NewBuffer(raw)
// decode inode
var inode uint64
if inode, err = binary.ReadUvarint(buffer); err != nil {
return nil, err
}
- var ext = NewExtend(inode)
+ ext := NewExtend(inode)
// decode number of key-value pairs
var numKV uint64
if numKV, err = binary.ReadUvarint(buffer); err != nil {
return nil, err
}
- var readBytes = func() ([]byte, error) {
+ readBytes := func() ([]byte, error) {
var length uint64
if length, err = binary.ReadUvarint(buffer); err != nil {
return nil, err
}
- var data = make([]byte, length)
+ data := make([]byte, length)
if _, err = buffer.Read(data); err != nil {
return nil, err
}
@@ -223,8 +224,8 @@ func (e *Extend) Bytes() ([]byte, error) {
e.mu.RLock()
defer e.mu.RUnlock()
var n int
- var tmp = make([]byte, binary.MaxVarintLen64)
- var buffer = bytes.NewBuffer(nil)
+ tmp := make([]byte, binary.MaxVarintLen64)
+ buffer := bytes.NewBuffer(nil)
// write inode with varint codec
n = binary.PutUvarint(tmp, e.inode)
if _, err = buffer.Write(tmp[:n]); err != nil {
@@ -236,7 +237,7 @@ func (e *Extend) Bytes() ([]byte, error) {
return nil, err
}
// write key-value paris
- var writeBytes = func(val []byte) error {
+ writeBytes := func(val []byte) error {
n = binary.PutUvarint(tmp, uint64(len(val)))
if _, err = buffer.Write(tmp[:n]); err != nil {
return err
diff --git a/metanode/extend_test.go b/metanode/extend_test.go
index dc33aab85..83dcf7c0a 100644
--- a/metanode/extend_test.go
+++ b/metanode/extend_test.go
@@ -27,7 +27,7 @@ func TestExtend_Bytes(t *testing.T) {
var err error
const numSamples = 100
- var random = rand.New(rand.NewSource(time.Now().UnixNano()))
+ random := rand.New(rand.NewSource(time.Now().UnixNano()))
extends := make([]*Extend, numSamples)
for i := 0; i < numSamples; i++ {
@@ -53,5 +53,4 @@ func TestExtend_Bytes(t *testing.T) {
t.Fatalf("result mismatch")
}
}
-
}
diff --git a/metanode/inode.go b/metanode/inode.go
index ddc251193..9d47116ab 100644
--- a/metanode/inode.go
+++ b/metanode/inode.go
@@ -671,7 +671,7 @@ func (i *Inode) MarshalInodeValue(buff *bytes.Buffer) {
}
i.Reserved |= V3EnableSnapInodeFlag
- //log.LogInfof("action[MarshalInodeValue] inode %v Reserved %v", i.Inode, i.Reserved)
+ // log.LogInfof("action[MarshalInodeValue] inode %v Reserved %v", i.Inode, i.Reserved)
if err = binary.Write(buff, binary.BigEndian, &i.Reserved); err != nil {
panic(err)
}
@@ -738,7 +738,6 @@ func (i *Inode) MarshalValue() (val []byte) {
// UnmarshalValue unmarshals the value from bytes.
func (i *Inode) UnmarshalInodeValue(buff *bytes.Buffer) (err error) {
-
if err = binary.Read(buff, binary.BigEndian, &i.Type); err != nil {
return
}
@@ -1441,7 +1440,7 @@ func (i *Inode) getLastestVer(reqVerSeq uint64, verlist *proto.VolVersionInfoLis
func (i *Inode) CreateUnlinkVer(mpVer uint64, nVer uint64) {
log.LogDebugf("action[CreateUnlinkVer] inode %v mpVer %v nVer %v", i.Inode, mpVer, nVer)
- //inode copy not include multi ver array
+ // inode copy not include multi ver array
ino := i.CopyDirectly().(*Inode)
ino.setVer(nVer)
@@ -1467,7 +1466,7 @@ func (i *Inode) CreateUnlinkVer(mpVer uint64, nVer uint64) {
}
func (i *Inode) CreateVer(ver uint64) {
- //inode copy not include multi ver array
+ // inode copy not include multi ver array
ino := i.CopyDirectly().(*Inode)
ino.Extents = NewSortedExtents()
ino.ObjExtents = NewSortedObjExtents()
@@ -1484,6 +1483,7 @@ func (i *Inode) CreateVer(ver uint64) {
}
i.multiSnap.multiVersions = append([]*Inode{ino}, i.multiSnap.multiVersions...)
}
+
func (i *Inode) buildMultiSnap() {
if i.multiSnap == nil {
i.multiSnap = &InodeMultiSnap{}
@@ -1494,7 +1494,6 @@ func (i *Inode) buildMultiSnap() {
}
func (i *Inode) SplitExtentWithCheck(param *AppendExtParam) (delExtents []proto.ExtentKey, status uint8) {
-
var err error
param.ek.SetSeq(param.mpVer)
log.LogDebugf("action[SplitExtentWithCheck] mpId[%v].inode %v,ek %v,hist len %v", param.mpId, i.Inode, param.ek, i.getLayerLen())
diff --git a/metanode/manager.go b/metanode/manager.go
index 8390a8c27..2b4616faf 100644
--- a/metanode/manager.go
+++ b/metanode/manager.go
@@ -38,8 +38,10 @@ import (
"github.com/cubefs/cubefs/util/log"
)
-const partitionPrefix = "partition_"
-const ExpiredPartitionPrefix = "expired_"
+const (
+ partitionPrefix = "partition_"
+ ExpiredPartitionPrefix = "expired_"
+)
const sampleDuration = 1 * time.Second
@@ -47,7 +49,7 @@ const sampleDuration = 1 * time.Second
type MetadataManager interface {
Start() error
Stop()
- //CreatePartition(id string, start, end uint64, peers []proto.Peer) error
+ // CreatePartition(id string, start, end uint64, peers []proto.Peer) error
HandleMetadataOperation(conn net.Conn, p *Packet, remoteAddr string) error
GetPartition(id uint64) (MetaPartition, error)
GetLeaderPartitions() map[uint64]MetaPartition
@@ -87,12 +89,11 @@ type metadataManager struct {
maxQuotaGoroutineNum int32
cpuUtil atomicutil.Float64
stopC chan struct{}
- volUpdating *sync.Map //map[string]*verOp2Phase
+ volUpdating *sync.Map // map[string]*verOp2Phase
verUpdateChan chan string
}
func (m *metadataManager) getPacketLabels(p *Packet) (labels map[string]string) {
-
labels = make(map[string]string)
labels[exporter.Op] = p.GetOpMsg()
labels[exporter.PartId] = ""
@@ -412,7 +413,7 @@ func (m *metadataManager) loadPartitions() (err error) {
// Check metadataDir directory
fileInfo, err := os.Stat(m.rootDir)
if err != nil {
- os.MkdirAll(m.rootDir, 0755)
+ os.MkdirAll(m.rootDir, 0o755)
err = nil
return
}
@@ -539,7 +540,6 @@ func (m *metadataManager) detachPartition(id uint64) (err error) {
}
func (m *metadataManager) createPartition(request *proto.CreateMetaPartitionRequest) (err error) {
-
partitionId := fmt.Sprintf("%d", request.PartitionID)
log.LogInfof("start create meta Partition, partition %s", partitionId)
diff --git a/metanode/manager_op.go b/metanode/manager_op.go
index d26923cd1..19c8831d6 100644
--- a/metanode/manager_op.go
+++ b/metanode/manager_op.go
@@ -977,8 +977,8 @@ func (m *metadataManager) opReadDirLimit(conn net.Conn, p *Packet,
}
func (m *metadataManager) opMetaInodeGet(conn net.Conn, p *Packet,
- remoteAddr string) (err error) {
-
+ remoteAddr string) (err error,
+) {
req := &InodeGetReq{}
if err = json.Unmarshal(p.Data, req); err != nil {
p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error()))
@@ -1011,8 +1011,8 @@ func (m *metadataManager) opMetaInodeGet(conn net.Conn, p *Packet,
if value, ok := m.volUpdating.Load(req.VolName); ok {
ver2Phase := value.(*verOp2Phase)
if ver2Phase.verSeq > req.VerSeq {
- //reuse ExtentType to identify flag of version inconsistent between metanode and client
- //will resp to client and make client update all streamer's extent and it's verSeq
+ // reuse ExtentType to identify flag of version inconsistent between metanode and client
+ // will resp to client and make client update all streamer's extent and it's verSeq
p.ExtentType |= proto.MultiVersionFlag
p.VerSeq = ver2Phase.verSeq
}
@@ -2375,9 +2375,7 @@ func (m *metadataManager) opMetaGetUniqID(conn net.Conn, p *Packet,
}
func (m *metadataManager) prepareCreateVersion(req *proto.MultiVersionOpRequest) (err error, opAagin bool) {
- var (
- ver2Phase *verOp2Phase
- )
+ var ver2Phase *verOp2Phase
if value, ok := m.volUpdating.Load(req.VolumeID); ok {
ver2Phase = value.(*verOp2Phase)
if req.VerSeq < ver2Phase.verSeq {
@@ -2403,9 +2401,7 @@ func (m *metadataManager) prepareCreateVersion(req *proto.MultiVersionOpRequest)
}
func (m *metadataManager) checkVolVerList() (err error) {
- var (
- volumeArr = make(map[string]bool)
- )
+ volumeArr := make(map[string]bool)
log.LogDebugf("checkVolVerList start")
m.Range(true, func(id uint64, partition MetaPartition) bool {
@@ -2414,7 +2410,7 @@ func (m *metadataManager) checkVolVerList() (err error) {
})
for volName := range volumeArr {
- var mpsVerlist = make(map[uint64]*proto.VolVersionInfoList)
+ mpsVerlist := make(map[uint64]*proto.VolVersionInfoList)
// need get first or else the mp verlist may be change in the follower process
m.Range(true, func(id uint64, partition MetaPartition) bool {
if partition.GetVolName() != volName {
@@ -2452,7 +2448,6 @@ func (m *metadataManager) checkVolVerList() (err error) {
}
func (m *metadataManager) commitCreateVersion(VolumeID string, VerSeq uint64, Op uint8, synchronize bool) (err error) {
-
log.LogWarnf("action[commitCreateVersion] volume %v seq %v", VolumeID, VerSeq)
var wg sync.WaitGroup
// wg.Add(len(m.partitions))
@@ -2576,7 +2571,6 @@ func (m *metadataManager) checkMultiVersionStatus(mp MetaPartition, p *Packet) (
}
func (m *metadataManager) checkAndPromoteVersion(volName string) (err error) {
-
log.LogInfof("action[checkmultiSnap.multiVersionstatus] volumeName %v", volName)
var info *proto.VolumeVerInfo
if value, ok := m.volUpdating.Load(volName); ok {
diff --git a/metanode/manager_proxy.go b/metanode/manager_proxy.go
index 6810042b6..a2344b0a6 100644
--- a/metanode/manager_proxy.go
+++ b/metanode/manager_proxy.go
@@ -27,9 +27,7 @@ const (
NoClosedConnect = false
)
-var (
- ErrForbiddenMetaPartition = errors.New("meta partition is forbidden")
-)
+var ErrForbiddenMetaPartition = errors.New("meta partition is forbidden")
func (m *metadataManager) IsForbiddenOp(mp MetaPartition, reqOp uint8) bool {
if !mp.IsForbidden() {
@@ -77,7 +75,7 @@ func (m *metadataManager) IsForbiddenOp(mp MetaPartition, reqOp uint8) bool {
proto.OpAddMultipartPart,
proto.OpRemoveMultipart,
proto.OpCreateMultipart,
- //quota
+ // quota
proto.OpMetaBatchSetInodeQuota,
proto.OpMetaBatchDeleteInodeQuota:
diff --git a/metanode/manager_resp.go b/metanode/manager_resp.go
index bd9450c61..96dc1f17b 100644
--- a/metanode/manager_resp.go
+++ b/metanode/manager_resp.go
@@ -18,7 +18,6 @@ import (
"net"
"github.com/cubefs/cubefs/proto"
-
"github.com/cubefs/cubefs/util/errors"
"github.com/cubefs/cubefs/util/log"
)
diff --git a/metanode/meta_quota_manager.go b/metanode/meta_quota_manager.go
index 45ce25f71..df78a1ace 100644
--- a/metanode/meta_quota_manager.go
+++ b/metanode/meta_quota_manager.go
@@ -60,9 +60,7 @@ func NewQuotaManager(volName string, mpId uint64) (mqMgr *MetaQuotaManager) {
}
func (qInode *MetaQuotaInode) Marshal() (result []byte, err error) {
- var (
- inodeBytes []byte
- )
+ var inodeBytes []byte
quotaBytes := bytes.NewBuffer(make([]byte, 0, 128))
buff := bytes.NewBuffer(make([]byte, 0, 128))
inodeBytes, err = qInode.inode.Marshal()
@@ -114,9 +112,7 @@ func (qInode *MetaQuotaInode) Unmarshal(raw []byte) (err error) {
}
func (qInode *TxMetaQuotaInode) Marshal() (result []byte, err error) {
- var (
- inodeBytes []byte
- )
+ var inodeBytes []byte
quotaBytes := bytes.NewBuffer(make([]byte, 0, 128))
buff := bytes.NewBuffer(make([]byte, 0, 128))
inodeBytes, err = qInode.txinode.Marshal()
diff --git a/metanode/metanode.go b/metanode/metanode.go
index f4d7558c6..2481cf7c7 100644
--- a/metanode/metanode.go
+++ b/metanode/metanode.go
@@ -15,22 +15,20 @@
package metanode
import (
+ "fmt"
syslog "log"
"os"
+ "strconv"
"strings"
"sync/atomic"
"time"
"github.com/xtaci/smux"
- masterSDK "github.com/cubefs/cubefs/sdk/master"
-
- "fmt"
- "strconv"
-
"github.com/cubefs/cubefs/cmd/common"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/raftstore"
+ masterSDK "github.com/cubefs/cubefs/sdk/master"
"github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/config"
"github.com/cubefs/cubefs/util/errors"
@@ -40,7 +38,7 @@ import (
var (
clusterInfo *proto.ClusterInfo
- //masterClient *masterSDK.MasterClient
+ // masterClient *masterSDK.MasterClient
masterClient *masterSDK.MasterCLientWithResolver
configTotalMem uint64
serverPort string
@@ -64,7 +62,7 @@ type MetaNode struct {
raftHeartbeatPort string
raftReplicatePort string
raftRetainLogs uint64
- raftSyncSnapFormatVersion uint32 //format version of snapshot that raft leader sent to follower
+ raftSyncSnapFormatVersion uint32 // format version of snapshot that raft leader sent to follower
zoneName string
httpStopC chan uint8
smuxStopC chan uint8
@@ -292,7 +290,7 @@ func (m *MetaNode) parseConfig(cfg *config.Config) (err error) {
RaftHeartbetPort: m.raftHeartbeatPort,
RaftReplicaPort: m.raftReplicatePort,
}
- var ok = false
+ ok := false
if ok, err = config.CheckOrStoreConstCfg(m.metadataDir, config.DefaultConstConfigFile, &constCfg); !ok {
log.LogErrorf("constCfg check failed %v %v %v %v", m.metadataDir, config.DefaultConstConfigFile, constCfg, err)
return fmt.Errorf("constCfg check failed %v %v %v %v", m.metadataDir, config.DefaultConstConfigFile, constCfg, err)
@@ -325,7 +323,7 @@ func (m *MetaNode) parseConfig(cfg *config.Config) (err error) {
updateInterval = DefaultNameResolveInterval
}
- //masterClient = masterSDK.NewMasterClient(masters, false)
+ // masterClient = masterSDK.NewMasterClient(masters, false)
masterClient = masterSDK.NewMasterCLientWithResolver(masters, false, updateInterval)
if masterClient == nil {
err = fmt.Errorf("parseConfig: masters addrs format err[%v]", masters)
@@ -347,7 +345,7 @@ func (m *MetaNode) parseSmuxConfig(cfg *config.Config) error {
}
// SMux buffer
- var maxBuffer = cfg.GetInt64(cfgSmuxMaxBuffer)
+ maxBuffer := cfg.GetInt64(cfgSmuxMaxBuffer)
if maxBuffer > 0 {
smuxPoolCfg.MaxReceiveBuffer = int(maxBuffer)
if smuxPoolCfg.MaxStreamBuffer > int(maxBuffer) {
@@ -397,7 +395,7 @@ func (m *MetaNode) validConfig() (err error) {
func (m *MetaNode) newMetaManager() (err error) {
if _, err = os.Stat(m.metadataDir); err != nil {
- if err = os.MkdirAll(m.metadataDir, 0755); err != nil {
+ if err = os.MkdirAll(m.metadataDir, 0o755); err != nil {
return
}
}
@@ -414,7 +412,7 @@ func (m *MetaNode) newMetaManager() (err error) {
RaftHeartbetPort: m.raftHeartbeatPort,
RaftReplicaPort: m.raftReplicatePort,
}
- var ok = false
+ ok := false
if ok, err = config.CheckOrStoreConstCfg(m.metadataDir, config.DefaultConstConfigFile, &constCfg); !ok {
log.LogErrorf("constCfg check failed %v %v %v %v", m.metadataDir, config.DefaultConstConfigFile, constCfg, err)
return fmt.Errorf("constCfg check failed %v %v %v %v", m.metadataDir, config.DefaultConstConfigFile, constCfg, err)
diff --git a/metanode/metrics.go b/metanode/metrics.go
index 699199b12..d17367923 100644
--- a/metanode/metrics.go
+++ b/metanode/metrics.go
@@ -21,7 +21,7 @@ import (
"github.com/cubefs/cubefs/util/exporter"
)
-//metrics
+// metrics
const (
StatPeriod = time.Minute * time.Duration(1)
diff --git a/metanode/multi_ver_test.go b/metanode/multi_ver_test.go
index 027607793..5c8b0113c 100644
--- a/metanode/multi_ver_test.go
+++ b/metanode/multi_ver_test.go
@@ -34,9 +34,11 @@ import (
"github.com/stretchr/testify/assert"
)
-var partitionId uint64 = 10
-var manager = &metadataManager{partitions: make(map[uint64]MetaPartition), volUpdating: new(sync.Map)}
-var mp *metaPartition
+var (
+ partitionId uint64 = 10
+ manager = &metadataManager{partitions: make(map[uint64]MetaPartition), volUpdating: new(sync.Map)}
+ mp *metaPartition
+)
// PartitionId uint64 `json:"partition_id"`
// VolName string `json:"vol_name"`
@@ -163,7 +165,7 @@ func checkOffSetInSequnce(t *testing.T, eks []proto.ExtentKey) bool {
)
for idx, ext := range eks[1:] {
- //t.Logf("idx:%v ext:%v, lastFileOff %v, lastSize %v", idx, ext, lastFileOff, lastSize)
+ // t.Logf("idx:%v ext:%v, lastFileOff %v, lastSize %v", idx, ext, lastFileOff, lastSize)
if ext.FileOffset != lastFileOff+uint64(lastSize) {
t.Errorf("checkOffSetInSequnce not equal idx %v %v:(%v+%v) eks{%v}", idx, ext.FileOffset, lastFileOff, lastSize, eks)
return false
@@ -229,7 +231,6 @@ func testCreateInode(t *testing.T, mode uint32) *Inode {
}
func testCreateDentry(t *testing.T, parentId uint64, inodeId uint64, name string, mod uint32) *Dentry {
-
dentry := &Dentry{
ParentId: parentId,
Name: name,
@@ -379,7 +380,6 @@ func TestSplitKeyDeletion(t *testing.T) {
assert.True(t, testGetSplitSize(t, fileIno) == 0)
assert.True(t, testGetEkRefCnt(t, fileIno, &initExt) == 0)
-
}
func testGetlastVer() (verSeq uint64) {
@@ -404,7 +404,7 @@ func testCreateVer() (verSeq uint64) {
}
func testReadDirAll(t *testing.T, verSeq uint64, parentId uint64) (resp *ReadDirLimitResp) {
- //testPrintAllDentry(t)
+ // testPrintAllDentry(t)
t.Logf("[testReadDirAll] with seq %v parentId %v", verSeq, parentId)
req := &ReadDirLimitReq{
PartitionID: partitionId,
@@ -432,8 +432,10 @@ func testVerListRemoveVer(t *testing.T, verSeq uint64) bool {
return false
}
-var ct = uint64(time.Now().Unix())
-var seqAllArr = []uint64{0, ct, ct + 2111, ct + 10333, ct + 53456, ct + 60000, ct + 72344, ct + 234424, ct + 334424}
+var (
+ ct = uint64(time.Now().Unix())
+ seqAllArr = []uint64{0, ct, ct + 2111, ct + 10333, ct + 53456, ct + 60000, ct + 72344, ct + 234424, ct + 334424}
+)
func TestAppendList(t *testing.T) {
initMp(t)
@@ -445,7 +447,7 @@ func TestAppendList(t *testing.T) {
mp.multiVersionList.VerList = append(mp.multiVersionList.VerList, verInfo)
}
- var ino = testCreateInode(t, 0)
+ ino := testCreateInode(t, 0)
t.Logf("enter TestAppendList")
index := 5
seqArr := seqAllArr[1:index]
@@ -482,7 +484,7 @@ func TestAppendList(t *testing.T) {
//------------- split at begin -----------------------------------------
t.Logf("start split at begin")
- var splitSeq = seqAllArr[index]
+ splitSeq := seqAllArr[index]
splitKey := buildExtentKey(splitSeq, 0, 0, 128000, 10)
extents := &SortedExtents{}
extents.eks = append(extents.eks, splitKey)
@@ -580,7 +582,7 @@ func TestAppendList(t *testing.T) {
assert.True(t, len(getExtRsp.Extents) == lastTopEksLen+1)
assert.True(t, len(ino.Extents.eks) == lastTopEksLen+1)
assert.True(t, isExtEqual(ino.Extents.eks[lastTopEksLen], splitKey))
- //assert.True(t, false)
+ // assert.True(t, false)
//-------- split at the splited one -----------------------------------------------
t.Logf("start split at end")
@@ -651,7 +653,6 @@ func testPrintAllInodeInfo(t *testing.T) {
}
func testPrintInodeInfo(t *testing.T, ino *Inode) {
-
i := mp.inodeTree.Get(ino).(*Inode)
t.Logf("action[PrintAllVersionInfo] toplayer inode [%v] verSeq [%v] hist len [%v]", i, i.getVer(), i.getLayerLen())
if i.getLayerLen() == 0 {
@@ -660,7 +661,6 @@ func testPrintInodeInfo(t *testing.T, ino *Inode) {
for id, info := range i.multiSnap.multiVersions {
t.Logf("action[PrintAllVersionInfo] layer [%v] verSeq [%v] inode [%v]", id, info.getVer(), info)
}
-
}
func testDelDirSnapshotVersion(t *testing.T, verSeq uint64, dirIno *Inode, dirDentry *Dentry) {
@@ -669,7 +669,7 @@ func testDelDirSnapshotVersion(t *testing.T, verSeq uint64, dirIno *Inode, dirDe
}
rspReadDir := testReadDirAll(t, verSeq, dirIno.Inode)
- //testPrintAllDentry(t)
+ // testPrintAllDentry(t)
rDirIno := dirIno.Copy().(*Inode)
rDirIno.setVerNoCheck(verSeq)
@@ -721,7 +721,7 @@ func testDelDirSnapshotVersion(t *testing.T, verSeq uint64, dirIno *Inode, dirDe
Inode: rino.Inode,
}
log.LogDebugf("test.testDelDirSnapshotVersion: dentry param %v ", dentry)
- //testPrintAllDentry(t)
+ // testPrintAllDentry(t)
iden, st := mp.getDentry(dentry)
if st != proto.OpOk {
t.Logf("testDelDirSnapshotVersion: dentry %v return st %v", dentry, proto.ParseErrorCode(int32(st)))
@@ -740,7 +740,7 @@ func TestDentry(t *testing.T) {
initMp(t)
var denArry []*Dentry
- //err := gohook.HookMethod(mp, "submit", MockSubmitTrue, nil)
+ // err := gohook.HookMethod(mp, "submit", MockSubmitTrue, nil)
mp.config.Cursor = 1100
//--------------------build dir and it's child on different version ------------------
seq0 := testCreateVer()
@@ -867,6 +867,7 @@ func testPrintDirTree(t *testing.T, parentId uint64, path string, verSeq uint64)
}
return
}
+
func testAppendExt(t *testing.T, seq uint64, idx int, inode uint64) {
exts := buildExtents(seq, uint64(idx*1000), uint64(idx))
t.Logf("buildExtents exts[%v]", exts)
@@ -959,7 +960,7 @@ func testDeleteFile(t *testing.T, verSeq uint64, parentId uint64, child *proto.D
t.Logf("testDeleteFile seq %v %v dentry %v", verSeq, fsmDentry.getSeqFiled(), fsmDentry)
assert.True(t, nil != mp.fsmDeleteDentry(fsmDentry, false))
- var rino = &Inode{
+ rino := &Inode{
Inode: child.Inode,
Type: child.Type,
multiSnap: &InodeMultiSnap{
@@ -1006,7 +1007,7 @@ func testSnapshotDeletion(t *testing.T, topFirst bool) {
log.LogDebugf("action[TestSnapshotDeletion] start!!!!!!!!!!!")
initMp(t)
initVer()
- //err := gohook.HookMethod(mp, "submit", MockSubmitTrue, nil)
+ // err := gohook.HookMethod(mp, "submit", MockSubmitTrue, nil)
mp.config.Cursor = 1100
//--------------------build dir and it's child on different version ------------------
@@ -1126,8 +1127,8 @@ func testSnapshotDeletion(t *testing.T, topFirst bool) {
t.Logf("---------------------------------------------------------------------")
t.Logf("after deletion current layerr mp inode freeList len %v fileCnt %v dircnt %v", mp.freeList.Len(), fileCnt, dirCnt)
assert.True(t, mp.freeList.Len() == fileCnt)
- //base on 3.2.0 the dir will push to freelist, not count in in later release version
- //assert.True(t, mp.freeList.Len() == fileCnt+dirCnt)
+ // base on 3.2.0 the dir will push to freelist, not count in in later release version
+ // assert.True(t, mp.freeList.Len() == fileCnt+dirCnt)
assert.True(t, 0 == testPrintAllDentry(t))
t.Logf("---------------------------------------------------------------------")
@@ -1136,7 +1137,7 @@ func testSnapshotDeletion(t *testing.T, topFirst bool) {
t.Logf("---------------------------------------------------------------------")
testPrintAllInodeInfo(t)
t.Logf("---------------------------------------------")
- //assert.True(t, false)
+ // assert.True(t, false)
}
// create
@@ -1213,6 +1214,7 @@ func TestSplitKey(t *testing.T) {
_, invalid = NewPacketToDeleteExtent(dp, ext)
assert.True(t, invalid == false)
}
+
func NewMetaPartitionForTest() *metaPartition {
mpC := &MetaPartitionConfig{
PartitionId: PartitionIdForTest,
@@ -1250,7 +1252,8 @@ func TestCheckVerList(t *testing.T) {
[]*proto.VolVersionInfo{
{Ver: 20, Status: proto.VersionNormal},
{Ver: 30, Status: proto.VersionNormal},
- {Ver: 40, Status: proto.VersionNormal}}...)
+ {Ver: 40, Status: proto.VersionNormal},
+ }...)
masterList := &proto.VolVersionInfoList{
VerList: []*proto.VolVersionInfo{
@@ -1258,7 +1261,8 @@ func TestCheckVerList(t *testing.T) {
{Ver: 20, Status: proto.VersionNormal},
{Ver: 30, Status: proto.VersionNormal},
{Ver: 40, Status: proto.VersionNormal},
- {Ver: 50, Status: proto.VersionNormal}},
+ {Ver: 50, Status: proto.VersionNormal},
+ },
}
var verData []byte
mp.checkVerList(masterList, false)
@@ -1270,7 +1274,8 @@ func TestCheckVerList(t *testing.T) {
masterList = &proto.VolVersionInfoList{
VerList: []*proto.VolVersionInfo{
{Ver: 20, Status: proto.VersionNormal},
- {Ver: 40, Status: proto.VersionNormal}},
+ {Ver: 40, Status: proto.VersionNormal},
+ },
}
needUpdate, _ := mp.checkVerList(masterList, false)
@@ -1509,7 +1514,8 @@ func TestDelPartitionVersion(t *testing.T) {
{Ver: 20, Status: proto.VersionNormal},
{Ver: 30, Status: proto.VersionNormal},
{Ver: 40, Status: proto.VersionNormal},
- {Ver: 50, Status: proto.VersionNormal}},
+ {Ver: 50, Status: proto.VersionNormal},
+ },
}
mp.checkByMasterVerlist(mp.multiVersionList, masterList)
mp.checkVerList(masterList, true)
@@ -1561,7 +1567,8 @@ func TestGetAllVerList(t *testing.T) {
{Ver: 20, Status: proto.VersionNormal},
{Ver: 30, Status: proto.VersionNormal},
{Ver: 40, Status: proto.VersionNormal},
- {Ver: 50, Status: proto.VersionNormal}},
+ {Ver: 50, Status: proto.VersionNormal},
+ },
}
tmp := mp.multiVersionList.VerList
mp.multiVersionList.VerList = append(mp.multiVersionList.VerList[:1], mp.multiVersionList.VerList[2:]...)
diff --git a/metanode/multipart.go b/metanode/multipart.go
index 9c4ffdd56..9d71562ed 100644
--- a/metanode/multipart.go
+++ b/metanode/multipart.go
@@ -43,8 +43,8 @@ func (m *Part) Equal(o *Part) bool {
func (m Part) Bytes() ([]byte, error) {
var err error
- var buffer = bytes.NewBuffer(nil)
- var tmp = make([]byte, binary.MaxVarintLen64)
+ buffer := bytes.NewBuffer(nil)
+ tmp := make([]byte, binary.MaxVarintLen64)
var n int
// ID
n = binary.PutUvarint(tmp, uint64(m.ID))
@@ -91,7 +91,7 @@ func PartFromBytes(raw []byte) *Part {
var md5Len uint64
md5Len, n = binary.Uvarint(raw[offset:])
offset += n
- var md5Content = string(raw[offset : offset+int(md5Len)])
+ md5Content := string(raw[offset : offset+int(md5Len)])
offset += int(md5Len)
// decode size
var sizeU64 uint64
@@ -101,7 +101,7 @@ func PartFromBytes(raw []byte) *Part {
var inode uint64
inode, n = binary.Uvarint(raw[offset:])
- var muPart = &Part{
+ muPart := &Part{
ID: uint16(u64ID),
UploadTime: time.Unix(0, uploadTimeI64),
MD5: md5Content,
@@ -201,8 +201,8 @@ func (m Parts) Search(id uint16) (part *Part, found bool) {
func (m Parts) Bytes() ([]byte, error) {
var err error
var n int
- var buffer = bytes.NewBuffer(nil)
- var tmp = make([]byte, binary.MaxVarintLen64)
+ buffer := bytes.NewBuffer(nil)
+ tmp := make([]byte, binary.MaxVarintLen64)
n = binary.PutUvarint(tmp, uint64(len(m)))
if _, err = buffer.Write(tmp[:n]); err != nil {
return nil, err
@@ -231,7 +231,7 @@ func PartsFromBytes(raw []byte) Parts {
var numPartsU64 uint64
numPartsU64, n = binary.Uvarint(raw)
offset += n
- var muParts = make([]*Part, int(numPartsU64))
+ muParts := make([]*Part, int(numPartsU64))
for i := 0; i < int(numPartsU64); i++ {
var partLengthU64 uint64
partLengthU64, n = binary.Uvarint(raw[offset:])
@@ -252,13 +252,13 @@ func NewMultipartExtend() MultipartExtend {
func (me MultipartExtend) Bytes() ([]byte, error) {
var n int
var err error
- var buffer = bytes.NewBuffer(nil)
- var tmp = make([]byte, binary.MaxVarintLen64)
+ buffer := bytes.NewBuffer(nil)
+ tmp := make([]byte, binary.MaxVarintLen64)
n = binary.PutUvarint(tmp, uint64(len(me)))
if _, err = buffer.Write(tmp[:n]); err != nil {
return nil, err
}
- var marshalStr = func(src string) error {
+ marshalStr := func(src string) error {
n = binary.PutUvarint(tmp, uint64(len(src)))
if _, err = buffer.Write(tmp[:n]); err != nil {
return err
@@ -283,7 +283,7 @@ func MultipartExtendFromBytes(raw []byte) MultipartExtend {
var offset, n int
var el uint64
me := NewMultipartExtend()
- var unmarshalStr = func(data []byte) (string, int) {
+ unmarshalStr := func(data []byte) (string, int) {
var n int
var lengthU64 uint64
lengthU64, n = binary.Uvarint(data)
@@ -365,11 +365,11 @@ func (m *Multipart) Parts() []*Part {
func (m *Multipart) Bytes() ([]byte, error) {
var n int
- var buffer = bytes.NewBuffer(nil)
+ buffer := bytes.NewBuffer(nil)
var err error
tmp := make([]byte, binary.MaxVarintLen64)
// marshal id
- var marshalStr = func(src string) error {
+ marshalStr := func(src string) error {
n = binary.PutUvarint(tmp, uint64(len(src)))
if _, err = buffer.Write(tmp[:n]); err != nil {
return err
@@ -420,7 +420,7 @@ func (m *Multipart) Bytes() ([]byte, error) {
}
func MultipartFromBytes(raw []byte) *Multipart {
- var unmarshalStr = func(data []byte) (string, int) {
+ unmarshalStr := func(data []byte) (string, int) {
var n int
var lengthU64 uint64
lengthU64, n = binary.Uvarint(data)
@@ -443,15 +443,15 @@ func MultipartFromBytes(raw []byte) *Multipart {
var partsLengthU64 uint64
partsLengthU64, n = binary.Uvarint(raw[offset:])
offset += n
- var parts = PartsFromBytes(raw[offset : offset+int(partsLengthU64)])
+ parts := PartsFromBytes(raw[offset : offset+int(partsLengthU64)])
offset += int(partsLengthU64)
// decode multipart extend
var extendLengthU64 uint64
extendLengthU64, n = binary.Uvarint(raw[offset:])
offset += n
- var me = MultipartExtendFromBytes(raw[offset : offset+int(extendLengthU64)])
+ me := MultipartExtendFromBytes(raw[offset : offset+int(extendLengthU64)])
- var muSession = &Multipart{
+ muSession := &Multipart{
id: id,
key: key,
initTime: time.Unix(0, initTimeI64),
diff --git a/metanode/multipart_test.go b/metanode/multipart_test.go
index cfa545a89..db2000301 100644
--- a/metanode/multipart_test.go
+++ b/metanode/multipart_test.go
@@ -52,8 +52,8 @@ func TestMUPart_Bytes(t *testing.T) {
func TestMUParts_Bytes(t *testing.T) {
var err error
- var random = rand.New(rand.NewSource(time.Now().UnixNano()))
- var parts1 = PartsFromBytes(nil)
+ random := rand.New(rand.NewSource(time.Now().UnixNano()))
+ parts1 := PartsFromBytes(nil)
for i := 0; i < 100; i++ {
part := &Part{
ID: uint16(i),
@@ -77,8 +77,8 @@ func TestMUParts_Bytes(t *testing.T) {
}
func TestMUParts_Modify(t *testing.T) {
- var random = rand.New(rand.NewSource(time.Now().UnixNano()))
- var parts = PartsFromBytes(nil)
+ random := rand.New(rand.NewSource(time.Now().UnixNano()))
+ parts := PartsFromBytes(nil)
for i := 0; i < 100; i++ {
part := &Part{
ID: uint16(i),
@@ -123,8 +123,8 @@ func TestMUParts_Modify(t *testing.T) {
func TestMUSession_Bytes(t *testing.T) {
var err error
- var random = rand.New(rand.NewSource(time.Now().UnixNano()))
- var session1 = MultipartFromBytes(nil)
+ random := rand.New(rand.NewSource(time.Now().UnixNano()))
+ session1 := MultipartFromBytes(nil)
me := NewMultipartExtend()
me["oss::tag"] = "name=123&age456"
diff --git a/metanode/nodeinfo.go b/metanode/nodeinfo.go
index 4e7ea8185..8688b30a7 100644
--- a/metanode/nodeinfo.go
+++ b/metanode/nodeinfo.go
@@ -5,7 +5,6 @@ import (
"time"
"github.com/cubefs/cubefs/proto"
-
"github.com/cubefs/cubefs/util/log"
)
@@ -72,7 +71,7 @@ func (m *MetaNode) stopUpdateNodeInfo() {
}
func (m *MetaNode) updateNodeInfo() {
- //clusterInfo, err := getClusterInfo()
+ // clusterInfo, err := getClusterInfo()
clusterInfo, err := masterClient.AdminAPI().GetClusterInfo()
if err != nil {
log.LogErrorf("[updateNodeInfo] %s", err.Error())
@@ -90,5 +89,5 @@ func (m *MetaNode) updateNodeInfo() {
log.LogInfof("updateNodeInfo: DirChildrenNumLimit(%v)", clusterInfo.DirChildrenNumLimit)
}
- //updateDirChildrenNumLimit(clusterInfo.DirChildrenNumLimit)
+ // updateDirChildrenNumLimit(clusterInfo.DirChildrenNumLimit)
}
diff --git a/metanode/packet.go b/metanode/packet.go
index 977ce4437..ffc4bbdac 100644
--- a/metanode/packet.go
+++ b/metanode/packet.go
@@ -16,6 +16,7 @@ package metanode
import (
"encoding/json"
+
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/storage"
"github.com/cubefs/cubefs/util"
diff --git a/metanode/partition.go b/metanode/partition.go
index 8e569b89a..a4961515e 100644
--- a/metanode/partition.go
+++ b/metanode/partition.go
@@ -18,7 +18,6 @@ import (
"bytes"
"encoding/json"
"fmt"
- "io/ioutil"
"math"
"math/rand"
"os"
@@ -63,6 +62,7 @@ type sortedPeers []proto.Peer
func (sp sortedPeers) Len() int {
return len(sp)
}
+
func (sp sortedPeers) Less(i, j int) bool {
return sp[i].ID < sp[j].ID
}
@@ -455,7 +455,6 @@ func (uMgr *UidManager) accumRebuildFin(rebuild bool) {
uMgr.accumDelta = uMgr.accumRebuildDelta
uMgr.accumRebuildBase = new(sync.Map)
uMgr.accumRebuildDelta = new(sync.Map)
-
}
func (uMgr *UidManager) accumInoUidSize(ino *Inode, accum *sync.Map) {
@@ -540,9 +539,11 @@ func (mp *metaPartition) SetEnableAuditLog(status bool) {
func (mp *metaPartition) acucumRebuildStart() bool {
return mp.uidManager.accumRebuildStart()
}
+
func (mp *metaPartition) acucumRebuildFin(rebuild bool) {
mp.uidManager.accumRebuildFin(rebuild)
}
+
func (mp *metaPartition) acucumUidSizeByStore(ino *Inode) {
mp.uidManager.accumInoUidSize(ino, mp.uidManager.accumRebuildBase)
}
@@ -720,9 +721,7 @@ func (mp *metaPartition) onStart(isCreate bool) (err error) {
return
}
- var (
- volumeInfo *proto.SimpleVolView
- )
+ var volumeInfo *proto.SimpleVolView
if volumeInfo, err = masterClient.AdminAPI().GetVolumeSimpleInfo(mp.config.VolName); err != nil {
log.LogErrorf("action[onStart] GetVolumeSimpleInfo err[%v]", err)
return
@@ -838,7 +837,7 @@ func (mp *metaPartition) startRaft() (err error) {
func (mp *metaPartition) stopRaft() {
if mp.raftPartition != nil {
// TODO Unhandled errors
- //mp.raftPartition.Stop()
+ // mp.raftPartition.Stop()
}
return
}
@@ -987,7 +986,7 @@ func (mp *metaPartition) RenameStaleMetadata() (err error) {
}
func (mp *metaPartition) parseCrcFromFile() ([]uint32, error) {
- data, err := ioutil.ReadFile(path.Join(path.Join(mp.config.RootDir, snapshotDir), SnapshotSign))
+ data, err := os.ReadFile(path.Join(path.Join(mp.config.RootDir, snapshotDir), SnapshotSign))
if err != nil {
return nil, err
}
@@ -1019,10 +1018,10 @@ func (mp *metaPartition) LoadSnapshot(snapshotPath string) (err error) {
return err
}
- var loadFuncs = []func(rootDir string, crc uint32) error{
+ loadFuncs := []func(rootDir string, crc uint32) error{
mp.loadInode,
mp.loadDentry,
- nil, //loading quota info from extend requires mp.loadInode() has been completed, so skip mp.loadExtend() here
+ nil, // loading quota info from extend requires mp.loadInode() has been completed, so skip mp.loadExtend() here
mp.loadMultipart,
}
@@ -1032,7 +1031,7 @@ func (mp *metaPartition) LoadSnapshot(snapshotPath string) (err error) {
return ErrSnapshotCrcMismatch
}
- //handle compatibility in upgrade scenarios
+ // handle compatibility in upgrade scenarios
needLoadTxStuff := false
needLoadUniqStuff := false
if crc_count >= CRC_COUNT_TX_STUFF {
@@ -1144,7 +1143,7 @@ func (mp *metaPartition) store(sm *storeMsg) (err error) {
os.RemoveAll(tmpDir)
}
err = nil
- if err = os.MkdirAll(tmpDir, 0775); err != nil {
+ if err = os.MkdirAll(tmpDir, 0o775); err != nil {
return
}
@@ -1154,8 +1153,8 @@ func (mp *metaPartition) store(sm *storeMsg) (err error) {
os.RemoveAll(tmpDir)
}
}()
- var crcBuffer = bytes.NewBuffer(make([]byte, 0, 16))
- var storeFuncs = []func(dir string, sm *storeMsg) (uint32, error){
+ crcBuffer := bytes.NewBuffer(make([]byte, 0, 16))
+ storeFuncs := []func(dir string, sm *storeMsg) (uint32, error){
mp.storeInode,
mp.storeDentry,
mp.storeExtend,
@@ -1188,7 +1187,7 @@ func (mp *metaPartition) store(sm *storeMsg) (err error) {
}
// write crc to file
- if err = ioutil.WriteFile(path.Join(tmpDir, SnapshotSign), crcBuffer.Bytes(), 0775); err != nil {
+ if err = os.WriteFile(path.Join(tmpDir, SnapshotSign), crcBuffer.Bytes(), 0o775); err != nil {
return
}
snapshotDir := path.Join(mp.config.RootDir, snapshotDir)
@@ -1396,7 +1395,7 @@ func (mp *metaPartition) multiVersionTTLWork(dur time.Duration) {
case <-ttl.C:
log.LogDebugf("[multiVersionTTLWork] begin cache ttl, mp[%v]", mp.config.PartitionId)
mp.multiVersionList.RWLock.RLock()
- var volVersionInfoList = &proto.VolVersionInfoList{
+ volVersionInfoList := &proto.VolVersionInfoList{
TemporaryVerMap: make(map[uint64]*proto.VolVersionInfo),
}
copy(volVersionInfoList.VerList, mp.multiVersionList.VerList)
@@ -1718,7 +1717,7 @@ func (mp *metaPartition) storeSnapshotFiles() (err error) {
}
func (mp *metaPartition) startCheckerEvict() {
- var timer = time.NewTimer(opCheckerInterval)
+ timer := time.NewTimer(opCheckerInterval)
for {
select {
case <-timer.C:
diff --git a/metanode/partition_delete_extents.go b/metanode/partition_delete_extents.go
index cf2cc7184..342a64e0a 100644
--- a/metanode/partition_delete_extents.go
+++ b/metanode/partition_delete_extents.go
@@ -52,7 +52,7 @@ func (mp *metaPartition) startToDeleteExtents() {
func (mp *metaPartition) createExtentDeleteFile(prefix string, idx int64, fileList *synclist.SyncList) (fp *os.File, fileName string, fileSize int64, err error) {
fileName = fmt.Sprintf("%s_%d", prefix, idx)
fp, err = os.OpenFile(path.Join(mp.config.RootDir, fileName),
- os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
+ os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644)
if err != nil {
log.LogErrorf("[metaPartition] createExtentDeletFile openFile %v %v error %v", mp.config.RootDir, fileName, err)
return
@@ -65,7 +65,7 @@ func (mp *metaPartition) createExtentDeleteFile(prefix string, idx int64, fileLi
return
}
-//append delete extents from extDelCh to EXTENT_DEL_N files
+// append delete extents from extDelCh to EXTENT_DEL_N files
func (mp *metaPartition) appendDelExtentsToFile(fileList *synclist.SyncList) {
defer func() {
if r := recover(); r != nil {
@@ -98,7 +98,7 @@ LOOP:
fileName = lastItem.Value.(string)
}
if lastItem == nil || !strings.HasPrefix(fileName, prefixDelExtentV2) {
- //if no exist EXTENT_DEL_*, create one
+ // if no exist EXTENT_DEL_*, create one
log.LogDebugf("action[appendDelExtentsToFile] verseq %v", mp.verSeq)
fp, fileName, fileSize, err = mp.createExtentDeleteFile(prefixDelExtentV2, idx, fileList)
log.LogDebugf("action[appendDelExtentsToFile] verseq %v fileName %v", mp.verSeq, fileName)
@@ -106,9 +106,9 @@ LOOP:
panic(err)
}
} else {
- //exist, open last file
+ // exist, open last file
fp, err = os.OpenFile(path.Join(mp.config.RootDir, fileName),
- os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
+ os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o644)
if err != nil {
panic(err)
}
@@ -206,24 +206,24 @@ func (mp *metaPartition) deleteExtentsFromList(fileList *synclist.SyncList) {
fileList.Remove(element)
goto LOOP
}
- //if not leader, ignore delete
+ // if not leader, ignore delete
if _, ok := mp.IsLeader(); !ok {
log.LogDebugf("[deleteExtentsFromList] partitionId=%d, "+
"not raft leader,please ignore", mp.config.PartitionId)
continue
}
- //leader do delete extent for EXTENT_DEL_* file
+ // leader do delete extent for EXTENT_DEL_* file
// read delete extents from file
buf := make([]byte, MB)
- fp, err := os.OpenFile(file, os.O_RDWR, 0644)
+ fp, err := os.OpenFile(file, os.O_RDWR, 0o644)
if err != nil {
log.LogErrorf("[deleteExtentsFromList] vol %v mp %v openFile %v error: %v", mp.GetVolName(), mp.config.PartitionId, file, err)
fileList.Remove(element)
goto LOOP
}
- //get delete extents cursor at file header 8 bytes
+ // get delete extents cursor at file header 8 bytes
if _, err = fp.ReadAt(buf[:8], 0); err != nil {
log.LogWarnf("[deleteExtentsFromList] partitionId=%d, "+
"read cursor least 8bytes, retry later", mp.config.PartitionId)
@@ -257,7 +257,7 @@ func (mp *metaPartition) deleteExtentsFromList(fileList *synclist.SyncList) {
}
buf = buf[:size]
}
- //read extents from cursor
+ // read extents from cursor
rLen, err := fp.ReadAt(buf, int64(cursor))
// TODO Unhandled errors
fp.Close()
@@ -335,7 +335,7 @@ func (mp *metaPartition) deleteExtentsFromList(fileList *synclist.SyncList) {
panic(err)
}
} else {
- //ek for del no need to get version
+ // ek for del no need to get version
if err = ek.UnmarshalBinary(buff, false); err != nil {
panic(err)
}
diff --git a/metanode/partition_file_stats.go b/metanode/partition_file_stats.go
index 4b0295490..bb1bd12fb 100644
--- a/metanode/partition_file_stats.go
+++ b/metanode/partition_file_stats.go
@@ -2,9 +2,10 @@ package metanode
import (
"fmt"
+ "time"
+
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/exporter"
- "time"
)
type FileSizeRange uint32
diff --git a/metanode/partition_free_list.go b/metanode/partition_free_list.go
index 8bd007a52..c3851da33 100644
--- a/metanode/partition_free_list.go
+++ b/metanode/partition_free_list.go
@@ -23,9 +23,8 @@ import (
"sync"
"time"
- "github.com/cubefs/cubefs/util"
-
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/errors"
"github.com/cubefs/cubefs/util/log"
)
@@ -35,7 +34,7 @@ const (
UpdateVolTicket = 2 * time.Minute
BatchCounts = 128
OpenRWAppendOpt = os.O_CREATE | os.O_RDWR | os.O_APPEND
- TempFileValidTime = 86400 //units: sec
+ TempFileValidTime = 86400 // units: sec
DeleteInodeFileExtension = "INODE_DEL"
DeleteWorkerCnt = 10
InodeNLink0DelayDeleteSeconds = 24 * 3600
@@ -43,7 +42,7 @@ const (
func (mp *metaPartition) startFreeList() (err error) {
if mp.delInodeFp, err = os.OpenFile(path.Join(mp.config.RootDir,
- DeleteInodeFileExtension), OpenRWAppendOpt, 0644); err != nil {
+ DeleteInodeFileExtension), OpenRWAppendOpt, 0o644); err != nil {
return
}
@@ -77,7 +76,7 @@ func (mp *metaPartition) updateVolView(convert func(view *proto.DataPartitionsVi
func (mp *metaPartition) updateVolWorker() {
t := time.NewTicker(UpdateVolTicket)
- var convert = func(view *proto.DataPartitionsView) *DataPartitionsView {
+ convert := func(view *proto.DataPartitionsView) *DataPartitionsView {
newView := &DataPartitionsView{
DataPartitions: make([]*DataPartition, len(view.DataPartitions)),
}
@@ -134,7 +133,7 @@ func (mp *metaPartition) deleteWorker() {
continue
}
- //add sleep time value
+ // add sleep time value
DeleteWorkerSleepMs()
isForceDeleted := sleepCnt%MaxSleepCnt == 0
@@ -159,7 +158,7 @@ func (mp *metaPartition) deleteWorker() {
break
}
- //check inode nlink == 0 and deleteMarkFlag unset
+ // check inode nlink == 0 and deleteMarkFlag unset
if inode, ok := mp.inodeTree.Get(&Inode{Inode: ino}).(*Inode); ok {
inTx, _ := mp.txProcessor.txResource.isInodeInTransction(inode)
if inode.ShouldDelayDelete() || inTx {
@@ -172,7 +171,7 @@ func (mp *metaPartition) deleteWorker() {
buffSlice = append(buffSlice, ino)
}
- //delay
+ // delay
for _, delayDeleteIno := range delayDeleteInos {
mp.freeList.Push(delayDeleteIno)
}
@@ -195,7 +194,7 @@ func (mp *metaPartition) batchDeleteExtentsByPartition(partitionDeleteExtents ma
lock sync.Mutex
)
- //wait all Partition do BatchDeleteExtents finish
+ // wait all Partition do BatchDeleteExtents finish
for partitionID, extents := range partitionDeleteExtents {
log.LogDebugf("batchDeleteExtentsByPartition partitionID %v extents %v", partitionID, extents)
wg.Add(1)
@@ -209,7 +208,7 @@ func (mp *metaPartition) batchDeleteExtentsByPartition(partitionDeleteExtents ma
}
wg.Wait()
- //range AllNode,find all Extents delete success on inode,it must to be append shouldCommit
+ // range AllNode,find all Extents delete success on inode,it must to be append shouldCommit
for i := 0; i < len(allInodes); i++ {
successDeleteExtentCnt := 0
inode := allInodes[i]
diff --git a/metanode/partition_fsm.go b/metanode/partition_fsm.go
index 60fd4fc60..1e82523c0 100644
--- a/metanode/partition_fsm.go
+++ b/metanode/partition_fsm.go
@@ -20,7 +20,6 @@ import (
"errors"
"fmt"
"io"
- "io/ioutil"
"math"
"net"
"os"
@@ -409,7 +408,7 @@ func (mp *metaPartition) Apply(command []byte, index uint64) (resp interface{},
}
resp = mp.fsmTxUnlinkInode(txIno)
case opFSMTxUpdateDentry:
- //txDen := NewTxDentry(0, "", 0, 0, nil)
+ // txDen := NewTxDentry(0, "", 0, 0, nil)
txUpdateDen := NewTxUpdateDentry(nil, nil, nil)
if err = txUpdateDen.Unmarshal(msg.V); err != nil {
return
@@ -583,7 +582,7 @@ func (mp *metaPartition) ApplyMemberChange(confChange *raftproto.ConfChange, ind
}
updated, err = mp.confRemoveNode(req, index)
case raftproto.ConfUpdateNode:
- //updated, err = mp.confUpdateNode(req, index)
+ // updated, err = mp.confUpdateNode(req, index)
default:
// do nothing
}
@@ -661,7 +660,6 @@ func (mp *metaPartition) ApplySnapshot(peers []raftproto.Peer, iter raftproto.Sn
return
}
}
-
}
defer func() {
@@ -729,7 +727,7 @@ func (mp *metaPartition) ApplySnapshot(peers []raftproto.Peer, iter raftproto.Sn
snap := NewMetaItem(0, nil, nil)
if err = snap.UnmarshalBinary(data); err != nil {
if index == 0 {
- //for compatibility, if leader send snapshot format int version_0, index=0 is applyId in uint64 and
+ // for compatibility, if leader send snapshot format int version_0, index=0 is applyId in uint64 and
// will cause snap.UnmarshalBinary err, then just skip index=0 and continue with the other fields
log.LogInfof("ApplySnapshot: snap.UnmarshalBinary failed in index=0, partitionID(%v), assuming snapshot format version_0",
mp.config.PartitionId)
@@ -807,7 +805,7 @@ func (mp *metaPartition) ApplySnapshot(peers []raftproto.Peer, iter raftproto.Sn
log.LogDebugf("ApplySnapshot: set extend attributes: partitionID(%v) extend(%v)",
mp.config.PartitionId, extend)
case opFSMCreateMultipart:
- var multipart = MultipartFromBytes(snap.V)
+ multipart := MultipartFromBytes(snap.V)
multipartTree.ReplaceOrInsert(multipart, true)
log.LogDebugf("ApplySnapshot: create multipart: partitionID(%v) multipart(%v)", mp.config.PartitionId, multipart)
case opFSMTxSnapshot:
@@ -831,7 +829,7 @@ func (mp *metaPartition) ApplySnapshot(peers []raftproto.Peer, iter raftproto.Sn
case opExtentFileSnapshot:
fileName := string(snap.K)
fileName = path.Join(mp.config.RootDir, fileName)
- if err = ioutil.WriteFile(fileName, snap.V, 0644); err != nil {
+ if err = os.WriteFile(fileName, snap.V, 0o644); err != nil {
log.LogErrorf("ApplySnapshot: write snap extent delete file fail: partitionID(%v) err(%v)",
mp.config.PartitionId, err)
}
diff --git a/metanode/partition_fsmop.go b/metanode/partition_fsmop.go
index c1463c25c..40caac85f 100644
--- a/metanode/partition_fsmop.go
+++ b/metanode/partition_fsmop.go
@@ -15,16 +15,15 @@
package metanode
import (
+ "encoding/binary"
"encoding/json"
+ "fmt"
"io/ioutil"
"os"
+ "path"
"strings"
"time"
- "encoding/binary"
- "fmt"
- "path"
-
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/log"
)
@@ -154,7 +153,6 @@ func (mp *metaPartition) confRemoveNode(req *proto.RemoveMetaPartitionRaftMember
}
func (mp *metaPartition) delOldExtentFile(buf []byte) (err error) {
-
fileName := string(buf)
log.LogWarnf("[delOldExtentFile] del extent file(%s), mp(%d)", fileName, mp.config.PartitionId)
@@ -192,7 +190,7 @@ func (mp *metaPartition) setExtentDeleteFileCursor(buf []byte) (err error) {
return
}
fp, err := os.OpenFile(path.Join(mp.config.RootDir, fileName), os.O_CREATE|os.O_RDWR,
- 0644)
+ 0o644)
if err != nil {
log.LogErrorf("[setExtentDeleteFileCursor] openFile %s failed: %s",
fileName, err.Error())
diff --git a/metanode/partition_fsmop_dentry.go b/metanode/partition_fsmop_dentry.go
index 306fb2309..11c9efe11 100644
--- a/metanode/partition_fsmop_dentry.go
+++ b/metanode/partition_fsmop_dentry.go
@@ -34,7 +34,6 @@ func NewDentryResponse() *DentryResponse {
}
func (mp *metaPartition) fsmTxCreateDentry(txDentry *TxDentry) (status uint8) {
-
done := mp.txProcessor.txManager.txInRMDone(txDentry.TxInfo.TxID)
if done {
log.LogWarnf("fsmTxCreateDentry: tx is already finish. txId %s", txDentry.TxInfo.TxID)
@@ -94,7 +93,7 @@ func (mp *metaPartition) fsmCreateDentry(dentry *Dentry,
}
if item, ok := mp.dentryTree.ReplaceOrInsert(dentry, false); !ok {
- //do not allow directories and files to overwrite each
+ // do not allow directories and files to overwrite each
// other when renaming
d := item.(*Dentry)
if d.isDeleted() {
@@ -223,7 +222,6 @@ func (mp *metaPartition) fsmTxDeleteDentry(txDentry *TxDentry) (resp *DentryResp
// Delete dentry from the dentry tree.
func (mp *metaPartition) fsmDeleteDentry(denParm *Dentry, checkInode bool) (resp *DentryResponse) {
-
log.LogDebugf("action[fsmDeleteDentry] mp [%v] delete param (%v) seq %v", mp.config.PartitionId, denParm, denParm.getSeqFiled())
resp = NewDentryResponse()
resp.Status = proto.OpOk
diff --git a/metanode/partition_fsmop_extend.go b/metanode/partition_fsmop_extend.go
index 22c0b8082..514b1d578 100644
--- a/metanode/partition_fsmop_extend.go
+++ b/metanode/partition_fsmop_extend.go
@@ -16,8 +16,9 @@ package metanode
import (
"fmt"
- "github.com/cubefs/cubefs/util/log"
"math"
+
+ "github.com/cubefs/cubefs/util/log"
)
type ExtendOpResult struct {
diff --git a/metanode/partition_fsmop_inode.go b/metanode/partition_fsmop_inode.go
index 8a599b9f9..4e335b8e3 100644
--- a/metanode/partition_fsmop_inode.go
+++ b/metanode/partition_fsmop_inode.go
@@ -19,16 +19,14 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
-
- "github.com/cubefs/cubefs/storage"
- "github.com/cubefs/cubefs/util"
- "github.com/cubefs/cubefs/util/timeutil"
-
"io"
"time"
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/storage"
+ "github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/log"
+ "github.com/cubefs/cubefs/util/timeutil"
)
type InodeResponse struct {
@@ -48,7 +46,7 @@ func (mp *metaPartition) fsmTxCreateInode(txIno *TxInode, quotaIds []uint32) (st
return proto.OpTxInfoNotExistErr
}
- //inodeInfo := mp.txProcessor.txManager.getTxInodeInfo(txIno.TxInfo.TxID, txIno.Inode.Inode)
+ // inodeInfo := mp.txProcessor.txManager.getTxInodeInfo(txIno.TxInfo.TxID, txIno.Inode.Inode)
inodeInfo, ok := txIno.TxInfo.TxInodeInfos[txIno.Inode.Inode]
if !ok {
status = proto.OpTxInodeInfoNotExistErr
@@ -66,7 +64,7 @@ func (mp *metaPartition) fsmTxCreateInode(txIno *TxInode, quotaIds []uint32) (st
mp.txProcessor.txResource.deleteTxRollbackInode(txIno.Inode.Inode, txIno.TxInfo.TxID)
}
}()
- //3.insert inode in inode tree
+ // 3.insert inode in inode tree
return mp.fsmCreateInode(txIno.Inode)
}
@@ -93,7 +91,7 @@ func (mp *metaPartition) fsmTxCreateLinkInode(txIno *TxInode) (resp *InodeRespon
return
}
- //2.register rollback item
+ // 2.register rollback item
inodeInfo, ok := txIno.TxInfo.TxInodeInfos[txIno.Inode.Inode]
if !ok {
resp.Status = proto.OpTxInodeInfoNotExistErr
@@ -283,9 +281,7 @@ func (mp *metaPartition) fsmTxUnlinkInode(txIno *TxInode) (resp *InodeResponse)
func (mp *metaPartition) fsmUnlinkInode(ino *Inode, uniqID uint64) (resp *InodeResponse) {
log.LogDebugf("action[fsmUnlinkInode] mp %v ino %v", mp.config.PartitionId, ino)
- var (
- ext2Del []proto.ExtentKey
- )
+ var ext2Del []proto.ExtentKey
resp = NewInodeResponse()
resp.Status = proto.OpOk
@@ -452,9 +448,7 @@ func (mp *metaPartition) fsmAppendExtents(ino *Inode) (status uint8) {
}
func (mp *metaPartition) fsmAppendExtentsWithCheck(ino *Inode, isSplit bool) (status uint8) {
- var (
- delExtents []proto.ExtentKey
- )
+ var delExtents []proto.ExtentKey
if mp.verSeq < ino.getVer() {
status = proto.OpArgMismatchErr
@@ -565,7 +559,6 @@ func (mp *metaPartition) fsmAppendObjExtents(ino *Inode) (status uint8) {
eks := ino.ObjExtents.CopyExtents()
err := inode.AppendObjExtents(eks, ino.ModifyTime)
-
// if err is not nil, means obj eks exist overlap.
if err != nil {
log.LogErrorf("fsmAppendExtents inode(%v) err(%v)", inode.Inode, err)
@@ -810,7 +803,7 @@ func (mp *metaPartition) fsmSetInodeQuotaBatch(req *proto.BatchSetMetaserverQuot
var isExist bool
var err error
- var extend = NewExtend(ino)
+ extend := NewExtend(ino)
treeItem := mp.extendTree.Get(extend)
inode := NewInode(ino, 0)
retMsg := mp.getInode(inode, false)
@@ -822,10 +815,10 @@ func (mp *metaPartition) fsmSetInodeQuotaBatch(req *proto.BatchSetMetaserverQuot
}
inode = retMsg.Msg
log.LogDebugf("fsmSetInodeQuotaBatch msg [%v] inode [%v]", retMsg, inode)
- var quotaInfos = &proto.MetaQuotaInfos{
+ quotaInfos := &proto.MetaQuotaInfos{
QuotaInfoMap: make(map[uint32]*proto.MetaQuotaInfo),
}
- var quotaInfo = &proto.MetaQuotaInfo{
+ quotaInfo := &proto.MetaQuotaInfo{
RootInode: req.IsRoot,
}
@@ -876,7 +869,7 @@ func (mp *metaPartition) fsmDeleteInodeQuotaBatch(req *proto.BatchDeleteMetaserv
for _, ino := range req.Inodes {
var err error
- var extend = NewExtend(ino)
+ extend := NewExtend(ino)
treeItem := mp.extendTree.Get(extend)
inode := NewInode(ino, 0)
retMsg := mp.getInode(inode, false)
@@ -887,7 +880,7 @@ func (mp *metaPartition) fsmDeleteInodeQuotaBatch(req *proto.BatchDeleteMetaserv
}
inode = retMsg.Msg
log.LogDebugf("fsmDeleteInodeQuotaBatch msg [%v] inode [%v]", retMsg, inode)
- var quotaInfos = &proto.MetaQuotaInfos{
+ quotaInfos := &proto.MetaQuotaInfos{
QuotaInfoMap: make(map[uint32]*proto.MetaQuotaInfo),
}
diff --git a/metanode/partition_fsmop_transaction.go b/metanode/partition_fsmop_transaction.go
index 2ac86c124..285fde8ed 100644
--- a/metanode/partition_fsmop_transaction.go
+++ b/metanode/partition_fsmop_transaction.go
@@ -60,13 +60,13 @@ func (mp *metaPartition) fsmTxCommit(txID string) (status uint8) {
}
func (mp *metaPartition) fsmTxInodeCommit(txID string, inode uint64) (status uint8) {
- //var err error
+ // var err error
status, _ = mp.txProcessor.txResource.commitInode(txID, inode)
return
}
func (mp *metaPartition) fsmTxDentryCommit(txID string, pId uint64, name string) (status uint8) {
- //var err error
+ // var err error
status, _ = mp.txProcessor.txResource.commitDentry(txID, pId, name)
return
}
@@ -162,7 +162,6 @@ func (mp *metaPartition) dentryInTx(parIno uint64, name string) uint8 {
}
func (mp *metaPartition) txInodeInRb(inode uint64, newTxId string) (rbInode *TxRollbackInode) {
-
rbIno := mp.txProcessor.txResource.getTxRbInode(inode)
if rbIno != nil && rbIno.txInodeInfo.TxID == newTxId {
return rbIno
diff --git a/metanode/partition_fsmop_uniq.go b/metanode/partition_fsmop_uniq.go
index ef1335c3b..5c41ef3c2 100644
--- a/metanode/partition_fsmop_uniq.go
+++ b/metanode/partition_fsmop_uniq.go
@@ -16,6 +16,7 @@ package metanode
import (
"encoding/binary"
+
"github.com/cubefs/cubefs/proto"
)
diff --git a/metanode/partition_item.go b/metanode/partition_item.go
index 306462161..10dbf9cb2 100644
--- a/metanode/partition_item.go
+++ b/metanode/partition_item.go
@@ -20,7 +20,6 @@ import (
"encoding/json"
"fmt"
"io"
- "io/ioutil"
"os"
"path"
"reflect"
@@ -211,7 +210,7 @@ func newMetaItemIterator(mp *metaPartition) (si *MetaItemIterator, err error) {
si.closeCh = make(chan struct{})
// collect extend del files
- var filenames = make([]string, 0)
+ filenames := make([]string, 0)
var fileInfos []os.DirEntry
if fileInfos, err = os.ReadDir(mp.config.RootDir); err != nil {
return
@@ -233,7 +232,7 @@ func newMetaItemIterator(mp *metaPartition) (si *MetaItemIterator, err error) {
close(iter.dataCh)
close(iter.errorCh)
}()
- var produceItem = func(item interface{}) (success bool) {
+ produceItem := func(item interface{}) (success bool) {
select {
case iter.dataCh <- item:
return true
@@ -241,13 +240,13 @@ func newMetaItemIterator(mp *metaPartition) (si *MetaItemIterator, err error) {
return false
}
}
- var produceError = func(err error) {
+ produceError := func(err error) {
select {
case iter.errorCh <- err:
default:
}
}
- var checkClose = func() (closed bool) {
+ checkClose := func() (closed bool) {
select {
case <-iter.closeCh:
return true
@@ -356,7 +355,7 @@ func newMetaItemIterator(mp *metaPartition) (si *MetaItemIterator, err error) {
var err error
var raw []byte
for _, filename := range iter.filenames {
- if raw, err = ioutil.ReadFile(path.Join(iter.fileRootDir, filename)); err != nil {
+ if raw, err = os.ReadFile(path.Join(iter.fileRootDir, filename)); err != nil {
produceError(err)
return
}
diff --git a/metanode/partition_op_dentry.go b/metanode/partition_op_dentry.go
index 5bf5d6e10..795a1a2c0 100644
--- a/metanode/partition_op_dentry.go
+++ b/metanode/partition_op_dentry.go
@@ -242,7 +242,7 @@ func (mp *metaPartition) TxDeleteDentry(req *proto.TxDeleteDentryRequest, p *Pac
}
txDentry := &TxDentry{
- //ParInode: inoResp.Msg,
+ // ParInode: inoResp.Msg,
Dentry: dentry,
TxInfo: txInfo,
}
diff --git a/metanode/partition_op_extend.go b/metanode/partition_op_extend.go
index 3affa2013..3e954c244 100644
--- a/metanode/partition_op_extend.go
+++ b/metanode/partition_op_extend.go
@@ -44,7 +44,7 @@ func (mp *metaPartition) UpdateXAttr(req *proto.UpdateXAttrRequest, p *Packet) (
newValue := strconv.FormatInt(int64(newFiles), 10) + "," +
strconv.FormatInt(int64(newDirs), 10) + "," +
strconv.FormatInt(int64(newBytes), 10)
- var extend = NewExtend(req.Inode)
+ extend := NewExtend(req.Inode)
extend.Put([]byte(req.Key), []byte(newValue), mp.verSeq)
if _, err = mp.putExtend(opFSMUpdateXAttr, extend); err != nil {
p.PacketErrorWithBody(proto.OpErr, []byte(err.Error()))
@@ -62,7 +62,7 @@ func (mp *metaPartition) UpdateXAttr(req *proto.UpdateXAttrRequest, p *Packet) (
return
}
} else {
- var extend = NewExtend(req.Inode)
+ extend := NewExtend(req.Inode)
extend.Put([]byte(req.Key), []byte(req.Value), mp.verSeq)
if _, err = mp.putExtend(opFSMUpdateXAttr, extend); err != nil {
p.PacketErrorWithBody(proto.OpErr, []byte(err.Error()))
@@ -74,7 +74,7 @@ func (mp *metaPartition) UpdateXAttr(req *proto.UpdateXAttrRequest, p *Packet) (
}
func (mp *metaPartition) SetXAttr(req *proto.SetXAttrRequest, p *Packet) (err error) {
- var extend = NewExtend(req.Inode)
+ extend := NewExtend(req.Inode)
extend.Put([]byte(req.Key), []byte(req.Value), mp.verSeq)
if _, err = mp.putExtend(opFSMSetXAttr, extend); err != nil {
p.PacketErrorWithBody(proto.OpErr, []byte(err.Error()))
@@ -85,7 +85,7 @@ func (mp *metaPartition) SetXAttr(req *proto.SetXAttrRequest, p *Packet) (err er
}
func (mp *metaPartition) BatchSetXAttr(req *proto.BatchSetXAttrRequest, p *Packet) (err error) {
- var extend = NewExtend(req.Inode)
+ extend := NewExtend(req.Inode)
for key, val := range req.Attrs {
extend.Put([]byte(key), []byte(val), mp.verSeq)
}
@@ -99,7 +99,7 @@ func (mp *metaPartition) BatchSetXAttr(req *proto.BatchSetXAttrRequest, p *Packe
}
func (mp *metaPartition) GetXAttr(req *proto.GetXAttrRequest, p *Packet) (err error) {
- var response = &proto.GetXAttrResponse{
+ response := &proto.GetXAttrResponse{
VolName: req.VolName,
PartitionId: req.PartitionId,
Inode: req.Inode,
@@ -124,7 +124,7 @@ func (mp *metaPartition) GetXAttr(req *proto.GetXAttrRequest, p *Packet) (err er
}
func (mp *metaPartition) GetAllXAttr(req *proto.GetAllXAttrRequest, p *Packet) (err error) {
- var response = &proto.GetAllXAttrResponse{
+ response := &proto.GetAllXAttrResponse{
VolName: req.VolName,
PartitionId: req.PartitionId,
Inode: req.Inode,
@@ -137,7 +137,6 @@ func (mp *metaPartition) GetAllXAttr(req *proto.GetAllXAttrRequest, p *Packet) (
response.Attrs[key] = string(val)
}
}
-
}
var encoded []byte
encoded, err = json.Marshal(response)
@@ -150,7 +149,7 @@ func (mp *metaPartition) GetAllXAttr(req *proto.GetAllXAttrRequest, p *Packet) (
}
func (mp *metaPartition) BatchGetXAttr(req *proto.BatchGetXAttrRequest, p *Packet) (err error) {
- var response = &proto.BatchGetXAttrResponse{
+ response := &proto.BatchGetXAttrResponse{
VolName: req.VolName,
PartitionId: req.PartitionId,
XAttrs: make([]*proto.XAttrInfo, 0, len(req.Inodes)),
@@ -184,7 +183,7 @@ func (mp *metaPartition) BatchGetXAttr(req *proto.BatchGetXAttrRequest, p *Packe
}
func (mp *metaPartition) RemoveXAttr(req *proto.RemoveXAttrRequest, p *Packet) (err error) {
- var extend = NewExtend(req.Inode)
+ extend := NewExtend(req.Inode)
extend.Put([]byte(req.Key), nil, req.VerSeq)
if _, err = mp.putExtend(opFSMRemoveXAttr, extend); err != nil {
p.PacketErrorWithBody(proto.OpErr, []byte(err.Error()))
@@ -195,7 +194,7 @@ func (mp *metaPartition) RemoveXAttr(req *proto.RemoveXAttrRequest, p *Packet) (
}
func (mp *metaPartition) ListXAttr(req *proto.ListXAttrRequest, p *Packet) (err error) {
- var response = &proto.ListXAttrResponse{
+ response := &proto.ListXAttrResponse{
VolName: req.VolName,
PartitionId: req.PartitionId,
Inode: req.Inode,
diff --git a/metanode/partition_op_extent.go b/metanode/partition_op_extent.go
index ca775cdf3..3ca94cfb2 100644
--- a/metanode/partition_op_extent.go
+++ b/metanode/partition_op_extent.go
@@ -21,11 +21,10 @@ import (
"sort"
"time"
- "github.com/cubefs/cubefs/util/auditlog"
- "github.com/cubefs/cubefs/util/exporter"
-
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/util/auditlog"
"github.com/cubefs/cubefs/util/errors"
+ "github.com/cubefs/cubefs/util/exporter"
"github.com/cubefs/cubefs/util/log"
)
@@ -158,8 +157,8 @@ func (mp *metaPartition) ExtentAppendWithCheck(req *proto.AppendExtentKeyWithChe
log.LogDebugf("ExtentAppendWithCheck: ino(%v) mp(%v) verSeq (%v) req.VerSeq(%v) rspcode(%v)", req.Inode, req.PartitionID, mp.verSeq, req.VerSeq, resp.(uint8))
if mp.verSeq > req.VerSeq {
- //reuse ExtentType to identify flag of version inconsistent between metanode and client
- //will resp to client and make client update all streamer's extent and it's verSeq
+ // reuse ExtentType to identify flag of version inconsistent between metanode and client
+ // will resp to client and make client update all streamer's extent and it's verSeq
p.ExtentType |= proto.MultiVersionFlag
p.VerSeq = mp.verSeq
}
@@ -185,7 +184,7 @@ type VerOpData struct {
}
func (mp *metaPartition) checkByMasterVerlist(mpVerList *proto.VolVersionInfoList, masterVerList *proto.VolVersionInfoList) (err error) {
- var currMasterSeq = masterVerList.GetLastVer()
+ currMasterSeq := masterVerList.GetLastVer()
verMapMaster := make(map[uint64]*proto.VolVersionInfo)
for _, ver := range masterVerList.VerList {
verMapMaster[ver.Ver] = ver
@@ -237,9 +236,7 @@ func (mp *metaPartition) checkVerList(reqVerListInfo *proto.VolVersionInfoList,
verMapReq[ver.Ver] = ver
}
- var (
- VerList []*proto.VolVersionInfo
- )
+ var VerList []*proto.VolVersionInfo
for _, info2 := range mp.multiVersionList.VerList {
log.LogDebugf("checkVerList. vol %v mp %v ver info %v", mp.config.VolName, mp.config.PartitionId, info2)
@@ -304,7 +301,6 @@ func (mp *metaPartition) checkVerList(reqVerListInfo *proto.VolVersionInfoList,
}
func (mp *metaPartition) HandleVersionOp(op uint8, verSeq uint64, verList []*proto.VolVersionInfo, sync bool) (err error) {
-
verData := &VerOpData{
Op: op,
VerSeq: verSeq,
@@ -367,7 +363,6 @@ func (mp *metaPartition) GetExtentByVer(ino *Inode, req *proto.GetExtentsRequest
sort.SliceStable(rsp.Extents, func(i, j int) bool {
return rsp.Extents[i].FileOffset < rsp.Extents[j].FileOffset
})
-
})
return
@@ -390,7 +385,7 @@ func (mp *metaPartition) ExtentsList(req *proto.GetExtentsRequest, p *Packet) (e
ino := NewInode(req.Inode, 0)
retMsg := mp.getInodeTopLayer(ino)
- //notice.getInode should not set verSeq due to extent need filter from the newest layer to req.VerSeq
+ // notice.getInode should not set verSeq due to extent need filter from the newest layer to req.VerSeq
ino = retMsg.Msg
var (
reply []byte
diff --git a/metanode/partition_op_inode.go b/metanode/partition_op_inode.go
index f130ffd65..1a218ce85 100644
--- a/metanode/partition_op_inode.go
+++ b/metanode/partition_op_inode.go
@@ -376,7 +376,6 @@ func (mp *metaPartition) UnlinkInode(req *UnlinkInoReq, p *Packet, remoteAddr st
// DeleteInode deletes an inode.
func (mp *metaPartition) UnlinkInodeBatch(req *BatchUnlinkInoReq, p *Packet, remoteAddr string) (err error) {
-
if len(req.Inodes) == 0 {
return nil
}
@@ -491,7 +490,6 @@ func (mp *metaPartition) InodeGetSplitEk(req *InodeGetSplitReq, p *Packet) (err
// InodeGet executes the inodeGet command from the client.
func (mp *metaPartition) InodeGet(req *InodeGetReq, p *Packet) (err error) {
-
ino := NewInode(req.Inode, 0)
ino.setVer(req.VerSeq)
getAllVerInfo := req.VerAll
@@ -551,7 +549,6 @@ func (mp *metaPartition) InodeGet(req *InodeGetReq, p *Packet) (err error) {
// InodeGetBatch executes the inodeBatchGet command from the client.
func (mp *metaPartition) InodeGetBatch(req *InodeGetReqBatch, p *Packet) (err error) {
-
resp := &proto.BatchInodeGetResponse{}
ino := NewInode(0, 0)
for _, inoId := range req.Inodes {
@@ -711,7 +708,6 @@ func (mp *metaPartition) EvictInode(req *EvictInodeReq, p *Packet, remoteAddr st
// EvictInode evicts an inode.
func (mp *metaPartition) EvictInodeBatch(req *BatchEvictInodeReq, p *Packet, remoteAddr string) (err error) {
-
if len(req.Inodes) == 0 {
return nil
}
@@ -795,7 +791,7 @@ func (mp *metaPartition) DeleteInode(req *proto.DeleteInodeRequest, p *Packet, r
auditlog.LogInodeOp(remoteAddr, mp.GetVolName(), p.GetOpMsg(), req.GetFullPath(), err, time.Since(start).Milliseconds(), req.Inode, 0)
}()
}
- var bytes = make([]byte, 8)
+ bytes := make([]byte, 8)
binary.BigEndian.PutUint64(bytes, req.Inode)
_, err = mp.submit(opFSMInternalDeleteInode, bytes)
if err != nil {
diff --git a/metanode/partition_op_multipart.go b/metanode/partition_op_multipart.go
index 6be8e01db..5561e46f3 100644
--- a/metanode/partition_op_multipart.go
+++ b/metanode/partition_op_multipart.go
@@ -19,14 +19,13 @@ import (
"strings"
"time"
- "github.com/cubefs/cubefs/util"
-
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/util"
)
func (mp *metaPartition) GetExpiredMultipart(req *proto.GetExpiredMultipartRequest, p *Packet) (err error) {
expiredMultiPartInfos := make([]*proto.ExpiredMultipartInfo, 0)
- var walkTreeFunc = func(i BtreeItem) bool {
+ walkTreeFunc := func(i BtreeItem) bool {
multipart := i.(*Multipart)
if len(req.Prefix) > 0 && !strings.HasPrefix(multipart.key, req.Prefix) {
// skip and continue
@@ -159,9 +158,7 @@ func (mp *metaPartition) RemoveMultipart(req *proto.RemoveMultipartRequest, p *P
}
func (mp *metaPartition) CreateMultipart(req *proto.CreateMultipartRequest, p *Packet) (err error) {
- var (
- multipartId string
- )
+ var multipartId string
for {
multipartId = util.CreateMultipartID(mp.config.PartitionId).String()
storedItem := mp.multipartTree.Get(&Multipart{key: req.Path, id: multipartId})
@@ -197,13 +194,12 @@ func (mp *metaPartition) CreateMultipart(req *proto.CreateMultipartRequest, p *P
}
func (mp *metaPartition) ListMultipart(req *proto.ListMultipartRequest, p *Packet) (err error) {
-
max := int(req.Max)
keyMarker := req.Marker
multipartIdMarker := req.MultipartIdMarker
prefix := req.Prefix
- var matches = make([]*Multipart, 0, max)
- var walkTreeFunc = func(i BtreeItem) bool {
+ matches := make([]*Multipart, 0, max)
+ walkTreeFunc := func(i BtreeItem) bool {
multipart := i.(*Multipart)
// prefix is enabled
if len(prefix) > 0 && !strings.HasPrefix(multipart.key, prefix) {
@@ -220,7 +216,7 @@ func (mp *metaPartition) ListMultipart(req *proto.ListMultipartRequest, p *Packe
}
multipartInfos := make([]*proto.MultipartInfo, len(matches))
- var convertPartFunc = func(part *Part) *proto.MultipartPartInfo {
+ convertPartFunc := func(part *Part) *proto.MultipartPartInfo {
return &proto.MultipartPartInfo{
ID: part.ID,
Inode: part.Inode,
@@ -230,7 +226,7 @@ func (mp *metaPartition) ListMultipart(req *proto.ListMultipartRequest, p *Packe
}
}
- var convertMultipartFunc = func(multipart *Multipart) *proto.MultipartInfo {
+ convertMultipartFunc := func(multipart *Multipart) *proto.MultipartInfo {
partInfos := make([]*proto.MultipartPartInfo, len(multipart.parts))
for i := 0; i < len(multipart.parts); i++ {
partInfos[i] = convertPartFunc(multipart.parts[i])
diff --git a/metanode/partition_op_quota.go b/metanode/partition_op_quota.go
index cec101dd3..a226d7128 100644
--- a/metanode/partition_op_quota.go
+++ b/metanode/partition_op_quota.go
@@ -127,7 +127,7 @@ func (mp *metaPartition) statisticExtendByStore(extend *Extend, inodeTree *BTree
log.LogDebugf("statisticExtendByStore get quota key failed, mp [%v] inode [%v]", mp.config.PartitionId, extend.GetInode())
return
}
- var quotaInfos = &proto.MetaQuotaInfos{
+ quotaInfos := &proto.MetaQuotaInfos{
QuotaInfoMap: make(map[uint32]*proto.MetaQuotaInfo),
}
if err := json.Unmarshal(value, "aInfos.QuotaInfoMap); err != nil {
@@ -164,7 +164,7 @@ func (mp *metaPartition) updateUsedInfo(size int64, files int64, ino uint64) {
}
func (mp *metaPartition) isExistQuota(ino uint64) (quotaIds []uint32, isFind bool) {
- var extend = NewExtend(ino)
+ extend := NewExtend(ino)
treeItem := mp.extendTree.Get(extend)
if treeItem == nil {
isFind = false
@@ -176,7 +176,7 @@ func (mp *metaPartition) isExistQuota(ino uint64) (quotaIds []uint32, isFind boo
isFind = false
return
}
- var quotaInfos = &proto.MetaQuotaInfos{
+ quotaInfos := &proto.MetaQuotaInfos{
QuotaInfoMap: make(map[uint32]*proto.MetaQuotaInfo),
}
if err := json.Unmarshal(value, "aInfos.QuotaInfoMap); err != nil {
@@ -209,8 +209,8 @@ func (mp *metaPartition) isOverQuota(ino uint64, size bool, files bool) (status
}
func (mp *metaPartition) getInodeQuota(inode uint64, p *Packet) (err error) {
- var extend = NewExtend(inode)
- var quotaInfos = &proto.MetaQuotaInfos{
+ extend := NewExtend(inode)
+ quotaInfos := &proto.MetaQuotaInfos{
QuotaInfoMap: make(map[uint32]*proto.MetaQuotaInfo),
}
var (
@@ -232,7 +232,7 @@ func (mp *metaPartition) getInodeQuota(inode uint64, p *Packet) (err error) {
}
}
handleRsp:
- var response = &proto.GetInodeQuotaResponse{}
+ response := &proto.GetInodeQuotaResponse{}
log.LogInfof("getInodeQuota indoe %v ,map %v", inode, quotaInfos.QuotaInfoMap)
response.MetaQuotaInfoMap = quotaInfos.QuotaInfoMap
@@ -252,7 +252,7 @@ func (mp *metaPartition) getInodeQuotaInfos(inode uint64) (quotaInfos map[uint32
return
}
extend := treeItem.(*Extend)
- var info = &proto.MetaQuotaInfos{
+ info := &proto.MetaQuotaInfos{
QuotaInfoMap: make(map[uint32]*proto.MetaQuotaInfo),
}
value, exist := extend.Get([]byte(proto.QuotaKey))
@@ -268,12 +268,12 @@ func (mp *metaPartition) getInodeQuotaInfos(inode uint64) (quotaInfos map[uint32
}
func (mp *metaPartition) setInodeQuota(quotaIds []uint32, inode uint64) {
- var extend = NewExtend(inode)
- var quotaInfos = &proto.MetaQuotaInfos{
+ extend := NewExtend(inode)
+ quotaInfos := &proto.MetaQuotaInfos{
QuotaInfoMap: make(map[uint32]*proto.MetaQuotaInfo),
}
for _, quotaId := range quotaIds {
- var quotaInfo = &proto.MetaQuotaInfo{
+ quotaInfo := &proto.MetaQuotaInfo{
RootInode: false,
}
quotaInfos.QuotaInfoMap[quotaId] = quotaInfo
diff --git a/metanode/partition_op_quota_test.go b/metanode/partition_op_quota_test.go
index f371ef36e..e094cd3e8 100644
--- a/metanode/partition_op_quota_test.go
+++ b/metanode/partition_op_quota_test.go
@@ -114,7 +114,7 @@ func TestQuotaHbInfo(t *testing.T) {
func TestGetQuotaReportInfos(t *testing.T) {
partition := NewMetaPartitionForQuotaTest()
var quotaId uint32 = 1
- //var infos []*proto.QuotaReportInfo
+ // var infos []*proto.QuotaReportInfo
partition.mqMgr.updateUsedInfo(100, 1, quotaId)
partition.mqMgr.updateUsedInfo(200, 2, quotaId)
partition.mqMgr.limitedMap.Store(quotaId, proto.QuotaLimitedInfo{false, false})
diff --git a/metanode/partition_op_transaction.go b/metanode/partition_op_transaction.go
index 0aac46587..536eb6055 100644
--- a/metanode/partition_op_transaction.go
+++ b/metanode/partition_op_transaction.go
@@ -26,7 +26,6 @@ import (
)
func (mp *metaPartition) TxCreate(req *proto.TxCreateRequest, p *Packet) error {
-
var err error
txInfo := req.TransactionInfo.GetCopy()
diff --git a/metanode/partition_op_uniq.go b/metanode/partition_op_uniq.go
index 5b581b4bd..53a07eb1b 100644
--- a/metanode/partition_op_uniq.go
+++ b/metanode/partition_op_uniq.go
@@ -24,7 +24,6 @@ import (
)
func (mp *metaPartition) GetUniqID(p *Packet, num uint32) (err error) {
-
idBuf := make([]byte, 4)
binary.BigEndian.PutUint32(idBuf, num)
resp, err := mp.submit(opFSMUniqID, idBuf)
@@ -56,7 +55,7 @@ func (mp *metaPartition) GetUniqID(p *Packet, num uint32) (err error) {
func (mp *metaPartition) allocateUniqID(num uint32) (start, end uint64) {
for {
- //cur is the last allocated id
+ // cur is the last allocated id
cur := mp.GetUniqId()
start = cur + 1
end := cur + uint64(num)
@@ -85,8 +84,10 @@ func (mp *metaPartition) uniqCheckerEvict() (left int, evict int, err error) {
return left, idx + 1, err
}
-var inodeOnceSize = 16
-var newInodeOnceSize = 24
+var (
+ inodeOnceSize = 16
+ newInodeOnceSize = 24
+)
type InodeOnce struct {
UniqID uint64
diff --git a/metanode/partition_op_uniq_test.go b/metanode/partition_op_uniq_test.go
index a0d852c31..5b3b6f8d2 100644
--- a/metanode/partition_op_uniq_test.go
+++ b/metanode/partition_op_uniq_test.go
@@ -111,7 +111,6 @@ func TestDoEvit1(t *testing.T) {
if checker.inQue.len() != 0 || len(checker.op) != 0 {
t.Errorf("failed, inQue %v, op %v", checker.inQue, checker.op)
}
-
}
func TestDoEvit2(t *testing.T) {
diff --git a/metanode/partition_store.go b/metanode/partition_store.go
index 358fc272a..b8040f074 100644
--- a/metanode/partition_store.go
+++ b/metanode/partition_store.go
@@ -21,17 +21,15 @@ import (
"fmt"
"hash/crc32"
"io"
- "io/ioutil"
"os"
"path"
"strings"
"sync/atomic"
"time"
- "github.com/cubefs/cubefs/util/log"
-
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/errors"
+ "github.com/cubefs/cubefs/util/log"
mmap "github.com/edsrzf/mmap-go"
)
@@ -61,13 +59,13 @@ const (
func (mp *metaPartition) loadMetadata() (err error) {
metaFile := path.Join(mp.config.RootDir, metadataFile)
- fp, err := os.OpenFile(metaFile, os.O_RDONLY, 0644)
+ fp, err := os.OpenFile(metaFile, os.O_RDONLY, 0o644)
if err != nil {
err = errors.NewErrorf("[loadMetadata]: OpenFile %s", err.Error())
return
}
defer fp.Close()
- data, err := ioutil.ReadAll(fp)
+ data, err := io.ReadAll(fp)
if err != nil || len(data) == 0 {
err = errors.NewErrorf("[loadMetadata]: ReadFile %s, data: %s", err.Error(),
string(data))
@@ -112,7 +110,7 @@ func (mp *metaPartition) loadInode(rootDir string, crc uint32) (err error) {
err = errors.NewErrorf("[loadInode] Stat: %s", err.Error())
return
}
- fp, err := os.OpenFile(filename, os.O_RDONLY, 0644)
+ fp, err := os.OpenFile(filename, os.O_RDONLY, 0o644)
if err != nil {
err = errors.NewErrorf("[loadInode] OpenFile: %s", err.Error())
return
@@ -175,7 +173,6 @@ func (mp *metaPartition) loadInode(rootDir string, crc uint32) (err error) {
}
numInodes += 1
}
-
}
// Load dentry from the dentry snapshot.
@@ -192,7 +189,7 @@ func (mp *metaPartition) loadDentry(rootDir string, crc uint32) (err error) {
err = errors.NewErrorf("[loadDentry] Stat: %s", err.Error())
return
}
- fp, err := os.OpenFile(filename, os.O_RDONLY, 0644)
+ fp, err := os.OpenFile(filename, os.O_RDONLY, 0o644)
if err != nil {
err = errors.NewErrorf("[loadDentry] OpenFile: %s", err.Error())
return
@@ -256,7 +253,7 @@ func (mp *metaPartition) loadExtend(rootDir string, crc uint32) (err error) {
err = errors.NewErrorf("[loadExtend] Stat: %s", err.Error())
return err
}
- fp, err := os.OpenFile(filename, os.O_RDONLY, 0644)
+ fp, err := os.OpenFile(filename, os.O_RDONLY, 0o644)
if err != nil {
err = errors.NewErrorf("[loadExtend] OpenFile: %s", err.Error())
return err
@@ -277,7 +274,7 @@ func (mp *metaPartition) loadExtend(rootDir string, crc uint32) (err error) {
numExtends, n = binary.Uvarint(mem)
offset += n
- var varintTmp = make([]byte, binary.MaxVarintLen64)
+ varintTmp := make([]byte, binary.MaxVarintLen64)
// write number of extends
n = binary.PutUvarint(varintTmp, numExtends)
@@ -298,7 +295,7 @@ func (mp *metaPartition) loadExtend(rootDir string, crc uint32) (err error) {
if _, err = crcCheck.Write(mem[offset-n : offset]); err != nil {
return err
}
- //log.LogDebugf("loadExtend: new extend from bytes: partitionID (%v) volume(%v) inode(%v)",
+ // log.LogDebugf("loadExtend: new extend from bytes: partitionID (%v) volume(%v) inode(%v)",
// mp.config.PartitionId, mp.config.VolName, extend.inode)
_ = mp.fsmSetXAttr(extend)
@@ -324,7 +321,7 @@ func (mp *metaPartition) loadMultipart(rootDir string, crc uint32) (err error) {
err = errors.NewErrorf("[loadMultipart] Stat: %s", err.Error())
return err
}
- fp, err := os.OpenFile(filename, os.O_RDONLY, 0644)
+ fp, err := os.OpenFile(filename, os.O_RDONLY, 0o644)
if err != nil {
err = errors.NewErrorf("[loadMultipart] OpenFile: %s", err.Error())
return err
@@ -343,7 +340,7 @@ func (mp *metaPartition) loadMultipart(rootDir string, crc uint32) (err error) {
// read number of multipart
var numMultiparts uint64
numMultiparts, n = binary.Uvarint(mem)
- var varintTmp = make([]byte, binary.MaxVarintLen64)
+ varintTmp := make([]byte, binary.MaxVarintLen64)
// write number of multipart
n = binary.PutUvarint(varintTmp, numMultiparts)
crcCheck := crc32.NewIEEE()
@@ -383,7 +380,7 @@ func (mp *metaPartition) loadApplyID(rootDir string) (err error) {
err = errors.NewErrorf("[loadApplyID]: Stat %s", err.Error())
return
}
- data, err := ioutil.ReadFile(filename)
+ data, err := os.ReadFile(filename)
if err != nil {
err = errors.NewErrorf("[loadApplyID] ReadFile: %s", err.Error())
return
@@ -395,7 +392,6 @@ func (mp *metaPartition) loadApplyID(rootDir string) (err error) {
var cursor uint64
if strings.Contains(string(data), "|") {
_, err = fmt.Sscanf(string(data), "%d|%d", &mp.applyID, &cursor)
-
} else {
_, err = fmt.Sscanf(string(data), "%d", &mp.applyID)
}
@@ -428,7 +424,7 @@ func (mp *metaPartition) loadTxRbDentry(rootDir string, crc uint32) (err error)
err = errors.NewErrorf("[loadTxRbDentry] Stat: %s", err.Error())
return
}
- fp, err := os.OpenFile(filename, os.O_RDONLY, 0644)
+ fp, err := os.OpenFile(filename, os.O_RDONLY, 0o644)
if err != nil {
err = errors.NewErrorf("[loadTxRbDentry] OpenFile: %s", err.Error())
return
@@ -484,7 +480,7 @@ func (mp *metaPartition) loadTxRbDentry(rootDir string, crc uint32) (err error)
return err
}
- //mp.txProcessor.txResource.txRollbackDentries[txRbDentry.txDentryInfo.GetKey()] = txRbDentry
+ // mp.txProcessor.txResource.txRollbackDentries[txRbDentry.txDentryInfo.GetKey()] = txRbDentry
mp.txProcessor.txResource.txRbDentryTree.ReplaceOrInsert(txRbDentry, true)
numTxRbDentry++
}
@@ -503,7 +499,7 @@ func (mp *metaPartition) loadTxRbInode(rootDir string, crc uint32) (err error) {
err = errors.NewErrorf("[loadTxRbInode] Stat: %s", err.Error())
return
}
- fp, err := os.OpenFile(filename, os.O_RDONLY, 0644)
+ fp, err := os.OpenFile(filename, os.O_RDONLY, 0o644)
if err != nil {
err = errors.NewErrorf("[loadTxRbInode] OpenFile: %s", err.Error())
return
@@ -572,7 +568,7 @@ func (mp *metaPartition) loadTxInfo(rootDir string, crc uint32) (err error) {
err = errors.NewErrorf("[loadTxInfo] Stat: %s", err.Error())
return
}
- fp, err := os.OpenFile(filename, os.O_RDONLY, 0644)
+ fp, err := os.OpenFile(filename, os.O_RDONLY, 0o644)
if err != nil {
err = errors.NewErrorf("[loadTxInfo] OpenFile: %s", err.Error())
return
@@ -639,7 +635,7 @@ func (mp *metaPartition) loadTxID(rootDir string) (err error) {
err = nil
return
}
- data, err := ioutil.ReadFile(filename)
+ data, err := os.ReadFile(filename)
if err != nil {
err = errors.NewErrorf("[loadTxID] OpenFile: %s", err.Error())
return
@@ -669,7 +665,7 @@ func (mp *metaPartition) loadUniqID(rootDir string) (err error) {
err = nil
return
}
- data, err := ioutil.ReadFile(filename)
+ data, err := os.ReadFile(filename)
if err != nil {
err = errors.NewErrorf("[loadUniqID] OpenFile: %s", err.Error())
return
@@ -703,7 +699,7 @@ func (mp *metaPartition) loadUniqChecker(rootDir string, crc uint32) (err error)
return
}
- data, err := ioutil.ReadFile(filename)
+ data, err := os.ReadFile(filename)
if err != nil {
log.LogErrorf("loadUniqChecker read file %s err(%s)", filename, err)
err = errors.NewErrorf("[loadUniqChecker] OpenFile: %v", err.Error())
@@ -737,7 +733,7 @@ func (mp *metaPartition) loadMultiVer(rootDir string, crc uint32) (err error) {
return
}
- data, err := ioutil.ReadFile(filename)
+ data, err := os.ReadFile(filename)
if err != nil {
if err == os.ErrNotExist {
err = nil
@@ -798,7 +794,7 @@ func (mp *metaPartition) loadMultiVer(rootDir string, crc uint32) (err error) {
func (mp *metaPartition) storeMultiVersion(rootDir string, sm *storeMsg) (crc uint32, err error) {
filename := path.Join(rootDir, verdataFile)
fp, err := os.OpenFile(filename, os.O_RDWR|os.O_APPEND|os.O_TRUNC|os.
- O_CREATE, 0755)
+ O_CREATE, 0o755)
if err != nil {
return
}
@@ -846,9 +842,9 @@ func (mp *metaPartition) persistMetadata() (err error) {
}
// TODO Unhandled errors
- os.MkdirAll(mp.config.RootDir, 0755)
+ os.MkdirAll(mp.config.RootDir, 0o755)
filename := path.Join(mp.config.RootDir, metadataFileTmp)
- fp, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.O_CREATE, 0755)
+ fp, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.O_CREATE, 0o755)
if err != nil {
return
}
@@ -877,7 +873,7 @@ func (mp *metaPartition) persistMetadata() (err error) {
func (mp *metaPartition) storeApplyID(rootDir string, sm *storeMsg) (err error) {
filename := path.Join(rootDir, applyIDFile)
fp, err := os.OpenFile(filename, os.O_RDWR|os.O_APPEND|os.O_TRUNC|os.
- O_CREATE, 0755)
+ O_CREATE, 0o755)
if err != nil {
return
}
@@ -898,7 +894,7 @@ func (mp *metaPartition) storeApplyID(rootDir string, sm *storeMsg) (err error)
func (mp *metaPartition) storeTxID(rootDir string, sm *storeMsg) (err error) {
filename := path.Join(rootDir, TxIDFile)
fp, err := os.OpenFile(filename, os.O_RDWR|os.O_APPEND|os.O_TRUNC|os.
- O_CREATE, 0755)
+ O_CREATE, 0o755)
if err != nil {
return
}
@@ -916,7 +912,7 @@ func (mp *metaPartition) storeTxID(rootDir string, sm *storeMsg) (err error) {
func (mp *metaPartition) storeTxRbDentry(rootDir string, sm *storeMsg) (crc uint32, err error) {
filename := path.Join(rootDir, txRbDentryFile)
- fp, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.O_CREATE, 0755)
+ fp, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.O_CREATE, 0o755)
if err != nil {
return
}
@@ -960,7 +956,7 @@ func (mp *metaPartition) storeTxRbDentry(rootDir string, sm *storeMsg) (crc uint
func (mp *metaPartition) storeTxRbInode(rootDir string, sm *storeMsg) (crc uint32, err error) {
filename := path.Join(rootDir, txRbInodeFile)
- fp, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.O_CREATE, 0755)
+ fp, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.O_CREATE, 0o755)
if err != nil {
return
}
@@ -1004,7 +1000,7 @@ func (mp *metaPartition) storeTxRbInode(rootDir string, sm *storeMsg) (crc uint3
func (mp *metaPartition) storeTxInfo(rootDir string, sm *storeMsg) (crc uint32, err error) {
filename := path.Join(rootDir, txInfoFile)
- fp, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.O_CREATE, 0755)
+ fp, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.O_CREATE, 0o755)
if err != nil {
return
}
@@ -1051,7 +1047,7 @@ func (mp *metaPartition) storeInode(rootDir string,
sm *storeMsg) (crc uint32, err error) {
filename := path.Join(rootDir, inodeFile)
fp, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.
- O_CREATE, 0755)
+ O_CREATE, 0o755)
if err != nil {
return
}
@@ -1110,7 +1106,7 @@ func (mp *metaPartition) storeDentry(rootDir string,
sm *storeMsg) (crc uint32, err error) {
filename := path.Join(rootDir, dentryFile)
fp, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.
- O_CREATE, 0755)
+ O_CREATE, 0o755)
if err != nil {
return
}
@@ -1151,10 +1147,10 @@ func (mp *metaPartition) storeDentry(rootDir string,
}
func (mp *metaPartition) storeExtend(rootDir string, sm *storeMsg) (crc uint32, err error) {
- var extendTree = sm.extendTree
- var fp = path.Join(rootDir, extendFile)
+ extendTree := sm.extendTree
+ fp := path.Join(rootDir, extendFile)
var f *os.File
- f, err = os.OpenFile(fp, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.O_CREATE, 0755)
+ f, err = os.OpenFile(fp, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.O_CREATE, 0o755)
if err != nil {
return
}
@@ -1166,9 +1162,9 @@ func (mp *metaPartition) storeExtend(rootDir string, sm *storeMsg) (crc uint32,
err = closeErr
}
}()
- var writer = bufio.NewWriterSize(f, 4*1024*1024)
- var crc32 = crc32.NewIEEE()
- var varintTmp = make([]byte, binary.MaxVarintLen64)
+ writer := bufio.NewWriterSize(f, 4*1024*1024)
+ crc32 := crc32.NewIEEE()
+ varintTmp := make([]byte, binary.MaxVarintLen64)
var n int
// write number of extends
n = binary.PutUvarint(varintTmp, uint64(extendTree.Len()))
@@ -1225,10 +1221,10 @@ func (mp *metaPartition) storeExtend(rootDir string, sm *storeMsg) (crc uint32,
}
func (mp *metaPartition) storeMultipart(rootDir string, sm *storeMsg) (crc uint32, err error) {
- var multipartTree = sm.multipartTree
- var fp = path.Join(rootDir, multipartFile)
+ multipartTree := sm.multipartTree
+ fp := path.Join(rootDir, multipartFile)
var f *os.File
- f, err = os.OpenFile(fp, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.O_CREATE, 0755)
+ f, err = os.OpenFile(fp, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.O_CREATE, 0o755)
if err != nil {
return
}
@@ -1238,9 +1234,9 @@ func (mp *metaPartition) storeMultipart(rootDir string, sm *storeMsg) (crc uint3
err = closeErr
}
}()
- var writer = bufio.NewWriterSize(f, 4*1024*1024)
- var crc32 = crc32.NewIEEE()
- var varintTmp = make([]byte, binary.MaxVarintLen64)
+ writer := bufio.NewWriterSize(f, 4*1024*1024)
+ crc32 := crc32.NewIEEE()
+ varintTmp := make([]byte, binary.MaxVarintLen64)
var n int
// write number of extends
n = binary.PutUvarint(varintTmp, uint64(multipartTree.Len()))
@@ -1292,7 +1288,7 @@ func (mp *metaPartition) storeMultipart(rootDir string, sm *storeMsg) (crc uint3
func (mp *metaPartition) storeUniqID(rootDir string, sm *storeMsg) (err error) {
filename := path.Join(rootDir, uniqIDFile)
fp, err := os.OpenFile(filename, os.O_RDWR|os.O_APPEND|os.O_TRUNC|os.
- O_CREATE, 0755)
+ O_CREATE, 0o755)
if err != nil {
return
}
@@ -1311,7 +1307,7 @@ func (mp *metaPartition) storeUniqID(rootDir string, sm *storeMsg) (err error) {
func (mp *metaPartition) storeUniqChecker(rootDir string, sm *storeMsg) (crc uint32, err error) {
filename := path.Join(rootDir, uniqCheckerFile)
fp, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os.
- O_CREATE, 0755)
+ O_CREATE, 0o755)
if err != nil {
return
}
diff --git a/metanode/partition_store_ticket.go b/metanode/partition_store_ticket.go
index 6a50e0685..5ec80fd88 100644
--- a/metanode/partition_store_ticket.go
+++ b/metanode/partition_store_ticket.go
@@ -16,11 +16,11 @@ package metanode
import (
"encoding/binary"
- "github.com/cubefs/cubefs/proto"
"sync/atomic"
"time"
"github.com/cubefs/cubefs/cmd/common"
+ "github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/errors"
"github.com/cubefs/cubefs/util/exporter"
"github.com/cubefs/cubefs/util/log"
diff --git a/metanode/partition_test.go b/metanode/partition_test.go
index 1beca8c5a..04b45188c 100644
--- a/metanode/partition_test.go
+++ b/metanode/partition_test.go
@@ -15,14 +15,14 @@
package metanode
import (
- "github.com/cubefs/cubefs/proto"
- "io/ioutil"
"os"
"path"
"testing"
"time"
"github.com/stretchr/testify/require"
+
+ "github.com/cubefs/cubefs/proto"
)
func TestMetaPartition_LoadSnapshot(t *testing.T) {
@@ -126,14 +126,13 @@ func TestMetaPartition_LoadSnapshot(t *testing.T) {
os.Rename(path.Join(snapshotPath, dentryFile+"1"), path.Join(snapshotPath, dentryFile))
// modify crc file
- crcData, err := ioutil.ReadFile(path.Join(snapshotPath, SnapshotSign))
+ crcData, err := os.ReadFile(path.Join(snapshotPath, SnapshotSign))
require.Nil(t, err)
require.True(t, len(crcData) != 0)
crcData[0] = '0'
crcData[1] = '1'
- err = ioutil.WriteFile(path.Join(snapshotPath, SnapshotSign), crcData, 0644)
+ err = os.WriteFile(path.Join(snapshotPath, SnapshotSign), crcData, 0o644)
require.Nil(t, err)
err = partition.LoadSnapshot(snapshotPath)
require.Equal(t, ErrSnapshotCrcMismatch, err)
-
}
diff --git a/metanode/raft_server.go b/metanode/raft_server.go
index 1f62cfa61..d5d2f3c65 100644
--- a/metanode/raft_server.go
+++ b/metanode/raft_server.go
@@ -32,7 +32,7 @@ func (m *MetaNode) startRaftServer(cfg *config.Config) (err error) {
if !os.IsNotExist(err) {
return
}
- if err = os.MkdirAll(m.raftDir, 0755); err != nil {
+ if err = os.MkdirAll(m.raftDir, 0o755); err != nil {
err = errors.NewErrorf("create raft server dir: %s", err.Error())
return
}
diff --git a/metanode/server.go b/metanode/server.go
index 2ea3182b3..ebc8817ef 100644
--- a/metanode/server.go
+++ b/metanode/server.go
@@ -19,10 +19,10 @@ import (
"io"
"net"
- "github.com/cubefs/cubefs/util"
"github.com/xtaci/smux"
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/log"
)
diff --git a/metanode/sorted_extents.go b/metanode/sorted_extents.go
index 406c5ad3e..f5cf65794 100644
--- a/metanode/sorted_extents.go
+++ b/metanode/sorted_extents.go
@@ -5,11 +5,9 @@ import (
"encoding/json"
"sync"
- "github.com/cubefs/cubefs/util/log"
-
- "github.com/cubefs/cubefs/storage"
-
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/storage"
+ "github.com/cubefs/cubefs/util/log"
)
type SortedExtents struct {
@@ -314,7 +312,7 @@ func (se *SortedExtents) SplitWithCheck(mpId uint64, inodeID uint64, ekSplit pro
ExtentId: key.ExtentId,
ExtentOffset: key.ExtentOffset + uint64(key.Size) + uint64(ekSplit.Size),
Size: keySize - key.Size - ekSplit.Size,
- //crc
+ // crc
SnapInfo: &proto.ExtSnapInfo{
VerSeq: key.GetSeq(),
ModGen: 0,
diff --git a/metanode/sorted_extents_test.go b/metanode/sorted_extents_test.go
index 2d41b196f..60f7bb909 100644
--- a/metanode/sorted_extents_test.go
+++ b/metanode/sorted_extents_test.go
@@ -104,7 +104,7 @@ func TestSortedMarshal(t *testing.T) {
ExtentId: 10,
ExtentOffset: 10110,
PartitionId: 100,
- CRC: 0000,
+ CRC: 0o000,
}
e2 := proto.ExtentKey{
FileOffset: 4,
@@ -112,7 +112,7 @@ func TestSortedMarshal(t *testing.T) {
ExtentId: 10,
ExtentOffset: 1010,
PartitionId: 100,
- CRC: 0200,
+ CRC: 0o200,
}
se.eks = append(se.eks, e1)
diff --git a/metanode/transaction.go b/metanode/transaction.go
index 261ff4bcf..f2d8ea66b 100644
--- a/metanode/transaction.go
+++ b/metanode/transaction.go
@@ -20,20 +20,21 @@ import (
"encoding/json"
"errors"
"fmt"
- "golang.org/x/time/rate"
"net"
"strconv"
"strings"
"sync"
"time"
+ "golang.org/x/time/rate"
+
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/btree"
"github.com/cubefs/cubefs/util/log"
)
-//Rollback Type
+// Rollback Type
const (
TxNoOp uint8 = iota
TxUpdate
@@ -52,7 +53,7 @@ func (i *TxRollbackInode) ToString() string {
type TxRollbackInode struct {
inode *Inode
txInodeInfo *proto.TxInodeInfo
- rbType uint8 //Rollback Type
+ rbType uint8 // Rollback Type
quotaIds []uint32
}
@@ -72,7 +73,6 @@ func (i *TxRollbackInode) Less(than btree.Item) bool {
// Copy returns a copy of the TxRollbackInode.
func (i *TxRollbackInode) Copy() btree.Item {
-
item := i.inode.Copy()
txInodeInfo := *i.txInodeInfo
@@ -184,7 +184,7 @@ func NewTxRollbackInode(inode *Inode, quotaIds []uint32, txInodeInfo *proto.TxIn
type TxRollbackDentry struct {
dentry *Dentry
txDentryInfo *proto.TxDentryInfo
- rbType uint8 //Rollback Type `
+ rbType uint8 // Rollback Type `
}
func (d *TxRollbackDentry) ToString() string {
@@ -294,9 +294,9 @@ func NewTxRollbackDentry(dentry *Dentry, txDentryInfo *proto.TxDentryInfo, rbTyp
}
}
-//TM
+// TM
type TransactionManager struct {
- //need persistence and sync to all the raft members of the mp
+ // need persistence and sync to all the raft members of the mp
txIdAlloc *TxIDAllocator
txTree *BTree
txProcessor *TransactionProcessor
@@ -305,17 +305,17 @@ type TransactionManager struct {
sync.RWMutex
}
-//RM
+// RM
type TransactionResource struct {
- txRbInodeTree *BTree //key: inode id
+ txRbInodeTree *BTree // key: inode id
txRbDentryTree *BTree // key: parentId_name
txProcessor *TransactionProcessor
sync.RWMutex
}
type TransactionProcessor struct {
- txManager *TransactionManager //TM
- txResource *TransactionResource //RM
+ txManager *TransactionManager // TM
+ txResource *TransactionResource // RM
mp *metaPartition
mask proto.TxOpMask
}
@@ -648,9 +648,8 @@ func (tm *TransactionManager) addTxInfo(txInfo *proto.TransactionInfo) {
tm.txTree.ReplaceOrInsert(txInfo, true)
}
-//TM register a transaction, process client transaction
+// TM register a transaction, process client transaction
func (tm *TransactionManager) registerTransaction(txInfo *proto.TransactionInfo) (err error) {
-
if uint64(txInfo.TmID) == tm.txProcessor.mp.config.PartitionId {
if err := tm.updateTxIdCursor(txInfo.TxID); err != nil {
log.LogErrorf("updateTxIdCursor failed, txInfo %s, err %s", txInfo.String(), err.Error())
@@ -848,7 +847,7 @@ func (tm *TransactionManager) commitTx(txId string, skipSetStat bool) (status ui
return
}
- //1.set transaction to TxStateCommit
+ // 1.set transaction to TxStateCommit
if !skipSetStat && tx.State != proto.TxStateCommit {
status, err = tm.setTransactionState(txId, proto.TxStateCommit)
if status != proto.OpOk {
@@ -857,13 +856,13 @@ func (tm *TransactionManager) commitTx(txId string, skipSetStat bool) (status ui
}
}
- //2. notify all related RMs that a transaction is completed
+ // 2. notify all related RMs that a transaction is completed
status = tm.sendToRM(tx, proto.OpTxCommitRM)
if status != proto.OpOk {
return
}
- //3. TM commit the transaction
+ // 3. TM commit the transaction
req := proto.TxApplyRequest{
TxID: txId,
}
@@ -971,7 +970,7 @@ func (tm *TransactionManager) rollbackTx(txId string, skipSetStat bool) (status
return
}
- //1.set transaction to TxStateRollback
+ // 1.set transaction to TxStateRollback
if !skipSetStat && tx.State != proto.TxStateRollback {
status, err = tm.setTransactionState(txId, proto.TxStateRollback)
if status != proto.OpOk {
@@ -980,7 +979,7 @@ func (tm *TransactionManager) rollbackTx(txId string, skipSetStat bool) (status
}
}
- //2. notify all related RMs that a transaction is completed
+ // 2. notify all related RMs that a transaction is completed
status = tm.sendToRM(tx, proto.OpTxRollbackRM)
if status != proto.OpOk {
return
@@ -995,7 +994,6 @@ func (tm *TransactionManager) rollbackTx(txId string, skipSetStat bool) (status
}
resp, err := tm.txProcessor.mp.submit(opFSMTxRollback, val)
-
if err != nil {
log.LogWarnf("commitTx: rollback transaction[%v] failed, err[%v]", txId, err)
return proto.OpAgain, err
@@ -1192,9 +1190,9 @@ func (tr *TransactionResource) Reset() {
tr.txProcessor = nil
}
-//check if item(inode, dentry) is in transaction for modifying
+// check if item(inode, dentry) is in transaction for modifying
func (tr *TransactionResource) isInodeInTransction(ino *Inode) (inTx bool, txID string) {
- //return true only if specified inode is in an ongoing transaction(not expired yet)
+ // return true only if specified inode is in an ongoing transaction(not expired yet)
tr.Lock()
defer tr.Unlock()
@@ -1271,7 +1269,7 @@ func (tr *TransactionResource) deleteTxRollbackInode(ino uint64, txId string) (s
return proto.OpOk
}
-//RM add an `TxRollbackInode` into `txRollbackInodes`
+// RM add an `TxRollbackInode` into `txRollbackInodes`
func (tr *TransactionResource) addTxRollbackInode(rbInode *TxRollbackInode) (status uint8) {
tr.Lock()
defer tr.Unlock()
@@ -1296,7 +1294,6 @@ func (tr *TransactionResource) addTxRollbackInode(rbInode *TxRollbackInode) (sta
}
func (tr *TransactionResource) getTxRbDentry(pId uint64, name string) *TxRollbackDentry {
-
keyNode := &TxRollbackDentry{
txDentryInfo: proto.NewTxDentryInfo("", pId, name, 0),
}
@@ -1333,7 +1330,7 @@ func (tr *TransactionResource) deleteTxRollbackDentry(pid uint64, name, txId str
return proto.OpOk
}
-//RM add a `TxRollbackDentry` into `txRollbackDentries`
+// RM add a `TxRollbackDentry` into `txRollbackDentries`
func (tr *TransactionResource) addTxRollbackDentry(rbDentry *TxRollbackDentry) (status uint8) {
tr.Lock()
defer tr.Unlock()
@@ -1409,7 +1406,7 @@ func (tr *TransactionResource) rollbackInodeInternal(rbInode *TxRollbackInode) (
return
}
-//RM roll back an inode, retry if error occours
+// RM roll back an inode, retry if error occours
func (tr *TransactionResource) rollbackInode(req *proto.TxInodeApplyRequest) (status uint8, err error) {
tr.Lock()
defer tr.Unlock()
@@ -1468,7 +1465,7 @@ func (tr *TransactionResource) rollbackDentryInternal(rbDentry *TxRollbackDentry
return
}
-//RM roll back a dentry, retry if error occours
+// RM roll back a dentry, retry if error occours
func (tr *TransactionResource) rollbackDentry(req *proto.TxDentryApplyRequest) (status uint8, err error) {
tr.Lock()
defer tr.Unlock()
@@ -1503,7 +1500,7 @@ func (tr *TransactionResource) rollbackDentry(req *proto.TxDentryApplyRequest) (
return
}
-//RM simplely remove the inode from TransactionResource
+// RM simplely remove the inode from TransactionResource
func (tr *TransactionResource) commitInode(txID string, inode uint64) (status uint8, err error) {
tr.Lock()
defer tr.Unlock()
@@ -1530,7 +1527,7 @@ func (tr *TransactionResource) commitInode(txID string, inode uint64) (status ui
return
}
-//RM simplely remove the dentry from TransactionResource
+// RM simplely remove the dentry from TransactionResource
func (tr *TransactionResource) commitDentry(txID string, pId uint64, name string) (status uint8, err error) {
tr.Lock()
defer tr.Unlock()
diff --git a/metanode/transaction_test.go b/metanode/transaction_test.go
index 1b909865a..b8d6f8aa0 100644
--- a/metanode/transaction_test.go
+++ b/metanode/transaction_test.go
@@ -16,19 +16,23 @@ package metanode
import (
"fmt"
- "github.com/cubefs/cubefs/util/log"
"reflect"
"testing"
"time"
- "github.com/cubefs/cubefs/proto"
"github.com/stretchr/testify/assert"
+
+ "github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/util/log"
)
-//var manager = &metadataManager{}
+// var manager = &metadataManager{}
var mp1 *metaPartition
-var mp2 *metaPartition
-var mp3 *metaPartition
+
+var (
+ mp2 *metaPartition
+ mp3 *metaPartition
+)
const FileModeType uint32 = 420
@@ -46,8 +50,7 @@ func init() {
}
func newMetaPartition(PartitionId uint64, manager *metadataManager) (mp *metaPartition) {
-
- var metaConf = &MetaPartitionConfig{
+ metaConf := &MetaPartitionConfig{
PartitionId: PartitionId,
VolName: "testVol",
PartitionType: proto.VolumeTypeHot,
@@ -76,7 +79,6 @@ func newMetaPartition(PartitionId uint64, manager *metadataManager) (mp *metaPar
}
func initMps(t *testing.T) {
-
test = true
mp1 = newMetaPartition(10001, &metadataManager{})
mp2 = newMetaPartition(10002, &metadataManager{})
@@ -101,7 +103,6 @@ func (i *TxRollbackInode) Equal(txRbInode *TxRollbackInode) bool {
}
func TestRollbackInodeLess(t *testing.T) {
-
inode := NewInode(101, 0)
txInodeInfo := proto.NewTxInodeInfo(MemberAddrs, inodeNum, 10001)
rbInode := NewTxRollbackInode(inode, []uint32{}, txInodeInfo, TxAdd)
@@ -121,7 +122,7 @@ func TestRollbackInodeSerialization(t *testing.T) {
Gid: 11,
Uid: 10,
Size: 101,
- Type: 0755,
+ Type: 0o755,
Generation: 13,
CreateTime: 102,
AccessTime: 104,
@@ -224,22 +225,22 @@ func TestTxMgrOp(t *testing.T) {
txId := txInfo.TxID
txMgr := mp1.txProcessor.txManager
- //register
+ // register
id := txMgr.txIdAlloc.getTransactionID()
expectedId := fmt.Sprintf("%d_%d", mp1.config.PartitionId, id)
assert.Equal(t, expectedId, txId)
txMgr.registerTransaction(txInfo)
- //get
+ // get
gotTxInfo := txMgr.getTransaction(txId)
assert.Equal(t, txInfo, gotTxInfo)
- //rollback
+ // rollback
txMgr.rollbackTxInfo(txId)
gotTxInfo = txMgr.getTransaction(txId)
assert.True(t, gotTxInfo.IsDone())
- //commit
+ // commit
status, _ := txMgr.commitTxInfo("dummy_txId")
assert.Equal(t, proto.OpTxInfoNotExistErr, status)
}
@@ -248,7 +249,7 @@ func TestTxRscOp(t *testing.T) {
initMps(t)
txMgr := mp1.txProcessor.txManager
- //rbInode
+ // rbInode
txInodeInfo1 := proto.NewTxInodeInfo(MemberAddrs, inodeNum, 10001)
txInodeInfo1.TxID = txMgr.nextTxID()
txInodeInfo1.Timeout = 5
@@ -274,7 +275,7 @@ func TestTxRscOp(t *testing.T) {
status = txRsc.addTxRollbackInode(rbInode2)
assert.Equal(t, proto.OpTxConflictErr, status)
- //rbDentry
+ // rbDentry
txDentryInfo1 := proto.NewTxDentryInfo(MemberAddrs, pInodeNum, dentryName, 10001)
dentry := &Dentry{
ParentId: pInodeNum,
@@ -391,7 +392,7 @@ func mockDeleteTxDentry(mp *metaPartition) *TxRollbackDentry {
func TestTxRscRollback(t *testing.T) {
initMps(t)
- //roll back add inode
+ // roll back add inode
rbInode1 := mockAddTxInode(mp1)
txRsc := mp1.txProcessor.txResource
req1 := &proto.TxInodeApplyRequest{
@@ -401,7 +402,7 @@ func TestTxRscRollback(t *testing.T) {
status, err := txRsc.rollbackInode(req1)
assert.True(t, status == proto.OpOk && err == nil)
- //roll back delete inode
+ // roll back delete inode
rbInode2 := mockDeleteTxInode(mp1)
req2 := &proto.TxInodeApplyRequest{
TxID: rbInode2.txInodeInfo.TxID,
@@ -410,7 +411,7 @@ func TestTxRscRollback(t *testing.T) {
status, err = txRsc.rollbackInode(req2)
assert.True(t, status == proto.OpOk && err == nil)
- //roll back add dentry
+ // roll back add dentry
rbDentry1 := mockAddTxDentry(mp1)
req3 := &proto.TxDentryApplyRequest{
TxID: rbDentry1.txDentryInfo.TxID,
@@ -420,7 +421,7 @@ func TestTxRscRollback(t *testing.T) {
status, err = txRsc.rollbackDentry(req3)
assert.True(t, status == proto.OpOk && err == nil)
- //roll back delete dentry
+ // roll back delete dentry
rbDentry2 := mockDeleteTxDentry(mp1)
req4 := &proto.TxDentryApplyRequest{
TxID: rbDentry2.txDentryInfo.TxID,
@@ -433,23 +434,23 @@ func TestTxRscRollback(t *testing.T) {
func TestTxRscCommit(t *testing.T) {
initMps(t)
- //commit add inode
+ // commit add inode
rbInode1 := mockAddTxInode(mp1)
txRsc := mp1.txProcessor.txResource
status, err := txRsc.commitInode(rbInode1.txInodeInfo.TxID, rbInode1.inode.Inode)
assert.True(t, status == proto.OpOk && err == nil)
- //commit delete inode
+ // commit delete inode
rbInode2 := mockDeleteTxInode(mp1)
status, err = txRsc.commitInode(rbInode2.txInodeInfo.TxID, rbInode2.inode.Inode)
assert.True(t, status == proto.OpOk && err == nil)
- //commit add dentry
+ // commit add dentry
rbDentry1 := mockAddTxDentry(mp1)
status, err = txRsc.commitDentry(rbDentry1.txDentryInfo.TxID, rbDentry1.txDentryInfo.ParentId, rbDentry1.txDentryInfo.Name)
assert.True(t, status == proto.OpOk && err == nil)
- //commit delete dentry
+ // commit delete dentry
rbDentry2 := mockDeleteTxDentry(mp1)
status, err = txRsc.commitDentry(rbDentry2.txDentryInfo.TxID, rbDentry2.txDentryInfo.ParentId, rbDentry2.txDentryInfo.Name)
assert.True(t, status == proto.OpOk && err == nil)
@@ -469,7 +470,7 @@ func TestTxTreeRollback(t *testing.T) {
txInfo.TmID = int64(mp1.config.PartitionId)
txMgr := mp1.txProcessor.txManager
- //register
+ // register
id := txMgr.txIdAlloc.getTransactionID()
expectedId := fmt.Sprintf("%d_%d", mp1.config.PartitionId, id)
assert.Equal(t, expectedId, txId)
@@ -484,7 +485,7 @@ func TestTxTreeRollback(t *testing.T) {
func TestCheckTxLimit(t *testing.T) {
initMps(t)
txMgr := mp1.txProcessor.txManager
- //txMgr.Start()
+ // txMgr.Start()
txMgr.setLimit(10)
txMgr.opLimiter.SetBurst(1)
txInfo := proto.NewTransactionInfo(0, proto.TxTypeCreate)
@@ -500,7 +501,7 @@ func TestCheckTxLimit(t *testing.T) {
func TestGetTxHandler(t *testing.T) {
initMps(t)
txMgr := mp1.txProcessor.txManager
- //txMgr.Start()
+ // txMgr.Start()
txInfo := proto.NewTransactionInfo(0, proto.TxTypeCreate)
txDentryInfo := proto.NewTxDentryInfo(MemberAddrs, pInodeNum, dentryName, 10001)
@@ -509,7 +510,7 @@ func TestGetTxHandler(t *testing.T) {
mp1.initTxInfo(txInfo)
}
- //register
+ // register
txMgr.registerTransaction(txInfo)
var (
req = &proto.TxGetInfoRequest{
diff --git a/metanode/txid_allocator.go b/metanode/txid_allocator.go
index f253290a2..6916625c2 100644
--- a/metanode/txid_allocator.go
+++ b/metanode/txid_allocator.go
@@ -25,7 +25,7 @@ type TxIDAllocator struct {
txIDLock sync.RWMutex
}
-//func newTxIDAllocator(mpID uint64, partition raftstore.Partition) (alloc *TxIDAllocator) {
+// func newTxIDAllocator(mpID uint64, partition raftstore.Partition) (alloc *TxIDAllocator) {
func newTxIDAllocator() (alloc *TxIDAllocator) {
alloc = new(TxIDAllocator)
return
diff --git a/metanode/uniq_checker.go b/metanode/uniq_checker.go
index c142ab884..ee5b367ba 100644
--- a/metanode/uniq_checker.go
+++ b/metanode/uniq_checker.go
@@ -191,7 +191,7 @@ func (checker *uniqChecker) doEvict(evictBid uint64) {
defer checker.Unlock()
cnt := 0
- //evict from map
+ // evict from map
if _, ok := checker.op[evictBid]; ok {
checker.inQue.scan(func(op *uniqOp) bool {
cnt++
@@ -207,10 +207,10 @@ func (checker *uniqChecker) doEvict(evictBid uint64) {
return
}
- //truncate from queue
+ // truncate from queue
checker.inQue.truncate(cnt - 1)
- //regular rebuild map to reduce memory usage
+ // regular rebuild map to reduce memory usage
n := timeutil.GetCurrentTimeUnix()
if n-checker.rtime > opRebuildSec {
checker.op = make(map[uint64]struct{}, checker.inQue.len())
diff --git a/metanode/uniq_checker_test.go b/metanode/uniq_checker_test.go
index 51e6943a1..a8e89f439 100644
--- a/metanode/uniq_checker_test.go
+++ b/metanode/uniq_checker_test.go
@@ -86,7 +86,6 @@ func TestOpQueue(t *testing.T) {
if q.len() != 0 || len(q.cur.s) != 0 || len(q.ss) != 1 {
t.Fatalf("op queue trancate failed")
}
-
}
func TestClone(t *testing.T) {
@@ -109,7 +108,6 @@ func TestClone(t *testing.T) {
i++
return true
})
-
}
func TestMarshal(t *testing.T) {
diff --git a/metanode/util.go b/metanode/util.go
index 8053ab9a2..db6534673 100644
--- a/metanode/util.go
+++ b/metanode/util.go
@@ -19,7 +19,6 @@ func (del DelExtFile) Swap(i, j int) {
}
func (del DelExtFile) Less(i, j int) bool {
-
idx1 := getDelExtFileIdx(del[i].Name())
idx2 := getDelExtFileIdx(del[j].Name())
diff --git a/objectnode/acl_api_test.go b/objectnode/acl_api_test.go
index f72d6f996..3b9ff05fa 100644
--- a/objectnode/acl_api_test.go
+++ b/objectnode/acl_api_test.go
@@ -375,7 +375,6 @@ func TestParseAcl_XmlBodyAcl(t *testing.T) {
req.ContentLength = int64(len(aclExample))
_, err = ParseACL(req, "user", true, false)
require.EqualError(t, err, AccessDenied.Error())
-
}
func TestCreateDefaultACL(t *testing.T) {
diff --git a/objectnode/api_handler_bucket.go b/objectnode/api_handler_bucket.go
index 2a8b8e6eb..27d4a1541 100644
--- a/objectnode/api_handler_bucket.go
+++ b/objectnode/api_handler_bucket.go
@@ -20,7 +20,6 @@ import (
"encoding/json"
"encoding/xml"
"io"
- "io/ioutil"
"net/http"
"regexp"
"strings"
@@ -94,7 +93,7 @@ func (o *ObjectNode) createBucketHandler(w http.ResponseWriter, r *http.Request)
return
}
if length > 0 {
- requestBytes, err := ioutil.ReadAll(r.Body)
+ requestBytes, err := io.ReadAll(r.Body)
if err != nil && err != io.EOF {
log.LogErrorf("createBucketHandler: read request body fail: requestID(%v) err(%v)", GetRequestID(r), err)
return
@@ -333,7 +332,7 @@ func (o *ObjectNode) getBucketTaggingHandler(w http.ResponseWriter, r *http.Requ
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if len(param.Bucket()) == 0 {
errorCode = InvalidBucketName
return
@@ -358,7 +357,7 @@ func (o *ObjectNode) getBucketTaggingHandler(w http.ResponseWriter, r *http.Requ
return
}
ossTaggingData := xattrInfo.Get(XAttrKeyOSSTagging)
- var output, _ = ParseTagging(string(ossTaggingData))
+ output, _ := ParseTagging(string(ossTaggingData))
if nil == output || len(output.TagSet) == 0 {
errorCode = NoSuchTagSetError
return
@@ -386,7 +385,7 @@ func (o *ObjectNode) putBucketTaggingHandler(w http.ResponseWriter, r *http.Requ
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -410,14 +409,14 @@ func (o *ObjectNode) putBucketTaggingHandler(w http.ResponseWriter, r *http.Requ
return
}
var body []byte
- if body, err = ioutil.ReadAll(r.Body); err != nil {
+ if body, err = io.ReadAll(r.Body); err != nil {
log.LogErrorf("putBucketTaggingHandler: read request body data fail: requestID(%v) err(%v)",
GetRequestID(r), err)
errorCode = InvalidArgument
return
}
- var tagging = NewTagging()
+ tagging := NewTagging()
if err = UnmarshalXMLEntity(body, tagging); err != nil {
log.LogWarnf("putBucketTaggingHandler: unmarshal request body fail: requestID(%v) body(%v) err(%v)",
GetRequestID(r), string(body), err)
@@ -453,7 +452,7 @@ func (o *ObjectNode) deleteBucketTaggingHandler(w http.ResponseWriter, r *http.R
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if len(param.Bucket()) == 0 {
errorCode = InvalidBucketName
return
@@ -509,7 +508,7 @@ func (o *ObjectNode) putObjectLockConfigurationHandler(w http.ResponseWriter, r
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -521,7 +520,7 @@ func (o *ObjectNode) putObjectLockConfigurationHandler(w http.ResponseWriter, r
return
}
var body []byte
- if body, err = ioutil.ReadAll(io.LimitReader(r.Body, MaxObjectLockSize+1)); err != nil {
+ if body, err = io.ReadAll(io.LimitReader(r.Body, MaxObjectLockSize+1)); err != nil {
log.LogErrorf("putObjectLockConfigurationHandler: read request body fail: requestID(%v) volume(%v) err(%v)",
GetRequestID(r), vol.Name(), err)
return
@@ -563,7 +562,7 @@ func (o *ObjectNode) getObjectLockConfigurationHandler(w http.ResponseWriter, r
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
diff --git a/objectnode/api_handler_multipart.go b/objectnode/api_handler_multipart.go
index 00f7472c6..46c03d6da 100644
--- a/objectnode/api_handler_multipart.go
+++ b/objectnode/api_handler_multipart.go
@@ -19,7 +19,6 @@ import (
"encoding/hex"
"encoding/xml"
"io"
- "io/ioutil"
"net/http"
"strconv"
"strings"
@@ -49,7 +48,7 @@ func (o *ObjectNode) createMultipleUploadHandler(w http.ResponseWriter, r *http.
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -98,7 +97,7 @@ func (o *ObjectNode) createMultipleUploadHandler(w http.ResponseWriter, r *http.
}
// Checking user-defined metadata
- var metadata = ParseUserDefinedMetadata(r.Header)
+ metadata := ParseUserDefinedMetadata(r.Header)
// Check 'x-amz-tagging' header
var tagging *Tagging
@@ -116,7 +115,7 @@ func (o *ObjectNode) createMultipleUploadHandler(w http.ResponseWriter, r *http.
GetRequestID(r), acl, err)
return
}
- var opt = &PutFileOption{
+ opt := &PutFileOption{
MIMEType: contentType,
Disposition: contentDisposition,
Tagging: tagging,
@@ -164,7 +163,7 @@ func (o *ObjectNode) uploadPartHandler(w http.ResponseWriter, r *http.Request) {
}()
// check args
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
// get upload id and part number
uploadId := param.GetVar(ParamUploadId)
partNumber := param.GetVar(ParamPartNumber)
@@ -285,7 +284,7 @@ func (o *ObjectNode) uploadPartCopyHandler(w http.ResponseWriter, r *http.Reques
}()
// step1: check args
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
uploadId := param.GetVar(ParamUploadId)
partNumber := param.GetVar(ParamPartNumber)
if uploadId == "" || partNumber == "" {
@@ -443,7 +442,7 @@ func (o *ObjectNode) listPartsHandler(w http.ResponseWriter, r *http.Request) {
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
// get upload id and part number
uploadId := param.GetVar(ParamUploadId)
maxParts := param.GetVar(ParamMaxParts)
@@ -632,7 +631,7 @@ func (o *ObjectNode) completeMultipartUploadHandler(w http.ResponseWriter, r *ht
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
// get upload id and part number
uploadId := param.GetVar(ParamUploadId)
if uploadId == "" {
@@ -673,7 +672,7 @@ func (o *ObjectNode) completeMultipartUploadHandler(w http.ResponseWriter, r *ht
if errorCode != nil {
return
}
- requestBytes, err := ioutil.ReadAll(r.Body)
+ requestBytes, err := io.ReadAll(r.Body)
if err != nil && err != io.EOF {
log.LogErrorf("completeMultipartUploadHandler: read request body fail: requestID(%v) err(%v)",
GetRequestID(r), err)
@@ -783,7 +782,7 @@ func (o *ObjectNode) abortMultipartUploadHandler(w http.ResponseWriter, r *http.
}()
// check args
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
uploadId := param.GetVar(ParamUploadId)
if uploadId == "" {
errorCode = InvalidArgument
@@ -839,7 +838,7 @@ func (o *ObjectNode) listMultipartUploadsHandler(w http.ResponseWriter, r *http.
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
// get list uploads parameter
prefix := param.GetVar(ParamPrefix)
keyMarker := param.GetVar(ParamKeyMarker)
@@ -894,7 +893,7 @@ func (o *ObjectNode) listMultipartUploadsHandler(w http.ResponseWriter, r *http.
uploads := NewUploads(fsUploads, param.AccessKey())
- var commonPrefixes = make([]*CommonPrefix, 0)
+ commonPrefixes := make([]*CommonPrefix, 0)
for _, prefix := range prefixes {
commonPrefix := &CommonPrefix{
Prefix: prefix,
diff --git a/objectnode/api_handler_object.go b/objectnode/api_handler_object.go
index 1e0a1c526..49b8ef017 100644
--- a/objectnode/api_handler_object.go
+++ b/objectnode/api_handler_object.go
@@ -20,7 +20,6 @@ import (
"encoding/xml"
"fmt"
"io"
- "io/ioutil"
"net/http"
"net/url"
"regexp"
@@ -54,7 +53,7 @@ func (o *ObjectNode) getObjectHandler(w http.ResponseWriter, r *http.Request) {
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -182,7 +181,7 @@ func (o *ObjectNode) getObjectHandler(w http.ResponseWriter, r *http.Request) {
}
// compute content length
- var contentLength = uint64(fileInfo.Size)
+ contentLength := uint64(fileInfo.Size)
if isRangeRead {
contentLength = rangeUpper - rangeLower + 1
}
@@ -270,7 +269,7 @@ func (o *ObjectNode) getObjectHandler(w http.ResponseWriter, r *http.Request) {
}
// get object content
- var offset = rangeLower
+ offset := rangeLower
size, err := safeConvertInt64ToUint64(fileInfo.Size)
fileSize := size
if err != nil {
@@ -375,7 +374,7 @@ func (o *ObjectNode) headObjectHandler(w http.ResponseWriter, r *http.Request) {
}()
// check args
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -544,7 +543,7 @@ func (o *ObjectNode) deleteObjectsHandler(w http.ResponseWriter, r *http.Request
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -567,7 +566,7 @@ func (o *ObjectNode) deleteObjectsHandler(w http.ResponseWriter, r *http.Request
if errorCode != nil {
return
}
- bytes, err := ioutil.ReadAll(r.Body)
+ bytes, err := io.ReadAll(r.Body)
if err != nil {
log.LogErrorf("deleteObjectsHandler: read request body fail: requestID(%v) volume(%v) err(%v)",
GetRequestID(r), param.Bucket(), err)
@@ -726,7 +725,7 @@ func (o *ObjectNode) copyObjectHandler(w http.ResponseWriter, r *http.Request) {
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -945,7 +944,7 @@ func (o *ObjectNode) getBucketV1Handler(w http.ResponseWriter, r *http.Request)
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -1020,9 +1019,9 @@ func (o *ObjectNode) getBucketV1Handler(w http.ResponseWriter, r *http.Request)
}
// get owner
- var bucketOwner = NewBucketOwner(vol)
+ bucketOwner := NewBucketOwner(vol)
log.LogDebugf("Owner: %v", bucketOwner)
- var contents = make([]*Content, 0, len(result.Files))
+ contents := make([]*Content, 0, len(result.Files))
for _, file := range result.Files {
if file.Mode == 0 {
// Invalid file mode, which means that the inode of the file may not exist.
@@ -1042,7 +1041,7 @@ func (o *ObjectNode) getBucketV1Handler(w http.ResponseWriter, r *http.Request)
contents = append(contents, content)
}
- var commonPrefixes = make([]*CommonPrefix, 0)
+ commonPrefixes := make([]*CommonPrefix, 0)
for _, prefix := range result.CommonPrefixes {
commonPrefix := &CommonPrefix{
Prefix: prefix,
@@ -1085,7 +1084,7 @@ func (o *ObjectNode) getBucketV2Handler(w http.ResponseWriter, r *http.Request)
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -1187,7 +1186,7 @@ func (o *ObjectNode) getBucketV2Handler(w http.ResponseWriter, r *http.Request)
bucketOwner = NewBucketOwner(vol)
}
- var contents = make([]*Content, 0)
+ contents := make([]*Content, 0)
if len(result.Files) > 0 {
for _, file := range result.Files {
if file.Mode == 0 {
@@ -1210,7 +1209,7 @@ func (o *ObjectNode) getBucketV2Handler(w http.ResponseWriter, r *http.Request)
}
}
- var commonPrefixes = make([]*CommonPrefix, 0)
+ commonPrefixes := make([]*CommonPrefix, 0)
for _, prefix := range result.CommonPrefixes {
commonPrefix := &CommonPrefix{
Prefix: prefix,
@@ -1254,7 +1253,7 @@ func (o *ObjectNode) putObjectHandler(w http.ResponseWriter, r *http.Request) {
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -1692,7 +1691,7 @@ func (o *ObjectNode) deleteObjectHandler(w http.ResponseWriter, r *http.Request)
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -1750,7 +1749,7 @@ func (o *ObjectNode) getObjectTaggingHandler(w http.ResponseWriter, r *http.Requ
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -1787,7 +1786,7 @@ func (o *ObjectNode) getObjectTaggingHandler(w http.ResponseWriter, r *http.Requ
ossTaggingData := xattrInfo.Get(XAttrKeyOSSTagging)
- var output, _ = ParseTagging(string(ossTaggingData))
+ output, _ := ParseTagging(string(ossTaggingData))
response, err := MarshalXMLEntity(output)
if err != nil {
log.LogErrorf("getObjectTaggingHandler: xml marshal result fail: requestID(%v) result(%v) err(%v)",
@@ -1812,7 +1811,7 @@ func (o *ObjectNode) putObjectTaggingHandler(w http.ResponseWriter, r *http.Requ
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -1841,14 +1840,14 @@ func (o *ObjectNode) putObjectTaggingHandler(w http.ResponseWriter, r *http.Requ
return
}
var requestBody []byte
- if requestBody, err = ioutil.ReadAll(r.Body); err != nil {
+ if requestBody, err = io.ReadAll(r.Body); err != nil {
log.LogErrorf("putObjectTaggingHandler: read request body data fail: requestID(%v) err(%v)",
GetRequestID(r), err)
errorCode = InvalidArgument
return
}
- var tagging = NewTagging()
+ tagging := NewTagging()
if err = xml.Unmarshal(requestBody, tagging); err != nil {
log.LogWarnf("putObjectTaggingHandler: decode request body fail: requestID(%v) err(%v)",
GetRequestID(r), err)
@@ -1890,7 +1889,7 @@ func (o *ObjectNode) deleteObjectTaggingHandler(w http.ResponseWriter, r *http.R
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -1938,7 +1937,7 @@ func (o *ObjectNode) putObjectXAttrHandler(w http.ResponseWriter, r *http.Reques
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if len(param.Bucket()) == 0 {
errorCode = InvalidBucketName
return
@@ -1966,7 +1965,7 @@ func (o *ObjectNode) putObjectXAttrHandler(w http.ResponseWriter, r *http.Reques
return
}
var requestBody []byte
- if requestBody, err = ioutil.ReadAll(r.Body); err != nil {
+ if requestBody, err = io.ReadAll(r.Body); err != nil {
errorCode = &ErrorCode{
ErrorCode: "BadRequest",
ErrorMessage: err.Error(),
@@ -1974,7 +1973,7 @@ func (o *ObjectNode) putObjectXAttrHandler(w http.ResponseWriter, r *http.Reques
}
return
}
- var putXAttrRequest = PutXAttrRequest{}
+ putXAttrRequest := PutXAttrRequest{}
if err = xml.Unmarshal(requestBody, &putXAttrRequest); err != nil {
errorCode = &ErrorCode{
ErrorCode: "BadRequest",
@@ -1983,7 +1982,7 @@ func (o *ObjectNode) putObjectXAttrHandler(w http.ResponseWriter, r *http.Reques
}
return
}
- var key, value = putXAttrRequest.XAttr.Key, putXAttrRequest.XAttr.Value
+ key, value := putXAttrRequest.XAttr.Key, putXAttrRequest.XAttr.Value
if len(key) == 0 {
return
}
@@ -2015,7 +2014,7 @@ func (o *ObjectNode) getObjectXAttrHandler(w http.ResponseWriter, r *http.Reques
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if len(param.Bucket()) == 0 {
errorCode = InvalidBucketName
return
@@ -2085,7 +2084,7 @@ func (o *ObjectNode) deleteObjectXAttrHandler(w http.ResponseWriter, r *http.Req
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if len(param.Bucket()) == 0 {
errorCode = InvalidBucketName
return
@@ -2141,7 +2140,7 @@ func (o *ObjectNode) listObjectXAttrs(w http.ResponseWriter, r *http.Request) {
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if len(param.Bucket()) == 0 {
errorCode = InvalidBucketName
return
@@ -2204,7 +2203,7 @@ func (o *ObjectNode) getObjectRetentionHandler(w http.ResponseWriter, r *http.Re
}()
// check args
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -2297,7 +2296,7 @@ func GetContentLength(r *http.Request) int64 {
func VerifyContentLength(r *http.Request, bodyLimit int64) (int64, *ErrorCode) {
dcl := r.Header.Get(HeaderNameXAmzDecodedContentLength)
- var length = r.ContentLength
+ length := r.ContentLength
if dcl != "" {
l, err := strconv.ParseInt(dcl, 10, 64)
if err == nil {
diff --git a/objectnode/api_middleware.go b/objectnode/api_middleware.go
index cd1d0449a..4895d869d 100644
--- a/objectnode/api_middleware.go
+++ b/objectnode/api_middleware.go
@@ -33,9 +33,7 @@ import (
const StatusServerPanic = 597
-var (
- routeSNRegexp = regexp.MustCompile(":(\\w){32}$")
-)
+var routeSNRegexp = regexp.MustCompile(":(\\w){32}$")
func IsMonitoredStatusCode(code int) bool {
if code > http.StatusInternalServerError {
@@ -53,7 +51,7 @@ func generateWarnDetail(r *http.Request, errorInfo string) string {
statusCode int
)
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
bucket = param.Bucket()
object = param.Object()
action = GetActionFromContext(r)
@@ -80,7 +78,7 @@ func (o *ObjectNode) auditMiddleware(next http.Handler) http.Handler {
// After receiving the request, the handler will assign a unique RequestID to
// the request and record the processing time of the request.
func (o *ObjectNode) traceMiddleware(next http.Handler) http.Handler {
- var generateRequestID = func() (string, error) {
+ generateRequestID := func() (string, error) {
var uUID uuid.UUID
var err error
if uUID, err = uuid.NewRandom(); err != nil {
@@ -124,10 +122,10 @@ func (o *ObjectNode) traceMiddleware(next http.Handler) http.Handler {
w.Header().Set(Connection, "keep-alive")
}
- var action = ActionFromRouteName(mux.CurrentRoute(r).GetName())
+ action := ActionFromRouteName(mux.CurrentRoute(r).GetName())
SetRequestAction(r, action)
- var startTime = time.Now()
+ startTime := time.Now()
metric := exporter.NewTPCnt(fmt.Sprintf("action_%v", action.Name()))
defer func() {
metric.Set(err)
@@ -147,7 +145,7 @@ func (o *ObjectNode) traceMiddleware(next http.Handler) http.Handler {
}
// failed request monitor
- var statusCode = GetStatusCodeFromContext(r)
+ statusCode := GetStatusCodeFromContext(r)
if IsMonitoredStatusCode(statusCode) {
exporter.NewTPCnt(fmt.Sprintf("failed_%v", statusCode)).Set(nil)
exporter.Warning(generateWarnDetail(r, getResponseErrorMessage(r)))
@@ -257,9 +255,8 @@ func (o *ObjectNode) expectMiddleware(next http.Handler) http.Handler {
// Access-Control-Max-Age [0]
func (o *ObjectNode) corsMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-
var err error
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
next.ServeHTTP(w, r)
return
diff --git a/objectnode/auth_signature_chunk_test.go b/objectnode/auth_signature_chunk_test.go
index 0f875e32f..cc3a0308b 100644
--- a/objectnode/auth_signature_chunk_test.go
+++ b/objectnode/auth_signature_chunk_test.go
@@ -16,7 +16,7 @@ package objectnode
import (
"bytes"
- "io/ioutil"
+ "io"
"strings"
"testing"
@@ -50,7 +50,7 @@ func TestSignChunkedReader(t *testing.T) {
seed := "4f232c4386841ef735655705268965c44a0e4690baa4adea153f7db9fa80a0a9"
reader := NewSignChunkedReader(buf, key, scope, datetime, seed)
- b, err := ioutil.ReadAll(reader)
+ b, err := io.ReadAll(reader)
require.NoError(t, err)
require.Equal(t, 66560, len(b))
require.Equal(t, strings.Repeat("a", 66560), string(b))
diff --git a/objectnode/const.go b/objectnode/const.go
index 040fba556..8caef1107 100644
--- a/objectnode/const.go
+++ b/objectnode/const.go
@@ -172,7 +172,7 @@ const (
)
const (
- DefaultFileMode = 0644
+ DefaultFileMode = 0o644
DefaultDirMode = DefaultFileMode | os.ModeDir
)
diff --git a/objectnode/cors_handler.go b/objectnode/cors_handler.go
index 3ff2c3499..0a872be63 100644
--- a/objectnode/cors_handler.go
+++ b/objectnode/cors_handler.go
@@ -18,7 +18,6 @@ package objectnode
import (
"io"
- "io/ioutil"
"net/http"
"github.com/cubefs/cubefs/util/log"
@@ -38,7 +37,7 @@ func (o *ObjectNode) getBucketCorsHandler(w http.ResponseWriter, r *http.Request
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -82,7 +81,7 @@ func (o *ObjectNode) putBucketCorsHandler(w http.ResponseWriter, r *http.Request
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -99,7 +98,7 @@ func (o *ObjectNode) putBucketCorsHandler(w http.ResponseWriter, r *http.Request
return
}
var body []byte
- if body, err = ioutil.ReadAll(io.LimitReader(r.Body, MaxCORSSize+1)); err != nil {
+ if body, err = io.ReadAll(io.LimitReader(r.Body, MaxCORSSize+1)); err != nil {
log.LogErrorf("putBucketCorsHandler: read request body fail: requestID(%v) volume(%v) err(%v)",
GetRequestID(r), vol.Name(), err)
return
@@ -138,7 +137,7 @@ func (o *ObjectNode) deleteBucketCorsHandler(w http.ResponseWriter, r *http.Requ
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
diff --git a/objectnode/etag_test.go b/objectnode/etag_test.go
index 35842a9e7..549554b9d 100644
--- a/objectnode/etag_test.go
+++ b/objectnode/etag_test.go
@@ -31,7 +31,8 @@ var samples = []sample{
etagValue: ETagValue{
Value: "41f9ede9b03b89d80f3a8460d7792ff6",
PartNum: 0,
- TS: time.Unix(0, 0)},
+ TS: time.Unix(0, 0),
+ },
etag: "41f9ede9b03b89d80f3a8460d7792ff6",
},
{
@@ -39,7 +40,8 @@ var samples = []sample{
etagValue: ETagValue{
Value: "41f9ede9b03b89d80f3a8460d7792ff6",
PartNum: 23,
- TS: time.Unix(0, 0)},
+ TS: time.Unix(0, 0),
+ },
etag: "41f9ede9b03b89d80f3a8460d7792ff6-23",
},
{
@@ -47,7 +49,8 @@ var samples = []sample{
etagValue: ETagValue{
Value: "41f9ede9b03b89d80f3a8460d7792ff6",
PartNum: 0,
- TS: time.Unix(1588562233, 0)},
+ TS: time.Unix(1588562233, 0),
+ },
etag: "41f9ede9b03b89d80f3a8460d7792ff6",
},
{
@@ -55,7 +58,8 @@ var samples = []sample{
etagValue: ETagValue{
Value: "41f9ede9b03b89d80f3a8460d7792ff6",
PartNum: 23,
- TS: time.Unix(1588562233, 0)},
+ TS: time.Unix(1588562233, 0),
+ },
etag: "41f9ede9b03b89d80f3a8460d7792ff6-23",
},
}
diff --git a/objectnode/fs_manager.go b/objectnode/fs_manager.go
index d416f6837..f3321d74f 100644
--- a/objectnode/fs_manager.go
+++ b/objectnode/fs_manager.go
@@ -20,7 +20,6 @@ import (
"time"
"github.com/cubefs/cubefs/proto"
-
"github.com/cubefs/cubefs/sdk/master"
"github.com/cubefs/cubefs/util/log"
)
@@ -88,7 +87,7 @@ func (loader *VolumeLoader) VolumeWithoutBlacklist(volName string) (*Volume, err
func (loader *VolumeLoader) syncVolumeInit(volume string) (releaseFunc func()) {
value, _ := loader.volInitMap.LoadOrStore(volume, new(sync.Mutex))
- var initMu = value.(*sync.Mutex)
+ initMu := value.(*sync.Mutex)
initMu.Lock()
log.LogDebugf("syncVolumeInit: get volume init lock: volume(%v)", volume)
return func() {
@@ -106,7 +105,7 @@ func (loader *VolumeLoader) loadVolumeWithoutBlacklist(volName string) (*Volume,
volume, exist = loader.volumes[volName]
loader.volMu.RUnlock()
if !exist {
- var release = loader.syncVolumeInit(volName)
+ release := loader.syncVolumeInit(volName)
loader.volMu.RLock()
volume, exist = loader.volumes[volName]
if exist {
@@ -123,7 +122,7 @@ func (loader *VolumeLoader) loadVolumeWithoutBlacklist(volName string) (*Volume,
default:
}
}
- var config = &VolumeConfig{
+ config := &VolumeConfig{
Volume: volName,
Masters: loader.masters,
Store: loader.store,
@@ -169,7 +168,7 @@ func (loader *VolumeLoader) loadVolume(volName string) (*Volume, error) {
loader.volMu.RUnlock()
log.LogDebugf("loadVolume: load volume from volumes: name(%v) exist(%v) volume(%+v)", volName, exist, volume)
if !exist {
- var release = loader.syncVolumeInit(volName)
+ release := loader.syncVolumeInit(volName)
loader.volMu.RLock()
volume, exist = loader.volumes[volName]
if exist {
@@ -188,7 +187,7 @@ func (loader *VolumeLoader) loadVolume(volName string) (*Volume, error) {
default:
}
}
- var config = &VolumeConfig{
+ config := &VolumeConfig{
Volume: volName,
Masters: loader.masters,
Store: loader.store,
diff --git a/objectnode/fs_store.go b/objectnode/fs_store.go
index e8e647b9a..06fa56f27 100644
--- a/objectnode/fs_store.go
+++ b/objectnode/fs_store.go
@@ -14,8 +14,7 @@
package objectnode
-type MetaStore interface {
-}
+type MetaStore interface{}
// MetaStore
type Store interface {
diff --git a/objectnode/fs_store_object.go b/objectnode/fs_store_object.go
index e71fb5a52..8a4d0d727 100644
--- a/objectnode/fs_store_object.go
+++ b/objectnode/fs_store_object.go
@@ -28,7 +28,7 @@ type objectStore struct {
func (s *objectStore) Init(vm *VolumeManager) {
s.vm = vm
- //TODO: init meta dir
+ // TODO: init meta dir
}
func (s *objectStore) Put(vol, obj, key string, data []byte) (err error) {
diff --git a/objectnode/fs_store_user.go b/objectnode/fs_store_user.go
index 79fa6e523..478ad1804 100644
--- a/objectnode/fs_store_user.go
+++ b/objectnode/fs_store_user.go
@@ -20,11 +20,9 @@ import (
"sync"
"time"
- "github.com/cubefs/cubefs/util/exporter"
-
- "github.com/cubefs/cubefs/sdk/master"
-
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/sdk/master"
+ "github.com/cubefs/cubefs/util/exporter"
"github.com/cubefs/cubefs/util/log"
)
@@ -180,7 +178,7 @@ func (us *CacheUserInfoLoader) scheduleUpdate() {
func (us *CacheUserInfoLoader) syncUserInit(accessKey string) (releaseFunc func()) {
value, _ := us.akInitMap.LoadOrStore(accessKey, new(sync.Mutex))
- var initMu = value.(*sync.Mutex)
+ initMu := value.(*sync.Mutex)
initMu.Lock()
log.LogDebugf("syncUserInit: get user init lock: accessKey(%v)", accessKey)
return func() {
@@ -206,7 +204,7 @@ func (us *CacheUserInfoLoader) LoadUser(accessKey string) (*proto.UserInfo, erro
userInfo, exist = us.akInfoStore[accessKey]
us.akInfoMutex.RUnlock()
if !exist {
- var release = us.syncUserInit(accessKey)
+ release := us.syncUserInit(accessKey)
us.akInfoMutex.RLock()
userInfo, exist = us.akInfoStore[accessKey]
if exist {
diff --git a/objectnode/fs_store_xattr.go b/objectnode/fs_store_xattr.go
index e295cd151..2cfe2cfd1 100644
--- a/objectnode/fs_store_xattr.go
+++ b/objectnode/fs_store_xattr.go
@@ -27,7 +27,7 @@ const (
)
type xattrStore struct {
- vm *VolumeManager //vol *Volume
+ vm *VolumeManager // vol *Volume
}
func (s *xattrStore) Init(vm *VolumeManager) {
@@ -105,6 +105,5 @@ func (s *xattrStore) Delete(vol, path, key string) (err error) {
}
func (s *xattrStore) List(vol, obj string) (data [][]byte, err error) {
-
return
}
diff --git a/objectnode/fs_volume.go b/objectnode/fs_volume.go
index 0a46f299d..c7bb65a54 100644
--- a/objectnode/fs_volume.go
+++ b/objectnode/fs_volume.go
@@ -318,7 +318,7 @@ func (v *Volume) SetXAttr(path string, key string, data []byte, autoCreate bool)
return err
}
if err == syscall.ENOENT {
- var dirs, filename = splitPath(path)
+ dirs, filename := splitPath(path)
var parentID uint64
if parentID, err = v.lookupDirectories(dirs, true); err != nil {
return err
@@ -370,7 +370,7 @@ func (v *Volume) GetXAttr(path string, key string) (info *proto.XAttrInfo, err e
var notUseCache bool
if objMetaCache != nil {
- var retry = 0
+ retry := 0
for {
if _, inode, _, _, err = v.recursiveLookupTarget(path, notUseCache); err != nil {
return v.getXAttr(path, key)
@@ -434,7 +434,6 @@ func (v *Volume) GetXAttr(path string, key string) (info *proto.XAttrInfo, err e
}
return v.getXAttr(path, key)
-
}
func (v *Volume) DeleteXAttr(path string, key string) (err error) {
@@ -471,7 +470,7 @@ func (v *Volume) ListXAttrs(path string) (keys []string, err error) {
var notUseCache bool
if objMetaCache != nil {
- var retry = 0
+ retry := 0
for {
if _, inode, _, _, err = v.recursiveLookupTarget(path, notUseCache); err != nil {
return v.listXAttrs(path)
@@ -513,7 +512,6 @@ func (v *Volume) ListXAttrs(path string) (keys []string, err error) {
return
}
return v.listXAttrs(path)
-
}
func (v *Volume) OSSSecure() (accessKey, secretKey string) {
@@ -609,12 +607,12 @@ func (v *Volume) PutObject(path string, reader io.Reader, opt *PutFileOption) (f
// The path is processed according to the content-type. If it is a directory type,
// a path separator is appended at the end of the path, so the recursiveMakeDirectory
// method can be processed directly in recursion.
- var fixedPath = path
+ fixedPath := path
if opt != nil && opt.MIMEType == ValueContentTypeDirectory && !strings.HasSuffix(path, pathSep) {
fixedPath = path + pathSep
}
- var pathItems = NewPathIterator(fixedPath).ToSlice()
+ pathItems := NewPathIterator(fixedPath).ToSlice()
if len(pathItems) == 0 {
// A blank directory entry indicates that the path after the validation is the volume
// root directory itself.
@@ -636,7 +634,7 @@ func (v *Volume) PutObject(path string, reader io.Reader, opt *PutFileOption) (f
v.name, path, err)
return
}
- var lastPathItem = pathItems[len(pathItems)-1]
+ lastPathItem := pathItems[len(pathItems)-1]
if lastPathItem.IsDirectory {
// If the last path node is a directory, then it has been processed by the previous logic.
// Just get the information of this node and return.
@@ -741,7 +739,7 @@ func (v *Volume) PutObject(path string, reader io.Reader, opt *PutFileOption) (f
return
}
- var etagValue = ETagValue{
+ etagValue := ETagValue{
Value: hex.EncodeToString(md5Hash.Sum(nil)),
PartNum: 0,
TS: finalInode.ModifyTime,
@@ -958,7 +956,7 @@ func (v *Volume) InitMultipart(path string, opt *PutFileOption) (multipartID str
}
// If tagging have been specified, use extend attributes for storage.
if opt != nil && opt.Tagging != nil {
- var encoded = opt.Tagging.Encode()
+ encoded := opt.Tagging.Encode()
extend[XAttrKeyOSSTagging] = encoded
}
// If ACL have been specified, use extend attributes for storage.
@@ -1197,7 +1195,7 @@ func (v *Volume) CompleteMultipart(path, multipartID string, multipartInfo *prot
var size uint64
var fileOffset uint64
if proto.IsCold(v.volType) {
- var completeObjExtentKeys = make([]proto.ObjExtentKey, 0)
+ completeObjExtentKeys := make([]proto.ObjExtentKey, 0)
for _, part := range parts {
var objExtents []proto.ObjExtentKey
if _, _, _, objExtents, err = v.mw.GetObjExtents(part.Inode); err != nil {
@@ -1218,7 +1216,7 @@ func (v *Volume) CompleteMultipart(path, multipartID string, multipartInfo *prot
return
}
} else {
- var completeExtentKeys = make([]proto.ExtentKey, 0)
+ completeExtentKeys := make([]proto.ExtentKey, 0)
for _, part := range parts {
var eks []proto.ExtentKey
if _, _, eks, err = v.mw.GetExtents(part.Inode); err != nil {
@@ -1246,7 +1244,7 @@ func (v *Volume) CompleteMultipart(path, multipartID string, multipartInfo *prot
if len(parts) == 1 {
md5Val = parts[0].MD5
} else {
- var md5Hash = md5.New()
+ md5Hash := md5.New()
for _, part := range parts {
md5Hash.Write([]byte(part.MD5))
}
@@ -1262,7 +1260,7 @@ func (v *Volume) CompleteMultipart(path, multipartID string, multipartInfo *prot
return
}
- var etagValue = ETagValue{
+ etagValue := ETagValue{
Value: md5Val,
PartNum: len(parts),
TS: finalInode.ModifyTime,
@@ -1419,7 +1417,7 @@ func (v *Volume) appendInodeHash(h hash.Hash, inode uint64, total uint64, preAll
}
}()
- var buf = preAllocatedBuf
+ buf := preAllocatedBuf
if len(buf) == 0 {
buf = make([]byte, 1024*64)
}
@@ -1510,7 +1508,7 @@ func (v *Volume) loadUserDefinedMetadata(inode uint64) (metadata map[string]stri
v.name, inode, err)
return
}
- var xattrKeys = make([]string, 0)
+ xattrKeys := make([]string, 0)
for _, storedXAttrKey := range storedXAttrKeys {
if !strings.HasPrefix(storedXAttrKey, "oss:") {
xattrKeys = append(xattrKeys, storedXAttrKey)
@@ -1551,7 +1549,7 @@ func (v *Volume) readFile(inode, inodeSize uint64, path string, writer io.Writer
}
func (v *Volume) readEbs(inode, inodeSize uint64, path string, writer io.Writer, offset, size uint64) error {
- var upper = size + offset
+ upper := size + offset
if upper > inodeSize {
upper = inodeSize - offset
}
@@ -1561,7 +1559,7 @@ func (v *Volume) readEbs(inode, inodeSize uint64, path string, writer io.Writer,
reader := v.getEbsReader(inode)
var n int
var rest uint64
- var tmp = buf.ReadBufPool.Get().([]byte)
+ tmp := buf.ReadBufPool.Get().([]byte)
defer buf.ReadBufPool.Put(tmp)
for {
@@ -1600,19 +1598,19 @@ func (v *Volume) readEbs(inode, inodeSize uint64, path string, writer io.Writer,
}
func (v *Volume) read(inode, inodeSize uint64, path string, writer io.Writer, offset, size uint64) error {
- var upper = size + offset
+ upper := size + offset
if upper > inodeSize {
upper = inodeSize - offset
}
var n int
- var tmp = make([]byte, 2*util.BlockSize)
+ tmp := make([]byte, 2*util.BlockSize)
for {
- var rest = upper - offset
+ rest := upper - offset
if rest == 0 {
break
}
- var readSize = len(tmp)
+ readSize := len(tmp)
if uint64(readSize) > rest {
readSize = int(rest)
}
@@ -1667,7 +1665,7 @@ func (v *Volume) ObjectMeta(path string) (info *FSFileInfo, xattr *proto.XAttrIn
var inode uint64
var mode os.FileMode
var inoInfo *proto.InodeInfo
- var retry = 0
+ retry := 0
var notUseCache bool
for {
if _, inode, _, mode, err = v.recursiveLookupTarget(path, notUseCache); err != nil {
@@ -1740,7 +1738,7 @@ func (v *Volume) ObjectMeta(path string) (info *FSFileInfo, xattr *proto.XAttrIn
disposition = string(xattr.Get(XAttrKeyOSSDISPOSITION))
cacheControl = string(xattr.Get(XAttrKeyOSSCacheControl))
expires = string(xattr.Get(XAttrKeyOSSExpires))
- var rawETag = string(xattr.Get(XAttrKeyOSSETag))
+ rawETag := string(xattr.Get(XAttrKeyOSSETag))
if len(rawETag) == 0 {
rawETag = string(xattr.Get(XAttrKeyOSSETagDeprecated))
}
@@ -1810,7 +1808,7 @@ func (v *Volume) Close() error {
// pathname did not exist, or the pathname was an empty string.
func (v *Volume) recursiveLookupTarget(path string, notUseCache bool) (parent uint64, ino uint64, name string, mode os.FileMode, err error) {
parent = rootIno
- var pathIterator = NewPathIterator(path)
+ pathIterator := NewPathIterator(path)
if !pathIterator.HasNext() {
err = syscall.ENOENT
return
@@ -1820,7 +1818,7 @@ func (v *Volume) recursiveLookupTarget(path string, notUseCache bool) (parent ui
if objMetaCache != nil && !notUseCache {
for pathIterator.HasNext() {
- var pathItem = pathIterator.Next()
+ pathItem := pathIterator.Next()
var curIno uint64
var curMode uint32
dentry := &DentryItem{
@@ -1888,7 +1886,7 @@ func (v *Volume) recursiveLookupTarget(path string, notUseCache bool) (parent ui
return
}
for pathIterator.HasNext() {
- var pathItem = pathIterator.Next()
+ pathItem := pathIterator.Next()
var curIno uint64
var curMode uint32
curIno, curMode, err = v.mw.Lookup_ll(parent, pathItem.Name)
@@ -1979,13 +1977,13 @@ func (v *Volume) recursiveMakeDirectory(path string) (partentIno uint64, err err
// in case of any mv or rename operation within refresh interval of dentry item in cache,
// recursiveMakeDirectory don't look up cache, and will force update dentry item
partentIno = rootIno
- var pathIterator = NewPathIterator(path)
+ pathIterator := NewPathIterator(path)
if !pathIterator.HasNext() {
err = syscall.ENOENT
return
}
for pathIterator.HasNext() {
- var pathItem = pathIterator.Next()
+ pathItem := pathIterator.Next()
if !pathItem.IsDirectory {
break
}
@@ -2033,7 +2031,7 @@ func (v *Volume) recursiveMakeDirectory(path string) (partentIno uint64, err err
// Deprecated
func (v *Volume) lookupDirectories(dirs []string, autoCreate bool) (inode uint64, err error) {
- var parentId = rootIno
+ parentId := rootIno
// check and create dirs
for _, dir := range dirs {
curIno, curMode, lookupErr := v.mw.Lookup_ll(parentId, dir)
@@ -2084,7 +2082,7 @@ func (v *Volume) lookupDirectories(dirs []string, autoCreate bool) (inode uint64
func (v *Volume) listFilesV1(prefix, marker, delimiter string, maxKeys uint64, onlyObject bool) (infos []*FSFileInfo,
prefixes Prefixes, nextMarker string, err error) {
- var prefixMap = PrefixMap(make(map[string]struct{}))
+ prefixMap := PrefixMap(make(map[string]struct{}))
parentId, dirs, err := v.findParentId(prefix)
@@ -2131,7 +2129,7 @@ func (v *Volume) listFilesV1(prefix, marker, delimiter string, maxKeys uint64, o
func (v *Volume) listFilesV2(prefix, startAfter, contToken, delimiter string, maxKeys uint64) (infos []*FSFileInfo,
prefixes Prefixes, nextMarker string, err error) {
- var prefixMap = PrefixMap(make(map[string]struct{}))
+ prefixMap := PrefixMap(make(map[string]struct{}))
var marker string
if startAfter != "" {
@@ -2196,7 +2194,7 @@ func (v *Volume) findParentId(prefix string) (inode uint64, prefixDirs []string,
return proto.RootIno, prefixDirs, nil
}
- var parentId = proto.RootIno
+ parentId := proto.RootIno
for index, dir := range dirs {
// Because lookup can only retrieve dentry whose name exactly matches,
@@ -2241,7 +2239,7 @@ func (v *Volume) recursiveScan(fileInfos []*FSFileInfo, prefixMap PrefixMap, par
var nextMarker string
var lastKey string
- var currentPath = strings.Join(dirs, pathSep) + pathSep
+ currentPath := strings.Join(dirs, pathSep) + pathSep
if strings.HasPrefix(currentPath, pathSep) {
currentPath = strings.TrimPrefix(currentPath, pathSep)
}
@@ -2304,7 +2302,7 @@ readDir:
if child.Name == lastKey {
continue
}
- var path = strings.Join(append(dirs, child.Name), pathSep)
+ path := strings.Join(append(dirs, child.Name), pathSep)
if os.FileMode(child.Type).IsDir() {
path += pathSep
}
@@ -2330,9 +2328,9 @@ readDir:
}
if delimiter != "" {
- var nonPrefixPart = strings.Replace(path, prefix, "", 1)
+ nonPrefixPart := strings.Replace(path, prefix, "", 1)
if idx := strings.Index(nonPrefixPart, delimiter); idx >= 0 {
- var commonPrefix = prefix + util.SubString(nonPrefixPart, 0, idx) + delimiter
+ commonPrefix := prefix + util.SubString(nonPrefixPart, 0, idx) + delimiter
if prefixMap.contain(commonPrefix) {
continue
}
@@ -2433,8 +2431,8 @@ func (v *Volume) supplyListFileInfo(fileInfos []*FSFileInfo) (err error) {
})
var etagValue ETagValue
if i >= 0 && i < len(xattrs) && xattrs[i].Inode == fileInfo.Inode {
- var xattr = xattrs[i]
- var rawETag = string(xattr.Get(XAttrKeyOSSETag))
+ xattr := xattrs[i]
+ rawETag := string(xattr.Get(XAttrKeyOSSETag))
if len(rawETag) == 0 {
rawETag = string(xattr.Get(XAttrKeyOSSETagDeprecated))
}
@@ -2461,7 +2459,7 @@ func (v *Volume) updateETag(inode uint64, size int64, mt time.Time) (etagValue E
if size == 0 {
etagValue = EmptyContentETagValue(mt)
} else {
- var splittedRanges = SplitFileRange(size, SplitFileRangeBlockSize)
+ splittedRanges := SplitFileRange(size, SplitFileRangeBlockSize)
etagValue = NewRandomUUIDETagValue(len(splittedRanges), mt)
}
if err = v.mw.XAttrSet_ll(inode, []byte(XAttrKeyOSSETag), []byte(etagValue.Encode())); err != nil {
@@ -2484,7 +2482,7 @@ func (v *Volume) ListMultipartUploads(prefix, delimiter, keyMarker string, multi
var count uint64
var lastUpload *proto.MultipartInfo
for _, session := range sessions {
- var tempKey = session.Path
+ tempKey := session.Path
if len(prefix) > 0 {
if !strings.HasPrefix(tempKey, prefix) {
continue
@@ -2861,7 +2859,7 @@ func (v *Volume) CopyFile(sv *Volume, sourcePath, targetPath, metaDirective stri
v.name, targetPath, tInodeInfo.Inode, err)
return
}
- var etagValue = ETagValue{
+ etagValue := ETagValue{
Value: md5Value,
PartNum: 0,
TS: finalInode.ModifyTime,
@@ -2970,7 +2968,6 @@ func (v *Volume) CopyFile(sv *Volume, sourcePath, targetPath, metaDirective stri
}
func (v *Volume) copyFile(parentID uint64, newFileName string, sourceFileInode uint64, mode uint32, newPath string, sourcePath string) (info *proto.InodeInfo, err error) {
-
if err = v.mw.DentryCreate_ll(parentID, newFileName, sourceFileInode, mode, newPath); err != nil {
return
}
@@ -2982,7 +2979,7 @@ func (v *Volume) copyFile(parentID uint64, newFileName string, sourceFileInode u
func NewVolume(config *VolumeConfig) (*Volume, error) {
var err error
- var metaConfig = &meta.MetaConfig{
+ metaConfig := &meta.MetaConfig{
Volume: config.Volume,
Masters: config.Masters,
Authenticate: false,
@@ -3016,7 +3013,7 @@ func NewVolume(config *VolumeConfig) (*Volume, error) {
return nil, proto.ErrVolNotExists
}
- var extentConfig = &stream.ExtentConfig{
+ extentConfig := &stream.ExtentConfig{
Volume: config.Volume,
Masters: config.Masters,
FollowerRead: true,
diff --git a/objectnode/lifecycle_handler.go b/objectnode/lifecycle_handler.go
index e8838c7c2..457d457b5 100644
--- a/objectnode/lifecycle_handler.go
+++ b/objectnode/lifecycle_handler.go
@@ -17,7 +17,6 @@ package objectnode
import (
"encoding/xml"
"io"
- "io/ioutil"
"net/http"
"github.com/cubefs/cubefs/proto"
@@ -33,7 +32,7 @@ func (o *ObjectNode) getBucketLifecycleConfigurationHandler(w http.ResponseWrite
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -50,7 +49,7 @@ func (o *ObjectNode) getBucketLifecycleConfigurationHandler(w http.ResponseWrite
return
}
- var lifeCycle = NewLifeCycle()
+ lifeCycle := NewLifeCycle()
lifeCycle.Rules = make([]*Rule, 0)
for _, lc := range lcConf.Rules {
rule := &Rule{
@@ -84,7 +83,6 @@ func (o *ObjectNode) getBucketLifecycleConfigurationHandler(w http.ResponseWrite
writeSuccessResponseXML(w, data)
return
-
}
// API reference: https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/API/API_PutBucketLifecycleConfiguration.html
@@ -96,7 +94,7 @@ func (o *ObjectNode) putBucketLifecycleConfigurationHandler(w http.ResponseWrite
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
@@ -111,7 +109,7 @@ func (o *ObjectNode) putBucketLifecycleConfigurationHandler(w http.ResponseWrite
return
}
var requestBody []byte
- if requestBody, err = ioutil.ReadAll(r.Body); err != nil && err != io.EOF {
+ if requestBody, err = io.ReadAll(r.Body); err != nil && err != io.EOF {
log.LogErrorf("putBucketLifecycle failed: read request body data err: requestID(%v) err(%v)", GetRequestID(r), err)
errorCode = &ErrorCode{
ErrorCode: http.StatusText(http.StatusBadRequest),
@@ -121,7 +119,7 @@ func (o *ObjectNode) putBucketLifecycleConfigurationHandler(w http.ResponseWrite
return
}
- var lifeCycle = NewLifeCycle()
+ lifeCycle := NewLifeCycle()
if err = UnmarshalXMLEntity(requestBody, lifeCycle); err != nil {
log.LogWarnf("putBucketLifecycle failed: decode request body err: requestID(%v) err(%v)", GetRequestID(r), err)
errorCode = LifeCycleErrMalformedXML
@@ -179,7 +177,7 @@ func (o *ObjectNode) deleteBucketLifecycleConfigurationHandler(w http.ResponseWr
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
diff --git a/objectnode/lifecycle_test.go b/objectnode/lifecycle_test.go
index 8f9ed7d77..71e8dda12 100644
--- a/objectnode/lifecycle_test.go
+++ b/objectnode/lifecycle_test.go
@@ -48,20 +48,20 @@ func TestLifecycleConfiguration(t *testing.T) {
`
- var l1 = NewLifeCycle()
+ l1 := NewLifeCycle()
err := xml.Unmarshal([]byte(LifecycleXml), l1)
require.NoError(t, err)
- //same id
+ // same id
_, err = l1.Validate()
require.Equal(t, err, LifeCycleErrSameRuleID)
- //id = ""
+ // id = ""
l1.Rules[0].ID = ""
_, err = l1.Validate()
require.Equal(t, err, LifeCycleErrMissingRuleID)
- //len(id) > 255
+ // len(id) > 255
var id string
for i := 0; i < 256; i++ {
id += "a"
@@ -71,13 +71,13 @@ func TestLifecycleConfiguration(t *testing.T) {
require.Equal(t, err, LifeCycleErrTooLongRuleID)
l1.Rules[0].ID = "id"
- //invalid status
+ // invalid status
l1.Rules[0].Status = ""
_, err = l1.Validate()
require.Equal(t, err, LifeCycleErrMalformedXML)
l1.Rules[0].Status = "Enabled"
- //days < 0
+ // days < 0
day := -1
l1.Rules[0].Expire.Days = &day
_, err = l1.Validate()
@@ -85,7 +85,7 @@ func TestLifecycleConfiguration(t *testing.T) {
day = 0
l1.Rules[0].Expire.Days = &day
- //date
+ // date
l1.Rules[0].Expire.Days = nil
now := time.Now().In(time.UTC)
ti := time.Date(now.Year(), now.Month(), now.Day(), 1, 0, 0, 0, time.UTC)
@@ -93,13 +93,13 @@ func TestLifecycleConfiguration(t *testing.T) {
_, err = l1.Validate()
require.Equal(t, err, LifeCycleErrDateType)
- //days and date all nil
+ // days and date all nil
l1.Rules[0].Expire.Days = nil
l1.Rules[0].Expire.Date = nil
_, err = l1.Validate()
require.Equal(t, err, LifeCycleErrMalformedXML)
- //days and date
+ // days and date
day = 1
l1.Rules[0].Expire.Days = &day
ti = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC)
@@ -115,7 +115,7 @@ func TestLifecycleConfiguration(t *testing.T) {
_, err = l1.Validate()
require.Equal(t, err, LifeCycleErrMissingActions)
- //no err
+ // no err
l1.Rules = l1.Rules[:1]
ok, _ := l1.Validate()
require.Equal(t, true, ok)
diff --git a/objectnode/meta_cache.go b/objectnode/meta_cache.go
index 05f2cc0f1..b1488245e 100644
--- a/objectnode/meta_cache.go
+++ b/objectnode/meta_cache.go
@@ -49,7 +49,7 @@ func (attr *AttrItem) IsExpired() bool {
return false
}
-//VolumeInodeAttrsCache caches Attrs for Inodes
+// VolumeInodeAttrsCache caches Attrs for Inodes
type VolumeInodeAttrsCache struct {
sync.RWMutex
cache map[uint64]*list.Element
@@ -109,7 +109,6 @@ func (vac *VolumeInodeAttrsCache) mergeAttr(attr *AttrItem) {
vac.RUnlock()
vac.putAttr(attr)
-
}
func (vac *VolumeInodeAttrsCache) getAttr(inode uint64) *AttrItem {
@@ -198,7 +197,7 @@ func (vac *VolumeInodeAttrsCache) GetAccessStat() (accssNum, validHit, miss uint
return vac.accessStat.accessNum, vac.accessStat.validHit, vac.accessStat.miss
}
-//type DentryItem metanode.Dentry
+// type DentryItem metanode.Dentry
type DentryItem struct {
metanode.Dentry
expiredTime int64
@@ -215,7 +214,7 @@ func (di *DentryItem) IsExpired() bool {
return false
}
-//VolumeDentryCache accelerates translating S3 path to posix-compatible file system metadata within a volume
+// VolumeDentryCache accelerates translating S3 path to posix-compatible file system metadata within a volume
type VolumeDentryCache struct {
sync.RWMutex
cache map[string]*list.Element
@@ -512,7 +511,6 @@ func (omc *ObjMetaCache) GetDentry(volume string, key string) (dentry *DentryIte
}
log.LogDebugf("ObjMetaCache GetDentry: volume(%v), key(%v), dentry:(%v)", volume, key, dentry)
return dentry, dentry.IsExpired()
-
}
func (omc *ObjMetaCache) DeleteDentry(volume string, key string) {
diff --git a/objectnode/multipart_form.go b/objectnode/multipart_form.go
index 3fdc98e98..4d9bd72d3 100644
--- a/objectnode/multipart_form.go
+++ b/objectnode/multipart_form.go
@@ -18,7 +18,6 @@ import (
"bytes"
"errors"
"io"
- "io/ioutil"
"mime"
"mime/multipart"
"net/http"
@@ -213,7 +212,7 @@ func (fr *formReader) close() error {
return err
}
// discard the keys after "file" if exist
- io.Copy(ioutil.Discard, p)
+ io.Copy(io.Discard, p)
}
}
diff --git a/objectnode/multipart_form_test.go b/objectnode/multipart_form_test.go
index 71221d78c..bf5aea10a 100644
--- a/objectnode/multipart_form_test.go
+++ b/objectnode/multipart_form_test.go
@@ -16,7 +16,7 @@ package objectnode
import (
"bytes"
- "io/ioutil"
+ "io"
"mime/multipart"
"net/http"
"testing"
@@ -87,7 +87,7 @@ func TestFormRequest(t *testing.T) {
require.NoError(t, err)
defer f.Close()
require.Equal(t, int64(len(fileData)), size)
- fb, _ := ioutil.ReadAll(f)
+ fb, _ := io.ReadAll(f)
require.Equal(t, fileData, string(fb))
// 5. on disk
@@ -109,6 +109,6 @@ func TestFormRequest(t *testing.T) {
require.NoError(t, err)
defer f.Close()
require.Equal(t, int64(len(fileData)), size)
- fb, _ = ioutil.ReadAll(f)
+ fb, _ = io.ReadAll(f)
require.Equal(t, fileData, string(fb))
}
diff --git a/objectnode/policy_condition.go b/objectnode/policy_condition.go
index 66939edd6..c69f78b5a 100644
--- a/objectnode/policy_condition.go
+++ b/objectnode/policy_condition.go
@@ -110,7 +110,6 @@ type Operation interface {
// returns condition operator of this operation.
operator() operator
-
toMap() map[Key]ValueSet
}
diff --git a/objectnode/policy_condition_test.go b/objectnode/policy_condition_test.go
index 7bc4c3861..facd1ead6 100644
--- a/objectnode/policy_condition_test.go
+++ b/objectnode/policy_condition_test.go
@@ -11,7 +11,6 @@ import (
)
func TestCondition_UnmarshalJSON(t *testing.T) {
-
op1, err := newIPAddressOp(map[Key]ValueSet{AWSSourceIP: NewValueSet(NewStringValue("1.1.1.1"))})
require.NoError(t, err)
var expectCondition1 Condition = []Operation{op1}
@@ -48,7 +47,6 @@ func TestCondition_UnmarshalJSON(t *testing.T) {
require.Equal(t, testCase.expect, result, fmt.Sprintf("test case %v", i+1))
}
}
-
}
func TestCondition_CheckValid(t *testing.T) {
diff --git a/objectnode/policy_const.go b/objectnode/policy_const.go
index 3dbcb50a9..8dc774f9e 100644
--- a/objectnode/policy_const.go
+++ b/objectnode/policy_const.go
@@ -17,7 +17,7 @@ package objectnode
type PolicyCheckResult int
const (
- POLICY_UNKNOW PolicyCheckResult = iota + 1 //no policy or not match
+ POLICY_UNKNOW PolicyCheckResult = iota + 1 // no policy or not match
POLICY_ALLOW
POLICY_DENY
)
@@ -30,6 +30,7 @@ const (
REFERER = "Referer"
HOST = "Host"
)
+
const (
Principal_Any PrincipalElementType = "*"
S3_ACTION_PREFIX = "s3:"
@@ -37,15 +38,15 @@ const (
S3_PRINCIPAL_PREFIX = "AWS"
)
-//if more s3 api is supported by policy, need extend bucketApiList, objectApiList
+// if more s3 api is supported by policy, need extend bucketApiList, objectApiList
var bucketApiList = SliceString{LIST_OBJECTS, LIST_OBJECTS_V2, HEAD_BUCKET, DELETE_BUCKET, LIST_MULTIPART_UPLOADS, GET_BUCKET_LOCATION, GET_OBJECT_LOCK_CFG, PUT_OBJECT_LOCK_CFG}
var objectApiList = SliceString{GET_OBJECT, HEAD_OBJECT, DELETE_OBJECT, PUT_OBJECT, POST_OBJECT, INITIALE_MULTIPART_UPLOAD, UPLOAD_PART, UPLOAD_PART_COPY, COMPLETE_MULTIPART_UPLOAD, COPY_OBJECT, ABORT_MULTIPART_UPLOAD, LIST_PARTS, BATCH_DELETE, GET_OBJECT_RETENTION}
type SliceString []string
-//https://docs.aws.amazon.com/AmazonS3/latest/dev/using-with-s3-actions.html
+// https://docs.aws.amazon.com/AmazonS3/latest/dev/using-with-s3-actions.html
const (
- //object level
+ // object level
ACTION_GET_OBJECT = "getobject"
ACTION_DELETE_OBJECT = "deleteobject"
ACTION_PUT_OBJECT = "putobject"
@@ -53,7 +54,7 @@ const (
ACTION_LIST_MULTIPART_UPLOAD_PARTS = "listmultipartuploadparts"
ACTION_GET_OBJECT_RETENTION = "getobjectretention"
- //bucket level
+ // bucket level
ACTION_LIST_BUCKET = "listbucket"
ACTION_DELETE_BUCKET = "deletebucket"
ACTION_LIST_BUCKET_MULTIPART_UPLOADS = "listbucketmultipartuploads"
@@ -61,7 +62,7 @@ const (
ACTION_GET_OBJECT_LOCK_CFG = "getobjectlockconfiguration"
ACTION_PUT_OBJECT_LOCK_CFG = "putobjectlockconfiguration"
- //bucket + object level
+ // bucket + object level
ACTION_ANY = "*"
)
@@ -83,7 +84,7 @@ var S3ActionToApis = map[string]SliceString{
var allowAnonymousActions = SliceString{ACTION_GET_OBJECT}
-//if more bucket actions support policy, need extend validBucketActions
+// if more bucket actions support policy, need extend validBucketActions
var validBucketActions = SliceString{ACTION_LIST_BUCKET, ACTION_DELETE_BUCKET, ACTION_LIST_BUCKET_MULTIPART_UPLOADS, ACTION_GET_BUCKET_LOCATION, ACTION_PUT_OBJECT_LOCK_CFG, ACTION_GET_OBJECT_LOCK_CFG}
func isPolicyApi(apiName string) bool {
diff --git a/objectnode/policy_handler.go b/objectnode/policy_handler.go
index 222427529..f6d1b44cd 100644
--- a/objectnode/policy_handler.go
+++ b/objectnode/policy_handler.go
@@ -17,7 +17,6 @@ package objectnode
import (
"encoding/json"
"io"
- "io/ioutil"
"net/http"
"github.com/cubefs/cubefs/util/log"
@@ -33,7 +32,7 @@ func (o *ObjectNode) getBucketPolicyHandler(w http.ResponseWriter, r *http.Reque
o.errorResponse(w, r, err, ec)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
ec = InvalidBucketName
return
@@ -76,7 +75,7 @@ func (o *ObjectNode) putBucketPolicyHandler(w http.ResponseWriter, r *http.Reque
o.errorResponse(w, r, err, ec)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
ec = InvalidBucketName
return
@@ -88,7 +87,7 @@ func (o *ObjectNode) putBucketPolicyHandler(w http.ResponseWriter, r *http.Reque
return
}
- policyRaw, err := ioutil.ReadAll(io.LimitReader(r.Body, BucketPolicyLimitSize+1))
+ policyRaw, err := io.ReadAll(io.LimitReader(r.Body, BucketPolicyLimitSize+1))
if err != nil {
log.LogErrorf("putBucketPolicyHandler: read request body fail: requestID(%v) err(%v)", GetRequestID(r), err)
return
@@ -134,7 +133,7 @@ func (o *ObjectNode) deleteBucketPolicyHandler(w http.ResponseWriter, r *http.Re
o.errorResponse(w, r, err, errorCode)
}()
- var param = ParseRequestParam(r)
+ param := ParseRequestParam(r)
if param.Bucket() == "" {
errorCode = InvalidBucketName
return
diff --git a/objectnode/policy_ipaddressop.go b/objectnode/policy_ipaddressop.go
index 11664a61e..f7cd0c69b 100644
--- a/objectnode/policy_ipaddressop.go
+++ b/objectnode/policy_ipaddressop.go
@@ -27,6 +27,7 @@ import (
type ipAddressOp struct {
m map[Key][]*IPInfo
}
+
type IPInfo struct {
IP net.IP
Net *net.IPNet
@@ -45,7 +46,7 @@ func (op ipAddressOp) evaluate(values map[string]string) bool {
if IP == nil {
panic(fmt.Errorf("invalid IP address '%v'", requestValue))
}
- nothingMatched := true //all values not matched
+ nothingMatched := true // all values not matched
for _, IPInfo := range v {
if IPInfo.Net.Contains(IP) {
nothingMatched = false
@@ -61,7 +62,6 @@ func (op ipAddressOp) evaluate(values map[string]string) bool {
// returns condition key which is used by this condition operation.
// Key is always AWSSourceIP.
func (op ipAddressOp) keys() KeySet {
-
keys := make(KeySet)
for key := range op.m {
keys.Add(key)
@@ -147,7 +147,7 @@ func newIPAddressOp(m map[Key]ValueSet) (Operation, error) {
return NewIPAddressOp(newMap)
}
-//returns new IP address operation.
+// returns new IP address operation.
func NewIPAddressOp(m map[Key][]*IPInfo) (Operation, error) {
for key := range m {
if key != AWSSourceIP {
@@ -158,7 +158,7 @@ func NewIPAddressOp(m map[Key][]*IPInfo) (Operation, error) {
return &ipAddressOp{m: m}, nil
}
-//returns new Not IP address operation.
+// returns new Not IP address operation.
func newNotIPAddressOp(m map[Key]ValueSet) (Operation, error) {
newMap := make(map[Key][]*IPInfo)
for k, v := range m {
diff --git a/objectnode/policy_ipaddressop_test.go b/objectnode/policy_ipaddressop_test.go
index 871135d07..40f66c5c6 100644
--- a/objectnode/policy_ipaddressop_test.go
+++ b/objectnode/policy_ipaddressop_test.go
@@ -49,5 +49,4 @@ func TestIPAddressOpKeys(t *testing.T) {
if len(result.Difference(expect)) != 0 || len(expect.Difference(result)) != 0 {
t.Fatalf("expect two value set equal, expected: %v, got: %v\n", expect, result)
}
-
}
diff --git a/objectnode/policy_keyset.go b/objectnode/policy_keyset.go
index 8598aab86..047178b39 100644
--- a/objectnode/policy_keyset.go
+++ b/objectnode/policy_keyset.go
@@ -32,7 +32,7 @@ const (
// AWSSourceIP - key representing client's IP address (not intermittent proxies) of any API.
AWSSourceIP Key = "aws:SourceIp"
- //AWSHost - key representing client's request host of any API, this is not standard AWS key
+ // AWSHost - key representing client's request host of any API, this is not standard AWS key
AWSHost Key = "aws:Host"
)
@@ -62,7 +62,7 @@ func (key Key) MarshalJSON() ([]byte, error) {
return json.Marshal(string(key))
}
-//returns key operator which is stripped value of prefixes "aws:" and "s3:"
+// returns key operator which is stripped value of prefixes "aws:" and "s3:"
func (key Key) Name() string {
keyString := string(key)
@@ -124,7 +124,6 @@ func (set KeySet) AddAll(keys KeySet) {
for key := range keys {
set[key] = struct{}{}
}
-
}
// returns a key set contains difference of two key set.
diff --git a/objectnode/policy_match.go b/objectnode/policy_match.go
index db2873701..7230e9461 100644
--- a/objectnode/policy_match.go
+++ b/objectnode/policy_match.go
@@ -21,11 +21,13 @@ import (
"github.com/cubefs/cubefs/util/log"
)
-type ActionElementType string
-type ActionType []interface{}
-type PrincipalElementType string
-type PrincipalType map[string]interface{}
-type ResourceElementType string
+type (
+ ActionElementType string
+ ActionType []interface{}
+ PrincipalElementType string
+ PrincipalType map[string]interface{}
+ ResourceElementType string
+)
func (s *Statement) CheckPolicy(apiName string, uid string, conditionCheck map[string]string) PolicyCheckResult {
if s.match(apiName, uid, conditionCheck) {
@@ -67,7 +69,6 @@ func (s *Statement) match(apiName string, uid string, conditionCheck map[string]
//----------------------------------------------------------------------------------------------------------------
func (s *Statement) matchAction(apiName string) bool {
-
log.LogDebug("start to match action")
switch s.Action.(type) {
case []interface{}: //["s3:PutObject", "s3:GetObject","s3:DeleteObject"]
@@ -110,7 +111,7 @@ func (s *Statement) matchPrincipal(uid string) bool {
switch s.Principal.(type) {
case string: // "*" or "123"
return PrincipalElementType(s.Principal.(string)).match(uid)
- case map[string]interface{}: //from json, {"AWS":["11", "22"]} or {"AWS":"11"} or {"AWS":"*"}
+ case map[string]interface{}: // from json, {"AWS":["11", "22"]} or {"AWS":"11"} or {"AWS":"*"}
p := s.Principal.(map[string]interface{})
return PrincipalType(p).match(uid)
default:
@@ -147,23 +148,21 @@ func (p PrincipalType) match(uid string) bool {
//----------------------------------------------------------------------------------------------------------------
func (s *Statement) matchResource(apiName string, keyname interface{}) bool {
-
if IsBucketApi(apiName) {
return s.matchBucketInResource()
}
- if keyname == nil { //keyname shoudn't be nil for object api, even if keyname = ""
+ if keyname == nil { // keyname shoudn't be nil for object api, even if keyname = ""
return false
}
if _, ok := keyname.(string); !ok {
return false
}
return s.matchKeyInResource(keyname.(string))
-
}
func (s *Statement) matchBucketInResource() bool {
- //if resource list contains bucket format, then match, since bucketId already checked when put policy.
+ // if resource list contains bucket format, then match, since bucketId already checked when put policy.
switch s.Resource.(type) {
case string:
return ResourceElement(s.Resource.(string)).isBucketFormat()
@@ -180,10 +179,9 @@ func (s *Statement) matchBucketInResource() bool {
default:
return false
}
-
}
-func (s *Statement) matchKeyInResource(keyname string) bool { //可以处理 keyname="" 的case
+func (s *Statement) matchKeyInResource(keyname string) bool { // 可以处理 keyname="" 的case
switch s.Resource.(type) {
case string:
@@ -208,11 +206,11 @@ func ResourceElement(r string) ResourceElementType {
return ResourceElementType(r1)
}
-func (r ResourceElementType) isBucketFormat() bool { //bucketFormat support bucket api
+func (r ResourceElementType) isBucketFormat() bool { // bucketFormat support bucket api
return !r.isKeyFormat()
}
-func (r ResourceElementType) isKeyFormat() bool { //keyFormat support object api
+func (r ResourceElementType) isKeyFormat() bool { // keyFormat support object api
return strings.Contains(string(r), "/")
}
@@ -220,7 +218,7 @@ func (r ResourceElementType) match(keyname string) bool {
if !r.isKeyFormat() {
return false
}
- //extract regex : "examplebucket/abc/*" => rawPattern="abc/*"
+ // extract regex : "examplebucket/abc/*" => rawPattern="abc/*"
r1 := string(r)
i := strings.Index(r1, "/")
rawPattern := r1[i+1:]
@@ -241,10 +239,9 @@ func makeRegexPattern(raw string) string {
//----------------------------------------------------------------------------------------------------------------
func (s *Statement) matchCondition(conditionCheck map[string]string) bool {
- //condition is optional
+ // condition is optional
if s.Condition == nil {
return true
}
return s.Condition.Evaluate(conditionCheck)
-
}
diff --git a/objectnode/policy_match_test.go b/objectnode/policy_match_test.go
index 43209aeea..56616f13e 100644
--- a/objectnode/policy_match_test.go
+++ b/objectnode/policy_match_test.go
@@ -9,7 +9,7 @@ import (
)
func TestRegexp(t *testing.T) {
- //case1, any keyname
+ // case1, any keyname
raw := "*"
pattern := makeRegexPattern(raw)
@@ -20,7 +20,7 @@ func TestRegexp(t *testing.T) {
require.True(t, ok)
}
- //case2, specify name
+ // case2, specify name
raw = "user?/img/*/2019/*"
pattern = makeRegexPattern(raw)
@@ -40,7 +40,7 @@ func TestRegexp(t *testing.T) {
func TestResourceMatch(t *testing.T) {
var s Statement
- //case1: resource is bucket, specified object(case sensitive)
+ // case1: resource is bucket, specified object(case sensitive)
s.Resource = []interface{}{"arn:aws:s3:::mybucket", "arn:aws:s3:::mybucket/abc/*", "arn:aws:s3:::mybucket/ABD"}
b := s.matchResource(LIST_OBJECTS, nil)
require.True(t, b)
@@ -57,7 +57,7 @@ func TestResourceMatch(t *testing.T) {
b = s.matchResource(PUT_OBJECT, "ABC/ab")
require.False(t, b)
- //case2: resource is any object
+ // case2: resource is any object
s.Resource = "arn:aws:s3:::examplebucket/*"
keynames := []string{"", "*", "abc", "/*"}
for _, k := range keynames {
@@ -202,22 +202,22 @@ func TestIpMatch_InWhite_NotInBlack(t *testing.T) {
require.NoError(t, err)
conditionToCheck := map[string]string{}
- //white ip
+ // white ip
clientIps := []string{"1.2.3.6", "4.4.4.4"}
for _, ip := range clientIps {
conditionToCheck[SOURCEIP] = ip
result := s.matchCondition(conditionToCheck)
require.True(t, result)
}
- //black ip
+ // black ip
clientIps = []string{"1.2.3.5", "2.2.2.2", "3.3.3.3"}
for _, ip := range clientIps {
conditionToCheck[SOURCEIP] = ip
result := s.matchCondition(conditionToCheck)
require.False(t, result)
}
-
}
+
func TestStringLikeMatch(t *testing.T) {
strCondition := `{
"StringLike":{"aws:Referer":["http://*.example.com/*","http://example.com/*"]}
diff --git a/objectnode/policy_statement.go b/objectnode/policy_statement.go
index f44698f06..636e90d05 100644
--- a/objectnode/policy_statement.go
+++ b/objectnode/policy_statement.go
@@ -25,8 +25,10 @@ import (
// https://docs.aws.amazon.com/AmazonS3/latest/dev/example-bucket-policies.html
// https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/dev/example-bucket-policies.html
-type Principal map[string]StringSet
-type Resource string
+type (
+ Principal map[string]StringSet
+ Resource string
+)
const (
Allow = "Allow"
@@ -43,7 +45,6 @@ type Statement struct {
}
func (s Statement) IsAllowed(p *RequestParam) bool {
-
return s.Effect == Allow
}
diff --git a/objectnode/policy_statement_test.go b/objectnode/policy_statement_test.go
index 73795545b..6693c9592 100644
--- a/objectnode/policy_statement_test.go
+++ b/objectnode/policy_statement_test.go
@@ -58,7 +58,6 @@ func TestPolicyExample(t *testing.T) {
out, err := json.Marshal(policy)
err = json.Unmarshal(out, &policy)
require.NoError(t, err)
-
}
func TestMissingRequiredField(t *testing.T) {
@@ -140,7 +139,6 @@ func TestEffectFormat(t *testing.T) {
json.Unmarshal([]byte(`"Deny"`), &s.Effect)
b = s.isEffectValid()
require.True(t, b)
-
}
func TestResourceFormat(t *testing.T) {
@@ -256,7 +254,6 @@ func TestActionFormat(t *testing.T) {
}
func TestConditionFormat(t *testing.T) {
-
validCondition := []string{
`{"IpAddress":{"aws:SourceIp":["1.1.1.1/24","1.1.1.1","fe80::45e:9d4c:20ca:20f7/64"]}}`,
`{"NotIpAddress":{"aws:SourceIp":"1.1.1.3"}}`,
@@ -298,7 +295,7 @@ func TestConditionFormat(t *testing.T) {
func TestActionResourceCombination(t *testing.T) {
var s Statement
- var resource_action = []struct {
+ resource_action := []struct {
action string
resource string
matchResult bool
diff --git a/objectnode/policy_stringlikeop.go b/objectnode/policy_stringlikeop.go
index 76c314336..526261973 100644
--- a/objectnode/policy_stringlikeop.go
+++ b/objectnode/policy_stringlikeop.go
@@ -36,7 +36,7 @@ func (op stringLikeOp) evaluate(values map[string]string) bool {
if !ok {
requestValue = values[k.Name()]
}
- nothingMatched := true //all values not matched
+ nothingMatched := true // all values not matched
for p := range v {
if Match(p, requestValue) {
nothingMatched = false
@@ -140,7 +140,6 @@ func newStringNotLikeOp(m map[Key]ValueSet) (Operation, error) {
// returns new StringNotLike operation.
func NewStringNotLikeOp(m map[Key]StringSet) (Operation, error) {
-
return &stringNotLikeOp{stringLikeOp{m}}, nil
}
diff --git a/objectnode/policy_stringlikeop_test.go b/objectnode/policy_stringlikeop_test.go
index e8285f07c..080696cd3 100644
--- a/objectnode/policy_stringlikeop_test.go
+++ b/objectnode/policy_stringlikeop_test.go
@@ -63,6 +63,7 @@ func TestStringLikeOpEvaluate(t *testing.T) {
}
}
}
+
func TestStringNotLikeOpEvaluate(t *testing.T) {
case1Operation, err := newStringNotLikeOp(map[Key]ValueSet{AWSReferer: NewValueSet(NewStringValue("*.cubefs.com"), NewStringValue("cubefs.com"))})
if err != nil {
diff --git a/objectnode/policy_valueset_test.go b/objectnode/policy_valueset_test.go
index 0453df90a..eb7dee85b 100644
--- a/objectnode/policy_valueset_test.go
+++ b/objectnode/policy_valueset_test.go
@@ -120,6 +120,7 @@ func TestValueGetType(t *testing.T) {
}
}
}
+
func TestValueSet_UnmarshalJSON(t *testing.T) {
testCases := []struct {
value []byte
diff --git a/objectnode/ratelimit.go b/objectnode/ratelimit.go
index 188e77a4f..73aae70f9 100644
--- a/objectnode/ratelimit.go
+++ b/objectnode/ratelimit.go
@@ -82,7 +82,6 @@ func NewRateLimit(apiLimitConf map[string]*proto.UserLimitConf) RateLimiter {
putApi: putApi,
}
return rateLimit
-
}
func (r *RateLimit) AcquireLimitResource(uid string, api string) error {
@@ -139,8 +138,7 @@ func (r *RateLimit) GetReader(uid string, api string, reader io.Reader) io.Reade
}
// No RateLimit
-type NullRateLimit struct {
-}
+type NullRateLimit struct{}
func (n *NullRateLimit) AcquireLimitResource(uid string, api string) error {
return nil
@@ -190,7 +188,6 @@ func NewUserRateMgr(conf *proto.UserLimitConf) UserRateManager {
}
func (r *UserRateMgr) QPSLimitAllowed(uid string) (bool, time.Duration) {
-
defaultQPSLimit := r.UserLimitConf.QPSQuota[proto.DefaultUid]
usrQPSLimit := r.UserLimitConf.QPSQuota[uid]
qpsQuota := getUserLimitQuota(defaultQPSLimit, usrQPSLimit)
@@ -209,7 +206,6 @@ func (r *UserRateMgr) QPSLimitAllowed(uid string) (bool, time.Duration) {
}
func (r *UserRateMgr) ConcurrentLimitAcquire(uid string) error {
-
defaultConcurrentLimit := r.UserLimitConf.ConcurrentQuota[proto.DefaultUid]
usrConcurrentLimit := r.UserLimitConf.ConcurrentQuota[uid]
@@ -219,7 +215,6 @@ func (r *UserRateMgr) ConcurrentLimitAcquire(uid string) error {
}
log.LogDebugf("ConcurrentLimit: defaultConcurrentLimit[%d] usrConcurrentLimit[%d] uid[%s]", defaultConcurrentLimit, usrConcurrentLimit, uid)
return r.ConcurrentLimit.Acquire(uid, int64(concurrentQuota))
-
}
func (r *UserRateMgr) ConcurrentLimitRelease(uid string) {
@@ -227,7 +222,6 @@ func (r *UserRateMgr) ConcurrentLimitRelease(uid string) {
}
func (r *UserRateMgr) GetResponseWriter(uid string, w io.Writer) io.Writer {
-
defaultBandWidthLimit := r.UserLimitConf.BandWidthQuota[proto.DefaultUid]
usrBandWidthLimit := r.UserLimitConf.BandWidthQuota[uid]
@@ -241,11 +235,9 @@ func (r *UserRateMgr) GetResponseWriter(uid string, w io.Writer) io.Writer {
w = flowctrl.NewRateWriterWithCtrl(w, flowCtrl)
return w
-
}
func (r *UserRateMgr) GetReader(uid string, reader io.Reader) io.Reader {
-
defaultBandWidthLimit := r.UserLimitConf.BandWidthQuota[proto.DefaultUid]
usrBandWidthLimit := r.UserLimitConf.BandWidthQuota[uid]
@@ -259,12 +251,10 @@ func (r *UserRateMgr) GetReader(uid string, reader io.Reader) io.Reader {
reader = flowctrl.NewRateReaderWithCtrl(reader, flowCtrl)
return reader
-
}
// priority: usrLimit > defaultLimit
func getUserLimitQuota(defaultLimit, usrLimit uint64) uint64 {
-
if usrLimit != 0 {
return usrLimit
}
diff --git a/objectnode/result_test.go b/objectnode/result_test.go
index ac0bdf7a1..11c0da4fe 100644
--- a/objectnode/result_test.go
+++ b/objectnode/result_test.go
@@ -148,15 +148,15 @@ func TestNewDeleteRequest(t *testing.T) {
objectRequest := []Object{
{
Key: "jvsTest001_1",
- //VersionId:"v0001",
+ // VersionId:"v0001",
},
{
Key: "jvsTest001_2",
- //VersionId:"v0001",
+ // VersionId:"v0001",
},
{
Key: "jvsTest001_3",
- //VersionId:"v0001",
+ // VersionId:"v0001",
},
}
@@ -221,7 +221,7 @@ func TestMarshalTagging(t *testing.T) {
func TestResult_PutXAttrRequest_Marshal(t *testing.T) {
var err error
- var request = PutXAttrRequest{
+ request := PutXAttrRequest{
XAttr: &XAttr{
Key: "xattr-key",
Value: "xattr-value",
@@ -235,7 +235,7 @@ func TestResult_PutXAttrRequest_Marshal(t *testing.T) {
}
func TestResult_PutXAttrRequest_Unmarshal(t *testing.T) {
- var raw = []byte(`
+ raw := []byte(`
xattr-key
@@ -244,7 +244,7 @@ func TestResult_PutXAttrRequest_Unmarshal(t *testing.T) {
`)
var err error
- var request = PutXAttrRequest{}
+ request := PutXAttrRequest{}
if err = xml.Unmarshal(raw, &request); err != nil {
t.Fatalf("unmarshal raw fail: err(%v)", err)
}
diff --git a/objectnode/router.go b/objectnode/router.go
index 191c19f65..b7871c9f7 100644
--- a/objectnode/router.go
+++ b/objectnode/router.go
@@ -24,7 +24,6 @@ import (
// register api routers
func (o *ObjectNode) registerApiRouters(router *mux.Router) {
-
var bucketRouters []*mux.Router
bRouter := router.PathPrefix("/").Subrouter()
for _, d := range o.domains {
@@ -33,7 +32,7 @@ func (o *ObjectNode) registerApiRouters(router *mux.Router) {
}
bucketRouters = append(bucketRouters, bRouter.PathPrefix("/{bucket}").Subrouter())
- var registerBucketHttpHeadRouters = func(r *mux.Router) {
+ registerBucketHttpHeadRouters := func(r *mux.Router) {
// Head object
// API reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_HeadObject.html
r.NewRoute().Name(ActionToUniqueRouteName(proto.OSSHeadObjectAction)).
@@ -48,8 +47,7 @@ func (o *ObjectNode) registerApiRouters(router *mux.Router) {
HandlerFunc(o.headBucketHandler)
}
- var registerBucketHttpGetRouters = func(r *mux.Router) {
-
+ registerBucketHttpGetRouters := func(r *mux.Router) {
// Get Object Lock configuration
// API reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectLockConfiguration.html
r.NewRoute().Name(ActionToUniqueRouteName(proto.OSSGetObjectLockConfigurationAction)).
@@ -265,7 +263,7 @@ func (o *ObjectNode) registerApiRouters(router *mux.Router) {
HandlerFunc(o.getBucketV1Handler)
}
- var registerBucketHttpPostRouters = func(r *mux.Router) {
+ registerBucketHttpPostRouters := func(r *mux.Router) {
// Create multipart upload
// API reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html
r.NewRoute().Name(ActionToUniqueRouteName(proto.OSSCreateMultipartUploadAction)).
@@ -305,7 +303,7 @@ func (o *ObjectNode) registerApiRouters(router *mux.Router) {
HandlerFunc(o.postObjectHandler)
}
- var registerBucketHttpPutRouters = func(r *mux.Router) {
+ registerBucketHttpPutRouters := func(r *mux.Router) {
// Put Object Lock configuration
// API reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectLockConfiguration.html
r.NewRoute().Name(ActionToUniqueRouteName(proto.OSSPutObjectLockConfigurationAction)).
@@ -486,7 +484,7 @@ func (o *ObjectNode) registerApiRouters(router *mux.Router) {
HandlerFunc(o.createBucketHandler)
}
- var registerBucketHttpDeleteRouters = func(r *mux.Router) {
+ registerBucketHttpDeleteRouters := func(r *mux.Router) {
// Abort multipart upload
// API reference: https://docs.aws.amazon.com/AmazonS3/latest/API/API_AbortMultipartUpload.html .
r.NewRoute().Name(ActionToUniqueRouteName(proto.OSSAbortMultipartUploadAction)).
@@ -592,10 +590,9 @@ func (o *ObjectNode) registerApiRouters(router *mux.Router) {
r.NewRoute().Name(ActionToUniqueRouteName(proto.OSSDeleteBucketAction)).
Methods(http.MethodDelete).
HandlerFunc(o.deleteBucketHandler)
-
}
- var registerBucketHttpOptionsRouters = func(r *mux.Router) {
+ registerBucketHttpOptionsRouters := func(r *mux.Router) {
// OPTIONS object
// https://docs.aws.amazon.com/AmazonS3/latest/API/RESTOPTIONSobject.html
r.NewRoute().Name(ActionToUniqueRouteName(proto.OSSOptionsObjectAction)).
diff --git a/objectnode/s3api_name.go b/objectnode/s3api_name.go
index e43c87676..d415a6cc5 100644
--- a/objectnode/s3api_name.go
+++ b/objectnode/s3api_name.go
@@ -14,81 +14,81 @@
package objectnode
-//service api refer to: https://docs.aws.amazon.com/en_pv/AmazonS3/latest/API/archive-RESTServiceOps.html
-//bucket api refer to: https://docs.aws.amazon.com/en_pv/AmazonS3/latest/API/archive-RESTBucketOps.html
-//object api refer to: https://docs.aws.amazon.com/en_pv/AmazonS3/latest/API/archive-RESTObjectOps
-//account api: https://docs.aws.amazon.com/en_pv/AmazonS3/latest/API/archive-RESTAccountOps.html , batch jobs
+// service api refer to: https://docs.aws.amazon.com/en_pv/AmazonS3/latest/API/archive-RESTServiceOps.html
+// bucket api refer to: https://docs.aws.amazon.com/en_pv/AmazonS3/latest/API/archive-RESTBucketOps.html
+// object api refer to: https://docs.aws.amazon.com/en_pv/AmazonS3/latest/API/archive-RESTObjectOps
+// account api: https://docs.aws.amazon.com/en_pv/AmazonS3/latest/API/archive-RESTAccountOps.html , batch jobs
const (
UNSUPPORT_API = "UnSupportAPI"
- GET_FEDERATION_TOKEN = "GetFederationToken" //api: POST /, host=s3-cn-east-1.cs.com, create sts token
- List_BUCKETS = "ListBuckets" //api: GET / , host=s3-cn-east-1.cs.com, list all buckets
- DELETE_BUCKET = "DeleteBucket" //api: Delete / , host=.domain
- DELETE_BUCKET_CORS = "DeleteBucketCors" //api: Delete /?cors , host=.domain
- DELETE_BUCKET_ENCRYPTION = "DeleteBucketEncryption" //api: Delete /?encryption , host=.domain
- DELETE_BUCKET_LIFECYCLE = "DeleteBucketLifeCycle" //api: Delete /?lifycycle , host=.domain
- DELETE_BUCKET_METRICS = "DeleteBucketMetrics" //api: Delete /?metrics&id= , host=.domain
- DELETE_BUCKET_POLICY = "DeleteBucketPolicy" //api: Delete /?policy , host=.domain
- DELETE_BUCKET_REPLICATION = "DeleteBucketReplication" //api: Delete /?replication , host=.domain
- DELETE_BUCKET_TAGGING = "DeleteBucketTagging" //api: Delete /?tagging , host=.domain
- DELETE_BUCKET_WEBSITE = "DeleteBucketWebsite" //api: Delete /?website , host=.domain
- LIST_OBJECTS = "ListObjects" //api: Get / , host=.domain , GetBucket version1
- LIST_OBJECTS_V2 = "ListObjectsV2" //api: Get /?list-type=2, host=.domain, GetBucket Version2
- GET_BUCKET_ACCELERATE = "GetBucketAccelerate" //api: GET /?accelerate
- GET_BUCKET_ACL = "GetBucketAcl" //api: GET /?acl
- GET_BUCKET_CORS = "GetBucketCors" //api: Get /?cors , host=.domain
- GET_BUCKET_ENCRYPTION = "GetBucketEncryption" //api: Get /?encryption , host=.domain
- GET_BUCKET_LIFECYCLE = "GetBucketLifeCycle" //api: Get /?lifycycle , host=.domain
- GET_BUCKET_LOCATION = "GetBucketLocation" //api: GET /?location , host=.domain
- GET_PUBLIC_ACCESS_BLOCK = "GetPublicAccessBlock" //api: Get /?publicAccessBlock , host=.domain
- GET_BUCKET_LOGGING = "GetBucketLogging" //api: Get /?logging , host=.domain
- GET_BUCKET_METRICS = "GetBucketMetrics" //api: Get /?metrics&id= , host=.domain
- GET_BUCKET_NOTIFICATION = "GetBucketNotification" //api: Get /?notification , host=.domain
- GET_BUCKET_POLICY_STATUS = "GetBucketPolicyStatus" //api: Get /?policyStatus , host=.domain
- GET_BUCKET_OBJECT_VERSIONS = "GetBucketObjectVersions" //api: Get /?versions , host=.domain
- GET_BUCKET_POLICY = "GetBucketPolicy" //api: Get /?policy , host=.domain
- GET_BUCKET_REPLICATION = "GetBucketReplication" //api: Get /?replication , host=.domain
- GET_BUCKET_TAGGING = "GetBucketTagging" //api: Get /?tagging , host=.domain
- GET_BUCKET_VERSIONING = "GetBucketVersioning" //api: Get /?versioning , host=.domain
- GET_BUCKET_WEBSITE = "GetBucketWebsite" //api: Get /?website , host=.domain
- GET_OBJECT_LOCK_CFG = "GetObjectLockConfiguration" //api: Get /?object-lock, host=.domain
- HEAD_BUCKET = "HeadBucket" //api: Head / , host=.domain
- LIST_MULTIPART_UPLOADS = "ListMultipartUploads" //api: GET /?uploads , host=.domain
- PUT_BUCKET = "CreateBucket" //api: Put / , host=.domain, CreateBucket
- PUT_BUCKET_ACCELERATE = "PutBucketAccelerate" //api: Put /?accelerate , host=.domain,
- PUT_BUCKET_ACL = "PutBucketAcl" //api: Put /?acl , host=.domain
- PUT_BUCKET_CORS = "PutBucketCors" //api: PUT /?cors , host=.domain
- PUT_BUCKET_ENCRYPTION = "PutBucketEncryption" //api: PUT /?encryption , host=.domain
- PUT_BUCKET_LIFECYCLE = "PutBucketLifecycle" //api: PUT /?lifecycle , host=.domain
- PUT_PUBLIC_ACCESS_BLOCK = "PutPublicAccessBlock" //api: PUT /?publicAccessBlock , host=.domain,
- PUT_BUCKET_LOGGING = "PutBucketLogging" //api: PUT /?logging , host=.domain
- PUT_BUCKET_METRICS = "PutBucketMetrics" //api: PUT /?metrics&id= , host=.domain
- PUT_BUCKET_NOTIFICATION = "PutBucketNotification" //api: PUT /?notification , host=.domain
- PUT_BUCKET_POLICY = "PutBucketPolicy" //api: PUT /?policy , host=.domain
- PUT_BUCKET_REPLICATION = "PutBucketReplication" //api: PUT /?replication , host=.domain
- PUT_BUCKET_REQUEST_PAYMENT = "PutBucketRequestPayment" //api: PUT /?requestPayment , host=.domain
- PUT_BUCKET_TAGGING = "PutBucketTagging" //api: PUT /?tagging , host=.domain
- PUT_BUCKET_VERSIONING = "PutBucketVersioning" //api: PUT /?versioning , host=.domain
- PUT_BUCKET_WEBSITE = "PutBucketWebsite" //api: PUT /?website , host=.domain
- PUT_OBJECT_LOCK_CFG = "PutObjectLockConfiguration" //api: Put /?object-lock, host=.domain
- BATCH_DELETE = "DeleteObjects" //api: POST /?delete , host=.domain, "DeleteObjects"
- DELETE_OBJECT = "DeleteObject" //api: Delete /, host=.domain
- DELETE_OBJECT_TAGGING = "DeleteObjectTagging" //api: Delete /?tagging, host=.domain
- GET_OBJECT = "GetObject" //api: Get / , host=.domain
- GET_OBJECT_ACL = "GetObjectAcl" //api: Get //?acl , host=.domain
- GET_OBJECT_TAGGING = "GetObjectTagging" //api: Get //?tagging , host=.domain
- GET_OBJECT_RETENTION = "GetObjectRetention" //api: Get //?retention, host=.domain
- HEAD_OBJECT = "HeadObject" //api: HEAD / , host=.domain
- OPTIONS_OBJECT = "OptionsObject" //api: OPTIONS /, host=.domain
- POST_OBJECT = "PostObject" //api: Post / , host=.domain
- PUT_OBJECT = "PutObject" //api: Put /, host=.domain
- COPY_OBJECT = "CopyObject" //api: Put / ,host=.domain, header["x-amz-copy-source"]
- PUT_OBJECT_ACL = "PutObjectAcl" //api: Put /?acl , host=.domain
- PUT_OBJECT_TAGGING = "PutObjectTagging" //api: Put /?tagging , host=.domain
- INITIALE_MULTIPART_UPLOAD = "CreateMultipartUpload" //api: POST /?uploads , host=.domain
- UPLOAD_PART = "UploadPart" //api: PUT /?partNumber=&uploadId=, host=.domain
- UPLOAD_PART_COPY = "UploadPartCopy" //api: PUT /?partNumber=&uploadId=, host=.domain , header["x-amz-copy-source"]
- LIST_PARTS = "ListParts" //api: GET /?uploadId= , host=.domain
- COMPLETE_MULTIPART_UPLOAD = "CompleteMultipartUpload" //api: POST /?uploadId= , host=.domain
- ABORT_MULTIPART_UPLOAD = "AbortMultipartUpload" //api: DELETE /?uploadId= , host=.domain
+ GET_FEDERATION_TOKEN = "GetFederationToken" // api: POST /, host=s3-cn-east-1.cs.com, create sts token
+ List_BUCKETS = "ListBuckets" // api: GET / , host=s3-cn-east-1.cs.com, list all buckets
+ DELETE_BUCKET = "DeleteBucket" // api: Delete / , host=.domain
+ DELETE_BUCKET_CORS = "DeleteBucketCors" // api: Delete /?cors , host=.domain
+ DELETE_BUCKET_ENCRYPTION = "DeleteBucketEncryption" // api: Delete /?encryption , host=.domain
+ DELETE_BUCKET_LIFECYCLE = "DeleteBucketLifeCycle" // api: Delete /?lifycycle , host=.domain
+ DELETE_BUCKET_METRICS = "DeleteBucketMetrics" // api: Delete /?metrics&id= , host=.domain
+ DELETE_BUCKET_POLICY = "DeleteBucketPolicy" // api: Delete /?policy , host=.domain
+ DELETE_BUCKET_REPLICATION = "DeleteBucketReplication" // api: Delete /?replication , host=.domain
+ DELETE_BUCKET_TAGGING = "DeleteBucketTagging" // api: Delete /?tagging , host=.domain
+ DELETE_BUCKET_WEBSITE = "DeleteBucketWebsite" // api: Delete /?website , host=.domain
+ LIST_OBJECTS = "ListObjects" // api: Get / , host=.domain , GetBucket version1
+ LIST_OBJECTS_V2 = "ListObjectsV2" // api: Get /?list-type=2, host=.domain, GetBucket Version2
+ GET_BUCKET_ACCELERATE = "GetBucketAccelerate" // api: GET /?accelerate
+ GET_BUCKET_ACL = "GetBucketAcl" // api: GET /?acl
+ GET_BUCKET_CORS = "GetBucketCors" // api: Get /?cors , host=.domain
+ GET_BUCKET_ENCRYPTION = "GetBucketEncryption" // api: Get /?encryption , host=.domain
+ GET_BUCKET_LIFECYCLE = "GetBucketLifeCycle" // api: Get /?lifycycle , host=.domain
+ GET_BUCKET_LOCATION = "GetBucketLocation" // api: GET /?location , host=.domain
+ GET_PUBLIC_ACCESS_BLOCK = "GetPublicAccessBlock" // api: Get /?publicAccessBlock , host=.domain
+ GET_BUCKET_LOGGING = "GetBucketLogging" // api: Get /?logging , host=.domain
+ GET_BUCKET_METRICS = "GetBucketMetrics" // api: Get /?metrics&id= , host=.domain
+ GET_BUCKET_NOTIFICATION = "GetBucketNotification" // api: Get /?notification , host=.domain
+ GET_BUCKET_POLICY_STATUS = "GetBucketPolicyStatus" // api: Get /?policyStatus , host=.domain
+ GET_BUCKET_OBJECT_VERSIONS = "GetBucketObjectVersions" // api: Get /?versions , host=.domain
+ GET_BUCKET_POLICY = "GetBucketPolicy" // api: Get /?policy , host=.domain
+ GET_BUCKET_REPLICATION = "GetBucketReplication" // api: Get /?replication , host=.domain
+ GET_BUCKET_TAGGING = "GetBucketTagging" // api: Get /?tagging , host=.domain
+ GET_BUCKET_VERSIONING = "GetBucketVersioning" // api: Get /?versioning , host=.domain
+ GET_BUCKET_WEBSITE = "GetBucketWebsite" // api: Get /?website , host=.domain
+ GET_OBJECT_LOCK_CFG = "GetObjectLockConfiguration" // api: Get /?object-lock, host=.domain
+ HEAD_BUCKET = "HeadBucket" // api: Head / , host=.domain
+ LIST_MULTIPART_UPLOADS = "ListMultipartUploads" // api: GET /?uploads , host=.domain
+ PUT_BUCKET = "CreateBucket" // api: Put / , host=.domain, CreateBucket
+ PUT_BUCKET_ACCELERATE = "PutBucketAccelerate" // api: Put /?accelerate , host=.domain,
+ PUT_BUCKET_ACL = "PutBucketAcl" // api: Put /?acl , host=.domain
+ PUT_BUCKET_CORS = "PutBucketCors" // api: PUT /?cors , host=.domain
+ PUT_BUCKET_ENCRYPTION = "PutBucketEncryption" // api: PUT /?encryption , host=.domain
+ PUT_BUCKET_LIFECYCLE = "PutBucketLifecycle" // api: PUT /?lifecycle , host=.domain
+ PUT_PUBLIC_ACCESS_BLOCK = "PutPublicAccessBlock" // api: PUT /?publicAccessBlock , host=.domain,
+ PUT_BUCKET_LOGGING = "PutBucketLogging" // api: PUT /?logging , host=.domain
+ PUT_BUCKET_METRICS = "PutBucketMetrics" // api: PUT /?metrics&id= , host=.domain
+ PUT_BUCKET_NOTIFICATION = "PutBucketNotification" // api: PUT /?notification , host=.domain
+ PUT_BUCKET_POLICY = "PutBucketPolicy" // api: PUT /?policy , host=.domain
+ PUT_BUCKET_REPLICATION = "PutBucketReplication" // api: PUT /?replication , host=.domain
+ PUT_BUCKET_REQUEST_PAYMENT = "PutBucketRequestPayment" // api: PUT /?requestPayment , host=.domain
+ PUT_BUCKET_TAGGING = "PutBucketTagging" // api: PUT /?tagging , host=.domain
+ PUT_BUCKET_VERSIONING = "PutBucketVersioning" // api: PUT /?versioning , host=.domain
+ PUT_BUCKET_WEBSITE = "PutBucketWebsite" // api: PUT /?website , host=.domain
+ PUT_OBJECT_LOCK_CFG = "PutObjectLockConfiguration" // api: Put /?object-lock, host=.domain
+ BATCH_DELETE = "DeleteObjects" // api: POST /?delete , host=.domain, "DeleteObjects"
+ DELETE_OBJECT = "DeleteObject" // api: Delete /, host=.domain
+ DELETE_OBJECT_TAGGING = "DeleteObjectTagging" // api: Delete /?tagging, host=.domain
+ GET_OBJECT = "GetObject" // api: Get / , host=.domain
+ GET_OBJECT_ACL = "GetObjectAcl" // api: Get //?acl , host=.domain
+ GET_OBJECT_TAGGING = "GetObjectTagging" // api: Get //?tagging , host=.domain
+ GET_OBJECT_RETENTION = "GetObjectRetention" // api: Get //?retention, host=.domain
+ HEAD_OBJECT = "HeadObject" // api: HEAD / , host=.domain
+ OPTIONS_OBJECT = "OptionsObject" // api: OPTIONS /, host=.domain
+ POST_OBJECT = "PostObject" // api: Post / , host=.domain
+ PUT_OBJECT = "PutObject" // api: Put /, host=.domain
+ COPY_OBJECT = "CopyObject" // api: Put / ,host=.domain, header["x-amz-copy-source"]
+ PUT_OBJECT_ACL = "PutObjectAcl" // api: Put /?acl , host=.domain
+ PUT_OBJECT_TAGGING = "PutObjectTagging" // api: Put /?tagging , host=.domain
+ INITIALE_MULTIPART_UPLOAD = "CreateMultipartUpload" // api: POST /?uploads , host=.domain
+ UPLOAD_PART = "UploadPart" // api: PUT /?partNumber=&uploadId=, host=.domain
+ UPLOAD_PART_COPY = "UploadPartCopy" // api: PUT /?partNumber=&uploadId=, host=.domain , header["x-amz-copy-source"]
+ LIST_PARTS = "ListParts" // api: GET /?uploadId= , host=.domain
+ COMPLETE_MULTIPART_UPLOAD = "CompleteMultipartUpload" // api: POST /?uploadId= , host=.domain
+ ABORT_MULTIPART_UPLOAD = "AbortMultipartUpload" // api: DELETE /?uploadId= , host=.domain
)
diff --git a/objectnode/server.go b/objectnode/server.go
index 7fc3f1bd7..dd017f61f 100644
--- a/objectnode/server.go
+++ b/objectnode/server.go
@@ -464,7 +464,7 @@ func (o *ObjectNode) startMuxRestAPI() (err error) {
o.contentMiddleware,
)
- var server = &http.Server{
+ server := &http.Server{
Addr: ":" + o.listen,
Handler: router,
ReadTimeout: 5 * time.Minute,
diff --git a/objectnode/util.go b/objectnode/util.go
index 26d4bad18..05c20649d 100644
--- a/objectnode/util.go
+++ b/objectnode/util.go
@@ -50,9 +50,7 @@ var (
regexpDupSep = regexp.MustCompile("/{2,}")
)
-var (
- keyEscapedSkipBytes = []byte{'/', '*', '.', '-', '_'}
-)
+var keyEscapedSkipBytes = []byte{'/', '*', '.', '-', '_'}
// PathItem defines path node attribute information,
// including node name and whether it is a directory.
@@ -78,7 +76,6 @@ func (p *PathIterator) init() {
p.path = regexpDupSep.ReplaceAllString(p.path, pathSep)
p.inited = true
}
-
}
func (p *PathIterator) HasNext() bool {
@@ -148,6 +145,7 @@ func formatSimpleTime(time time.Time) string {
func formatTimeISO(time time.Time) string {
return time.UTC().Format("2006-01-02T15:04:05.000Z")
}
+
func formatTimeISOLocal(time time.Time) string {
return time.Local().Format("2006-01-02T15:04:05.000Z")
}
@@ -235,7 +233,7 @@ func wrapUnescapedQuot(src string) string {
}
func encodeKey(key, encodingType string) string {
- var isKeyEscapedSkipByte = func(b byte) bool {
+ isKeyEscapedSkipByte := func(b byte) bool {
for _, skipByte := range keyEscapedSkipBytes {
if b == skipByte {
return true
@@ -310,7 +308,7 @@ var cacheControlDir = []string{"public", "private", "no-cache", "no-store", "no-
var maxAgeRegexp = regexp.MustCompile("^((max-age)|(s-maxage))=[1-9][0-9]*$")
func ValidateCacheControl(cacheControl string) bool {
- var cacheDirs = strings.Split(cacheControl, ",")
+ cacheDirs := strings.Split(cacheControl, ",")
for _, dir := range cacheDirs {
if !contains(cacheControlDir, dir) && !maxAgeRegexp.MatchString(dir) {
log.LogErrorf("invalid cache-control directive: %v", dir)
diff --git a/objectnode/wildcard.go b/objectnode/wildcard.go
index c747bd69e..8b6f6b6c1 100644
--- a/objectnode/wildcard.go
+++ b/objectnode/wildcard.go
@@ -38,12 +38,12 @@ func (w *Wildcard) Parse(host string) (bucket string, is bool) {
}
func NewWildcard(domain string) (*Wildcard, error) {
- var regexpString = "^(([a-zA-Z0-9]|-|_)+.)+" + domain + "(:(\\d)+)*$"
+ regexpString := "^(([a-zA-Z0-9]|-|_)+.)+" + domain + "(:(\\d)+)*$"
r, err := regexp.Compile(regexpString)
if err != nil {
return nil, err
}
- var wc = &Wildcard{
+ wc := &Wildcard{
domain: domain,
r: r,
}
@@ -63,7 +63,7 @@ func (ws Wildcards) Parse(host string) (bucket string, is bool) {
func NewWildcards(domains []string) (Wildcards, error) {
var err error
- var ws = make([]*Wildcard, len(domains))
+ ws := make([]*Wildcard, len(domains))
for i := 0; i < len(domains); i++ {
if ws[i], err = NewWildcard(domains[i]); err != nil {
return nil, err
diff --git a/objectnode/wildcard_test.go b/objectnode/wildcard_test.go
index 4ae8a0d9d..684cf6c60 100644
--- a/objectnode/wildcard_test.go
+++ b/objectnode/wildcard_test.go
@@ -17,8 +17,7 @@ package objectnode
import "testing"
func TestWildcards_Parse(t *testing.T) {
-
- var domains = []string{
+ domains := []string{
"object.cube.io",
"oss.cube.io",
}
@@ -33,7 +32,7 @@ func TestWildcards_Parse(t *testing.T) {
e expect
}
- var samples = []sample{
+ samples := []sample{
{h: "object.cube.io", e: expect{wildcard: false}},
{h: "object.cube.io:8080", e: expect{wildcard: false}},
{h: "a.object.cube.io", e: expect{wildcard: true, bucket: "a"}},
diff --git a/preload/preload.go b/preload/preload.go
index 4f1e2fe3e..1e0f404ab 100644
--- a/preload/preload.go
+++ b/preload/preload.go
@@ -29,7 +29,7 @@ func main() {
fmt.Print(proto.DumpVersion(Role))
os.Exit(0)
}
- //TODO: why *configFlie
+ // TODO: why *configFlie
cfg, err := config.LoadConfigFile(*configFile)
if err != nil {
fmt.Println("LoadConfigFile failed")
@@ -66,11 +66,13 @@ func main() {
LogDir: cfg.GetString("logDir"),
LogLevel: cfg.GetString("logLevel"),
ProfPort: cfg.GetString("prof"),
- LimitParam: sdk.LimitParameters{TraverseDirConcurrency: travereDirConcurrency,
+ LimitParam: sdk.LimitParameters{
+ TraverseDirConcurrency: travereDirConcurrency,
PreloadFileConcurrency: preloadFileConcurrency,
ReadBlockConcurrency: int32(readBlockConcurrency),
PreloadFileSizeLimit: preloadFileSizeLimit,
- ClearFileConcurrency: clearFileConcurrency},
+ ClearFileConcurrency: clearFileConcurrency,
+ },
}
cli := sdk.NewClient(config)
@@ -100,17 +102,16 @@ func main() {
fmt.Printf("action[%v] is not support\n", action)
os.Exit(1)
}
-
}
func checkConfig(cfg *config.Config) bool {
- var masters = cfg.GetString("masterAddr")
- var target = cfg.GetString("target")
- var vol = cfg.GetString("volumeName")
- var logDir = cfg.GetString("logDir")
- var logLevel = cfg.GetString("logLevel")
- var ttl = cfg.GetString("ttl")
- var action = cfg.GetString("action")
+ masters := cfg.GetString("masterAddr")
+ target := cfg.GetString("target")
+ vol := cfg.GetString("volumeName")
+ logDir := cfg.GetString("logDir")
+ logLevel := cfg.GetString("logLevel")
+ ttl := cfg.GetString("ttl")
+ action := cfg.GetString("action")
if len(masters) == 0 || len(target) == 0 || len(vol) == 0 || len(logDir) == 0 ||
len(logLevel) == 0 || len(ttl) == 0 || len(action) == 0 {
diff --git a/preload/preload_test.go b/preload/preload_test.go
index 0c1bcf9c8..973997ce9 100644
--- a/preload/preload_test.go
+++ b/preload/preload_test.go
@@ -15,13 +15,14 @@
package main
import (
- "github.com/cubefs/cubefs/util/config"
"testing"
+
+ "github.com/cubefs/cubefs/util/config"
)
func TestCheckConfMaster(t *testing.T) {
t.Run("masters", func(t *testing.T) {
- var cfgJSON = `{"target":"/",
+ cfgJSON := `{"target":"/",
"volumeName": "cold3",
"masterAddr": "10.177.69.105:17010, 10.177.69.106:17010, 10.177.117.108:17010",
"logDir": "/home/ADC/80256477/adls/log/preload",
@@ -35,7 +36,7 @@ func TestCheckConfMaster(t *testing.T) {
})
t.Run("masters_empty", func(t *testing.T) {
- var cfgJSON = `{"target":"/",
+ cfgJSON := `{"target":"/",
"volumeName": "cold3",
"logDir": "/home/ADC/80256477/adls/log/preload",
"logLevel": "debug",
@@ -49,9 +50,8 @@ func TestCheckConfMaster(t *testing.T) {
}
func TestCheckConfTarget(t *testing.T) {
-
t.Run("target_empty", func(t *testing.T) {
- var cfgJSON = `{
+ cfgJSON := `{
"volumeName": "cold3",
"masterAddr": "10.177.69.105:17010, 10.177.69.106:17010, 10.177.117.108:17010",
"logDir": "/home/ADC/80256477/adls/log/preload",
@@ -67,7 +67,7 @@ func TestCheckConfTarget(t *testing.T) {
func TestCheckConfVol(t *testing.T) {
t.Run("vol_empty", func(t *testing.T) {
- var cfgJSON = `{"target":"/",
+ cfgJSON := `{"target":"/",
"masterAddr": "10.177.69.105:17010, 10.177.69.106:17010, 10.177.117.108:17010",
"logDir": "/home/ADC/80256477/adls/log/preload",
"logLevel": "debug",
@@ -82,7 +82,7 @@ func TestCheckConfVol(t *testing.T) {
func TestCheckConfLogDir(t *testing.T) {
t.Run("logDir_empty", func(t *testing.T) {
- var cfgJSON = `{"target":"/",
+ cfgJSON := `{"target":"/",
"volumeName": "cold3",
"masterAddr": "10.177.69.105:17010, 10.177.69.106:17010, 10.177.117.108:17010",
"logLevel": "debug",
@@ -97,7 +97,7 @@ func TestCheckConfLogDir(t *testing.T) {
func TestCheckConfLogLevel(t *testing.T) {
t.Run("logLevel_empty", func(t *testing.T) {
- var cfgJSON = `{"target":"/",
+ cfgJSON := `{"target":"/",
"volumeName": "cold3",
"masterAddr": "10.177.69.105:17010, 10.177.69.106:17010, 10.177.117.108:17010",
"logDir": "/home/ADC/80256477/adls/log/preload",
@@ -112,7 +112,7 @@ func TestCheckConfLogLevel(t *testing.T) {
func TestCheckConfTTL(t *testing.T) {
t.Run("ttl_empty", func(t *testing.T) {
- var cfgJSON = `{"target":"/",
+ cfgJSON := `{"target":"/",
"volumeName": "cold3",
"masterAddr": "10.177.69.105:17010, 10.177.69.106:17010, 10.177.117.108:17010",
"logDir": "/home/ADC/80256477/adls/log/preload",
@@ -127,7 +127,7 @@ func TestCheckConfTTL(t *testing.T) {
func TestCheckConfAction(t *testing.T) {
t.Run("action_empty", func(t *testing.T) {
- var cfgJSON = `{"target":"/",
+ cfgJSON := `{"target":"/",
"volumeName": "cold3",
"masterAddr": "10.177.69.105:17010, 10.177.69.106:17010, 10.177.117.108:17010",
"logDir": "/home/ADC/80256477/adls/log/preload",
diff --git a/preload/sdk/preloadsdk.go b/preload/sdk/preloadsdk.go
index 728816800..6d4ff44fe 100644
--- a/preload/sdk/preloadsdk.go
+++ b/preload/sdk/preloadsdk.go
@@ -53,7 +53,7 @@ type PreLoadClient struct {
mc *masterSDK.MasterClient
ebsc *blobstore.BlobStoreClient
sync.RWMutex
- fileCache []fileInfo //file list for target dir
+ fileCache []fileInfo // file list for target dir
vol string
limitParam LimitParameters
cacheAction int
@@ -276,7 +276,6 @@ func (c *PreLoadClient) walker(dir string, wg *sync.WaitGroup, currentGoroutineN
}
children, err := c.mw.ReadDir_ll(info.Inode)
-
if err != nil {
log.LogErrorf("ReadDir_ll path(%v) faild(%v)", dir, err)
return err
@@ -322,7 +321,7 @@ func (c *PreLoadClient) allocatePreloadDPWorker(ch <-chan fileInfo) uint64 {
total += info.Size
cachefino := cache[info.Inode]
cachefino.size = info.Size
- //append
+ // append
c.fileCache = append(c.fileCache, cachefino)
log.LogDebugf("allocatePreloadDPWorker append:%v", cachefino)
}
@@ -332,7 +331,7 @@ func (c *PreLoadClient) allocatePreloadDPWorker(ch <-chan fileInfo) uint64 {
delete(cache, key)
}
}
- //flush cache
+ // flush cache
if len(inodes) != 0 {
infos := c.mw.BatchInodeGet(inodes)
@@ -341,7 +340,7 @@ func (c *PreLoadClient) allocatePreloadDPWorker(ch <-chan fileInfo) uint64 {
total += info.Size
cachefino := cache[info.Inode]
cachefino.size = info.Size
- //append
+ // append
c.fileCache = append(c.fileCache, cachefino)
log.LogDebugf("allocatePreloadDPWorker append#2:%v", cachefino)
}
@@ -441,7 +440,7 @@ func (c *PreLoadClient) preloadFileWorker(id int64, jobs <-chan fileInfo, wg *sy
for job := range jobs {
if noWritableDP == true {
log.LogWarnf("no writable dp,ingnore (%v) to cbfs", job.name)
- continue //consume the job
+ continue // consume the job
}
total += 1
log.LogDebugf("worker %v ready to preload(%v)", id, job.name)
@@ -476,7 +475,7 @@ func (c *PreLoadClient) preloadFileWorker(id int64, jobs <-chan fileInfo, wg *sy
for _, objExtent := range objExtents {
size := objExtent.Size
- var buf = make([]byte, size)
+ buf := make([]byte, size)
var n int
n, err = fileReader.Read(c.ctx(0, ino), buf, int(objExtent.FileOffset), int(size))
@@ -491,7 +490,7 @@ func (c *PreLoadClient) preloadFileWorker(id int64, jobs <-chan fileInfo, wg *sy
continue
}
_, err = c.ec.Write(ino, int(objExtent.FileOffset), buf, 0, nil)
- //in preload mode,onece extend_hander set to error, streamer is set to error
+ // in preload mode,onece extend_hander set to error, streamer is set to error
// so write should failed immediately
if err != nil {
subErr = true
@@ -540,7 +539,6 @@ func (c *PreLoadClient) preloadFile() error {
} else {
return errors.New("Preload failed")
}
-
}
func (c *PreLoadClient) CheckColdVolume() bool {
@@ -578,7 +576,7 @@ func (c *PreLoadClient) PreloadDir(target string, count int, ttl uint64, zones s
log.LogDebugf("Wait 100s for preload dp get ready")
time.Sleep(time.Duration(100) * time.Second)
log.LogDebugf("Sleep end")
- //Step3.2 preload the file
+ // Step3.2 preload the file
return c.preloadFile()
}
diff --git a/preload/sdk/preloadsdk_test.go b/preload/sdk/preloadsdk_test.go
index d526376ba..74ebc3014 100644
--- a/preload/sdk/preloadsdk_test.go
+++ b/preload/sdk/preloadsdk_test.go
@@ -15,8 +15,9 @@
package sdk
import (
- "github.com/cubefs/cubefs/util/log"
"testing"
+
+ "github.com/cubefs/cubefs/util/log"
)
func TestConvertDebugLevel(t *testing.T) {
diff --git a/proto/admin_proto.go b/proto/admin_proto.go
index 172909f75..6bf3bee75 100644
--- a/proto/admin_proto.go
+++ b/proto/admin_proto.go
@@ -98,12 +98,12 @@ const (
AdminQueryDecommissionDiskLimit = "/admin/queryDecommissionDiskLimit"
AdminEnableAutoDecommissionDisk = "/admin/enableAutoDecommissionDisk"
AdminQueryAutoDecommissionDisk = "/admin/queryAutoDecommissionDisk"
- //graphql master api
+ // graphql master api
AdminClusterAPI = "/api/cluster"
AdminUserAPI = "/api/user"
AdminVolumeAPI = "/api/volume"
- //graphql coonsole api
+ // graphql coonsole api
ConsoleIQL = "/iql"
ConsoleLoginAPI = "/login"
ConsoleMonitorAPI = "/cfs_monitor"
@@ -134,7 +134,7 @@ const (
// uid api
AdminUid = "/admin/uidOp"
- //raft node APIs
+ // raft node APIs
AddRaftNode = "/raftNode/add"
RemoveRaftNode = "/raftNode/remove"
RaftStatus = "/get/raftStatus"
@@ -173,7 +173,7 @@ const (
AdminDeleteMetaReplica = "/metaReplica/delete"
AdminPutDataPartitions = "/dataPartitions/set"
- //admin multi version snapshot
+ // admin multi version snapshot
AdminCreateVersion = "/multiVer/create"
AdminDelVersion = "/multiVer/del"
AdminGetVersionInfo = "/multiVer/get"
@@ -217,12 +217,12 @@ const (
UserTransferVol = "/user/transferVol"
UserList = "/user/list"
UsersOfVol = "/vol/users"
- //graphql api for header
+ // graphql api for header
HeadAuthorized = "Authorization"
ParamAuthorized = "_authorization"
UserKey = "_user_key"
UserInfoKey = "_user_info_key"
- //quota
+ // quota
QuotaCreate = "/quota/create"
QuotaUpdate = "/quota/update"
QuotaDelete = "/quota/delete"
@@ -342,7 +342,7 @@ var GApiInfo map[string]string = map[string]string{
"usersofvol": UsersOfVol,
}
-//const TimeFormat = "2006-01-02 15:04:05"
+// const TimeFormat = "2006-01-02 15:04:05"
const (
TimeFormat = "2006-01-02 15:04:05"
@@ -728,8 +728,8 @@ type DataNodeHeartbeatResponse struct {
PartitionReports []*DataPartitionReport
Status uint8
Result string
- BadDisks []string //Keep this old field for compatibility
- BadDiskStats []BadDiskStat //key: disk path
+ BadDisks []string // Keep this old field for compatibility
+ BadDiskStats []BadDiskStat // key: disk path
CpuUtil float64 `json:"cpuUtil"`
IoUtils map[string]float64 `json:"ioUtil"`
}
@@ -893,11 +893,9 @@ type MetaPartitionView struct {
Status int8
}
-type DataNodeDisksRequest struct {
-}
+type DataNodeDisksRequest struct{}
-type DataNodeDisksResponse struct {
-}
+type DataNodeDisksResponse struct{}
type OSSSecure struct {
AccessKey string
@@ -1102,6 +1100,7 @@ type NodeSetInfo struct {
DataTotal uint64
DataNodes []*DataNodeInfo
}
+
type SimpleNodeSetGrpInfo struct {
ID uint64
Status uint8
@@ -1179,7 +1178,6 @@ const (
)
func GetDpType(volType int, isPreload bool) int {
-
if volType == VolumeTypeHot {
return PartitionTypeNormal
}
diff --git a/proto/auth_proto.go b/proto/auth_proto.go
index 4c66d4b94..cc149d5f6 100644
--- a/proto/auth_proto.go
+++ b/proto/auth_proto.go
@@ -19,7 +19,7 @@ import (
"encoding/binary"
"encoding/json"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"net/url"
"regexp"
@@ -63,7 +63,7 @@ const (
AdminDeleteCaps = "/admin/deletecaps"
AdminGetCaps = "/admin/getcaps"
- //raft node APIs
+ // raft node APIs
AdminAddRaftNode = "/admin/addraftnode"
AdminRemoveRaftNode = "/admin/removeraftnode"
@@ -86,7 +86,7 @@ const (
// DataServiceID defines ticket for datanode access (not supported)
DataServiceID = "DatanodeService"
- //ObjectServiceID defines ticket for objectnode access
+ // ObjectServiceID defines ticket for objectnode access
ObjectServiceID = "ObjectService"
)
@@ -196,10 +196,10 @@ const (
// MsgMasterAPIAccessResp response type for master api access
MsgMasterAPIAccessResp MsgType = 0x60001
- //Master API ClientVol
+ // Master API ClientVol
MsgMasterFetchVolViewReq MsgType = MsgMasterAPIAccessReq + 0x10000
- //Master API cluster management
+ // Master API cluster management
MsgMasterClusterFreezeReq MsgType = MsgMasterAPIAccessReq + 0x20100
MsgMasterAddRaftNodeReq MsgType = MsgMasterAPIAccessReq + 0x20200
MsgMasterRemoveRaftNodeReq MsgType = MsgMasterAPIAccessReq + 0x20300
@@ -287,7 +287,7 @@ var MsgType2ResourceMap = map[MsgType]string{
MsgMasterFetchVolViewReq: "master:getvol",
- //Master API cluster management
+ // Master API cluster management
MsgMasterClusterFreezeReq: "master:clusterfreeze",
MsgMasterAddRaftNodeReq: "master:addraftnode",
MsgMasterRemoveRaftNodeReq: "master:removeraftnode",
@@ -508,9 +508,7 @@ func GetDataFromResp(body []byte, key []byte) (plaintext []byte, err error) {
// ParseAuthGetTicketResp parse and validate the auth get ticket resp
func ParseAuthGetTicketResp(body []byte, key []byte) (resp AuthGetTicketResp, err error) {
- var (
- plaintext []byte
- )
+ var plaintext []byte
if plaintext, err = GetDataFromResp(body, key); err != nil {
return
@@ -525,9 +523,7 @@ func ParseAuthGetTicketResp(body []byte, key []byte) (resp AuthGetTicketResp, er
// ParseAuthAPIAccessResp parse and validate the auth api access resp
func ParseAuthAPIAccessResp(body []byte, key []byte) (resp AuthAPIAccessResp, err error) {
- var (
- plaintext []byte
- )
+ var plaintext []byte
if plaintext, err = GetDataFromResp(body, key); err != nil {
return
@@ -542,9 +538,7 @@ func ParseAuthAPIAccessResp(body []byte, key []byte) (resp AuthAPIAccessResp, er
// ParseAuthRaftNodeResp parse and validate the auth raft node resp
func ParseAuthRaftNodeResp(body []byte, key []byte) (resp AuthRaftNodeResp, err error) {
- var (
- plaintext []byte
- )
+ var plaintext []byte
if plaintext, err = GetDataFromResp(body, key); err != nil {
return
@@ -558,9 +552,7 @@ func ParseAuthRaftNodeResp(body []byte, key []byte) (resp AuthRaftNodeResp, err
}
func ParseAuthOSAKResp(body []byte, key []byte) (resp AuthOSAccessKeyResp, err error) {
- var (
- plaintext []byte
- )
+ var plaintext []byte
if plaintext, err = GetDataFromResp(body, key); err != nil {
return
@@ -574,9 +566,7 @@ func ParseAuthOSAKResp(body []byte, key []byte) (resp AuthOSAccessKeyResp, err e
}
func ExtractTicket(str string, key []byte) (ticket cryptoutil.Ticket, err error) {
- var (
- plaintext []byte
- )
+ var plaintext []byte
if plaintext, err = cryptoutil.DecodeMessage(str, key); err != nil {
return
@@ -603,9 +593,7 @@ func checkTicketCaps(ticket *cryptoutil.Ticket, kind string, cap string) (err er
// ParseVerifier checks the verifier structure for replay attack mitigation
func ParseVerifier(verifier string, key []byte) (ts int64, err error) {
- var (
- plainttext []byte
- )
+ var plainttext []byte
if plainttext, err = cryptoutil.DecodeMessage(verifier, key); err != nil {
return
@@ -716,7 +704,6 @@ func ExtractIDAndAuthKey(authIDKey string) (id string, authKey []byte, err error
}
func CheckVOLAccessCaps(ticket *cryptoutil.Ticket, volName string, action string, accessNode string) (err error) {
-
rule := accessNode + capSeparator + volName + capSeparator + action
if err = checkTicketCaps(ticket, OwnerVOLRsc, rule); err != nil {
@@ -786,7 +773,7 @@ func SendBytes(client *http.Client, target string, data []byte) (res []byte, err
return
}
defer resp.Body.Close()
- body, err := ioutil.ReadAll(resp.Body)
+ body, err := io.ReadAll(resp.Body)
if err != nil {
err = fmt.Errorf("action[doRealSend] failed:" + err.Error())
return
diff --git a/proto/extent_key.go b/proto/extent_key.go
index b34828f83..baaeea1c3 100644
--- a/proto/extent_key.go
+++ b/proto/extent_key.go
@@ -55,7 +55,7 @@ type ExtentKey struct {
ExtentOffset uint64 // offset in extent like tiny extent offset large than 0,normal is 0
Size uint32 // real size that inode used on the extent,it's size may be part of extent real size, such as tinyExt
CRC uint32
- //snapshot
+ // snapshot
SnapInfo *ExtSnapInfo
}
diff --git a/proto/fs_proto.go b/proto/fs_proto.go
index fe98630ea..f122ae34a 100644
--- a/proto/fs_proto.go
+++ b/proto/fs_proto.go
@@ -283,7 +283,7 @@ type TxInodeApplyRequest struct {
type TxDentryApplyRequest struct {
TxID string `json:"txid"`
- //DenKey string `json:"denkey"`
+ // DenKey string `json:"denkey"`
Pid uint64 `json:"pid"`
Name string `json:"name"`
TxApplyType int `json:"type"`
@@ -364,7 +364,7 @@ type UnlinkInodeRequest struct {
VolName string `json:"vol"`
PartitionID uint64 `json:"pid"`
Inode uint64 `json:"ino"`
- UniqID uint64 `json:"uid"` //for request dedup
+ UniqID uint64 `json:"uid"` // for request dedup
VerSeq uint64 `json:"ver"`
DenVerSeq uint64 `json:"denVer"`
RequestExtend
@@ -549,6 +549,7 @@ type LookupRequest struct {
VerSeq uint64 `json:"seq"`
VerAll bool `json:"verAll"`
}
+
type DetryInfo struct {
Inode uint64 `json:"ino"`
Mode uint32 `json:"mode"`
@@ -632,6 +633,7 @@ type ReadDirOnlyRequest struct {
type ReadDirResponse struct {
Children []Dentry `json:"children"`
}
+
type ReadDirOnlyResponse struct {
Children []Dentry `json:"children"`
}
diff --git a/proto/lifecycle.go b/proto/lifecycle.go
index 42e5e9b34..e84aa1ff1 100644
--- a/proto/lifecycle.go
+++ b/proto/lifecycle.go
@@ -141,7 +141,7 @@ func (f *BatchDentries) Len() int {
func (f *BatchDentries) BatchGetAndClear() (map[uint64]*ScanDentry, []uint64) {
f.Lock()
defer f.Unlock()
- var dentries = f.dentries
+ dentries := f.dentries
var inodes []uint64
for i := range f.dentries {
inodes = append(inodes, i)
diff --git a/proto/model.go b/proto/model.go
index 1323f3942..e45703142 100644
--- a/proto/model.go
+++ b/proto/model.go
@@ -16,9 +16,10 @@ package proto
import (
"fmt"
- "github.com/cubefs/cubefs/util/log"
"sync"
"time"
+
+ "github.com/cubefs/cubefs/util/log"
)
const (
@@ -132,22 +133,22 @@ type ClusterView struct {
// ClusterNode defines the structure of a cluster node
type ClusterNodeInfo struct {
- //BatchCount int
+ // BatchCount int
LoadFactor string
- //MarkDeleteRate int
- //AutoRepairRate int
- //DeleteWorkerSleepMs int
+ // MarkDeleteRate int
+ // AutoRepairRate int
+ // DeleteWorkerSleepMs int
}
type ClusterIP struct {
Cluster string
- //MetaNodeDeleteBatchCount int
- //MetaNodeDeleteWorkerSleepMs int
- //DataNodeDeleteLimitRate int
- //DataNodeAutoRepairLimitRate int
- //Ip string
+ // MetaNodeDeleteBatchCount int
+ // MetaNodeDeleteWorkerSleepMs int
+ // DataNodeDeleteLimitRate int
+ // DataNodeAutoRepairLimitRate int
+ // Ip string
EbsAddr string
- //ServicePath string
+ // ServicePath string
}
// NodeView provides the view of the data or meta node.
@@ -184,6 +185,7 @@ type ZoneStat struct {
DataNodeStat *ZoneNodesStat
MetaNodeStat *ZoneNodesStat
}
+
type ZoneNodesStat struct {
Total float64 `json:"TotalGB"`
Used float64 `json:"UsedGB"`
@@ -312,7 +314,7 @@ type DataPartitionDiagnosis struct {
RepFileCountDifferDpIDs []uint64
RepUsedSizeDifferDpIDs []uint64
ExcessReplicaDpIDs []uint64
- //BadDataPartitionIDs []BadPartitionView
+ // BadDataPartitionIDs []BadPartitionView
BadDataPartitionInfos []BadPartitionRepairView
BadReplicaDataPartitionIDs []uint64
}
@@ -418,6 +420,7 @@ type DecommissionDiskLimitDetail struct {
NodeSetId uint64
Limit int
}
+
type DecommissionDiskLimit struct {
Details []DecommissionDiskLimitDetail
}
diff --git a/proto/mount_options.go b/proto/mount_options.go
index 0331ec274..0640bb9fe 100644
--- a/proto/mount_options.go
+++ b/proto/mount_options.go
@@ -50,7 +50,7 @@ const (
EnableUnixPermission
RequestTimeout
- //adls
+ // adls
VolType
EbsEndpoint
EbsServerPath
@@ -72,7 +72,7 @@ const (
MinWriteAbleDataPartitionCnt
FileSystemName
- //snapshot
+ // snapshot
SnapshotReadVerSeq
MaxMountOption
@@ -148,24 +148,26 @@ func InitMountOptions(opts []MountOption) {
opts[EbsServerPath] = MountOption{"ebsServerPath", "Ebs service path", "", ""}
opts[CacheAction] = MountOption{"cacheAction", "Cold cache action", "", int64(0)}
opts[EbsBlockSize] = MountOption{"ebsBlockSize", "Ebs object size", "", ""}
- //opts[EnableBcache] = MountOption{"enableBcache", "Enable block cache", "", false}
+ // opts[EnableBcache] = MountOption{"enableBcache", "Enable block cache", "", false}
opts[BcacheDir] = MountOption{"bcacheDir", "block cache dir", "", ""}
opts[ReadThreads] = MountOption{"readThreads", "Cold volume read threads", "", int64(10)}
opts[WriteThreads] = MountOption{"writeThreads", "Cold volume write threads", "", int64(10)}
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
opts[MaxStreamerLimit] = MountOption{"maxStreamerLimit", "The maximum number of streamers", "", int64(0)} // default 0
opts[BcacheFilterFiles] = MountOption{"bcacheFilterFiles", "The block cache filter files suffix", "", "py;pyx;sh;yaml;conf;pt;pth;log;out"}
opts[BcacheBatchCnt] = MountOption{"bcacheBatchCnt", "The block cache get meta count", "", int64(100000)}
opts[BcacheCheckIntervalS] = MountOption{"bcacheCheckIntervalS", "The block cache check interval", "", int64(300)}
opts[EnableAudit] = MountOption{"enableAudit", "enable client audit logging", "", false}
opts[RequestTimeout] = MountOption{"requestTimeout", "The Request Expiration Time", "", int64(0)}
- opts[MinWriteAbleDataPartitionCnt] = MountOption{"minWriteAbleDataPartitionCnt",
+ opts[MinWriteAbleDataPartitionCnt] = MountOption{
+ "minWriteAbleDataPartitionCnt",
"Min writeable data partition count retained int dpSelector when update DataPartitionsView from master",
- "", int64(10)}
+ "", int64(10),
+ }
opts[FileSystemName] = MountOption{"fileSystemName", "The explicit name of the filesystem", "", ""}
- opts[SnapshotReadVerSeq] = MountOption{"snapshotReadSeq", "Snapshot read seq", "", int64(0)} //default false
+ opts[SnapshotReadVerSeq] = MountOption{"snapshotReadSeq", "Snapshot read seq", "", int64(0)} // default false
for i := 0; i < MaxMountOption; i++ {
flag.StringVar(&opts[i].cmdlineValue, opts[i].keyword, "", opts[i].description)
diff --git a/proto/packet.go b/proto/packet.go
index e3a86c33c..2f97ae176 100644
--- a/proto/packet.go
+++ b/proto/packet.go
@@ -20,7 +20,6 @@ import (
"encoding/json"
"errors"
"fmt"
- "github.com/cubefs/cubefs/util/log"
"io"
"net"
"strconv"
@@ -30,6 +29,7 @@ import (
"github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/buf"
+ "github.com/cubefs/cubefs/util/log"
)
var (
@@ -90,7 +90,7 @@ const (
OpMetaSetattr uint8 = 0x30
OpMetaReleaseOpen uint8 = 0x31
- //Operations: MetaNode Leader -> MetaNode Follower
+ // Operations: MetaNode Leader -> MetaNode Follower
OpMetaFreeInodesOnRaftFollower uint8 = 0x32
OpMetaDeleteInode uint8 = 0x33 // delete specified inode immediately and do not remove data.
@@ -151,13 +151,13 @@ const (
OpBatchDeleteExtent uint8 = 0x75 // SDK to MetaNode
OpGetExpiredMultipart uint8 = 0x76
- //Operations: MetaNode Leader -> MetaNode Follower
+ // Operations: MetaNode Leader -> MetaNode Follower
OpMetaBatchDeleteInode uint8 = 0x90
OpMetaBatchDeleteDentry uint8 = 0x91
OpMetaBatchUnlinkInode uint8 = 0x92
OpMetaBatchEvictInode uint8 = 0x93
- //Transaction Operations: Client -> MetaNode.
+ // Transaction Operations: Client -> MetaNode.
OpMetaTxCreate uint8 = 0xA0
OpMetaTxCreateInode uint8 = 0xA1
OpMetaTxUnlinkInode uint8 = 0xA2
@@ -171,10 +171,10 @@ const (
OpMetaTxLinkInode uint8 = 0xAA
OpMetaTxGet uint8 = 0xAB
- //Operations: Client -> MetaNode.
+ // Operations: Client -> MetaNode.
OpMetaGetUniqID uint8 = 0xAC
- //Multi version snapshot
+ // Multi version snapshot
OpRandomWriteAppend uint8 = 0xB1
OpSyncRandomWriteAppend uint8 = 0xB2
OpRandomWriteVer uint8 = 0xB3
@@ -220,7 +220,7 @@ const (
OpMetaBatchSetXAttr uint8 = 0xD2
OpMetaGetAllXAttr uint8 = 0xD3
- //transaction error
+ // transaction error
OpTxInodeInfoNotExistErr uint8 = 0xE0
OpTxConflictErr uint8 = 0xE1
@@ -739,7 +739,7 @@ func (p *Packet) UnmarshalHeader(in []byte) error {
// header opcode OpRandomWriteVer should not unmarshal here due to header size is const
// the ver param should read at the higher level directly
- //if p.Opcode ==OpRandomWriteVer {
+ // if p.Opcode ==OpRandomWriteVer {
return nil
}
@@ -835,7 +835,7 @@ func (p *Packet) WriteToConn(c net.Conn) (err error) {
if p.Opcode == OpRandomWriteVer || p.ExtentType&MultiVersionFlag > 0 {
headSize = util.PacketHeaderVerSize
}
- //log.LogDebugf("packet opcode %v header size %v extentype %v conn %v", p.Opcode, headSize, p.ExtentType, c)
+ // log.LogDebugf("packet opcode %v header size %v extentype %v conn %v", p.Opcode, headSize, p.ExtentType, c)
header, err := Buffers.Get(headSize)
if err != nil {
header = make([]byte, headSize)
@@ -1120,7 +1120,6 @@ func (p *Packet) setPacketPrefix() {
"Size(%v)_Opcode(%v)_CRC(%v)",
p.ReqID, p.PartitionID, p.ExtentID, p.ExtentOffset,
p.KernelOffset, p.Size, p.GetOpMsg(), p.CRC)
-
}
// IsForwardPkt returns if the packet is the forward packet (a packet that will be forwarded to the followers).
@@ -1133,7 +1132,6 @@ func (p *Packet) LogMessage(action, remote string, start int64, err error) (m st
if err == nil {
m = fmt.Sprintf("id[%v] isPrimaryBackReplLeader[%v] remote[%v] "+
" cost[%v] ", p.GetUniqueLogId(), p.IsForwardPkt(), remote, (time.Now().UnixNano()-start)/1e6)
-
} else {
m = fmt.Sprintf("id[%v] isPrimaryBackReplLeader[%v] remote[%v]"+
", err[%v]", p.GetUniqueLogId(), p.IsForwardPkt(), remote, err.Error())
diff --git a/proto/perm_action.go b/proto/perm_action.go
index 173481961..e0b6022f0 100644
--- a/proto/perm_action.go
+++ b/proto/perm_action.go
@@ -36,7 +36,7 @@ func (a Action) IsNone() bool {
}
func (a Action) Name() string {
- var loc = actionPrefixRegexp.FindStringIndex(a.String())
+ loc := actionPrefixRegexp.FindStringIndex(a.String())
if len(loc) != 2 {
return "Unknown"
}
@@ -177,90 +177,88 @@ const (
NoneAction Action = ""
)
-var (
- AllActions = []Action{
- // Object storage interface actions
- OSSGetObjectAction,
- OSSPutObjectAction,
- OSSPostObjectAction,
- OSSCopyObjectAction,
- OSSListObjectsAction,
- OSSDeleteObjectAction,
- OSSDeleteObjectsAction,
- OSSHeadObjectAction,
- OSSCreateBucketAction,
- OSSDeleteBucketAction,
- OSSHeadBucketAction,
- OSSListBucketsAction,
- OSSGetBucketPolicyAction,
- OSSPutBucketPolicyAction,
- OSSDeleteBucketPolicyAction,
- OSSGetBucketPolicyStatusAction,
- OSSGetBucketAclAction,
- OSSPutBucketAclAction,
- OSSGetObjectTorrentAction,
- OSSGetObjectAclAction,
- OSSPutObjectAclAction,
- OSSCreateMultipartUploadAction,
- OSSListMultipartUploadsAction,
- OSSUploadPartAction,
- OSSUploadPartCopyAction,
- OSSListPartsAction,
- OSSCompleteMultipartUploadAction,
- OSSAbortMultipartUploadAction,
- OSSGetBucketLocationAction,
- OSSGetObjectXAttrAction,
- OSSPutObjectXAttrAction,
- OSSListObjectXAttrsAction,
- OSSDeleteObjectXAttrAction,
- OSSGetObjectTaggingAction,
- OSSPutObjectTaggingAction,
- OSSDeleteObjectTaggingAction,
- OSSGetBucketTaggingAction,
- OSSPutBucketTaggingAction,
- OSSDeleteBucketTaggingAction,
- OSSGetBucketLifecycleAction,
- OSSPutBucketLifecycleAction,
- OSSDeleteBucketLifecycleAction,
- OSSGetBucketLifecycleConfigurationAction,
- OSSPutBucketLifecycleConfigurationAction,
- OSSDeleteBucketLifecycleConfigurationAction,
- OSSGetBucketVersioningAction,
- OSSPutBucketVersioningAction,
- OSSListObjectVersionsAction,
- OSSGetObjectLegalHoldAction,
- OSSPutObjectLegalHoldAction,
- OSSGetObjectRetentionAction,
- OSSPutObjectRetentionAction,
- OSSGetBucketEncryptionAction,
- OSSPutBucketEncryptionAction,
- OSSDeleteBucketEncryptionAction,
- OSSGetBucketCorsAction,
- OSSPutBucketCorsAction,
- OSSDeleteBucketCorsAction,
- OSSGetBucketWebsiteAction,
- OSSPutBucketWebsiteAction,
- OSSDeleteBucketWebsiteAction,
- OSSRestoreObjectAction,
- OSSGetPublicAccessBlockAction,
- OSSPutPublicAccessBlockAction,
- OSSDeletePublicAccessBlockAction,
- OSSGetBucketRequestPaymentAction,
- OSSPutBucketRequestPaymentAction,
- OSSGetBucketReplicationAction,
- OSSPutBucketReplicationAction,
- OSSDeleteBucketReplicationAction,
- OSSOptionsObjectAction,
- OSSGetFederationTokenAction,
+var AllActions = []Action{
+ // Object storage interface actions
+ OSSGetObjectAction,
+ OSSPutObjectAction,
+ OSSPostObjectAction,
+ OSSCopyObjectAction,
+ OSSListObjectsAction,
+ OSSDeleteObjectAction,
+ OSSDeleteObjectsAction,
+ OSSHeadObjectAction,
+ OSSCreateBucketAction,
+ OSSDeleteBucketAction,
+ OSSHeadBucketAction,
+ OSSListBucketsAction,
+ OSSGetBucketPolicyAction,
+ OSSPutBucketPolicyAction,
+ OSSDeleteBucketPolicyAction,
+ OSSGetBucketPolicyStatusAction,
+ OSSGetBucketAclAction,
+ OSSPutBucketAclAction,
+ OSSGetObjectTorrentAction,
+ OSSGetObjectAclAction,
+ OSSPutObjectAclAction,
+ OSSCreateMultipartUploadAction,
+ OSSListMultipartUploadsAction,
+ OSSUploadPartAction,
+ OSSUploadPartCopyAction,
+ OSSListPartsAction,
+ OSSCompleteMultipartUploadAction,
+ OSSAbortMultipartUploadAction,
+ OSSGetBucketLocationAction,
+ OSSGetObjectXAttrAction,
+ OSSPutObjectXAttrAction,
+ OSSListObjectXAttrsAction,
+ OSSDeleteObjectXAttrAction,
+ OSSGetObjectTaggingAction,
+ OSSPutObjectTaggingAction,
+ OSSDeleteObjectTaggingAction,
+ OSSGetBucketTaggingAction,
+ OSSPutBucketTaggingAction,
+ OSSDeleteBucketTaggingAction,
+ OSSGetBucketLifecycleAction,
+ OSSPutBucketLifecycleAction,
+ OSSDeleteBucketLifecycleAction,
+ OSSGetBucketLifecycleConfigurationAction,
+ OSSPutBucketLifecycleConfigurationAction,
+ OSSDeleteBucketLifecycleConfigurationAction,
+ OSSGetBucketVersioningAction,
+ OSSPutBucketVersioningAction,
+ OSSListObjectVersionsAction,
+ OSSGetObjectLegalHoldAction,
+ OSSPutObjectLegalHoldAction,
+ OSSGetObjectRetentionAction,
+ OSSPutObjectRetentionAction,
+ OSSGetBucketEncryptionAction,
+ OSSPutBucketEncryptionAction,
+ OSSDeleteBucketEncryptionAction,
+ OSSGetBucketCorsAction,
+ OSSPutBucketCorsAction,
+ OSSDeleteBucketCorsAction,
+ OSSGetBucketWebsiteAction,
+ OSSPutBucketWebsiteAction,
+ OSSDeleteBucketWebsiteAction,
+ OSSRestoreObjectAction,
+ OSSGetPublicAccessBlockAction,
+ OSSPutPublicAccessBlockAction,
+ OSSDeletePublicAccessBlockAction,
+ OSSGetBucketRequestPaymentAction,
+ OSSPutBucketRequestPaymentAction,
+ OSSGetBucketReplicationAction,
+ OSSPutBucketReplicationAction,
+ OSSDeleteBucketReplicationAction,
+ OSSOptionsObjectAction,
+ OSSGetFederationTokenAction,
- // POSIX file system interface actions
- POSIXReadAction,
- POSIXWriteAction,
+ // POSIX file system interface actions
+ POSIXReadAction,
+ POSIXWriteAction,
- OSSPutObjectLockConfigurationAction,
- OSSGetObjectLockConfigurationAction,
- }
-)
+ OSSPutObjectLockConfigurationAction,
+ OSSGetObjectLockConfigurationAction,
+}
func ParseAction(str string) Action {
if len(str) == 0 || !actionRegexp.MatchString(str) {
@@ -401,64 +399,62 @@ func NewCustomPermission(name string) Permission {
return Permission(CustomPermissionPrefix + Permission(name))
}
-var (
- builtinPermissionActionsMap = map[Permission]Actions{
- BuiltinPermissionReadOnly: {
- // Object storage interface actions
- OSSGetObjectAction,
- OSSListObjectsAction,
- OSSHeadObjectAction,
- OSSHeadBucketAction,
- OSSGetObjectTorrentAction,
- OSSGetObjectAclAction,
- OSSListPartsAction,
- OSSGetBucketLocationAction,
- OSSGetObjectTaggingAction,
- OSSListObjectVersionsAction,
- OSSGetObjectLegalHoldAction,
- OSSGetObjectRetentionAction,
- OSSGetBucketEncryptionAction,
+var builtinPermissionActionsMap = map[Permission]Actions{
+ BuiltinPermissionReadOnly: {
+ // Object storage interface actions
+ OSSGetObjectAction,
+ OSSListObjectsAction,
+ OSSHeadObjectAction,
+ OSSHeadBucketAction,
+ OSSGetObjectTorrentAction,
+ OSSGetObjectAclAction,
+ OSSListPartsAction,
+ OSSGetBucketLocationAction,
+ OSSGetObjectTaggingAction,
+ OSSListObjectVersionsAction,
+ OSSGetObjectLegalHoldAction,
+ OSSGetObjectRetentionAction,
+ OSSGetBucketEncryptionAction,
- // file system interface
- POSIXReadAction,
- },
- BuiltinPermissionWritable: {
- // Object storage interface actions
- OSSGetObjectAction,
- OSSPutObjectAction,
- OSSCopyObjectAction,
- OSSListObjectsAction,
- OSSDeleteObjectAction,
- OSSDeleteObjectsAction,
- OSSHeadObjectAction,
- OSSHeadBucketAction,
- OSSGetObjectTorrentAction,
- OSSGetObjectAclAction,
- OSSPutObjectAclAction,
- OSSCreateMultipartUploadAction,
- OSSListMultipartUploadsAction,
- OSSUploadPartAction,
- OSSUploadPartCopyAction,
- OSSListPartsAction,
- OSSCompleteMultipartUploadAction,
- OSSAbortMultipartUploadAction,
- OSSGetBucketLocationAction,
- OSSGetObjectTaggingAction,
- OSSPutObjectTaggingAction,
- OSSDeleteObjectTaggingAction,
- OSSListObjectVersionsAction,
- OSSGetObjectLegalHoldAction,
- OSSPutObjectLegalHoldAction,
- OSSGetObjectRetentionAction,
- OSSPutObjectRetentionAction,
- OSSGetBucketEncryptionAction,
+ // file system interface
+ POSIXReadAction,
+ },
+ BuiltinPermissionWritable: {
+ // Object storage interface actions
+ OSSGetObjectAction,
+ OSSPutObjectAction,
+ OSSCopyObjectAction,
+ OSSListObjectsAction,
+ OSSDeleteObjectAction,
+ OSSDeleteObjectsAction,
+ OSSHeadObjectAction,
+ OSSHeadBucketAction,
+ OSSGetObjectTorrentAction,
+ OSSGetObjectAclAction,
+ OSSPutObjectAclAction,
+ OSSCreateMultipartUploadAction,
+ OSSListMultipartUploadsAction,
+ OSSUploadPartAction,
+ OSSUploadPartCopyAction,
+ OSSListPartsAction,
+ OSSCompleteMultipartUploadAction,
+ OSSAbortMultipartUploadAction,
+ OSSGetBucketLocationAction,
+ OSSGetObjectTaggingAction,
+ OSSPutObjectTaggingAction,
+ OSSDeleteObjectTaggingAction,
+ OSSListObjectVersionsAction,
+ OSSGetObjectLegalHoldAction,
+ OSSPutObjectLegalHoldAction,
+ OSSGetObjectRetentionAction,
+ OSSPutObjectRetentionAction,
+ OSSGetBucketEncryptionAction,
- // POSIX file system interface actions
- POSIXReadAction,
- POSIXWriteAction,
- },
- }
-)
+ // POSIX file system interface actions
+ POSIXReadAction,
+ POSIXWriteAction,
+ },
+}
func BuiltinPermissionActions(perm Permission) Actions {
var p Permission
diff --git a/proto/transaction.go b/proto/transaction.go
index 7f7d81c03..632190560 100644
--- a/proto/transaction.go
+++ b/proto/transaction.go
@@ -19,22 +19,23 @@ import (
"encoding/binary"
"encoding/json"
"errors"
- "github.com/cubefs/cubefs/util/btree"
- "github.com/cubefs/cubefs/util/log"
"io"
"strconv"
"strings"
"time"
+
+ "github.com/cubefs/cubefs/util/btree"
+ "github.com/cubefs/cubefs/util/log"
)
const (
- DefaultTransactionTimeout = 1 //minutes
- MaxTransactionTimeout = 60 //minutes
+ DefaultTransactionTimeout = 1 // minutes
+ MaxTransactionTimeout = 60 // minutes
DefaultTxConflictRetryNum = 10
MaxTxConflictRetryNum = 100
- DefaultTxConflictRetryInterval = 20 //ms
- MaxTxConflictRetryInterval = 1000 //ms
- MinTxConflictRetryInterval = 10 //ms
+ DefaultTxConflictRetryInterval = 20 // ms
+ MaxTxConflictRetryInterval = 1000 // ms
+ MinTxConflictRetryInterval = 10 // ms
DefaultTxDeleteTime = 120
ClearOrphanTxTime = 3600
)
@@ -46,6 +47,7 @@ const (
TxOpMaskAll TxOpMask = 0x7F
TxPause TxOpMask = 0xFF
)
+
const (
TxOpMaskCreate TxOpMask = 0x01 << iota
TxOpMaskMkdir
@@ -143,7 +145,7 @@ func GetMaskFromString(maskStr string) (mask TxOpMask, err error) {
type TxInodeInfo struct {
Ino uint64
MpID uint64
- CreateTime int64 //time.Now().Unix()
+ CreateTime int64 // time.Now().Unix()
Timeout int64
TxID string
MpMembers string
@@ -266,7 +268,7 @@ type TxDentryInfo struct {
MpMembers string
TxID string
MpID uint64
- CreateTime int64 //time.Now().Unix()
+ CreateTime int64 // time.Now().Unix()
Timeout int64
}
@@ -463,8 +465,8 @@ type TransactionInfo struct {
TxID string // "metapartitionId_atomicId", if empty, mp should be TM, otherwise it will be RM
TxType uint32
TmID int64
- CreateTime int64 //time.Now()
- Timeout int64 //minutes
+ CreateTime int64 // time.Now()
+ Timeout int64 // minutes
State int32
DoneTime int64 // time.now()
RMFinish bool // used to check whether tx success on target rm.
diff --git a/proto/transaction_test.go b/proto/transaction_test.go
index 624ccefc6..fa318e7db 100644
--- a/proto/transaction_test.go
+++ b/proto/transaction_test.go
@@ -1,10 +1,11 @@
package proto
import (
- "github.com/stretchr/testify/require"
"reflect"
"testing"
"time"
+
+ "github.com/stretchr/testify/require"
)
func TestGetMaskFromString(t *testing.T) {
@@ -51,7 +52,7 @@ func TestTxInodeInfoMarshal(t *testing.T) {
MpID: 11,
CreateTime: 10110,
Timeout: 112,
- //TxID: "tx123",
+ // TxID: "tx123",
}
bs, err := ifo.Marshal()
@@ -75,7 +76,7 @@ func TestTxDentryInfoMarshal(t *testing.T) {
MpID: 11,
CreateTime: 10110,
Timeout: 112,
- //TxID: "tx123",
+ // TxID: "tx123",
}
bs, err := ifo.Marshal()
diff --git a/proto/user_proto.go b/proto/user_proto.go
index 3414b2186..60e94bea6 100644
--- a/proto/user_proto.go
+++ b/proto/user_proto.go
@@ -23,8 +23,10 @@ import (
var (
AKRegexp = regexp.MustCompile("^[a-zA-Z0-9]{16}$")
SKRegexp = regexp.MustCompile("^[a-zA-Z0-9]{32}$")
- WriteS3Api = []string{"PostObject", "PutObject", "CopyObject", "CreateMultipartUpload", "UploadPart", "UploadPartCopy",
- "CompleteMultipartUpload", "AbortMultipartUpload", "DeleteObjects", "DeleteObject"}
+ WriteS3Api = []string{
+ "PostObject", "PutObject", "CopyObject", "CreateMultipartUpload", "UploadPart", "UploadPartCopy",
+ "CompleteMultipartUpload", "AbortMultipartUpload", "DeleteObjects", "DeleteObject",
+ }
)
type UserType uint8
@@ -104,7 +106,7 @@ type UserInfo struct {
CreateTime string `json:"create_time" graphql:"create_time"`
Description string `json:"description" graphql:"description"`
Mu sync.RWMutex `json:"-" graphql:"-"`
- EMPTY bool //graphql need ???
+ EMPTY bool // graphql need ???
}
func (i *UserInfo) String() string {
@@ -225,7 +227,7 @@ func (policy *UserPolicy) RemoveOwnVol(volume string) {
}
}
-func (policy *UserPolicy) AddAuthorizedVol(volume string, policies []string) { //todo check duplicate
+func (policy *UserPolicy) AddAuthorizedVol(volume string, policies []string) { // todo check duplicate
policy.mu.Lock()
defer policy.mu.Unlock()
newPolicies := make([]string, 0)
@@ -255,7 +257,7 @@ func (policy *UserPolicy) SetPerm(volume string, perm Permission) {
func (policy *UserPolicy) SetActions(volume string, actions Actions) {
policy.mu.Lock()
defer policy.mu.Unlock()
- var values = make([]string, actions.Len())
+ values := make([]string, actions.Len())
for i, action := range actions {
values[i] = action.String()
}
diff --git a/raftstore/log_test.go b/raftstore/log_test.go
index d877bb3d0..63d243d9b 100644
--- a/raftstore/log_test.go
+++ b/raftstore/log_test.go
@@ -12,7 +12,7 @@ func TestCleanRaftLog(t *testing.T) {
dir := path.Join("/tmp/raft", "logs")
_, err := os.Stat(dir)
if os.IsNotExist(err) {
- os.MkdirAll(dir, 0755)
+ os.MkdirAll(dir, 0o755)
}
logFilePath1 := path.Join(dir, "raft_info.log.old")
diff --git a/raftstore/monitor.go b/raftstore/monitor.go
index 56ec50fa1..49705e462 100644
--- a/raftstore/monitor.go
+++ b/raftstore/monitor.go
@@ -2,12 +2,13 @@ package raftstore
import (
"fmt"
+ "sync"
+ "time"
+
"github.com/cubefs/cubefs/depends/tiglabs/raft/proto"
"github.com/cubefs/cubefs/util/config"
"github.com/cubefs/cubefs/util/exporter"
"github.com/cubefs/cubefs/util/log"
- "sync"
- "time"
)
const (
diff --git a/raftstore/partition.go b/raftstore/partition.go
index d8869e6d5..8d23976f8 100644
--- a/raftstore/partition.go
+++ b/raftstore/partition.go
@@ -66,9 +66,7 @@ type Partition interface {
// Truncate raft log
Truncate(index uint64)
-
TryToLeader(nodeID uint64) error
-
IsOfflinePeer() bool
}
diff --git a/raftstore/raftstore.go b/raftstore/raftstore.go
index ad67ab1ed..c54f51484 100644
--- a/raftstore/raftstore.go
+++ b/raftstore/raftstore.go
@@ -75,13 +75,12 @@ func (s *raftStore) Stop() {
}
func newRaftLogger(dir string) {
-
raftLogPath := path.Join(dir, "logs")
_, err := os.Stat(raftLogPath)
if err != nil {
if pathErr, ok := err.(*os.PathError); ok {
if os.IsNotExist(pathErr) {
- os.MkdirAll(raftLogPath, 0755)
+ os.MkdirAll(raftLogPath, 0o755)
}
}
}
diff --git a/raftstore/raftstore_db/store_rocksdb.go b/raftstore/raftstore_db/store_rocksdb.go
index 6ecc1c216..384d7adc0 100644
--- a/raftstore/raftstore_db/store_rocksdb.go
+++ b/raftstore/raftstore_db/store_rocksdb.go
@@ -16,9 +16,8 @@ package raftstore_db
import (
"fmt"
- "strings"
-
"os"
+ "strings"
"github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/fileutil"
@@ -48,7 +47,6 @@ func (rs *RocksDBStore) GetDir() string {
// NewRocksDBStore returns a new RocksDB instance.
func NewRocksDBStore(dir string, lruCacheSize, writeBufferSize int) (store *RocksDBStore, err error) {
-
if err = os.MkdirAll(dir, os.ModePerm); err != nil {
return
}
diff --git a/raftstore/resolver.go b/raftstore/resolver.go
index aac10101d..97365b691 100644
--- a/raftstore/resolver.go
+++ b/raftstore/resolver.go
@@ -16,10 +16,11 @@ package raftstore
import (
"fmt"
- "github.com/cubefs/cubefs/depends/tiglabs/raft"
- "github.com/cubefs/cubefs/util/errors"
"strings"
"sync"
+
+ "github.com/cubefs/cubefs/depends/tiglabs/raft"
+ "github.com/cubefs/cubefs/util/errors"
)
// Error definitions.
diff --git a/regression/idempotent/main.go b/regression/idempotent/main.go
index 3bce83bc0..a0a72c418 100644
--- a/regression/idempotent/main.go
+++ b/regression/idempotent/main.go
@@ -58,7 +58,7 @@ func main() {
data1 := "1111\n"
data2 := "2222\n"
- file1, err := os.OpenFile(outPath1, os.O_WRONLY|os.O_CREATE, 0666)
+ file1, err := os.OpenFile(outPath1, os.O_WRONLY|os.O_CREATE, 0o666)
if err != nil {
fmt.Println(err)
return
diff --git a/regression/overlapping/main.go b/regression/overlapping/main.go
index 6dfaefbe6..e9e1bc6a8 100644
--- a/regression/overlapping/main.go
+++ b/regression/overlapping/main.go
@@ -30,13 +30,13 @@ func main() {
outPath2 := os.Args[2]
data := "aoifjiwjefojwofoiwenfowepojpjoipgnoirngo\n"
- file1, err := os.OpenFile(outPath1, os.O_WRONLY|os.O_CREATE, 0666)
+ file1, err := os.OpenFile(outPath1, os.O_WRONLY|os.O_CREATE, 0o666)
if err != nil {
fmt.Println(err)
return
}
defer file1.Close()
- file2, err := os.OpenFile(outPath2, os.O_WRONLY|os.O_CREATE, 0666)
+ file2, err := os.OpenFile(outPath2, os.O_WRONLY|os.O_CREATE, 0o666)
if err != nil {
fmt.Println(err)
return
diff --git a/repl/packet.go b/repl/packet.go
index 1be5e13fd..00115901e 100644
--- a/repl/packet.go
+++ b/repl/packet.go
@@ -16,7 +16,6 @@ package repl
import (
"fmt"
- "github.com/cubefs/cubefs/util/log"
"io"
"net"
"strings"
@@ -28,6 +27,7 @@ import (
"github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/errors"
"github.com/cubefs/cubefs/util/exporter"
+ "github.com/cubefs/cubefs/util/log"
)
var (
@@ -135,7 +135,6 @@ func copyPacket(src *Packet, dst *FollowerPacket) {
dst.ExtentOffset = src.ExtentOffset
dst.ReqID = src.ReqID
dst.Data = src.OrgBuffer
-
}
func (p *Packet) BeforeTp(clusterID string) (ok bool) {
@@ -289,9 +288,7 @@ func (p *Packet) getErrMessage() (m string) {
return fmt.Sprintf("req(%v) err(%v)", p.GetUniqueLogId(), string(p.Data[:p.Size]))
}
-var (
- ErrorUnknownOp = errors.New("unknown opcode")
-)
+var ErrorUnknownOp = errors.New("unknown opcode")
func (p *Packet) identificationErrorResultCode(errLog string, errMsg string) {
log.LogDebugf("action[identificationErrorResultCode] error %v, errmsg %v", errLog, errMsg)
diff --git a/repl/repl_protocol.go b/repl/repl_protocol.go
index 53d20787d..215025c5f 100644
--- a/repl/repl_protocol.go
+++ b/repl/repl_protocol.go
@@ -19,7 +19,6 @@ import (
"fmt"
"net"
"sync"
-
"sync/atomic"
"time"
@@ -28,9 +27,7 @@ import (
"github.com/cubefs/cubefs/util/log"
)
-var (
- gConnPool = util.NewConnectPool()
-)
+var gConnPool = util.NewConnectPool()
// ReplProtocol defines the struct of the replication protocol.
// 1. ServerConn reads a packet from the client socket, and analyzes the addresses of the followers.
@@ -217,9 +214,7 @@ func (rp *ReplProtocol) SetSmux(f func(addr string) (net.Conn, error), putSmux f
// ServerConn keeps reading data from the socket to analyze the follower address, execute the prepare function,
// and throw the packets to the to-be-processed channel.
func (rp *ReplProtocol) ServerConn() {
- var (
- err error
- )
+ var err error
defer func() {
rp.Stop()
rp.exitedMu.Lock()
@@ -239,7 +234,6 @@ func (rp *ReplProtocol) ServerConn() {
}
}
}
-
}
// Receive response from all followers.
@@ -273,7 +267,7 @@ func (rp *ReplProtocol) readPkgAndPrepare() (err error) {
if err = request.ReadFromConnWithVer(rp.sourceConn, proto.NoReadDeadlineTime); err != nil {
return
}
- //log.LogDebugf("action[readPkgAndPrepare] packet(%v) op %v from remote(%v) conn(%v) ",
+ // log.LogDebugf("action[readPkgAndPrepare] packet(%v) op %v from remote(%v) conn(%v) ",
// request.GetUniqueLogId(), request.Opcode, rp.sourceConn.RemoteAddr().String(), rp.sourceConn)
if err = request.resolveFollowersAddr(); err != nil {
@@ -341,7 +335,6 @@ func (rp *ReplProtocol) OperatorAndForwardPktGoRoutine() {
return
}
}
-
}
func (rp *ReplProtocol) writeResponseToClientGoRroutine() {
@@ -359,7 +352,6 @@ func (rp *ReplProtocol) writeResponseToClientGoRroutine() {
return
}
}
-
}
// func (rp *ReplProtocol) operatorFuncWithWaitGroup(wg *sync.WaitGroup, request *Packet) {
@@ -371,9 +363,7 @@ func (rp *ReplProtocol) writeResponseToClientGoRroutine() {
// If failed to read the response, then mark the packet as failure, and delete it from the list.
// If all the reads succeed, then mark the packet as success.
func (rp *ReplProtocol) checkLocalResultAndReciveAllFollowerResponse() {
- var (
- e *list.Element
- )
+ var e *list.Element
if e = rp.getNextPacket(); e == nil {
return
@@ -443,7 +433,6 @@ func (rp *ReplProtocol) Stop() {
}
atomic.StoreInt32(&rp.exited, ReplExiting)
}
-
}
type SmuxConn struct {
diff --git a/sdk/auth/client.go b/sdk/auth/client.go
index 23fae3037..1e49e98f6 100644
--- a/sdk/auth/client.go
+++ b/sdk/auth/client.go
@@ -17,15 +17,15 @@ package auth
import (
"encoding/json"
"fmt"
+ "net/http"
+ "os"
+ "sync"
+ "time"
+
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/auth"
"github.com/cubefs/cubefs/util/cryptoutil"
"github.com/cubefs/cubefs/util/keystore"
- "io/ioutil"
- "net/http"
- "sync"
- "time"
-
"github.com/cubefs/cubefs/util/log"
)
@@ -77,7 +77,7 @@ func (c *AuthClient) request(clientID, clientKey string, key []byte, data interf
urlProto = "http://"
client = &http.Client{}
}
- //TODO don't retry if the param is wrong
+ // TODO don't retry if the param is wrong
for i := 0; i < RequestMaxRetry; i++ {
for _, ip := range c.authnodes {
url = urlProto + ip + path
@@ -183,7 +183,7 @@ func (c *AuthClient) serveAdminRequest(id, key string, ticket *auth.Ticket, keyI
}
func loadCertfile(path string) (caCert []byte, err error) {
- caCert, err = ioutil.ReadFile(path)
+ caCert, err = os.ReadFile(path)
if err != nil {
return
}
diff --git a/sdk/data/blobstore/blobstore_client.go b/sdk/data/blobstore/blobstore_client.go
index eabb8a3c9..87a2e0f67 100644
--- a/sdk/data/blobstore/blobstore_client.go
+++ b/sdk/data/blobstore/blobstore_client.go
@@ -41,7 +41,6 @@ type BlobStoreClient struct {
}
func NewEbsClient(cfg access.Config) (*BlobStoreClient, error) {
-
cli, err := access.New(cfg)
return &BlobStoreClient{
client: cli,
@@ -81,11 +80,9 @@ func (ebs *BlobStoreClient) Read(ctx context.Context, volName string, buf []byte
BlobSize: oek.BlobSize,
Blobs: sliceInfos,
}
- //func get has retry
+ // func get has retry
log.LogDebugf("TRACE Ebs Read,oek(%v) loc(%v)", oek, loc)
- var (
- body io.ReadCloser
- )
+ var body io.ReadCloser
defer func() {
if body != nil {
body.Close()
diff --git a/sdk/data/blobstore/blobstore_client_test.go b/sdk/data/blobstore/blobstore_client_test.go
index c54ca230d..b7cd7fa29 100644
--- a/sdk/data/blobstore/blobstore_client_test.go
+++ b/sdk/data/blobstore/blobstore_client_test.go
@@ -36,9 +36,7 @@ const (
blobSize = 1 << 20
)
-var (
- dataCache []byte
-)
+var dataCache []byte
type MockEbsService struct {
service *httptest.Server
@@ -181,7 +179,7 @@ func TestEbsClient_Write_Read(t *testing.T) {
if err != nil {
panic(err)
}
- var testCases = []struct {
+ testCases := []struct {
size int
}{
{1},
@@ -195,7 +193,7 @@ func TestEbsClient_Write_Read(t *testing.T) {
location, err := blobStoreClient.Write(ctx, "testVol", data, uint32(tc.size))
require.Exactly(t, nil, err)
- //read prepare
+ // read prepare
blobs := make([]cproto.Blob, 0)
for _, info := range location.Blobs {
blob := cproto.Blob{
@@ -219,5 +217,4 @@ func TestEbsClient_Write_Read(t *testing.T) {
require.NoError(t, err)
require.Exactly(t, tc.size, read)
}
-
}
diff --git a/sdk/data/blobstore/reader.go b/sdk/data/blobstore/reader.go
index f442ce959..c229cefd0 100644
--- a/sdk/data/blobstore/reader.go
+++ b/sdk/data/blobstore/reader.go
@@ -17,22 +17,21 @@ package blobstore
import (
"context"
"fmt"
- "github.com/cubefs/cubefs/sdk/data/manager"
"io"
"os"
"sync"
"syscall"
"time"
- "github.com/cubefs/cubefs/util/exporter"
- "github.com/cubefs/cubefs/util/stat"
-
"github.com/cubefs/cubefs/blockcache/bcache"
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/sdk/data/manager"
"github.com/cubefs/cubefs/sdk/data/stream"
"github.com/cubefs/cubefs/sdk/meta"
"github.com/cubefs/cubefs/util"
+ "github.com/cubefs/cubefs/util/exporter"
"github.com/cubefs/cubefs/util/log"
+ "github.com/cubefs/cubefs/util/stat"
)
type rwSlice struct {
@@ -180,7 +179,6 @@ func (reader *Reader) Read(ctx context.Context, buf []byte, offset int, size int
}
log.LogDebugf("TRACE reader Read Exit. ino(%v) readN(%v) buf-len(%v)", reader.ino, read, len(buf))
return read, nil
-
}
func (reader *Reader) Close(ctx context.Context) {
@@ -268,7 +266,6 @@ func (reader *Reader) buildExtentKey(rs *rwSlice) {
}
rs.extentKey = proto.ExtentKey{}
}
-
}
func (reader *Reader) readSliceRange(ctx context.Context, rs *rwSlice) (err error) {
@@ -277,9 +274,7 @@ func (reader *Reader) readSliceRange(ctx context.Context, rs *rwSlice) (err erro
cacheKey := util.GenerateKey(reader.volName, reader.ino, rs.fileOffset)
log.LogDebugf("TRACE blobStore readSliceRange. ino(%v) cacheKey(%v) ", reader.ino, cacheKey)
buf := make([]byte, rs.rSize)
- var (
- readN int
- )
+ var readN int
bgTime := stat.BeginStat()
stat.EndStat("CacheGet", nil, bgTime, 1)
@@ -289,7 +284,7 @@ func (reader *Reader) readSliceRange(ctx context.Context, rs *rwSlice) (err erro
metric.SetWithLabels(err, map[string]string{exporter.Vol: reader.volName})
}()
- //read local cache
+ // read local cache
if reader.enableBcache {
readN, err = reader.bc.Get(cacheKey, buf, rs.rOffset, rs.rSize)
if err == nil {
@@ -311,10 +306,10 @@ func (reader *Reader) readSliceRange(ctx context.Context, rs *rwSlice) (err erro
}
readLimitOn := false
- //read cfs and cache to bcache
+ // read cfs and cache to bcache
if rs.extentKey != (proto.ExtentKey{}) {
- //check if dp is exist in preload sence
+ // check if dp is exist in preload sence
err = reader.ec.CheckDataPartitionExsit(rs.extentKey.PartitionId)
if err == nil || ctx.Value("objectnode") != nil {
readN, err, readLimitOn = reader.ec.ReadExtent(reader.ino, &rs.extentKey, buf, int(rs.rOffset), int(rs.rSize))
@@ -348,7 +343,7 @@ func (reader *Reader) readSliceRange(ctx context.Context, rs *rwSlice) (err erro
read := copy(rs.Data, buf)
reader.err <- nil
- //cache full block
+ // cache full block
if !reader.needCacheL1() && !reader.needCacheL2() || reader.ec.IsPreloadMode() {
log.LogDebugf("TRACE blobStore readSliceRange exit without cache. read counter=%v", read)
return nil
diff --git a/sdk/data/blobstore/reader_test.go b/sdk/data/blobstore/reader_test.go
index d88122004..a61fcb81a 100644
--- a/sdk/data/blobstore/reader_test.go
+++ b/sdk/data/blobstore/reader_test.go
@@ -17,7 +17,6 @@ package blobstore
import (
"context"
"fmt"
- "github.com/cubefs/cubefs/sdk/data/manager"
"io"
"math/rand"
"os"
@@ -26,12 +25,14 @@ import (
"testing"
"github.com/brahma-adshonor/gohook"
+ "github.com/stretchr/testify/assert"
+
"github.com/cubefs/cubefs/blockcache/bcache"
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/sdk/data/manager"
"github.com/cubefs/cubefs/sdk/data/stream"
"github.com/cubefs/cubefs/sdk/meta"
"github.com/cubefs/cubefs/util/errors"
- "github.com/stretchr/testify/assert"
)
func TestNewReader(t *testing.T) {
@@ -64,7 +65,6 @@ func TestNewReader(t *testing.T) {
}
func TestBuildExtentKey(t *testing.T) {
-
testCase := []struct {
eks []proto.ExtentKey
expectEk proto.ExtentKey
@@ -327,7 +327,6 @@ func TestAsyncCache(t *testing.T) {
reader.cacheAction = tc.cacheAction
reader.asyncCache(ctx, "cacheKey", objEk)
}
-
}
func TestNeedCacheL2(t *testing.T) {
@@ -392,16 +391,36 @@ func TestReadSliceRange(t *testing.T) {
ebsReadFunc func(*BlobStoreClient, context.Context, string, []byte, uint64, uint64, proto.ObjExtentKey) (int, error)
expectError error
}{
- {false, proto.ExtentKey{}, MockGetTrue, MockCheckDataPartitionExistTrue,
- MockReadExtentTrue, MockEbscReadTrue, nil},
- {false, proto.ExtentKey{}, MockGetTrue, MockCheckDataPartitionExistTrue,
- MockReadExtentTrue, MockEbscReadFalse, syscall.EIO},
- {true, proto.ExtentKey{}, MockGetTrue, MockCheckDataPartitionExistTrue,
- MockReadExtentTrue, MockEbscReadFalse, nil},
- {true, proto.ExtentKey{}, MockGetFalse, MockCheckDataPartitionExistTrue,
- MockReadExtentTrue, MockEbscReadFalse, syscall.EIO},
- {true, proto.ExtentKey{}, MockGetFalse, MockCheckDataPartitionExistTrue,
- MockReadExtentTrue, MockEbscReadTrue, nil},
+ {
+ false,
+ proto.ExtentKey{},
+ MockGetTrue, MockCheckDataPartitionExistTrue,
+ MockReadExtentTrue, MockEbscReadTrue, nil,
+ },
+ {
+ false,
+ proto.ExtentKey{},
+ MockGetTrue, MockCheckDataPartitionExistTrue,
+ MockReadExtentTrue, MockEbscReadFalse, syscall.EIO,
+ },
+ {
+ true,
+ proto.ExtentKey{},
+ MockGetTrue, MockCheckDataPartitionExistTrue,
+ MockReadExtentTrue, MockEbscReadFalse, nil,
+ },
+ {
+ true,
+ proto.ExtentKey{},
+ MockGetFalse, MockCheckDataPartitionExistTrue,
+ MockReadExtentTrue, MockEbscReadFalse, syscall.EIO,
+ },
+ {
+ true,
+ proto.ExtentKey{},
+ MockGetFalse, MockCheckDataPartitionExistTrue,
+ MockReadExtentTrue, MockEbscReadTrue, nil,
+ },
}
for _, tc := range testCase {
@@ -514,6 +533,7 @@ func MockWriteFalse(client *stream.ExtentClient, inode uint64, offset int, data
func MockPutTrue(bc *bcache.BcacheClient, key string, buf []byte) error {
return nil
}
+
func MockPutFalse(bc *bcache.BcacheClient, key string, buf []byte) error {
return errors.New("Bcache put failed")
}
diff --git a/sdk/data/blobstore/task_pool_test.go b/sdk/data/blobstore/task_pool_test.go
index 944abfba6..cb1fcf34f 100644
--- a/sdk/data/blobstore/task_pool_test.go
+++ b/sdk/data/blobstore/task_pool_test.go
@@ -15,12 +15,13 @@
package blobstore
import (
- "github.com/cubefs/cubefs/proto"
- "github.com/stretchr/testify/assert"
"math/rand"
"sync"
"testing"
"time"
+
+ "github.com/cubefs/cubefs/proto"
+ "github.com/stretchr/testify/assert"
)
func TestNew(t *testing.T) {
@@ -58,9 +59,9 @@ func TestNew(t *testing.T) {
pool := New(3, sliceSize)
wg.Add(sliceSize)
for _, rs := range rSlices {
- //rs_ := rs
+ // rs_ := rs
pool.Execute(&rs, func(param *rwSlice) {
- //syslog.Printf("pool.Execute rs = %v", rs_)
+ // syslog.Printf("pool.Execute rs = %v", rs_)
time.Sleep(1 * time.Second)
wg.Done()
})
diff --git a/sdk/data/blobstore/writer.go b/sdk/data/blobstore/writer.go
index 7aafb2a7d..9eab095d0 100644
--- a/sdk/data/blobstore/writer.go
+++ b/sdk/data/blobstore/writer.go
@@ -105,7 +105,7 @@ func (writer *Writer) String() string {
}
func (writer *Writer) WriteWithoutPool(ctx context.Context, offset int, data []byte) (size int, err error) {
- //atomic.StoreInt32(&writer.idle, 0)
+ // atomic.StoreInt32(&writer.idle, 0)
if writer == nil {
return 0, fmt.Errorf("writer is not opened yet")
}
@@ -118,7 +118,7 @@ func (writer *Writer) WriteWithoutPool(ctx context.Context, offset int, data []b
err = syscall.EOPNOTSUPP
return
}
- //write buffer
+ // write buffer
log.LogDebugf("TRACE blobStore WriteWithoutPool: ino(%v) offset(%v) len(%v)",
writer.ino, offset, len(data))
@@ -128,7 +128,7 @@ func (writer *Writer) WriteWithoutPool(ctx context.Context, offset int, data []b
}
func (writer *Writer) Write(ctx context.Context, offset int, data []byte, flags int) (size int, err error) {
- //atomic.StoreInt32(&writer.idle, 0)
+ // atomic.StoreInt32(&writer.idle, 0)
if writer == nil {
return 0, fmt.Errorf("writer is not opened yet")
}
@@ -139,13 +139,13 @@ func (writer *Writer) Write(ctx context.Context, offset int, data []byte, flags
err = syscall.EOPNOTSUPP
return
}
- //write buffer
+ // write buffer
log.LogDebugf("TRACE blobStore Write: ino(%v) offset(%v) len(%v) flags&proto.FlagsSyncWrite(%v)", writer.ino, offset, len(data), flags&proto.FlagsSyncWrite)
if flags&proto.FlagsSyncWrite == 0 {
size, err = writer.doBufferWrite(ctx, data, offset)
return
}
- //parallel io write ebs direct
+ // parallel io write ebs direct
size, err = writer.doParallelWrite(ctx, data, offset)
return
}
@@ -176,7 +176,7 @@ func (writer *Writer) doParallelWrite(ctx context.Context, data []byte, offset i
}
}
close(writer.err)
- //update meta
+ // update meta
oeks := make([]proto.ObjExtentKey, 0)
for _, wSlice := range wSlices {
size += int(wSlice.size)
@@ -514,7 +514,6 @@ func (writer *Writer) asyncCache(ino uint64, offset int, data []byte) {
log.LogDebugf("TRACE asyncCache Enter,fileOffset(%v) len(%v)", offset, len(data))
write, err := writer.ec.Write(ino, offset, data, proto.FlagsCache, nil)
log.LogDebugf("TRACE asyncCache Exit,write(%v) err(%v)", write, err)
-
}
func (writer *Writer) resetBufferWithoutPool() {
@@ -522,7 +521,7 @@ func (writer *Writer) resetBufferWithoutPool() {
}
func (writer *Writer) resetBuffer() {
- //writer.buf = writer.buf[:0]
+ // writer.buf = writer.buf[:0]
writer.blockPosition = 0
}
@@ -557,7 +556,7 @@ func (writer *Writer) flushWithoutPool(inode uint64, ctx context.Context, flushF
}
oeks := make([]proto.ObjExtentKey, 0)
- //update meta
+ // update meta
oeks = append(oeks, wSlice.objExtentKey)
if err = writer.mw.AppendObjExtentKeys(writer.ino, oeks); err != nil {
log.LogErrorf("slice write error,meta append ebsc extent keys fail,ino(%v) fileOffset(%v) len(%v) err(%v)", inode, wSlice.fileOffset, wSlice.size, err)
@@ -600,7 +599,7 @@ func (writer *Writer) flush(inode uint64, ctx context.Context, flushFlag bool) (
}
oeks := make([]proto.ObjExtentKey, 0)
- //update meta
+ // update meta
oeks = append(oeks, wSlice.objExtentKey)
if err = writer.mw.AppendObjExtentKeys(writer.ino, oeks); err != nil {
log.LogErrorf("slice write error,meta append ebsc extent keys fail,ino(%v) fileOffset(%v) len(%v) err(%v)", inode, wSlice.fileOffset, wSlice.size, err)
diff --git a/sdk/data/blobstore/writer_test.go b/sdk/data/blobstore/writer_test.go
index 6481391d9..72864a0be 100644
--- a/sdk/data/blobstore/writer_test.go
+++ b/sdk/data/blobstore/writer_test.go
@@ -32,13 +32,10 @@ import (
"github.com/cubefs/cubefs/util/buf"
)
-var (
- writer *Writer
-)
+var writer *Writer
func init() {
-
- //start ebs mock service
+ // start ebs mock service
mockServer := NewMockEbsService()
cfg := access.Config{
ConnMode: access.QuickConnMode,
@@ -91,16 +88,16 @@ func TestNotInstanceWriter_Write(t *testing.T) {
var flag int
flag |= proto.FlagsAppend
_, err := writer.Write(ctx, 0, data, flag)
- //expect err is not nil
+ // expect err is not nil
if err == nil {
t.Fatalf("write is called by not instance writer.")
}
}
func TestWriter_doBufferWrite_(t *testing.T) {
- //write data to buffer,not write to ebs when len(buffer)= ek.FileOffset && offset < ek.FileOffset+uint64(ek.Size) {
ret = ek
}
diff --git a/sdk/data/stream/extent_client.go b/sdk/data/stream/extent_client.go
index a632a38bd..6c329be29 100644
--- a/sdk/data/stream/extent_client.go
+++ b/sdk/data/stream/extent_client.go
@@ -37,14 +37,16 @@ import (
"golang.org/x/time/rate"
)
-type SplitExtentKeyFunc func(parentInode, inode uint64, key proto.ExtentKey) error
-type AppendExtentKeyFunc func(parentInode, inode uint64, key proto.ExtentKey, discard []proto.ExtentKey) error
-type GetExtentsFunc func(inode uint64) (uint64, uint64, []proto.ExtentKey, error)
-type TruncateFunc func(inode, size uint64, fullPath string) error
-type EvictIcacheFunc func(inode uint64)
-type LoadBcacheFunc func(key string, buf []byte, offset uint64, size uint32) (int, error)
-type CacheBcacheFunc func(key string, buf []byte) error
-type EvictBacheFunc func(key string) error
+type (
+ SplitExtentKeyFunc func(parentInode, inode uint64, key proto.ExtentKey) error
+ AppendExtentKeyFunc func(parentInode, inode uint64, key proto.ExtentKey, discard []proto.ExtentKey) error
+ GetExtentsFunc func(inode uint64) (uint64, uint64, []proto.ExtentKey, error)
+ TruncateFunc func(inode, size uint64, fullPath string) error
+ EvictIcacheFunc func(inode uint64)
+ LoadBcacheFunc func(key string, buf []byte, offset uint64, size uint32) (int, error)
+ CacheBcacheFunc func(key string, buf []byte) error
+ EvictBacheFunc func(key string) error
+)
const (
MaxMountRetryLimit = 6
@@ -149,7 +151,7 @@ type ExtentClient struct {
splitExtentKey SplitExtentKeyFunc
getExtents GetExtentsFunc
truncate TruncateFunc
- evictIcache EvictIcacheFunc //May be null, must check before using
+ evictIcache EvictIcacheFunc // May be null, must check before using
loadBcache LoadBcacheFunc
cacheBcache CacheBcacheFunc
evictBcache EvictBacheFunc
@@ -205,7 +207,6 @@ func (client *ExtentClient) batchEvictStramer(batchCnt int) {
break
}
}
-
}
func (client *ExtentClient) backgroundEvictStream() {
@@ -337,12 +338,15 @@ func (client *ExtentClient) GetVolumeName() string {
func (client *ExtentClient) GetLatestVer() uint64 {
return atomic.LoadUint64(&client.multiVerMgr.latestVerSeq)
}
+
func (client *ExtentClient) GetReadVer() uint64 {
return atomic.LoadUint64(&client.multiVerMgr.verReadSeq)
}
+
func (client *ExtentClient) GetVerMgr() *proto.VolVersionInfoList {
return client.multiVerMgr.verList
}
+
func (client *ExtentClient) UpdateLatestVer(verList *proto.VolVersionInfoList) (err error) {
verSeq := verList.GetLastVer()
if verSeq == 0 || verSeq <= atomic.LoadUint64(&client.multiVerMgr.latestVerSeq) {
@@ -553,8 +557,8 @@ func (client *ExtentClient) Flush(inode uint64) error {
}
func (client *ExtentClient) Read(inode uint64, data []byte, offset int, size int) (read int, err error) {
- //log.LogErrorf("======> ExtentClient Read Enter, inode(%v), len(data)=(%v), offset(%v), size(%v).", inode, len(data), offset, size)
- //t1 := time.Now()
+ // log.LogErrorf("======> ExtentClient Read Enter, inode(%v), len(data)=(%v), offset(%v), size(%v).", inode, len(data), offset, size)
+ // t1 := time.Now()
if size == 0 {
return
}
@@ -605,7 +609,7 @@ func (client *ExtentClient) ReadExtent(inode uint64, ek *proto.ExtentKey, data [
return
}
- var needCache = false
+ needCache := false
cacheKey := util.GenerateKey(s.client.volumeName, s.inode, ek.FileOffset)
if _, ok := client.inflightL1cache.Load(cacheKey); !ok && client.shouldBcache() {
client.inflightL1cache.Store(cacheKey, true)
@@ -615,7 +619,7 @@ func (client *ExtentClient) ReadExtent(inode uint64, ek *proto.ExtentKey, data [
// do cache.
if needCache {
- //read full extent
+ // read full extent
buf := make([]byte, ek.Size)
req = NewExtentRequest(int(ek.FileOffset), int(ek.Size), buf, ek)
read, err = reader.Read(req)
@@ -637,7 +641,7 @@ func (client *ExtentClient) ReadExtent(inode uint64, ek *proto.ExtentKey, data [
}
return
} else {
- //read data by offset:size
+ // read data by offset:size
req = NewExtentRequest(int(ek.FileOffset)+offset, size, data, ek)
ctx := context.Background()
s.client.readLimiter.Wait(ctx)
diff --git a/sdk/data/stream/extent_handler.go b/sdk/data/stream/extent_handler.go
index 46f756159..7aecccacc 100644
--- a/sdk/data/stream/extent_handler.go
+++ b/sdk/data/stream/extent_handler.go
@@ -16,7 +16,6 @@ package stream
import (
"fmt"
- "github.com/cubefs/cubefs/util/stat"
"net"
"sync/atomic"
"time"
@@ -26,6 +25,7 @@ import (
"github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/errors"
"github.com/cubefs/cubefs/util/log"
+ "github.com/cubefs/cubefs/util/stat"
)
// State machines
@@ -36,9 +36,7 @@ const (
ExtentStatusError
)
-var (
- gExtentHandlerID = uint64(0)
-)
+var gExtentHandlerID = uint64(0)
// GetExtentHandlerID returns the extent handler ID.
func GetExtentHandlerID() uint64 {
@@ -175,7 +173,7 @@ func (eh *ExtentHandler) write(data []byte, offset, size int, direct bool) (ek *
if direct {
eh.packet.Opcode = proto.OpSyncWrite
}
- //log.LogDebugf("ExtentHandler Write: NewPacket, eh(%v) packet(%v)", eh, eh.packet)
+ // log.LogDebugf("ExtentHandler Write: NewPacket, eh(%v) packet(%v)", eh, eh.packet)
}
packsize := int(eh.packet.Size)
write = util.Min(size-total, blksize-packsize)
@@ -351,9 +349,7 @@ func (eh *ExtentHandler) processReply(packet *Packet) {
eh.dp.RecordWrite(packet.StartT)
- var (
- extID, extOffset uint64
- )
+ var extID, extOffset uint64
if eh.storeMode == proto.TinyExtentType {
extID = reply.ExtentID
@@ -566,7 +562,7 @@ func (eh *ExtentHandler) allocateExtent() (err error) {
eh.conn = conn
eh.extID = extID
- //log.LogDebugf("ExtentHandler allocateExtent exit: eh(%v) dp(%v) extID(%v)", eh, dp, extID)
+ // log.LogDebugf("ExtentHandler allocateExtent exit: eh(%v) dp(%v) extID(%v)", eh, dp, extID)
return nil
}
diff --git a/sdk/data/stream/extent_reader.go b/sdk/data/stream/extent_reader.go
index 85af40cc5..d55783151 100644
--- a/sdk/data/stream/extent_reader.go
+++ b/sdk/data/stream/extent_reader.go
@@ -77,7 +77,7 @@ func (reader *ExtentReader) Read(req *ExtentRequest) (readBytes int, err error)
return TryOtherAddrError, false
}
- //log.LogDebugf("ExtentReader Read: ResultCode(%v) req(%v) reply(%v) readBytes(%v)", replyPacket.GetResultMsg(), reqPacket, replyPacket, readBytes)
+ // log.LogDebugf("ExtentReader Read: ResultCode(%v) req(%v) reply(%v) readBytes(%v)", replyPacket.GetResultMsg(), reqPacket, replyPacket, readBytes)
if replyPacket.ResultCode == proto.OpAgain {
return nil, true
@@ -97,7 +97,7 @@ func (reader *ExtentReader) Read(req *ExtentRequest) (readBytes int, err error)
})
if err != nil {
- //if cold vol and cach is invaild
+ // if cold vol and cach is invaild
if !reader.retryRead && (err == TryOtherAddrError || strings.Contains(err.Error(), "ExistErr")) {
log.LogWarnf("Extent Reader Read: err(%v) req(%v) reqPacket(%v)", err, req, reqPacket)
} else {
diff --git a/sdk/data/stream/packet.go b/sdk/data/stream/packet.go
index 32ff58e69..17a0d279e 100644
--- a/sdk/data/stream/packet.go
+++ b/sdk/data/stream/packet.go
@@ -17,13 +17,14 @@ package stream
import (
"encoding/binary"
"fmt"
- "github.com/cubefs/cubefs/proto"
- "github.com/cubefs/cubefs/sdk/data/wrapper"
- "github.com/cubefs/cubefs/util"
"hash/crc32"
"io"
"net"
"time"
+
+ "github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/sdk/data/wrapper"
+ "github.com/cubefs/cubefs/util"
)
// Packet defines a wrapper of the packet in proto.
diff --git a/sdk/data/stream/stream_conn.go b/sdk/data/stream/stream_conn.go
index a7bd4b7cb..ab4e5569c 100644
--- a/sdk/data/stream/stream_conn.go
+++ b/sdk/data/stream/stream_conn.go
@@ -16,11 +16,11 @@ package stream
import (
"fmt"
- "github.com/cubefs/cubefs/proto"
"net"
"sync/atomic"
"time"
+ "github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/sdk/data/wrapper"
"github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/errors"
@@ -45,9 +45,7 @@ type StreamConn struct {
currAddr string
}
-var (
- StreamConnPool = util.NewConnectPool()
-)
+var StreamConnPool = util.NewConnectPool()
// NewStreamConn returns a new stream connection.
func NewStreamConn(dp *wrapper.DataPartition, follower bool) (sc *StreamConn) {
diff --git a/sdk/data/stream/stream_reader.go b/sdk/data/stream/stream_reader.go
index 1a810868a..3be7d7295 100644
--- a/sdk/data/stream/stream_reader.go
+++ b/sdk/data/stream/stream_reader.go
@@ -184,7 +184,7 @@ func (s *Streamer) read(data []byte, offset int, size int) (total int, err error
bcacheMetric.AddWithLabels(1, map[string]string{exporter.Vol: s.client.volumeName})
}
- //skip hole,ek is not nil,read block cache firstly
+ // skip hole,ek is not nil,read block cache firstly
log.LogDebugf("Stream read: ino(%v) req(%v) s.client.bcacheEnable(%v) s.needBCache(%v)", s.inode, req, s.client.bcacheEnable, s.needBCache)
cacheKey := util.GenerateRepVolKey(s.client.volumeName, s.inode, req.ExtentKey.PartitionId, req.ExtentKey.ExtentId, req.ExtentKey.FileOffset)
if s.client.bcacheEnable && s.needBCache && filesize <= bcache.MaxFileSize {
@@ -207,7 +207,7 @@ func (s *Streamer) read(data []byte, offset int, size int) (total int, err error
bcacheMetric.AddWithLabels(1, map[string]string{exporter.Vol: s.client.volumeName})
}
- //read extent
+ // read extent
reader, err = s.GetExtentReader(req.ExtentKey)
if err != nil {
log.LogErrorf("action[streamer.read] req %v err %v", req, err)
@@ -215,9 +215,9 @@ func (s *Streamer) read(data []byte, offset int, size int) (total int, err error
}
if s.client.bcacheEnable && s.needBCache && filesize <= bcache.MaxFileSize {
- //limit big block cache
+ // limit big block cache
if s.exceedBlockSize(req.ExtentKey.Size) && atomic.LoadInt32(&s.client.inflightL1BigBlock) > 10 {
- //do nothing
+ // do nothing
} else {
select {
case s.pendingCache <- bcacheKey{cacheKey: cacheKey, extentKey: req.ExtentKey}:
@@ -259,7 +259,7 @@ func (s *Streamer) asyncBlockCache() {
cacheKey := pending.cacheKey
log.LogDebugf("asyncBlockCache: cacheKey=(%v) ek=(%v)", cacheKey, ek)
- //read full extent
+ // read full extent
var data []byte
if ek.Size == bcache.MaxBlockSize {
data = buf.BCachePool.Get()
@@ -295,7 +295,6 @@ func (s *Streamer) asyncBlockCache() {
return
}
}
-
}
}
diff --git a/sdk/data/stream/stream_writer.go b/sdk/data/stream/stream_writer.go
index fcf37057b..96f3af3f0 100644
--- a/sdk/data/stream/stream_writer.go
+++ b/sdk/data/stream/stream_writer.go
@@ -302,7 +302,6 @@ func (s *Streamer) handleRequest(request interface{}) {
request.done <- struct{}{}
default:
}
-
}
func (s *Streamer) write(data []byte, offset, size, flags int, checkFunc func() error) (total int, err error) {
@@ -433,7 +432,6 @@ func (s *Streamer) doOverWriteByAppend(req *ExtentRequest, direct bool) (total i
}
func (s *Streamer) tryDirectAppendWrite(req *ExtentRequest, direct bool) (total int, extKey *proto.ExtentKey, err error, status int32) {
-
req.ExtentKey = s.handler.key
return s.doDirectWriteByAppend(req, direct, proto.OpTryWriteAppend)
}
@@ -735,7 +733,7 @@ func (s *Streamer) tryInitExtentHandlerByLastEk(offset, size int) (isLastEkVerNo
VerSeq: seq,
},
}
- //handler.dp = dp
+ // handler.dp = dp
if s.handler != nil {
log.LogDebugf("tryInitExtentHandlerByLastEk: close old handler, currentEK.PartitionId(%v)",
diff --git a/sdk/data/wrapper/data_partition.go b/sdk/data/wrapper/data_partition.go
index 4cd43fe50..481558c41 100644
--- a/sdk/data/wrapper/data_partition.go
+++ b/sdk/data/wrapper/data_partition.go
@@ -105,9 +105,11 @@ type DataPartitionSorter []*DataPartition
func (ds DataPartitionSorter) Len() int {
return len(ds)
}
+
func (ds DataPartitionSorter) Swap(i, j int) {
ds[i], ds[j] = ds[j], ds[i]
}
+
func (ds DataPartitionSorter) Less(i, j int) bool {
return ds[i].Metrics.AvgWriteLatencyNano < ds[j].Metrics.AvgWriteLatencyNano
}
@@ -140,7 +142,6 @@ func (dp *DataPartition) CheckAllHostsIsAvail(exclude map[string]struct{}) {
}
conn.Close()
}
-
}
// GetAllAddrs returns the addresses of all the replicas of the data partition.
diff --git a/sdk/data/wrapper/data_partition_selector.go b/sdk/data/wrapper/data_partition_selector.go
index 2fd2880d3..3f9e224f4 100644
--- a/sdk/data/wrapper/data_partition_selector.go
+++ b/sdk/data/wrapper/data_partition_selector.go
@@ -53,7 +53,7 @@ var (
// RegisterDataPartitionSelector registers a selector constructor.
// Users can register their own defined selector through this method.
func RegisterDataPartitionSelector(name string, constructor DataPartitionSelectorConstructor) error {
- var clearName = strings.TrimSpace(strings.ToLower(name))
+ clearName := strings.TrimSpace(strings.ToLower(name))
if _, exist := dataPartitionSelectorConstructors[clearName]; exist {
return ErrDuplicatedDataPartitionSelectorConstructor
}
@@ -62,7 +62,7 @@ func RegisterDataPartitionSelector(name string, constructor DataPartitionSelecto
}
func newDataPartitionSelector(name string, param string) (newDpSelector DataPartitionSelector, err error) {
- var clearName = strings.TrimSpace(strings.ToLower(name))
+ clearName := strings.TrimSpace(strings.ToLower(name))
constructor, exist := dataPartitionSelectorConstructors[clearName]
if !exist {
return nil, ErrDataPartitionSelectorConstructorNotExist
@@ -72,7 +72,7 @@ func newDataPartitionSelector(name string, param string) (newDpSelector DataPart
func (w *Wrapper) initDpSelector() (err error) {
w.dpSelectorChanged = false
- var selectorName = w.dpSelectorName
+ selectorName := w.dpSelectorName
if strings.TrimSpace(selectorName) == "" {
log.LogInfof("initDpSelector: can not find dp selector[%v], use default selector", w.dpSelectorName)
selectorName = DefaultRandomSelectorName
@@ -94,7 +94,7 @@ func (w *Wrapper) refreshDpSelector(partitions []*DataPartition) {
w.Lock.RUnlock()
if dpSelectorChanged {
- var selectorName = w.dpSelectorName
+ selectorName := w.dpSelectorName
if strings.TrimSpace(selectorName) == "" {
log.LogWarnf("refreshDpSelector: can not find dp selector[%v], use default selector", w.dpSelectorName)
selectorName = DefaultRandomSelectorName
diff --git a/sdk/data/wrapper/wrapper.go b/sdk/data/wrapper/wrapper.go
index 17af5ac95..b1c9876b1 100644
--- a/sdk/data/wrapper/wrapper.go
+++ b/sdk/data/wrapper/wrapper.go
@@ -292,7 +292,6 @@ func (w *Wrapper) CheckPermission() {
}
func (w *Wrapper) updateVerlist(client SimpleClientInfo) (err error) {
-
verList, err := w.mc.AdminAPI().GetVerList(w.volName)
if err != nil {
log.LogErrorf("CheckReadVerSeq: get cluster fail: err(%v)", err)
@@ -348,8 +347,7 @@ func (w *Wrapper) updateSimpleVolView() (err error) {
}
func (w *Wrapper) updateDataPartitionByRsp(isInit bool, DataPartitions []*proto.DataPartitionResponse) (err error) {
-
- var convert = func(response *proto.DataPartitionResponse) *DataPartition {
+ convert := func(response *proto.DataPartitionResponse) *DataPartition {
return &DataPartition{
DataPartitionResponse: *response,
ClientWrapper: w,
@@ -371,7 +369,7 @@ func (w *Wrapper) updateDataPartitionByRsp(isInit bool, DataPartitions []*proto.
}
log.LogInfof("updateDataPartition: dp(%v)", dp)
w.replaceOrInsertPartition(dp)
- //do not insert preload dp in cold vol
+ // do not insert preload dp in cold vol
if proto.IsCold(w.volType) && proto.IsPreLoadDp(dp.PartitionType) {
continue
}
@@ -417,7 +415,6 @@ func (w *Wrapper) UpdateDataPartition() (err error) {
// getDataPartitionFromMaster will call master to get data partition info which not include in cache updated by
// updateDataPartition which may not take effect if nginx be placed for reduce the pressure of master
func (w *Wrapper) getDataPartitionFromMaster(isInit bool, dpId uint64) (err error) {
-
var dpInfo *proto.DataPartitionInfo
if dpInfo, err = w.mc.AdminAPI().GetDataPartition(w.volName, dpId); err != nil {
log.LogErrorf("getDataPartitionFromMaster: get data partitions fail: volume(%v) dpId(%v) err(%v)",
@@ -461,7 +458,7 @@ func (w *Wrapper) AllocatePreLoadDataPartition(volName string, count int, capaci
log.LogWarnf("CreatePreLoadDataPartition fail: err(%v)", err)
return
}
- var convert = func(response *proto.DataPartitionResponse) *DataPartition {
+ convert := func(response *proto.DataPartitionResponse) *DataPartition {
return &DataPartition{
DataPartitionResponse: *response,
ClientWrapper: w,
@@ -484,9 +481,7 @@ func (w *Wrapper) AllocatePreLoadDataPartition(volName string, count int, capaci
}
func (w *Wrapper) replaceOrInsertPartition(dp *DataPartition) {
- var (
- oldstatus int8
- )
+ var oldstatus int8
w.Lock.Lock()
old, ok := w.partitions[dp.PartitionID]
if ok {
diff --git a/sdk/graphql/general.go b/sdk/graphql/general.go
index b2d104ea1..379be3f80 100644
--- a/sdk/graphql/general.go
+++ b/sdk/graphql/general.go
@@ -4,21 +4,21 @@ import (
"bytes"
"encoding/json"
"fmt"
+ "os"
+ "strings"
+
"github.com/cubefs/cubefs/master"
"github.com/cubefs/cubefs/proto"
"github.com/samsarahq/thunder/graphql"
"github.com/samsarahq/thunder/graphql/introspection"
- "io/ioutil"
- "os"
- "strings"
)
func main() {
us := master.UserService{}
parseSchema(us.Schema(), proto.AdminUserAPI, "user")
- //vs := master.VolumeService{}
- //parseSchema(vs.Schema(), proto.AdminVolumeAPI, "volume")
+ // vs := master.VolumeService{}
+ // parseSchema(vs.Schema(), proto.AdminVolumeAPI, "volume")
cs := master.ClusterService{}
parseSchema(cs.Schema(), proto.AdminClusterAPI, "cluster")
@@ -127,7 +127,7 @@ func (f *Function) String() string {
var returnBody string
if s, found := structMap[realKind(f.returnType)]; !found {
- //panic(fmt.Sprintf("method:[%s] can return %s, %s", f.name, f.returnType, realKind(f.returnType)))
+ // panic(fmt.Sprintf("method:[%s] can return %s, %s", f.name, f.returnType, realKind(f.returnType)))
println("fun:[%s] the return type %s must can make", f.name, f.returnType)
} else {
returnBody = s.GraphqlFields(3)
@@ -154,7 +154,6 @@ func (f *Function) String() string {
buf.WriteString("\n}")
return buf.String()
-
}
func makeIt(name string) string {
@@ -187,7 +186,7 @@ func (f *Function) VarParam() string {
return buf.String()
}
-//for graphql query varparam
+// for graphql query varparam
func (f *Function) VarParamValue() string {
if len(f.args) == 0 {
return ""
@@ -221,7 +220,6 @@ var methodBing string
var hasTime bool
func parseSchema(schema *graphql.Schema, path, name string) {
-
structMap = make(map[string]Struct)
functionMap = make(map[string]Function)
url = path
@@ -251,7 +249,7 @@ func parseSchema(schema *graphql.Schema, path, name string) {
}
makeSource(name)
- if e := ioutil.WriteFile(outfile, source.Bytes(), os.ModePerm); e != nil {
+ if e := os.WriteFile(outfile, source.Bytes(), os.ModePerm); e != nil {
panic(e)
}
}
@@ -337,7 +335,6 @@ func parseFunction(tp map[string]interface{}) {
for _, f := range fields {
_parseFunction(f.(map[string]interface{}), tp["name"].(string))
}
-
}
func _parseFunction(m map[string]interface{}, methodType string) {
@@ -376,7 +373,6 @@ func makeReturnType(buf *bytes.Buffer, tp map[string]interface{}, none bool) {
} else {
panic(fmt.Sprintf("can do this for kind:[%s]", kind))
}
-
}
func parseArgs(m map[string]interface{}) Field {
@@ -437,5 +433,4 @@ func New%sClient(c *client.MasterGClient) *%sClient {
source.WriteString(f.String())
source.WriteString("\n\n")
}
-
}
diff --git a/sdk/master/api_admin.go b/sdk/master/api_admin.go
index 26007e81a..44149351e 100644
--- a/sdk/master/api_admin.go
+++ b/sdk/master/api_admin.go
@@ -32,7 +32,7 @@ type AdminAPI struct {
func (api *AdminAPI) GetCluster() (cv *proto.ClusterView, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.AdminGetCluster)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetCluster)
if buf, err = api.mc.serveRequest(request); err != nil {
return
}
@@ -48,7 +48,7 @@ func (api *AdminAPI) GetCluster() (cv *proto.ClusterView, err error) {
func (api *AdminAPI) GetClusterNodeInfo() (cn *proto.ClusterNodeInfo, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.AdminGetNodeInfo)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetNodeInfo)
if buf, err = api.mc.serveRequest(request); err != nil {
return
}
@@ -64,7 +64,7 @@ func (api *AdminAPI) GetClusterNodeInfo() (cn *proto.ClusterNodeInfo, err error)
func (api *AdminAPI) GetClusterIP() (cp *proto.ClusterIP, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.AdminGetIP)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetIP)
if buf, err = api.mc.serveRequest(request); err != nil {
return
}
@@ -78,7 +78,7 @@ func (api *AdminAPI) GetClusterIP() (cp *proto.ClusterIP, err error) {
}
func (api *AdminAPI) GetClusterStat() (cs *proto.ClusterStatInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminClusterStat)
+ request := newAPIRequest(http.MethodGet, proto.AdminClusterStat)
request.addHeader("isTimeOut", "false")
var buf []byte
if buf, err = api.mc.serveRequest(request); err != nil {
@@ -90,8 +90,9 @@ func (api *AdminAPI) GetClusterStat() (cs *proto.ClusterStatInfo, err error) {
}
return
}
+
func (api *AdminAPI) ListZones() (zoneViews []*proto.ZoneView, err error) {
- var request = newAPIRequest(http.MethodGet, proto.GetAllZones)
+ request := newAPIRequest(http.MethodGet, proto.GetAllZones)
var buf []byte
if buf, err = api.mc.serveRequest(request); err != nil {
return
@@ -102,8 +103,9 @@ func (api *AdminAPI) ListZones() (zoneViews []*proto.ZoneView, err error) {
}
return
}
+
func (api *AdminAPI) ListNodeSets(zoneName string) (nodeSetStats []*proto.NodeSetStat, err error) {
- var request = newAPIRequest(http.MethodGet, proto.GetAllNodeSets)
+ request := newAPIRequest(http.MethodGet, proto.GetAllNodeSets)
if zoneName != "" {
request.addParam("zoneName", zoneName)
}
@@ -117,8 +119,9 @@ func (api *AdminAPI) ListNodeSets(zoneName string) (nodeSetStats []*proto.NodeSe
}
return
}
+
func (api *AdminAPI) GetNodeSet(nodeSetId string) (nodeSetStatInfo *proto.NodeSetStatInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.GetNodeSet)
+ request := newAPIRequest(http.MethodGet, proto.GetNodeSet)
request.addParam("nodesetId", nodeSetId)
var buf []byte
if buf, err = api.mc.serveRequest(request); err != nil {
@@ -132,7 +135,7 @@ func (api *AdminAPI) GetNodeSet(nodeSetId string) (nodeSetStatInfo *proto.NodeSe
}
func (api *AdminAPI) UpdateNodeSet(nodeSetId string, dataNodeSelector string, metaNodeSelector string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.UpdateNodeSet)
+ request := newAPIRequest(http.MethodGet, proto.UpdateNodeSet)
request.addParam("nodesetId", nodeSetId)
request.addParam("dataNodeSelector", dataNodeSelector)
request.addParam("metaNodeSelector", metaNodeSelector)
@@ -143,7 +146,7 @@ func (api *AdminAPI) UpdateNodeSet(nodeSetId string, dataNodeSelector string, me
}
func (api *AdminAPI) UpdateZone(name string, enable bool, dataNodesetSelector string, metaNodesetSelector string, dataNodeSelector string, metaNodeSelector string) (err error) {
- var request = newAPIRequest(http.MethodPost, proto.UpdateZone)
+ request := newAPIRequest(http.MethodPost, proto.UpdateZone)
request.params["name"] = name
request.params["enable"] = strconv.FormatBool(enable)
request.params["dataNodesetSelector"] = dataNodesetSelector
@@ -158,7 +161,7 @@ func (api *AdminAPI) UpdateZone(name string, enable bool, dataNodesetSelector st
func (api *AdminAPI) Topo() (topo *proto.TopologyView, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.GetTopologyView)
+ request := newAPIRequest(http.MethodGet, proto.GetTopologyView)
if buf, err = api.mc.serveRequest(request); err != nil {
return
}
@@ -171,7 +174,7 @@ func (api *AdminAPI) Topo() (topo *proto.TopologyView, err error) {
func (api *AdminAPI) GetDataPartition(volName string, partitionID uint64) (partition *proto.DataPartitionInfo, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.AdminGetDataPartition)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetDataPartition)
request.addParam("id", fmt.Sprintf("%v", partitionID))
request.addParam("name", volName)
if buf, err = api.mc.serveRequest(request); err != nil {
@@ -185,7 +188,7 @@ func (api *AdminAPI) GetDataPartition(volName string, partitionID uint64) (parti
}
func (api *AdminAPI) GetDataPartitionById(partitionID uint64) (partition *proto.DataPartitionInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminGetDataPartition)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetDataPartition)
request.addParam("id", strconv.Itoa(int(partitionID)))
var data []byte
if data, err = api.mc.serveRequest(request); err != nil {
@@ -200,7 +203,7 @@ func (api *AdminAPI) GetDataPartitionById(partitionID uint64) (partition *proto.
func (api *AdminAPI) DiagnoseDataPartition(ignoreDiscardDp bool) (diagnosis *proto.DataPartitionDiagnosis, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.AdminDiagnoseDataPartition)
+ request := newAPIRequest(http.MethodGet, proto.AdminDiagnoseDataPartition)
request.addParam("ignoreDiscard", strconv.FormatBool(ignoreDiscardDp))
if buf, err = api.mc.serveRequest(request); err != nil {
return
@@ -214,7 +217,7 @@ func (api *AdminAPI) DiagnoseDataPartition(ignoreDiscardDp bool) (diagnosis *pro
func (api *AdminAPI) DiagnoseMetaPartition() (diagnosis *proto.MetaPartitionDiagnosis, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.AdminDiagnoseMetaPartition)
+ request := newAPIRequest(http.MethodGet, proto.AdminDiagnoseMetaPartition)
if buf, err = api.mc.serveRequest(request); err != nil {
return
}
@@ -226,7 +229,7 @@ func (api *AdminAPI) DiagnoseMetaPartition() (diagnosis *proto.MetaPartitionDiag
}
func (api *AdminAPI) LoadDataPartition(volName string, partitionID uint64, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminLoadDataPartition)
+ request := newAPIRequest(http.MethodGet, proto.AdminLoadDataPartition)
request.addParam("id", strconv.Itoa(int(partitionID)))
request.addParam("name", volName)
request.addParam("clientIDKey", clientIDKey)
@@ -237,7 +240,7 @@ func (api *AdminAPI) LoadDataPartition(volName string, partitionID uint64, clien
}
func (api *AdminAPI) CreateDataPartition(volName string, count int, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminCreateDataPartition)
+ request := newAPIRequest(http.MethodGet, proto.AdminCreateDataPartition)
request.addParam("name", volName)
request.addParam("count", strconv.Itoa(count))
request.addParam("clientIDKey", clientIDKey)
@@ -248,7 +251,7 @@ func (api *AdminAPI) CreateDataPartition(volName string, count int, clientIDKey
}
func (api *AdminAPI) DecommissionDataPartition(dataPartitionID uint64, nodeAddr string, raftForce bool, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminDecommissionDataPartition)
+ request := newAPIRequest(http.MethodGet, proto.AdminDecommissionDataPartition)
request.addParam("id", strconv.FormatUint(dataPartitionID, 10))
request.addParam("addr", nodeAddr)
request.addParam("raftForceDel", strconv.FormatBool(raftForce))
@@ -260,7 +263,7 @@ func (api *AdminAPI) DecommissionDataPartition(dataPartitionID uint64, nodeAddr
}
func (api *AdminAPI) DecommissionMetaPartition(metaPartitionID uint64, nodeAddr, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminDecommissionMetaPartition)
+ request := newAPIRequest(http.MethodGet, proto.AdminDecommissionMetaPartition)
request.addParam("id", strconv.FormatUint(metaPartitionID, 10))
request.addParam("addr", nodeAddr)
request.addParam("clientIDKey", clientIDKey)
@@ -271,7 +274,7 @@ func (api *AdminAPI) DecommissionMetaPartition(metaPartitionID uint64, nodeAddr,
}
func (api *AdminAPI) DeleteDataReplica(dataPartitionID uint64, nodeAddr, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminDeleteDataReplica)
+ request := newAPIRequest(http.MethodGet, proto.AdminDeleteDataReplica)
request.addParam("id", strconv.FormatUint(dataPartitionID, 10))
request.addParam("addr", nodeAddr)
request.addParam("clientIDKey", clientIDKey)
@@ -282,7 +285,7 @@ func (api *AdminAPI) DeleteDataReplica(dataPartitionID uint64, nodeAddr, clientI
}
func (api *AdminAPI) AddDataReplica(dataPartitionID uint64, nodeAddr, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminAddDataReplica)
+ request := newAPIRequest(http.MethodGet, proto.AdminAddDataReplica)
request.addParam("id", strconv.FormatUint(dataPartitionID, 10))
request.addParam("addr", nodeAddr)
request.addParam("clientIDKey", clientIDKey)
@@ -293,7 +296,7 @@ func (api *AdminAPI) AddDataReplica(dataPartitionID uint64, nodeAddr, clientIDKe
}
func (api *AdminAPI) DeleteMetaReplica(metaPartitionID uint64, nodeAddr string, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminDeleteMetaReplica)
+ request := newAPIRequest(http.MethodGet, proto.AdminDeleteMetaReplica)
request.addParam("id", strconv.FormatUint(metaPartitionID, 10))
request.addParam("addr", nodeAddr)
request.addParam("clientIDKey", clientIDKey)
@@ -304,7 +307,7 @@ func (api *AdminAPI) DeleteMetaReplica(metaPartitionID uint64, nodeAddr string,
}
func (api *AdminAPI) AddMetaReplica(metaPartitionID uint64, nodeAddr string, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminAddMetaReplica)
+ request := newAPIRequest(http.MethodGet, proto.AdminAddMetaReplica)
request.addParam("id", strconv.FormatUint(metaPartitionID, 10))
request.addParam("addr", nodeAddr)
request.addParam("clientIDKey", clientIDKey)
@@ -315,7 +318,7 @@ func (api *AdminAPI) AddMetaReplica(metaPartitionID uint64, nodeAddr string, cli
}
func (api *AdminAPI) DeleteVolume(volName, authKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminDeleteVol)
+ request := newAPIRequest(http.MethodGet, proto.AdminDeleteVol)
request.addParam("name", volName)
request.addParam("authKey", authKey)
if _, err = api.mc.serveRequest(request); err != nil {
@@ -325,7 +328,7 @@ func (api *AdminAPI) DeleteVolume(volName, authKey string) (err error) {
}
func (api *AdminAPI) DeleteVolumeWithAuthNode(volName, authKey, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminDeleteVol)
+ request := newAPIRequest(http.MethodGet, proto.AdminDeleteVol)
request.addParam("name", volName)
request.addParam("authKey", authKey)
request.addParam("clientIDKey", clientIDKey)
@@ -344,7 +347,7 @@ func (api *AdminAPI) UpdateVolume(
txConflictRetryInterval int64,
txOpLimit int,
clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminUpdateVol)
+ request := newAPIRequest(http.MethodGet, proto.AdminUpdateVol)
request.addParam("name", vv.Name)
request.addParam("description", vv.Description)
request.addParam("authKey", util.CalcAuthKey(vv.Owner))
@@ -394,7 +397,7 @@ func (api *AdminAPI) UpdateVolume(
}
func (api *AdminAPI) PutDataPartitions(volName string, dpsView []byte) (err error) {
- var request = newAPIRequest(http.MethodPost, proto.AdminPutDataPartitions)
+ request := newAPIRequest(http.MethodPost, proto.AdminPutDataPartitions)
request.addParam("name", volName)
request.addBody(dpsView)
@@ -405,7 +408,7 @@ func (api *AdminAPI) PutDataPartitions(volName string, dpsView []byte) (err erro
}
func (api *AdminAPI) VolShrink(volName string, capacity uint64, authKey, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminVolShrink)
+ request := newAPIRequest(http.MethodGet, proto.AdminVolShrink)
request.addParam("name", volName)
request.addParam("authKey", authKey)
request.addParam("capacity", strconv.FormatUint(capacity, 10))
@@ -417,7 +420,7 @@ func (api *AdminAPI) VolShrink(volName string, capacity uint64, authKey, clientI
}
func (api *AdminAPI) VolExpand(volName string, capacity uint64, authKey, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminVolExpand)
+ request := newAPIRequest(http.MethodGet, proto.AdminVolExpand)
request.addParam("name", volName)
request.addParam("authKey", authKey)
request.addParam("capacity", strconv.FormatUint(capacity, 10))
@@ -433,7 +436,7 @@ func (api *AdminAPI) CreateVolName(volName, owner string, capacity uint64, delet
cacheCapacity, cacheAction, cacheThreshold, cacheTTL, cacheHighWater, cacheLowWater, cacheLRUInterval int,
dpReadOnlyWhenVolFull bool, txMask string, txTimeout uint32, txConflictRetryNum int64, txConflictRetryInterval int64, optEnableQuota string,
clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminCreateVol)
+ request := newAPIRequest(http.MethodGet, proto.AdminCreateVol)
request.addParam("name", volName)
request.addParam("owner", owner)
request.addParam("capacity", strconv.FormatUint(capacity, 10))
@@ -483,7 +486,7 @@ func (api *AdminAPI) CreateVolName(volName, owner string, capacity uint64, delet
}
func (api *AdminAPI) CreateDefaultVolume(volName, owner string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminCreateVol)
+ request := newAPIRequest(http.MethodGet, proto.AdminCreateVol)
request.addParam("name", volName)
request.addParam("owner", owner)
request.addParam("capacity", "10")
@@ -494,7 +497,7 @@ func (api *AdminAPI) CreateDefaultVolume(volName, owner string) (err error) {
}
func (api *AdminAPI) GetVolumeSimpleInfo(volName string) (vv *proto.SimpleVolView, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminGetVol)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetVol)
request.addParam("name", volName)
var buf []byte
if buf, err = api.mc.serveRequest(request); err != nil {
@@ -528,7 +531,7 @@ func (api *AdminAPI) SetVolumeAuditLog(volName string, enable bool) (err error)
}
func (api *AdminAPI) GetMonitorPushAddr() (addr string, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminGetMonitorPushAddr)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetMonitorPushAddr)
var buf []byte
if buf, err = api.mc.serveRequest(request); err != nil {
return
@@ -539,7 +542,7 @@ func (api *AdminAPI) GetMonitorPushAddr() (addr string, err error) {
func (api *AdminAPI) UploadFlowInfo(volName string,
flowInfo *proto.ClientReportLimitInfo) (vv *proto.LimitRsp2Client, err error) {
- var request = newAPIRequest(http.MethodGet, proto.QosUpload)
+ request := newAPIRequest(http.MethodGet, proto.QosUpload)
request.addParam("name", volName)
if flowInfo == nil {
return nil, fmt.Errorf("flowinfo is nil")
@@ -567,7 +570,7 @@ func (api *AdminAPI) UploadFlowInfo(volName string,
}
func (api *AdminAPI) GetVolumeSimpleInfoWithFlowInfo(volName string) (vv *proto.SimpleVolView, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminGetVol)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetVol)
request.addParam("name", volName)
request.addParam("init", "true")
@@ -584,7 +587,7 @@ func (api *AdminAPI) GetVolumeSimpleInfoWithFlowInfo(volName string) (vv *proto.
// access control list
func (api *AdminAPI) CheckACL() (ci *proto.ClusterInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminACL)
+ request := newAPIRequest(http.MethodGet, proto.AdminACL)
var buf []byte
if buf, err = api.mc.serveRequest(request); err != nil {
return
@@ -597,7 +600,7 @@ func (api *AdminAPI) CheckACL() (ci *proto.ClusterInfo, err error) {
}
func (api *AdminAPI) GetClusterInfo() (ci *proto.ClusterInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminGetIP)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetIP)
var buf []byte
if buf, err = api.mc.serveRequest(request); err != nil {
return
@@ -610,7 +613,7 @@ func (api *AdminAPI) GetClusterInfo() (ci *proto.ClusterInfo, err error) {
}
func (api *AdminAPI) GetVerInfo(volName string) (ci *proto.VolumeVerInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminGetVolVer)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetVolVer)
request.addParam("name", volName)
var buf []byte
if buf, err = api.mc.serveRequest(request); err != nil {
@@ -624,8 +627,7 @@ func (api *AdminAPI) GetVerInfo(volName string) (ci *proto.VolumeVerInfo, err er
}
func (api *AdminAPI) CreateMetaPartition(volName string, inodeStart uint64, clientIDKey string) (err error) {
-
- var request = newAPIRequest(http.MethodGet, proto.AdminCreateMetaPartition)
+ request := newAPIRequest(http.MethodGet, proto.AdminCreateMetaPartition)
request.addParam("name", volName)
request.addParam("start", strconv.FormatUint(inodeStart, 10))
request.addParam("clientIDKey", clientIDKey)
@@ -636,7 +638,7 @@ func (api *AdminAPI) CreateMetaPartition(volName string, inodeStart uint64, clie
}
func (api *AdminAPI) ListVols(keywords string) (volsInfo []*proto.VolInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminListVols)
+ request := newAPIRequest(http.MethodGet, proto.AdminListVols)
request.addParam("keywords", keywords)
var buf []byte
if buf, err = api.mc.serveRequest(request); err != nil {
@@ -650,7 +652,7 @@ func (api *AdminAPI) ListVols(keywords string) (volsInfo []*proto.VolInfo, err e
}
func (api *AdminAPI) IsFreezeCluster(isFreeze bool, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminClusterFreeze)
+ request := newAPIRequest(http.MethodGet, proto.AdminClusterFreeze)
request.addParam("enable", strconv.FormatBool(isFreeze))
request.addParam("clientIDKey", clientIDKey)
if _, err = api.mc.serveRequest(request); err != nil {
@@ -660,7 +662,7 @@ func (api *AdminAPI) IsFreezeCluster(isFreeze bool, clientIDKey string) (err err
}
func (api *AdminAPI) SetForbidMpDecommission(disable bool) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminClusterForbidMpDecommission)
+ request := newAPIRequest(http.MethodGet, proto.AdminClusterForbidMpDecommission)
request.addParam("enable", strconv.FormatBool(disable))
if _, err = api.mc.serveRequest(request); err != nil {
return
@@ -669,7 +671,7 @@ func (api *AdminAPI) SetForbidMpDecommission(disable bool) (err error) {
}
func (api *AdminAPI) SetMetaNodeThreshold(threshold float64, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminSetMetaNodeThreshold)
+ request := newAPIRequest(http.MethodGet, proto.AdminSetMetaNodeThreshold)
request.addParam("threshold", strconv.FormatFloat(threshold, 'f', 6, 64))
request.addParam("clientIDKey", clientIDKey)
if _, err = api.mc.serveRequest(request); err != nil {
@@ -680,7 +682,7 @@ func (api *AdminAPI) SetMetaNodeThreshold(threshold float64, clientIDKey string)
func (api *AdminAPI) SetClusterParas(batchCount, markDeleteRate, deleteWorkerSleepMs, autoRepairRate, loadFactor, maxDpCntLimit, clientIDKey string,
dataNodesetSelector, metaNodesetSelector, dataNodeSelector, metaNodeSelector string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminSetNodeInfo)
+ request := newAPIRequest(http.MethodGet, proto.AdminSetNodeInfo)
request.addParam("batchCount", batchCount)
request.addParam("markDeleteRate", markDeleteRate)
request.addParam("deleteWorkerSleepMs", deleteWorkerSleepMs)
@@ -700,7 +702,7 @@ func (api *AdminAPI) SetClusterParas(batchCount, markDeleteRate, deleteWorkerSle
}
func (api *AdminAPI) GetClusterParas() (delParas map[string]string, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminGetNodeInfo)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetNodeInfo)
if _, err = api.mc.serveRequest(request); err != nil {
return
}
@@ -716,7 +718,7 @@ func (api *AdminAPI) GetClusterParas() (delParas map[string]string, err error) {
}
func (api *AdminAPI) CreatePreLoadDataPartition(volName string, count int, capacity, ttl uint64, zongs string) (view *proto.DataPartitionsView, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminCreatePreLoadDataPartition)
+ request := newAPIRequest(http.MethodGet, proto.AdminCreatePreLoadDataPartition)
request.addParam("name", volName)
request.addParam("replicaNum", strconv.Itoa(count))
request.addParam("capacity", strconv.FormatUint(capacity, 10))
@@ -734,7 +736,7 @@ func (api *AdminAPI) CreatePreLoadDataPartition(volName string, count int, capac
}
func (api *AdminAPI) ListQuota(volName string) (quotaInfo []*proto.QuotaInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.QuotaList)
+ request := newAPIRequest(http.MethodGet, proto.QuotaList)
resp := &proto.ListMasterQuotaResponse{}
request.addParam("name", volName)
var data []byte
@@ -752,7 +754,7 @@ func (api *AdminAPI) ListQuota(volName string) (quotaInfo []*proto.QuotaInfo, er
}
func (api *AdminAPI) CreateQuota(volName string, quotaPathInfos []proto.QuotaPathInfo, maxFiles uint64, maxBytes uint64) (quotaId uint32, err error) {
- var request = newAPIRequest(http.MethodGet, proto.QuotaCreate)
+ request := newAPIRequest(http.MethodGet, proto.QuotaCreate)
request.addParam("name", volName)
request.addParam("maxFiles", strconv.FormatUint(maxFiles, 10))
request.addParam("maxBytes", strconv.FormatUint(maxBytes, 10))
@@ -776,7 +778,7 @@ func (api *AdminAPI) CreateQuota(volName string, quotaPathInfos []proto.QuotaPat
}
func (api *AdminAPI) UpdateQuota(volName string, quotaId string, maxFiles uint64, maxBytes uint64) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.QuotaUpdate)
+ request := newAPIRequest(http.MethodGet, proto.QuotaUpdate)
request.addParam("name", volName)
request.addParam("quotaId", quotaId)
request.addParam("maxFiles", strconv.FormatUint(maxFiles, 10))
@@ -790,7 +792,7 @@ func (api *AdminAPI) UpdateQuota(volName string, quotaId string, maxFiles uint64
}
func (api *AdminAPI) DeleteQuota(volName string, quotaId string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.QuotaDelete)
+ request := newAPIRequest(http.MethodGet, proto.QuotaDelete)
request.addParam("name", volName)
request.addParam("quotaId", quotaId)
@@ -803,7 +805,7 @@ func (api *AdminAPI) DeleteQuota(volName string, quotaId string) (err error) {
}
func (api *AdminAPI) GetQuota(volName string, quotaId string) (quotaInfo *proto.QuotaInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.QuotaGet)
+ request := newAPIRequest(http.MethodGet, proto.QuotaGet)
request.addParam("name", volName)
request.addParam("quotaId", quotaId)
var data []byte
@@ -823,7 +825,7 @@ func (api *AdminAPI) GetQuota(volName string, quotaId string) (quotaInfo *proto.
func (api *AdminAPI) QueryBadDisks() (badDisks *proto.BadDiskInfos, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.QueryBadDisks)
+ request := newAPIRequest(http.MethodGet, proto.QueryBadDisks)
if buf, err = api.mc.serveRequest(request); err != nil {
return
}
@@ -870,7 +872,7 @@ func (api *AdminAPI) QueryDecommissionDiskProgress(addr string, disk string) (pr
}
func (api *AdminAPI) ListQuotaAll() (volsInfo []*proto.VolInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.QuotaListAll)
+ request := newAPIRequest(http.MethodGet, proto.QuotaListAll)
var data []byte
if data, err = api.mc.serveRequest(request); err != nil {
@@ -886,7 +888,7 @@ func (api *AdminAPI) ListQuotaAll() (volsInfo []*proto.VolInfo, err error) {
func (api *AdminAPI) GetDiscardDataPartition() (DiscardDpInfos *proto.DiscardDataPartitionInfos, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.AdminGetDiscardDp)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetDiscardDp)
if buf, err = api.mc.serveRequest(request); err != nil {
return
}
@@ -898,7 +900,7 @@ func (api *AdminAPI) GetDiscardDataPartition() (DiscardDpInfos *proto.DiscardDat
}
func (api *AdminAPI) DeleteVersion(volName string, verSeq string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminDelVersion)
+ request := newAPIRequest(http.MethodGet, proto.AdminDelVersion)
request.addParam("name", volName)
request.addParam("verSeq", verSeq)
if _, err = api.mc.serveRequest(request); err != nil {
@@ -908,8 +910,7 @@ func (api *AdminAPI) DeleteVersion(volName string, verSeq string) (err error) {
}
func (api *AdminAPI) SetStrategy(volName string, periodic string, count string, enable string, force string) (err error) {
-
- var request = newAPIRequest(http.MethodGet, proto.AdminSetVerStrategy)
+ request := newAPIRequest(http.MethodGet, proto.AdminSetVerStrategy)
request.addParam("name", volName)
request.addParam("periodic", periodic)
request.addParam("count", count)
@@ -923,7 +924,7 @@ func (api *AdminAPI) SetStrategy(volName string, periodic string, count string,
func (api *AdminAPI) CreateVersion(volName string) (ver *proto.VolVersionInfo, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.AdminCreateVersion)
+ request := newAPIRequest(http.MethodGet, proto.AdminCreateVersion)
request.addParam("name", volName)
if buf, err = api.mc.serveRequest(request); err != nil {
return
@@ -937,7 +938,7 @@ func (api *AdminAPI) CreateVersion(volName string) (ver *proto.VolVersionInfo, e
func (api *AdminAPI) GetLatestVer(volName string) (ver *proto.VolVersionInfo, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.AdminGetVersionInfo)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetVersionInfo)
request.addParam("name", volName)
if buf, err = api.mc.serveRequest(request); err != nil {
return
@@ -951,7 +952,7 @@ func (api *AdminAPI) GetLatestVer(volName string) (ver *proto.VolVersionInfo, er
func (api *AdminAPI) GetVerList(volName string) (verList *proto.VolVersionInfoList, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.AdminGetAllVersionInfo)
+ request := newAPIRequest(http.MethodGet, proto.AdminGetAllVersionInfo)
request.addParam("name", volName)
if buf, err = api.mc.serveRequest(request); err != nil {
return
@@ -968,7 +969,7 @@ func (api *AdminAPI) GetVerList(volName string) (verList *proto.VolVersionInfoLi
}
func (api *AdminAPI) SetBucketLifecycle(req *proto.LcConfiguration) (err error) {
- var request = newAPIRequest(http.MethodPost, proto.SetBucketLifecycle)
+ request := newAPIRequest(http.MethodPost, proto.SetBucketLifecycle)
var encoded []byte
if encoded, err = json.Marshal(req); err != nil {
return
@@ -979,8 +980,9 @@ func (api *AdminAPI) SetBucketLifecycle(req *proto.LcConfiguration) (err error)
}
return
}
+
func (api *AdminAPI) GetBucketLifecycle(volume string) (lcConf *proto.LcConfiguration, err error) {
- var request = newAPIRequest(http.MethodGet, proto.GetBucketLifecycle)
+ request := newAPIRequest(http.MethodGet, proto.GetBucketLifecycle)
request.addParam("name", volume)
var buf []byte
if buf, err = api.mc.serveRequest(request); err != nil {
@@ -992,8 +994,9 @@ func (api *AdminAPI) GetBucketLifecycle(volume string) (lcConf *proto.LcConfigur
}
return
}
+
func (api *AdminAPI) DelBucketLifecycle(volume string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.DeleteBucketLifecycle)
+ request := newAPIRequest(http.MethodGet, proto.DeleteBucketLifecycle)
request.addParam("name", volume)
if _, err = api.mc.serveRequest(request); err != nil {
return
@@ -1002,7 +1005,7 @@ func (api *AdminAPI) DelBucketLifecycle(volume string) (err error) {
}
func (api *AdminAPI) GetS3QoSInfo() (data []byte, err error) {
- var request = newAPIRequest(http.MethodGet, proto.S3QoSGet)
+ request := newAPIRequest(http.MethodGet, proto.S3QoSGet)
if data, err = api.mc.serveRequest(request); err != nil {
return
}
diff --git a/sdk/master/api_client.go b/sdk/master/api_client.go
index cc285e2bb..3086b245d 100644
--- a/sdk/master/api_client.go
+++ b/sdk/master/api_client.go
@@ -35,7 +35,7 @@ type ClientAPI struct {
}
func (api *ClientAPI) GetVolume(volName string, authKey string) (vv *proto.VolView, err error) {
- var request = newAPIRequest(http.MethodPost, proto.ClientVol)
+ request := newAPIRequest(http.MethodPost, proto.ClientVol)
request.addParam("name", volName)
request.addParam("authKey", authKey)
var data []byte
@@ -50,7 +50,7 @@ func (api *ClientAPI) GetVolume(volName string, authKey string) (vv *proto.VolVi
}
func (api *ClientAPI) GetVolumeWithoutAuthKey(volName string) (vv *proto.VolView, err error) {
- var request = newAPIRequest(http.MethodPost, proto.ClientVol)
+ request := newAPIRequest(http.MethodPost, proto.ClientVol)
request.addParam("name", volName)
request.addHeader(proto.SkipOwnerValidation, strconv.FormatBool(true))
var data []byte
@@ -66,7 +66,7 @@ func (api *ClientAPI) GetVolumeWithoutAuthKey(volName string) (vv *proto.VolView
func (api *ClientAPI) GetVolumeWithAuthnode(volName string, authKey string, token string, decoder Decoder) (vv *proto.VolView, err error) {
var body []byte
- var request = newAPIRequest(http.MethodPost, proto.ClientVol)
+ request := newAPIRequest(http.MethodPost, proto.ClientVol)
request.addParam("name", volName)
request.addParam("authKey", authKey)
request.addParam(proto.ClientMessage, token)
@@ -86,7 +86,7 @@ func (api *ClientAPI) GetVolumeWithAuthnode(volName string, authKey string, toke
}
func (api *ClientAPI) GetVolumeStat(volName string) (info *proto.VolStatInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.ClientVolStat)
+ request := newAPIRequest(http.MethodGet, proto.ClientVolStat)
request.addParam("name", volName)
request.addParam("version", strconv.FormatInt(proto.LFClient, 10))
var data []byte
@@ -101,7 +101,7 @@ func (api *ClientAPI) GetVolumeStat(volName string) (info *proto.VolStatInfo, er
}
func (api *ClientAPI) GetMetaPartition(partitionID uint64) (partition *proto.MetaPartitionInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.ClientMetaPartition)
+ request := newAPIRequest(http.MethodGet, proto.ClientMetaPartition)
request.addParam("id", strconv.FormatUint(partitionID, 10))
var data []byte
if data, err = api.mc.serveRequest(request); err != nil {
@@ -115,7 +115,7 @@ func (api *ClientAPI) GetMetaPartition(partitionID uint64) (partition *proto.Met
}
func (api *ClientAPI) GetMetaPartitions(volName string) (views []*proto.MetaPartitionView, err error) {
- var request = newAPIRequest(http.MethodGet, proto.ClientMetaPartitions)
+ request := newAPIRequest(http.MethodGet, proto.ClientMetaPartitions)
request.addParam("name", volName)
var data []byte
if data, err = api.mc.serveRequest(request); err != nil {
@@ -128,7 +128,7 @@ func (api *ClientAPI) GetMetaPartitions(volName string) (views []*proto.MetaPart
}
func (api *ClientAPI) GetDataPartitions(volName string) (view *proto.DataPartitionsView, err error) {
- var request = newAPIRequest(http.MethodGet, proto.ClientDataPartitions)
+ request := newAPIRequest(http.MethodGet, proto.ClientDataPartitions)
request.addParam("name", volName)
lastLeader := api.mc.leaderAddr
@@ -151,7 +151,7 @@ func (api *ClientAPI) GetDataPartitions(volName string) (view *proto.DataPartiti
}
func (api *ClientAPI) GetPreLoadDataPartitions(volName string) (view *proto.DataPartitionsView, err error) {
- var request = newAPIRequest(http.MethodGet, proto.ClientDataPartitions)
+ request := newAPIRequest(http.MethodGet, proto.ClientDataPartitions)
request.addParam("name", volName)
var data []byte
if data, err = api.mc.serveRequest(request); err != nil {
diff --git a/sdk/master/api_node.go b/sdk/master/api_node.go
index a7511ca01..5e9de44bb 100644
--- a/sdk/master/api_node.go
+++ b/sdk/master/api_node.go
@@ -27,7 +27,7 @@ type NodeAPI struct {
}
func (api *NodeAPI) AddDataNode(serverAddr, zoneName string) (id uint64, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AddDataNode)
+ request := newAPIRequest(http.MethodGet, proto.AddDataNode)
request.addParam("addr", serverAddr)
request.addParam("zoneName", zoneName)
var data []byte
@@ -39,7 +39,7 @@ func (api *NodeAPI) AddDataNode(serverAddr, zoneName string) (id uint64, err err
}
func (api *NodeAPI) AddDataNodeWithAuthNode(serverAddr, zoneName, clientIDKey string) (id uint64, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AddDataNode)
+ request := newAPIRequest(http.MethodGet, proto.AddDataNode)
request.addParam("addr", serverAddr)
request.addParam("zoneName", zoneName)
request.addParam("clientIDKey", clientIDKey)
@@ -52,7 +52,7 @@ func (api *NodeAPI) AddDataNodeWithAuthNode(serverAddr, zoneName, clientIDKey st
}
func (api *NodeAPI) AddMetaNode(serverAddr, zoneName string) (id uint64, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AddMetaNode)
+ request := newAPIRequest(http.MethodGet, proto.AddMetaNode)
request.addParam("addr", serverAddr)
request.addParam("zoneName", zoneName)
var data []byte
@@ -64,7 +64,7 @@ func (api *NodeAPI) AddMetaNode(serverAddr, zoneName string) (id uint64, err err
}
func (api *NodeAPI) AddMetaNodeWithAuthNode(serverAddr, zoneName, clientIDKey string) (id uint64, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AddMetaNode)
+ request := newAPIRequest(http.MethodGet, proto.AddMetaNode)
request.addParam("addr", serverAddr)
request.addParam("zoneName", zoneName)
request.addParam("clientIDKey", clientIDKey)
@@ -78,7 +78,7 @@ func (api *NodeAPI) AddMetaNodeWithAuthNode(serverAddr, zoneName, clientIDKey st
func (api *NodeAPI) GetDataNode(serverHost string) (node *proto.DataNodeInfo, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.GetDataNode)
+ request := newAPIRequest(http.MethodGet, proto.GetDataNode)
request.addParam("addr", serverHost)
if buf, err = api.mc.serveRequest(request); err != nil {
return
@@ -92,7 +92,7 @@ func (api *NodeAPI) GetDataNode(serverHost string) (node *proto.DataNodeInfo, er
func (api *NodeAPI) GetMetaNode(serverHost string) (node *proto.MetaNodeInfo, err error) {
var buf []byte
- var request = newAPIRequest(http.MethodGet, proto.GetMetaNode)
+ request := newAPIRequest(http.MethodGet, proto.GetMetaNode)
request.addParam("addr", serverHost)
if buf, err = api.mc.serveRequest(request); err != nil {
return
@@ -109,7 +109,7 @@ func (api *NodeAPI) ResponseMetaNodeTask(task *proto.AdminTask) (err error) {
if encoded, err = json.Marshal(task); err != nil {
return
}
- var request = newAPIRequest(http.MethodPost, proto.GetMetaNodeTaskResponse)
+ request := newAPIRequest(http.MethodPost, proto.GetMetaNodeTaskResponse)
request.addBody(encoded)
if _, err = api.mc.serveRequest(request); err != nil {
return
@@ -118,12 +118,11 @@ func (api *NodeAPI) ResponseMetaNodeTask(task *proto.AdminTask) (err error) {
}
func (api *NodeAPI) ResponseDataNodeTask(task *proto.AdminTask) (err error) {
-
var encoded []byte
if encoded, err = json.Marshal(task); err != nil {
return
}
- var request = newAPIRequest(http.MethodPost, proto.GetDataNodeTaskResponse)
+ request := newAPIRequest(http.MethodPost, proto.GetDataNodeTaskResponse)
request.addBody(encoded)
if _, err = api.mc.serveRequest(request); err != nil {
return
@@ -132,7 +131,7 @@ func (api *NodeAPI) ResponseDataNodeTask(task *proto.AdminTask) (err error) {
}
func (api *NodeAPI) DataNodeDecommission(nodeAddr string, count int, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.DecommissionDataNode)
+ request := newAPIRequest(http.MethodGet, proto.DecommissionDataNode)
request.addParam("addr", nodeAddr)
request.addParam("count", strconv.Itoa(count))
request.addParam("clientIDKey", clientIDKey)
@@ -144,7 +143,7 @@ func (api *NodeAPI) DataNodeDecommission(nodeAddr string, count int, clientIDKey
}
func (api *NodeAPI) MetaNodeDecommission(nodeAddr string, count int, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.DecommissionMetaNode)
+ request := newAPIRequest(http.MethodGet, proto.DecommissionMetaNode)
request.addParam("addr", nodeAddr)
request.addParam("count", strconv.Itoa(count))
request.addHeader("isTimeOut", "false")
@@ -156,7 +155,7 @@ func (api *NodeAPI) MetaNodeDecommission(nodeAddr string, count int, clientIDKey
}
func (api *NodeAPI) MetaNodeMigrate(srcAddr, targetAddr string, count int, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.MigrateMetaNode)
+ request := newAPIRequest(http.MethodGet, proto.MigrateMetaNode)
request.addParam("srcAddr", srcAddr)
request.addParam("targetAddr", targetAddr)
request.addParam("count", strconv.Itoa(count))
@@ -169,7 +168,7 @@ func (api *NodeAPI) MetaNodeMigrate(srcAddr, targetAddr string, count int, clien
}
func (api *NodeAPI) DataNodeMigrate(srcAddr, targetAddr string, count int, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodGet, proto.MigrateDataNode)
+ request := newAPIRequest(http.MethodGet, proto.MigrateDataNode)
request.addParam("srcAddr", srcAddr)
request.addParam("targetAddr", targetAddr)
request.addParam("count", strconv.Itoa(count))
@@ -182,7 +181,7 @@ func (api *NodeAPI) DataNodeMigrate(srcAddr, targetAddr string, count int, clien
}
func (api *NodeAPI) AddLcNode(serverAddr string) (id uint64, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AddLcNode)
+ request := newAPIRequest(http.MethodGet, proto.AddLcNode)
request.addParam("addr", serverAddr)
var data []byte
if data, err = api.mc.serveRequest(request); err != nil {
@@ -197,7 +196,7 @@ func (api *NodeAPI) ResponseLcNodeTask(task *proto.AdminTask) (err error) {
if encoded, err = json.Marshal(task); err != nil {
return
}
- var request = newAPIRequest(http.MethodPost, proto.GetLcNodeTaskResponse)
+ request := newAPIRequest(http.MethodPost, proto.GetLcNodeTaskResponse)
request.addBody(encoded)
if _, err = api.mc.serveRequest(request); err != nil {
return
diff --git a/sdk/master/api_user.go b/sdk/master/api_user.go
index 4ef133e9e..b509e43d3 100644
--- a/sdk/master/api_user.go
+++ b/sdk/master/api_user.go
@@ -3,12 +3,12 @@ package master
import (
"encoding/json"
"fmt"
- "github.com/cubefs/cubefs/util/ump"
"net/http"
"os"
"strconv"
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/util/ump"
)
type UserAPI struct {
@@ -16,7 +16,7 @@ type UserAPI struct {
}
func (api *UserAPI) CreateUser(param *proto.UserCreateParam, clientIDKey string) (userInfo *proto.UserInfo, err error) {
- var request = newAPIRequest(http.MethodPost, proto.UserCreate)
+ request := newAPIRequest(http.MethodPost, proto.UserCreate)
request.addParam("clientIDKey", clientIDKey)
var reqBody []byte
if reqBody, err = json.Marshal(param); err != nil {
@@ -35,7 +35,7 @@ func (api *UserAPI) CreateUser(param *proto.UserCreateParam, clientIDKey string)
}
func (api *UserAPI) DeleteUser(userID string, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodPost, proto.UserDelete)
+ request := newAPIRequest(http.MethodPost, proto.UserDelete)
request.addParam("user", userID)
request.addParam("clientIDKey", clientIDKey)
if _, err = api.mc.serveRequest(request); err != nil {
@@ -45,7 +45,7 @@ func (api *UserAPI) DeleteUser(userID string, clientIDKey string) (err error) {
}
func (api *UserAPI) UpdateUser(param *proto.UserUpdateParam, clientIDKey string) (userInfo *proto.UserInfo, err error) {
- var request = newAPIRequest(http.MethodPost, proto.UserUpdate)
+ request := newAPIRequest(http.MethodPost, proto.UserUpdate)
request.addParam("clientIDKey", clientIDKey)
var reqBody []byte
if reqBody, err = json.Marshal(param); err != nil {
@@ -65,7 +65,7 @@ func (api *UserAPI) UpdateUser(param *proto.UserUpdateParam, clientIDKey string)
func (api *UserAPI) GetAKInfo(accesskey string) (userInfo *proto.UserInfo, err error) {
localIP, _ := ump.GetLocalIpAddr()
- var request = newAPIRequest(http.MethodGet, proto.UserGetAKInfo)
+ request := newAPIRequest(http.MethodGet, proto.UserGetAKInfo)
request.addParam("ak", accesskey)
request.addParam("ip", localIP)
var data []byte
@@ -80,7 +80,7 @@ func (api *UserAPI) GetAKInfo(accesskey string) (userInfo *proto.UserInfo, err e
}
func (api *UserAPI) AclOperation(volName string, localIP string, op uint32) (aclInfo *proto.AclRsp, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminACL)
+ request := newAPIRequest(http.MethodGet, proto.AdminACL)
request.addParam("name", volName)
request.addParam("ip", localIP)
request.addParam("op", strconv.Itoa(int(op)))
@@ -99,7 +99,7 @@ func (api *UserAPI) AclOperation(volName string, localIP string, op uint32) (acl
}
func (api *UserAPI) UidOperation(volName string, uid string, op uint32, val string) (uidInfo *proto.UidSpaceRsp, err error) {
- var request = newAPIRequest(http.MethodGet, proto.AdminUid)
+ request := newAPIRequest(http.MethodGet, proto.AdminUid)
request.addParam("name", volName)
request.addParam("uid", uid)
request.addParam("op", strconv.Itoa(int(op)))
@@ -119,7 +119,7 @@ func (api *UserAPI) UidOperation(volName string, uid string, op uint32, val stri
}
func (api *UserAPI) GetUserInfo(userID string) (userInfo *proto.UserInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.UserGetInfo)
+ request := newAPIRequest(http.MethodGet, proto.UserGetInfo)
request.addParam("user", userID)
var data []byte
if data, err = api.mc.serveRequest(request); err != nil {
@@ -133,7 +133,7 @@ func (api *UserAPI) GetUserInfo(userID string) (userInfo *proto.UserInfo, err er
}
func (api *UserAPI) UpdatePolicy(param *proto.UserPermUpdateParam, clientIDKey string) (userInfo *proto.UserInfo, err error) {
- var request = newAPIRequest(http.MethodPost, proto.UserUpdatePolicy)
+ request := newAPIRequest(http.MethodPost, proto.UserUpdatePolicy)
request.addParam("clientIDKey", clientIDKey)
var reqBody []byte
if reqBody, err = json.Marshal(param); err != nil {
@@ -152,7 +152,7 @@ func (api *UserAPI) UpdatePolicy(param *proto.UserPermUpdateParam, clientIDKey s
}
func (api *UserAPI) RemovePolicy(param *proto.UserPermRemoveParam, clientIDKey string) (userInfo *proto.UserInfo, err error) {
- var request = newAPIRequest(http.MethodPost, proto.UserRemovePolicy)
+ request := newAPIRequest(http.MethodPost, proto.UserRemovePolicy)
request.addParam("clientIDKey", clientIDKey)
var reqBody []byte
if reqBody, err = json.Marshal(param); err != nil {
@@ -171,7 +171,7 @@ func (api *UserAPI) RemovePolicy(param *proto.UserPermRemoveParam, clientIDKey s
}
func (api *UserAPI) DeleteVolPolicy(vol, clientIDKey string) (err error) {
- var request = newAPIRequest(http.MethodPost, proto.UserDeleteVolPolicy)
+ request := newAPIRequest(http.MethodPost, proto.UserDeleteVolPolicy)
request.addParam("name", vol)
request.addParam("clientIDKey", clientIDKey)
if _, err = api.mc.serveRequest(request); err != nil {
@@ -181,7 +181,7 @@ func (api *UserAPI) DeleteVolPolicy(vol, clientIDKey string) (err error) {
}
func (api *UserAPI) TransferVol(param *proto.UserTransferVolParam, clientIDKey string) (userInfo *proto.UserInfo, err error) {
- var request = newAPIRequest(http.MethodPost, proto.UserTransferVol)
+ request := newAPIRequest(http.MethodPost, proto.UserTransferVol)
request.addParam("clientIDKey", clientIDKey)
var reqBody []byte
if reqBody, err = json.Marshal(param); err != nil {
@@ -200,7 +200,7 @@ func (api *UserAPI) TransferVol(param *proto.UserTransferVolParam, clientIDKey s
}
func (api *UserAPI) ListUsers(keywords string) (users []*proto.UserInfo, err error) {
- var request = newAPIRequest(http.MethodGet, proto.UserList)
+ request := newAPIRequest(http.MethodGet, proto.UserList)
request.addParam("keywords", keywords)
var data []byte
if data, err = api.mc.serveRequest(request); err != nil {
@@ -214,7 +214,7 @@ func (api *UserAPI) ListUsers(keywords string) (users []*proto.UserInfo, err err
}
func (api *UserAPI) ListUsersOfVol(vol string) (users []string, err error) {
- var request = newAPIRequest(http.MethodGet, proto.UsersOfVol)
+ request := newAPIRequest(http.MethodGet, proto.UsersOfVol)
request.addParam("name", vol)
var data []byte
if data, err = api.mc.serveRequest(request); err != nil {
diff --git a/sdk/master/client.go b/sdk/master/client.go
index 36dcad76a..81e37198f 100644
--- a/sdk/master/client.go
+++ b/sdk/master/client.go
@@ -18,7 +18,7 @@ import (
"bytes"
"errors"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"strconv"
"strings"
@@ -33,9 +33,7 @@ const (
requestTimeout = 30 * time.Second
)
-var (
- ErrNoValidMaster = errors.New("no valid master")
-)
+var ErrNoValidMaster = errors.New("no valid master")
type MasterCLientWithResolver struct {
MasterClient
@@ -138,7 +136,7 @@ func (c *MasterClient) serveRequest(r *request) (repsData []byte, err error) {
} else {
schema = "http"
}
- var url = fmt.Sprintf("%s://%s%s", schema, host,
+ url := fmt.Sprintf("%s://%s%s", schema, host,
r.path)
resp, err = c.httpRequest(r.method, url, r.params, r.header, r.body)
if err != nil {
@@ -146,7 +144,7 @@ func (c *MasterClient) serveRequest(r *request) (repsData []byte, err error) {
continue
}
stateCode := resp.StatusCode
- repsData, err = ioutil.ReadAll(resp.Body)
+ repsData, err = io.ReadAll(resp.Body)
_ = resp.Body.Close()
if err != nil {
log.LogErrorf("serveRequest: read http response body fail: err(%v)", err)
@@ -169,7 +167,7 @@ func (c *MasterClient) serveRequest(r *request) (repsData []byte, err error) {
log.LogDebugf("server Request resp new master[%v] old [%v]", host, leaderAddr)
c.SetLeader(host)
}
- var body = new(proto.HTTPReplyRaw)
+ body := new(proto.HTTPReplyRaw)
if err := body.Unmarshal(repsData); err != nil {
log.LogErrorf("unmarshal response body err:%v", err)
return nil, fmt.Errorf("unmarshal response body err:%v", err)
@@ -348,7 +346,6 @@ func (mc *MasterCLientWithResolver) Start() (err error) {
}
func (mc *MasterCLientWithResolver) Stop() {
-
select {
case mc.stopC <- struct{}{}:
log.LogDebugf("stop resolver, notified!")
@@ -359,7 +356,7 @@ func (mc *MasterCLientWithResolver) Stop() {
// NewMasterHelper returns a new MasterClient instance.
func NewMasterClient(masters []string, useSSL bool) *MasterClient {
- var mc = &MasterClient{masters: masters, useSSL: useSSL, timeout: requestTimeout}
+ mc := &MasterClient{masters: masters, useSSL: useSSL, timeout: requestTimeout}
mc.adminAPI = &AdminAPI{mc: mc}
mc.clientAPI = &ClientAPI{mc: mc}
mc.nodeAPI = &NodeAPI{mc: mc}
@@ -371,7 +368,7 @@ func NewMasterClient(masters []string, useSSL bool) *MasterClient {
// string and returns a new MasterClient instance.
// Notes that a valid format raw string must match: "{HOST}:{PORT},{HOST}:{PORT}"
func NewMasterClientFromString(masterAddr string, useSSL bool) *MasterClient {
- var masters = make([]string, 0)
+ masters := make([]string, 0)
for _, master := range strings.Split(masterAddr, ",") {
master = strings.TrimSpace(master)
if master != "" {
diff --git a/sdk/master/name_resolver.go b/sdk/master/name_resolver.go
index 91e933a55..3f63ee081 100644
--- a/sdk/master/name_resolver.go
+++ b/sdk/master/name_resolver.go
@@ -17,7 +17,6 @@ package master
import (
"errors"
"fmt"
- "github.com/cubefs/cubefs/util/log"
"math/rand"
"net"
"regexp"
@@ -25,6 +24,8 @@ import (
"strings"
"sync"
"time"
+
+ "github.com/cubefs/cubefs/util/log"
)
var domainRegexp = regexp.MustCompile(`^(?i)[a-z0-9-]+(\.[a-z0-9-]+)+\.?$`)
@@ -35,7 +36,7 @@ func IsValidDomain(domain string) bool {
type IpCache struct {
sync.RWMutex
- Ts int64 //time.Now().Unix()
+ Ts int64 // time.Now().Unix()
Ips []string
}
diff --git a/sdk/master/request.go b/sdk/master/request.go
index 3d950839c..fc71e73ae 100644
--- a/sdk/master/request.go
+++ b/sdk/master/request.go
@@ -28,9 +28,7 @@ type request struct {
body []byte
}
-var (
- ReqHeaderUA = fmt.Sprintf("cubefs-sdk/%v (commit %v)", proto.Version, proto.CommitID)
-)
+var ReqHeaderUA = fmt.Sprintf("cubefs-sdk/%v (commit %v)", proto.Version, proto.CommitID)
func (r *request) addParam(key, value string) {
r.params[key] = value
diff --git a/sdk/meta/api.go b/sdk/meta/api.go
index febe4321d..da0d888ba 100644
--- a/sdk/meta/api.go
+++ b/sdk/meta/api.go
@@ -27,9 +27,8 @@ import (
"syscall"
"time"
- "github.com/cubefs/cubefs/util"
-
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/log"
)
@@ -359,10 +358,8 @@ func (mw *MetaWrapper) Lookup_ll(parentID uint64, name string) (inode uint64, mo
func (mw *MetaWrapper) BatchGetExpiredMultipart(prefix string, days int) (expiredIds []*proto.ExpiredMultipartInfo, err error) {
partitions := mw.partitions
- var (
- mp *MetaPartition
- )
- var wg = new(sync.WaitGroup)
+ var mp *MetaPartition
+ wg := new(sync.WaitGroup)
var resultMu sync.Mutex
log.LogDebugf("BatchGetExpiredMultipart: mp num(%v) prefix(%v) days(%v)", len(partitions), prefix, days)
for _, mp = range partitions {
@@ -502,7 +499,7 @@ func (mw *MetaWrapper) BatchGetXAttr(inodes []uint64, keys []string) ([]*proto.X
mpInodes = make(map[uint64][]uint64) // Mapping: partition ID -> inodes
)
for _, ino := range inodes {
- var mp = mw.getPartitionByInode(ino)
+ mp := mw.getPartitionByInode(ino)
if mp != nil {
mps[mp.PartitionID] = mp
mpInodes[mp.PartitionID] = append(mpInodes[mp.PartitionID], ino)
@@ -540,7 +537,7 @@ func (mw *MetaWrapper) BatchGetXAttr(inodes []uint64, keys []string) ([]*proto.X
return nil, <-errorsCh
}
- var xattrs = make([]*proto.XAttrInfo, 0, len(inodes))
+ xattrs := make([]*proto.XAttrInfo, 0, len(inodes))
for {
info := <-xattrsCh
if info == nil {
@@ -558,6 +555,7 @@ func (mw *MetaWrapper) Delete_ll(parentID uint64, name string, isDir bool, fullP
return mw.Delete_ll_EX(parentID, name, isDir, 0, fullPath)
}
}
+
func (mw *MetaWrapper) Delete_Ver_ll(parentID uint64, name string, isDir bool, verSeq uint64, fullPath string) (*proto.InodeInfo, error) {
if verSeq == 0 {
verSeq = math.MaxUint64
@@ -832,7 +830,6 @@ func isObjectLocked(mw *MetaWrapper, inode uint64, name string) error {
}
func (mw *MetaWrapper) deletewithcond_ll(parentID, cond uint64, name string, isDir bool, fullPath string) (*proto.InodeInfo, error) {
-
err := isObjectLocked(mw, cond, name)
if err != nil {
return nil, err
@@ -1014,12 +1011,11 @@ func (mw *MetaWrapper) txRename_ll(srcParentID uint64, srcName string, dstParent
newSt, newErr = mw.txDcreate(tx, dstParentMP, dstParentID, dstName, srcInode, srcMode, []uint32{}, dstFullPath)
return newSt, newErr
})
-
} else {
return statusToErrno(status)
}
- //var inode uint64
+ // var inode uint64
funcs = append(funcs, func() (int, error) {
var newSt int
var newErr error
@@ -1513,7 +1509,6 @@ func (mw *MetaWrapper) Truncate(inode, size uint64, fullPath string) error {
return statusToErrno(status)
}
return nil
-
}
func (mw *MetaWrapper) Link(parentID uint64, name string, ino uint64, fullPath string) (*proto.InodeInfo, error) {
@@ -1872,7 +1867,7 @@ func (mw *MetaWrapper) GetMultipart_ll(path, multipartId string) (info *proto.Mu
info, _, err = mw.broadcastGetMultipart(path, multipartId)
return
}
- var mp = mw.getPartitionByID(mpId)
+ mp := mw.getPartitionByID(mpId)
if mp == nil {
err = syscall.ENOENT
return
@@ -1900,7 +1895,7 @@ func (mw *MetaWrapper) AddMultipartPart_ll(path, multipartId string, partId uint
return
}
}
- var mp = mw.getPartitionByID(mpId)
+ mp := mw.getPartitionByID(mpId)
if mp == nil {
log.LogWarnf("AddMultipartPart_ll: has no meta partition: multipartId(%v) mpId(%v)", multipartId, mpId)
err = syscall.ENOENT
@@ -1927,7 +1922,7 @@ func (mw *MetaWrapper) RemoveMultipart_ll(path, multipartID string) (err error)
return
}
}
- var mp = mw.getPartitionByID(mpId)
+ mp := mw.getPartitionByID(mpId)
if mp == nil {
err = syscall.ENOENT
return
@@ -1945,10 +1940,8 @@ func (mw *MetaWrapper) RemoveMultipart_ll(path, multipartID string) (err error)
func (mw *MetaWrapper) broadcastGetMultipart(path, multipartId string) (info *proto.MultipartInfo, mpID uint64, err error) {
log.LogInfof("broadcastGetMultipart: find meta partition broadcast multipartId(%v)", multipartId)
partitions := mw.partitions
- var (
- mp *MetaPartition
- )
- var wg = new(sync.WaitGroup)
+ var mp *MetaPartition
+ wg := new(sync.WaitGroup)
var resultMu sync.Mutex
for _, mp = range partitions {
wg.Add(1)
@@ -1980,9 +1973,9 @@ func (mw *MetaWrapper) broadcastGetMultipart(path, multipartId string) (info *pr
func (mw *MetaWrapper) ListMultipart_ll(prefix, delimiter, keyMarker string, multipartIdMarker string, maxUploads uint64) (sessionResponse []*proto.MultipartInfo, err error) {
partitions := mw.partitions
- var wg = sync.WaitGroup{}
- var wl = sync.Mutex{}
- var sessions = make([]*proto.MultipartInfo, 0)
+ wg := sync.WaitGroup{}
+ wl := sync.Mutex{}
+ sessions := make([]*proto.MultipartInfo, 0)
for _, mp := range partitions {
wg.Add(1)
diff --git a/sdk/meta/conn.go b/sdk/meta/conn.go
index 90f75dd60..50a613e8d 100644
--- a/sdk/meta/conn.go
+++ b/sdk/meta/conn.go
@@ -20,9 +20,8 @@ import (
"syscall"
"time"
- "github.com/cubefs/cubefs/util/errors"
-
"github.com/cubefs/cubefs/proto"
+ "github.com/cubefs/cubefs/util/errors"
"github.com/cubefs/cubefs/util/log"
)
@@ -33,8 +32,8 @@ const (
type MetaConn struct {
conn *net.TCPConn
- id uint64 //PartitionID
- addr string //MetaNode addr
+ id uint64 // PartitionID
+ addr string // MetaNode addr
}
// Connection managements
diff --git a/sdk/meta/meta.go b/sdk/meta/meta.go
index b42f79278..921e2c533 100644
--- a/sdk/meta/meta.go
+++ b/sdk/meta/meta.go
@@ -189,7 +189,7 @@ func NewMetaWrapper(config *MetaConfig) (*MetaWrapper, error) {
mw.closeCh = make(chan struct{}, 1)
if config.Authenticate {
- var ticketMess = config.TicketMess
+ ticketMess := config.TicketMess
mw.ac = authSDK.NewAuthClient(ticketMess.TicketHosts, ticketMess.EnableHTTPS, ticketMess.CertFile)
ticket, err := mw.ac.API().GetTicket(config.Owner, ticketMess.ClientKey, proto.MasterServiceID)
if err != nil {
diff --git a/sdk/meta/operation.go b/sdk/meta/operation.go
index 3ecec832a..4ef0f121f 100644
--- a/sdk/meta/operation.go
+++ b/sdk/meta/operation.go
@@ -79,7 +79,7 @@ func (mw *MetaWrapper) txIcreate(tx *Transaction, mp *MetaPartition, mode, uid,
status = parseStatus(packet.ResultCode)
if status != statusOK {
- //set tx error msg
+ // set tx error msg
err = errors.New(packet.GetResultMsg())
log.LogErrorf("txIcreate: packet(%v) mp(%v) req(%v) result(%v)", packet, mp, *req, packet.GetResultMsg())
return
@@ -330,7 +330,7 @@ func (mw *MetaWrapper) iunlink(mp *MetaPartition, inode uint64, verSeq uint64, d
stat.EndStat("iunlink", err, bgTime, 1)
}()
- //use uniq id to dedup request
+ // use uniq id to dedup request
status, uniqID, err := mw.consumeUniqID(mp)
if err != nil || status != statusOK {
err = statusToErrno(status)
@@ -876,7 +876,6 @@ func (mw *MetaWrapper) ddelete(mp *MetaPartition, parentID uint64, name string,
}
func (mw *MetaWrapper) canDeleteInode(mp *MetaPartition, info *proto.InodeInfo, ino uint64) (can bool, err error) {
-
createTime := info.CreateTime.Unix()
deleteLockTime := mw.volDeleteLockTime * 60 * 60
@@ -1061,9 +1060,7 @@ func (mw *MetaWrapper) iget(mp *MetaPartition, inode uint64, verSeq uint64) (sta
func (mw *MetaWrapper) batchIget(wg *sync.WaitGroup, mp *MetaPartition, inodes []uint64, respCh chan []*proto.InodeInfo) {
defer wg.Done()
- var (
- err error
- )
+ var err error
bgTime := stat.BeginStat()
defer func() {
@@ -1485,7 +1482,7 @@ func (mw *MetaWrapper) ilinkWork(mp *MetaPartition, inode uint64, op uint8, full
stat.EndStat("ilink", err, bgTime, 1)
}()
- //use unique id to dedup request
+ // use unique id to dedup request
status, uniqID, err := mw.consumeUniqID(mp)
if err != nil || status != statusOK {
err = statusToErrno(status)
@@ -2333,9 +2330,7 @@ func (mw *MetaWrapper) listMultiparts(mp *MetaPartition, prefix, delimiter, keyM
}
func (mw *MetaWrapper) batchGetXAttr(mp *MetaPartition, inodes []uint64, keys []string) ([]*proto.XAttrInfo, error) {
- var (
- err error
- )
+ var err error
bgTime := stat.BeginStat()
defer func() {
@@ -2662,8 +2657,8 @@ func (mw *MetaWrapper) applyQuota(parentIno uint64, quotaId uint32, totalInodeCo
*totalInodeCount = *totalInodeCount + 1
}
var defaultReaddirLimit uint64 = 1024
- var noMore = false
- var from = ""
+ noMore := false
+ from := ""
for !noMore {
entries, err := mw.ReadDirLimit_ll(parentIno, from, defaultReaddirLimit)
if err != nil {
@@ -2722,8 +2717,8 @@ func (mw *MetaWrapper) revokeQuota(parentIno uint64, quotaId uint32, totalInodeC
}
var defaultReaddirLimit uint64 = 1024
- var noMore = false
- var from = ""
+ noMore := false
+ from := ""
for !noMore {
entries, err := mw.ReadDirLimit_ll(parentIno, from, defaultReaddirLimit)
if err != nil {
@@ -2834,7 +2829,6 @@ func (mw *MetaWrapper) getUniqID(mp *MetaPartition, num uint32) (status int, sta
}
func (mw *MetaWrapper) checkVerFromMeta(packet *proto.Packet) {
-
if packet.VerSeq <= mw.Client.GetLatestVer() {
return
}
diff --git a/sdk/meta/partition.go b/sdk/meta/partition.go
index d5aa76a69..b4f969883 100644
--- a/sdk/meta/partition.go
+++ b/sdk/meta/partition.go
@@ -16,6 +16,7 @@ package meta
import (
"fmt"
+
"github.com/cubefs/cubefs/util/btree"
)
diff --git a/sdk/meta/transaction.go b/sdk/meta/transaction.go
index 0f109a537..85bd0ec62 100644
--- a/sdk/meta/transaction.go
+++ b/sdk/meta/transaction.go
@@ -17,11 +17,12 @@ package meta
import (
"errors"
"fmt"
+ "sync"
+
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/exporter"
"github.com/cubefs/cubefs/util/log"
"github.com/cubefs/cubefs/util/stat"
- "sync"
)
type Transaction struct {
@@ -102,11 +103,11 @@ func (tx *Transaction) SetOnCommit(job func()) {
func (tx *Transaction) SetOnRollback(job func()) {
tx.onRollbackFuncs = append(tx.onRollbackFuncs, job)
- //tx.onRollback = job
+ // tx.onRollback = job
}
func (tx *Transaction) OnDone(err error, mw *MetaWrapper) (newErr error) {
- //commit or rollback depending on status
+ // commit or rollback depending on status
newErr = err
if !tx.Started {
return
@@ -143,7 +144,7 @@ func (tx *Transaction) Commit(mw *MetaWrapper) (err error) {
TxID: tx.txInfo.TxID,
TmID: uint64(tx.txInfo.TmID),
TxApplyType: proto.TxCommit,
- //TxInfo: tx.txInfo,
+ // TxInfo: tx.txInfo,
}
packet := proto.NewPacketReqID()
@@ -202,7 +203,7 @@ func (tx *Transaction) Rollback(mw *MetaWrapper) {
TxID: tx.txInfo.TxID,
TmID: uint64(tx.txInfo.TmID),
TxApplyType: proto.TxRollback,
- //TxInfo: tx.txInfo,
+ // TxInfo: tx.txInfo,
}
packet := proto.NewPacketReqID()
diff --git a/sdk/meta/transaction_helper.go b/sdk/meta/transaction_helper.go
index 196adfe4e..4e5270c0d 100644
--- a/sdk/meta/transaction_helper.go
+++ b/sdk/meta/transaction_helper.go
@@ -16,9 +16,10 @@ package meta
import (
"fmt"
+ "sync/atomic"
+
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util/log"
- "sync/atomic"
)
var txId uint64 = 1
@@ -28,7 +29,7 @@ func genTransactionId(clientId uint64) string {
}
func getMembersFromMp(parentMp *MetaPartition) string {
- var members = parentMp.LeaderAddr
+ members := parentMp.LeaderAddr
for _, addr := range parentMp.Members {
if addr == parentMp.LeaderAddr {
continue
@@ -43,7 +44,7 @@ func getMembersFromMp(parentMp *MetaPartition) string {
}
func NewCreateTransaction(parentMp, inoMp *MetaPartition, parentID uint64, name string, txTimeout int64, txType uint32) (tx *Transaction, err error) {
- //tx = NewTransaction(txTimeout, proto.TxTypeCreate)
+ // tx = NewTransaction(txTimeout, proto.TxTypeCreate)
tx = NewTransaction(txTimeout, txType)
members := getMembersFromMp(parentMp)
diff --git a/sdk/meta/view.go b/sdk/meta/view.go
index d6abd944f..cbd08a6d6 100644
--- a/sdk/meta/view.go
+++ b/sdk/meta/view.go
@@ -91,7 +91,7 @@ func (mw *MetaWrapper) fetchVolumeView() (view *VolumeView, err error) {
vv.Name, vv.Status)
return nil, proto.ErrVolNotExists
}
- var convert = func(volView *proto.VolView) *VolumeView {
+ convert := func(volView *proto.VolView) *VolumeView {
result := &VolumeView{
Name: volView.Name,
Owner: volView.Owner,
@@ -154,7 +154,6 @@ func (mw *MetaWrapper) updateDirChildrenNumLimit() (err error) {
}
func (mw *MetaWrapper) updateVolStatInfo() (err error) {
-
var info *proto.VolStatInfo
if info, err = mw.mc.ClientAPI().GetVolumeStat(mw.volname); err != nil {
log.LogWarnf("updateVolStatInfo: get volume status fail: volume(%v) err(%v)", mw.volname, err)
@@ -333,7 +332,7 @@ func (mw *MetaWrapper) parseAndVerifyResp(body []byte, ts int64) (dataBody []byt
log.LogWarnf("fetchVolumeView verify response: err(%v)", err)
return nil, err
}
- var viewBody = &struct {
+ viewBody := &struct {
Code int32 `json:"code"`
Msg string `json:"msg"`
Data json.RawMessage
@@ -386,7 +385,6 @@ func (mw *MetaWrapper) updateQuotaInfoTick() {
case <-mw.closeCh:
return
}
-
}
}
diff --git a/snapshot/cmd/clean.go b/snapshot/cmd/clean.go
index 59c8f0de2..860108b91 100644
--- a/snapshot/cmd/clean.go
+++ b/snapshot/cmd/clean.go
@@ -38,7 +38,7 @@ const snapshotFullPath = "(Snapshot Cmd Unsupported)"
var gMetaWrapper *meta.MetaWrapper
func newCleanCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "clean",
Short: "clean snapshot related inode or dentry according to some rules",
Args: cobra.MinimumNArgs(0),
@@ -55,7 +55,7 @@ func newCleanCmd() *cobra.Command {
}
func newCleanSnapshotCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "snapshot",
Short: "clean snapshot",
Run: func(cmd *cobra.Command, args []string) {
@@ -69,7 +69,7 @@ func newCleanSnapshotCmd() *cobra.Command {
}
func newCleanInodeCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "inode",
Short: "clean dirty inode",
Run: func(cmd *cobra.Command, args []string) {
@@ -83,7 +83,7 @@ func newCleanInodeCmd() *cobra.Command {
}
func newCleanDentryCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "dentry",
Short: "clean dirty dentry",
Run: func(cmd *cobra.Command, args []string) {
@@ -97,7 +97,7 @@ func newCleanDentryCmd() *cobra.Command {
}
func newEvictInodeCmd() *cobra.Command {
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: "evict",
Short: "clean dirty dentry",
Run: func(cmd *cobra.Command, args []string) {
@@ -125,7 +125,7 @@ func Clean(opt string, args []string) error {
}
masters := strings.Split(MasterAddr, meta.HostsSeparator)
- var metaConfig = &meta.MetaConfig{
+ metaConfig := &meta.MetaConfig{
Volume: VolName,
Masters: masters,
}
@@ -291,7 +291,7 @@ func cleanSnapshot() (err error) {
parents []proto.Dentry
ino *proto.InodeInfo
)
- //return readSnapshot()
+ // return readSnapshot()
log.LogDebugf("action[cleanSnapshot] ReadDirLimit_ll parent root verSeq %v", VerSeq)
parents, err = gMetaWrapper.ReadDirLimitForSnapShotClean(1, "", math.MaxUint64, VerSeq, false) // one more for nextMarker
diff --git a/snapshot/cmd/root.go b/snapshot/cmd/root.go
index 9c389cfe5..e29f68c78 100644
--- a/snapshot/cmd/root.go
+++ b/snapshot/cmd/root.go
@@ -25,7 +25,7 @@ import (
func NewRootCmd() *cobra.Command {
var optShowVersion bool
- var c = &cobra.Command{
+ c := &cobra.Command{
Use: path.Base(os.Args[0]),
Short: "CubeFS snapshot tool",
Args: cobra.MinimumNArgs(0),
diff --git a/snapshot/main.go b/snapshot/main.go
index f477c8a90..ea99121d3 100644
--- a/snapshot/main.go
+++ b/snapshot/main.go
@@ -16,9 +16,9 @@ package main
import (
"fmt"
- "github.com/cubefs/cubefs/proto"
"os"
+ "github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/snapshot/cmd"
)
diff --git a/util/auditlog/auditlog.go b/util/auditlog/auditlog.go
index 7e8463257..13323af9c 100644
--- a/util/auditlog/auditlog.go
+++ b/util/auditlog/auditlog.go
@@ -120,8 +120,10 @@ type Audit struct {
lock sync.Mutex
}
-var gAdt *Audit = nil
-var gAdtMutex sync.RWMutex
+var (
+ gAdt *Audit = nil
+ gAdtMutex sync.RWMutex
+)
func getAddr() (HostName, IPAddr string) {
hostName, err := os.Hostname()
@@ -154,9 +156,7 @@ func getAddr() (HostName, IPAddr string) {
// NOTE: for client http apis
func ResetWriterBuffSize(w http.ResponseWriter, r *http.Request) {
- var (
- err error
- )
+ var err error
if err = r.ParseForm(); err != nil {
BuildFailureResp(w, http.StatusBadRequest, err.Error())
return
@@ -237,13 +237,13 @@ func NewAudit(dir, logModule string, logMaxSize int64) (*Audit, error) {
}
fi, err := os.Stat(absPath)
if err != nil {
- os.MkdirAll(absPath, 0755)
+ os.MkdirAll(absPath, 0o755)
} else {
if !fi.IsDir() {
return nil, errors.New(absPath + " is not a directory")
}
}
- _ = os.Chmod(absPath, 0755)
+ _ = os.Chmod(absPath, 0o755)
logName := path.Join(absPath, Audit_Module) + ".log"
audit := &Audit{
hostName: host,
@@ -473,7 +473,7 @@ func (a *Audit) newWriterSize(size int) error {
}
if a.logFile == nil {
- logFile, err := os.OpenFile(a.logFileName, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)
+ logFile, err := os.OpenFile(a.logFileName, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0o666)
if err != nil {
log.LogErrorf("newWriterSize failed, logFileName: %s, err: %v\n", a.logFileName, err)
return fmt.Errorf("OpenLogFile failed, logFileName %s", a.logFileName)
@@ -506,7 +506,6 @@ func (a *Audit) newWriterSize(size int) error {
}
func (a *Audit) removeLogFile() {
-
fs := syscall.Statfs_t{}
if err := syscall.Statfs(a.logDir, &fs); err != nil {
log.LogErrorf("Get fs stat failed, err: %v", err)
diff --git a/util/auth/auth.go b/util/auth/auth.go
index dcca75424..863b0564c 100644
--- a/util/auth/auth.go
+++ b/util/auth/auth.go
@@ -7,7 +7,7 @@ type TicketMess struct {
CertFile string
}
-//the ticket from authnode
+// the ticket from authnode
type Ticket struct {
ID string `json:"client_id"`
SessionKey string `json:"session_key"`
diff --git a/util/btree/btree_test.go b/util/btree/btree_test.go
index 78a90cd8a..4dacdd9bf 100644
--- a/util/btree/btree_test.go
+++ b/util/btree/btree_test.go
@@ -239,6 +239,7 @@ func TestDescendRange(t *testing.T) {
t.Fatalf("descendrange:\n got: %v\nwant: %v", got, want)
}
}
+
func TestAscendLessThan(t *testing.T) {
tr := New(*btreeDegree)
for _, v := range perm(100) {
@@ -290,6 +291,7 @@ func TestDescendLessOrEqual(t *testing.T) {
t.Fatalf("descendlessorequal:\n got: %v\nwant: %v", got, want)
}
}
+
func TestAscendGreaterOrEqual(t *testing.T) {
tr := New(*btreeDegree)
for _, v := range perm(100) {
@@ -546,6 +548,7 @@ func BenchmarkDescend(b *testing.B) {
})
}
}
+
func BenchmarkAscendRange(b *testing.B) {
arr := perm(benchmarkTreeSize)
tr := New(*btreeDegree)
@@ -591,6 +594,7 @@ func BenchmarkDescendRange(b *testing.B) {
}
}
}
+
func BenchmarkAscendGreaterOrEqual(b *testing.B) {
arr := perm(benchmarkTreeSize)
tr := New(*btreeDegree)
@@ -618,6 +622,7 @@ func BenchmarkAscendGreaterOrEqual(b *testing.B) {
}
}
}
+
func BenchmarkDescendLessOrEqual(b *testing.B) {
arr := perm(benchmarkTreeSize)
tr := New(*btreeDegree)
diff --git a/util/buf/buffer_pool.go b/util/buf/buffer_pool.go
index 1badbae42..db06e6d1b 100644
--- a/util/buf/buffer_pool.go
+++ b/util/buf/buffer_pool.go
@@ -28,28 +28,38 @@ const (
BufferTypeHeaderVer = 2
)
-var tinyBuffersTotalLimit int64 = 4096
-var NormalBuffersTotalLimit int64
-var HeadBuffersTotalLimit int64
-var HeadVerBuffersTotalLimit int64
+var (
+ tinyBuffersTotalLimit int64 = 4096
+ NormalBuffersTotalLimit int64
+ HeadBuffersTotalLimit int64
+ HeadVerBuffersTotalLimit int64
+)
-var tinyBuffersCount int64
-var normalBuffersCount int64
-var headBuffersCount int64
-var headVerBuffersCount int64
+var (
+ tinyBuffersCount int64
+ normalBuffersCount int64
+ headBuffersCount int64
+ headVerBuffersCount int64
+)
-var normalBufAllocId uint64
-var headBufAllocId uint64
-var headBufVerAllocId uint64
+var (
+ normalBufAllocId uint64
+ headBufAllocId uint64
+ headBufVerAllocId uint64
+)
-var normalBufFreecId uint64
-var headBufFreeId uint64
-var headBufVerFreeId uint64
+var (
+ normalBufFreecId uint64
+ headBufFreeId uint64
+ headBufVerFreeId uint64
+)
-var buffersRateLimit = rate.NewLimiter(rate.Limit(16), 16)
-var normalBuffersRateLimit = rate.NewLimiter(rate.Limit(16), 16)
-var headBuffersRateLimit = rate.NewLimiter(rate.Limit(16), 16)
-var headVerBuffersRateLimit = rate.NewLimiter(rate.Limit(16), 16)
+var (
+ buffersRateLimit = rate.NewLimiter(rate.Limit(16), 16)
+ normalBuffersRateLimit = rate.NewLimiter(rate.Limit(16), 16)
+ headBuffersRateLimit = rate.NewLimiter(rate.Limit(16), 16)
+ headVerBuffersRateLimit = rate.NewLimiter(rate.Limit(16), 16)
+)
func NewTinyBufferPool() *sync.Pool {
return &sync.Pool{
@@ -110,9 +120,7 @@ type BufferPool struct {
headVerPool *sync.Pool
}
-var (
- slotCnt = uint64(16)
-)
+var slotCnt = uint64(16)
// NewBufferPool returns a new buffered pool.
func NewBufferPool() (bufferP *BufferPool) {
@@ -131,6 +139,7 @@ func NewBufferPool() (bufferP *BufferPool) {
bufferP.normalPool = NewNormalBufferPool()
return bufferP
}
+
func (bufferP *BufferPool) getHead(id uint64) (data []byte) {
select {
case data = <-bufferP.headPools[id%slotCnt]:
diff --git a/util/buf/cache_pool.go b/util/buf/cache_pool.go
index 217abf8a6..fbcfdcbee 100644
--- a/util/buf/cache_pool.go
+++ b/util/buf/cache_pool.go
@@ -2,17 +2,20 @@ package buf
import (
"context"
+ "sync"
+ "sync/atomic"
+
"github.com/cubefs/cubefs/util"
"github.com/cubefs/cubefs/util/log"
"golang.org/x/time/rate"
- "sync"
- "sync/atomic"
)
-var cacheTotalLimit int64
-var cacheRateLimit = rate.NewLimiter(rate.Limit(16), 16)
-var cacheCount int64
-var CachePool *FileCachePool
+var (
+ cacheTotalLimit int64
+ cacheRateLimit = rate.NewLimiter(rate.Limit(16), 16)
+ cacheCount int64
+ CachePool *FileCachePool
+)
func newWriterCachePool(blockSize int) *sync.Pool {
return &sync.Pool{
diff --git a/util/caps/caps.go b/util/caps/caps.go
index 6dfbf4d93..1ed632da3 100644
--- a/util/caps/caps.go
+++ b/util/caps/caps.go
@@ -76,7 +76,7 @@ func (c *Caps) Dump() (d string) {
for _, s := range c.API {
d += fmt.Sprintf("API:%s,", s)
}
- //TODO c.vol (no usage?)
+ // TODO c.vol (no usage?)
return
}
diff --git a/util/concurrent/keyconcurrentlimit.go b/util/concurrent/keyconcurrentlimit.go
index fb7505171..b8787b735 100644
--- a/util/concurrent/keyconcurrentlimit.go
+++ b/util/concurrent/keyconcurrentlimit.go
@@ -20,9 +20,7 @@ import (
"sync/atomic"
)
-var (
- ErrLimit = errors.New("limit exceeded")
-)
+var ErrLimit = errors.New("limit exceeded")
type KeyConcurrentLimit struct {
mutex sync.RWMutex
@@ -34,7 +32,6 @@ func NewLimit() *KeyConcurrentLimit {
}
func (s *KeyConcurrentLimit) Acquire(key string, limit int64) error {
-
s.mutex.RLock()
count := s.current[key]
s.mutex.RUnlock()
@@ -66,7 +63,6 @@ func (s *KeyConcurrentLimit) Release(key string) {
if val < 0 {
atomic.StoreInt64(count, 0)
}
-
}
func (s *KeyConcurrentLimit) Running() int {
diff --git a/util/concurrent/keyconcurrentlimit_test.go b/util/concurrent/keyconcurrentlimit_test.go
index 775f7493d..84ae05052 100644
--- a/util/concurrent/keyconcurrentlimit_test.go
+++ b/util/concurrent/keyconcurrentlimit_test.go
@@ -21,7 +21,6 @@ import (
)
func TestSyncKeyLimit(t *testing.T) {
-
l := NewLimit()
key1, key2, key3 := string("1"), string("2"), string("3")
require.Equal(t, 0, l.Running())
@@ -86,5 +85,4 @@ func TestKeyLimit_Switch(t *testing.T) {
ast.NoError(l.Acquire(key, 10))
ast.Equal(int64(3), l.Get(key))
-
}
diff --git a/util/config/config.go b/util/config/config.go
index c82224685..0115a9702 100644
--- a/util/config/config.go
+++ b/util/config/config.go
@@ -252,7 +252,7 @@ func (ccfg *ConstConfig) Equals(cfg *ConstConfig) bool {
// check listen port, raft replica port and raft heartbeat port
func CheckOrStoreConstCfg(fileDir, fileName string, cfg *ConstConfig) (ok bool, err error) {
- var filePath = path.Join(fileDir, fileName)
+ filePath := path.Join(fileDir, fileName)
var buf []byte
buf, err = ioutil.ReadFile(filePath)
if err != nil && !os.IsNotExist(err) {
@@ -263,11 +263,11 @@ func CheckOrStoreConstCfg(fileDir, fileName string, cfg *ConstConfig) (ok bool,
if buf, err = json.Marshal(cfg); err != nil {
return false, fmt.Errorf("marshal const config failed: %v", err)
}
- if err = os.MkdirAll(fileDir, 0755); err != nil {
+ if err = os.MkdirAll(fileDir, 0o755); err != nil {
return false, fmt.Errorf("make directory %v filed: %v", fileDir, err)
}
var file *os.File
- if file, err = os.OpenFile(filePath, os.O_CREATE|os.O_RDWR, 0755); err != nil {
+ if file, err = os.OpenFile(filePath, os.O_CREATE|os.O_RDWR, 0o755); err != nil {
return false, fmt.Errorf("create config file %v failed: %v", filePath, err)
}
defer func() {
@@ -308,7 +308,7 @@ func CheckOrStoreClusterUuid(dirPath, id string, force bool) (err error) {
if err != nil {
return fmt.Errorf("json marshal failed: %v", err.Error())
}
- if err = ioutil.WriteFile(versionFile, data, 0755); err != nil {
+ if err = ioutil.WriteFile(versionFile, data, 0o755); err != nil {
return fmt.Errorf("write file %v failed: %v", versionFile, err.Error())
}
} else {
diff --git a/util/conn_pool.go b/util/conn_pool.go
index 0031ed009..21cd2137c 100644
--- a/util/conn_pool.go
+++ b/util/conn_pool.go
@@ -90,7 +90,7 @@ func (cp *ConnectPool) GetConnect(targetAddr string) (c *net.TCPConn, err error)
cp.Lock()
pool, ok = cp.pools[targetAddr]
if !ok {
- //pool = NewPool(cp.mincap, cp.maxcap, cp.timeout, cp.connectTimeout, targetAddr)
+ // pool = NewPool(cp.mincap, cp.maxcap, cp.timeout, cp.connectTimeout, targetAddr)
pool = newPool
cp.pools[targetAddr] = pool
}
@@ -127,7 +127,7 @@ func (cp *ConnectPool) PutConnect(c *net.TCPConn, forceClose bool) {
}
func (cp *ConnectPool) autoRelease() {
- var timer = time.NewTimer(time.Second)
+ timer := time.NewTimer(time.Second)
for {
select {
case <-cp.closeCh:
@@ -254,9 +254,7 @@ func (p *Pool) NewConnect(target string) (c *net.TCPConn, err error) {
}
func (p *Pool) GetConnectFromPool() (c *net.TCPConn, err error) {
- var (
- o *Object
- )
+ var o *Object
for {
select {
case o = <-p.objects:
diff --git a/util/cryptoutil/cryptoutil.go b/util/cryptoutil/cryptoutil.go
index 471bac307..05d87f04e 100644
--- a/util/cryptoutil/cryptoutil.go
+++ b/util/cryptoutil/cryptoutil.go
@@ -49,9 +49,7 @@ func unpad(src []byte) []byte {
// AesEncryptCBC defines aes encryption with CBC
func AesEncryptCBC(key, plaintext []byte) (ciphertext []byte, err error) {
- var (
- block cipher.Block
- )
+ var block cipher.Block
if len(plaintext) == 0 {
err = fmt.Errorf("input for encryption is invalid")
@@ -170,7 +168,6 @@ func EncodeMessage(plaintext []byte, key []byte) (message string, err error) {
message = base64.StdEncoding.EncodeToString(cipher)
return
-
}
// DecodeMessage decode a message and verify its validity
@@ -208,7 +205,7 @@ func DecodeMessage(message string, key []byte) (plaintext []byte, err error) {
plaintext = decodedText[MessageOffset:]
- //fmt.Printf("DecodeMessage CBC: %s\n", plaintext)
+ // fmt.Printf("DecodeMessage CBC: %s\n", plaintext)
return
}
diff --git a/util/exporter/alarm.go b/util/exporter/alarm.go
index 9e7fa9372..5b567b236 100644
--- a/util/exporter/alarm.go
+++ b/util/exporter/alarm.go
@@ -26,7 +26,7 @@ var (
AlarmPool = &sync.Pool{New: func() interface{} {
return new(Alarm)
}}
- //AlarmGroup sync.Map
+ // AlarmGroup sync.Map
AlarmCh chan *Alarm
)
diff --git a/util/exporter/consul_register.go b/util/exporter/consul_register.go
index 77d264aff..78f06e799 100644
--- a/util/exporter/consul_register.go
+++ b/util/exporter/consul_register.go
@@ -18,7 +18,7 @@ import (
"bytes"
"encoding/json"
"fmt"
- "io/ioutil"
+ "io"
"net"
"net/http"
"regexp"
@@ -55,7 +55,6 @@ func GetConsulId(app string, role string, host string, port int64) string {
// do consul register process
func DoConsulRegisterProc(addr, app, role, cluster, meta, host string, port int64) {
if len(addr) <= 0 {
-
return
}
log.LogInfof("metrics consul register %v %v %v", addr, cluster, port)
@@ -75,7 +74,7 @@ func DoConsulRegisterProc(addr, app, role, cluster, meta, host string, port int6
}
if resp, _ := client.Do(req); resp != nil {
- ioutil.ReadAll(resp.Body)
+ io.ReadAll(resp.Body)
resp.Body.Close()
}
@@ -86,7 +85,7 @@ func DoConsulRegisterProc(addr, app, role, cluster, meta, host string, port int6
return
}
if resp, _ := client.Do(req); resp != nil {
- ioutil.ReadAll(resp.Body)
+ io.ReadAll(resp.Body)
resp.Body.Close()
}
}
diff --git a/util/exporter/exporter.go b/util/exporter/exporter.go
index e06ce6997..3976b030f 100644
--- a/util/exporter/exporter.go
+++ b/util/exporter/exporter.go
@@ -35,15 +35,15 @@ import (
const (
PromHandlerPattern = "/metrics" // prometheus handler
- AppName = "cfs" //app name
- ConfigKeyExporterEnable = "exporterEnable" //exporter enable
- ConfigKeyExporterPort = "exporterPort" //exporter port
- ConfigKeyConsulAddr = "consulAddr" //consul addr
+ AppName = "cfs" // app name
+ ConfigKeyExporterEnable = "exporterEnable" // exporter enable
+ ConfigKeyExporterPort = "exporterPort" // exporter port
+ ConfigKeyConsulAddr = "consulAddr" // consul addr
ConfigKeyConsulMeta = "consulMeta" // consul meta
ConfigKeyIpFilter = "ipFilter" // add ip filter
ConfigKeyEnablePid = "enablePid" // enable report partition id
ConfigKeyPushAddr = "pushAddr" // enable push data to gateway
- ChSize = 1024 * 10 //collect chan size
+ ChSize = 1024 * 10 // collect chan size
// monitor label name
Vol = "vol"
@@ -194,7 +194,6 @@ func RegistConsul(cluster string, role string, cfg *config.Config) {
}
func autoPush(pushAddr, role, cluster, ip, mountPoint string) {
-
pid := os.Getpid()
client := &http.Client{
@@ -229,7 +228,6 @@ func autoPush(pushAddr, role, cluster, ip, mountPoint string) {
}
}
}()
-
}
func collect() {
diff --git a/util/exporter/exporter_test.go b/util/exporter/exporter_test.go
index 832bb69bb..5118c97fe 100644
--- a/util/exporter/exporter_test.go
+++ b/util/exporter/exporter_test.go
@@ -39,11 +39,10 @@ func TestNewCounter(t *testing.T) {
name2 := fmt.Sprintf("name_%d_counter", i%2)
c := NewGauge(name2)
if c != nil {
- //c.Set(float64(i))
+ // c.Set(float64(i))
c.SetWithLabels(float64(i), map[string]string{"volname": label, "cluster": name})
// t.Logf("metric: %v", name2)
}
-
}(int64(i))
}
diff --git a/util/exporter/gauge.go b/util/exporter/gauge.go
index 917501df6..3a1135764 100644
--- a/util/exporter/gauge.go
+++ b/util/exporter/gauge.go
@@ -33,7 +33,7 @@ func collectGauge() {
m := <-GaugeCh
metric := m.Metric()
metric.Set(m.val)
- //log.LogDebugf("collect metric %v", m)
+ // log.LogDebugf("collect metric %v", m)
}
}
diff --git a/util/flowctrl/controller.go b/util/flowctrl/controller.go
old mode 100755
new mode 100644
diff --git a/util/flowctrl/controller_test.go b/util/flowctrl/controller_test.go
old mode 100755
new mode 100644
diff --git a/util/flowctrl/keycontroller.go b/util/flowctrl/keycontroller.go
old mode 100755
new mode 100644
index ce4a46020..7d0ddf00e
--- a/util/flowctrl/keycontroller.go
+++ b/util/flowctrl/keycontroller.go
@@ -40,7 +40,6 @@ func NewKeyFlowCtrl() *KeyFlowCtrl {
}
func (k *KeyFlowCtrl) Acquire(key string, rate int) *Controller {
-
k.mutex.Lock()
ctrl, ok := k.current[key]
if !ok {
@@ -53,7 +52,6 @@ func (k *KeyFlowCtrl) Acquire(key string, rate int) *Controller {
}
func (k *KeyFlowCtrl) Release(key string) {
-
k.mutex.Lock()
defer k.mutex.Unlock()
ctrl, ok := k.current[key]
diff --git a/util/flowctrl/keycontroller_test.go b/util/flowctrl/keycontroller_test.go
old mode 100755
new mode 100644
index 15d2915d3..780c5fd2b
--- a/util/flowctrl/keycontroller_test.go
+++ b/util/flowctrl/keycontroller_test.go
@@ -17,7 +17,6 @@ package flowctrl
import (
"fmt"
"io"
- "io/ioutil"
"math/rand"
"strings"
"testing"
@@ -26,7 +25,6 @@ import (
)
func TestKeyController(t *testing.T) {
-
k := NewKeyFlowCtrl()
key1, key2, key3 := "10001", "10002", "10003"
k.Acquire(key1, 1024)
@@ -54,7 +52,6 @@ func TestKeyController(t *testing.T) {
assert.Panics(t, func() {
k.Release(key3)
})
-
}
func BenchmarkRWKeyRateCtrl(b *testing.B) {
@@ -83,7 +80,7 @@ func BenchmarkRWKeyRateCtrlReader(b *testing.B) {
c := k.Acquire(uidStr, 1024)
defer k.Release(uidStr)
reader := NewRateReaderWithCtrl(strings.NewReader(str), c)
- io.Copy(ioutil.Discard, reader)
+ io.Copy(io.Discard, reader)
}
})
t := testing.T{}
diff --git a/util/flowctrl/reader.go b/util/flowctrl/reader.go
old mode 100755
new mode 100644
index 27aad54a5..6cabcd072
--- a/util/flowctrl/reader.go
+++ b/util/flowctrl/reader.go
@@ -22,7 +22,6 @@ type rateReader struct {
}
func (self *rateReader) Read(p []byte) (n int, err error) {
-
size := len(p)
size = self.c.acquire(size)
diff --git a/util/flowctrl/reader_test.go b/util/flowctrl/reader_test.go
old mode 100755
new mode 100644
diff --git a/util/flowctrl/writer.go b/util/flowctrl/writer.go
old mode 100755
new mode 100644
diff --git a/util/flowctrl/writer_test.go b/util/flowctrl/writer_test.go
old mode 100755
new mode 100644
diff --git a/util/keystore/keystore.go b/util/keystore/keystore.go
index a40675b2b..1fabb6cb6 100644
--- a/util/keystore/keystore.go
+++ b/util/keystore/keystore.go
@@ -28,9 +28,7 @@ type KeyInfo struct {
// DumpJSONFile dump KeyInfo to file in json format
func (u *KeyInfo) DumpJSONFile(filename string, authIdKey string) (err error) {
- var (
- data string
- )
+ var data string
if data, err = u.DumpJSONStr(authIdKey); err != nil {
return
}
diff --git a/util/loadutil/cpu.go b/util/loadutil/cpu.go
index 4afed68c2..a7e89a8af 100644
--- a/util/loadutil/cpu.go
+++ b/util/loadutil/cpu.go
@@ -16,10 +16,11 @@ package loadutil
import (
"fmt"
- "github.com/cubefs/cubefs/util/log"
"time"
"github.com/shirou/gopsutil/cpu"
+
+ "github.com/cubefs/cubefs/util/log"
)
func GetCpuUtilPercent(sampleDuration time.Duration) (used float64, err error) {
diff --git a/util/log/log.go b/util/log/log.go
index ed86535bc..6ffc06951 100644
--- a/util/log/log.go
+++ b/util/log/log.go
@@ -183,11 +183,11 @@ func (writer *asyncWriter) flushToFile() {
FileNameDateFormat) + RotatedExtension
if _, err := os.Lstat(oldFile); err != nil {
if err := writer.rename(oldFile); err == nil {
- if fp, err := os.OpenFile(writer.fileName, FileOpt, 0666); err == nil {
+ if fp, err := os.OpenFile(writer.fileName, FileOpt, 0o666); err == nil {
writer.file.Close()
writer.file = fp
writer.logSize = 0
- _ = os.Chmod(writer.fileName, 0666)
+ _ = os.Chmod(writer.fileName, 0o666)
} else {
syslog.Printf("log rotate: openFile %v error: %v", writer.fileName, err)
}
@@ -213,7 +213,7 @@ func (writer *asyncWriter) rename(newName string) error {
}
func newAsyncWriter(fileName string, rotateSize int64) (*asyncWriter, error) {
- fp, err := os.OpenFile(fileName, FileOpt, 0666)
+ fp, err := os.OpenFile(fileName, FileOpt, 0o666)
if err != nil {
return nil, err
}
@@ -221,7 +221,7 @@ func newAsyncWriter(fileName string, rotateSize int64) (*asyncWriter, error) {
if err != nil {
return nil, err
}
- _ = os.Chmod(fileName, 0666)
+ _ = os.Chmod(fileName, 0o666)
w := &asyncWriter{
file: fp,
fileName: fileName,
@@ -311,13 +311,13 @@ func InitLog(dir, module string, level Level, rotate *LogRotate, logLeftSpaceLim
LogDir = dir
fi, err := os.Stat(dir)
if err != nil {
- os.MkdirAll(dir, 0755)
+ os.MkdirAll(dir, 0o755)
} else {
if !fi.IsDir() {
return nil, errors.New(dir + " is not a directory")
}
}
- _ = os.Chmod(dir, 0755)
+ _ = os.Chmod(dir, 0o755)
fs := syscall.Statfs_t{}
if err := syscall.Statfs(dir, &fs); err != nil {
@@ -455,9 +455,7 @@ const (
)
func SetLogLevel(w http.ResponseWriter, r *http.Request) {
- var (
- err error
- )
+ var err error
if err = r.ParseForm(); err != nil {
buildFailureResp(w, http.StatusBadRequest, err.Error())
return
diff --git a/util/log/log_test.go b/util/log/log_test.go
index 95ae67c92..a81edcfa4 100644
--- a/util/log/log_test.go
+++ b/util/log/log_test.go
@@ -33,7 +33,7 @@ func TestLog(t *testing.T) {
dir := path.Join("/tmp/cfs", "cfs")
_, err := os.Stat(dir)
if os.IsNotExist(err) {
- os.MkdirAll(dir, 0755)
+ os.MkdirAll(dir, 0o755)
}
defer os.RemoveAll(dir)
@@ -85,7 +85,7 @@ func prepareTestLeftSpaceLimit(dir string, logFileName string) (diskSpaceLeft in
_, err = os.Stat(dir)
if os.IsNotExist(err) {
- os.MkdirAll(dir, 0755)
+ os.MkdirAll(dir, 0o755)
}
logFilePath = path.Join(dir, logFileName)
diff --git a/util/master_helper.go b/util/master_helper.go
index 158f4e32e..1a6e0571a 100644
--- a/util/master_helper.go
+++ b/util/master_helper.go
@@ -19,7 +19,7 @@ import (
"encoding/json"
"errors"
"fmt"
- "io/ioutil"
+ "io"
"net/http"
"strings"
"sync"
@@ -32,9 +32,7 @@ const (
requestTimeout = 30 * time.Second
)
-var (
- ErrNoValidMaster = errors.New("no valid master")
-)
+var ErrNoValidMaster = errors.New("no valid master")
// MasterHelper defines the helper struct to manage the master.
type MasterHelper interface {
@@ -97,7 +95,7 @@ func (helper *masterHelper) request(method, path string, param, header map[strin
continue
}
stateCode := resp.StatusCode
- repsData, err = ioutil.ReadAll(resp.Body)
+ repsData, err = io.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
log.LogErrorf("[masterHelper] %s", err)
@@ -119,14 +117,13 @@ func (helper *masterHelper) request(method, path string, param, header map[strin
if leaderAddr != host {
helper.setLeader(host)
}
- var body = &struct {
+ body := &struct {
Code int32 `json:"code"`
Msg string `json:"msg"`
Data json.RawMessage `json:"data"`
}{}
if err := json.Unmarshal(repsData, body); err != nil {
return nil, fmt.Errorf("unmarshal response body err:%v", err)
-
}
// o represent proto.ErrCodeSuccess
if body.Code != 0 {
diff --git a/util/ratelimit/keyratelimit.go b/util/ratelimit/keyratelimit.go
index 51c7fea67..d3ea74cfa 100644
--- a/util/ratelimit/keyratelimit.go
+++ b/util/ratelimit/keyratelimit.go
@@ -43,7 +43,6 @@ func NewKeyRateLimit() *KeyRateLimit {
}
func (k *KeyRateLimit) Acquire(key string, rate int) *ratelimit.RateLimiter {
-
k.mutex.Lock()
limit, ok := k.current[key]
if !ok {
@@ -56,7 +55,6 @@ func (k *KeyRateLimit) Acquire(key string, rate int) *ratelimit.RateLimiter {
}
func (k *KeyRateLimit) Release(key string) {
-
k.mutex.Lock()
defer k.mutex.Unlock()
limit, ok := k.current[key]
diff --git a/util/ratelimit/keyratelimit_test.go b/util/ratelimit/keyratelimit_test.go
index 788a98301..037f8aaa0 100644
--- a/util/ratelimit/keyratelimit_test.go
+++ b/util/ratelimit/keyratelimit_test.go
@@ -21,7 +21,6 @@ import (
)
func TestKeyController(t *testing.T) {
-
k := NewKeyRateLimit()
key1, key2, key3 := "10001", "10002", "10003"
k.Acquire(key1, 1024)
@@ -49,5 +48,4 @@ func TestKeyController(t *testing.T) {
assert.Panics(t, func() {
k.Release(key3)
})
-
}
diff --git a/util/reloadconf/reload_conf.go b/util/reloadconf/reload_conf.go
index 44390715c..494be9f10 100644
--- a/util/reloadconf/reload_conf.go
+++ b/util/reloadconf/reload_conf.go
@@ -19,7 +19,6 @@ import (
"crypto/md5"
"encoding/base64"
"fmt"
- "io/ioutil"
"os"
"sync"
"time"
@@ -39,7 +38,6 @@ type ReloadConf struct {
}
func (self *ReloadConf) reload(reload func(data []byte) error) error {
-
self.mutex.Lock()
defer self.mutex.Unlock()
@@ -63,7 +61,6 @@ func (self *ReloadConf) reload(reload func(data []byte) error) error {
}
func (self *ReloadConf) remoteReload(reload func(data []byte) error) (err error) {
-
data, md5sum, err := fetchRemote(self.RequestRemote)
if err != nil {
err = errors.Info(err, "fetchRemote").Detail(err)
@@ -77,9 +74,9 @@ func (self *ReloadConf) remoteReload(reload func(data []byte) error) (err error)
}
confName := fmt.Sprintf("%v_%v", self.ConfName, base64.URLEncoding.EncodeToString(md5sum))
- err = ioutil.WriteFile(confName, data, 0666)
+ err = os.WriteFile(confName, data, 0o666)
if err != nil {
- err = errors.Info(err, "ioutil.WriteFile")
+ err = errors.Info(err, "os.WriteFile")
return
}
log.LogInfof("remoteReload %v remote file is changed, oldmd5: %v, newmd5: %v", self.ConfName, self.md5sum, md5sum)
@@ -103,10 +100,9 @@ func (self *ReloadConf) remoteReload(reload func(data []byte) error) (err error)
}
func (self *ReloadConf) localReload(reload func(data []byte) error) (err error) {
-
- data, err := ioutil.ReadFile(self.ConfName)
+ data, err := os.ReadFile(self.ConfName)
if err != nil {
- err = errors.Info(err, "ioutil.ReadFile").Detail(err)
+ err = errors.Info(err, "os.ReadFile").Detail(err)
return
}
md5sum := calcMD5Sum(data)
@@ -127,10 +123,9 @@ func (self *ReloadConf) localReload(reload func(data []byte) error) (err error)
}
func fetchRemote(requestRemote func() ([]byte, error)) (data, md5sum []byte, err error) {
-
data, err = requestRemote()
if err != nil {
- err = errors.Info(err, "ioutil.ReadAll")
+ err = errors.Info(err, "io.ReadAll")
return
}
md5sum = calcMD5Sum(data)
@@ -139,7 +134,6 @@ func fetchRemote(requestRemote func() ([]byte, error)) (data, md5sum []byte, err
}
func StartReload(cfg *ReloadConf, reload func(data []byte) error) (err error) {
-
err = cfg.reload(reload)
if err != nil {
log.LogError("cfg.reload:", cfg.ConfName, errors.Detail(err))
diff --git a/util/routinepool/pool.go b/util/routinepool/pool.go
index 7b2e7d160..2f2fc2d3a 100644
--- a/util/routinepool/pool.go
+++ b/util/routinepool/pool.go
@@ -30,9 +30,7 @@ type RoutinePool struct {
runningNum int32
}
-var (
- ErrorClosed = errors.New("pool is closed")
-)
+var ErrorClosed = errors.New("pool is closed")
func NewRoutinePool(maxRoutineNum int) *RoutinePool {
if maxRoutineNum <= 0 {
diff --git a/util/set.go b/util/set.go
index 8bcf2f148..2df65e32f 100644
--- a/util/set.go
+++ b/util/set.go
@@ -16,12 +16,13 @@ package util
import "sync"
-type Null struct {
-}
-type Set struct {
- sync.RWMutex
- m map[string]Null
-}
+type (
+ Null struct{}
+ Set struct {
+ sync.RWMutex
+ m map[string]Null
+ }
+)
func NewSet() *Set {
return &Set{
@@ -34,6 +35,7 @@ func (s *Set) Add(val string) {
defer s.Unlock()
s.m[val] = Null{}
}
+
func (s *Set) Remove(val string) {
s.Lock()
defer s.Unlock()
diff --git a/util/smux_conn_pool.go b/util/smux_conn_pool.go
index 5f1bf9e74..582442e3d 100644
--- a/util/smux_conn_pool.go
+++ b/util/smux_conn_pool.go
@@ -38,9 +38,7 @@ const (
defaultCreateInterval = int64(time.Microsecond * 200)
)
-var (
- ErrTooMuchSmuxStreams = errors.New("too much smux streams")
-)
+var ErrTooMuchSmuxStreams = errors.New("too much smux streams")
// addr = ip:port
// afterShift = ip:(port+shift)
@@ -58,7 +56,7 @@ func ShiftAddrPort(addr string, shift int) (afterShift string) {
return
}
-//filter smux accept error
+// filter smux accept error
func FilterSmuxAcceptError(err error) error {
if err == nil {
return nil
@@ -240,7 +238,7 @@ func (cp *SmuxConnectPool) PutConnect(stream *smux.Stream, forceClose bool) {
}
func (cp *SmuxConnectPool) autoRelease() {
- var timer = time.NewTimer(time.Duration(cp.cfg.StreamIdleTimeout))
+ timer := time.NewTimer(time.Duration(cp.cfg.StreamIdleTimeout))
for {
select {
case <-cp.closeCh:
@@ -391,7 +389,7 @@ func (p *SmuxPool) callCreate() (createCall *createSessCall) {
} else {
return
}
- //default:
+ // default:
}
tryCreateNewSess:
prev := createCall
@@ -471,7 +469,7 @@ func (p *SmuxPool) canUse(sess *smux.Session) bool {
maxStreams := p.cfg.StreamsPerConn * p.cfg.ConnsPerAddr
inflight := p.inflightStreamNum()
if inflight >= maxStreams {
- //oversold
+ // oversold
return streamNum <= ((inflight / p.cfg.ConnsPerAddr) + 1)
} else {
return false
@@ -496,7 +494,7 @@ func (p *SmuxPool) ReleaseAll() {
}
func (p *SmuxPool) getAvailSess() (sess *smux.Session) {
- //every time start from different pos
+ // every time start from different pos
iter := atomic.AddInt64(&p.sessionsIter, 1) - 1
p.sessionsLock.RLock()
sessionsLen := len(p.sessions)
@@ -513,7 +511,7 @@ func (p *SmuxPool) getAvailSess() (sess *smux.Session) {
func (p *SmuxPool) insertSession(sess *smux.Session) {
p.sessionsLock.Lock()
- //replace
+ // replace
for i, o := range p.sessions {
if o == nil || o.IsClosed() {
p.sessions[i] = sess
@@ -521,7 +519,7 @@ func (p *SmuxPool) insertSession(sess *smux.Session) {
return
}
}
- //or append
+ // or append
p.sessions = append(p.sessions, sess)
p.sessionsLock.Unlock()
}
diff --git a/util/smux_conn_pool_test.go b/util/smux_conn_pool_test.go
index c7ceea35d..4e423bf37 100644
--- a/util/smux_conn_pool_test.go
+++ b/util/smux_conn_pool_test.go
@@ -541,7 +541,6 @@ func TestConcurrentGetConn(t *testing.T) {
for stream := range streamsCh {
pool.PutConnect(stream, true)
}
-
}
func TestConcurrentGetPutConn(t *testing.T) {
diff --git a/util/stat/statistic.go b/util/stat/statistic.go
index 586ed4ae3..205e1b3d8 100644
--- a/util/stat/statistic.go
+++ b/util/stat/statistic.go
@@ -94,13 +94,13 @@ func NewStatistic(dir, logModule string, logMaxSize int64, timeOutUs [MaxTimeout
dir = path.Join(dir, logModule)
fi, err := os.Stat(dir)
if err != nil {
- os.MkdirAll(dir, 0755)
+ os.MkdirAll(dir, 0o755)
} else {
if !fi.IsDir() {
return nil, errors.New(dir + " is not a directory")
}
}
- _ = os.Chmod(dir, 0755)
+ _ = os.Chmod(dir, 0o755)
logName := path.Join(dir, Stat_Module)
st := &Statistic{
logDir: dir,
@@ -228,7 +228,7 @@ func WriteStat() error {
}
logFileName := gSt.logBaseName + ".log"
- statFile, err := os.OpenFile(logFileName, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0666)
+ statFile, err := os.OpenFile(logFileName, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0o666)
if err != nil {
log.LogErrorf("OpenLogFile failed, logFileName: %s, err: %v\n", logFileName, err)
return fmt.Errorf("OpenLogFile failed, logFileName %s\n", logFileName)
diff --git a/util/ump/ump_async_log.go b/util/ump/ump_async_log.go
index 14a40b1c5..9996ad171 100644
--- a/util/ump/ump_async_log.go
+++ b/util/ump/ump_async_log.go
@@ -87,7 +87,7 @@ func (lw *LogWrite) initLogFp(sufixx string) (err error) {
lw.bf = bytes.NewBuffer([]byte{})
lw.jsonEncoder = json.NewEncoder(lw.bf)
lw.jsonEncoder.SetEscapeHTML(false)
- if lw.logFp, err = os.OpenFile(lw.logName, LogFileOpt, 0666); err != nil {
+ if lw.logFp, err = os.OpenFile(lw.logName, LogFileOpt, 0o666); err != nil {
return
}
if fi, err = lw.logFp.Stat(); err != nil {
@@ -114,7 +114,7 @@ func (lw *LogWrite) backGroundCheckFile() (err error) {
}
os.Rename(lw.logName, name)
- if lw.logFp, err = os.OpenFile(lw.logName, LogFileOpt, 0666); err != nil {
+ if lw.logFp, err = os.OpenFile(lw.logName, LogFileOpt, 0o666); err != nil {
lw.seq--
return
}
@@ -129,9 +129,7 @@ func (lw *LogWrite) backGroundCheckFile() (err error) {
func (lw *LogWrite) backGroundWrite(umpType string) {
for {
- var (
- body []byte
- )
+ var body []byte
obj := <-lw.logCh
switch umpType {
case FunctionTpType:
@@ -173,7 +171,7 @@ func initLogName(module, dataDir string) (err error) {
} else {
return fmt.Errorf("warnLogDir dir not config")
}
- if err = os.MkdirAll(UmpDataDir, 0755); err != nil {
+ if err = os.MkdirAll(UmpDataDir, 0o755); err != nil {
return
}
diff --git a/util/unboundedchan/ringbuffer.go b/util/unboundedchan/ringbuffer.go
index 19121a065..5d2c3f8f3 100644
--- a/util/unboundedchan/ringbuffer.go
+++ b/util/unboundedchan/ringbuffer.go
@@ -121,7 +121,6 @@ func (buf *RingBuffer) Len() uint32 {
} else {
return buf.wIndex + buf.size - buf.rIndex
}
-
}
func (buf *RingBuffer) Reset() {
diff --git a/util/unboundedchan/ringbuffer_test.go b/util/unboundedchan/ringbuffer_test.go
index 1c45a4736..92a2557cc 100644
--- a/util/unboundedchan/ringbuffer_test.go
+++ b/util/unboundedchan/ringbuffer_test.go
@@ -25,13 +25,12 @@ func TestReadEmptyRingBuffer(t *testing.T) {
if v != nil || err == nil {
t.Errorf("expected:(%v %v), got:(%v %v)", nil, errors.New("ringbuffer is empty"), v, err)
}
-
}
func TestWriteAndReadOne(t *testing.T) {
data := "value"
buffer := NewRingBuffer(10)
- //write
+ // write
buffer.Write(data)
if buffer.Len() != 1 {
t.Errorf("expected buf len:(%v), got:(%v)", 1, buffer.Len())
@@ -54,7 +53,7 @@ func TestWriteAndReadOne(t *testing.T) {
func TestBufferScaleUp(t *testing.T) {
buffer := NewRingBuffer(10)
- //write till buffer full
+ // write till buffer full
for i := 0; i < 9; i++ {
buffer.Write(i)
}
@@ -63,9 +62,9 @@ func TestBufferScaleUp(t *testing.T) {
t.Errorf("expected buffer size:(%v), got(%v", 10, buffer.size)
}
- //trigger scaling up
+ // trigger scaling up
buffer.Write(10)
- //scale buffer size up to double the size of the current buffer
+ // scale buffer size up to double the size of the current buffer
if buffer.size != 20 {
t.Errorf("expected buffer size:(%v), got(%v", 20, buffer.size)
}
diff --git a/util/unboundedchan/unbounded_chan.go b/util/unboundedchan/unbounded_chan.go
index 1eda0de7c..421eda5ec 100644
--- a/util/unboundedchan/unbounded_chan.go
+++ b/util/unboundedchan/unbounded_chan.go
@@ -18,8 +18,8 @@ import "sync/atomic"
type UnboundedChan struct {
bufCount int64
- In chan<- V //for user to write data into, BUT NOT TO READ FROM! In channel can be "close" by user
- Out <-chan V //for user to read data from, BUT NOT TO WRITE INTO!
+ In chan<- V // for user to write data into, BUT NOT TO READ FROM! In channel can be "close" by user
+ Out <-chan V // for user to read data from, BUT NOT TO WRITE INTO!
buffer *RingBuffer
}
@@ -62,13 +62,13 @@ func run(in, out chan V, uc *UnboundedChan) {
defer close(out)
LOOP:
for {
- //read data from in channel
+ // read data from in channel
val, ok := <-in
if !ok {
break LOOP
}
- //move data to buffer or out channel
+ // move data to buffer or out channel
if atomic.LoadInt64(&uc.bufCount) > 0 {
uc.feedBuffer(val)
} else {
@@ -76,16 +76,15 @@ LOOP:
case out <- val:
continue
default:
- //out channel is full
+ // out channel is full
uc.feedBuffer(val)
}
-
}
- //try feeding out channel with buffer data
+ // try feeding out channel with buffer data
for !uc.buffer.IsEmpty() {
select {
- //when out channel is full, data may still feed in channel
+ // when out channel is full, data may still feed in channel
case val, ok := <-in:
if !ok {
break LOOP
@@ -98,11 +97,10 @@ LOOP:
uc.resetBuffer()
}
}
-
}
}
- //no more in data, keep feeding out channel with buffer data until it's drained
+ // no more in data, keep feeding out channel with buffer data until it's drained
for !uc.buffer.IsEmpty() {
out <- uc.buffer.Pop()
atomic.AddInt64(&uc.bufCount, -1)
diff --git a/util/unboundedchan/unbounded_chan_test.go b/util/unboundedchan/unbounded_chan_test.go
index 5dc9d36fe..ca778a1d7 100644
--- a/util/unboundedchan/unbounded_chan_test.go
+++ b/util/unboundedchan/unbounded_chan_test.go
@@ -20,7 +20,7 @@ import (
)
func TestWriteReadUnboundedChan(t *testing.T) {
- //concurrent write and read unbounded chan
+ // concurrent write and read unbounded chan
UChan := NewUnboundedChan(10)
var wg sync.WaitGroup
for i := 0; i < 100; i++ {
diff --git a/util/unit.go b/util/unit.go
index 113e9c6bb..3a229f2f5 100644
--- a/util/unit.go
+++ b/util/unit.go
@@ -18,11 +18,11 @@ import (
"crypto/md5"
"encoding/hex"
"fmt"
- "github.com/cubefs/cubefs/depends/tiglabs/raft/util"
"net"
"regexp"
"strings"
+ "github.com/cubefs/cubefs/depends/tiglabs/raft/util"
"github.com/cubefs/cubefs/util/log"
)