chore(format): format all code with gofumpt

Signed-off-by: slasher <shenjie1@oppo.com>
This commit is contained in:
slasher 2024-01-12 10:23:26 +08:00 committed by 梁曟風
parent 3a13a6ebcb
commit 1d84f74acd
310 changed files with 2008 additions and 2347 deletions

View File

@ -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
}

View File

@ -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 {

View File

@ -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

View File

@ -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
}

View File

@ -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)

View File

@ -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

View File

@ -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)
}

View File

@ -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 {

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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"

View File

@ -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

View File

@ -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
}

View File

@ -19,7 +19,6 @@ import (
"time"
"github.com/cubefs/cubefs/depends/bazil.org/fuse"
"github.com/cubefs/cubefs/proto"
)

View File

@ -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

View File

@ -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 {

View File

@ -2,9 +2,10 @@ package fs
import (
"container/list"
"github.com/cubefs/cubefs/sdk/meta"
"sync"
"time"
"github.com/cubefs/cubefs/sdk/meta"
)
const (

View File

@ -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)

View File

@ -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 {

View File

@ -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()

View File

@ -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() {

View File

@ -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()

View File

@ -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)
}

View File

@ -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) {

View File

@ -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")

View File

@ -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

View File

@ -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())

View File

@ -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)

View File

@ -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 {

View File

@ -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 ")

View File

@ -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 {

View File

@ -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
}

View File

@ -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
}

View File

@ -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)

View File

@ -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"
)

View File

@ -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")
}

View File

@ -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 {

View File

@ -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

View File

@ -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
}

View File

@ -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) {

View File

@ -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
}

View File

@ -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

View File

@ -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")
}

View File

@ -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 {

View File

@ -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()

View File

@ -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)
}
}
},
}

View File

@ -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

View File

@ -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")
}

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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),

View File

@ -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),

View File

@ -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)
}

View File

@ -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{

View File

@ -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
}

View File

@ -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()

View File

@ -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
}

View File

@ -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) {

View File

@ -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, &param); 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, &param); 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, &param); 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, &param); 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, &param); err != nil {
sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()})
return

View File

@ -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,

View File

@ -16,9 +16,8 @@ package master
import (
"fmt"
"strconv"
"math"
"strconv"
"github.com/cubefs/cubefs/proto"
"github.com/cubefs/cubefs/util"

View File

@ -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

View File

@ -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) {

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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)
}

View File

@ -236,7 +236,6 @@ func (dpMap *DataPartitionMap) freeMemOccupiedByDataPartitions(partitions []*Dat
}(dp)
}
wg.Wait()
}
func (dpMap *DataPartitionMap) getDataPartitionsToBeChecked(loadFrequencyTime int64) (partitions []*DataPartition, startIndex uint64) {

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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) {

View File

@ -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]

View File

@ -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)

View File

@ -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

View File

@ -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"`

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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)

View File

@ -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

View File

@ -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)
}

View File

@ -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
}

View File

@ -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()))

View File

@ -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 {

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)
}

View File

@ -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
}

View File

@ -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")

View File

@ -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())

Some files were not shown because too many files have changed in this diff Show More