diff --git a/authnode/api_service.go b/authnode/api_service.go index dcba2fd80..2b2ffc6d7 100644 --- a/authnode/api_service.go +++ b/authnode/api_service.go @@ -29,10 +29,6 @@ import ( "github.com/cubefs/cubefs/util/log" ) -const ( - nodeType = "auth" -) - func (m *Server) getTicket(w http.ResponseWriter, r *http.Request) { var ( plaintext []byte @@ -43,7 +39,7 @@ func (m *Server) getTicket(w http.ResponseWriter, r *http.Request) { message string ) - if m.metaReady == false { + if !m.metaReady { log.LogWarnf("action[handlerWithInterceptor] leader meta has not ready") http.Error(w, m.leaderInfo.addr, http.StatusBadRequest) } @@ -79,7 +75,6 @@ func (m *Server) getTicket(w http.ResponseWriter, r *http.Request) { } sendOkReply(w, r, newSuccessHTTPAuthReply(message)) - return } func (m *Server) raftNodeOp(w http.ResponseWriter, r *http.Request) { @@ -145,21 +140,14 @@ func (m *Server) raftNodeOp(w http.ResponseWriter, r *http.Request) { } sendOkReply(w, r, newSuccessHTTPAuthReply(message)) - return } func (m *Server) handleAddRaftNode(raftNodeInfo *proto.AuthRaftNodeInfo) (err error) { - if err = m.cluster.addRaftNode(raftNodeInfo.ID, raftNodeInfo.Addr); err != nil { - return - } - return + return m.cluster.addRaftNode(raftNodeInfo.ID, raftNodeInfo.Addr) } func (m *Server) handleRemoveRaftNode(raftNodeInfo *proto.AuthRaftNodeInfo) (err error) { - if err = m.cluster.removeRaftNode(raftNodeInfo.ID, raftNodeInfo.Addr); err != nil { - return - } - return + return m.cluster.removeRaftNode(raftNodeInfo.ID, raftNodeInfo.Addr) } func genAuthRaftNodeOpResp(req *proto.APIAccessReq, ts int64, key []byte, msg string) (message string, err error) { @@ -289,28 +277,18 @@ func (m *Server) apiAccessEntry(w http.ResponseWriter, r *http.Request) { } sendOkReply(w, r, newSuccessHTTPAuthReply(message)) - return } func (m *Server) handleCreateKey(keyInfo *keystore.KeyInfo) (res *keystore.KeyInfo, err error) { - if res, err = m.cluster.CreateNewKey(keyInfo.ID, keyInfo); err != nil { - return - } - return + return m.cluster.CreateNewKey(keyInfo.ID, keyInfo) } func (m *Server) handleDeleteKey(keyInfo *keystore.KeyInfo) (res *keystore.KeyInfo, err error) { - if res, err = m.cluster.DeleteKey(keyInfo.ID); err != nil { - return - } - return + return m.cluster.DeleteKey(keyInfo.ID) } func (m *Server) handleGetKey(keyInfo *keystore.KeyInfo) (res *keystore.KeyInfo, err error) { - if res, err = m.getSecretKeyInfo(keyInfo.ID); err != nil { - return - } - return + return m.getSecretKeyInfo(keyInfo.ID) } func (m *Server) handleAddCaps(keyInfo *keystore.KeyInfo) (res *keystore.KeyInfo, err error) { @@ -437,7 +415,6 @@ func (m *Server) osCapsOp(w http.ResponseWriter, r *http.Request) { } sendOkReply(w, r, newSuccessHTTPAuthReply(message)) - return } func (m *Server) genTicket(key []byte, serviceID string, IP string, caps []byte) (ticket cryptoutil.Ticket) { @@ -680,7 +657,6 @@ func send(w http.ResponseWriter, r *http.Request, reply []byte) { return } log.LogInfof("URL[%v],remoteAddr[%v],response ok", r.URL, r.RemoteAddr) - return } func keyNotFound(name string) (err error) { @@ -700,5 +676,4 @@ func sendErrReply(w http.ResponseWriter, r *http.Request, HTTPAuthReply *proto.H if _, err = w.Write(reply); err != nil { log.LogErrorf("fail to write http reply[%s] len[%d].URL[%v],remoteAddr[%v] err:[%v]", string(reply), len(reply), r.URL, r.RemoteAddr, err) } - return } diff --git a/authnode/authnode_manager.go b/authnode/authnode_manager.go index 5c56bc441..1dc332e47 100644 --- a/authnode/authnode_manager.go +++ b/authnode/authnode_manager.go @@ -36,7 +36,7 @@ func (m *Server) handleLeaderChange(leader uint64) { log.LogWarnf("action[handleLeaderChange] change leader to [%v] ", m.leaderInfo.addr) m.authProxy = m.newAuthProxy() // TODO no lock? - if m.metaReady == false { + if !m.metaReady { if err := m.cluster.loadKeystore(); err != nil { panic(err) } @@ -73,5 +73,4 @@ func (m *Server) handlePeerChange(confChange *proto.ConfChange) (err error) { func (m *Server) handleApplySnapshot() { log.LogInfof("clusterID[%v] peerID:%v action[handleApplySnapshot]", m.clusterName, m.id) m.fsm.restore() - return } diff --git a/authnode/cluster.go b/authnode/cluster.go index 091118845..aa6da9e9c 100644 --- a/authnode/cluster.go +++ b/authnode/cluster.go @@ -57,8 +57,8 @@ func newCluster(name string, leaderInfo *LeaderInfo, fsm *KeystoreFsm, partition c.cfg = cfg c.fsm = fsm c.partition = partition - c.fsm.keystore = make(map[string]*keystore.KeyInfo, 0) - c.fsm.accessKeystore = make(map[string]*keystore.AccessKeyInfo, 0) + c.fsm.keystore = make(map[string]*keystore.KeyInfo) + c.fsm.accessKeystore = make(map[string]*keystore.AccessKeyInfo) return } @@ -66,10 +66,6 @@ func (c *Cluster) scheduleTask() { c.scheduleToCheckHeartbeat() } -func (c *Cluster) authAddr() (addr string) { - return c.leaderInfo.addr -} - func (c *Cluster) scheduleToCheckHeartbeat() { go func() { for { diff --git a/authnode/const.go b/authnode/const.go index af03b93de..4a14706b3 100644 --- a/authnode/const.go +++ b/authnode/const.go @@ -37,3 +37,9 @@ const ( akAcronym = "ak" akPrefix = keySeparator + akAcronym + keySeparator ) + +// TODO: unused +var ( + _ = opSyncGetKey + _ = opSyncGetCaps +) diff --git a/authnode/http_server.go b/authnode/http_server.go index 3beb77b68..1ef4879e6 100644 --- a/authnode/http_server.go +++ b/authnode/http_server.go @@ -54,7 +54,6 @@ func (m *Server) startHTTPService() { } } }() - return } func (m *Server) newAuthProxy() *AuthProxy { @@ -122,7 +121,6 @@ func (m *Server) handleFunctions() { http.Handle(proto.OSAddCaps, m.handlerWithInterceptor()) http.Handle(proto.OSDeleteCaps, m.handlerWithInterceptor()) http.Handle(proto.OSGetCaps, m.handlerWithInterceptor()) - return } func (m *Server) handlerWithInterceptor() http.Handler { diff --git a/authnode/keystore_cache_op.go b/authnode/keystore_cache_op.go index 363f5a6c5..c75d06188 100644 --- a/authnode/keystore_cache_op.go +++ b/authnode/keystore_cache_op.go @@ -30,7 +30,6 @@ func (mf *KeystoreFsm) DeleteKey(id string) { mf.ksMutex.Lock() defer mf.ksMutex.Unlock() delete(mf.keystore, id) - return } func (mf *KeystoreFsm) PutAKInfo(akInfo *keystore.AccessKeyInfo) { @@ -55,5 +54,4 @@ func (mf *KeystoreFsm) DeleteAKInfo(accessKey string) { mf.aksMutex.Lock() defer mf.aksMutex.Unlock() delete(mf.accessKeystore, accessKey) - return } diff --git a/authnode/keystore_fsm.go b/authnode/keystore_fsm.go index 5390e7b17..489e5c4de 100644 --- a/authnode/keystore_fsm.go +++ b/authnode/keystore_fsm.go @@ -37,8 +37,6 @@ type raftLeaderChangeHandler func(leader uint64) type raftPeerChangeHandler func(confChange *proto.ConfChange) (err error) -type raftCmdApplyHandler func(cmd *RaftCmd) (err error) - type raftApplySnapshotHandler func() // KeystoreFsm represents the finite state machine of a keystore diff --git a/authnode/keystore_fsm_op.go b/authnode/keystore_fsm_op.go index a20cc284d..54c9e1e08 100644 --- a/authnode/keystore_fsm_op.go +++ b/authnode/keystore_fsm_op.go @@ -118,7 +118,7 @@ func (c *Cluster) syncPutAccessKeyInfo(opType uint32, accessKeyInfo *keystore.Ac } func (c *Cluster) loadKeystore() (err error) { - ks := make(map[string]*keystore.KeyInfo, 0) + ks := make(map[string]*keystore.KeyInfo) log.LogInfof("action[loadKeystore]") result, err := c.fsm.store.SeekForPrefix([]byte(ksPrefix)) if err != nil { @@ -143,14 +143,8 @@ func (c *Cluster) loadKeystore() (err error) { return } -func (c *Cluster) clearKeystore() { - c.fsm.ksMutex.Lock() - defer c.fsm.ksMutex.Unlock() - c.fsm.keystore = nil -} - func (c *Cluster) loadAKstore() (err error) { - aks := make(map[string]*keystore.AccessKeyInfo, 0) + aks := make(map[string]*keystore.AccessKeyInfo) log.LogInfof("action[loadAccessKeystore]") result, err := c.fsm.store.SeekForPrefix([]byte(akPrefix)) if err != nil { @@ -175,12 +169,6 @@ func (c *Cluster) loadAKstore() (err error) { return } -func (c *Cluster) clearAKstore() { - c.fsm.aksMutex.Lock() - defer c.fsm.aksMutex.Unlock() - c.fsm.accessKeystore = nil -} - func (c *Cluster) addRaftNode(nodeID uint64, addr string) (err error) { peer := proto.Peer{ID: nodeID} _, err = c.partition.ChangeMember(proto.ConfAddNode, peer, []byte(addr)) diff --git a/authnode/server.go b/authnode/server.go index 419aaafd0..2c8b1aaac 100644 --- a/authnode/server.go +++ b/authnode/server.go @@ -212,7 +212,7 @@ func (m *Server) Start(cfg *config.Config) (err error) { return fmt.Errorf("action[Start] failed %v,err: auth root Key invalid=%s", proto.ErrInvalidCfg, AuthRootKey) } - if cfg.GetBool(EnableHTTPS) == true { + if cfg.GetBool(EnableHTTPS) { m.cluster.PKIKey.EnableHTTPS = true if m.cluster.PKIKey.AuthRootPublicKey, err = os.ReadFile("/app/server.crt"); err != nil { return fmt.Errorf("action[Start] failed,err[%v]", err) diff --git a/authtool/authtool.go b/authtool/authtool.go index de205bc67..b834ca0da 100644 --- a/authtool/authtool.go +++ b/authtool/authtool.go @@ -57,10 +57,7 @@ var action2PathMap = map[string]string{ OSGetCaps: proto.OSGetCaps, } -var ( - cflag string - flaginfo flagInfo -) +var flaginfo flagInfo type ticketFlag struct { key string @@ -364,7 +361,7 @@ func accessAuthServer() { panic(err) } } else { - if res, err = resp.KeyInfo.DumpJSONStr(resp.AuthIDKey); err != nil { + if _, err = resp.KeyInfo.DumpJSONStr(resp.AuthIDKey); err != nil { panic(err) } } diff --git a/autofs/cfs.go b/autofs/cfs.go index 13478a3a9..c0e4be648 100644 --- a/autofs/cfs.go +++ b/autofs/cfs.go @@ -175,7 +175,7 @@ func cfsList() error { for _, v := range mps { if v.Type == "fuse" || v.Type == "fuse.cubefs" { - fmt.Println(fmt.Sprintf("%s on %s type %s (%s)", v.Device, v.Path, v.Type, strings.Join(v.Opts, ","))) + fmt.Printf("%s on %s type %s (%s)\n", v.Device, v.Path, v.Type, strings.Join(v.Opts, ",")) } } diff --git a/autofs/cfs_test.go b/autofs/cfs_test.go index 1a6921c51..3c29fe400 100644 --- a/autofs/cfs_test.go +++ b/autofs/cfs_test.go @@ -10,15 +10,11 @@ import ( func TestCfsOption_Parse(t *testing.T) { c1 := cfsParse("tmp/mp", "subdir=sc1ch,volName=m1-project,owner=11111111,accessKey=ya0VE1xxxyyy===gY431,secretKey=5Clssf7831eXSmxxxyyyDQl2Is6J2x,masterAddr=10.0.0.1:22222,enablePosixACL") - if c1 == nil { - t.Error("parsed nil") - } - if c1.MountPoint != "tmp/mp" || c1.Subdir != "sc1ch" || c1.AccessKey != "ya0VE1xxxyyy===gY431" { t.Error("parsedErr, c1: ", fmt.Sprintf("%+v", c1)) } - log.Println(fmt.Sprintf("option: %+v", c1)) + log.Printf("option: %+v", c1) } func TestCfsOption_ConvertToCliOptions(t *testing.T) { diff --git a/autofs/main.go b/autofs/main.go index 1cd3f3f9c..f4ccd9740 100644 --- a/autofs/main.go +++ b/autofs/main.go @@ -25,7 +25,7 @@ var rootCmd = &cobra.Command{ // version v, _ := c.Flags().GetBool("version") if v { - fmt.Println(fmt.Sprintf("Version: %s, BuildDate: %s", buildVersion, buildDate)) + fmt.Printf("Version: %s, BuildDate: %s\n", buildVersion, buildDate) return } diff --git a/blockcache/cmd.go b/blockcache/cmd.go index b68bae24c..c704a4384 100644 --- a/blockcache/cmd.go +++ b/blockcache/cmd.go @@ -40,9 +40,6 @@ import ( "github.com/jacobsa/daemonize" ) -//TODO: remove this later. -//go:generate golangci-lint run --issues-exit-code=1 -D errcheck -E bodyclose ./... - const ( ConfigKeyLogDir = "logDir" ConfigKeyLogLevel = "logLevel" diff --git a/cli/cli.go b/cli/cli.go index c50d2fec3..56e1e3ff6 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -24,9 +24,6 @@ import ( "github.com/spf13/cobra" ) -//TODO: remove this later. -//go:generate golangci-lint run --issues-exit-code=1 -D errcheck -E bodyclose ./... - func runCLI() (err error) { var cfg *cmd.Config if cfg, err = cmd.LoadConfig(); err != nil { diff --git a/client/fs/dir.go b/client/fs/dir.go index f6aa5862e..f2115d683 100644 --- a/client/fs/dir.go +++ b/client/fs/dir.go @@ -49,7 +49,7 @@ type DirContexts struct { func NewDirContexts() (dctx *DirContexts) { dctx = &DirContexts{} - dctx.dirCtx = make(map[fuse.HandleID]*DirContext, 0) + dctx.dirCtx = make(map[fuse.HandleID]*DirContext) return } @@ -510,7 +510,6 @@ func (d *Dir) ReadDirAll(ctx context.Context) ([]fuse.Dirent, error) { } batchNr := uint64(len(batches)) if batchNr == 0 || (from != "" && batchNr == 1) { - noMore = true break } else if batchNr < DefaultReaddirLimit { noMore = true diff --git a/client/fs/summarycache.go b/client/fs/summarycache.go index 51d212712..265e8f6ac 100644 --- a/client/fs/summarycache.go +++ b/client/fs/summarycache.go @@ -126,19 +126,13 @@ func (sc *SummaryCache) evict(foreground bool) { func (sc *SummaryCache) backgroundEviction() { t := time.NewTicker(SummaryBgEvictionInterval) defer t.Stop() - for { - select { - case <-t.C: - sc.Lock() - sc.evict(false) - sc.Unlock() - } + for range t.C { + sc.Lock() + sc.evict(false) + sc.Unlock() } } func cacheExpired(info *summaryCacheElement) bool { - if time.Now().UnixNano() > info.expiration { - return true - } - return false + return time.Now().UnixNano() > info.expiration } diff --git a/client/fs/super.go b/client/fs/super.go index 66c3cb9c5..96b89bb48 100644 --- a/client/fs/super.go +++ b/client/fs/super.go @@ -88,9 +88,8 @@ type Super struct { ebsc *blobstore.BlobStoreClient sc *SummaryCache - taskPool []common.TaskPool - closeC chan struct{} - enableVerRead bool + taskPool []common.TaskPool + closeC chan struct{} } // Functions that Super needs to implement @@ -290,9 +289,8 @@ func NewSuper(opt *proto.MountOptions) (s *Super, err error) { func (s *Super) scheduleFlush() { t := time.NewTicker(2 * time.Second) defer t.Stop() - for { - select { - case <-t.C: + for range t.C { + { ctx := context.Background() s.fslock.Lock() for ino, node := range s.nodeCache { @@ -338,8 +336,8 @@ func (s *Super) Node(ino, pino uint64, mode uint32) (fs.Node, error) { // the node is not evict. So we create a streamer for it, // and streamer's refcnt is 0. file := node.(*File) - file.Open(nil, nil, nil) - file.Release(nil, nil) + file.Open(context.TODO(), nil, nil) + file.Release(context.TODO(), nil) } s.fslock.Lock() s.nodeCache[ino] = node @@ -398,10 +396,6 @@ func (s *Super) SetRate(w http.ResponseWriter, r *http.Request) { } } -func (s *Super) exporterKey(act string) string { - return fmt.Sprintf("%v_fuseclient_%v", s.cluster, act) -} - func (s *Super) umpKey(act string) string { return fmt.Sprintf("%v_fuseclient_%v", s.cluster, act) } @@ -456,11 +450,11 @@ func (s *Super) SetSuspend(w http.ResponseWriter, r *http.Request) { // wait msg := <-s.suspendCh - switch msg.(type) { + switch msgVal := msg.(type) { case error: - err = msg.(error) + err = msgVal case string: - ret = msg.(string) + ret = msgVal default: err = fmt.Errorf("Unknown return type: %v", msg) } diff --git a/client/fuse.go b/client/fuse.go index bb2cb356d..a3be78f35 100644 --- a/client/fuse.go +++ b/client/fuse.go @@ -70,12 +70,12 @@ const ( ) const ( - LoggerDir = "client" + // LoggerDir = "client" LoggerPrefix = "client" LoggerOutput = "output.log" - ModuleName = "fuseclient" - ConfigKeyExporterPort = "exporterKey" + ModuleName = "fuseclient" + // ConfigKeyExporterPort = "exporterKey" ControlCommandSetRate = "/rate/set" ControlCommandGetRate = "/rate/get" diff --git a/console/assets_generate_test.go b/console/assets_generate_test.go index 6029e2e9f..6cadb5ea1 100644 --- a/console/assets_generate_test.go +++ b/console/assets_generate_test.go @@ -9,7 +9,7 @@ import ( func TestMakeHtml2GoBin(t *testing.T) { // when you need rebuild html . please open it - return + _ = getAssets /* assets := getAssets() diff --git a/console/cutil/handler.go b/console/cutil/handler.go index 23d1171ed..d9a13d713 100644 --- a/console/cutil/handler.go +++ b/console/cutil/handler.go @@ -128,7 +128,7 @@ func (h *graphqlProxyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) } UserID := ui.User_id - header.Set(proto.UserKey, UserID) + header.Set(string(proto.UserKey), UserID) rep, err := h.client.Proxy(r.Context(), r, header) if err != nil { @@ -273,26 +273,6 @@ func (h *httpHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { runner.Stop() } -func parseResponseNames(r *http.Request) ([]string, error) { - var params httpPostBody - if err := json.NewDecoder(r.Body).Decode(¶ms); err != nil { - return nil, err - } - - query, err := graphql.Parse(params.Query, params.Variables) - if err != nil { - return nil, err - } - - list := make([]string, 0) - - for _, s := range query.Selections { - list = append(list, s.Name) - } - - return list, nil -} - func IQLFun(writer http.ResponseWriter, request *http.Request) { writer.Write([]byte(` diff --git a/console/server.go b/console/server.go index 7a33effad..90ae8472f 100644 --- a/console/server.go +++ b/console/server.go @@ -120,7 +120,7 @@ func (c *ConsoleNode) loadConfig(cfg *config.Config) (err error) { if len(c.listen) == 0 { c.listen = "80" } - if match := regexp.MustCompile("^(\\d)+$").MatchString(c.listen); !match { + if match := regexp.MustCompile(`^(\d)+$`).MatchString(c.listen); !match { return fmt.Errorf("invalid listen configuration:[%s]", c.listen) } log.LogInfof("console loadConfig: setup config: %v(%v)", proto.ListenPort, c.listen) diff --git a/console/server_test.go b/console/server_test.go index 4bb522237..0c9d403e2 100644 --- a/console/server_test.go +++ b/console/server_test.go @@ -8,8 +8,8 @@ import ( ) func TestServer(t *testing.T) { - return - + _ = graphErr{} + _ = graphResponse{} // if _, err := log.InitLog("/tmp", "console", log.DebugLevel, nil); err != nil { // panic(err) // } diff --git a/console/service/monitor.go b/console/service/monitor.go index 10ae1b1a5..4ea362a36 100644 --- a/console/service/monitor.go +++ b/console/service/monitor.go @@ -32,7 +32,8 @@ func NewMonitorService(addr, app, cluster, dashboardAddr string) *MonitorService func (fs *MonitorService) empty(ctx context.Context, args struct { Empty bool -}) bool { +}, +) bool { return args.Empty } @@ -60,8 +61,9 @@ func (ms *MonitorService) RangeQuery(ctx context.Context, args struct { if err != nil { return "", err } + defer resp.Body.Close() - b, err := io.ReadAll(resp.Body) + b, _ := io.ReadAll(resp.Body) return string(b), nil } @@ -109,8 +111,9 @@ func (ms *MonitorService) Query(ctx context.Context, args struct { if err != nil { return "", err } + defer resp.Body.Close() - b, err := io.ReadAll(resp.Body) + b, _ := io.ReadAll(resp.Body) return string(b), nil } @@ -150,8 +153,9 @@ func (ms *MonitorService) FuseClientList(ctx context.Context, args struct{}) ([] if err != nil { return nil, err } + defer resp.Body.Close() - b, err := io.ReadAll(resp.Body) + b, _ := io.ReadAll(resp.Body) result := struct { Data struct { diff --git a/cubefs.go b/cubefs.go new file mode 100644 index 000000000..f6e1c76b8 --- /dev/null +++ b/cubefs.go @@ -0,0 +1,17 @@ +// Copyright 2024 The CubeFS Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +// implied. See the License for the specific language governing +// permissions and limitations under the License. + +package cubefs + +//go:generate golangci-lint run --issues-exit-code=1 --timeout 10m --skip-dirs depends --max-same-issues 1000 -D errcheck -E bodyclose ./... diff --git a/datanode/const.go b/datanode/const.go index bab5d08e5..d4a3c4d9c 100644 --- a/datanode/const.go +++ b/datanode/const.go @@ -103,3 +103,11 @@ const ( MaxFullSyncTinyDeleteTime = 3600 * 24 MinTinyExtentDeleteRecordSyncSize = 4 * 1024 * 1024 ) + +// TODO: to remove unused by golangci +var ( + _ = (*DataPartition).canRemoveSelf + _ = (*DataPartition).getMemberExtentIDAndPartitionSize + _ = (*DataNode).detachDataPartition + _ = (*DataNode).loadDataPartition +) diff --git a/datanode/data_partition_repair_test.go b/datanode/data_partition_repair_test.go old mode 100755 new mode 100644 index 0e604dc46..47df53a4c --- a/datanode/data_partition_repair_test.go +++ b/datanode/data_partition_repair_test.go @@ -22,13 +22,13 @@ import ( type repairWorker struct { proto.Packet - followersAddrs []string - followerPackets []*repl.FollowerPacket - IsReleased int32 // TODO what is released? - Object interface{} - TpObject *exporter.TimePointCount - NeedReply bool - OrgBuffer []byte + // followersAddrs []string + // followerPackets []*repl.FollowerPacket + IsReleased int32 // TODO what is released? + Object interface{} + TpObject *exporter.TimePointCount + NeedReply bool + OrgBuffer []byte // used locally shallDegrade bool @@ -166,8 +166,8 @@ func (p *repairWorker) WriteToConn(c net.Conn) (err error) { } func (p *repairWorker) ReadFromConnWithVer(c net.Conn, timeoutSec int) (err error) { - select { - case pr := <-p.packChannel: + pr := <-p.packChannel + { p.CRC = pr.GetCRC() p.Data = make([]byte, len(pr.GetData())) copy(p.Data, pr.GetData()) @@ -285,7 +285,6 @@ func extentReloadCheckNormalCrc(t *testing.T, s *storage.ExtentStore, id uint64, assert.True(t, err == nil) extCrc := e.GetCrc(0) assert.True(t, crc == extCrc) - return } func extentStoreSnapshotRwTest(t *testing.T, s *storage.ExtentStore, id uint64, crc uint32, data []byte) { @@ -377,7 +376,7 @@ func mockInitWorker(t *testing.T, role string) *repairWorker { return new(net.TCPConn), nil } worker.dp.dataNode.putRepairConnFunc = func(con net.Conn, force bool) { - return + _ = struct{}{} } return worker } @@ -399,8 +398,6 @@ func workerInit(t *testing.T, id uint64, data []byte, crc uint32) { recvWorker = mockInitWorker(t, "receiver") sendWorker.dstWorker = recvWorker recvWorker.dstWorker = sendWorker - - return } func senderRepairWorker(t *testing.T, exitCh chan struct{}) { diff --git a/datanode/disk.go b/datanode/disk.go index f0cc990de..39639967c 100644 --- a/datanode/disk.go +++ b/datanode/disk.go @@ -99,7 +99,8 @@ const ( type PartitionVisitor func(dp *DataPartition) func NewDisk(path string, reservedSpace, diskRdonlySpace uint64, maxErrCnt int, space *SpaceManager, - diskEnableReadRepairExtentLimit bool) (d *Disk, err error) { + diskEnableReadRepairExtentLimit bool, +) (d *Disk, err error) { d = new(Disk) d.Path = path d.ReservedSpace = reservedSpace @@ -127,7 +128,7 @@ func NewDisk(path string, reservedSpace, diskRdonlySpace uint64, maxErrCnt int, } d.startScheduleToUpdateSpaceInfo() - d.limitFactor = make(map[uint32]*rate.Limiter, 0) + d.limitFactor = make(map[uint32]*rate.Limiter) d.limitFactor[proto.FlowReadType] = rate.NewLimiter(rate.Limit(proto.QosDefaultDiskMaxFLowLimit), proto.QosDefaultBurst) d.limitFactor[proto.FlowWriteType] = rate.NewLimiter(rate.Limit(proto.QosDefaultDiskMaxFLowLimit), proto.QosDefaultBurst) d.limitFactor[proto.IopsReadType] = rate.NewLimiter(rate.Limit(proto.QosDefaultDiskMaxIoLimit), defaultIOLimitBurst) @@ -135,7 +136,7 @@ func NewDisk(path string, reservedSpace, diskRdonlySpace uint64, maxErrCnt int, d.limitRead = newIOLimiter(space.dataNode.diskReadFlow, space.dataNode.diskReadIocc) d.limitWrite = newIOLimiter(space.dataNode.diskWriteFlow, space.dataNode.diskWriteIocc) - d.DiskErrPartitionSet = make(map[uint64]struct{}, 0) + d.DiskErrPartitionSet = make(map[uint64]struct{}) err = d.initDecommissionStatus() if err != nil { diff --git a/datanode/nodeinfo.go b/datanode/nodeinfo.go index 43b6d52ef..29ff96b8d 100644 --- a/datanode/nodeinfo.go +++ b/datanode/nodeinfo.go @@ -5,11 +5,9 @@ import ( "time" "github.com/cubefs/cubefs/util/log" - "golang.org/x/time/rate" ) const ( - defaultMarkDeleteLimitRate = rate.Inf defaultMarkDeleteLimitBurst = 512 defaultIOLimitBurst = 512 UpdateNodeInfoTicket = 1 * time.Minute diff --git a/datanode/partition.go b/datanode/partition.go index 9911f570b..42cae1144 100644 --- a/datanode/partition.go +++ b/datanode/partition.go @@ -129,9 +129,9 @@ type DataPartition struct { persistMetaMutex sync.RWMutex // snapshot + // verSeqPrepare uint64 + // verSeqCommitStatus int8 verSeq uint64 - verSeqPrepare uint64 - verSeqCommitStatus int8 volVersionInfoList *proto.VolVersionInfoList decommissionRepairProgress float64 // record repair progress for decommission datapartition stopRecover bool @@ -736,7 +736,6 @@ func (dp *DataPartition) checkIsDiskError(err error, rwFlag uint8) { // must after change disk.status dp.statusUpdate() - return } func newRaftApplyError(err error) error { diff --git a/datanode/server.go b/datanode/server.go index 235accd2e..fdbf5ed94 100644 --- a/datanode/server.go +++ b/datanode/server.go @@ -52,8 +52,8 @@ var ( ErrNewSpaceManagerFailed = errors.New("Creater new space manager failed") ErrGetMasterDatanodeInfoFailed = errors.New("Failed to get datanode info from master") - LocalIP, serverPort string - gConnPool = util.NewConnectPool() + LocalIP string + gConnPool = util.NewConnectPool() // MasterClient = masterSDK.NewMasterClient(nil, false) MasterClient *masterSDK.MasterCLientWithResolver ) @@ -133,7 +133,6 @@ type DataNode struct { port string zoneName string clusterID string - localIP string bindIp bool localServerAddr string nodeID uint64 @@ -144,6 +143,7 @@ type DataNode struct { tickInterval int raftRecvBufSize int startTime int64 + // localIP string tcpListener net.Listener stopC chan bool @@ -174,12 +174,12 @@ type DataNode struct { diskWriteIops int diskWriteFlow int dpMaxRepairErrCnt uint64 - dpRepairTimeOut uint64 clusterUuid string clusterUuidEnable bool serviceIDKey string cpuUtil atomicutil.Float64 cpuSamplerDone chan struct{} + // dpRepairTimeOut uint64 diskUnavailablePartitionErrorCount uint64 // disk status becomes unavailable when disk error partition count reaches this value } @@ -189,7 +189,7 @@ type verOp2Phase struct { verPrepare uint64 status uint32 step uint32 - op uint8 + // op uint8 sync.Mutex } @@ -305,7 +305,6 @@ func (s *DataNode) parseConfig(cfg *config.Config) (err error) { LocalIP = cfg.GetString(ConfigKeyLocalIP) port = cfg.GetString(proto.ListenPort) s.bindIp = cfg.GetBool(proto.BindIpKey) - serverPort = port if regexpPort, err = regexp.Compile(`^(\d)+$`); err != nil { return fmt.Errorf("Err:no port") } diff --git a/datanode/server_handler.go b/datanode/server_handler.go index e781f08b3..2664e7af0 100644 --- a/datanode/server_handler.go +++ b/datanode/server_handler.go @@ -727,8 +727,6 @@ func (s *DataNode) loadDataPartition(w http.ResponseWriter, r *http.Request) { for _, fileInfo := range fileInfoList { filename := fileInfo.Name() if !disk.isPartitionDir(filename) { - if disk.isExpiredPartitionDir(filename) { - } continue } diff --git a/datanode/space_manager.go b/datanode/space_manager.go index 42f62b5ca..f450213ef 100644 --- a/datanode/space_manager.go +++ b/datanode/space_manager.go @@ -31,22 +31,20 @@ import ( // SpaceManager manages the disk space. type SpaceManager struct { - clusterID string - disks map[string]*Disk - partitions map[uint64]*DataPartition - raftStore raftstore.RaftStore - nodeID uint64 - diskMutex sync.RWMutex - partitionMutex sync.RWMutex - stats *Stats - stopC chan bool - selectedIndex int // TODO what is selected index - diskList []string - dataNode *DataNode - createPartitionMutex sync.RWMutex - diskUtils map[string]*atomicutil.Float64 - samplerDone chan struct{} - allDisksLoaded bool + clusterID string + disks map[string]*Disk + partitions map[uint64]*DataPartition + raftStore raftstore.RaftStore + nodeID uint64 + diskMutex sync.RWMutex + partitionMutex sync.RWMutex + stats *Stats + stopC chan bool + diskList []string + dataNode *DataNode + diskUtils map[string]*atomicutil.Float64 + samplerDone chan struct{} + allDisksLoaded bool } const diskSampleDuration = 1 * time.Second @@ -227,7 +225,8 @@ func (manager *SpaceManager) Stats() *Stats { } func (manager *SpaceManager) LoadDisk(path string, reservedSpace, diskRdonlySpace uint64, maxErrCnt int, - diskEnableReadRepairExtentLimit bool) (err error) { + diskEnableReadRepairExtentLimit bool, +) (err error) { var ( disk *Disk visitor PartitionVisitor @@ -503,11 +502,3 @@ func (s *DataNode) buildHeartBeatResponse(response *proto.DataNodeHeartbeatRespo response.DiskStats = append(response.DiskStats, bds) } } - -func (manager *SpaceManager) getPartitionIds() []uint64 { - res := make([]uint64, 0) - for id := range manager.partitions { - res = append(res, id) - } - return res -} diff --git a/datanode/stat.go b/datanode/stat.go index 36eee5b0f..a35df0687 100644 --- a/datanode/stat.go +++ b/datanode/stat.go @@ -22,11 +22,6 @@ import ( // Stats defines various metrics that will be collected during the execution. type Stats struct { - inDataSize uint64 - outDataSize uint64 - inFlow uint64 - outFlow uint64 - Zone string ConnectionCnt int64 ClusterID string @@ -71,7 +66,8 @@ func (s *Stats) GetConnectionCount() int64 { func (s *Stats) updateMetrics( total, used, available, createdPartitionWeights, remainWeightsForCreatePartition, - maxWeightsForCreatePartition, dataPartitionCnt uint64) { + maxWeightsForCreatePartition, dataPartitionCnt uint64, +) { s.Lock() defer s.Unlock() diff --git a/datanode/wrap_operator.go b/datanode/wrap_operator.go index 88fdc7677..3698d2ac2 100644 --- a/datanode/wrap_operator.go +++ b/datanode/wrap_operator.go @@ -954,6 +954,7 @@ func (s *DataNode) handleExtentRepairReadPacket(p *repl.Packet, connect net.Conn partition := p.Object.(*DataPartition) if !partition.disk.RequireReadExtentToken(partition.partitionID) { err = storage.NoDiskReadRepairExtentTokenError + log.LogWarn("check the source code cos i don't understand the unuesd error,", err) log.LogDebugf("dp(%v) disk(%v) extent(%v) wait for read extent token", p.PartitionID, partition.disk.Path, p.ExtentID) return @@ -1047,10 +1048,6 @@ func writeEmptyPacketOnExtentRepairRead(reply repl.PacketInterface, newOffset, c return } -func (s *DataNode) attachAvaliSizeOnExtentRepairRead(reply *repl.Packet, avaliSize uint64) { - binary.BigEndian.PutUint64(reply.Arg[9:17], avaliSize) -} - func (s *DataNode) NormalSnapshotExtentRepairRead(request *repl.Packet, connect net.Conn) { replyFunc := func() repl.PacketInterface { reply := repl.NewNormalExtentWithHoleStreamReadResponsePacket(request.ReqID, request.PartitionID, request.ExtentID) @@ -1082,7 +1079,6 @@ func (s *DataNode) tinyExtentRepairRead(request *repl.Packet, connect net.Conn) return reply } s.ExtentWithHoleRepairRead(request, connect, replyFunc) - return } // Handle tinyExtentRepairRead packet. diff --git a/deploy/cmd/firewall.go b/deploy/cmd/firewall.go index 8a7399803..6ab894876 100644 --- a/deploy/cmd/firewall.go +++ b/deploy/cmd/firewall.go @@ -1,7 +1,6 @@ package cmd import ( - "fmt" "log" "os/exec" ) @@ -61,12 +60,12 @@ func stopFirewall(nodeUser, node string) { log.Println(cmd) } -func checkPortStatus(nodeUser, node string, port string) (string, error) { - cmd := exec.Command("ssh", nodeUser+"@"+node, "firewall-cmd --list-all | grep "+port) - fmt.Println(cmd) - _, err := cmd.Output() - if err != nil { - return fmt.Sprintf("Port %s %s is closed", node, port), err - } - return fmt.Sprintf("Port %s is open", port), nil -} +// func checkPortStatus(nodeUser, node string, port string) (string, error) { +// cmd := exec.Command("ssh", nodeUser+"@"+node, "firewall-cmd --list-all | grep "+port) +// fmt.Println(cmd) +// _, err := cmd.Output() +// if err != nil { +// return fmt.Sprintf("Port %s %s is closed", node, port), err +// } +// return fmt.Sprintf("Port %s is open", port), nil +// } diff --git a/deploy/cmd/transform.go b/deploy/cmd/transform.go index b6f399ecf..dcbb07f1d 100644 --- a/deploy/cmd/transform.go +++ b/deploy/cmd/transform.go @@ -46,6 +46,9 @@ func transferDirectoryToRemote(localFilePath string, remoteFilePath string, remo return nil } +// TODO: to remove unused by golangci +var _ = copyFolder + func copyFolder(sourcePath, destinationPath string) error { err := filepath.Walk(sourcePath, func(path string, info os.FileInfo, err error) error { if err != nil { diff --git a/docker/script/run_format.sh b/docker/script/run_format.sh index 77458ac38..1b0a00735 100755 --- a/docker/script/run_format.sh +++ b/docker/script/run_format.sh @@ -15,12 +15,16 @@ popd export PATH=$PATH:/go/bin -for subdir in proto blockcache storage cli lcnode -do - pushd ${CurrentPath}/../../${subdir} - go generate ./... - if [[ $? -ne 0 ]]; then - exit 1 - fi - popd -done +golintFile=golint.diff +pushd ${CurrentPath}/../.. +go generate . > ${golintFile} +cat ${golintFile} +if [[ $? -ne 0 ]]; then + exit 1 +fi +if [ "$(cat ${golintFile}|wc -l)" -gt 0 ]; then + popd + exit 1 +fi +rm -f ${golintFile} +popd diff --git a/fdstore/fdstore.go b/fdstore/fdstore.go index 1a80ff290..aad129e27 100644 --- a/fdstore/fdstore.go +++ b/fdstore/fdstore.go @@ -126,7 +126,7 @@ func SendFuseFdToNewClient(udsListener net.Listener, file *os.File) (err error) if file == nil { err = fmt.Errorf("no file is received") - fmt.Fprintf(os.Stderr, err.Error()) + fmt.Fprintln(os.Stderr, err.Error()) return } else { if err = util.SendFd(socket, file.Name(), file.Fd()); err != nil { @@ -176,11 +176,6 @@ func SendSuspendRequest(port string, udsListener net.Listener) (err error) { return nil } -func WaitSuspendFinish(ch chan error) error { - err := <-ch - return err -} - func doSuspend(port string) error { var fud *os.File @@ -319,7 +314,6 @@ func doDump(filePathes string) { ) rsize, err = handleListFile.Read(data) if rsize == 0 || err == io.EOF { - err = nil break } @@ -357,7 +351,7 @@ func main() { flag.Parse() if *optVersion { - fmt.Printf(proto.DumpVersion("fdstore")) + fmt.Println(proto.DumpVersion("fdstore")) os.Exit(0) } @@ -385,6 +379,5 @@ func main() { os.Exit(-1) } - fmt.Printf("Done Successfully\n") - return + fmt.Println("Done Successfully") } diff --git a/fsck/cmd/clean.go b/fsck/cmd/clean.go index c8fc8e6e5..5674656f2 100644 --- a/fsck/cmd/clean.go +++ b/fsck/cmd/clean.go @@ -228,36 +228,6 @@ func doEvictInode(inode *Inode) error { return nil } -func doUnlinkInode(inode *Inode) error { - /* - * Do clean inode with the following exceptions: - * 1. nlink == 0, might be a temorary inode - * 2. size == 0 && ctime is close to current time, might be in the process of file creation - */ - // if inode.NLink == 0 || - // (inode.Size == 0 && - // time.Unix(inode.CreateTime, 0).Add(24*time.Hour).After(time.Now())) { - // return nil - // } - // - // err := gMetaWrapper.Unlink_ll(inode.Inode) - // if err != nil { - // if err != syscall.ENOENT { - // return err - // } - // err = nil - // } - // - // err = gMetaWrapper.Evict(inode.Inode) - // if err != nil { - // if err != syscall.ENOENT { - // return err - // } - // } - - return nil -} - func cleanDentries() error { // filePath := fmt.Sprintf("_export_%s/%s", VolName, obsoleteDentryDumpFileName) // TODO: send request to meta node directly with pino, name and ino. diff --git a/fsck/cmd/common.go b/fsck/cmd/common.go index f6ceb7723..2f1a5f755 100644 --- a/fsck/cmd/common.go +++ b/fsck/cmd/common.go @@ -30,7 +30,6 @@ var ( var ( inodeDumpFileName string = "inode.dump" dentryDumpFileName string = "dentry.dump" - inodeUpdateDumpFileName string = "inode.dump.update" obsoleteInodeDumpFileName string = "inode.dump.obsolete" obsoleteDentryDumpFileName string = "dentry.dump.obsolete" pathDumpFileName string = "path.dump" diff --git a/fsck/cmd/getInfo.go b/fsck/cmd/getInfo.go index 235c122a1..bc3dc03a5 100644 --- a/fsck/cmd/getInfo.go +++ b/fsck/cmd/getInfo.go @@ -38,12 +38,6 @@ const ( MaxFollowPathTaskNum = 120 ) -type Summary struct { - files uint64 - dirs uint64 - bytes uint64 -} - func newInfoCmd() *cobra.Command { c := &cobra.Command{ Use: "get", diff --git a/fsck/cmd/root.go b/fsck/cmd/root.go index ae0cecc88..af00328a2 100644 --- a/fsck/cmd/root.go +++ b/fsck/cmd/root.go @@ -32,7 +32,7 @@ func NewRootCmd() *cobra.Command { Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { if optShowVersion { - _, _ = fmt.Fprintf(os.Stdout, proto.DumpVersion("FSCK")) + fmt.Fprintln(os.Stdout, proto.DumpVersion("FSCK")) return } }, diff --git a/lcnode/server.go b/lcnode/server.go index d79253603..3462d19f2 100644 --- a/lcnode/server.go +++ b/lcnode/server.go @@ -35,9 +35,6 @@ import ( "golang.org/x/time/rate" ) -//TODO: remove this later. -//go:generate golangci-lint run --issues-exit-code=1 -D errcheck -E bodyclose ./... - type LcNode struct { listen string localServerAddr string diff --git a/libsdk/libsdk.go b/libsdk/libsdk.go index ccb185c23..1f630862d 100644 --- a/libsdk/libsdk.go +++ b/libsdk/libsdk.go @@ -130,7 +130,6 @@ var ( statusEISDIR = errorToStatus(syscall.EISDIR) statusENOSPC = errorToStatus(syscall.ENOSPC) ) -var once sync.Once func init() { gClientManager = &clientManager{ @@ -154,10 +153,6 @@ type clientManager struct { mu sync.RWMutex } -type pushConfig struct { - PushAddr string `json:"pushAddr"` -} - func newClient() *client { id := atomic.AddInt64(&gClientManager.nextClientID, 1) c := &client{ @@ -851,7 +846,7 @@ func cfs_lsdir(id C.int64_t, fd C.int, direntsInfo []C.struct_cfs_dirent_info, c } dirp := f.dirp - inodeIDS := make([]uint64, count, count) + inodeIDS := make([]uint64, count) inodeMap := make(map[uint64]C.int) for dirp.pos < len(dirp.dirents) && n < count { inodeIDS[n] = dirp.dirents[dirp.pos].Inode diff --git a/master/admin_task_manager.go b/master/admin_task_manager.go index b553528eb..c9afa39b4 100644 --- a/master/admin_task_manager.go +++ b/master/admin_task_manager.go @@ -84,7 +84,6 @@ func (sender *AdminTaskManager) doDeleteTasks() { for _, t := range delTasks { sender.DelTask(t) } - return } func (sender *AdminTaskManager) getToBeDeletedTasks() (delTasks []*proto.AdminTask) { @@ -260,14 +259,14 @@ func (sender *AdminTaskManager) getToDoTasks() (tasks []*proto.AdminTask) { // send heartbeat task first for _, t := range sender.TaskMap { - if t.IsHeartbeatTask() && t.CheckTaskNeedSend() == true { + if t.IsHeartbeatTask() && t.CheckTaskNeedSend() { tasks = append(tasks, t) t.SendTime = time.Now().Unix() } } // send urgent task immediately for _, t := range sender.TaskMap { - if t.IsUrgentTask() && t.CheckTaskNeedSend() == true { + if t.IsUrgentTask() && t.CheckTaskNeedSend() { tasks = append(tasks, t) t.SendTime = time.Now().Unix() } diff --git a/master/api_args_parse.go b/master/api_args_parse.go index 28df18782..cd07a4c2d 100644 --- a/master/api_args_parse.go +++ b/master/api_args_parse.go @@ -211,18 +211,6 @@ func parseAndExtractNodeAddr(r *http.Request) (nodeAddr string, err error) { return extractNodeAddr(r) } -func parseRequestToDecommissionNode(r *http.Request) (nodeAddr, diskPath string, err error) { - if err = r.ParseForm(); err != nil { - return - } - nodeAddr, err = extractNodeAddr(r) - if err != nil { - return - } - diskPath, err = extractDiskPath(r) - return -} - func parseRequestToGetTaskResponse(r *http.Request) (tr *proto.AdminTask, err error) { var body []byte if err = r.ParseForm(); err != nil { @@ -346,7 +334,7 @@ func extractUint64WithDefault(r *http.Request, key string, def uint64) (val uint return def, nil } - if val, err = strconv.ParseUint(str, 10, 64); err != nil || val < 0 { + if val, err = strconv.ParseUint(str, 10, 64); err != nil { return 0, fmt.Errorf("parse [%s] is not valid uint [%d], err %v", key, val, err) } @@ -783,7 +771,7 @@ func parseRequestToCreateVol(r *http.Request, req *createVolReq) (err error) { if err != nil { return } - if followerExist && followerRead == false && proto.IsHot(req.volType) && + if followerExist && !followerRead && proto.IsHot(req.volType) && (req.dpReplicaNum == 1 || req.dpReplicaNum == 2) { return fmt.Errorf("vol with 1 ro 2 replia should enable followerRead") } @@ -814,7 +802,7 @@ func parseRequestToCreateVol(r *http.Request, req *createVolReq) (err error) { return } - req.enablePosixAcl, err = extractPosixAcl(r) + req.enablePosixAcl, _ = extractPosixAcl(r) if req.DpReadOnlyWhenVolFull, err = extractBoolWithDefault(r, dpReadOnlyWhenVolFull, false); err != nil { return @@ -868,18 +856,6 @@ func parseRequestToCreateDataPartition(r *http.Request) (count int, name string, return } -func parseRequestToGetConcurrentLcNode(r *http.Request) (count uint64, err error) { - if err = r.ParseForm(); err != nil { - return - } - if count, err = extractUint64(r, countKey); err != nil || count == 0 { - err = unmatchedKey(countKey) - return - } - - return -} - func parseRequestToGetDataPartition(r *http.Request) (ID uint64, volName string, err error) { if err = r.ParseForm(); err != nil { return @@ -1089,30 +1065,6 @@ func extractFollowerRead(r *http.Request) (followerRead bool, exist bool, err er return } -func extractAuthenticate(r *http.Request) (authenticate bool, err error) { - var value string - if value = r.FormValue(authenticateKey); value == "" { - authenticate = false - return - } - if authenticate, err = strconv.ParseBool(value); err != nil { - return - } - return -} - -func extractCrossZone(r *http.Request) (crossZone bool, err error) { - var value string - if value = r.FormValue(crossZoneKey); value == "" { - crossZone = false - return - } - if crossZone, err = strconv.ParseBool(value); err != nil { - return - } - return -} - func parseAndExtractDirLimit(r *http.Request) (limit uint32, err error) { if err = r.ParseForm(); err != nil { return @@ -1194,7 +1146,6 @@ func parseAndExtractSetNodeSetInfoParams(r *http.Request) (params map[string]int nodesetId := uint64(0) nodesetId, err = strconv.ParseUint(value, 10, 64) if err != nil { - err = unmatchedKey(idKey) err = unmatchedKey(idKey) return } @@ -1472,7 +1423,7 @@ func extractUint64(r *http.Request, key string) (val uint64, err error) { return 0, nil } - if val, err = strconv.ParseUint(str, 10, 64); err != nil || val < 0 { + if val, err = strconv.ParseUint(str, 10, 64); err != nil { return 0, fmt.Errorf("args [%s] is not legal, val %s", key, str) } @@ -1486,7 +1437,7 @@ func extractUint32(r *http.Request, key string) (val uint32, err error) { } var tmp uint64 - if tmp, err = strconv.ParseUint(str, 10, 32); err != nil || val < 0 { + if tmp, err = strconv.ParseUint(str, 10, 32); err != nil { return 0, fmt.Errorf("args [%s] is not legal, val %s", key, str) } @@ -1669,7 +1620,6 @@ func send(w http.ResponseWriter, r *http.Request, reply []byte) { return } log.LogInfof("URL[%v],remoteAddr[%v],response ok", r.URL, r.RemoteAddr) - return } func sendErrReply(w http.ResponseWriter, r *http.Request, httpReply *proto.HTTPReply) { @@ -1686,8 +1636,6 @@ func sendErrReply(w http.ResponseWriter, r *http.Request, httpReply *proto.HTTPR if _, err = w.Write(reply); err != nil { log.LogErrorf("fail to write http len[%d].URL[%v],remoteAddr[%v] err:[%v]", len(reply), r.URL, r.RemoteAddr, err) } - - return } func parseRequestToUpdateDecommissionLimit(r *http.Request) (limit uint64, err error) { @@ -1817,14 +1765,6 @@ func parseGetQuotaParam(r *http.Request) (volName string, quotaId uint32, err er return } -func extractPath(r *http.Request) (fullPath string, err error) { - if fullPath = r.FormValue(fullPathKey); fullPath == "" { - err = keyNotFound(nameKey) - return - } - return -} - func extractQuotaId(r *http.Request) (quotaId uint32, err error) { var value string if value = r.FormValue(quotaKey); value == "" { @@ -1836,15 +1776,6 @@ func extractQuotaId(r *http.Request) (quotaId uint32, err error) { return } -func extractInodeId(r *http.Request) (inode uint64, err error) { - var value string - if value = r.FormValue(inodeKey); value == "" { - err = keyNotFound(inodeKey) - return - } - return strconv.ParseUint(value, 10, 64) -} - func parseRequestToUpdateDecommissionDiskFactor(r *http.Request) (factor float64, err error) { if err = r.ParseForm(); err != nil { return diff --git a/master/api_service.go b/master/api_service.go index 244307e22..9b5670420 100644 --- a/master/api_service.go +++ b/master/api_service.go @@ -104,7 +104,7 @@ type ZoneView struct { } func newZoneView(name string) *ZoneView { - return &ZoneView{NodeSet: make(map[uint64]*NodeSetView, 0), Name: name} + return &ZoneView{NodeSet: make(map[uint64]*NodeSetView), Name: name} } type badPartitionView = proto.BadPartitionView @@ -606,7 +606,7 @@ func (m *Server) clusterStat(w http.ResponseWriter, r *http.Request) { cs := &proto.ClusterStatInfo{ DataNodeStatInfo: m.cluster.dataNodeStatInfo, MetaNodeStatInfo: m.cluster.metaNodeStatInfo, - ZoneStatInfo: make(map[string]*proto.ZoneStat, 0), + ZoneStatInfo: make(map[string]*proto.ZoneStat), } for zoneName, zoneStat := range m.cluster.zoneStatInfos { cs.ZoneStatInfo[zoneName] = zoneStat @@ -641,6 +641,7 @@ func (m *Server) UidOperate(w http.ResponseWriter, r *http.Request) { op, err = strconv.ParseUint(value, 10, 64) if err != nil { err = fmt.Errorf("parseUintParam %s-%s is not legal, err %s", OperateKey, value, err.Error()) + log.LogWarn(err) return } @@ -714,6 +715,7 @@ func (m *Server) aclOperate(w http.ResponseWriter, r *http.Request) { op, err = strconv.ParseUint(value, 10, 64) if err != nil { err = fmt.Errorf("parseUintParam %s-%s is not legal, err %s", OperateKey, value, err.Error()) + log.LogWarn(err) return } @@ -744,7 +746,7 @@ func (m *Server) aclOperate(w http.ResponseWriter, r *http.Request) { } case util.AclAddIP, util.AclDelIP: if opAclRes != nil { - if err, res = opAclRes.(error); !res { + if _, res = opAclRes.(error); !res { sendErrReply(w, r, newErrHTTPReply(fmt.Errorf("inner error"))) return } @@ -854,7 +856,6 @@ func (m *Server) setApiQpsLimit(w http.ResponseWriter, r *http.Request) { } sendOkReply(w, r, newSuccessHTTPReply(fmt.Sprintf("set api qps limit success: name: %v, limit: %v, timeout: %v", name, limit, timeout))) - return } func (m *Server) getApiQpsLimit(w http.ResponseWriter, r *http.Request) { @@ -983,7 +984,7 @@ func (m *Server) createMetaPartition(w http.ResponseWriter, r *http.Request) { return } - sendOkReply(w, r, newSuccessHTTPReply(fmt.Sprint("create meta partition successfully"))) + sendOkReply(w, r, newSuccessHTTPReply("create meta partition successfully")) } func parsePreloadDpReq(r *http.Request, preload *DataPartitionPreLoad) (err error) { @@ -1437,7 +1438,6 @@ RET: return } _ = sendOkReply(w, r, newSuccessHTTPReply("success")) - return } func (m *Server) createDataPartition(w http.ResponseWriter, r *http.Request) { @@ -1518,7 +1518,7 @@ func (m *Server) changeDataPartitionLeader(w http.ResponseWriter, r *http.Reques sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()}) return } - rstMsg := fmt.Sprintf(" changeDataPartitionLeader command success send to dest host but need check. ") + rstMsg := " changeDataPartitionLeader command success send to dest host but need check. " _ = sendOkReply(w, r, newSuccessHTTPReply(rstMsg)) } @@ -1788,7 +1788,7 @@ func (m *Server) changeMetaPartitionLeader(w http.ResponseWriter, r *http.Reques sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()}) return } - rstMsg := fmt.Sprintf(" changeMetaPartitionLeader command success send to dest host but need check. ") + rstMsg := " changeMetaPartitionLeader command success send to dest host but need check. " _ = sendOkReply(w, r, newSuccessHTTPReply(rstMsg)) } @@ -1838,7 +1838,7 @@ func (m *Server) balanceMetaPartitionLeader(w http.ResponseWriter, r *http.Reque sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()}) return } - rstMsg := fmt.Sprintf("balanceMetaPartitionLeader command sucess") + rstMsg := "balanceMetaPartitionLeader command sucess" _ = sendOkReply(w, r, newSuccessHTTPReply(rstMsg)) } @@ -2499,8 +2499,6 @@ func (m *Server) checkCreateReq(req *createVolReq) (err error) { func (m *Server) createVol(w http.ResponseWriter, r *http.Request) { req := &createVolReq{} - vol := &Vol{} - var err error metric := exporter.NewTPCnt(apiToMetricsName(proto.AdminCreateVol)) @@ -2523,6 +2521,7 @@ func (m *Server) createVol(w http.ResponseWriter, r *http.Request) { sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()}) return } + var vol *Vol if vol, err = m.cluster.createVol(req); err != nil { sendErrReply(w, r, newErrHTTPReply(err)) return @@ -3268,10 +3267,7 @@ func (m *Server) updateClusterSelector(dataNodesetSelector string, metaNodesetSe return false } err = m.updateZoneNodeSelector(zone.name, dataNodeSelector, metaNodeSelector) - if err != nil { - return false - } - return true + return err == nil }) return } @@ -3552,7 +3548,6 @@ func (m *Server) setNodeRdOnlyHandler(w http.ResponseWriter, r *http.Request) { } sendOkReply(w, r, newSuccessHTTPReply(fmt.Sprintf("[setNodeRdOnlyHandler] set node %s to rdOnly(%v) success", addr, rdOnly))) - return } func (m *Server) setDpRdOnlyHandler(w http.ResponseWriter, r *http.Request) { @@ -3582,7 +3577,6 @@ func (m *Server) setDpRdOnlyHandler(w http.ResponseWriter, r *http.Request) { } sendOkReply(w, r, newSuccessHTTPReply(fmt.Sprintf("[setNodeRdOnlyHandler] set dpid %v to rdOnly(%v) success", dpId, rdOnly))) - return } func (m *Server) updateNodeSetCapacityHandler(w http.ResponseWriter, r *http.Request) { @@ -3712,7 +3706,7 @@ func (m *Server) updateNodeSetIdHandler(w http.ResponseWriter, r *http.Request) return } - sendOkReply(w, r, newSuccessHTTPReply(fmt.Sprintf("update node setid successfully"))) + sendOkReply(w, r, newSuccessHTTPReply("update node setid successfully")) } func (m *Server) updateNodeSetNodeSelector(w http.ResponseWriter, r *http.Request) { @@ -3821,7 +3815,7 @@ func (m *Server) createDomainHandler(w http.ResponseWriter, r *http.Request) { return } - sendOkReply(w, r, newSuccessHTTPReply(fmt.Sprintf("successful"))) + sendOkReply(w, r, newSuccessHTTPReply("successful")) } // get metanode some interval params @@ -4776,7 +4770,6 @@ func (m *Server) getMetaPartitions(w http.ResponseWriter, r *http.Request) { mpsCache = vol.getMpsCache() } send(w, r, mpsCache) - return } func (m *Server) putDataPartitions(w http.ResponseWriter, r *http.Request) { @@ -5025,9 +5018,7 @@ func getMetaPartitionView(mp *MetaPartition) (mpView *proto.MetaPartitionView) { mpView = proto.NewMetaPartitionView(mp.PartitionID, mp.Start, mp.End, mp.Status) mp.RLock() defer mp.RUnlock() - for _, host := range mp.Hosts { - mpView.Members = append(mpView.Members, host) - } + mpView.Members = append(mpView.Members, mp.Hosts...) mr, err := mp.getMetaReplicaLeader() if err != nil { return @@ -5168,7 +5159,7 @@ func (m *Server) changeMasterLeader(w http.ResponseWriter, r *http.Request) { sendErrReply(w, r, &proto.HTTPReply{Code: proto.ErrCodeParamError, Msg: err.Error()}) return } - rstMsg := fmt.Sprintf(" changeMasterLeader. command success send to dest host but need check. ") + rstMsg := " changeMasterLeader. command success send to dest host but need check. " _ = sendOkReply(w, r, newSuccessHTTPReply(rstMsg)) } @@ -5253,7 +5244,7 @@ func (m *Server) DelVersion(w http.ResponseWriter, r *http.Request) { return } - verSeq, err = extractUint64(r, verSeqKey) + verSeq, _ = extractUint64(r, verSeqKey) log.LogDebugf("action[DelVersion] vol %v verSeq %v", name, verSeq) if value = r.FormValue(forceKey); value != "" { force, _ = strconv.ParseBool(value) @@ -5844,7 +5835,6 @@ func (m *Server) setConfigHandler(w http.ResponseWriter, r *http.Request) { } sendOkReply(w, r, newSuccessHTTPReply(fmt.Sprintf("set config key[%v], value[%v] success", key, value))) - return } func (m *Server) getConfigHandler(w http.ResponseWriter, r *http.Request) { @@ -6000,7 +5990,6 @@ func (m *Server) DeleteQuota(w http.ResponseWriter, r *http.Request) { msg := fmt.Sprintf("delete quota successfully, vol [%v] quotaId [%v]", name, quotaId) sendOkReply(w, r, newSuccessHTTPReply(msg)) - return } func (m *Server) ListQuota(w http.ResponseWriter, r *http.Request) { @@ -6031,7 +6020,6 @@ func (m *Server) ListQuota(w http.ResponseWriter, r *http.Request) { log.LogInfof("list quota vol [%v] resp [%v] success.", name, *resp) sendOkReply(w, r, newSuccessHTTPReply(resp)) - return } func (m *Server) ListQuotaAll(w http.ResponseWriter, r *http.Request) { @@ -6043,7 +6031,6 @@ func (m *Server) ListQuotaAll(w http.ResponseWriter, r *http.Request) { volsInfo := m.cluster.listQuotaAll() log.LogInfof("list all vol has quota [%v]", volsInfo) sendOkReply(w, r, newSuccessHTTPReply(volsInfo)) - return } func (m *Server) GetQuota(w http.ResponseWriter, r *http.Request) { @@ -6076,7 +6063,6 @@ func (m *Server) GetQuota(w http.ResponseWriter, r *http.Request) { log.LogInfof("get quota vol [%v] quotaInfo [%v] success.", name, *quotaInfo) sendOkReply(w, r, newSuccessHTTPReply(quotaInfo)) - return } // func (m *Server) BatchModifyQuotaFullPath(w http.ResponseWriter, r *http.Request) { @@ -6188,7 +6174,6 @@ func (m *Server) setDpDiscardHandler(w http.ResponseWriter, r *http.Request) { msg := fmt.Sprintf("[setDpDiscardHandler] set dpid %v to discard(%v) success", dpId, discard) log.LogInfo(msg) sendOkReply(w, r, newSuccessHTTPReply(msg)) - return } func (m *Server) getDiscardDpHandler(w http.ResponseWriter, r *http.Request) { @@ -6201,8 +6186,7 @@ func (m *Server) getDiscardDpHandler(w http.ResponseWriter, r *http.Request) { vols := m.cluster.copyVols() for _, vol := range vols { - var dps *DataPartitionMap - dps = vol.dataPartitions + dps := vol.dataPartitions for _, dp := range dps.partitions { if dp.IsDiscard { DiscardDpInfos.DiscardDps = append(DiscardDpInfos.DiscardDps, *dp.buildDpInfo(m.cluster)) @@ -6213,7 +6197,6 @@ func (m *Server) getDiscardDpHandler(w http.ResponseWriter, r *http.Request) { msg := fmt.Sprintf("[GetDiscardDpHandler] discard dp num:%v", len(DiscardDpInfos.DiscardDps)) log.LogInfo(msg) sendOkReply(w, r, newSuccessHTTPReply(DiscardDpInfos)) - return } func (m *Server) queryBadDisks(w http.ResponseWriter, r *http.Request) { @@ -6404,7 +6387,7 @@ func (m *Server) SetBucketLifecycle(w http.ResponseWriter, r *http.Request) { return } _ = m.cluster.SetBucketLifecycle(&req) - sendOkReply(w, r, newSuccessHTTPReply(fmt.Sprintf("PutBucketLifecycleConfiguration successful "))) + sendOkReply(w, r, newSuccessHTTPReply("PutBucketLifecycleConfiguration successful")) } func (m *Server) GetBucketLifecycle(w http.ResponseWriter, r *http.Request) { @@ -6543,7 +6526,7 @@ func (m *Server) S3QosGet(w http.ResponseWriter, r *http.Request) { doStatAndMetric(proto.S3QoSGet, metric, err, nil) }() - apiLimitConf := make(map[string]*proto.UserLimitConf, 0) + apiLimitConf := make(map[string]*proto.UserLimitConf) s3QosResponse := proto.S3QoSResponse{ ApiLimitConf: apiLimitConf, } @@ -6561,9 +6544,9 @@ func (m *Server) S3QosGet(w http.ResponseWriter, r *http.Request) { return true } if _, ok := apiLimitConf[api]; !ok { - bandWidthQuota := make(map[string]uint64, 0) - qpsQuota := make(map[string]uint64, 0) - concurrentQuota := make(map[string]uint64, 0) + bandWidthQuota := make(map[string]uint64) + qpsQuota := make(map[string]uint64) + concurrentQuota := make(map[string]uint64) userLimitConf := &proto.UserLimitConf{ BandWidthQuota: bandWidthQuota, QPSQuota: qpsQuota, diff --git a/master/api_service_test.go b/master/api_service_test.go index 14e346c02..0f349963c 100644 --- a/master/api_service_test.go +++ b/master/api_service_test.go @@ -175,13 +175,13 @@ func createDefaultMasterServerForTest() *Server { qosLimitArgs: &qosArgs{}, } - vol, err := testServer.cluster.createVol(req) + _, err = testServer.cluster.createVol(req) if err != nil { log.LogFlush() panic(err) } - vol, err = testServer.cluster.getVol(req.name) + vol, err := testServer.cluster.getVol(req.name) if err != nil { panic(err) } @@ -307,11 +307,6 @@ func TestGetIpAndClusterName(t *testing.T) { process(reqURL, t) } -func fatal(t *testing.T, str string) { - log.LogFlush() - t.Fatal(str) -} - type httpReply = proto.HTTPReplyRaw func processWithFatalV2(url string, success bool, req map[string]interface{}, t *testing.T) (reply *httpReply) { @@ -588,10 +583,6 @@ func setUpdateVolParm(key string, req map[string]interface{}, val interface{}, t setParam(key, proto.AdminUpdateVol, req, val, t) } -func checkUpdateVolParm(key string, req map[string]interface{}, wrong, correct interface{}, t *testing.T) { - checkParam(key, proto.AdminUpdateVol, req, wrong, correct, t) -} - func delVol(name string, t *testing.T) { req := map[string]interface{}{ nameKey: name, diff --git a/master/cluster.go b/master/cluster.go index 6ec9de4e0..5f59f6cde 100644 --- a/master/cluster.go +++ b/master/cluster.go @@ -78,7 +78,6 @@ type Cluster struct { MasterSecretKey []byte lastZoneIdxForNode int zoneIdxMux sync.Mutex // - zoneList []string followerReadManager *followerReadManager diskQosEnable bool QosAcceptLimit *rate.Limiter @@ -172,7 +171,8 @@ func (mgr *followerReadManager) getVolumeDpView() { } for _, vv := range volViews { - if (vv.Status == proto.VolStatusMarkDelete && !vv.Forbidden) || (vv.Status == proto.VolStatusMarkDelete && vv.Forbidden && vv.DeleteExecTime.Sub(time.Now()) <= 0) { + if (vv.Status == proto.VolStatusMarkDelete && !vv.Forbidden) || + (vv.Status == proto.VolStatusMarkDelete && vv.Forbidden && time.Until(vv.DeleteExecTime) <= 0) { mgr.rwMutex.Lock() mgr.lastUpdateTick[vv.Name] = time.Now() mgr.status[vv.Name] = false @@ -194,7 +194,8 @@ func (mgr *followerReadManager) sendFollowerVolumeDpView() { vols := mgr.c.copyVols() for _, vol := range vols { log.LogDebugf("followerReadManager.getVolumeDpView %v", vol.Name) - if (vol.Status == proto.VolStatusMarkDelete && !vol.Forbidden) || (vol.Status == proto.VolStatusMarkDelete && vol.Forbidden && vol.DeleteExecTime.Sub(time.Now()) <= 0) { + if (vol.Status == proto.VolStatusMarkDelete && !vol.Forbidden) || + (vol.Status == proto.VolStatusMarkDelete && vol.Forbidden && time.Until(vol.DeleteExecTime) <= 0) { continue } var body []byte @@ -225,12 +226,8 @@ func (mgr *followerReadManager) isVolRecordObsolete(volName string) bool { // vol has been completely deleted return true } - - if (volView.Status == proto.VolStatusMarkDelete && !volView.Forbidden) || (volView.Status == proto.VolStatusMarkDelete && volView.Forbidden && volView.DeleteExecTime.Sub(time.Now()) <= 0) { - return true - } - - return false + return (volView.Status == proto.VolStatusMarkDelete && !volView.Forbidden) || + (volView.Status == proto.VolStatusMarkDelete && volView.Forbidden && time.Until(volView.DeleteExecTime) <= 0) } func (mgr *followerReadManager) DelObsoleteVolRecord(obsoleteVolNames map[string]struct{}) { @@ -311,9 +308,9 @@ func (mgr *followerReadManager) getVolViewAsFollower(key string, compress bool) defer mgr.rwMutex.RUnlock() ok = true if compress { - value, _ = mgr.volDataPartitionsCompress[key] + value = mgr.volDataPartitionsCompress[key] } else { - value, _ = mgr.volDataPartitionsView[key] + value = mgr.volDataPartitionsView[key] } log.LogDebugf("getVolViewAsFollower. volume %v return!", key) return @@ -332,9 +329,9 @@ func newCluster(name string, leaderInfo *LeaderInfo, fsm *MetadataFsm, partition c = new(Cluster) c.Name = name c.leaderInfo = leaderInfo - c.vols = make(map[string]*Vol, 0) + c.vols = make(map[string]*Vol) c.delayDeleteVolsInfo = make([]*delayDeleteVolInfo, 0) - c.stopc = make(chan bool, 0) + c.stopc = make(chan bool) c.cfg = cfg if c.cfg.MaxDpCntLimit == 0 { c.cfg.MaxDpCntLimit = defaultMaxDpCntLimit @@ -484,7 +481,7 @@ func (c *Cluster) scheduleToCheckDelayDeleteVols() { for index := 0; index < len(c.delayDeleteVolsInfo); index++ { currentDeleteVol := c.delayDeleteVolsInfo[index] log.LogDebugf("action[scheduleToCheckDelayDeleteVols] currentDeleteVol[%v]", currentDeleteVol) - if currentDeleteVol.execTime.Sub(time.Now()) > 0 { + if time.Until(currentDeleteVol.execTime) > 0 { continue } go func() { @@ -578,7 +575,7 @@ func (c *Cluster) scheduleToCheckVolQos() { func (c *Cluster) scheduleToCheckNodeSetGrpManagerStatus() { go func() { for { - if c.FaultDomain == false || !c.partition.IsRaftLeader() { + if !c.FaultDomain || !c.partition.IsRaftLeader() { time.Sleep(time.Minute) continue } @@ -638,7 +635,8 @@ func (c *Cluster) doLoadDataPartitions() { }() vols := c.allVols() for _, vol := range vols { - if (vol.Status == proto.VolStatusMarkDelete && !vol.Forbidden) || (vol.Status == proto.VolStatusMarkDelete && vol.Forbidden && vol.DeleteExecTime.Sub(time.Now()) <= 0) { + if (vol.Status == proto.VolStatusMarkDelete && !vol.Forbidden) || + (vol.Status == proto.VolStatusMarkDelete && vol.Forbidden && time.Until(vol.DeleteExecTime) <= 0) { continue } vol.loadDataPartition(c) @@ -703,10 +701,6 @@ func (c *Cluster) scheduleToCheckHeartbeat() { }() } -func (c *Cluster) passAclCheck(ip string) { - // do nothing -} - func (c *Cluster) checkLeaderAddr() { leaderID, _ := c.partition.LeaderTerm() c.leaderInfo.addr = AddrDatabase[leaderID] @@ -801,7 +795,6 @@ func (c *Cluster) checkLcNodeHeartbeat() { log.LogInfof("checkLcNodeHeartbeat: deregister node(%v)", node) _ = c.delLcNode(node) } - return } func (c *Cluster) scheduleToCheckMetaPartitions() { @@ -1163,8 +1156,7 @@ func (c *Cluster) checkLackReplicaAndHostDataPartitions() (lackReplicaDataPartit vols := c.copyVols() var ids []uint64 for _, vol := range vols { - var dps *DataPartitionMap - dps = vol.dataPartitions + dps := vol.dataPartitions for _, dp := range dps.partitions { if dp.ReplicaNum > uint8(len(dp.Hosts)) && len(dp.Hosts) == len(dp.Replicas) && (dp.IsDecommissionInitial() || dp.IsRollbackFailed()) { lackReplicaDataPartitions = append(lackReplicaDataPartitions, dp) @@ -1181,8 +1173,7 @@ func (c *Cluster) checkLackReplicaDataPartitions() (lackReplicaDataPartitions [] lackReplicaDataPartitions = make([]*DataPartition, 0) vols := c.copyVols() for _, vol := range vols { - var dps *DataPartitionMap - dps = vol.dataPartitions + dps := vol.dataPartitions for _, dp := range dps.partitions { if dp.ReplicaNum > uint8(len(dp.Hosts)) { lackReplicaDataPartitions = append(lackReplicaDataPartitions, dp) @@ -1195,7 +1186,8 @@ func (c *Cluster) checkLackReplicaDataPartitions() (lackReplicaDataPartitions [] func (c *Cluster) checkReplicaOfDataPartitions(ignoreDiscardDp bool) ( lackReplicaDPs []*DataPartition, unavailableReplicaDPs []*DataPartition, repFileCountDifferDps []*DataPartition, - repUsedSizeDifferDps []*DataPartition, excessReplicaDPs []*DataPartition, noLeaderDPs []*DataPartition, err error) { + repUsedSizeDifferDps []*DataPartition, excessReplicaDPs []*DataPartition, noLeaderDPs []*DataPartition, err error, +) { noLeaderDPs = make([]*DataPartition, 0) lackReplicaDPs = make([]*DataPartition, 0) unavailableReplicaDPs = make([]*DataPartition, 0) @@ -1203,14 +1195,14 @@ func (c *Cluster) checkReplicaOfDataPartitions(ignoreDiscardDp bool) ( vols := c.copyVols() for _, vol := range vols { - var dps *DataPartitionMap - dps = vol.dataPartitions + dps := vol.dataPartitions for _, dp := range dps.partitions { if ignoreDiscardDp && dp.IsDiscard { continue } - if (vol.Status == proto.VolStatusMarkDelete && !vol.Forbidden) || (vol.Status == proto.VolStatusMarkDelete && vol.Forbidden && vol.DeleteExecTime.Sub(time.Now()) <= 0) { + if (vol.Status == proto.VolStatusMarkDelete && !vol.Forbidden) || + (vol.Status == proto.VolStatusMarkDelete && vol.Forbidden && time.Until(vol.DeleteExecTime) <= 0) { continue } @@ -1376,7 +1368,6 @@ func (c *Cluster) deleteVol(name string) { c.volMutex.Lock() defer c.volMutex.Unlock() delete(c.vols, name) - return } func (c *Cluster) markDeleteVol(name, authKey string, force bool, isNotCancel bool) (err error) { @@ -1652,7 +1643,8 @@ errHandler: } func (c *Cluster) syncCreateDataPartitionToDataNode(host string, size uint64, dp *DataPartition, - peers []proto.Peer, hosts []string, createType int, partitionType int, needRollBack, ignoreDecommissionDisk bool) (diskPath string, err error) { + peers []proto.Peer, hosts []string, createType int, partitionType int, needRollBack, ignoreDecommissionDisk bool, +) (diskPath string, err error) { log.LogInfof("action[syncCreateDataPartitionToDataNode] dp [%v] createType[%v], partitionType[%v] ignoreDecommissionDisk[%v]", dp.PartitionID, createType, partitionType, ignoreDecommissionDisk) dataNode, err := c.dataNode(host) @@ -1766,7 +1758,8 @@ func (c *Cluster) chooseZone2Plus1(zones []*Zone, excludeNodeSets []uint64, excl } func (c *Cluster) chooseZoneNormal(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) { log.LogInfof("action[chooseZoneNormal] zones[%s] nodeType[%d] replicaNum[%d]", printZonesName(zones), nodeType, replicaNum) c.zoneIdxMux.Lock() @@ -1834,8 +1827,6 @@ func (c *Cluster) getHostFromNormalZone(nodeType uint32, excludeZones []string, goto result } - hosts = make([]string, 0) - peers = make([]proto.Peer, 0) if excludeHosts == nil { excludeHosts = make([]string, 0) } @@ -2085,7 +2076,7 @@ func (c *Cluster) delDecommissionDiskFromCache(dd *DecommissionDisk) { func (c *Cluster) decommissionSingleDp(dp *DataPartition, newAddr, offlineAddr string) (err error) { var ( dataNode *DataNode - decommContinue = false + decommContinue bool newReplica *DataReplica ) @@ -2140,7 +2131,7 @@ func (c *Cluster) decommissionSingleDp(dp *DataPartition, newAddr, offlineAddr s log.LogInfof("action[decommissionSingleDp] dp %v replica[%v] status %v", dp.PartitionID, newReplica.Addr, newReplica.Status) if newReplica.isRepairing() { // wait for repair - if time.Now().Sub(dp.RecoverStartTime) > c.GetDecommissionDataPartitionRecoverTimeOut() { + if time.Since(dp.RecoverStartTime) > c.GetDecommissionDataPartitionRecoverTimeOut() { err = fmt.Errorf("action[decommissionSingleDp] dp %v new replica %v repair time out", dp.PartitionID, newAddr) dp.DecommissionNeedRollback = true @@ -3621,7 +3612,7 @@ func (c *Cluster) allVolNames() (vols []string) { } func (c *Cluster) copyVols() (vols map[string]*Vol) { - vols = make(map[string]*Vol, 0) + vols = make(map[string]*Vol) c.volMutex.RLock() defer c.volMutex.RUnlock() @@ -3634,7 +3625,7 @@ func (c *Cluster) copyVols() (vols map[string]*Vol) { // Return all the volumes except the ones that have been marked to be deleted. func (c *Cluster) allVols() (vols map[string]*Vol) { - vols = make(map[string]*Vol, 0) + vols = make(map[string]*Vol) c.volMutex.RLock() defer c.volMutex.RUnlock() for name, vol := range c.vols { @@ -3793,11 +3784,6 @@ func (c *Cluster) setMetaNodeDeleteWorkerSleepMs(val uint64) (err error) { return } -func (c *Cluster) getMaxDpCntLimit() (dpCntInLimit uint64) { - dpCntInLimit = atomic.LoadUint64(&c.cfg.MaxDpCntLimit) - return -} - func (c *Cluster) setMaxDpCntLimit(val uint64) (err error) { if val == 0 { val = defaultMaxDpCntLimit @@ -3863,8 +3849,8 @@ func (c *Cluster) setMaxConcurrentLcNodes(count uint64) (err error) { func (c *Cluster) clearVols() { c.volMutex.Lock() - defer c.volMutex.Unlock() - c.vols = make(map[string]*Vol, 0) + c.vols = make(map[string]*Vol) + c.volMutex.Unlock() } func (c *Cluster) clearTopology() { @@ -3911,7 +3897,7 @@ func (c *Cluster) checkDecommissionDataNode() { partitions := c.getAllDataPartitionByDataNode(dataNode.Addr) // if only decommission part of data partitions, do not remove the data node if len(partitions) != 0 { - if time.Now().Sub(time.Unix(dataNode.DecommissionCompleteTime, 0)) > (20 * time.Minute) { + if time.Since(time.Unix(dataNode.DecommissionCompleteTime, 0)) > (20 * time.Minute) { log.LogWarnf("action[checkDecommissionDataNode] dataNode %v decommission completed, "+ "but has dp left, so only reset decommission status", dataNode.Addr) dataNode.resetDecommissionStatus() @@ -4185,7 +4171,7 @@ func (c *Cluster) checkDecommissionDisk() { // keep failed decommission disk in list for preventing the reuse of a // term in future decommissioning operations if status == DecommissionSuccess { - if time.Now().Sub(time.Unix(disk.DecommissionCompleteTime, 0)) > (20 * time.Minute) { + if time.Since(time.Unix(disk.DecommissionCompleteTime, 0)) > (20 * time.Minute) { if err := c.syncDeleteDecommissionDisk(disk); err != nil { msg := fmt.Sprintf("action[checkDecommissionDisk],clusterID[%v] node[%v] disk[%v],"+ "syncDeleteDecommissionDisk failed,err[%v]", @@ -4706,7 +4692,6 @@ func (c *Cluster) DelBucketLifecycle(VolName string) { } c.lcMgr.DelS3BucketLifecycle(VolName) log.LogInfof("action[DelS3BucketLifecycle],clusterID[%v] vol:%v", c.Name, VolName) - return } func (c *Cluster) addDecommissionDiskToNodeset(dd *DecommissionDisk) (err error) { diff --git a/master/cluster_task.go b/master/cluster_task.go index daaf34c2e..3733208a1 100644 --- a/master/cluster_task.go +++ b/master/cluster_task.go @@ -295,7 +295,8 @@ type VolNameSet map[string]struct{} func (c *Cluster) checkReplicaMetaPartitions() ( lackReplicaMetaPartitions []*MetaPartition, noLeaderMetaPartitions []*MetaPartition, - unavailableReplicaMPs []*MetaPartition, excessReplicaMetaPartitions, inodeCountNotEqualMPs, maxInodeNotEqualMPs, dentryCountNotEqualMPs []*MetaPartition, err error) { + unavailableReplicaMPs []*MetaPartition, excessReplicaMetaPartitions, inodeCountNotEqualMPs, maxInodeNotEqualMPs, dentryCountNotEqualMPs []*MetaPartition, err error, +) { lackReplicaMetaPartitions = make([]*MetaPartition, 0) noLeaderMetaPartitions = make([]*MetaPartition, 0) excessReplicaMetaPartitions = make([]*MetaPartition, 0) @@ -501,10 +502,8 @@ func (c *Cluster) addMetaReplica(partition *MetaPartition, addr string) (err err if err = c.addMetaPartitionRaftMember(partition, addPeer); err != nil { return } - newHosts := make([]string, 0, len(partition.Hosts)+1) - newPeers := make([]proto.Peer, 0, len(partition.Hosts)+1) - newHosts = append(partition.Hosts, addPeer.Addr) - newPeers = append(partition.Peers, addPeer) + newHosts := append(partition.Hosts, addPeer.Addr) + newPeers := append(partition.Peers, addPeer) if err = partition.persistToRocksDB("addMetaReplica", partition.volName, newHosts, newPeers, c); err != nil { return } @@ -886,7 +885,6 @@ func (c *Cluster) adjustMetaNode(metaNode *MetaNode) { return } err = c.t.putMetaNode(metaNode) - return } func (c *Cluster) handleDataNodeTaskResponse(nodeAddr string, task *proto.AdminTask) { @@ -935,7 +933,6 @@ func (c *Cluster) handleDataNodeTaskResponse(nodeAddr string, task *proto.AdminT errHandler: log.LogErrorf("process task[%v] failed,err:%v", task.ToString(), err) - return } func (c *Cluster) dealDeleteDataPartitionResponse(nodeAddr string, resp *proto.DeleteDataPartitionResponse) (err error) { @@ -1069,7 +1066,6 @@ func (c *Cluster) adjustDataNode(dataNode *DataNode) { return } err = c.t.putDataNode(dataNode) - return } /*if node report data partition infos,so range data partition infos,then update data partition info*/ diff --git a/master/cluster_test.go b/master/cluster_test.go index 6be9cc661..0fcd7faad 100644 --- a/master/cluster_test.go +++ b/master/cluster_test.go @@ -97,7 +97,6 @@ func TestPanicCheckMetaPartitions(t *testing.T) { } mp := newMetaPartition(partitionID, 1, defaultMaxMetaPartitionInodeID, vol.mpReplicaNum, vol.Name, vol.ID, 0) vol.addMetaPartition(mp) - mp = nil c.checkMetaPartitions() t.Logf("catched panic") } @@ -152,9 +151,7 @@ func TestCheckBadDiskRecovery(t *testing.T) { } vol.volLock.RLock() dps := make([]*DataPartition, 0) - for _, dp := range vol.dataPartitions.partitions { - dps = append(dps, dp) - } + dps = append(dps, vol.dataPartitions.partitions...) dpsMapLen := len(vol.dataPartitions.partitionMap) vol.volLock.RUnlock() dpsLen := len(dps) @@ -165,7 +162,6 @@ func TestCheckBadDiskRecovery(t *testing.T) { for _, dp := range dps { dp.RLock() if len(dp.Replicas) == 0 { - dpsLen-- dp.RUnlock() return } @@ -241,7 +237,6 @@ func TestCheckBadMetaPartitionRecovery(t *testing.T) { for _, mp := range mps { mp.RLock() if len(mp.Replicas) == 0 { - mpsLen-- mp.RUnlock() return } diff --git a/master/config.go b/master/config.go index fefed50fc..39680adcc 100644 --- a/master/config.go +++ b/master/config.go @@ -90,9 +90,9 @@ const ( defaultMaxDpCntLimit = 3000 defaultIntervalToScanS3Expiration = 12 * 3600 defaultMaxConcurrentLcNodes = 3 - defaultIntervalToCheckDelVerTaskExpiration = 3 metaPartitionInodeUsageThreshold float64 = 0.75 // inode usage threshold on a meta partition lowerLimitRWMetaPartition = 3 // lower limit of RW meta partition, equal defaultReplicaNum + // defaultIntervalToCheckDelVerTaskExpiration = 3 ) // AddrDatabase is a map that stores the address of a given host (e.g., the leader) diff --git a/master/const.go b/master/const.go index ea7128f94..7bd00896a 100644 --- a/master/const.go +++ b/master/const.go @@ -144,12 +144,11 @@ const ( ) const ( - deleteIllegalReplicaErr = "deleteIllegalReplicaErr " - addMissingReplicaErr = "addMissingReplicaErr " - checkDataPartitionDiskErr = "checkDataPartitionDiskErr " - dataNodeOfflineErr = "dataNodeOfflineErr " - diskOfflineErr = "diskOfflineErr " - handleDataPartitionOfflineErr = "handleDataPartitionOffLineErr " + deleteIllegalReplicaErr = "deleteIllegalReplicaErr " + addMissingReplicaErr = "addMissingReplicaErr " + checkDataPartitionDiskErr = "checkDataPartitionDiskErr " + dataNodeOfflineErr = "dataNodeOfflineErr " + diskOfflineErr = "diskOfflineErr " ) const ( @@ -351,3 +350,31 @@ const ( DataNodeType = NodeType(0) MetaNodeType = NodeType(iota) ) + +// TODO: to remove unused by golangci +var ( + _ = startKey + _ = nodeHostsKey + _ = fullPathKey + _ = inodeKey + _ = dataNodeOfflineErr + _ = defaultMigrateDpCnt + _ = idSeparator + _ = volCachePrefix + _ = opSyncDataPartitionsView + _ = opSyncUpdateLcNode + + _ = (createVolReq{}).clientReqPeriod + _ = (createVolReq{}).clientHitTriggerCnt + + _ = (*Server).createDomainHandler + _ = (*VolumeService).markDeleteVol + + __c = (*Cluster)(nil) + _ = __c.checkLackReplicaDataPartitions + _ = __c.getAllMetaPartitionsByMetaNode + _ = __c.isRecovering + _ = __c.updateInodeIDRange + _ = __c.setMaxConcurrentLcNodes + _ = __c.checkCorruptMetaNode +) diff --git a/master/data_node.go b/master/data_node.go index 81817a842..574b1febe 100644 --- a/master/data_node.go +++ b/master/data_node.go @@ -101,8 +101,6 @@ func (dataNode *DataNode) checkLiveness() { if time.Since(dataNode.ReportTime) > time.Second*time.Duration(defaultNodeTimeOutSec) { dataNode.isActive = false } - - return } func (dataNode *DataNode) badPartitions(diskPath string, c *Cluster) (partitions []*DataPartition) { @@ -171,17 +169,10 @@ func (dataNode *DataNode) updateNodeMetric(resp *proto.DataNodeHeartbeatResponse func (dataNode *DataNode) canAlloc() bool { dataNode.RLock() defer dataNode.RUnlock() - if !overSoldLimit() { return true } - - maxCapacity := overSoldCap(dataNode.Total) - if maxCapacity < dataNode.TotalPartitionSize { - return false - } - - return true + return overSoldCap(dataNode.Total) >= dataNode.TotalPartitionSize } func (dataNode *DataNode) isWriteAble() (ok bool) { @@ -224,7 +215,7 @@ func (dataNode *DataNode) isWriteAbleWithSize(size uint64) (ok bool) { dataNode.RLock() defer dataNode.RUnlock() - if dataNode.isActive == true && dataNode.AvailableSpace > size { + if dataNode.isActive && dataNode.AvailableSpace > size { ok = true } diff --git a/master/data_partition.go b/master/data_partition.go index 0d670f964..f97539c9d 100644 --- a/master/data_partition.go +++ b/master/data_partition.go @@ -97,7 +97,7 @@ func newDataPartition(ID uint64, replicaNum uint8, volName string, volID uint64, partition.Hosts = make([]string, 0) partition.Peers = make([]proto.Peer, 0) partition.Replicas = make([]*DataReplica, 0) - partition.FileInCoreMap = make(map[string]*FileInCore, 0) + partition.FileInCoreMap = make(map[string]*FileInCore) partition.FilesWithMissingReplica = make(map[string]int64) partition.MissingNodes = make(map[string]int64) @@ -130,14 +130,6 @@ func (partition *DataPartition) isSpecialReplicaCnt() bool { return partition.ReplicaNum == 1 || partition.ReplicaNum == 2 } -func (partition *DataPartition) isSingleReplica() bool { - return partition.ReplicaNum == 1 -} - -func (partition *DataPartition) isTwoReplica() bool { - return partition.ReplicaNum == 2 -} - func (partition *DataPartition) resetFilesWithMissingReplica() { partition.Lock() defer partition.Unlock() @@ -353,21 +345,6 @@ func (partition *DataPartition) canBeOffLine(offlineAddr string) (err error) { return } -// get all the valid replicas of the given data partition -func (partition *DataPartition) availableDataReplicas() (replicas []*DataReplica) { - replicas = make([]*DataReplica, 0) - for i := 0; i < len(partition.Replicas); i++ { - replica := partition.Replicas[i] - - // the node reports heartbeat normally and the node is available - if replica.isLocationAvailable() == true && partition.hasHost(replica.Addr) == true { - replicas = append(replicas, replica) - } - } - - return -} - // Remove the replica address from the memory. func (partition *DataPartition) removeReplicaByAddr(addr string) { delIndex := -1 @@ -385,11 +362,9 @@ func (partition *DataPartition) removeReplicaByAddr(addr string) { if delIndex == -1 { return } - partition.FileInCoreMap = make(map[string]*FileInCore, 0) + partition.FileInCoreMap = make(map[string]*FileInCore) partition.deleteReplicaByIndex(delIndex) partition.modifyTime = time.Now().Unix() - - return } func (partition *DataPartition) deleteReplicaByIndex(index int) { @@ -409,7 +384,7 @@ func (partition *DataPartition) createLoadTasks() (tasks []*proto.AdminTask) { defer partition.Unlock() for _, addr := range partition.Hosts { replica, err := partition.getReplica(addr) - if err != nil || replica.isLive(defaultDataPartitionTimeOutSec) == false { + if err != nil || !replica.isLive(defaultDataPartitionTimeOutSec) { continue } replica.HasLoadResponse = false @@ -486,13 +461,13 @@ func (partition *DataPartition) checkLoadResponse(timeOutSec int64) (isResponse return } timePassed := time.Now().Unix() - partition.LastLoadedTime - if replica.HasLoadResponse == false && timePassed > timeToWaitForResponse { + if !replica.HasLoadResponse && timePassed > timeToWaitForResponse { msg := fmt.Sprintf("action[checkLoadResponse], partitionID:%v on node:%v no response, spent time %v s", partition.PartitionID, addr, timePassed) log.LogWarn(msg) return } - if replica.isLive(timeOutSec) == false || replica.HasLoadResponse == false { + if !replica.isLive(timeOutSec) || !replica.HasLoadResponse { log.LogInfof("action[checkLoadResponse] partitionID:%v getReplica addr %v replica.isLive(timeOutSec) %v", partition.PartitionID, addr, replica.isLive(timeOutSec)) return } @@ -540,7 +515,7 @@ func (partition *DataPartition) releaseDataPartition() { fc.MetadataArray = nil delete(partition.FileInCoreMap, name) } - partition.FileInCoreMap = make(map[string]*FileInCore, 0) + partition.FileInCoreMap = make(map[string]*FileInCore) for name, fileMissReplicaTime := range partition.FilesWithMissingReplica { if time.Now().Unix()-fileMissReplicaTime > 2*intervalToLoadDataPartition { delete(partition.FilesWithMissingReplica, name) @@ -624,7 +599,7 @@ func (partition *DataPartition) getLiveReplicasFromHosts(timeOutSec int64) (repl if !ok { continue } - if replica.isLive(timeOutSec) == true { + if replica.isLive(timeOutSec) { replicas = append(replicas, replica) } else { replica.Status = proto.Unavailable @@ -640,7 +615,7 @@ func (partition *DataPartition) getLiveReplicasFromHosts(timeOutSec int64) (repl func (partition *DataPartition) getLiveReplicas(timeOutSec int64) (replicas []*DataReplica) { replicas = make([]*DataReplica, 0) for _, replica := range partition.Replicas { - if replica.isLive(timeOutSec) == true { + if replica.isLive(timeOutSec) { replicas = append(replicas, replica) } else { replica.Status = proto.Unavailable @@ -653,9 +628,7 @@ func (partition *DataPartition) getLiveReplicas(timeOutSec int64) (replicas []*D } func (partition *DataPartition) checkAndRemoveMissReplica(addr string) { - if _, ok := partition.MissingNodes[addr]; ok { - delete(partition.MissingNodes, addr) - } + delete(partition.MissingNodes, addr) } func (partition *DataPartition) loadFile(dataNode *DataNode, resp *proto.LoadDataPartitionResponse) { @@ -833,18 +806,6 @@ func (partition *DataPartition) getReplicaDisk(nodeAddr string) string { return "" } -func (partition *DataPartition) getMinus() (minus float64) { - partition.RLock() - defer partition.RUnlock() - used := partition.Replicas[0].Used - for _, replica := range partition.Replicas { - if math.Abs(float64(replica.Used)-float64(used)) > minus { - minus = math.Abs(float64(replica.Used) - float64(used)) - } - } - return minus -} - func (partition *DataPartition) activeUsedSimilar() bool { partition.RLock() defer partition.RUnlock() @@ -1039,10 +1000,9 @@ const ( const InvalidDecommissionDpCnt = -1 const ( - defaultDecommissionParallelLimit = 10 - defaultDecommissionRetryLimit = 5 - defaultDecommissionRollbackLimit = 3 - defaultDecommissionDiskParallelFactor = 0 + defaultDecommissionParallelLimit = 10 + defaultDecommissionRetryLimit = 5 + defaultDecommissionRollbackLimit = 3 ) func GetDecommissionStatusMessage(status uint32) string { @@ -1501,7 +1461,7 @@ func (partition *DataPartition) pauseReplicaRepair(replicaAddr string, stop bool log.LogDebugf("action[pauseReplicaRepair]dp[%v] replica %v RecoverStartTime sub %v seconds", partition.PartitionID, replicaAddr, partition.RecoverLastConsumeTime.Seconds()) } else { - partition.RecoverLastConsumeTime = time.Now().Sub(partition.RecoverStartTime) + partition.RecoverLastConsumeTime = time.Since(partition.RecoverStartTime) log.LogDebugf("action[pauseReplicaRepair]dp[%v] replica %v already recover %v seconds", partition.PartitionID, replicaAddr, partition.RecoverLastConsumeTime.Seconds()) } diff --git a/master/data_partition_check.go b/master/data_partition_check.go index 51f2eac85..b0754e2e0 100644 --- a/master/data_partition_check.go +++ b/master/data_partition_check.go @@ -26,7 +26,8 @@ import ( ) func (partition *DataPartition) checkStatus(clusterName string, needLog bool, dpTimeOutSec int64, c *Cluster, - shouldDpInhibitWriteByVolFull bool, forbiddenVol bool) { + shouldDpInhibitWriteByVolFull bool, forbiddenVol bool, +) { partition.Lock() defer partition.Unlock() var liveReplicas []*DataReplica @@ -81,7 +82,7 @@ func (partition *DataPartition) checkStatus(clusterName string, needLog bool, dp partition.Status = proto.Unavailable } - if needLog == true && len(liveReplicas) != int(partition.ReplicaNum) { + if needLog && len(liveReplicas) != int(partition.ReplicaNum) { msg := fmt.Sprintf("action[extractStatus],partitionID:%v replicaNum:%v liveReplicas:%v Status:%v RocksDBHost:%v ", partition.PartitionID, partition.ReplicaNum, len(liveReplicas), partition.Status, partition.Hosts) log.LogInfo(msg) @@ -94,22 +95,7 @@ func (partition *DataPartition) checkStatus(clusterName string, needLog bool, dp func (partition *DataPartition) hasEnoughAvailableSpace() bool { avail := partition.total - partition.used - if int64(avail) > 10*util.GB { - return true - } - return false -} - -func (partition *DataPartition) checkReplicaNotHaveStatus(liveReplicas []*DataReplica, status int8) (equal bool) { - for _, replica := range liveReplicas { - if replica.Status == status { - log.LogInfof("action[checkReplicaNotHaveStatus] partition %v replica %v status %v dst status %v", - partition.PartitionID, replica.Addr, replica.Status, status) - return - } - } - - return true + return int64(avail) > 10*util.GB } func (partition *DataPartition) checkReplicaEqualStatus(liveReplicas []*DataReplica, status int8) (equal bool) { @@ -165,7 +151,6 @@ func (partition *DataPartition) checkLeader(clusterID string, timeOut int64) { if WarnMetrics != nil { WarnMetrics.WarnDpNoLeader(clusterID, partition.PartitionID, report) } - return } // Check if there is any missing replica for a data partition. @@ -269,7 +254,7 @@ func (partition *DataPartition) hasMissingDataPartition(addr string) (isMissing } func (partition *DataPartition) checkDiskError(clusterID, leaderAddr string) { - diskErrorAddrs := make(map[string]string, 0) + diskErrorAddrs := make(map[string]string) partition.Lock() defer partition.Unlock() @@ -299,8 +284,6 @@ func (partition *DataPartition) checkDiskError(clusterID, leaderAddr string) { checkDataPartitionDiskErr, clusterID, partition.PartitionID, addr, leaderAddr, addr, diskPath) Warn(clusterID, msg) } - - return } func (partition *DataPartition) checkReplicationTask(clusterID string, dataPartitionSize uint64) { @@ -324,8 +307,6 @@ func (partition *DataPartition) checkReplicationTask(clusterID string, dataParti addMissingReplicaErr, partition.PartitionID, lackAddr, lackErr.Error(), partition.Hosts) Warn(clusterID, msg) } - - return } func (partition *DataPartition) deleteIllegalReplica() (excessAddr string, err error) { diff --git a/master/data_partition_map.go b/master/data_partition_map.go index b8f899cce..5aa0f77a2 100644 --- a/master/data_partition_map.go +++ b/master/data_partition_map.go @@ -43,7 +43,7 @@ type DataPartitionMap struct { func newDataPartitionMap(volName string) (dpMap *DataPartitionMap) { dpMap = new(DataPartitionMap) - dpMap.partitionMap = make(map[uint64]*DataPartition, 0) + dpMap.partitionMap = make(map[uint64]*DataPartition) dpMap.partitions = make([]*DataPartition, 0) dpMap.responseCache = make([]byte, 0) dpMap.responseCompressCache = make([]byte, 0) @@ -55,13 +55,9 @@ func newDataPartitionMap(volName string) (dpMap *DataPartitionMap) { // attention: it's not deep clone for element, dataPartition func (dpMap *DataPartitionMap) clonePartitions() []*DataPartition { dpMap.RLock() - defer dpMap.RUnlock() - - partitions := make([]*DataPartition, 0) - for _, dp := range dpMap.partitions { - partitions = append(partitions, dp) - } - + partitions := make([]*DataPartition, 0, len(dpMap.partitions)) + partitions = append(partitions, dpMap.partitions...) + dpMap.RUnlock() return partitions } diff --git a/master/data_partition_test.go b/master/data_partition_test.go index ff931f38e..9215a9ab1 100644 --- a/master/data_partition_test.go +++ b/master/data_partition_test.go @@ -23,6 +23,7 @@ func TestDataPartition(t *testing.T) { partition := commonVol.dataPartitions.partitions[0] getDataPartition(partition.PartitionID, t) loadDataPartitionTest(partition, t) + _ = decommissionDataPartition // decommissionDataPartition(partition, t) } diff --git a/master/data_replica.go b/master/data_replica.go index fcb4ba112..0654b9e9f 100644 --- a/master/data_replica.go +++ b/master/data_replica.go @@ -25,7 +25,7 @@ import ( type DataReplica struct { proto.DataReplica dataNode *DataNode - loc uint8 + // loc uint8 } func newDataReplica(dataNode *DataNode) (replica *DataReplica) { @@ -65,18 +65,6 @@ func (replica *DataReplica) getReplicaNode() (node *DataNode) { return replica.dataNode } -// check if the replica's location is available -func (replica *DataReplica) isLocationAvailable() (isAvailable bool) { - dataNode := replica.getReplicaNode() - dataNode.Lock() - defer dataNode.Unlock() - if dataNode.isActive == true && replica.isActive(defaultDataPartitionTimeOutSec) == true { - isAvailable = true - } - - return -} - func (replica *DataReplica) isRepairing() bool { return replica.Status == proto.Recovering } diff --git a/master/disk_manager.go b/master/disk_manager.go index 6091c83b6..3cfda9dfb 100644 --- a/master/disk_manager.go +++ b/master/disk_manager.go @@ -94,7 +94,6 @@ func (c *Cluster) checkDiskRecoveryProgress() { err = c.syncUpdateDataPartition(partition) if err != nil { log.LogErrorf("[checkDiskRecoveryProgress] update dp(%v) fail, err(%v)", partitionID, err) - err = nil } partition.RUnlock() continue @@ -114,7 +113,6 @@ func (c *Cluster) checkDiskRecoveryProgress() { err = c.syncUpdateDataPartition(partition) if err != nil { log.LogErrorf("[checkDiskRecoveryProgress] update dp(%v) fail, err(%v)", partitionID, err) - err = nil } partition.RUnlock() } else { @@ -139,7 +137,6 @@ func (c *Cluster) checkDiskRecoveryProgress() { err = c.syncUpdateDataPartition(partition) if err != nil { log.LogErrorf("[checkDiskRecoveryProgress] update dp(%v) fail, err(%v)", partitionID, err) - err = nil } partition.RUnlock() } @@ -182,7 +179,8 @@ func (c *Cluster) deleteAndSyncDecommissionedDisk(dataNode *DataNode, diskPath s } func (c *Cluster) decommissionDisk(dataNode *DataNode, raftForce bool, badDiskPath string, - badPartitions []*DataPartition, diskDisable bool) (err error) { + badPartitions []*DataPartition, diskDisable bool, +) (err error) { msg := fmt.Sprintf("action[decommissionDisk], Node[%v] OffLine,disk[%v]", dataNode.Addr, badDiskPath) log.LogWarn(msg) diff --git a/master/filecheck.go b/master/filecheck.go index 04479eb8c..3d05665d0 100644 --- a/master/filecheck.go +++ b/master/filecheck.go @@ -48,7 +48,6 @@ func (partition *DataPartition) validateCRC(clusterID string) { Warn(clusterID, fmt.Sprintf("vol[%v],dpId[%v],liveAddrs[%v],inactiveAddrs[%v]", partition.VolName, partition.PartitionID, liveAddrs, inactiveAddrs)) } partition.doValidateCRC(liveReplicas, clusterID) - return } func (partition *DataPartition) doValidateCRC(liveReplicas []*DataReplica, clusterID string) { @@ -73,7 +72,7 @@ func (partition *DataPartition) doValidateCRC(liveReplicas []*DataReplica, clust } func (partition *DataPartition) checkTinyExtentFile(fc *FileInCore, liveReplicas []*DataReplica, clusterID string, getInfoCallback func() string) { - if fc.shouldCheckCrc() == false { + if !fc.shouldCheckCrc() { return } fms, needRepair := fc.needCrcRepair(liveReplicas, getInfoCallback) @@ -93,11 +92,10 @@ func (partition *DataPartition) checkTinyExtentFile(fc *FileInCore, liveReplicas msg = msg + fmt.Sprintf("fm[%v]:%v\n", fm.locIndex, fm) } Warn(clusterID, msg) - return } func (partition *DataPartition) checkExtentFile(fc *FileInCore, liveReplicas []*DataReplica, clusterID string, getInfoCallback func() string) { - if fc.shouldCheckCrc() == false { + if !fc.shouldCheckCrc() { return } fms, needRepair := fc.needCrcRepair(liveReplicas, getInfoCallback) @@ -155,5 +153,4 @@ func (partition *DataPartition) checkExtentFile(fc *FileInCore, liveReplicas []* Warn(clusterID, msg) } } - return } diff --git a/master/filecrc.go b/master/filecrc.go index 84312a9d1..64cb4455a 100644 --- a/master/filecrc.go +++ b/master/filecrc.go @@ -122,7 +122,7 @@ func (fc *FileInCore) calculateCrc(badVfNodes []*FileMetadata) (fileCrcArr []*Fi } } - if isFound == false { + if !isFound { crc = newFileCrc(crcKey) crc.meta = badVfNodes[i] fileCrcArr = append(fileCrcArr, crc) diff --git a/master/filemeta.go b/master/filemeta.go index 6f87c78ff..f4d0738bf 100644 --- a/master/filemeta.go +++ b/master/filemeta.go @@ -99,7 +99,7 @@ func (fc *FileInCore) updateFileInCore(volID uint64, vf *proto.File, volLoc *Dat } } - if isFind == false { + if !isFind { fm := newFileMetadata(vf.Crc, volLoc.Addr, volLocIndex, vf.Size, vf.ApplyID) fc.MetadataArray = append(fc.MetadataArray, fm) } diff --git a/master/gapi_cluster.go b/master/gapi_cluster.go index 0315f31e4..6ebc7e613 100644 --- a/master/gapi_cluster.go +++ b/master/gapi_cluster.go @@ -227,7 +227,8 @@ func (m *ClusterService) decommissionDataNode(ctx context.Context, args struct { func (m *ClusterService) decommissionMetaNode(ctx context.Context, args struct { OffLineAddr string -}) (*proto.GeneralResp, error) { +}, +) (*proto.GeneralResp, error) { if _, _, err := permissions(ctx, ADMIN); err != nil { return nil, err } @@ -244,7 +245,8 @@ func (m *ClusterService) decommissionMetaNode(ctx context.Context, args struct { func (m *ClusterService) loadMetaPartition(ctx context.Context, args struct { PartitionID uint64 -}) (*proto.GeneralResp, error) { +}, +) (*proto.GeneralResp, error) { if _, _, err := permissions(ctx, ADMIN); err != nil { return nil, err } @@ -261,7 +263,8 @@ func (m *ClusterService) loadMetaPartition(ctx context.Context, args struct { func (m *ClusterService) decommissionMetaPartition(ctx context.Context, args struct { PartitionID uint64 NodeAddr string -}) (*proto.GeneralResp, error) { +}, +) (*proto.GeneralResp, error) { if _, _, err := permissions(ctx, ADMIN); err != nil { return nil, err } @@ -276,19 +279,6 @@ func (m *ClusterService) decommissionMetaPartition(ctx context.Context, args str return proto.Success("success"), nil } -func (m *ClusterService) getMetaNode(ctx context.Context, args struct { - NodeAddr string -}) (*MetaNode, error) { - if _, _, err := permissions(ctx, ADMIN); err != nil { - return nil, err - } - metaNode, err := m.cluster.metaNode(args.NodeAddr) - if err != nil { - return nil, err - } - return metaNode, nil -} - // View the topology of the cluster. func (m *ClusterService) getTopology(ctx context.Context, args struct{}) (*proto.GeneralResp, error) { if _, _, err := permissions(ctx, ADMIN); err != nil { @@ -361,7 +351,8 @@ func (s *ClusterService) masterList(ctx context.Context, args struct{}) ([]*Mast func (s *ClusterService) dataNodeGet(ctx context.Context, args struct { Addr string -}) (*DataNode, error) { +}, +) (*DataNode, error) { if _, _, err := permissions(ctx, ADMIN); err != nil { return nil, err } @@ -382,7 +373,8 @@ func (s *ClusterService) dataNodeList(ctx context.Context, args struct{}) ([]*Da func (s *ClusterService) dataNodeListTest(ctx context.Context, args struct { Num int64 -}) ([]*DataNode, error) { +}, +) ([]*DataNode, error) { if _, _, err := permissions(ctx, ADMIN); err != nil { return nil, err } @@ -409,7 +401,8 @@ func (s *ClusterService) dataNodeListTest(ctx context.Context, args struct { func (s *ClusterService) metaNodeGet(ctx context.Context, args struct { Addr string -}) (*MetaNode, error) { +}, +) (*MetaNode, error) { if _, _, err := permissions(ctx, ADMIN); err != nil { return nil, err } @@ -432,22 +425,12 @@ func (s *ClusterService) metaNodeList(ctx context.Context, args struct{}) ([]*Me return all, nil } -func (m *ClusterService) addMetaNode(ctx context.Context, args struct { - NodeAddr string - ZoneName string -}) (uint64, error) { - if id, err := m.cluster.addMetaNode(args.NodeAddr, args.ZoneName, 0); err != nil { - return 0, err - } else { - return id, nil - } -} - // Dynamically remove a master node. Similar to addRaftNode, this operation is performed online. func (m *ClusterService) removeRaftNode(ctx context.Context, args struct { Id uint64 Addr string -}) (*proto.GeneralResp, error) { +}, +) (*proto.GeneralResp, error) { if _, _, err := permissions(ctx, ADMIN); err != nil { return nil, err } @@ -463,7 +446,8 @@ func (m *ClusterService) removeRaftNode(ctx context.Context, args struct { func (m *ClusterService) addRaftNode(ctx context.Context, args struct { Id uint64 Addr string -}) (*proto.GeneralResp, error) { +}, +) (*proto.GeneralResp, error) { if _, _, err := permissions(ctx, ADMIN); err != nil { return nil, err } @@ -486,7 +470,8 @@ func (m *ClusterService) addRaftNode(ctx context.Context, args struct { // 2. and the number of r&w data partition is less than 20. func (m *ClusterService) clusterFreeze(ctx context.Context, args struct { Status bool -}) (*proto.GeneralResp, error) { +}, +) (*proto.GeneralResp, error) { if _, _, err := permissions(ctx, ADMIN); err != nil { return nil, err } @@ -508,7 +493,8 @@ type WarnMessage struct { func (m *ClusterService) alarmList(ctx context.Context, args struct { Size int32 -}) ([]*WarnMessage, error) { +}, +) ([]*WarnMessage, error) { if _, _, err := permissions(ctx, ADMIN); err != nil { return nil, err } diff --git a/master/gapi_user.go b/master/gapi_user.go index a8cf48e24..447832b72 100644 --- a/master/gapi_user.go +++ b/master/gapi_user.go @@ -85,8 +85,9 @@ func (s *UserService) registerQuery(schema *schemabuilder.Schema) { func (m *UserService) getUserAKInfo(ctx context.Context, args struct { AccessKey string -}) (*proto.UserInfo, error) { - uid, perm, err := permissions(ctx, ADMIN|USER) +}, +) (*proto.UserInfo, error) { + uid, perm, _ := permissions(ctx, ADMIN|USER) userInfo, err := m.user.getKeyInfo(args.AccessKey) if err != nil { return nil, err @@ -222,7 +223,8 @@ func (s *UserService) updateUser(ctx context.Context, args proto.UserUpdateParam func (s *UserService) deleteUser(ctx context.Context, args struct { UserID string -}) (*proto.GeneralResp, error) { +}, +) (*proto.GeneralResp, error) { uid, _, err := permissions(ctx, ADMIN) if err != nil { return nil, err @@ -239,7 +241,8 @@ func (s *UserService) deleteUser(ctx context.Context, args struct { func (s *UserService) getUserInfo(ctx context.Context, args struct { UserID string -}) (*proto.UserInfo, error) { +}, +) (*proto.UserInfo, error) { uid, perm, err := permissions(ctx, ADMIN|USER) if err != nil { return nil, err @@ -274,7 +277,8 @@ type UserUseSpace struct { func (s *UserService) topNUser(ctx context.Context, args struct { N int32 -}) ([]*UserUseSpace, error) { +}, +) ([]*UserUseSpace, error) { if _, _, err := permissions(ctx, ADMIN); err != nil { return nil, err } @@ -334,7 +338,8 @@ func (s *UserService) topNUser(ctx context.Context, args struct { func (s *UserService) validatePassword(ctx context.Context, args struct { UserID string Password string -}) (*proto.UserInfo, error) { +}, +) (*proto.UserInfo, error) { ui, err := s.user.getUserInfo(args.UserID) if err != nil { return nil, err diff --git a/master/gapi_volume.go b/master/gapi_volume.go index 2c4921082..938e03a53 100644 --- a/master/gapi_volume.go +++ b/master/gapi_volume.go @@ -366,7 +366,8 @@ func (s *VolumeService) listVolume(ctx context.Context, args struct { continue } - if (vol.Status == proto.VolStatusMarkDelete && !vol.Forbidden) || (vol.Status == proto.VolStatusMarkDelete && vol.Forbidden && vol.DeleteExecTime.Sub(time.Now()) <= 0) { + if (vol.Status == proto.VolStatusMarkDelete && !vol.Forbidden) || + (vol.Status == proto.VolStatusMarkDelete && vol.Forbidden && time.Until(vol.DeleteExecTime) <= 0) { continue } diff --git a/master/http_server.go b/master/http_server.go index 1eeb77e7f..c7c16b6c9 100644 --- a/master/http_server.go +++ b/master/http_server.go @@ -62,7 +62,6 @@ func (m *Server) startHTTPService(modulename string, cfg *config.Config) { } go serveAPI() m.apiServer = server - return } func (m *Server) isClientPartitionsReq(r *http.Request) bool { @@ -771,7 +770,7 @@ func (m *Server) registerHandler(router *mux.Router, model string, schema *graph gHandler := graphql.HTTPHandler(schema) router.NewRoute().Name(model).Methods(http.MethodGet, http.MethodPost).Path(model).HandlerFunc(func(writer http.ResponseWriter, request *http.Request) { - userID := request.Header.Get(proto.UserKey) + userID := request.Header.Get(string(proto.UserKey)) if userID == "" { ErrResponse(writer, fmt.Errorf("not found [%s] in header", proto.UserKey)) return diff --git a/master/lifecycle_manager.go b/master/lifecycle_manager.go index 4fcab23d4..7884633fb 100644 --- a/master/lifecycle_manager.go +++ b/master/lifecycle_manager.go @@ -90,7 +90,7 @@ func (lcMgr *lifecycleManager) scanning() bool { } for _, v := range lcMgr.lcRuleTaskStatus.Results { - if v.Done != true && time.Now().Before(v.UpdateTime.Add(time.Minute*10)) { + if !v.Done && time.Now().Before(v.UpdateTime.Add(time.Minute*10)) { return true } } @@ -232,19 +232,16 @@ func (ns *lcNodeStatus) GetIdleNode() (nodeAddr string) { func (ns *lcNodeStatus) RemoveNode(nodeAddr string) { ns.Lock() - defer ns.Unlock() delete(ns.WorkingCount, nodeAddr) - return + ns.Unlock() } func (ns *lcNodeStatus) UpdateNode(nodeAddr string, count int) { ns.Lock() - defer ns.Unlock() ns.WorkingCount[nodeAddr] = count - return + ns.Unlock() } -// ----------------------------------------------- type lcRuleTaskStatus struct { sync.RWMutex ToBeScanned map[string]*proto.RuleTask diff --git a/master/lifecycle_node.go b/master/lifecycle_node.go index cc0481080..742cd9c2f 100644 --- a/master/lifecycle_node.go +++ b/master/lifecycle_node.go @@ -52,8 +52,6 @@ func (lcNode *LcNode) checkLiveness() { if time.Since(lcNode.ReportTime) > time.Second*time.Duration(defaultNodeTimeOutSec) { lcNode.IsActive = false } - - return } func (lcNode *LcNode) createHeartbeatTask(masterAddr string) (task *proto.AdminTask) { diff --git a/master/lifecycle_task.go b/master/lifecycle_task.go index 40d17b4ca..853bbd862 100644 --- a/master/lifecycle_task.go +++ b/master/lifecycle_task.go @@ -63,7 +63,6 @@ func (c *Cluster) handleLcNodeTaskResponse(nodeAddr string, task *proto.AdminTas errHandler: log.LogWarnf("lc handleLcNodeTaskResponse failed, task: %v, err: %v", task.ToString(), err) - return } func (c *Cluster) handleLcNodeHeartbeatResp(nodeAddr string, resp *proto.LcNodeHeartbeatResponse) (err error) { diff --git a/master/limiter.go b/master/limiter.go index 7e3665edf..878749d1a 100644 --- a/master/limiter.go +++ b/master/limiter.go @@ -154,7 +154,8 @@ func (uMgr *UidSpaceManager) volUidUpdate(report *proto.MetaPartitionReport) { } } if _, ok := uidInfo[space.Uid]; !ok { - uidInfo[space.Uid] = &(*uMgr.uidInfo[space.Uid]) + infoCopy := *uMgr.uidInfo[space.Uid] + uidInfo[space.Uid] = &infoCopy } log.LogDebugf("volUidUpdate.vol %v uid %v from mpId %v useSize %v add %v", uMgr.vol, space.Uid, mpId, uidInfo[space.Uid].UsedSize, space.Size) @@ -682,7 +683,6 @@ func (qosManager *QosCtrlManager) updateServerLimitByClientsInfo(factorType uint } log.QosWriteDebugf("action[updateServerLimitByClientsInfo] vol [%v] type [%v] after adjust limitRatio serverLimit:(%v)", qosManager.vol.Name, proto.QosTypeString(factorType), serverLimit) - return } func (qosManager *QosCtrlManager) assignClientsNewQos(factorType uint32) { @@ -800,14 +800,14 @@ func (vol *Vol) getClientLimitInfo(id uint64, ip string) (interface{}, error) { Cli: &ClientReportOutput{ ID: info.Cli.ID, Status: info.Cli.Status, - FactorMap: make(map[uint32]*proto.ClientLimitInfo, 0), + FactorMap: make(map[uint32]*proto.ClientLimitInfo), }, Assign: &LimitOutput{ ID: info.Assign.ID, Enable: info.Assign.Enable, ReqPeriod: info.Assign.ReqPeriod, HitTriggerCnt: info.Assign.HitTriggerCnt, - FactorMap: make(map[uint32]*proto.ClientLimitInfo, 0), + FactorMap: make(map[uint32]*proto.ClientLimitInfo), }, Time: info.Time, Host: info.Host, diff --git a/master/master_manager.go b/master/master_manager.go index 7797056a5..992e8ddb6 100644 --- a/master/master_manager.go +++ b/master/master_manager.go @@ -98,7 +98,6 @@ func (m *Server) handlePeerChange(confChange *proto.ConfChange) (err error) { func (m *Server) handleApplySnapshot() { m.fsm.restore() m.restoreIDAlloc() - return } func (m *Server) handleRaftUserCmd(opt uint32, key string, cmdMap map[string][]byte) (err error) { diff --git a/master/master_quota_manager.go b/master/master_quota_manager.go index 4a730c28d..560285385 100644 --- a/master/master_quota_manager.go +++ b/master/master_quota_manager.go @@ -77,14 +77,11 @@ func (mqMgr *MasterQuotaManager) createQuota(req *proto.SetMasterQuotaReuqest) ( VolName: req.VolName, QuotaId: quotaId, CTime: time.Now().Unix(), - PathInfos: make([]proto.QuotaPathInfo, 0, 0), + PathInfos: make([]proto.QuotaPathInfo, 0), MaxFiles: req.MaxFiles, MaxBytes: req.MaxBytes, } - - for _, pathInfo := range req.PathInfos { - quotaInfo.PathInfos = append(quotaInfo.PathInfos, pathInfo) - } + quotaInfo.PathInfos = append(quotaInfo.PathInfos, req.PathInfos...) var value []byte if value, err = json.Marshal(quotaInfo); err != nil { @@ -230,7 +227,7 @@ func (mqMgr *MasterQuotaManager) quotaUpdate(report *proto.MetaPartitionReport) quotaInfo.UsedInfo.UsedFiles = 0 quotaInfo.UsedInfo.UsedBytes = 0 } - deleteQuotaIds := make(map[uint32]bool, 0) + deleteQuotaIds := make(map[uint32]bool) for mpId, reportInfos := range mqMgr.MpQuotaInfoMap { for _, info := range reportInfos { if _, isFind := mqMgr.IdQuotaInfoMap[info.QuotaId]; !isFind { @@ -258,7 +255,6 @@ func (mqMgr *MasterQuotaManager) quotaUpdate(report *proto.MetaPartitionReport) } log.LogDebugf("[quotaUpdate] quotaId [%v] quotaInfo [%v]", id, quotaInfo) } - return } func (mqMgr *MasterQuotaManager) getQuotaHbInfos() (infos []*proto.QuotaHeartBeatInfo) { @@ -281,9 +277,5 @@ func (mqMgr *MasterQuotaManager) getQuotaHbInfos() (infos []*proto.QuotaHeartBea func (mqMgr *MasterQuotaManager) HasQuota() bool { mqMgr.RLock() defer mqMgr.RUnlock() - - if len(mqMgr.IdQuotaInfoMap) == 0 { - return false - } - return true + return len(mqMgr.IdQuotaInfoMap) > 0 } diff --git a/master/meta_partition.go b/master/meta_partition.go index d4e977488..704178199 100644 --- a/master/meta_partition.go +++ b/master/meta_partition.go @@ -92,7 +92,7 @@ func newMetaPartition(partitionID, start, end uint64, replicaNum uint8, volName mp.Replicas = make([]*MetaReplica, 0) mp.LeaderReportTime = time.Now().Unix() mp.Status = proto.Unavailable - mp.MissNodes = make(map[string]int64, 0) + mp.MissNodes = make(map[string]int64) mp.Peers = make([]proto.Peer, 0) mp.Hosts = make([]string, 0) mp.VerSeq = verSeq @@ -120,7 +120,6 @@ func (mp *MetaPartition) addReplica(mr *MetaReplica) { } } mp.Replicas = append(mp.Replicas, mr) - return } func (mp *MetaPartition) removeReplica(mr *MetaReplica) { @@ -132,7 +131,6 @@ func (mp *MetaPartition) removeReplica(mr *MetaReplica) { newReplicas = append(newReplicas, m) } mp.Replicas = newReplicas - return } func (mp *MetaPartition) removeReplicaByAddr(addr string) { @@ -144,7 +142,6 @@ func (mp *MetaPartition) removeReplicaByAddr(addr string) { newReplicas = append(newReplicas, m) } mp.Replicas = newReplicas - return } func (mp *MetaPartition) updateInodeIDRangeForAllReplicas() { @@ -260,9 +257,7 @@ func (mp *MetaPartition) getMetaReplica(addr string) (mr *MetaReplica, err error } func (mp *MetaPartition) removeMissingReplica(addr string) { - if _, ok := mp.MissNodes[addr]; ok { - delete(mp.MissNodes, addr) - } + delete(mp.MissNodes, addr) } func (mp *MetaPartition) isLeaderExist() bool { @@ -292,7 +287,6 @@ func (mp *MetaPartition) checkLeader(clusterID string) { if WarnMetrics != nil { WarnMetrics.WarnMpNoLeader(clusterID, mp.PartitionID, report) } - return } func (mp *MetaPartition) checkStatus(clusterID string, writeLog bool, replicaNum int, maxPartitionID uint64, metaPartitionInodeIdStep uint64, forbiddenVol bool) (doSplit bool) { @@ -487,7 +481,6 @@ func (mp *MetaPartition) checkReplicas() { mr.Status = proto.Unavailable } } - return } func (mp *MetaPartition) persistToRocksDB(action, volName string, newHosts []string, newPeers []proto.Peer, c *Cluster) (err error) { @@ -600,7 +593,7 @@ func (mp *MetaPartition) replicaCreationTasks(clusterID, volName string) (tasks func (mp *MetaPartition) buildNewMetaPartitionTasks(specifyAddrs []string, peers []proto.Peer, volName string) (tasks []*proto.AdminTask) { tasks = make([]*proto.AdminTask, 0) - hosts := make([]string, 0) + var hosts []string req := &proto.CreateMetaPartitionRequest{ Start: mp.Start, @@ -694,17 +687,6 @@ func (mp *MetaPartition) createTaskToRemoveRaftMember(removePeer proto.Peer) (t return } -func (mp *MetaPartition) createTaskToDecommissionReplica(volName string, removePeer proto.Peer, addPeer proto.Peer) (t *proto.AdminTask, err error) { - mr, err := mp.getMetaReplicaLeader() - if err != nil { - return nil, errors.NewError(err) - } - req := &proto.MetaPartitionDecommissionRequest{PartitionID: mp.PartitionID, VolName: volName, RemovePeer: removePeer, AddPeer: addPeer} - t = proto.NewAdminTask(proto.OpDecommissionMetaPartition, mr.Addr, req) - resetMetaPartitionTaskID(t, mp.PartitionID) - return -} - func resetMetaPartitionTaskID(t *proto.AdminTask, partitionID uint64) { t.ID = fmt.Sprintf("%v_pid[%v]", t.ID, partitionID) t.PartitionID = partitionID @@ -905,21 +887,6 @@ func (mp *MetaPartition) SetTxCnt() { mp.TxCnt, mp.TxRbInoCnt, mp.TxRbDenCnt = txCnt, rbInoCnt, rbDenCnt } -func (mp *MetaPartition) getAllNodeSets() (nodeSets []uint64) { - mp.RLock() - defer mp.RUnlock() - nodeSets = make([]uint64, 0) - for _, mr := range mp.Replicas { - if mr.metaNode == nil { - continue - } - if !containsID(nodeSets, mr.metaNode.NodeSetID) { - nodeSets = append(nodeSets, mr.metaNode.NodeSetID) - } - } - return -} - func (mp *MetaPartition) getLiveZones(offlineAddr string) (zones []string) { mp.RLock() defer mp.RUnlock() diff --git a/master/metadata_fsm_op.go b/master/metadata_fsm_op.go index 6a6f84784..a9da63129 100644 --- a/master/metadata_fsm_op.go +++ b/master/metadata_fsm_op.go @@ -886,11 +886,6 @@ func (c *Cluster) buildPutMetaNodeCmd(opType uint32, metaNode *MetaNode) (metada return } -func (c *Cluster) buildAddMetaNodeCmd(metaNode *MetaNode) (metadata *RaftCmd, err error) { - metadata, err = c.buildPutMetaNodeCmd(opSyncAddMetaNode, metaNode) - return -} - func (c *Cluster) buildDeleteMetaNodeCmd(metaNode *MetaNode) (metadata *RaftCmd, err error) { metadata, err = c.buildPutMetaNodeCmd(opSyncDeleteMetaNode, metaNode) return @@ -922,11 +917,6 @@ func (c *Cluster) syncUpdateDataNode(dataNode *DataNode) (err error) { return c.syncPutDataNode(opSyncUpdateDataNode, dataNode) } -func (c *Cluster) buildAddDataNodeCmd(dataNode *DataNode) (metadata *RaftCmd, err error) { - metadata, err = c.buildPutDataNodeCmd(opSyncAddDataNode, dataNode) - return -} - func (c *Cluster) buildDeleteDataNodeCmd(dataNode *DataNode) (metadata *RaftCmd, err error) { metadata, err = c.buildPutDataNodeCmd(opSyncDeleteDataNode, dataNode) return @@ -1094,7 +1084,6 @@ func (c *Cluster) checkPersistClusterValue() { panic(err) } log.LogInfo("action[checkPersistClusterValue] add cluster value record") - return } func (c *Cluster) loadClusterValue() (err error) { @@ -1286,13 +1275,12 @@ func (c *Cluster) loadZoneDomain() (ok bool, err error) { for zoneName, domainId := range c.domainManager.ZoneName2DomainIdMap { log.LogInfof("action[loadZoneDomain] zoneName %v domainid %v", zoneName, domainId) - if domainIndex, ok := c.domainManager.domainId2IndexMap[domainId]; !ok { + if _, ok := c.domainManager.domainId2IndexMap[domainId]; !ok { log.LogInfof("action[loadZoneDomain] zoneName %v domainid %v build new domainnodesetgrp manager", zoneName, domainId) domainGrp := newDomainNodeSetGrpManager() domainGrp.domainId = domainId c.domainManager.domainNodeSetGrpVec = append(c.domainManager.domainNodeSetGrpVec, domainGrp) - domainIndex = len(c.domainManager.domainNodeSetGrpVec) - 1 - c.domainManager.domainId2IndexMap[domainId] = domainIndex + c.domainManager.domainId2IndexMap[domainId] = len(c.domainManager.domainNodeSetGrpVec) - 1 } } @@ -1732,10 +1720,6 @@ func (c *Cluster) syncDeleteLcNode(ln *LcNode) (err error) { return c.syncPutLcNodeInfo(opSyncDeleteLcNode, ln) } -func (c *Cluster) syncUpdateLcNode(ln *LcNode) (err error) { - return c.syncPutLcNodeInfo(opSyncUpdateLcNode, ln) -} - func (c *Cluster) syncPutLcNodeInfo(opType uint32, ln *LcNode) (err error) { metadata := new(RaftCmd) metadata.Op = opType diff --git a/master/mocktest/meta_server.go b/master/mocktest/meta_server.go index 516bd23d8..5bc601f66 100644 --- a/master/mocktest/meta_server.go +++ b/master/mocktest/meta_server.go @@ -39,7 +39,7 @@ type MockMetaServer struct { func NewMockMetaServer(addr string, zoneName string) *MockMetaServer { mms := &MockMetaServer{ - TcpAddr: addr, partitions: make(map[uint64]*MockMetaPartition, 0), + TcpAddr: addr, partitions: make(map[uint64]*MockMetaPartition), ZoneName: zoneName, mc: master.NewMasterClient([]string{hostAddr}, false), } diff --git a/master/mocktest/partition.go b/master/mocktest/partition.go index 881eb5081..ff8b67001 100644 --- a/master/mocktest/partition.go +++ b/master/mocktest/partition.go @@ -43,10 +43,6 @@ type MockMetaPartition struct { // MockMetaReplica defines the replica of a meta partition type MockMetaReplica struct { Addr string - start uint64 // lower bound of the inode id - end uint64 // upper bound of the inode id - dataSize uint64 - nodeID uint64 MaxInodeID uint64 InodeCount uint64 DentryCount uint64 diff --git a/master/monitor_metrics.go b/master/monitor_metrics.go index 9f587271b..d688484c1 100644 --- a/master/monitor_metrics.go +++ b/master/monitor_metrics.go @@ -483,23 +483,21 @@ func (mm *monitorMetrics) start() { func (mm *monitorMetrics) statMetrics() { ticker := time.NewTicker(StatPeriod) defer func() { + ticker.Stop() if err := recover(); err != nil { ticker.Stop() log.LogErrorf("statMetrics panic,msg:%v", err) } }() - for { - select { - case <-ticker.C: - partition := mm.cluster.partition - if partition != nil && partition.IsRaftLeader() { - mm.resetFollowerMetrics() - mm.doStat() - } else { - mm.resetAllLeaderMetrics() - mm.doFollowerStat() - } + for range ticker.C { + partition := mm.cluster.partition + if partition != nil && partition.IsRaftLeader() { + mm.resetFollowerMetrics() + mm.doStat() + } else { + mm.resetAllLeaderMetrics() + mm.doFollowerStat() } } } @@ -554,11 +552,11 @@ func (mm *monitorMetrics) setMpAndDpMetrics() { vols := mm.cluster.copyVols() for _, vol := range vols { - if (vol.Status == proto.VolStatusMarkDelete && !vol.Forbidden) || (vol.Status == proto.VolStatusMarkDelete && vol.Forbidden && vol.DeleteExecTime.Sub(time.Now()) <= 0) { + if (vol.Status == proto.VolStatusMarkDelete && !vol.Forbidden) || + (vol.Status == proto.VolStatusMarkDelete && vol.Forbidden && time.Until(vol.DeleteExecTime) <= 0) { continue } - var dps *DataPartitionMap - dps = vol.dataPartitions + dps := vol.dataPartitions dpCount += len(dps.partitions) for _, dp := range dps.partitions { if dp.ReplicaNum > uint8(len(dp.liveReplicas(defaultDataPartitionTimeOutSec))) { @@ -580,9 +578,7 @@ func (mm *monitorMetrics) setMpAndDpMetrics() { mm.dataPartitionCount.Set(float64(dpCount)) mm.ReplicaMissingDPCount.Set(float64(dpMissingReplicaDpCount)) mm.DpMissingLeaderCount.Set(float64(dpMissingLeaderCount)) - mm.MpMissingLeaderCount.Set(float64(mpMissingLeaderCount)) - return } func (mm *monitorMetrics) setVolNoCacheMetrics() { @@ -598,7 +594,7 @@ func (mm *monitorMetrics) setVolNoCacheMetrics() { continue } - if stat == true { + if stat { deleteVolNames[volName] = struct{}{} log.LogDebugf("setVolNoCacheMetrics: to deleteVolNames volName %v for status becomes ok", volName) continue @@ -632,9 +628,7 @@ func (mm *monitorMetrics) setVolMetrics() { return true } mm.volNames[volName] = struct{}{} - if _, ok := deleteVolNames[volName]; ok { - delete(deleteVolNames, volName) - } + delete(deleteVolNames, volName) mm.volTotalSpace.SetWithLabelValues(float64(volStatInfo.TotalSize)/float64(util.GB), volName) mm.volUsedSpace.SetWithLabelValues(float64(volStatInfo.UsedSize)/float64(util.GB), volName) @@ -709,7 +703,8 @@ func (mm *monitorMetrics) setMpInconsistentErrorMetric() { defer mm.cluster.volMutex.RUnlock() for _, vol := range mm.cluster.vols { - if (vol.Status == proto.VolStatusMarkDelete && !vol.Forbidden) || (vol.Status == proto.VolStatusMarkDelete && vol.Forbidden && vol.DeleteExecTime.Sub(time.Now()) <= 0) { + if (vol.Status == proto.VolStatusMarkDelete && !vol.Forbidden) || + (vol.Status == proto.VolStatusMarkDelete && vol.Forbidden && time.Until(vol.DeleteExecTime) <= 0) { continue } vol.mpsLock.RLock() @@ -906,7 +901,7 @@ func (mm *monitorMetrics) deleteS3LcVolMetric(volName string) { func (mm *monitorMetrics) setLcMetrics() { lcTaskStatus := mm.cluster.lcMgr.lcRuleTaskStatus - volumeScanStatistics := make(map[string]proto.LcNodeRuleTaskStatistics, 0) + volumeScanStatistics := make(map[string]proto.LcNodeRuleTaskStatistics) lcTaskStatus.RLock() for _, r := range lcTaskStatus.Results { key := r.Volume + "[" + r.RuleId + "]" diff --git a/master/multi_ver_snapshot.go b/master/multi_ver_snapshot.go index a891a744c..fb0fa81e5 100644 --- a/master/multi_ver_snapshot.go +++ b/master/multi_ver_snapshot.go @@ -196,7 +196,7 @@ func (verMgr *VolVersionManager) SetVerStrategy(strategy proto.VolumeVerStrategy log.LogWarnf("vol %v SetVerStrategy.keepCnt %v need in [1-%v], peroidic %v need in [1-%v], enable %v", verMgr.vol.Name, strategy.KeepVerCnt, MaxSnapshotCount, strategy.GetPeriodic(), 24*7, strategy.Enable) - if strategy.Enable == true { + if strategy.Enable { if strategy.KeepVerCnt > MaxSnapshotCount || strategy.GetPeriodic() > 24*7 || strategy.KeepVerCnt < 0 || strategy.GetPeriodic() < 0 { return fmt.Errorf("SetVerStrategy.vol %v keepCnt %v need in [1-%v], peroidic %v need in [1-%v] not qualified", verMgr.vol.Name, strategy.KeepVerCnt, MaxSnapshotCount, strategy.GetPeriodic(), 24*7) @@ -759,18 +759,6 @@ func (verMgr *VolVersionManager) getOldestVer() (ver uint64, status uint8) { return verMgr.multiVersionList[0].Ver, verMgr.multiVersionList[0].Status } -func (verMgr *VolVersionManager) getVolDelStatus() (status uint8) { - verMgr.RLock() - defer verMgr.RUnlock() - - size := len(verMgr.multiVersionList) - if size == 0 { - return 0 - } - log.LogInfof("action[getLatestVer] ver len %v verMgr %v", size, verMgr) - return verMgr.multiVersionList[size-1].Status -} - func (verMgr *VolVersionManager) getLatestVer() (ver uint64) { verMgr.RLock() defer verMgr.RUnlock() diff --git a/master/node_selector_test.go b/master/node_selector_test.go index cb456dda8..8547d09c6 100644 --- a/master/node_selector_test.go +++ b/master/node_selector_test.go @@ -259,13 +259,11 @@ func TestCarryWeightNodeSelector(t *testing.T) { if node == nil { return } - count, _ := dataSelectTimes[node.ID] - count += 1 - dataSelectTimes[node.ID] = count + dataSelectTimes[node.ID]++ } t.Logf("%v data node select times:\n", selector.GetName()) printNodeSelectTimes(t, dataSelectTimes) - count, _ := dataSelectTimes[dataNode.ID] + count := dataSelectTimes[dataNode.ID] for _, c := range dataSelectTimes { if count < c { t.Errorf("%v failed to select data nodes", selector.GetName()) @@ -290,13 +288,11 @@ func TestCarryWeightNodeSelector(t *testing.T) { if node == nil { return } - count, _ := metaSelectTimes[node.ID] - count += 1 - metaSelectTimes[node.ID] = count + metaSelectTimes[node.ID]++ } t.Logf("%v meta node select times:\n", selector.GetName()) printNodeSelectTimes(t, metaSelectTimes) - count, _ = metaSelectTimes[metaNode.ID] + count = metaSelectTimes[metaNode.ID] for _, c := range metaSelectTimes { if count < c { t.Errorf("%v failed to select meta nodes", selector.GetName()) @@ -379,13 +375,11 @@ func TestStrawNodeSelector(t *testing.T) { if node == nil { return } - count, _ := dataSelectTimes[node.ID] - count += 1 - dataSelectTimes[node.ID] = count + dataSelectTimes[node.ID]++ } t.Logf("%v data node select times:\n", selector.GetName()) printNodeSelectTimes(t, dataSelectTimes) - count, _ := dataSelectTimes[dataNode.ID] + count := dataSelectTimes[dataNode.ID] for _, c := range dataSelectTimes { if count < c { t.Errorf("%v failed to select data nodes", selector.GetName()) @@ -406,13 +400,11 @@ func TestStrawNodeSelector(t *testing.T) { if node == nil { return } - count, _ := metaSelectTimes[node.ID] - count += 1 - metaSelectTimes[node.ID] = count + metaSelectTimes[node.ID]++ } t.Logf("%v meta node select times:\n", selector.GetName()) printNodeSelectTimes(t, metaSelectTimes) - count, _ = metaSelectTimes[metaNode.ID] + count = metaSelectTimes[metaNode.ID] for _, c := range metaSelectTimes { if count < c { t.Errorf("%v failed to select meta nodes", selector.GetName()) @@ -480,9 +472,7 @@ func nodeSelectorBench(selector NodeSelector, nset *nodeSet, onSelect func(addr return nil, err } for _, peer := range peers { - count, _ := times[peer.ID] - count += 1 - times[peer.ID] = count + times[peer.ID]++ if onSelect != nil { onSelect(peer.Addr) } diff --git a/master/nodeset_selector_test.go b/master/nodeset_selector_test.go index 8f2274327..e607b77d1 100644 --- a/master/nodeset_selector_test.go +++ b/master/nodeset_selector_test.go @@ -119,8 +119,6 @@ func prepareMetaNodesetForBench(count int, initTotal uint64, grow uint64) (nsc n return } -const loopNodesetSelectorTestCount = 100 - func nodesetSelectorBench(selector NodesetSelector, nsc nodeSetCollection, onSelect func(id uint64)) (map[uint64]int, error) { times := make(map[uint64]int) for i := 0; i < loopNodeSelectorTestCount; i++ { @@ -128,9 +126,7 @@ func nodesetSelectorBench(selector NodesetSelector, nsc nodeSetCollection, onSel if err != nil { return nil, err } - count, _ := times[ns.ID] - count += 1 - times[ns.ID] = count + times[ns.ID]++ if onSelect != nil { onSelect(ns.ID) } diff --git a/master/operate_util.go b/master/operate_util.go index e198649aa..3e8852196 100644 --- a/master/operate_util.go +++ b/master/operate_util.go @@ -31,7 +31,8 @@ import ( func newCreateDataPartitionRequest(volName string, ID uint64, replicaNum int, members []proto.Peer, dataPartitionSize, leaderSize int, hosts []string, createType int, partitionType int, - decommissionedDisks []string, verSeq uint64) (req *proto.CreateDataPartitionRequest) { + decommissionedDisks []string, verSeq uint64, +) (req *proto.CreateDataPartitionRequest) { req = &proto.CreateDataPartitionRequest{ PartitionTyp: partitionType, PartitionId: ID, @@ -133,7 +134,7 @@ func unmarshalTaskResponse(task *proto.AdminTask) (err error) { } func contains(arr []string, element string) (ok bool) { - if arr == nil || len(arr) == 0 { + if len(arr) == 0 { return } @@ -147,7 +148,7 @@ func contains(arr []string, element string) (ok bool) { } func containsID(arr []uint64, element uint64) bool { - if arr == nil || len(arr) == 0 { + if len(arr) == 0 { return false } @@ -161,7 +162,7 @@ func containsID(arr []uint64, element uint64) bool { } func reshuffleHosts(oldHosts []string) (newHosts []string, err error) { - if oldHosts == nil || len(oldHosts) == 0 { + if len(oldHosts) == 0 { log.LogError(fmt.Sprintf("action[reshuffleHosts],err:%v", proto.ErrReshuffleArray)) err = proto.ErrReshuffleArray return @@ -203,10 +204,6 @@ func unmatchedKey(name string) (err error) { return errors.NewErrorf("parameter %v not match", name) } -func txInvalidMask() (err error) { - return errors.New("transaction mask key value pair should be: enableTxMaskKey=[create|mkdir|remove|rename|mknod|symlink|link]\n enableTxMaskKey=off \n enableTxMaskKey=all") -} - func notFoundMsg(name string) (err error) { return errors.NewErrorf("%v not found", name) } @@ -227,10 +224,6 @@ func dataReplicaNotFound(addr string) (err error) { return notFoundMsg(fmt.Sprintf("data replica[%v]", addr)) } -func zoneNotFound(name string) (err error) { - return notFoundMsg(fmt.Sprintf("zone[%v]", name)) -} - func nodeSetNotFound(id uint64) (err error) { return notFoundMsg(fmt.Sprintf("node set[%v]", id)) } @@ -247,10 +240,6 @@ func lcNodeNotFound(addr string) (err error) { return notFoundMsg(fmt.Sprintf("lc node[%v]", addr)) } -func volNotFound(name string) (err error) { - return notFoundMsg(fmt.Sprintf("vol[%v]", name)) -} - func matchKey(serverKey, clientKey string) bool { h := md5.New() _, err := h.Write([]byte(serverKey)) @@ -259,5 +248,5 @@ func matchKey(serverKey, clientKey string) bool { return false } cipherStr := h.Sum(nil) - return strings.ToLower(clientKey) == strings.ToLower(hex.EncodeToString(cipherStr)) + return strings.EqualFold(clientKey, hex.EncodeToString(cipherStr)) } diff --git a/master/server.go b/master/server.go index c115e22ea..16cfa257a 100644 --- a/master/server.go +++ b/master/server.go @@ -79,11 +79,7 @@ var ( var overSoldFactor = defaultOverSoldFactor func overSoldLimit() bool { - if overSoldFactor <= 0 { - return false - } - - return true + return overSoldFactor > 0 } func overSoldCap(cap uint64) uint64 { @@ -100,8 +96,6 @@ 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") - // Server represents the server in a cluster type Server struct { id uint64 @@ -180,7 +174,7 @@ func (m *Server) Start(cfg *config.Config) (err error) { stat.DefaultTimeOutUs, true) m.wg.Add(1) - return nil + return err } // Shutdown closes the server diff --git a/master/snapshot_manager.go b/master/snapshot_manager.go index 93325db14..4b148d2e0 100644 --- a/master/snapshot_manager.go +++ b/master/snapshot_manager.go @@ -176,12 +176,12 @@ func (vs *lcSnapshotVerStatus) DeleteOldResult() { defer vs.Unlock() for k, v := range vs.TaskResults { // delete result that already done - if v.Done == true && time.Now().After(v.EndTime.Add(time.Minute*10)) { + if v.Done && time.Now().After(v.EndTime.Add(time.Minute*10)) { delete(vs.TaskResults, k) log.LogDebugf("delete result already done: %v", v) } // delete result that not done but no updating - if v.Done != true && time.Now().After(v.UpdateTime.Add(time.Minute*10)) { + if !v.Done && time.Now().After(v.UpdateTime.Add(time.Minute*10)) { delete(vs.TaskResults, k) log.LogWarnf("delete result that not done but no updating: %v", v) } diff --git a/master/topology.go b/master/topology.go index d046bfe96..e78471a78 100644 --- a/master/topology.go +++ b/master/topology.go @@ -140,15 +140,6 @@ func (t *topology) deleteDataNode(dataNode *DataNode) { t.dataNodes.Delete(dataNode.Addr) } -func (t *topology) getZoneByDataNode(dataNode *DataNode) (zone *Zone, err error) { - _, ok := t.dataNodes.Load(dataNode.Addr) - if !ok { - return nil, errors.Trace(dataNodeNotFound(dataNode.Addr), "%v not found", dataNode.Addr) - } - - return t.getZone(dataNode.ZoneName) -} - func (t *topology) putMetaNode(metaNode *MetaNode) (err error) { if _, ok := t.metaNodes.Load(metaNode.Addr); ok { return @@ -266,7 +257,7 @@ func (nsgm *DomainManager) start() { } func (nsgm *DomainManager) createDomain(zoneName string) (err error) { - if nsgm.init == false { + if !nsgm.init { return fmt.Errorf("createDomain err [%v]", err) } log.LogInfof("zone name [%v] createDomain", zoneName) @@ -328,7 +319,7 @@ func (nsgm *DomainManager) checkExcludeZoneState() { excludeNeedDomain) nsgm.c.needFaultDomain = true } else { - if nsgm.c.needFaultDomain == true { + if nsgm.c.needFaultDomain { log.LogInfof("action[checkExcludeZoneState] needFaultDomain be set false") } nsgm.c.needFaultDomain = false @@ -456,8 +447,7 @@ func (nsgm *DomainManager) buildNodeSetGrp(domainGrpManager *DomainNodeSetGrpMan return } - var method map[int]buildNodeSetGrpMethod - method = make(map[int]buildNodeSetGrpMethod) + method := make(map[int]buildNodeSetGrpMethod) method[3] = buildNodeSetGrp3Zone method[2] = buildNodeSetGrp2Plus1 method[1] = buildNodeSetGrpOneZone @@ -578,7 +568,8 @@ func (nsgm *DomainManager) getHostFromNodeSetGrpSpecific(domainGrpManager *Domai func (nsgm *DomainManager) getHostFromNodeSetGrp(domainId uint64, replicaNum uint8, createType uint32) ( hosts []string, peers []proto.Peer, - err error) { + err error, +) { var ok bool var index int @@ -893,7 +884,7 @@ func (nsgm *DomainManager) putNodeSet(ns *nodeSet, load bool) (err error) { nsgm.ZoneName2DomainIdMap[ns.zoneName] = 0 } if index, ok = nsgm.domainId2IndexMap[domainId]; !ok { - if domainId > 0 && load == false { // domainId 0 can be created through nodeset create,others be created by createDomain + if domainId > 0 && !load { // domainId 0 can be created through nodeset create,others be created by createDomain err = fmt.Errorf("inconsistent domainid exist in name map but node exist in index map") log.LogErrorf("action[putNodeSet] %v", err) return @@ -1276,12 +1267,6 @@ func (t *topology) getAllZones() (zones []*Zone) { return } -func (t *topology) getZoneByIndex(index int) (zone *Zone) { - t.zoneLock.RLock() - defer t.zoneLock.RUnlock() - return t.zones[index] -} - func (t *topology) getNodeSetByNodeSetId(nodeSetId uint64) (nodeSet *nodeSet, err error) { zones := t.getAllZones() for _, zone := range zones { @@ -1406,15 +1391,6 @@ func (t *topology) allocZonesForDataNode(zoneNum, replicaNum int, excludeZone [] return } -func (ns *nodeSet) dataNodeCount() int { - var count int - ns.dataNodes.Range(func(key, value interface{}) bool { - count++ - return true - }) - return count -} - // Zone stores all the zone related information type Zone struct { name string @@ -1520,12 +1496,6 @@ func (zone *Zone) getStatusToString() string { } } -func (zone *Zone) isSingleNodeSet() bool { - zone.RLock() - defer zone.RUnlock() - return len(zone.nodeSetMap) == 1 -} - func (zone *Zone) getNodeSet(setID uint64) (ns *nodeSet, err error) { zone.nsLock.RLock() defer zone.nsLock.RUnlock() @@ -1653,15 +1623,6 @@ func (zone *Zone) putDataNode(dataNode *DataNode) (err error) { return } -func (zone *Zone) getDataNode(addr string) (dataNode *DataNode, err error) { - value, ok := zone.dataNodes.Load(addr) - if !ok { - return nil, errors.Trace(dataNodeNotFound(addr), "%v not found", addr) - } - dataNode = value.(*DataNode) - return -} - func (zone *Zone) deleteDataNode(dataNode *DataNode) { ns, err := zone.getNodeSet(dataNode.NodeSetID) if err != nil { @@ -1770,7 +1731,7 @@ func (zone *Zone) isUsedRatio(ratio float64) (can bool) { ) zone.dataNodes.Range(func(addr, value interface{}) bool { dataNode := value.(*DataNode) - if dataNode.isActive == true { + if dataNode.isActive { dataNodeUsed += dataNode.Used } else { dataNodeUsed += dataNode.Total @@ -1786,7 +1747,7 @@ func (zone *Zone) isUsedRatio(ratio float64) (can bool) { zone.metaNodes.Range(func(addr, value interface{}) bool { metaNode := value.(*MetaNode) - if metaNode.IsActive == true && metaNode.isWritable() == true { + if metaNode.IsActive && metaNode.isWritable() { metaNodeUsed += metaNode.Used } else { metaNodeUsed += metaNode.Total @@ -1808,7 +1769,7 @@ func (zone *Zone) getDataUsed() (dataNodeUsed uint64, dataNodeTotal uint64) { defer zone.RUnlock() zone.dataNodes.Range(func(addr, value interface{}) bool { dataNode := value.(*DataNode) - if dataNode.isActive == true { + if dataNode.isActive { dataNodeUsed += dataNode.Used } else { dataNodeUsed += dataNode.Total @@ -1826,7 +1787,7 @@ func (zone *Zone) getMetaUsed() (metaNodeUsed uint64, metaNodeTotal uint64) { zone.metaNodes.Range(func(addr, value interface{}) bool { metaNode := value.(*MetaNode) - if metaNode.IsActive == true && metaNode.isWritable() == true { + if metaNode.IsActive && metaNode.isWritable() { metaNodeUsed += metaNode.Used } else { metaNodeUsed += metaNode.Total @@ -1853,7 +1814,7 @@ func (zone *Zone) canWriteForMetaNode(replicaNum uint8) (can bool) { var leastAlive uint8 zone.metaNodes.Range(func(addr, value interface{}) bool { metaNode := value.(*MetaNode) - if metaNode.IsActive == true && metaNode.isWritable() == true { + if metaNode.IsActive && metaNode.isWritable() { leastAlive++ } if leastAlive >= replicaNum { @@ -1865,17 +1826,6 @@ func (zone *Zone) canWriteForMetaNode(replicaNum uint8) (can bool) { return } -func (zone *Zone) getDataNodeMaxTotal() (maxTotal uint64) { - zone.dataNodes.Range(func(key, value interface{}) bool { - dataNode := value.(*DataNode) - if dataNode.Total > maxTotal { - maxTotal = dataNode.Total - } - return true - }) - return -} - func (zone *Zone) getAvailNodeHosts(nodeType uint32, excludeNodeSets []uint64, excludeHosts []string, replicaNum int) (newHosts []string, peers []proto.Peer, err error) { if replicaNum == 0 { return @@ -2169,7 +2119,6 @@ func (l *DecommissionDataPartitionList) pushFailedDp(value *DataPartition, c *Cl l.mu.Unlock() log.LogInfof("action[pushFailedDp] add dp[%v] status[%v] isRecover[%v]", value.PartitionID, status, value.isRecover) - return } func (l *DecommissionDataPartitionList) Remove(value *DataPartition) { diff --git a/master/topology_test.go b/master/topology_test.go index e31b71323..83034f320 100644 --- a/master/topology_test.go +++ b/master/topology_test.go @@ -120,14 +120,14 @@ func TestAllocZones(t *testing.T) { cluster.cfg = newClusterConfig() // don't cross zone - hosts, _, err := cluster.getHostFromNormalZone(TypeDataPartition, nil, nil, nil, replicaNum, 1, "") + _, _, err = cluster.getHostFromNormalZone(TypeDataPartition, nil, nil, nil, replicaNum, 1, "") if err != nil { t.Error(err) return } // cross zone - hosts, _, err = cluster.getHostFromNormalZone(TypeDataPartition, nil, nil, nil, replicaNum, 2, "") + hosts, _, err := cluster.getHostFromNormalZone(TypeDataPartition, nil, nil, nil, replicaNum, 2, "") if err != nil { t.Error(err) return diff --git a/master/user.go b/master/user.go index 1db80c3c2..b32aa498d 100644 --- a/master/user.go +++ b/master/user.go @@ -460,9 +460,7 @@ func (u *User) getUsersOfVol(volName string) (userIDs []string, err error) { } volUser.Mu.RLock() defer volUser.Mu.RUnlock() - for _, userID := range volUser.UserIDs { - userIDs = append(userIDs, userID) - } + userIDs = append(userIDs, volUser.UserIDs...) log.LogInfof("action[getUsersOfVol], vol: %v, user numbers: %v", volName, len(userIDs)) return } diff --git a/master/vol.go b/master/vol.go index d0d058c14..73582cdf5 100644 --- a/master/vol.go +++ b/master/vol.go @@ -40,7 +40,6 @@ type VolVarargs struct { dpSelectorName string dpSelectorParm string coldArgs *coldVolArgs - domainId uint64 dpReplicaNum uint8 enablePosixAcl bool dpReadOnlyWhenVolFull bool @@ -121,8 +120,7 @@ type Vol struct { } func newVol(vv volValue) (vol *Vol) { - vol = &Vol{ID: vv.ID, Name: vv.Name, MetaPartitions: make(map[uint64]*MetaPartition, 0)} - + vol = &Vol{ID: vv.ID, Name: vv.Name, MetaPartitions: make(map[uint64]*MetaPartition)} if vol.threshold <= 0 { vol.threshold = defaultMetaPartitionMemUsageThreshold } @@ -284,9 +282,8 @@ func (mpsLock *mpsLockManager) RUnlock() { func (mpsLock *mpsLockManager) CheckExceptionLock(interval time.Duration, expireTime time.Duration) { ticker := time.NewTicker(interval) - for { - select { - case <-ticker.C: + for range ticker.C { + { if mpsLock.vol.status() == proto.VolStatusMarkDelete || atomic.LoadInt32(&mpsLock.enable) == 0 { break } @@ -331,7 +328,7 @@ func (vol *Vol) CheckStrategy(c *Cluster) { return } vol.VersionMgr.RLock() - if vol.VersionMgr.strategy.GetPeriodicSecond() == 0 || vol.VersionMgr.strategy.Enable == false { // strategy not be set + if vol.VersionMgr.strategy.GetPeriodicSecond() == 0 || !vol.VersionMgr.strategy.Enable { // strategy not be set vol.VersionMgr.RUnlock() continue } @@ -371,8 +368,8 @@ func (vol *Vol) getPreloadCapacity() uint64 { func (vol *Vol) initQosManager(limitArgs *qosArgs) { vol.qosManager = &QosCtrlManager{ - cliInfoMgrMap: make(map[uint64]*ClientInfoMgr, 0), - serverFactorLimitMap: make(map[uint32]*ServerFactorLimit, 0), + cliInfoMgrMap: make(map[uint64]*ClientInfoMgr), + serverFactorLimitMap: make(map[uint32]*ServerFactorLimit), qosEnable: limitArgs.qosEnable, vol: vol, ClientHitTriggerCnt: defaultClientTriggerHitCnt, @@ -793,7 +790,6 @@ func (vol *Vol) checkSplitMetaPartition(c *Cluster, metaPartitionInodeStep uint6 log.LogInfof("volume[%v] split MaxMP[%v], MaxInodeID[%d] Start[%d] RWMPNum[%d] maxMPInodeUsedRatio[%.2f]", vol.Name, maxPartitionID, maxMP.MaxInodeID, maxMP.Start, RWMPNum, maxMPInodeUsedRatio) } - return } func (mp *MetaPartition) memUsedReachThreshold(clusterName, volName string) bool { @@ -820,7 +816,7 @@ func (mp *MetaPartition) memUsedReachThreshold(clusterName, volName string) bool } func (vol *Vol) cloneMetaPartitionMap() (mps map[uint64]*MetaPartition) { - mps = make(map[uint64]*MetaPartition, 0) + mps = make(map[uint64]*MetaPartition) vol.mpsLock.RLock() defer vol.mpsLock.RUnlock() for _, mp := range vol.MetaPartitions { @@ -842,7 +838,7 @@ func (vol *Vol) setMpForbid() { func (vol *Vol) cloneDataPartitionMap() (dps map[uint64]*DataPartition) { vol.dataPartitions.RLock() defer vol.dataPartitions.RUnlock() - dps = make(map[uint64]*DataPartition, 0) + dps = make(map[uint64]*DataPartition) for _, dp := range vol.dataPartitions.partitionMap { dps[dp.PartitionID] = dp } @@ -939,11 +935,7 @@ func (vol *Vol) shouldInhibitWriteBySpaceFull() bool { } usedSpace := vol.totalUsedSpace() / util.GB - if usedSpace >= vol.capacity() { - return true - } - - return false + return usedSpace >= vol.capacity() } func (vol *Vol) needCreateDataPartition() (ok bool, err error) { @@ -1065,21 +1057,6 @@ func (vol *Vol) cfsUsedSpace() uint64 { return vol.dataPartitions.totalUsedSpace() } -func (vol *Vol) sendViewCacheToFollower(c *Cluster) { - var err error - log.LogInfof("action[asyncSendPartitionsToFollower]") - - metadata := new(RaftCmd) - metadata.Op = opSyncDataPartitionsView - metadata.K = vol.Name - metadata.V = vol.dataPartitions.getDataPartitionResponseCache() - - if err = c.submit(metadata); err != nil { - log.LogErrorf("action[asyncSendPartitionsToFollower] error [%v]", err) - } - log.LogInfof("action[asyncSendPartitionsToFollower] finished") -} - func (vol *Vol) ebsUsedSpace() uint64 { size := uint64(0) vol.mpsLock.RLock() @@ -1231,8 +1208,6 @@ func (vol *Vol) checkStatus(c *Cluster) { vol.deleteDataPartitionFromDataNode(c, dataTask) } }() - - return } func (vol *Vol) deleteMetaPartitionFromMetaNode(c *Cluster, task *proto.AdminTask) { @@ -1262,7 +1237,6 @@ func (vol *Vol) deleteMetaPartitionFromMetaNode(c *Cluster, task *proto.AdminTas mp.removeReplicaByAddr(metaNode.Addr) mp.removeMissingReplica(metaNode.Addr) mp.Unlock() - return } func (vol *Vol) deleteDataPartitionFromDataNode(c *Cluster, task *proto.AdminTask) (err error) { @@ -1325,7 +1299,6 @@ func (vol *Vol) deleteMetaPartitionsFromStore(c *Cluster) { for _, mp := range vol.MetaPartitions { c.syncDeleteMetaPartition(mp) } - return } func (vol *Vol) deleteDataPartitionsFromStore(c *Cluster) { @@ -1385,7 +1358,7 @@ func (vol *Vol) doSplitMetaPartition(c *Cluster, mp *MetaPartition, end uint64, } log.LogWarnf("action[splitMetaPartition],partition[%v],start[%v],end[%v],new end[%v]", mp.PartitionID, mp.Start, mp.End, end) - cmdMap := make(map[string]*RaftCmd, 0) + cmdMap := make(map[string]*RaftCmd) oldEnd := mp.End mp.End = end diff --git a/master/vol_test.go b/master/vol_test.go index 3b16dc95f..887d1a77d 100644 --- a/master/vol_test.go +++ b/master/vol_test.go @@ -218,11 +218,9 @@ func createVol(kv map[string]interface{}, t *testing.T) { switch kv[volTypeKey].(int) { case proto.VolumeTypeHot: checkWithDefault(kv, replicaNumKey, 3) - break case proto.VolumeTypeCold: checkWithDefault(kv, cacheCapacity, 80) checkWithDefault(kv, replicaNumKey, 1) - break default: // do nothing } diff --git a/metanode/api_handler.go b/metanode/api_handler.go index 588bd8640..fff58eb31 100644 --- a/metanode/api_handler.go +++ b/metanode/api_handler.go @@ -78,8 +78,7 @@ func (m *MetaNode) registerAPIHandler() (err error) { return } -func (m *MetaNode) getParamsHandler(w http.ResponseWriter, - r *http.Request) { +func (m *MetaNode) getParamsHandler(w http.ResponseWriter, r *http.Request) { resp := NewAPIResponse(http.StatusOK, http.StatusText(http.StatusOK)) params := make(map[string]interface{}) params[metaNodeDeleteBatchCountKey] = DeleteBatchCount() @@ -90,8 +89,7 @@ func (m *MetaNode) getParamsHandler(w http.ResponseWriter, } } -func (m *MetaNode) getSmuxStatHandler(w http.ResponseWriter, - r *http.Request) { +func (m *MetaNode) getSmuxStatHandler(w http.ResponseWriter, r *http.Request) { resp := NewAPIResponse(http.StatusOK, http.StatusText(http.StatusOK)) resp.Data = smuxPool.GetStat() data, _ := resp.Marshal() @@ -100,8 +98,7 @@ func (m *MetaNode) getSmuxStatHandler(w http.ResponseWriter, } } -func (m *MetaNode) getPartitionsHandler(w http.ResponseWriter, - r *http.Request) { +func (m *MetaNode) getPartitionsHandler(w http.ResponseWriter, r *http.Request) { resp := NewAPIResponse(http.StatusOK, http.StatusText(http.StatusOK)) resp.Data = m.metadataManager data, _ := resp.Marshal() @@ -288,7 +285,6 @@ func (m *MetaNode) getSplitKeyHandler(w http.ResponseWriter, r *http.Request) { } else { log.LogDebugf("getSplitKeyHandler") } - return } func (m *MetaNode) getInodeHandler(w http.ResponseWriter, r *http.Request) { @@ -343,7 +339,6 @@ func (m *MetaNode) getInodeHandler(w http.ResponseWriter, r *http.Request) { if len(p.Data) > 0 { resp.Data = json.RawMessage(p.Data) } - return } func (m *MetaNode) getRaftStatusHandler(w http.ResponseWriter, r *http.Request) { @@ -371,8 +366,7 @@ func (m *MetaNode) getRaftStatusHandler(w http.ResponseWriter, r *http.Request) resp.Data = raftStatus } -func (m *MetaNode) getEbsExtentsByInodeHandler(w http.ResponseWriter, - r *http.Request) { +func (m *MetaNode) getEbsExtentsByInodeHandler(w http.ResponseWriter, r *http.Request) { r.ParseForm() resp := NewAPIResponse(http.StatusBadRequest, "") defer func() { @@ -412,11 +406,9 @@ func (m *MetaNode) getEbsExtentsByInodeHandler(w http.ResponseWriter, if len(p.Data) > 0 { resp.Data = json.RawMessage(p.Data) } - return } -func (m *MetaNode) getExtentsByInodeHandler(w http.ResponseWriter, - r *http.Request) { +func (m *MetaNode) getExtentsByInodeHandler(w http.ResponseWriter, r *http.Request) { r.ParseForm() resp := NewAPIResponse(http.StatusBadRequest, "") defer func() { @@ -466,7 +458,6 @@ func (m *MetaNode) getExtentsByInodeHandler(w http.ResponseWriter, if len(p.Data) > 0 { resp.Data = json.RawMessage(p.Data) } - return } func (m *MetaNode) getDentryHandler(w http.ResponseWriter, r *http.Request) { @@ -524,7 +515,6 @@ func (m *MetaNode) getDentryHandler(w http.ResponseWriter, r *http.Request) { if len(p.Data) > 0 { resp.Data = json.RawMessage(p.Data) } - return } func (m *MetaNode) getTxHandler(w http.ResponseWriter, r *http.Request) { @@ -573,7 +563,6 @@ func (m *MetaNode) getTxHandler(w http.ResponseWriter, r *http.Request) { if len(p.Data) > 0 { resp.Data = json.RawMessage(p.Data) } - return } func (m *MetaNode) getRealVerSeq(w http.ResponseWriter, r *http.Request) (verSeq uint64, err error) { @@ -661,7 +650,6 @@ func (m *MetaNode) getAllDentriesHandler(w http.ResponseWriter, r *http.Request) if _, err = w.Write(buff.Bytes()); err != nil { log.LogErrorf("[getAllDentriesHandler] response %s", err) } - return } func (m *MetaNode) getAllTxHandler(w http.ResponseWriter, r *http.Request) { @@ -710,17 +698,11 @@ func (m *MetaNode) getAllTxHandler(w http.ResponseWriter, r *http.Request) { if ino, ok := i.(*TxRollbackInode); ok { _, err = w.Write([]byte(ino.ToString())) - if err != nil { - return false - } - return true + return err == nil } if den, ok := i.(*TxRollbackDentry); ok { _, err = w.Write([]byte(den.ToString())) - if err != nil { - return false - } - return true + return err == nil } val, err = json.Marshal(i) @@ -745,7 +727,6 @@ func (m *MetaNode) getAllTxHandler(w http.ResponseWriter, r *http.Request) { if _, err = w.Write(buff.Bytes()); err != nil { log.LogErrorf("[getAllTxHandler] response %s", err) } - return } func (m *MetaNode) getDirectoryHandler(w http.ResponseWriter, r *http.Request) { @@ -795,7 +776,6 @@ func (m *MetaNode) getDirectoryHandler(w http.ResponseWriter, r *http.Request) { if len(p.Data) > 0 { resp.Data = json.RawMessage(p.Data) } - return } func (m *MetaNode) genClusterVersionFileHandler(w http.ResponseWriter, r *http.Request) { @@ -823,7 +803,6 @@ func (m *MetaNode) genClusterVersionFileHandler(w http.ResponseWriter, r *http.R return } } - return } func (m *MetaNode) getInodeSnapshotHandler(w http.ResponseWriter, r *http.Request) { diff --git a/metanode/api_handler_test.go b/metanode/api_handler_test.go index d93ff15ca..e44475e33 100644 --- a/metanode/api_handler_test.go +++ b/metanode/api_handler_test.go @@ -134,15 +134,14 @@ func getSnapshot(t *testing.T, snapshotFile string, url string) { func TestGetInodeSnapshot(t *testing.T) { url := fmt.Sprintf("http://127.0.0.1:%v%v?pid=%v", PROF_PORT, "/getInodeSnapshot", METAPARTITION_ID) - fmt.Printf(url) - fmt.Printf("\n") + fmt.Println(url) getSnapshot(t, inodeFile, url) } func TestGetDentrySnapshot(t *testing.T) { url := fmt.Sprintf("http://127.0.0.1:%v%v?pid=%v", PROF_PORT, "/getDentrySnapshot", METAPARTITION_ID) - fmt.Printf(url) + fmt.Println(url) getSnapshot(t, dentryFile, url) } diff --git a/metanode/const.go b/metanode/const.go index 98e2009b2..656af1fa2 100644 --- a/metanode/const.go +++ b/metanode/const.go @@ -189,8 +189,6 @@ const ( opFSMVerListSnapShot = 73 ) -var exporterKey string - var ( ErrNoLeader = errors.New("no leader") ErrNotALeader = errors.New("not a leader") @@ -200,16 +198,13 @@ var ( const ( defaultMetadataDir = "metadataDir" defaultRaftDir = "raftDir" - defaultAuthTimeout = 5 // seconds ) // Configuration keys const ( cfgLocalIP = "localIP" - cfgListen = "listen" cfgMetadataDir = "metadataDir" cfgRaftDir = "raftDir" - cfgMasterAddrs = "masterAddrs" // will be deprecated cfgRaftHeartbeatPort = "raftHeartbeatPort" cfgRaftReplicaPort = "raftReplicaPort" cfgDeleteBatchCount = "deleteBatchCount" @@ -248,3 +243,21 @@ const ( MB GB ) + +// TODO: to remove unused by golangci +var ( + _ = opFSMDelVer + _ = opFSMDeletePartition + _ = opFSMSentToChanV1 + _ = opFSMStoreTickV1 + _ = opFSMUpdateSummaryInfo + _ = (*metaPartition).doDeleteMarkedInodes + _ = (*Dentry).getLastestVer + _ = (*Inode).isEkInRefMap + _ = (*metaPartition).notifyRaftFollowerToFreeInodes + _ = (*metaPartition).decommissionPartition + _ = (*metaPartition).getDentryTree + _ = (*metaPartition).internalHasInode + _ = (*metaPartition).fsmDelVerExtents + _ = (*TransactionResource).copyGetTxRbInode +) diff --git a/metanode/dentry.go b/metanode/dentry.go index 74191443d..33cb0a7f2 100644 --- a/metanode/dentry.go +++ b/metanode/dentry.go @@ -703,7 +703,7 @@ func (d *Dentry) UnmarshalKey(k []byte) (err error) { if err = binary.Read(buff, binary.BigEndian, &d.ParentId); err != nil { return } - d.Name = string(buff.Bytes()) + d.Name = buff.String() return } diff --git a/metanode/extend.go b/metanode/extend.go index 1095dabb4..2ab83e20d 100644 --- a/metanode/extend.go +++ b/metanode/extend.go @@ -23,11 +23,6 @@ import ( "github.com/cubefs/cubefs/util/btree" ) -type ExtentVal struct { - dataMap map[string][]byte - verSeq uint64 -} - type Extend struct { inode uint64 dataMap map[string][]byte @@ -178,9 +173,8 @@ func (e *Extend) Get(key []byte) (value []byte, exist bool) { func (e *Extend) Remove(key []byte) { e.mu.Lock() - defer e.mu.Unlock() delete(e.dataMap, string(key)) - return + e.mu.Unlock() } func (e *Extend) Range(visitor func(key, value []byte) bool) { diff --git a/metanode/inode.go b/metanode/inode.go index 2a8f71956..bcf048984 100644 --- a/metanode/inode.go +++ b/metanode/inode.go @@ -136,7 +136,7 @@ func (i *Inode) setVerNoCheck(seq uint64) { func (i *Inode) setVer(seq uint64) { if i.getVer() > seq { - syslog.Println(fmt.Sprintf("inode[%v] old seq [%v] cann't use seq [%v]", i.getVer(), seq, string(debug.Stack()))) + syslog.Printf("inode[%v] old seq [%v] cann't use seq [%v]\n", i.getVer(), seq, string(debug.Stack())) log.LogFatalf("inode[%v] old seq [%v] cann't use seq [%v] stack %v", i.Inode, i.getVer(), seq, string(debug.Stack())) } i.verUpdate(seq) @@ -704,8 +704,6 @@ func (i *Inode) MarshalInodeValue(buff *bytes.Buffer) { if err = binary.Write(buff, binary.BigEndian, i.getVer()); err != nil { panic(err) } - - return } // MarshalValue marshals the value to bytes. diff --git a/metanode/manager.go b/metanode/manager.go index 2b4616faf..67d96b4eb 100644 --- a/metanode/manager.go +++ b/metanode/manager.go @@ -83,7 +83,6 @@ type metadataManager struct { mu sync.RWMutex partitions map[uint64]MetaPartition // Key: metaRangeId, Val: metaPartition metaNode *MetaNode - flDeleteBatchCount atomic.Value fileStatsEnable bool curQuotaGoroutineNum int32 maxQuotaGoroutineNum int32 @@ -377,7 +376,6 @@ func (m *metadataManager) onStop() { // stop sampler close(m.stopC) } - return } // LoadMetaPartition returns the meta partition with the specified volName. @@ -511,7 +509,7 @@ func (m *metadataManager) loadPartitions() (err error) { } func (m *metadataManager) attachPartition(id uint64, partition MetaPartition) (err error) { - syslog.Println(fmt.Sprintf("start load metaPartition %v", id)) + syslog.Printf("start load metaPartition %v\n", id) partition.ForceSetMetaPartitionToLoadding() if err = partition.Start(false); err != nil { msg := fmt.Sprintf("load meta partition %v fail: %v", id, err) @@ -639,10 +637,7 @@ func (m *metadataManager) MarshalJSON() (data []byte, err error) { func (m *metadataManager) QuotaGoroutineIsOver() (lsOver bool) { log.LogInfof("QuotaGoroutineIsOver cur [%v] max [%v]", m.curQuotaGoroutineNum, m.maxQuotaGoroutineNum) - if atomic.LoadInt32(&m.curQuotaGoroutineNum) >= m.maxQuotaGoroutineNum { - return true - } - return false + return atomic.LoadInt32(&m.curQuotaGoroutineNum) >= m.maxQuotaGoroutineNum } func (m *metadataManager) QuotaGoroutineInc(num int32) { diff --git a/metanode/manager_op.go b/metanode/manager_op.go index 5bb0c015b..84ffc7ea9 100644 --- a/metanode/manager_op.go +++ b/metanode/manager_op.go @@ -47,7 +47,6 @@ func (m *metadataManager) checkFollowerRead(volNames []string, partition MetaPar } } partition.SetFollowerRead(false) - return } func (m *metadataManager) checkForbiddenVolume(volNames []string, partition MetaPartition) { @@ -59,7 +58,6 @@ func (m *metadataManager) checkForbiddenVolume(volNames []string, partition Meta } } partition.SetForbidden(false) - return } func (m *metadataManager) checkDisableAuditLogVolume(volNames []string, partition MetaPartition) { @@ -71,11 +69,9 @@ func (m *metadataManager) checkDisableAuditLogVolume(volNames []string, partitio } } partition.SetEnableAuditLog(true) - return } -func (m *metadataManager) opMasterHeartbeat(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMasterHeartbeat(conn net.Conn, p *Packet, remoteAddr string) (err error) { // For ack to master data := p.Data m.responseAckOKToMaster(conn, p) @@ -164,8 +160,7 @@ func (m *metadataManager) opMasterHeartbeat(conn net.Conn, p *Packet, return } -func (m *metadataManager) opCreateMetaPartition(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opCreateMetaPartition(conn net.Conn, p *Packet, remoteAddr string) (err error) { defer func() { var buf []byte status := proto.OpOk @@ -201,8 +196,7 @@ func (m *metadataManager) opCreateMetaPartition(conn net.Conn, p *Packet, } // Handle OpCreate inode. -func (m *metadataManager) opCreateInode(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opCreateInode(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &CreateInoReq{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -300,8 +294,7 @@ func (m *metadataManager) opTxMetaLinkInode(conn net.Conn, p *Packet, remoteAddr return } -func (m *metadataManager) opMetaLinkInode(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaLinkInode(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &LinkInodeReq{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -333,8 +326,7 @@ func (m *metadataManager) opMetaLinkInode(conn net.Conn, p *Packet, } // Handle OpCreate -func (m *metadataManager) opFreeInodeOnRaftFollower(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opFreeInodeOnRaftFollower(conn net.Conn, p *Packet, remoteAddr string) (err error) { mp, err := m.getPartition(p.PartitionID) if err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -350,8 +342,7 @@ func (m *metadataManager) opFreeInodeOnRaftFollower(conn net.Conn, p *Packet, } // Handle OpCreate -func (m *metadataManager) opTxCreateDentry(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opTxCreateDentry(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.TxCreateDentryRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -385,8 +376,7 @@ func (m *metadataManager) opTxCreateDentry(conn net.Conn, p *Packet, return } -func (m *metadataManager) opTxCreate(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opTxCreate(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.TxCreateRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -415,8 +405,7 @@ func (m *metadataManager) opTxCreate(conn net.Conn, p *Packet, return } -func (m *metadataManager) opTxGet(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opTxGet(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.TxGetInfoRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -447,8 +436,7 @@ func (m *metadataManager) opTxGet(conn net.Conn, p *Packet, return } -func (m *metadataManager) opTxCommitRM(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opTxCommitRM(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.TxApplyRMRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -477,8 +465,7 @@ func (m *metadataManager) opTxCommitRM(conn net.Conn, p *Packet, return } -func (m *metadataManager) opTxRollbackRM(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opTxRollbackRM(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.TxApplyRMRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -507,8 +494,7 @@ func (m *metadataManager) opTxRollbackRM(conn net.Conn, p *Packet, return } -func (m *metadataManager) opTxCommit(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opTxCommit(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.TxApplyRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -537,8 +523,7 @@ func (m *metadataManager) opTxCommit(conn net.Conn, p *Packet, return } -func (m *metadataManager) opTxRollback(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opTxRollback(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.TxApplyRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -568,8 +553,7 @@ func (m *metadataManager) opTxRollback(conn net.Conn, p *Packet, } // Handle OpCreate -func (m *metadataManager) opCreateDentry(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opCreateDentry(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &CreateDentryReq{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -601,8 +585,7 @@ func (m *metadataManager) opCreateDentry(conn net.Conn, p *Packet, return } -func (m *metadataManager) opQuotaCreateDentry(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opQuotaCreateDentry(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.QuotaCreateDentryRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -635,8 +618,7 @@ func (m *metadataManager) opQuotaCreateDentry(conn net.Conn, p *Packet, } // Handle OpDelete Dentry -func (m *metadataManager) opTxDeleteDentry(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opTxDeleteDentry(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.TxDeleteDentryRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -666,8 +648,7 @@ func (m *metadataManager) opTxDeleteDentry(conn net.Conn, p *Packet, } // Handle OpDelete Dentry -func (m *metadataManager) opDeleteDentry(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opDeleteDentry(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &DeleteDentryReq{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -701,8 +682,7 @@ func (m *metadataManager) opDeleteDentry(conn net.Conn, p *Packet, } // Handle Op batch Delete Dentry -func (m *metadataManager) opBatchDeleteDentry(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opBatchDeleteDentry(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &BatchDeleteDentryReq{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -767,8 +747,7 @@ func (m *metadataManager) opTxUpdateDentry(conn net.Conn, p *Packet, remoteAddr return } -func (m *metadataManager) opUpdateDentry(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opUpdateDentry(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &UpdateDentryReq{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -834,8 +813,7 @@ func (m *metadataManager) opTxMetaUnlinkInode(conn net.Conn, p *Packet, remoteAd return } -func (m *metadataManager) opMetaUnlinkInode(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaUnlinkInode(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &UnlinkInoReq{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -866,8 +844,7 @@ func (m *metadataManager) opMetaUnlinkInode(conn net.Conn, p *Packet, return } -func (m *metadataManager) opMetaBatchUnlinkInode(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaBatchUnlinkInode(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &BatchUnlinkInoReq{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -898,8 +875,7 @@ func (m *metadataManager) opMetaBatchUnlinkInode(conn net.Conn, p *Packet, return } -func (m *metadataManager) opReadDirOnly(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opReadDirOnly(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.ReadDirOnlyRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -925,8 +901,7 @@ func (m *metadataManager) opReadDirOnly(conn net.Conn, p *Packet, } // Handle OpReadDir -func (m *metadataManager) opReadDir(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opReadDir(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.ReadDirRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -952,8 +927,7 @@ func (m *metadataManager) opReadDir(conn net.Conn, p *Packet, } // Handle OpReadDirLimit -func (m *metadataManager) opReadDirLimit(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opReadDirLimit(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.ReadDirLimitRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -978,9 +952,7 @@ func (m *metadataManager) opReadDirLimit(conn net.Conn, p *Packet, return } -func (m *metadataManager) opMetaInodeGet(conn net.Conn, p *Packet, - remoteAddr string) (err error, -) { +func (m *metadataManager) opMetaInodeGet(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &InodeGetReq{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -1001,6 +973,7 @@ func (m *metadataManager) opMetaInodeGet(conn net.Conn, p *Packet, } if err = mp.InodeGet(req, p); err != nil { err = errors.NewErrorf("InodeGet [%v],req[%v],err[%v]", p.GetOpMsgWithReqAndResult(), req, string(p.Data)) + log.LogDebug(err) } if err = m.respondToClient(conn, p); err != nil { @@ -1023,8 +996,7 @@ func (m *metadataManager) opMetaInodeGet(conn net.Conn, p *Packet, return } -func (m *metadataManager) opBatchMetaEvictInode(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opBatchMetaEvictInode(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.BatchEvictInodeRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, []byte(err.Error())) @@ -1057,8 +1029,7 @@ func (m *metadataManager) opBatchMetaEvictInode(conn net.Conn, p *Packet, return } -func (m *metadataManager) opMetaEvictInode(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaEvictInode(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.EvictInodeRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -1091,8 +1062,7 @@ func (m *metadataManager) opMetaEvictInode(conn net.Conn, p *Packet, return } -func (m *metadataManager) opSetAttr(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opSetAttr(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &SetattrRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -1128,8 +1098,7 @@ func (m *metadataManager) opSetAttr(conn net.Conn, p *Packet, } // Lookup request -func (m *metadataManager) opMetaLookup(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaLookup(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.LookupRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -1162,8 +1131,7 @@ func (m *metadataManager) opMetaLookup(conn net.Conn, p *Packet, return } -func (m *metadataManager) opMetaExtentsAdd(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaExtentsAdd(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.AppendExtentKeyRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -1199,8 +1167,7 @@ func (m *metadataManager) opMetaExtentsAdd(conn net.Conn, p *Packet, } // Append one extent with discard check -func (m *metadataManager) opMetaExtentAddWithCheck(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaExtentAddWithCheck(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.AppendExtentKeyWithCheckRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -1237,8 +1204,7 @@ func (m *metadataManager) opMetaExtentAddWithCheck(conn net.Conn, p *Packet, return } -func (m *metadataManager) opMetaExtentsList(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaExtentsList(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.GetExtentsRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -1266,8 +1232,7 @@ func (m *metadataManager) opMetaExtentsList(conn net.Conn, p *Packet, return } -func (m *metadataManager) opMetaObjExtentsList(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaObjExtentsList(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.GetExtentsRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -1293,8 +1258,7 @@ func (m *metadataManager) opMetaObjExtentsList(conn net.Conn, p *Packet, return } -func (m *metadataManager) opMetaExtentsDel(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaExtentsDel(conn net.Conn, p *Packet, remoteAddr string) (err error) { panic("not implemented yet") // req := &proto.DelExtentKeyRequest{} // if err = json.Unmarshal(p.Data, req); err != nil { @@ -1320,8 +1284,7 @@ func (m *metadataManager) opMetaExtentsDel(conn net.Conn, p *Packet, // return } -func (m *metadataManager) opMetaExtentsTruncate(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaExtentsTruncate(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &ExtentsTruncateReq{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -1352,8 +1315,7 @@ func (m *metadataManager) opMetaExtentsTruncate(conn net.Conn, p *Packet, return } -func (m *metadataManager) opMetaClearInodeCache(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaClearInodeCache(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.ClearInodeCacheRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -1379,8 +1341,7 @@ func (m *metadataManager) opMetaClearInodeCache(conn net.Conn, p *Packet, } // Delete a meta partition. -func (m *metadataManager) opDeleteMetaPartition(conn net.Conn, - p *Packet, remoteAddr string) (err error) { +func (m *metadataManager) opDeleteMetaPartition(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.DeleteMetaPartitionRequest{} adminTask := &proto.AdminTask{ Request: req, @@ -1413,8 +1374,7 @@ func (m *metadataManager) opDeleteMetaPartition(conn net.Conn, return } -func (m *metadataManager) opUpdateMetaPartition(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opUpdateMetaPartition(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := new(UpdatePartitionReq) adminTask := &proto.AdminTask{ Request: req, @@ -1453,8 +1413,7 @@ func (m *metadataManager) opUpdateMetaPartition(conn net.Conn, p *Packet, return } -func (m *metadataManager) opLoadMetaPartition(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opLoadMetaPartition(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.MetaPartitionLoadRequest{} adminTask := &proto.AdminTask{ Request: req, @@ -1488,8 +1447,7 @@ func (m *metadataManager) opLoadMetaPartition(conn net.Conn, p *Packet, return } -func (m *metadataManager) opDecommissionMetaPartition(conn net.Conn, - p *Packet, remoteAddr string) (err error) { +func (m *metadataManager) opDecommissionMetaPartition(conn net.Conn, p *Packet, remoteAddr string) (err error) { var reqData []byte req := &proto.MetaPartitionDecommissionRequest{} adminTask := &proto.AdminTask{ @@ -1547,8 +1505,7 @@ func (m *metadataManager) opDecommissionMetaPartition(conn net.Conn, return } -func (m *metadataManager) opAddMetaPartitionRaftMember(conn net.Conn, - p *Packet, remoteAddr string) (err error) { +func (m *metadataManager) opAddMetaPartitionRaftMember(conn net.Conn, p *Packet, remoteAddr string) (err error) { var reqData []byte req := &proto.AddMetaPartitionRaftMemberRequest{} adminTask := &proto.AdminTask{ @@ -1616,8 +1573,7 @@ func (m *metadataManager) opAddMetaPartitionRaftMember(conn net.Conn, return } -func (m *metadataManager) opRemoveMetaPartitionRaftMember(conn net.Conn, - p *Packet, remoteAddr string) (err error) { +func (m *metadataManager) opRemoveMetaPartitionRaftMember(conn net.Conn, p *Packet, remoteAddr string) (err error) { var reqData []byte req := &proto.RemoveMetaPartitionRaftMemberRequest{} adminTask := &proto.AdminTask{ @@ -1694,8 +1650,7 @@ func (m *metadataManager) opRemoveMetaPartitionRaftMember(conn net.Conn, return } -func (m *metadataManager) opMetaBatchInodeGet(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaBatchInodeGet(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.BatchInodeGetRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -1721,8 +1676,7 @@ func (m *metadataManager) opMetaBatchInodeGet(conn net.Conn, p *Packet, return } -func (m *metadataManager) opMetaPartitionTryToLeader(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaPartitionTryToLeader(conn net.Conn, p *Packet, remoteAddr string) (err error) { mp, err := m.getPartition(p.PartitionID) if err != nil { goto errDeal @@ -1739,8 +1693,7 @@ errDeal: return } -func (m *metadataManager) opMetaDeleteInode(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaDeleteInode(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.DeleteInodeRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -1765,8 +1718,7 @@ func (m *metadataManager) opMetaDeleteInode(conn net.Conn, p *Packet, return } -func (m *metadataManager) opMetaBatchDeleteInode(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaBatchDeleteInode(conn net.Conn, p *Packet, remoteAddr string) (err error) { var req *proto.DeleteInodeBatchRequest if err = json.Unmarshal(p.Data, &req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -2214,8 +2166,7 @@ func (m *metadataManager) opListMultipart(conn net.Conn, p *Packet, remoteAddr s } // Handle OpMetaTxCreateInode inode. -func (m *metadataManager) opTxCreateInode(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opTxCreateInode(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.TxCreateInodeRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -2351,8 +2302,7 @@ func (m *metadataManager) opMetaGetInodeQuota(conn net.Conn, p *Packet, remote s return } -func (m *metadataManager) opMetaGetUniqID(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMetaGetUniqID(conn net.Conn, p *Packet, remoteAddr string) (err error) { req := &proto.GetUniqIDRequest{} if err = json.Unmarshal(p.Data, req); err != nil { p.PacketErrorWithBody(proto.OpErr, ([]byte)(err.Error())) @@ -2539,7 +2489,6 @@ func (m *metadataManager) updatePackRspSeq(mp MetaPartition, p *Packet) { p.VerList = make([]*proto.VolVersionInfo, len(mp.GetVerList())) copy(p.VerList, mp.GetVerList()) } - return } func (m *metadataManager) checkMultiVersionStatus(mp MetaPartition, p *Packet) (err error) { @@ -2628,8 +2577,7 @@ func (m *metadataManager) checkAndPromoteVersion(volName string) (err error) { return } -func (m *metadataManager) opMultiVersionOp(conn net.Conn, p *Packet, - remoteAddr string) (err error) { +func (m *metadataManager) opMultiVersionOp(conn net.Conn, p *Packet, remoteAddr string) (err error) { // For ack to master data := p.Data m.responseAckOKToMaster(conn, p) diff --git a/metanode/meta_quota_manager.go b/metanode/meta_quota_manager.go index 068008838..018d8f182 100644 --- a/metanode/meta_quota_manager.go +++ b/metanode/meta_quota_manager.go @@ -194,7 +194,6 @@ func (mqMgr *MetaQuotaManager) setQuotaHbInfo(infos []*proto.QuotaHeartBeatInfo) } return true }) - return } func (mqMgr *MetaQuotaManager) getQuotaReportInfos() (infos []*proto.QuotaReportInfo) { @@ -331,7 +330,6 @@ func (mqMgr *MetaQuotaManager) updateUsedInfo(size int64, files int64, quotaId u mqMgr.statisticRebuildTemp.Store(quotaId, baseTemp) } log.LogDebugf("updateUsedInfo mpId [%v] quotaId [%v] baseInfo [%v] baseTemp[%v]", mqMgr.mpID, quotaId, baseInfo, baseTemp) - return } func (mqMgr *MetaQuotaManager) EnableQuota() bool { diff --git a/metanode/metanode.go b/metanode/metanode.go index 2481cf7c7..cf9f3c459 100644 --- a/metanode/metanode.go +++ b/metanode/metanode.go @@ -271,7 +271,7 @@ func (m *MetaNode) parseConfig(cfg *config.Config) (err error) { if cfg.HasKey(cfgRaftSyncSnapFormatVersion) { raftSyncSnapFormatVersion := uint32(cfg.GetInt64(cfgRaftSyncSnapFormatVersion)) - if raftSyncSnapFormatVersion < 0 || raftSyncSnapFormatVersion > SnapFormatVersion_1 { + if raftSyncSnapFormatVersion > SnapFormatVersion_1 { m.raftSyncSnapFormatVersion = SnapFormatVersion_1 log.LogInfof("invalid config raftSyncSnapFormatVersion, using default[%v]", m.raftSyncSnapFormatVersion) } else { diff --git a/metanode/metrics.go b/metanode/metrics.go index d17367923..0746a54de 100644 --- a/metanode/metrics.go +++ b/metanode/metrics.go @@ -42,7 +42,7 @@ type MetaNodeMetrics struct { func (m *MetaNode) startStat() { m.metrics = &MetaNodeMetrics{ - metricStopCh: make(chan struct{}, 0), + metricStopCh: make(chan struct{}), MetricConnectionCount: exporter.NewGauge(MetricConnectionCount), MetricMetaFailedPartition: exporter.NewGauge(MetricMetaFailedPartition), diff --git a/metanode/multi_ver_test.go b/metanode/multi_ver_test.go index 13e82f7e1..45efd6561 100644 --- a/metanode/multi_ver_test.go +++ b/metanode/multi_ver_test.go @@ -64,10 +64,6 @@ var cfgJSON = `{ }` var tlog *testing.T -func tLogf(format string, args ...interface{}) { - tlog.Log(fmt.Sprintf(format, args...)) -} - func newPartition(conf *MetaPartitionConfig, manager *metadataManager) (mp *metaPartition) { mp = &metaPartition{ config: conf, @@ -102,7 +98,6 @@ func init() { return } log.LogDebugf("action start") - return } func initMp(t *testing.T) { @@ -605,7 +600,7 @@ func TestAppendList(t *testing.T) { mp.verSeq = iTmp.getVer() mp.fsmAppendExtentsWithCheck(iTmp, true) - getExtRsp = testGetExtList(t, ino, ino.getLayerVer(0)) + _ = testGetExtList(t, ino, ino.getLayerVer(0)) assert.True(t, len(ino.Extents.eks) == lastTopEksLen+2) assert.True(t, checkOffSetInSequnce(t, ino.Extents.eks)) @@ -988,7 +983,6 @@ func testDeleteDirTree(t *testing.T, parentId uint64, verSeq uint64) { log.LogDebugf("action[testDeleteDirTree] seq [%v] delete children %v", verSeq, child) testDeleteFile(t, verSeq, parentId, &child) } - return } func testCleanSnapshot(t *testing.T, verSeq uint64) { @@ -999,7 +993,6 @@ func testCleanSnapshot(t *testing.T, verSeq uint64) { verSeq = math.MaxUint64 } testDeleteDirTree(t, 1, verSeq) - return } // create @@ -1574,12 +1567,7 @@ func TestGetAllVerList(t *testing.T) { mp.multiVersionList.VerList = append(mp.multiVersionList.VerList[:1], mp.multiVersionList.VerList[2:]...) tmp = append(tmp, &proto.VolVersionInfo{Ver: 30, Status: proto.VersionNormal}) - sort.SliceStable(tmp, func(i, j int) bool { - if tmp[i].Ver < tmp[j].Ver { - return true - } - return false - }) + sort.SliceStable(tmp, func(i, j int) bool { return tmp[i].Ver < tmp[j].Ver }) t.Logf("tmp[%v]", tmp) t.Logf("mp.multiVersionList %v", mp.multiVersionList) diff --git a/metanode/multipart.go b/metanode/multipart.go index 4bf122ff4..e389d327c 100644 --- a/metanode/multipart.go +++ b/metanode/multipart.go @@ -99,7 +99,7 @@ func PartFromBytes(raw []byte) *Part { offset += n // decode inode var inode uint64 - inode, n = binary.Uvarint(raw[offset:]) + inode, _ = binary.Uvarint(raw[offset:]) muPart := &Part{ ID: uint16(u64ID), diff --git a/metanode/multipart_test.go b/metanode/multipart_test.go index db2000301..81ba56f1c 100644 --- a/metanode/multipart_test.go +++ b/metanode/multipart_test.go @@ -65,7 +65,7 @@ func TestMUParts_Bytes(t *testing.T) { parts1.Insert(part, false) } var partsBytes []byte - partsBytes, err = parts1.Bytes() + parts1.Bytes() if partsBytes, err = parts1.Bytes(); err != nil { t.Fatalf("get bytes of part fail cause: %v", err) } diff --git a/metanode/nodeinfo.go b/metanode/nodeinfo.go index 8688b30a7..9f931480a 100644 --- a/metanode/nodeinfo.go +++ b/metanode/nodeinfo.go @@ -19,7 +19,7 @@ type NodeInfo struct { var ( nodeInfo = &NodeInfo{} - nodeInfoStopC = make(chan struct{}, 0) + nodeInfoStopC = make(chan struct{}) deleteWorkerSleepMs uint64 = 0 dirChildrenNumLimit uint32 = proto.DefaultDirChildrenNumLimit ) @@ -40,10 +40,6 @@ func updateDeleteWorkerSleepMs(val uint64) { atomic.StoreUint64(&deleteWorkerSleepMs, val) } -func updateDirChildrenNumLimit(val uint32) { - atomic.StoreUint32(&dirChildrenNumLimit, val) -} - func DeleteWorkerSleepMs() { val := atomic.LoadUint64(&deleteWorkerSleepMs) if val > 0 { diff --git a/metanode/partition.go b/metanode/partition.go index b124b7276..c103f279e 100644 --- a/metanode/partition.go +++ b/metanode/partition.go @@ -107,10 +107,6 @@ func (c *MetaPartitionConfig) checkMeta() (err error) { "now partition id is: %d", c.PartitionId) return } - if c.Start < 0 { - err = errors.NewErrorf("[checkMeta]: start at least 0") - return - } if c.End <= c.Start { err = errors.NewErrorf("[checkMeta]: end=%v, "+ "start=%v; end <= start", c.End, c.Start) @@ -288,8 +284,6 @@ type UidManager struct { accumRebuildDelta *sync.Map // snapshot redoLog accumRebuildBase *sync.Map // snapshot mirror uidAcl *sync.Map - lastUpdateTime time.Time - enable bool rbuilding bool volName string acLock sync.RWMutex @@ -503,7 +497,6 @@ type metaPartition struct { vol *Vol manager *metadataManager isLoadingMetaPartition bool - summaryLock sync.Mutex ebsClient *blobstore.BlobStoreClient volType int isFollowerRead bool @@ -515,7 +508,6 @@ type metaPartition struct { uniqChecker *uniqChecker verSeq uint64 multiVersionList *proto.VolVersionInfoList - versionLock sync.Mutex verUpdateChan chan []byte enableAuditLog bool } @@ -574,10 +566,7 @@ func (mp *metaPartition) GetAllVerList() (verList []*proto.VolVersionInfo) { verList = append(verList, verInfo) } sort.SliceStable(verList, func(i, j int) bool { - if verList[i].Ver < verList[j].Ver { - return true - } - return false + return verList[i].Ver < verList[j].Ver }) return } @@ -838,8 +827,8 @@ func (mp *metaPartition) stopRaft() { if mp.raftPartition != nil { // TODO Unhandled errors // mp.raftPartition.Stop() + _ = struct{}{} } - return } func (mp *metaPartition) getRaftPort() (heartbeat, replica int, err error) { @@ -905,7 +894,6 @@ func (mp *metaPartition) SetFollowerRead(fRead bool) { return } mp.isFollowerRead = fRead - return } // IsLeader returns the raft leader address and if the current meta partition is the leader. @@ -1142,7 +1130,6 @@ func (mp *metaPartition) store(sm *storeMsg) (err error) { // TODO Unhandled errors os.RemoveAll(tmpDir) } - err = nil if err = os.MkdirAll(tmpDir, 0o775); err != nil { return } @@ -1261,7 +1248,8 @@ func (mp *metaPartition) GetBaseConfig() MetaPartitionConfig { // UpdatePartition updates the meta partition. TODO remove? no usage? func (mp *metaPartition) UpdatePartition(req *UpdatePartitionReq, - resp *UpdatePartitionResp) (err error) { + resp *UpdatePartitionResp, +) (err error) { reqData, err := json.Marshal(req) if err != nil { resp.Status = proto.TaskFailed @@ -1425,8 +1413,6 @@ func (mp *metaPartition) multiVersionTTLWork(dur time.Duration) { return } } - - return } func (mp *metaPartition) delPartitionVersion(verSeq uint64) { @@ -1566,8 +1552,6 @@ func (mp *metaPartition) delPartitionInodesVersion(verSeq uint64, wg *sync.WaitG } return true }) - - return } // cacheTTLWork only happen in datalake situation diff --git a/metanode/partition_delete_extents.go b/metanode/partition_delete_extents.go index df64ae100..5041d68e0 100644 --- a/metanode/partition_delete_extents.go +++ b/metanode/partition_delete_extents.go @@ -35,7 +35,6 @@ import ( const ( prefixDelExtent = "EXTENT_DEL" prefixDelExtentV2 = "EXTENT_DEL_V2" - prefixMultiVer = verdataFile maxDeleteExtentSize = 10 * MB ) diff --git a/metanode/partition_file_stats.go b/metanode/partition_file_stats.go index bb1bd12fb..54afec2eb 100644 --- a/metanode/partition_file_stats.go +++ b/metanode/partition_file_stats.go @@ -76,7 +76,7 @@ func (mp *metaPartition) fileStats(ino *Inode) { } fileRange := mp.fileRange if ino.NLink > 0 && proto.IsRegular(ino.Type) { - if 0 <= ino.Size && ino.Size < Size1K { + if ino.Size < Size1K { fileRange[LessThan1K] += 1 } else if Size1K <= ino.Size && ino.Size < Size1M { fileRange[LessThan1M] += 1 diff --git a/metanode/partition_free_list.go b/metanode/partition_free_list.go index 47f053a5d..48b4ead36 100644 --- a/metanode/partition_free_list.go +++ b/metanode/partition_free_list.go @@ -199,7 +199,8 @@ func (mp *metaPartition) deleteWorker() { // delete Extents by Partition,and find all successDelete inode func (mp *metaPartition) batchDeleteExtentsByPartition(partitionDeleteExtents map[uint64][]*proto.ExtentKey, - allInodes []*Inode) (shouldCommit []*Inode, shouldPushToFreeList []*Inode) { + allInodes []*Inode, +) (shouldCommit []*Inode, shouldPushToFreeList []*Inode) { occurErrors := make(map[uint64]error) shouldCommit = make([]*Inode, 0, len(allInodes)) shouldPushToFreeList = make([]*Inode, 0) @@ -266,8 +267,6 @@ func (mp *metaPartition) deleteMarkedInodes(inoSlice []uint64) { return } log.LogDebugf("[deleteMarkedInodes] . mp[%v] inoSlice [%v]", mp.config.PartitionId, inoSlice) - shouldCommit := make([]*Inode, 0, DeleteBatchCount()) - shouldRePushToFreeList := make([]*Inode, 0) deleteExtentsByPartition := make(map[uint64][]*proto.ExtentKey) allInodes := make([]*Inode, 0) for _, ino := range inoSlice { @@ -306,6 +305,7 @@ func (mp *metaPartition) deleteMarkedInodes(inoSlice []uint64) { allInodes = append(allInodes, inode) } + var shouldCommit, shouldRePushToFreeList []*Inode if proto.IsCold(mp.volType) { // delete ebs obj extents shouldCommit, shouldRePushToFreeList = mp.doBatchDeleteObjExtentsInEBS(allInodes) @@ -392,7 +392,6 @@ func (mp *metaPartition) notifyRaftFollowerToFreeInodes(wg *sync.WaitGroup, targ func (mp *metaPartition) doDeleteMarkedInodes(ext *proto.ExtentKey) (err error) { // get the data node view dp := mp.vol.GetPartition(ext.PartitionId) - log.LogDebugf("action[doDeleteMarkedInodes] dp(%v) status (%v)", dp.PartitionID, dp.Status) if dp == nil { if proto.IsCold(mp.volType) { log.LogInfof("[doDeleteMarkedInodes] ext(%s) is already been deleted, not delete any more", ext.String()) @@ -403,6 +402,7 @@ func (mp *metaPartition) doDeleteMarkedInodes(ext *proto.ExtentKey) (err error) ext.PartitionId) return } + log.LogDebugf("action[doDeleteMarkedInodes] dp(%v) status (%v)", dp.PartitionID, dp.Status) // delete the data node if len(dp.Hosts) < 1 { @@ -493,8 +493,6 @@ func (mp *metaPartition) doBatchDeleteExtentsByPartition(partitionID uint64, ext conn, err := smuxPool.GetConnect(addr) log.LogInfof("doBatchDeleteExtentsByPartition mp (%v) GetConnect (%v)", mp.config.PartitionId, addr) - ResultCode := proto.OpOk - defer func() { smuxPool.PutConnect(conn, ForceClosedConnect) log.LogInfof("doBatchDeleteExtentsByPartition mp (%v) PutConnect (%v)", mp.config.PartitionId, addr) @@ -518,8 +516,7 @@ func (mp *metaPartition) doBatchDeleteExtentsByPartition(partitionID uint64, ext return } - ResultCode = p.ResultCode - + ResultCode := p.ResultCode if ResultCode == proto.OpTryOtherAddr && proto.IsCold(mp.volType) { log.LogInfof("[doBatchDeleteExtentsByPartition] deleteOp retrun tryOtherAddr code means dp is deleted for LF vol, dp(%d)", partitionID) return diff --git a/metanode/partition_fsmop_dentry.go b/metanode/partition_fsmop_dentry.go index 54f7ca74b..e681de16a 100644 --- a/metanode/partition_fsmop_dentry.go +++ b/metanode/partition_fsmop_dentry.go @@ -68,8 +68,7 @@ func (mp *metaPartition) fsmTxCreateDentry(txDentry *TxDentry) (status uint8) { } // Insert a dentry into the dentry tree. -func (mp *metaPartition) fsmCreateDentry(dentry *Dentry, - forceUpdate bool) (status uint8) { +func (mp *metaPartition) fsmCreateDentry(dentry *Dentry, forceUpdate bool) (status uint8) { status = proto.OpOk var parIno *Inode if !forceUpdate { @@ -158,11 +157,9 @@ func (mp *metaPartition) getDentryList(dentry *Dentry) (denList []proto.DetryInf // Query a dentry from the dentry tree with specified dentry info. func (mp *metaPartition) getDentry(dentry *Dentry) (*Dentry, uint8) { - status := proto.OpOk item := mp.dentryTree.Get(dentry) if item == nil { - status = proto.OpNotExistErr - return nil, status + return nil, proto.OpNotExistErr } log.LogDebugf("action[getDentry] get dentry[%v] by req dentry %v", item.(*Dentry), dentry) @@ -265,9 +262,10 @@ func (mp *metaPartition) fsmDeleteDentry(denParm *Dentry, checkInode bool) (resp } } - if item != nil && (clean == true || (item.(*Dentry).getSnapListLen() == 0 && item.(*Dentry).isDeleted())) { + if item != nil && (clean || (item.(*Dentry).getSnapListLen() == 0 && item.(*Dentry).isDeleted())) { log.LogDebugf("action[fsmDeleteDentry] mp[%v] dnetry %v really be deleted", mp.config.PartitionId, item.(*Dentry)) item = mp.dentryTree.Delete(item.(*Dentry)) + log.LogDebugf("action[fsmDeleteDentry] mp[%v] dnetry %v done", mp.config.PartitionId, item) } if !doMore { // not the top layer,do nothing to parent inode @@ -359,8 +357,7 @@ func (mp *metaPartition) fsmTxUpdateDentry(txUpDateDentry *TxUpdateDentry) (resp return } -func (mp *metaPartition) fsmUpdateDentry(dentry *Dentry) ( - resp *DentryResponse) { +func (mp *metaPartition) fsmUpdateDentry(dentry *Dentry) (resp *DentryResponse) { resp = NewDentryResponse() resp.Status = proto.OpOk mp.dentryTree.CopyFind(dentry, func(item BtreeItem) { @@ -446,7 +443,6 @@ func (mp *metaPartition) readDir(req *ReadDirReq) (resp *ReadDirResp) { // else if req.Marker != "" and req.Limit == 0, return dentries from pid:name to pid+1 // else if req.Marker == "" and req.Limit != 0, return dentries from pid with limit count // else if req.Marker != "" and req.Limit != 0, return dentries from pid:marker to pid:xxxx with limit count -// func (mp *metaPartition) readDirLimit(req *ReadDirLimitReq) (resp *ReadDirLimitResp) { log.LogDebugf("action[readDirLimit] mp[%v] req %v", mp.config.PartitionId, req) resp = &ReadDirLimitResp{} diff --git a/metanode/partition_fsmop_inode.go b/metanode/partition_fsmop_inode.go index abcf3287f..f96d7654f 100644 --- a/metanode/partition_fsmop_inode.go +++ b/metanode/partition_fsmop_inode.go @@ -181,7 +181,7 @@ func (mp *metaPartition) getInode(ino *Inode, listAll bool) (resp *InodeResponse resp.Status = proto.OpOk i := mp.getInodeByVer(ino) - if i == nil || (listAll == false && i.ShouldDelete()) { + if i == nil || (!listAll && i.ShouldDelete()) { log.LogDebugf("action[getInode] ino %v not found", ino) resp.Status = proto.OpNotExistErr return @@ -308,7 +308,7 @@ func (mp *metaPartition) fsmUnlinkInode(ino *Inode, uniqID uint64) (resp *InodeR log.LogDebugf("action[fsmUnlinkInode] mp[%v] get inode[%v]", mp.config.PartitionId, inode) var ( doMore bool - status = proto.OpOk + status uint8 ) if ino.getVer() == 0 { @@ -416,11 +416,9 @@ func (mp *metaPartition) internalDeleteInode(ino *Inode) { mp.inodeTree.Delete(ino) mp.freeList.Remove(ino.Inode) mp.extendTree.Delete(&Extend{inode: ino.Inode}) // Also delete extend attribute. - return } func (mp *metaPartition) fsmAppendExtents(ino *Inode) (status uint8) { - status = proto.OpOk item := mp.inodeTree.CopyGet(ino) if item == nil { status = proto.OpNotExistErr @@ -795,7 +793,7 @@ func (mp *metaPartition) fsmSetInodeQuotaBatch(req *proto.BatchSetMetaserverQuot var files int64 var bytes int64 resp = &proto.BatchSetMetaserverQuotaResponse{} - resp.InodeRes = make(map[uint64]uint8, 0) + resp.InodeRes = make(map[uint64]uint8) for _, ino := range req.Inodes { var isExist bool var err error @@ -862,7 +860,7 @@ func (mp *metaPartition) fsmDeleteInodeQuotaBatch(req *proto.BatchDeleteMetaserv var files int64 var bytes int64 resp = &proto.BatchDeleteMetaserverQuotaResponse{} - resp.InodeRes = make(map[uint64]uint8, 0) + resp.InodeRes = make(map[uint64]uint8) for _, ino := range req.Inodes { var err error diff --git a/metanode/partition_item.go b/metanode/partition_item.go index 10dbf9cb2..ea876aa69 100644 --- a/metanode/partition_item.go +++ b/metanode/partition_item.go @@ -44,11 +44,12 @@ func (s *MetaItem) MarshalJson() ([]byte, error) { // MarshalBinary marshals MetaItem to binary data. // Binary frame structure: -// +------+----+------+------+------+------+ -// | Item | Op | LenK | K | LenV | V | -// +------+----+------+------+------+------+ -// | byte | 4 | 4 | LenK | 4 | LenV | -// +------+----+------+------+------+------+ +// +// +------+----+------+------+------+------+ +// | Item | Op | LenK | K | LenV | V | +// +------+----+------+------+------+------+ +// | byte | 4 | 4 | LenK | 4 | LenV | +// +------+----+------+------+------+------+ func (s *MetaItem) MarshalBinary() (result []byte, err error) { buff := bytes.NewBuffer(make([]byte, 0)) buff.Grow(4 + len(s.K) + len(s.V)) @@ -78,11 +79,12 @@ func (s *MetaItem) UnmarshalJson(data []byte) error { // MarshalBinary unmarshal this MetaItem entity from binary data. // Binary frame structure: -// +------+----+------+------+------+------+ -// | Item | Op | LenK | K | LenV | V | -// +------+----+------+------+------+------+ -// | byte | 4 | 4 | LenK | 4 | LenV | -// +------+----+------+------+------+------+ +// +// +------+----+------+------+------+------+ +// | Item | Op | LenK | K | LenV | V | +// +------+----+------+------+------+------+ +// | byte | 4 | 4 | LenK | 4 | LenV | +// +------+----+------+------+------+------+ func (s *MetaItem) UnmarshalBinary(raw []byte) (err error) { var ( lenK uint32 @@ -378,7 +380,6 @@ func (si *MetaItemIterator) Close() { si.closeOnce.Do(func() { close(si.closeCh) }) - return } // Next returns the next item. diff --git a/metanode/partition_op_extent.go b/metanode/partition_op_extent.go index a62005ea0..b88cf81a1 100644 --- a/metanode/partition_op_extent.go +++ b/metanode/partition_op_extent.go @@ -364,8 +364,6 @@ func (mp *metaPartition) GetExtentByVer(ino *Inode, req *proto.GetExtentsRequest return rsp.Extents[i].FileOffset < rsp.Extents[j].FileOffset }) }) - - return } func (mp *metaPartition) SetUidLimit(info []*proto.UidSpaceInfo) { diff --git a/metanode/partition_op_inode.go b/metanode/partition_op_inode.go index 2dc221ed3..d406cf3aa 100644 --- a/metanode/partition_op_inode.go +++ b/metanode/partition_op_inode.go @@ -141,7 +141,7 @@ func (mp *metaPartition) CreateInode(req *CreateInoReq, p *Packet, remoteAddr st resp := &CreateInoResp{ Info: &proto.InodeInfo{}, } - if replyInfo(resp.Info, ino, make(map[uint32]*proto.MetaQuotaInfo, 0)) { + if replyInfo(resp.Info, ino, make(map[uint32]*proto.MetaQuotaInfo)) { status = proto.OpOk reply, err = json.Marshal(resp) if err != nil { @@ -244,7 +244,7 @@ func (mp *metaPartition) TxUnlinkInode(req *proto.TxUnlinkInodeRequest, p *Packe Info: &proto.InodeInfo{}, } if respIno != nil { - replyInfo(resp.Info, respIno, make(map[uint32]*proto.MetaQuotaInfo, 0)) + replyInfo(resp.Info, respIno, make(map[uint32]*proto.MetaQuotaInfo)) if reply, err = json.Marshal(resp); err != nil { status = proto.OpErr reply = []byte(err.Error()) @@ -332,7 +332,7 @@ func (mp *metaPartition) UnlinkInode(req *UnlinkInoReq, p *Packet, remoteAddr st resp := &UnlinkInoResp{ Info: &proto.InodeInfo{}, } - replyInfo(resp.Info, msg.Msg, make(map[uint32]*proto.MetaQuotaInfo, 0)) + replyInfo(resp.Info, msg.Msg, make(map[uint32]*proto.MetaQuotaInfo)) if reply, err = json.Marshal(resp); err != nil { status = proto.OpErr reply = []byte(err.Error()) @@ -415,7 +415,7 @@ func (mp *metaPartition) UnlinkInodeBatch(req *BatchUnlinkInoReq, p *Packet, rem } info := &proto.InodeInfo{} - replyInfo(info, ir.Msg, make(map[uint32]*proto.MetaQuotaInfo, 0)) + replyInfo(info, ir.Msg, make(map[uint32]*proto.MetaQuotaInfo)) result.Items = append(result.Items, &struct { Info *proto.InodeInfo `json:"info"` Status uint8 `json:"status"` @@ -498,8 +498,6 @@ func (mp *metaPartition) InodeGet(req *InodeGetReq, p *Packet) (err error) { log.LogDebugf("action[Inode] %v seq [%v] retMsg.status [%v], getAllVerInfo %v", ino.Inode, req.VerSeq, retMsg.Status, getAllVerInfo) - ino = retMsg.Msg - var ( reply []byte status = proto.OpNotExistErr @@ -619,7 +617,7 @@ func (mp *metaPartition) TxCreateInodeLink(req *proto.TxLinkInodeRequest, p *Pac resp := &proto.TxLinkInodeResponse{ Info: &proto.InodeInfo{}, } - if replyInfo(resp.Info, retMsg.Msg, make(map[uint32]*proto.MetaQuotaInfo, 0)) { + if replyInfo(resp.Info, retMsg.Msg, make(map[uint32]*proto.MetaQuotaInfo)) { status = proto.OpOk reply, err = json.Marshal(resp) if err != nil { @@ -668,7 +666,7 @@ func (mp *metaPartition) CreateInodeLink(req *LinkInodeReq, p *Packet, remoteAdd resp := &LinkInodeResp{ Info: &proto.InodeInfo{}, } - if replyInfo(resp.Info, retMsg.Msg, make(map[uint32]*proto.MetaQuotaInfo, 0)) { + if replyInfo(resp.Info, retMsg.Msg, make(map[uint32]*proto.MetaQuotaInfo)) { status = proto.OpOk reply, err = json.Marshal(resp) if err != nil { diff --git a/metanode/partition_op_quota.go b/metanode/partition_op_quota.go index d1da33bb0..479c1af3c 100644 --- a/metanode/partition_op_quota.go +++ b/metanode/partition_op_quota.go @@ -22,7 +22,8 @@ import ( ) func (mp *metaPartition) batchSetInodeQuota(req *proto.BatchSetMetaserverQuotaReuqest, - resp *proto.BatchSetMetaserverQuotaResponse) (err error) { + resp *proto.BatchSetMetaserverQuotaResponse, +) (err error) { if len(req.Inodes) == 0 { return nil } @@ -45,7 +46,8 @@ func (mp *metaPartition) batchSetInodeQuota(req *proto.BatchSetMetaserverQuotaRe } func (mp *metaPartition) batchDeleteInodeQuota(req *proto.BatchDeleteMetaserverQuotaReuqest, - resp *proto.BatchDeleteMetaserverQuotaResponse) (err error) { + resp *proto.BatchDeleteMetaserverQuotaResponse, +) (err error) { if len(req.Inodes) == 0 { return nil } @@ -69,7 +71,6 @@ func (mp *metaPartition) batchDeleteInodeQuota(req *proto.BatchDeleteMetaserverQ func (mp *metaPartition) setQuotaHbInfo(infos []*proto.QuotaHeartBeatInfo) { mp.mqMgr.setQuotaHbInfo(infos) - return } func (mp *metaPartition) getQuotaReportInfos() (infos []*proto.QuotaReportInfo) { @@ -106,7 +107,6 @@ func (mp *metaPartition) statisticExtendByLoad(extend *Extend) { } } log.LogInfof("statisticExtendByLoad ino[%v] isFind [%v].", ino.Inode, isFind) - return } func (mp *metaPartition) statisticExtendByStore(extend *Extend, inodeTree *BTree) { @@ -149,7 +149,6 @@ func (mp *metaPartition) statisticExtendByStore(extend *Extend, inodeTree *BTree mp.config.PartitionId, quotaId, extend.GetInode(), baseInfo) } log.LogDebugf("statisticExtendByStore mp[%v] inode[%v] success.", mp.config.PartitionId, extend.GetInode()) - return } func (mp *metaPartition) updateUsedInfo(size int64, files int64, ino uint64) { @@ -160,7 +159,6 @@ func (mp *metaPartition) updateUsedInfo(size int64, files int64, ino uint64) { mp.mqMgr.updateUsedInfo(size, files, quotaId) } } - return } func (mp *metaPartition) isExistQuota(ino uint64) (quotaIds []uint32, isFind bool) { @@ -294,5 +292,4 @@ func (mp *metaPartition) setInodeQuota(quotaIds []uint32, inode uint64) { } log.LogInfof("setInodeQuota inode[%v] quota [%v] success.", inode, quotaIds) - return } diff --git a/metanode/partition_op_quota_test.go b/metanode/partition_op_quota_test.go index a1b54b95b..88a4c303a 100644 --- a/metanode/partition_op_quota_test.go +++ b/metanode/partition_op_quota_test.go @@ -91,7 +91,7 @@ func TestQuotaHbInfo(t *testing.T) { hbInfo := &proto.QuotaHeartBeatInfo{ VolName: VolNameForTest, QuotaId: quotaId, - LimitedInfo: proto.QuotaLimitedInfo{true, true}, + LimitedInfo: proto.QuotaLimitedInfo{LimitedFiles: true, LimitedBytes: true}, Enable: true, } hbInfos = append(hbInfos, hbInfo) @@ -102,7 +102,7 @@ func TestQuotaHbInfo(t *testing.T) { hbInfo = &proto.QuotaHeartBeatInfo{ VolName: VolNameForTest, QuotaId: quotaId2, - LimitedInfo: proto.QuotaLimitedInfo{true, false}, + LimitedInfo: proto.QuotaLimitedInfo{LimitedFiles: true}, Enable: false, } hbInfos = append(hbInfos, hbInfo) @@ -117,10 +117,10 @@ func TestGetQuotaReportInfos(t *testing.T) { // var infos []*proto.QuotaReportInfo partition.mqMgr.updateUsedInfo(100, 1, quotaId) partition.mqMgr.updateUsedInfo(200, 2, quotaId) - partition.mqMgr.limitedMap.Store(quotaId, proto.QuotaLimitedInfo{false, false}) + partition.mqMgr.limitedMap.Store(quotaId, proto.QuotaLimitedInfo{}) info := &proto.QuotaReportInfo{ QuotaId: quotaId, - UsedInfo: proto.QuotaUsedInfo{3, 300}, + UsedInfo: proto.QuotaUsedInfo{UsedFiles: 3, UsedBytes: 300}, } infos := partition.mqMgr.getQuotaReportInfos() diff --git a/metanode/partition_op_transaction.go b/metanode/partition_op_transaction.go index 536eb6055..514931897 100644 --- a/metanode/partition_op_transaction.go +++ b/metanode/partition_op_transaction.go @@ -112,7 +112,6 @@ func (mp *metaPartition) txInitToRm(txInfo *proto.TransactionInfo, p *Packet) { } p.ResultCode = proto.OpOk - return } func canRetry(status uint8) bool { diff --git a/metanode/partition_store.go b/metanode/partition_store.go index 92917e6e1..084861261 100644 --- a/metanode/partition_store.go +++ b/metanode/partition_store.go @@ -54,7 +54,6 @@ const ( verdataFile = "multiVer" StaleMetadataSuffix = ".old" StaleMetadataTimeFormat = "20060102150405.000000000" - verdataInitFile = "multiVerInitFile" ) func (mp *metaPartition) loadMetadata() (err error) { @@ -339,7 +338,7 @@ func (mp *metaPartition) loadMultipart(rootDir string, crc uint32) (err error) { var offset, n int // read number of multipart var numMultiparts uint64 - numMultiparts, n = binary.Uvarint(mem) + numMultiparts, _ = binary.Uvarint(mem) varintTmp := make([]byte, binary.MaxVarintLen64) // write number of multipart n = binary.PutUvarint(varintTmp, numMultiparts) @@ -356,8 +355,7 @@ func (mp *metaPartition) loadMultipart(rootDir string, crc uint32) (err error) { if _, err = crcCheck.Write(mem[offset-n : offset]); err != nil { return err } - var multipart *Multipart - multipart = MultipartFromBytes(mem[offset : offset+int(numBytes)]) + multipart := MultipartFromBytes(mem[offset : offset+int(numBytes)]) log.LogDebugf("loadMultipart: create multipart from bytes: partitionID(%v) multipartID(%v)", mp.config.PartitionId, multipart.id) mp.fsmCreateMultipart(multipart) offset += int(numBytes) @@ -1043,8 +1041,7 @@ func (mp *metaPartition) storeTxInfo(rootDir string, sm *storeMsg) (crc uint32, return } -func (mp *metaPartition) storeInode(rootDir string, - sm *storeMsg) (crc uint32, err error) { +func (mp *metaPartition) storeInode(rootDir string, sm *storeMsg) (crc uint32, err error) { filename := path.Join(rootDir, inodeFile) fp, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os. O_CREATE, 0o755) @@ -1102,8 +1099,7 @@ func (mp *metaPartition) storeInode(rootDir string, return } -func (mp *metaPartition) storeDentry(rootDir string, - sm *storeMsg) (crc uint32, err error) { +func (mp *metaPartition) storeDentry(rootDir string, sm *storeMsg) (crc uint32, err error) { filename := path.Join(rootDir, dentryFile) fp, err := os.OpenFile(filename, os.O_RDWR|os.O_TRUNC|os.O_APPEND|os. O_CREATE, 0o755) diff --git a/metanode/sorted_obj_extents.go b/metanode/sorted_obj_extents.go index a90e433e3..9d0881ad1 100644 --- a/metanode/sorted_obj_extents.go +++ b/metanode/sorted_obj_extents.go @@ -4,7 +4,6 @@ import ( "bytes" "encoding/json" "fmt" - "math" "sync" "github.com/cubefs/cubefs/proto" @@ -153,7 +152,7 @@ func (se *SortedObjExtents) FindOffsetExist(fileOffset uint64) (bool, int) { } left, right, mid := 0, len(se.eks)-1, 0 for { - mid = int(math.Floor(float64((left + right) / 2))) + mid = (left + right) / 2 if se.eks[mid].FileOffset > fileOffset { right = mid - 1 } else if se.eks[mid].FileOffset < fileOffset { diff --git a/metanode/transaction.go b/metanode/transaction.go index 803c99a8a..9adf86828 100644 --- a/metanode/transaction.go +++ b/metanode/transaction.go @@ -394,7 +394,6 @@ func (tm *TransactionManager) processExpiredTransactions() { log.LogWarnf("processExpiredTransactions for mp[%v] exit", mpId) txCheckTimer.Stop() clearTimer.Stop() - return }() for { @@ -748,7 +747,6 @@ func buildTxPacket(data interface{}, mp uint64, op uint8) (pkt *proto.Packet, er func (tm *TransactionManager) setTransactionState(txId string, state int32) (status uint8, err error) { var val []byte var resp interface{} - status = proto.OpOk stateReq := &proto.TxSetStateRequest{ TxID: txId, @@ -830,7 +828,6 @@ func (tm *TransactionManager) clearOrphanTx(tx *proto.TransactionInfo) { err = tm.txProcessor.mp.TxRollbackRM(aReq, newPkt) log.LogWarnf("clearOrphanTx: finally rollback tx in rm, tx %v, status %s, err %v", tx, newPkt.GetResultMsg(), err) - return } func (tm *TransactionManager) commitTx(txId string, skipSetStat bool) (status uint8, err error) { diff --git a/metanode/transaction_test.go b/metanode/transaction_test.go index b8d6f8aa0..ff9456c41 100644 --- a/metanode/transaction_test.go +++ b/metanode/transaction_test.go @@ -41,7 +41,6 @@ const ( inodeNum = 1001 pInodeNum = 1002 inodeNum2 = 1003 - inodeNum3 = 1004 dentryName = "parent" ) diff --git a/metanode/uniq_checker.go b/metanode/uniq_checker.go index ee5b367ba..279d71729 100644 --- a/metanode/uniq_checker.go +++ b/metanode/uniq_checker.go @@ -196,10 +196,7 @@ func (checker *uniqChecker) doEvict(evictBid uint64) { checker.inQue.scan(func(op *uniqOp) bool { cnt++ delete(checker.op, op.uniqid) - if op.uniqid == evictBid { - return false - } - return true + return op.uniqid != evictBid }) } diff --git a/objectnode/acl_handler.go b/objectnode/acl_handler.go index 4f58781f6..08ac5b7e1 100644 --- a/objectnode/acl_handler.go +++ b/objectnode/acl_handler.go @@ -63,7 +63,6 @@ func (o *ObjectNode) getBucketACLHandler(w http.ResponseWriter, r *http.Request) } writeSuccessResponseXML(w, data) - return } // https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketAcl.html @@ -104,8 +103,6 @@ func (o *ObjectNode) putBucketACLHandler(w http.ResponseWriter, r *http.Request) return } vol.metaLoader.storeACL(acl) - - return } // https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectAcl.html @@ -156,7 +153,6 @@ func (o *ObjectNode) getObjectACLHandler(w http.ResponseWriter, r *http.Request) } writeSuccessResponseXML(w, data) - return } // https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutObjectAcl.html @@ -236,6 +232,4 @@ func (o *ObjectNode) putObjectACLHandler(w http.ResponseWriter, r *http.Request) } return } - - return } diff --git a/objectnode/api_handler.go b/objectnode/api_handler.go index de196a04f..99120ebf9 100644 --- a/objectnode/api_handler.go +++ b/objectnode/api_handler.go @@ -147,5 +147,4 @@ func (o *ObjectNode) unsupportedOperationHandler(w http.ResponseWriter, r *http. ActionFromRouteName(mux.CurrentRoute(r).GetName()), r.UserAgent()) UnsupportedOperation.ServeResponse(w, r) - return } diff --git a/objectnode/api_handler_bucket.go b/objectnode/api_handler_bucket.go index 89a8399b8..6b7ae99bc 100644 --- a/objectnode/api_handler_bucket.go +++ b/objectnode/api_handler_bucket.go @@ -142,8 +142,6 @@ func (o *ObjectNode) createBucketHandler(w http.ResponseWriter, r *http.Request) } vol.metaLoader.storeACL(acl) } - - return } // Delete bucket @@ -207,7 +205,6 @@ func (o *ObjectNode) deleteBucketHandler(w http.ResponseWriter, r *http.Request) // release Volume from Volume manager o.vm.Release(bucket) w.WriteHeader(http.StatusNoContent) - return } // List buckets @@ -276,7 +273,6 @@ func (o *ObjectNode) listBucketsHandler(w http.ResponseWriter, r *http.Request) } writeSuccessResponseXML(w, response) - return } // Get bucket location @@ -318,7 +314,6 @@ func (o *ObjectNode) getBucketLocationHandler(w http.ResponseWriter, r *http.Req } writeSuccessResponseXML(w, response) - return } // Get bucket tagging @@ -371,7 +366,6 @@ func (o *ObjectNode) getBucketTaggingHandler(w http.ResponseWriter, r *http.Requ } writeSuccessResponseXML(w, response) - return } // Put bucket tagging @@ -437,7 +431,6 @@ func (o *ObjectNode) putBucketTaggingHandler(w http.ResponseWriter, r *http.Requ } w.WriteHeader(http.StatusNoContent) - return } // Delete bucket tagging @@ -477,7 +470,6 @@ func (o *ObjectNode) deleteBucketTaggingHandler(w http.ResponseWriter, r *http.R } w.WriteHeader(http.StatusNoContent) - return } func calculateAuthKey(key string) (authKey string, err error) { @@ -547,7 +539,6 @@ func (o *ObjectNode) putObjectLockConfigurationHandler(w http.ResponseWriter, r vol.metaLoader.storeObjectLock(config) w.WriteHeader(http.StatusNoContent) - return } // Get Object Lock Configuration @@ -592,7 +583,6 @@ func (o *ObjectNode) getObjectLockConfigurationHandler(w http.ResponseWriter, r } writeSuccessResponseXML(w, data) - return } func (o *ObjectNode) getUserInfoByAccessKeyV2(accessKey string) (userInfo *proto.UserInfo, err error) { diff --git a/objectnode/api_handler_multipart.go b/objectnode/api_handler_multipart.go index 80119efa4..65c27eaad 100644 --- a/objectnode/api_handler_multipart.go +++ b/objectnode/api_handler_multipart.go @@ -146,7 +146,6 @@ func (o *ObjectNode) createMultipleUploadHandler(w http.ResponseWriter, r *http. } writeSuccessResponseXML(w, response) - return } // Upload part @@ -272,7 +271,6 @@ func (o *ObjectNode) uploadPartHandler(w http.ResponseWriter, r *http.Request) { // write header to response w.Header()[ETag] = []string{"\"" + fsFileInfo.ETag + "\""} - return } // Upload part copy @@ -424,7 +422,6 @@ func (o *ObjectNode) uploadPartCopyHandler(w http.ResponseWriter, r *http.Reques response := NewS3CopyPartResult(Etag, fsFileInfo.CreateTime.UTC().Format(time.RFC3339)).String() writeSuccessResponseXML(w, []byte(response)) - return } func handleWritePartErr(err error) error { @@ -556,18 +553,18 @@ func (o *ObjectNode) listPartsHandler(w http.ResponseWriter, r *http.Request) { } writeSuccessResponseXML(w, response) - return } func (o *ObjectNode) checkReqParts(param *RequestParam, reqParts *CompleteMultipartUploadRequest, multipartInfo *proto.MultipartInfo) ( - discardedPartInodes map[uint64]uint16, committedPartInfo *proto.MultipartInfo, err error) { + discardedPartInodes map[uint64]uint16, committedPartInfo *proto.MultipartInfo, err error, +) { if len(reqParts.Parts) <= 0 { err = InvalidPart log.LogErrorf("checkReqParts: upload part is empty: requestID(%v) volume(%v)", GetRequestID(param.r), param.Bucket()) return } - reqInfo := make(map[int]int, 0) + reqInfo := make(map[int]int) for _, reqPart := range reqParts.Parts { reqInfo[reqPart.PartNumber] = 0 } @@ -588,8 +585,8 @@ func (o *ObjectNode) checkReqParts(param *RequestParam, reqParts *CompleteMultip maxPartNum := saveParts[len(saveParts)-1].ID allSaveParts := make([]*proto.MultipartPartInfo, maxPartNum+1) - uploadedInfo := make(map[uint16]string, 0) - discardedPartInodes = make(map[uint64]uint16, 0) + uploadedInfo := make(map[uint16]string) + discardedPartInodes = make(map[uint64]uint16) for _, uploadedPart := range multipartInfo.Parts { log.LogDebugf("checkReqParts: server save part check: requestID(%v) volume(%v) part(%v)", GetRequestID(param.r), param.Bucket(), uploadedPart) @@ -785,7 +782,6 @@ func (o *ObjectNode) completeMultipartUploadHandler(w http.ResponseWriter, r *ht } writeSuccessResponseXML(w, response) - return } // Abort multipart @@ -840,7 +836,6 @@ func (o *ObjectNode) abortMultipartUploadHandler(w http.ResponseWriter, r *http. } w.WriteHeader(http.StatusNoContent) - return } // List multipart uploads @@ -940,7 +935,6 @@ func (o *ObjectNode) listMultipartUploadsHandler(w http.ResponseWriter, r *http. } writeSuccessResponseXML(w, response) - return } func determineCopyRange(copyRange string, fsize int64) (firstByte, copyLength int64, err *ErrorCode) { diff --git a/objectnode/api_handler_object.go b/objectnode/api_handler_object.go index b3bb80db8..f43383ecd 100644 --- a/objectnode/api_handler_object.go +++ b/objectnode/api_handler_object.go @@ -36,7 +36,7 @@ import ( ) var ( - rangeRegexp = regexp.MustCompile("^bytes=(\\d)*-(\\d)*$") + rangeRegexp = regexp.MustCompile(`^bytes=(\d)*-(\d)*$`) MaxKeyLength = 750 ) @@ -300,8 +300,6 @@ func (o *ObjectNode) getObjectHandler(w http.ResponseWriter, r *http.Request) { } return } - - return } func CheckConditionInHeader(r *http.Request, fileInfo *FSFileInfo) *ErrorCode { @@ -526,8 +524,6 @@ func (o *ObjectNode) headObjectHandler(w http.ResponseWriter, r *http.Request) { for name, value := range fileInfo.Metadata { w.Header().Set(XAmzMetaPrefix+name, value) } - - return } // Delete objects (multiple objects) @@ -549,8 +545,7 @@ func (o *ObjectNode) deleteObjectsHandler(w http.ResponseWriter, r *http.Request return } - var vol *Volume - if vol, err = o.getVol(param.Bucket()); err != nil { + if _, err = o.getVol(param.Bucket()); err != nil { log.LogErrorf("deleteObjectsHandler: load volume fail: requestID(%v) volume(%v) err(%v)", GetRequestID(r), param.Bucket(), err) return @@ -629,7 +624,6 @@ func (o *ObjectNode) deleteObjectsHandler(w http.ResponseWriter, r *http.Request deletedObjects := make([]Deleted, 0, len(deleteReq.Objects)) deletedErrors := make([]Error, 0) - objectKeys := make([]string, 0, len(deleteReq.Objects)) start := time.Now() for _, object := range deleteReq.Objects { result := POLICY_UNKNOW @@ -650,7 +644,6 @@ func (o *ObjectNode) deleteObjectsHandler(w http.ResponseWriter, r *http.Request }) continue } - objectKeys = append(objectKeys, object.Key) log.LogWarnf("deleteObjectsHandler: delete path: requestID(%v) remote(%v) volume(%v) path(%v)", GetRequestID(r), getRequestIP(r), vol.Name(), object.Key) // QPS and Concurrency Limit @@ -684,7 +677,6 @@ func (o *ObjectNode) deleteObjectsHandler(w http.ResponseWriter, r *http.Request } writeSuccessResponseXML(w, response) - return } func extractSrcBucketKey(r *http.Request) (srcBucketId, srcKey, versionId string, err error) { @@ -928,7 +920,6 @@ func (o *ObjectNode) copyObjectHandler(w http.ResponseWriter, r *http.Request) { } writeSuccessResponseXML(w, response) - return } // List objects v1 @@ -1068,7 +1059,6 @@ func (o *ObjectNode) getBucketV1Handler(w http.ResponseWriter, r *http.Request) } writeSuccessResponseXML(w, response) - return } // List objects version 2 @@ -1237,7 +1227,6 @@ func (o *ObjectNode) getBucketV2Handler(w http.ResponseWriter, r *http.Request) } writeSuccessResponseXML(w, response) - return } // Put object @@ -1407,7 +1396,6 @@ func (o *ObjectNode) putObjectHandler(w http.ResponseWriter, r *http.Request) { // set response header w.Header()[ETag] = []string{wrapUnescapedQuot(fsFileInfo.ETag)} - return } // Post object @@ -1732,7 +1720,6 @@ func (o *ObjectNode) deleteObjectHandler(w http.ResponseWriter, r *http.Request) } w.WriteHeader(http.StatusNoContent) - return } // Get object tagging @@ -1794,7 +1781,6 @@ func (o *ObjectNode) getObjectTaggingHandler(w http.ResponseWriter, r *http.Requ } writeSuccessResponseXML(w, response) - return } // Put object tagging @@ -1870,8 +1856,6 @@ func (o *ObjectNode) putObjectTaggingHandler(w http.ResponseWriter, r *http.Requ } return } - - return } // Delete object tagging @@ -1923,7 +1907,6 @@ func (o *ObjectNode) deleteObjectTaggingHandler(w http.ResponseWriter, r *http.R } w.WriteHeader(http.StatusNoContent) - return } // Put object extend attribute (xattr) @@ -1999,8 +1982,6 @@ func (o *ObjectNode) putObjectXAttrHandler(w http.ResponseWriter, r *http.Reques } return } - - return } // Get object extend attribute (xattr) @@ -2070,7 +2051,6 @@ func (o *ObjectNode) getObjectXAttrHandler(w http.ResponseWriter, r *http.Reques } writeSuccessResponseXML(w, response) - return } // Delete object extend attribute (xattr) @@ -2125,8 +2105,6 @@ func (o *ObjectNode) deleteObjectXAttrHandler(w http.ResponseWriter, r *http.Req } return } - - return } // List object xattrs @@ -2187,7 +2165,6 @@ func (o *ObjectNode) listObjectXAttrs(w http.ResponseWriter, r *http.Request) { } writeSuccessResponseXML(w, response) - return } // GetObjectRetention @@ -2254,7 +2231,6 @@ func (o *ObjectNode) getObjectRetentionHandler(w http.ResponseWriter, r *http.Re } writeSuccessResponseXML(w, b) - return } func parsePartInfo(partNumber uint64, fileSize uint64) (uint64, uint64, uint64, uint64) { diff --git a/objectnode/api_middleware.go b/objectnode/api_middleware.go index 5dde03c71..969bfbd0b 100644 --- a/objectnode/api_middleware.go +++ b/objectnode/api_middleware.go @@ -34,13 +34,10 @@ import ( const StatusServerPanic = 597 -var routeSNRegexp = regexp.MustCompile(":(\\w){32}$") +var routeSNRegexp = regexp.MustCompile(`:(\w){32}$`) func IsMonitoredStatusCode(code int) bool { - if code > http.StatusInternalServerError { - return true - } - return false + return code > http.StatusInternalServerError } func generateWarnDetail(r *http.Request, errorInfo string) string { @@ -192,7 +189,6 @@ func (o *ObjectNode) policyCheckMiddleware(next http.Handler) http.Handler { return http.HandlerFunc( func(w http.ResponseWriter, r *http.Request) { o.policyCheck(next.ServeHTTP).ServeHTTP(w, r) - return }) } @@ -300,7 +296,6 @@ func (o *ObjectNode) corsMiddleware(next http.Handler) http.Handler { return } next.ServeHTTP(w, r) - return }) } diff --git a/objectnode/auth_form.go b/objectnode/auth_form.go index 93a192888..b2317143c 100644 --- a/objectnode/auth_form.go +++ b/objectnode/auth_form.go @@ -121,7 +121,7 @@ func (auth *FormAuth) parseSignV4() error { func (auth *FormAuth) FromMultipartForm(key string) string { for k, v := range auth.request.MultipartForm.Value { - if strings.ToLower(k) == strings.ToLower(key) && len(v) > 0 { + if strings.EqualFold(k, key) && len(v) > 0 { return v[0] } } diff --git a/objectnode/auth_test.go b/objectnode/auth_test.go index 1b85ba515..ed3fe2510 100644 --- a/objectnode/auth_test.go +++ b/objectnode/auth_test.go @@ -24,6 +24,18 @@ import ( "github.com/stretchr/testify/require" ) +func init() { + // unused + _s := SignatureInfo{} + _ = _s.credential + _ = _s.signedHeaders + _ = _s.version + _ = _s.algorithm + _ = _s.signature + _ = _s.stringToSign + _ = _s.canonicalRequest +} + func TestGetSecurityToken(t *testing.T) { token := "X-AMZ-SECURITY-TOKEN-EXAMPLE" // header diff --git a/objectnode/const.go b/objectnode/const.go index 8caef1107..c319b32c6 100644 --- a/objectnode/const.go +++ b/objectnode/const.go @@ -196,3 +196,20 @@ const ( TaggingKeyMaxLength = 128 TaggingValueMaxLength = 256 ) + +// TODO: to remove unused by golangci +var ( + _ = tempFileName + _ = formatSimpleTime + _ = formatTimeISOLocal + _ = transferError + _ = isIPNetContainsIP + _ = patternMatch + _ = (*objectStore).Init + _ = (*objectStore).List + _ = (*xattrStore).getInode + _ = (*Volume).appendInodeHash + _ = (*Volume).loadUserDefinedMetadata + _ = (*Volume).copyFile + _ = (*Condition).parseOperations +) diff --git a/objectnode/cors_handler.go b/objectnode/cors_handler.go index 0a872be63..0155a169a 100644 --- a/objectnode/cors_handler.go +++ b/objectnode/cors_handler.go @@ -68,7 +68,6 @@ func (o *ObjectNode) getBucketCorsHandler(w http.ResponseWriter, r *http.Request } writeSuccessResponseXML(w, data) - return } // https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketCors.html @@ -123,8 +122,6 @@ func (o *ObjectNode) putBucketCorsHandler(w http.ResponseWriter, r *http.Request return } vol.metaLoader.storeCORS(corsConfig) - - return } // https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucketCors.html @@ -156,7 +153,6 @@ func (o *ObjectNode) deleteBucketCorsHandler(w http.ResponseWriter, r *http.Requ vol.metaLoader.storeCORS(nil) w.WriteHeader(http.StatusNoContent) - return } // Option object @@ -164,5 +160,4 @@ func (o *ObjectNode) deleteBucketCorsHandler(w http.ResponseWriter, r *http.Requ func (o *ObjectNode) optionsObjectHandler(w http.ResponseWriter, r *http.Request) { log.LogInfof("optionsObjectHandler: OPTIONS object, requestID(%v) remote(%v)", GetRequestID(r), r.RemoteAddr) // Already done in methods 'corsMiddleware'. - return } diff --git a/objectnode/etag.go b/objectnode/etag.go index ae0d85d89..fd924797c 100644 --- a/objectnode/etag.go +++ b/objectnode/etag.go @@ -28,11 +28,11 @@ import ( ) var ( - regexpEncodedETagValue = regexp.MustCompile("^(\\w)+(-(\\d)+)?(:(\\d)+)?$") + regexpEncodedETagValue = regexp.MustCompile(`^(\w)+(-(\d)+)?(:(\d)+)?$`) regexpEncodedETagParts = [3]*regexp.Regexp{ - regexp.MustCompile("(\\w)+"), - regexp.MustCompile("-(\\d)+"), - regexp.MustCompile(":(\\d)+"), + regexp.MustCompile(`(\w)+`), + regexp.MustCompile(`-(\d)+`), + regexp.MustCompile(`:(\d)+`), } staticDirectoryETagValue = ETagValue{Value: EmptyContentMD5String, PartNum: 0} ) @@ -139,7 +139,6 @@ func ParseETagValue(raw string) ETagValue { if len(tsLoc) == 2 { unixSec, _ := strconv.ParseInt(raw[offset:][tsLoc[0]+1:tsLoc[1]], 10, 64) value.TS = time.Unix(unixSec, 0) - offset += tsLoc[1] - tsLoc[0] } else { value.TS = time.Unix(0, 0) } diff --git a/objectnode/fs_manager.go b/objectnode/fs_manager.go index f3321d74f..527789c13 100644 --- a/objectnode/fs_manager.go +++ b/objectnode/fs_manager.go @@ -20,7 +20,6 @@ import ( "time" "github.com/cubefs/cubefs/proto" - "github.com/cubefs/cubefs/sdk/master" "github.com/cubefs/cubefs/util/log" ) @@ -245,7 +244,6 @@ func NewVolumeLoader(masters []string, store Store, strict bool) *VolumeLoader { type VolumeManager struct { masters []string - mc *master.MasterClient loaders [volumeLoaderNum]*VolumeLoader store Store metaStrict bool diff --git a/objectnode/fs_store_user.go b/objectnode/fs_store_user.go index 478ad1804..4555e3b32 100644 --- a/objectnode/fs_store_user.go +++ b/objectnode/fs_store_user.go @@ -91,7 +91,6 @@ func ReleaseUserInfoStore(store UserInfoStore) { if cacheStore, is := store.(*CacheUserInfoStore); is { cacheStore.Close() } - return } type CacheUserInfoLoader struct { diff --git a/objectnode/fs_store_xattr.go b/objectnode/fs_store_xattr.go index 2cfe2cfd1..9c516a32c 100644 --- a/objectnode/fs_store_xattr.go +++ b/objectnode/fs_store_xattr.go @@ -83,8 +83,7 @@ func (s *xattrStore) Get(vol, path, key string) (val []byte, err error) { return } - var strVal string - strVal = xattrInfo.XAttrs[key] + strVal := xattrInfo.XAttrs[key] if len(strVal) > 0 { val = []byte(strVal) return diff --git a/objectnode/fs_volume.go b/objectnode/fs_volume.go index c7bb65a54..beec17e29 100644 --- a/objectnode/fs_volume.go +++ b/objectnode/fs_volume.go @@ -391,7 +391,7 @@ func (v *Volume) GetXAttr(path string, key string) (info *proto.XAttrInfo, err e info = &proto.XAttrInfo{ Inode: inode, - XAttrs: make(map[string]string, 0), + XAttrs: make(map[string]string), } var attr *proto.XAttrInfo @@ -1555,12 +1555,12 @@ func (v *Volume) readEbs(inode, inodeSize uint64, path string, writer io.Writer, } ctx := context.Background() - _ = context.WithValue(ctx, "objectnode", 1) + // _ = context.WithValue(ctx, "objectnode", 1) // TODO: ??? reader := v.getEbsReader(inode) var n int var rest uint64 tmp := buf.ReadBufPool.Get().([]byte) - defer buf.ReadBufPool.Put(tmp) + defer buf.ReadBufPool.Put(tmp) // nolint: staticcheck for { if rest = upper - offset; rest <= 0 { @@ -1749,7 +1749,7 @@ func (v *Volume) ObjectMeta(path string) (info *FSFileInfo, xattr *proto.XAttrIn // Load user-defined metadata var retainUntilDate string var retainUntilDateInt64 int64 - metadata := make(map[string]string, 0) + metadata := make(map[string]string) for key, val := range xattr.XAttrs { if !strings.HasPrefix(key, XAttrKeyOSSPrefix) { metadata[key] = val @@ -1959,7 +1959,7 @@ func updateAttrCache(inode uint64, key, value, volName string) { attrItem := &AttrItem{ XAttrInfo: proto.XAttrInfo{ Inode: inode, - XAttrs: make(map[string]string, 0), + XAttrs: make(map[string]string), }, } attrItem.XAttrs[key] = value @@ -2080,8 +2080,8 @@ func (v *Volume) lookupDirectories(dirs []string, autoCreate bool) (inode uint64 return } -func (v *Volume) listFilesV1(prefix, marker, delimiter string, maxKeys uint64, onlyObject bool) (infos []*FSFileInfo, - prefixes Prefixes, nextMarker string, err error) { +func (v *Volume) listFilesV1(prefix, marker, delimiter string, maxKeys uint64, onlyObject bool, +) (infos []*FSFileInfo, prefixes Prefixes, nextMarker string, err error) { prefixMap := PrefixMap(make(map[string]struct{})) parentId, dirs, err := v.findParentId(prefix) @@ -2127,8 +2127,8 @@ func (v *Volume) listFilesV1(prefix, marker, delimiter string, maxKeys uint64, o return } -func (v *Volume) listFilesV2(prefix, startAfter, contToken, delimiter string, maxKeys uint64) (infos []*FSFileInfo, - prefixes Prefixes, nextMarker string, err error) { +func (v *Volume) listFilesV2(prefix, startAfter, contToken, delimiter string, maxKeys uint64, +) (infos []*FSFileInfo, prefixes Prefixes, nextMarker string, err error) { prefixMap := PrefixMap(make(map[string]struct{})) var marker string @@ -2234,15 +2234,14 @@ func (v *Volume) findParentId(prefix string) (inode uint64, prefixDirs []string, // that match the prefix and delimiter criteria. Stop when the number of matches reaches a threshold // or all files and directories are scanned. func (v *Volume) recursiveScan(fileInfos []*FSFileInfo, prefixMap PrefixMap, parentId, maxKeys, readLimit, rc uint64, dirs []string, - prefix, marker, delimiter string, onlyObject, firstEnter bool) ([]*FSFileInfo, PrefixMap, string, uint64, error) { + prefix, marker, delimiter string, onlyObject, firstEnter bool, +) ([]*FSFileInfo, PrefixMap, string, uint64, error) { var err error var nextMarker string var lastKey string currentPath := strings.Join(dirs, pathSep) + pathSep - if strings.HasPrefix(currentPath, pathSep) { - currentPath = strings.TrimPrefix(currentPath, pathSep) - } + currentPath = strings.TrimPrefix(currentPath, pathSep) log.LogDebugf("recursiveScan enter: currentPath(/%v) fileInfos(%v) parentId(%v) prefix(%v) marker(%v) rc(%v)", currentPath, fileInfos, parentId, prefix, marker, rc) defer func() { @@ -2468,8 +2467,8 @@ func (v *Volume) updateETag(inode uint64, size int64, mt time.Time) (etagValue E return } -func (v *Volume) ListMultipartUploads(prefix, delimiter, keyMarker string, multipartIdMarker string, maxUploads uint64) ( - uploads []*FSUpload, nextMarker, nextMultipartIdMarker string, isTruncated bool, prefixes []string, err error) { +func (v *Volume) ListMultipartUploads(prefix, delimiter, keyMarker string, multipartIdMarker string, maxUploads uint64, +) (uploads []*FSUpload, nextMarker, nextMultipartIdMarker string, isTruncated bool, prefixes []string, err error) { sessions, err := v.mw.ListMultipart_ll(prefix, delimiter, keyMarker, multipartIdMarker, maxUploads) if err != nil || len(sessions) == 0 { return @@ -2674,7 +2673,7 @@ func (v *Volume) CopyFile(sv *Volume, sourcePath, targetPath, metaDirective stri log.LogInfof("CopyFile: target path is equal with source path, replace metadata, source path(%v) target path(%v) opt(%v)", sourcePath, targetPath, opt) } - info, xattr, err = sv.ObjectMeta(sourcePath) + info, _, err = sv.ObjectMeta(sourcePath) return info, err } diff --git a/objectnode/fs_volume_meta.go b/objectnode/fs_volume_meta.go index db33ffe9a..fe9214390 100644 --- a/objectnode/fs_volume_meta.go +++ b/objectnode/fs_volume_meta.go @@ -78,7 +78,6 @@ func (c *cacheMetaLoader) storePolicy(p *Policy) { c.om.policyLock.Lock() c.om.policy = p c.om.policyLock.Unlock() - return } func (c *cacheMetaLoader) loadACL() (p *AccessControlPolicy, err error) { @@ -103,7 +102,6 @@ func (c *cacheMetaLoader) storeACL(p *AccessControlPolicy) { c.om.aclLock.Lock() c.om.acl = p c.om.aclLock.Unlock() - return } func (c *cacheMetaLoader) loadCORS() (cors *CORSConfiguration, err error) { @@ -128,7 +126,6 @@ func (c *cacheMetaLoader) storeCORS(cors *CORSConfiguration) { c.om.corsLock.Lock() c.om.corsConfig = cors c.om.corsLock.Unlock() - return } func (c *cacheMetaLoader) loadObjectLock() (config *ObjectLockConfig, err error) { @@ -153,7 +150,6 @@ func (c *cacheMetaLoader) storeObjectLock(config *ObjectLockConfig) { c.om.objectLock.Lock() c.om.lockConfig = config c.om.objectLock.Unlock() - return } func (c *cacheMetaLoader) setSynced() { diff --git a/objectnode/lifecycle_handler.go b/objectnode/lifecycle_handler.go index 457d457b5..b1508c143 100644 --- a/objectnode/lifecycle_handler.go +++ b/objectnode/lifecycle_handler.go @@ -82,7 +82,6 @@ func (o *ObjectNode) getBucketLifecycleConfigurationHandler(w http.ResponseWrite } writeSuccessResponseXML(w, data) - return } // API reference: https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/API/API_PutBucketLifecycleConfiguration.html diff --git a/objectnode/meta_cache.go b/objectnode/meta_cache.go index b1488245e..73caac058 100644 --- a/objectnode/meta_cache.go +++ b/objectnode/meta_cache.go @@ -43,10 +43,7 @@ type AttrItem struct { } func (attr *AttrItem) IsExpired() bool { - if attr.expiredTime < time.Now().Unix() { - return true - } - return false + return attr.expiredTime < time.Now().Unix() } // VolumeInodeAttrsCache caches Attrs for Inodes @@ -208,10 +205,7 @@ func (di *DentryItem) Key() string { } func (di *DentryItem) IsExpired() bool { - if di.expiredTime < time.Now().Unix() { - return true - } - return false + return di.expiredTime < time.Now().Unix() } // VolumeDentryCache accelerates translating S3 path to posix-compatible file system metadata within a volume diff --git a/objectnode/multipart_form.go b/objectnode/multipart_form.go index 4d9bd72d3..ef5603157 100644 --- a/objectnode/multipart_form.go +++ b/objectnode/multipart_form.go @@ -95,7 +95,7 @@ func (r *FormRequest) ParseMultipartForm() error { // If key is not present, MultipartFormValue returns the empty string. func (r *FormRequest) MultipartFormValue(key string) string { for k, v := range r.MultipartForm.Value { - if strings.ToLower(k) == strings.ToLower(key) && len(v) > 0 { + if strings.EqualFold(k, key) && len(v) > 0 { return v[0] } } diff --git a/objectnode/policy.go b/objectnode/policy.go index 167d8b9e3..066008f9b 100644 --- a/objectnode/policy.go +++ b/objectnode/policy.go @@ -183,7 +183,7 @@ func (o *ObjectNode) policyCheck(f http.HandlerFunc) http.HandlerFunc { // step2. Check user policy userInfo := new(proto.UserInfo) - userPolicy := new(proto.UserPolicy) + var userPolicy *proto.UserPolicy isOwner := false if isAnonymous(param.accessKey) && apiAllowAnonymous(param.apiName) { log.LogDebugf("anonymous user: requestID(%v)", GetRequestID(r)) @@ -332,7 +332,7 @@ func (o *ObjectNode) allowedBySrcBucketPolicy(param *RequestParam, reqUid string log.LogDebugf("copySource(%v) argument invalid: requestID(%v)", paramCopy.r.Header.Get(XAmzCopySource), GetRequestID(paramCopy.r)) return } - vol, acl, policy, err := o.loadBucketMeta(srcBucketId) + vol, _, policy, err := o.loadBucketMeta(srcBucketId) if err != nil { log.LogErrorf("srcBucket policy check: load bucket metadata fail: requestID(%v) err(%v)", GetRequestID(paramCopy.r), err) return @@ -363,6 +363,7 @@ func (o *ObjectNode) allowedBySrcBucketPolicy(param *RequestParam, reqUid string } isOwner := reqUid == vol.owner + var acl *AccessControlPolicy if acl, err = getObjectACL(vol, srcKey, true); err != nil && err != syscall.ENOENT { log.LogErrorf("srcBucket acl check: get object acl fail: requestID(%v) volume(%v) path(%v) err(%v)", GetRequestID(paramCopy.r), srcBucketId, srcKey, err) diff --git a/objectnode/policy_condition.go b/objectnode/policy_condition.go index c69f78b5a..57df8d87c 100644 --- a/objectnode/policy_condition.go +++ b/objectnode/policy_condition.go @@ -251,11 +251,11 @@ func (operations *Condition) parseOperations(operatorMap map[string]map[string]i if err != nil { return err } - switch values.(type) { + switch vals := values.(type) { case string: - valueSet.Add(NewStringValue(values.(string))) + valueSet.Add(NewStringValue(vals)) case []interface{}: - for _, value := range values.([]interface{}) { + for _, value := range vals { if valueString, ok := value.(string); ok { valueSet.Add(NewStringValue(valueString)) } else { diff --git a/objectnode/policy_const.go b/objectnode/policy_const.go index 8dc774f9e..99f90548e 100644 --- a/objectnode/policy_const.go +++ b/objectnode/policy_const.go @@ -32,15 +32,18 @@ const ( ) const ( - Principal_Any PrincipalElementType = "*" - S3_ACTION_PREFIX = "s3:" - S3_RESOURCE_PREFIX = "arn:aws:s3:::" - S3_PRINCIPAL_PREFIX = "AWS" + Principal_Any PrincipalElementType = "*" + + S3_ACTION_PREFIX = "s3:" + S3_RESOURCE_PREFIX = "arn:aws:s3:::" + S3_PRINCIPAL_PREFIX = "AWS" ) // if more s3 api is supported by policy, need extend bucketApiList, objectApiList -var bucketApiList = SliceString{LIST_OBJECTS, LIST_OBJECTS_V2, HEAD_BUCKET, DELETE_BUCKET, LIST_MULTIPART_UPLOADS, GET_BUCKET_LOCATION, GET_OBJECT_LOCK_CFG, PUT_OBJECT_LOCK_CFG} -var objectApiList = SliceString{GET_OBJECT, HEAD_OBJECT, DELETE_OBJECT, PUT_OBJECT, POST_OBJECT, INITIALE_MULTIPART_UPLOAD, UPLOAD_PART, UPLOAD_PART_COPY, COMPLETE_MULTIPART_UPLOAD, COPY_OBJECT, ABORT_MULTIPART_UPLOAD, LIST_PARTS, BATCH_DELETE, GET_OBJECT_RETENTION} +var ( + bucketApiList = SliceString{LIST_OBJECTS, LIST_OBJECTS_V2, HEAD_BUCKET, DELETE_BUCKET, LIST_MULTIPART_UPLOADS, GET_BUCKET_LOCATION, GET_OBJECT_LOCK_CFG, PUT_OBJECT_LOCK_CFG} + objectApiList = SliceString{GET_OBJECT, HEAD_OBJECT, DELETE_OBJECT, PUT_OBJECT, POST_OBJECT, INITIALE_MULTIPART_UPLOAD, UPLOAD_PART, UPLOAD_PART_COPY, COMPLETE_MULTIPART_UPLOAD, COPY_OBJECT, ABORT_MULTIPART_UPLOAD, LIST_PARTS, BATCH_DELETE, GET_OBJECT_RETENTION} +) type SliceString []string diff --git a/objectnode/policy_handler.go b/objectnode/policy_handler.go index f6d1b44cd..c1cd92a91 100644 --- a/objectnode/policy_handler.go +++ b/objectnode/policy_handler.go @@ -62,7 +62,6 @@ func (o *ObjectNode) getBucketPolicyHandler(w http.ResponseWriter, r *http.Reque } writeSuccessResponseJSON(w, response) - return } // https://docs.aws.amazon.com/AmazonS3/latest/API/API_PutBucketPolicy.html @@ -120,7 +119,6 @@ func (o *ObjectNode) putBucketPolicyHandler(w http.ResponseWriter, r *http.Reque vol.metaLoader.storePolicy(policy) w.WriteHeader(http.StatusNoContent) - return } // https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteBucketPolicy.html @@ -153,5 +151,4 @@ func (o *ObjectNode) deleteBucketPolicyHandler(w http.ResponseWriter, r *http.Re vol.metaLoader.storePolicy(nil) w.WriteHeader(http.StatusNoContent) - return } diff --git a/objectnode/policy_ipaddressop.go b/objectnode/policy_ipaddressop.go index f7cd0c69b..f7e999eb9 100644 --- a/objectnode/policy_ipaddressop.go +++ b/objectnode/policy_ipaddressop.go @@ -119,7 +119,7 @@ func valuesToIPNets(op operator, values ValueSet) ([]*IPInfo, error) { return nil, fmt.Errorf(invalidCIDR, v, op) } - if strings.Index(s, "/") < 0 { + if !strings.Contains(s, "/") { s += "/32" } IP, IPNet, err := net.ParseCIDR(s) diff --git a/objectnode/policy_match.go b/objectnode/policy_match.go index 7230e9461..462aaf447 100644 --- a/objectnode/policy_match.go +++ b/objectnode/policy_match.go @@ -67,7 +67,6 @@ func (s *Statement) match(apiName string, uid string, conditionCheck map[string] return true } -//---------------------------------------------------------------------------------------------------------------- func (s *Statement) matchAction(apiName string) bool { log.LogDebug("start to match action") switch s.Action.(type) { @@ -106,7 +105,6 @@ func (actions ActionType) match(apiToMatch string) bool { return false } -//---------------------------------------------------------------------------------------------------------------- func (s *Statement) matchPrincipal(uid string) bool { switch s.Principal.(type) { case string: // "*" or "123" @@ -128,9 +126,9 @@ func (p PrincipalType) match(uid string) bool { if !ok { return false } - switch p1.(type) { + switch pval := p1.(type) { case []interface{}: - p2 := p1.([]interface{}) + p2 := pval for _, p3 := range p2 { if p4, ok := p3.(string); ok { if PrincipalElementType(p4).match(uid) { @@ -140,13 +138,12 @@ func (p PrincipalType) match(uid string) bool { } return false case string: - return PrincipalElementType(p1.(string)).match(uid) + return PrincipalElementType(pval).match(uid) default: return false } } -//---------------------------------------------------------------------------------------------------------------- func (s *Statement) matchResource(apiName string, keyname interface{}) bool { if IsBucketApi(apiName) { return s.matchBucketInResource() @@ -237,7 +234,6 @@ func makeRegexPattern(raw string) string { return pattern } -//---------------------------------------------------------------------------------------------------------------- func (s *Statement) matchCondition(conditionCheck map[string]string) bool { // condition is optional if s.Condition == nil { diff --git a/objectnode/policy_statement.go b/objectnode/policy_statement.go index 636e90d05..3bc11147f 100644 --- a/objectnode/policy_statement.go +++ b/objectnode/policy_statement.go @@ -131,9 +131,9 @@ func (p PrincipalType) valid() bool { if !ok { return false } - switch p1.(type) { + switch pval := p1.(type) { case []interface{}: - p2 := p1.([]interface{}) + p2 := pval if len(p2) == 0 { return false } @@ -148,7 +148,7 @@ func (p PrincipalType) valid() bool { } return true case string: - if !PrincipalElementType(p1.(string)).valid() { + if !PrincipalElementType(pval).valid() { return false } default: diff --git a/objectnode/policy_statement_test.go b/objectnode/policy_statement_test.go index 6693c9592..c6703ce2d 100644 --- a/objectnode/policy_statement_test.go +++ b/objectnode/policy_statement_test.go @@ -55,7 +55,7 @@ func TestPolicyExample(t *testing.T) { var policy Policy err := json.Unmarshal([]byte(policyJson), &policy) require.NoError(t, err) - out, err := json.Marshal(policy) + out, _ := json.Marshal(policy) err = json.Unmarshal(out, &policy) require.NoError(t, err) } diff --git a/objectnode/ratelimit.go b/objectnode/ratelimit.go index 73aae70f9..70d159225 100644 --- a/objectnode/ratelimit.go +++ b/objectnode/ratelimit.go @@ -19,7 +19,6 @@ import ( "io" "strconv" "strings" - "sync" "time" "github.com/cubefs/cubefs/proto" @@ -51,6 +50,8 @@ var listApi = map[string]string{ LIST_MULTIPART_UPLOADS: List, } +var _ = listApi + type RateLimiter interface { AcquireLimitResource(uid string, api string) error ReleaseLimitResource(uid string, api string) @@ -62,7 +63,6 @@ type RateLimit struct { S3ApiRateLimitMgr map[string]UserRateManager // api -> UserRateMgr ApiLimitConf map[string]*proto.UserLimitConf // api -> UserLimitConf putApi map[string]string - limitMutex sync.RWMutex } func NewRateLimit(apiLimitConf map[string]*proto.UserLimitConf) RateLimiter { @@ -145,7 +145,7 @@ func (n *NullRateLimit) AcquireLimitResource(uid string, api string) error { } func (n *NullRateLimit) ReleaseLimitResource(uid string, api string) { - return + _ = struct{}{} } func (n *NullRateLimit) GetResponseWriter(uid string, api string, w io.Writer) io.Writer { diff --git a/objectnode/server.go b/objectnode/server.go index dd017f61f..82c2314ea 100644 --- a/objectnode/server.go +++ b/objectnode/server.go @@ -171,7 +171,7 @@ const ( var ( // Regular expression used to verify the configuration of the service listening port. // A valid service listening port configuration is a string containing only numbers. - regexpListen = regexp.MustCompile("^(\\d)+$") + regexpListen = regexp.MustCompile(`^(\d)+$`) objMetaCache *ObjMetaCache blockCache *bcache.BcacheClient ebsClient *blobstore.BlobStoreClient @@ -188,9 +188,9 @@ type ObjectNode struct { httpServer *http.Server vm *VolumeManager mc *master.MasterClient - state uint32 - wg sync.WaitGroup userStore UserInfoStore + // state uint32 + // wg sync.WaitGroup localAuditHandler rpc.ProgressHandler externalAudit *ExternalAudit diff --git a/objectnode/sts_handler.go b/objectnode/sts_handler.go index 7a52f597d..78043ed86 100644 --- a/objectnode/sts_handler.go +++ b/objectnode/sts_handler.go @@ -111,5 +111,4 @@ func (o *ObjectNode) getFederationTokenHandler(w http.ResponseWriter, r *http.Re } writeSuccessResponseXML(w, response) - return } diff --git a/objectnode/util.go b/objectnode/util.go index 05c20649d..611288d84 100644 --- a/objectnode/util.go +++ b/objectnode/util.go @@ -304,8 +304,10 @@ func ParseUserDefinedMetadata(header http.Header) map[string]string { } // validate Cache-Control -var cacheControlDir = []string{"public", "private", "no-cache", "no-store", "no-transform", "must-revalidate", "proxy-revalidate"} -var maxAgeRegexp = regexp.MustCompile("^((max-age)|(s-maxage))=[1-9][0-9]*$") +var ( + cacheControlDir = []string{"public", "private", "no-cache", "no-store", "no-transform", "must-revalidate", "proxy-revalidate"} + maxAgeRegexp = regexp.MustCompile("^((max-age)|(s-maxage))=[1-9][0-9]*$") +) func ValidateCacheControl(cacheControl string) bool { cacheDirs := strings.Split(cacheControl, ",") diff --git a/preload/preload.go b/preload/preload.go index 1e0f404ab..f2412a905 100644 --- a/preload/preload.go +++ b/preload/preload.go @@ -82,7 +82,7 @@ func main() { os.Exit(1) } - if cli.CheckColdVolume() == false { + if !cli.CheckColdVolume() { fmt.Println("Preload only work in cold volume") os.Exit(1) } diff --git a/preload/sdk/preloadsdk.go b/preload/sdk/preloadsdk.go index 6d4ff44fe..567bf9dc3 100644 --- a/preload/sdk/preloadsdk.go +++ b/preload/sdk/preloadsdk.go @@ -378,7 +378,7 @@ func (c *PreLoadClient) allocatePreloadDP(target string, count int, ttl uint64, if float64(need+used) > float64(total) { log.LogErrorf("AllocatePreLoadDataPartition failed: need space (%v) GB, volume total(%v)GB used(%v)GB", need, total, used) - return errors.New(fmt.Sprintf("AllocatePreLoadDataPartition failed: need space (%v) GB, volume total(%v)GB used(%v)GB", need, total, used)) + return fmt.Errorf("AllocatePreLoadDataPartition failed: need space (%v) GB, volume total(%v)GB used(%v)GB", need, total, used) } err = c.ec.AllocatePreLoadDataPartition(c.vol, count, need, ttl, zones) @@ -438,7 +438,7 @@ func (c *PreLoadClient) preloadFileWorker(id int64, jobs <-chan fileInfo, wg *sy var succeed int64 = 0 noWritableDP := false for job := range jobs { - if noWritableDP == true { + if noWritableDP { log.LogWarnf("no writable dp,ingnore (%v) to cbfs", job.name) continue // consume the job } @@ -503,7 +503,7 @@ func (c *PreLoadClient) preloadFileWorker(id int64, jobs <-chan fileInfo, wg *sy } } c.ec.CloseStream(ino) - if subErr == false { + if !subErr { log.LogInfof("worker %v preload (%v) to cbfs success", id, job.name) succeed += 1 } diff --git a/proto/admin_proto.go b/proto/admin_proto.go index 14eaf441e..0a3a8f65c 100644 --- a/proto/admin_proto.go +++ b/proto/admin_proto.go @@ -23,6 +23,8 @@ import ( "github.com/cubefs/cubefs/util" ) +type ContextUserKey string + // api const ( // Admin APIs @@ -225,8 +227,8 @@ const ( // graphql api for header HeadAuthorized = "Authorization" ParamAuthorized = "_authorization" - UserKey = "_user_key" - UserInfoKey = "_user_info_key" + UserKey = ContextUserKey("_user_key") + UserInfoKey = ContextUserKey("_user_info_key") // quota QuotaCreate = "/quota/create" QuotaUpdate = "/quota/update" diff --git a/proto/version.go b/proto/version.go index e17b7e36a..335743308 100644 --- a/proto/version.go +++ b/proto/version.go @@ -5,9 +5,6 @@ import ( "runtime" ) -//TODO: remove this later. -//go:generate golangci-lint run --issues-exit-code=1 -D errcheck -E bodyclose . - var ( Version string CommitID string diff --git a/raftstore/monitor.go b/raftstore/monitor.go index 49705e462..7ee96356b 100644 --- a/raftstore/monitor.go +++ b/raftstore/monitor.go @@ -83,9 +83,7 @@ type monitor struct { } func newMonitor() *monitor { - var m *monitor - m = &monitor{} - + m := &monitor{} m.zombieDurations = make(map[zombiePeer]time.Duration) m.noLeaderDurations = make(map[uint64]time.Duration) return m diff --git a/raftstore/raftstore.go b/raftstore/raftstore.go index c54f51484..3657baa54 100644 --- a/raftstore/raftstore.go +++ b/raftstore/raftstore.go @@ -91,7 +91,6 @@ func newRaftLogger(dir string) { return } logger.SetLogger(raftLog) - return } // NewRaftStore returns a new raft store instance. diff --git a/regression/idempotent/main.go b/regression/idempotent/main.go index a0a72c418..49ea26489 100644 --- a/regression/idempotent/main.go +++ b/regression/idempotent/main.go @@ -86,6 +86,4 @@ func main() { fmt.Println("2: ", err) return } - - return } diff --git a/regression/overlapping/main.go b/regression/overlapping/main.go index e9e1bc6a8..111659134 100644 --- a/regression/overlapping/main.go +++ b/regression/overlapping/main.go @@ -78,6 +78,4 @@ func main() { fmt.Println(err) return } - - return } diff --git a/repl/packet.go b/repl/packet.go index a94a43e59..a7ac08f00 100644 --- a/repl/packet.go +++ b/repl/packet.go @@ -203,11 +203,6 @@ func (p *Packet) resolveFollowersAddr() (err error) { p.followersAddrs = followerAddrs[:int(followerNum)] log.LogInfof("action[resolveFollowersAddr] %v", p.followersAddrs) } - if p.RemainingFollowers < 0 { - err = ErrBadNodes - return - } - return } @@ -424,10 +419,6 @@ func (p *Packet) IsErrPacket() bool { return p.ResultCode != proto.OpOk && p.ResultCode != proto.OpInitResultCode } -func (p *Packet) getErrMessage() (m string) { - return fmt.Sprintf("req(%v) err(%v)", p.GetUniqueLogId(), string(p.Data[:p.Size])) -} - var ErrorUnknownOp = errors.New("unknown opcode") func (p *Packet) identificationErrorResultCode(errLog string, errMsg string) { diff --git a/repl/repl_protocol.go b/repl/repl_protocol.go index 9b41aa19c..ee5be06a6 100644 --- a/repl/repl_protocol.go +++ b/repl/repl_protocol.go @@ -186,7 +186,8 @@ func (ft *FollowerTransport) Write(p *FollowerPacket) { } func NewReplProtocol(inConn net.Conn, prepareFunc func(p *Packet) error, - operatorFunc func(p *Packet, c net.Conn) error, postFunc func(p *Packet) error) *ReplProtocol { + operatorFunc func(p *Packet, c net.Conn) error, postFunc func(p *Packet) error, +) *ReplProtocol { rp := new(ReplProtocol) rp.packetList = list.New() rp.ackCh = make(chan struct{}, RequestChanSize) @@ -259,10 +260,6 @@ func (rp *ReplProtocol) setReplProtocolError(request *Packet, index int) { atomic.StoreInt32(&rp.isError, ReplProtocolError) } -func (rp *ReplProtocol) hasError() bool { - return atomic.LoadInt32(&rp.isError) == ReplProtocolError -} - func (rp *ReplProtocol) readPkgAndPrepare() (err error) { request := NewPacket() if err = request.ReadFromConnWithVer(rp.sourceConn, proto.NoReadDeadlineTime); err != nil { @@ -303,11 +300,11 @@ func (rp *ReplProtocol) sendRequestToAllFollowers(request *Packet) (index int, e } // OperatorAndForwardPktGoRoutine reads packets from the to-be-processed channel and writes responses to the client. -// 1. Read a packet from toBeProcessCh, and determine if it needs to be forwarded or not. If the answer is no, then -// process the packet locally and put it into responseCh. -// 2. If the packet needs to be forwarded, the first send it to the followers, and execute the operator function. -// Then notify receiveResponse to read the followers' responses. -// 3. Read a reply from responseCh, and write to the client. +// 1. Read a packet from toBeProcessCh, and determine if it needs to be forwarded or not. If the answer is no, then +// process the packet locally and put it into responseCh. +// 2. If the packet needs to be forwarded, the first send it to the followers, and execute the operator function. +// Then notify receiveResponse to read the followers' responses. +// 3. Read a reply from responseCh, and write to the client. func (rp *ReplProtocol) OperatorAndForwardPktGoRoutine() { for { select { diff --git a/sdk/auth/client.go b/sdk/auth/client.go index 1e49e98f6..1931b3e09 100644 --- a/sdk/auth/client.go +++ b/sdk/auth/client.go @@ -30,7 +30,7 @@ import ( ) const ( - requestTimeout = 30 * time.Second + // requestTimeout = 30 * time.Second RequestMaxRetry = 5 RequestSleepInterval = 100 * time.Millisecond ) @@ -41,7 +41,6 @@ type AuthClient struct { enableHTTPS bool certFile string ticket *auth.Ticket - leaderAddr string } func (c *AuthClient) API() *API { diff --git a/sdk/data/blobstore/blobstore_client_test.go b/sdk/data/blobstore/blobstore_client_test.go index b7cd7fa29..d3bd20624 100644 --- a/sdk/data/blobstore/blobstore_client_test.go +++ b/sdk/data/blobstore/blobstore_client_test.go @@ -32,10 +32,6 @@ import ( "github.com/stretchr/testify/require" ) -const ( - blobSize = 1 << 20 -) - var dataCache []byte type MockEbsService struct { @@ -56,7 +52,8 @@ func NewMockEbsService() *MockEbsService { w.Header().Set("X-Ack-Crc-Encoded", "1") w.WriteHeader(http.StatusOK) - body := crc32block.NewDecoderReader(req.Body) + body := crc32block.NewBodyDecoder(req.Body) + defer body.Close() dataCache = dataCache[:cap(dataCache)] dataCache = dataCache[:crc32block.DecodeSizeWithDefualtBlock(int64(l))] io.ReadFull(body, dataCache) diff --git a/sdk/data/blobstore/reader.go b/sdk/data/blobstore/reader.go index c229cefd0..8bde2c143 100644 --- a/sdk/data/blobstore/reader.go +++ b/sdk/data/blobstore/reader.go @@ -21,7 +21,6 @@ import ( "os" "sync" "syscall" - "time" "github.com/cubefs/cubefs/blockcache/bcache" "github.com/cubefs/cubefs/proto" @@ -59,21 +58,17 @@ type Reader struct { volName string volType int ino uint64 - offset uint64 - data []byte err chan error bc *bcache.BcacheClient mw *meta.MetaWrapper ec *stream.ExtentClient ebs *BlobStoreClient readConcurrency int - cacheTimeout time.Duration wg sync.WaitGroup once sync.Once sync.Mutex close bool extentKeys []proto.ExtentKey - missExtentKeys []proto.ExtentKey objExtentKeys []proto.ObjExtentKey enableBcache bool cacheAction int @@ -335,7 +330,7 @@ func (reader *Reader) readSliceRange(ctx context.Context, rs *rwSlice) (err erro reader.limitManager.ReadAlloc(ctx, int(rs.rSize)) } - readN, err = reader.ebs.Read(ctx, reader.volName, buf, rs.rOffset, uint64(rs.rSize), rs.objExtentKey) + _, err = reader.ebs.Read(ctx, reader.volName, buf, rs.rOffset, uint64(rs.rSize), rs.objExtentKey) if err != nil { reader.err <- err return diff --git a/sdk/data/blobstore/reader_test.go b/sdk/data/blobstore/reader_test.go index a61fcb81a..bca815d12 100644 --- a/sdk/data/blobstore/reader_test.go +++ b/sdk/data/blobstore/reader_test.go @@ -321,7 +321,7 @@ func TestAsyncCache(t *testing.T) { ctx := context.Background() err := gohook.HookMethod(ebsc, "Read", tc.ebsReadFunc, nil) if err != nil { - t.Fatal(fmt.Sprintf("Hook advance instance method failed:%s", err.Error())) + t.Fatalf("Hook advance instance method failed:%s", err.Error()) } reader.fileLength = tc.fileSize reader.cacheAction = tc.cacheAction @@ -470,8 +470,8 @@ func TestReadSliceRange(t *testing.T) { } } -func MockGetObjExtentsTrue(m *meta.MetaWrapper, inode uint64) (gen uint64, size uint64, - extents []proto.ExtentKey, objExtents []proto.ObjExtentKey, err error) { +func MockGetObjExtentsTrue(m *meta.MetaWrapper, inode uint64, +) (gen uint64, size uint64, extents []proto.ExtentKey, objExtents []proto.ObjExtentKey, err error) { objEks := make([]proto.ObjExtentKey, 0) objEkLen := 5 expectedFileSize := 0 @@ -483,32 +483,34 @@ func MockGetObjExtentsTrue(m *meta.MetaWrapper, inode uint64) (gen uint64, size return 1, 1, nil, objEks, nil } -func MockGetObjExtentsFalse(m *meta.MetaWrapper, inode uint64) (gen uint64, size uint64, - extents []proto.ExtentKey, objExtents []proto.ObjExtentKey, err error) { +func MockGetObjExtentsFalse(m *meta.MetaWrapper, inode uint64, +) (gen uint64, size uint64, extents []proto.ExtentKey, objExtents []proto.ObjExtentKey, err error) { return 1, 1, nil, nil, errors.New("Get objEks failed") } func MockEbscReadTrue(ebsc *BlobStoreClient, ctx context.Context, volName string, - buf []byte, offset uint64, size uint64, - oek proto.ObjExtentKey) (readN int, err error) { + buf []byte, offset uint64, size uint64, oek proto.ObjExtentKey, +) (readN int, err error) { reader := strings.NewReader("Hello world.") - readN, err = io.ReadFull(reader, buf) + readN, _ = io.ReadFull(reader, buf) return readN, nil } func MockEbscReadFalse(ebsc *BlobStoreClient, ctx context.Context, volName string, - buf []byte, offset uint64, size uint64, - oek proto.ObjExtentKey) (readN int, err error) { + buf []byte, offset uint64, size uint64, oek proto.ObjExtentKey, +) (readN int, err error) { return 0, syscall.EIO } func MockReadExtentTrue(client *stream.ExtentClient, inode uint64, ek *proto.ExtentKey, - data []byte, offset int, size int) (read int, err error, b bool) { + data []byte, offset int, size int, +) (read int, err error, b bool) { return len("Hello world"), nil, true } func MockReadExtentFalse(client *stream.ExtentClient, inode uint64, ek *proto.ExtentKey, - data []byte, offset int, size int) (read int, err error) { + data []byte, offset int, size int, +) (read int, err error) { return 0, errors.New("Read extent failed") } @@ -521,12 +523,13 @@ func MockCheckDataPartitionExistFalse(client *stream.ExtentClient, partitionID u } func MockWriteTrue(client *stream.ExtentClient, inode uint64, offset int, data []byte, - flags int, checkFunc func() error) (write int, err error) { + flags int, checkFunc func() error, +) (write int, err error) { return len(data), nil } -func MockWriteFalse(client *stream.ExtentClient, inode uint64, offset int, data []byte, - flags int) (write int, err error) { +func MockWriteFalse(client *stream.ExtentClient, inode uint64, offset int, data []byte, flags int, +) (write int, err error) { return 0, errors.New("Write failed") } diff --git a/sdk/data/blobstore/writer.go b/sdk/data/blobstore/writer.go index 9eab095d0..c4b0aa0bd 100644 --- a/sdk/data/blobstore/writer.go +++ b/sdk/data/blobstore/writer.go @@ -211,7 +211,7 @@ func (writer *Writer) WriteFromReader(ctx context.Context, reader io.Reader, h h exec = NewExecutor(writer.wConcurrency) leftToWrite int ) - defer buf.ReadBufPool.Put(tmp) + defer buf.ReadBufPool.Put(tmp) // nolint: staticcheck writer.fileOffset = 0 writer.err = make(chan *wSliceErr) @@ -430,10 +430,6 @@ func (writer *Writer) Flush(ino uint64, ctx context.Context) (err error) { return writer.flush(ino, ctx, true) } -func (writer *Writer) shouldCacheCfs() bool { - return writer.cacheAction == proto.RWCache -} - func (writer *Writer) prepareWriteSlice(offset int, data []byte) []*rwSlice { size := len(data) wSlices := make([]*rwSlice, 0) diff --git a/sdk/data/manager/limiter.go b/sdk/data/manager/limiter.go index d2738b4d4..3e991c00a 100644 --- a/sdk/data/manager/limiter.go +++ b/sdk/data/manager/limiter.go @@ -51,7 +51,6 @@ type LimitFactor struct { mgr *LimitManager gridId uint64 magnify uint32 - winBuffer uint64 lock sync.RWMutex valAllocApply uint64 valAllocCommit uint64 @@ -60,24 +59,6 @@ type LimitFactor struct { isSetLimitZero bool } -func (factor *LimitFactor) getNeedByMagnify(allocCnt uint32, magnify uint32) uint64 { - if magnify == 0 { - return 0 - } - if allocCnt > 1000 { - log.QosWriteDebugf("action[getNeedByMagnify] allocCnt %v", allocCnt) - magnify = defaultMagnifyFactor - } - - need := uint64(allocCnt * magnify) - if factor.factorType == proto.FlowWriteType || factor.factorType == proto.FlowReadType { - if need > util.GB/8 { - need = util.GB / 8 - } - } - return need -} - func (factor *LimitFactor) alloc(allocCnt uint32) (ret uint8, future *util.Future) { log.QosWriteDebugf("action[alloc] type [%v] alloc [%v], tmp factor waitlist [%v] hitlimtcnt [%v] len [%v]", proto.QosTypeString(factor.factorType), allocCnt, factor.waitList.Len(), factor.gidHitLimitCnt, factor.gridList.Len()) @@ -240,7 +221,6 @@ func (factor *LimitFactor) TryReleaseWaitList() { log.QosWriteDebugf("action[TryReleaseWaitList] type [%v] ele used [%v] consumed!", proto.QosTypeString(factor.factorType), ele.used) ele.future.Respond(true, nil) - value = value.Next() factor.waitList.Remove(factor.waitList.Front()) } } @@ -321,7 +301,7 @@ type LimitManager struct { func NewLimitManager(client wrapper.SimpleClientInfo) *LimitManager { mgr := &LimitManager{ - limitMap: make(map[uint32]*LimitFactor, 0), + limitMap: make(map[uint32]*LimitFactor), enable: false, // assign from master simpleClient: client, HitTriggerCnt: gridHitLimitCnt, @@ -372,7 +352,7 @@ func (limitManager *LimitManager) CalcNeedByPow(limitFactor *LimitFactor, used u func (limitManager *LimitManager) GetFlowInfo() (*proto.ClientReportLimitInfo, bool) { info := &proto.ClientReportLimitInfo{ - FactorMap: make(map[uint32]*proto.ClientLimitInfo, 0), + FactorMap: make(map[uint32]*proto.ClientLimitInfo), } var ( validCliInfo bool diff --git a/sdk/data/stream/extent_client.go b/sdk/data/stream/extent_client.go index 80349a90d..dca6f59b8 100644 --- a/sdk/data/stream/extent_client.go +++ b/sdk/data/stream/extent_client.go @@ -323,7 +323,6 @@ func (client *ExtentClient) GetFlowInfo() (*proto.ClientReportLimitInfo, bool) { func (client *ExtentClient) UpdateFlowInfo(limit *proto.LimitRsp2Client) { log.LogInfof("action[UpdateFlowInfo.UpdateFlowInfo]") client.LimitManager.SetClientLimit(limit) - return } func (client *ExtentClient) SetClientID(id uint64) (err error) { @@ -539,7 +538,8 @@ func (client *ExtentClient) Truncate(mw *meta.MetaWrapper, parentIno uint64, ino var err error var oldSize uint64 if mw.EnableSummary { - info, err = mw.InodeGet_ll(inode) + // TODO: err ??? + info, _ = mw.InodeGet_ll(inode) oldSize = info.Size } err = s.IssueTruncRequest(size, fullPath) diff --git a/sdk/data/stream/extent_handler.go b/sdk/data/stream/extent_handler.go index 5071c1816..667f36397 100644 --- a/sdk/data/stream/extent_handler.go +++ b/sdk/data/stream/extent_handler.go @@ -108,9 +108,9 @@ type ExtentHandler struct { doneSender chan struct{} // ver update need alloc new extent - verUpdate chan uint64 - appendLK sync.Mutex - lastKey proto.ExtentKey + appendLK sync.Mutex + lastKey proto.ExtentKey + // verUpdate chan uint64 } // NewExtentHandler returns a new extent handler. @@ -380,7 +380,6 @@ func (eh *ExtentHandler) processReply(packet *Packet) { proto.Buffers.Put(packet.Data) packet.Data = nil eh.dirty = true - return } func (eh *ExtentHandler) processReplyError(packet *Packet, errmsg string) { @@ -516,20 +515,9 @@ func (eh *ExtentHandler) waitForFlush() { if atomic.LoadInt32(&eh.inflight) <= 0 { return } - - // t := time.NewTicker(10 * time.Second) - // defer t.Stop() - - for { - select { - case <-eh.empty: - if atomic.LoadInt32(&eh.inflight) <= 0 { - return - } - // case <-t.C: - // if atomic.LoadInt32(&eh.inflight) <= 0 { - // return - // } + for range eh.empty { + if atomic.LoadInt32(&eh.inflight) <= 0 { + return } } } @@ -622,7 +610,7 @@ func (eh *ExtentHandler) allocateExtent() (err error) { return nil } - errmsg := fmt.Sprintf("allocateExtent failed: hit max retry limit") + errmsg := "allocateExtent failed: hit max retry limit" if err != nil { err = errors.Trace(err, errmsg) } else { @@ -631,18 +619,6 @@ func (eh *ExtentHandler) allocateExtent() (err error) { return err } -func (eh *ExtentHandler) createConnection(dp *wrapper.DataPartition) (*net.TCPConn, error) { - conn, err := net.DialTimeout("tcp", dp.Hosts[0], time.Second) - if err != nil { - return nil, err - } - connect := conn.(*net.TCPConn) - // TODO unhandled error - connect.SetKeepAlive(true) - connect.SetNoDelay(true) - return connect, nil -} - func (eh *ExtentHandler) createExtent(dp *wrapper.DataPartition) (extID int, err error) { bgTime := stat.BeginStat() defer func() { diff --git a/sdk/data/stream/packet.go b/sdk/data/stream/packet.go index 17a0d279e..bd041fba3 100644 --- a/sdk/data/stream/packet.go +++ b/sdk/data/stream/packet.go @@ -70,7 +70,8 @@ func NewWritePacket(inode uint64, fileOffset, storeMode int) *Packet { // NewOverwritePacket returns a new overwrite packet. func NewOverwriteByAppendPacket(dp *wrapper.DataPartition, extentID uint64, extentOffset int, - inode uint64, fileOffset int, direct bool, op uint8) *Packet { + inode uint64, fileOffset int, direct bool, op uint8, +) *Packet { p := new(Packet) p.PartitionID = dp.PartitionID p.Magic = proto.ProtoMagic @@ -206,10 +207,6 @@ func (p *Packet) readFromConn(c net.Conn, deadlineTime time.Duration) (err error } } - if p.Size < 0 { - return - } - size := int(p.Size) if size > len(p.Data) { size = len(p.Data) diff --git a/sdk/data/stream/stream_reader.go b/sdk/data/stream/stream_reader.go index 3be7d7295..480126145 100644 --- a/sdk/data/stream/stream_reader.go +++ b/sdk/data/stream/stream_reader.go @@ -266,7 +266,7 @@ func (s *Streamer) asyncBlockCache() { } else { data = make([]byte, ek.Size) } - reader, err := s.GetExtentReader(ek) + reader, _ := s.GetExtentReader(ek) fullReq := NewExtentRequest(int(ek.FileOffset), int(ek.Size), data, ek) readBytes, err := reader.Read(fullReq) if err != nil || readBytes != len(data) { @@ -299,8 +299,5 @@ func (s *Streamer) asyncBlockCache() { } func (s *Streamer) exceedBlockSize(size uint32) bool { - if size > bcache.BigExtentSize { - return true - } - return false + return size > bcache.BigExtentSize } diff --git a/sdk/data/stream/stream_writer.go b/sdk/data/stream/stream_writer.go index 76040c5e3..876ffecd2 100644 --- a/sdk/data/stream/stream_writer.go +++ b/sdk/data/stream/stream_writer.go @@ -209,7 +209,7 @@ func (s *Streamer) server() { if s.idle >= streamWriterIdleTimeoutPeriod && len(s.request) == 0 { if s.client.disableMetaCache || !s.needBCache { // get current stream in map - current_s, _ := s.client.streamers[s.inode] + current_s := s.client.streamers[s.inode] // one stream maybe has multi server coroutine // when the stream's residual server coroutine exits, others stream maybe deleted if current_s == s { @@ -534,7 +534,6 @@ func (s *Streamer) doDirectWriteByAppend(req *ExtentRequest, direct bool, op uin } total += packSize - break } if err != nil { log.LogErrorf("action[doDirectWriteByAppend] data process err %v", err) diff --git a/sdk/data/wrapper/data_partition.go b/sdk/data/wrapper/data_partition.go index 481558c41..f200f042e 100644 --- a/sdk/data/wrapper/data_partition.go +++ b/sdk/data/wrapper/data_partition.go @@ -56,12 +56,9 @@ func (dp *DataPartition) RecordWrite(startT int64) { cost := time.Now().UnixNano() - startT dp.Metrics.Lock() - defer dp.Metrics.Unlock() - dp.Metrics.WriteOpNum++ dp.Metrics.SumWriteLatencyNano += cost - - return + dp.Metrics.Unlock() } func (dp *DataPartition) MetricsRefresh() { diff --git a/sdk/data/wrapper/default_random_selector.go b/sdk/data/wrapper/default_random_selector.go index 800bfa305..d2d71c4cb 100644 --- a/sdk/data/wrapper/default_random_selector.go +++ b/sdk/data/wrapper/default_random_selector.go @@ -124,10 +124,8 @@ func (s *DefaultRandomSelector) RemoveDP(partitionID uint64) { newLocalLeaderPartitions = append(newLocalLeaderPartitions, localLeaderPartitions[i+1:]...) s.Lock() - defer s.Unlock() s.localLeaderPartitions = newLocalLeaderPartitions - - return + s.Unlock() } func (s *DefaultRandomSelector) Count() int { @@ -143,8 +141,7 @@ func (s *DefaultRandomSelector) getLocalLeaderDataPartition(exclude map[string]s return s.getRandomDataPartition(localLeaderPartitions, exclude) } -func (s *DefaultRandomSelector) getRandomDataPartition(partitions []*DataPartition, exclude map[string]struct{}) ( - dp *DataPartition) { +func (s *DefaultRandomSelector) getRandomDataPartition(partitions []*DataPartition, exclude map[string]struct{}) (dp *DataPartition) { length := len(partitions) if length == 0 { return nil diff --git a/sdk/data/wrapper/k_faster_random_selector.go b/sdk/data/wrapper/k_faster_random_selector.go index f2a54d2a9..278bda221 100644 --- a/sdk/data/wrapper/k_faster_random_selector.go +++ b/sdk/data/wrapper/k_faster_random_selector.go @@ -142,8 +142,6 @@ func (s *KFasterRandomSelector) RemoveDP(partitionID uint64) { newRwPartition = append(newRwPartition, partitions[i+1:]...) s.Refresh(newRwPartition) - - return } func (s *KFasterRandomSelector) Count() int { diff --git a/sdk/graphql/client/login_client.go b/sdk/graphql/client/login_client.go index 5a536f9d5..a37dd2836 100644 --- a/sdk/graphql/client/login_client.go +++ b/sdk/graphql/client/login_client.go @@ -45,7 +45,7 @@ func (c *MasterGClient) ValidatePassword(ctx context.Context, userID string, pas } `, } - req.header.Set(proto.UserKey, userID) + req.header.Set(string(proto.UserKey), userID) req.header.Set("Content-Type", MIME_TYPE_JSON) req.header.Set("Accept", MIME_TYPE_JSON) @@ -146,7 +146,7 @@ func NewRequest(ctx context.Context, query string) *Request { } if userKey := ctx.Value(proto.UserKey); userKey != nil { - req.header.Set(proto.UserKey, userKey.(string)) + req.header.Set(string(proto.UserKey), userKey.(string)) } if token := ctx.Value(proto.HeadAuthorized); token != nil { @@ -199,6 +199,7 @@ func doPost(ctx context.Context, url string, qr *Request) (*Response, error) { if err != nil { return nil, err } + defer resp.Body.Close() rep := &Response{ Code: resp.StatusCode, diff --git a/sdk/master/name_resolver.go b/sdk/master/name_resolver.go index 3f63ee081..2dc9e6294 100644 --- a/sdk/master/name_resolver.go +++ b/sdk/master/name_resolver.go @@ -189,7 +189,7 @@ func (ns *NameResolver) Resolve() (changed bool, err error) { return false, fmt.Errorf("name or ip empty") } - ipSet := make(map[string]struct{}, 0) + ipSet := make(map[string]struct{}) if len(ns.domains) > 0 { var addrs []net.IP diff --git a/sdk/master/request.go b/sdk/master/request.go index 42dc6d8b2..bcede281f 100644 --- a/sdk/master/request.go +++ b/sdk/master/request.go @@ -50,16 +50,6 @@ func (r *request) addParam(key, value string) *request { return r } -func (r *request) addHeader(key, value string) *request { - r.header[key] = value - return r -} - -func (r *request) setBody(body []byte) *request { - r.body = body - return r -} - func (r *request) Param(params ...anyParam) *request { for _, param := range params { r.addParamAny(param.key, param.val) diff --git a/sdk/meta/api.go b/sdk/meta/api.go index f9c9e033c..bfd596c9f 100644 --- a/sdk/meta/api.go +++ b/sdk/meta/api.go @@ -53,20 +53,6 @@ const ( ForceUpdateRWMP = "ForceUpdateRWMP" ) -func mapHaveSameKeys(m1, m2 map[uint32]*proto.MetaQuotaInfo) bool { - if len(m1) != len(m2) { - return false - } - - for k := range m1 { - if _, ok := m2[k]; !ok { - return false - } - } - - return true -} - func (mw *MetaWrapper) GetRootIno(subdir string) (uint64, error) { rootIno, err := mw.LookupPath(subdir) if err != nil { @@ -113,7 +99,7 @@ func (mw *MetaWrapper) Statfs() (total, used, inodeCount uint64) { func (mw *MetaWrapper) Create_ll(parentID uint64, name string, mode, uid, gid uint32, target []byte, fullPath string) (*proto.InodeInfo, error) { // if mw.EnableTransaction { - txMask := proto.TxOpMaskOff + var txMask proto.TxOpMask if proto.IsRegular(mode) { txMask = proto.TxOpMaskCreate } else if proto.IsDir(mode) { @@ -148,7 +134,8 @@ func (mw *MetaWrapper) txCreate_ll(parentID uint64, name string, mode, uid, gid var quotaIds []uint32 if mw.EnableQuota { - quotaInfos, err := mw.getInodeQuota(parentMP, parentID) + var quotaInfos map[uint32]*proto.MetaQuotaInfo + quotaInfos, err = mw.getInodeQuota(parentMP, parentID) if err != nil { log.LogErrorf("Create_ll: get parent quota fail, parentID(%v) err(%v)", parentID, err) return nil, syscall.ENOENT @@ -1640,7 +1627,8 @@ func (mw *MetaWrapper) link(parentID uint64, name string, ino uint64, fullPath s return nil, statusToErrno(status) } if mw.EnableQuota { - quotaInfos, err := mw.getInodeQuota(parentMP, parentID) + var quotaInfos map[uint32]*proto.MetaQuotaInfo + quotaInfos, err = mw.getInodeQuota(parentMP, parentID) if err != nil { log.LogErrorf("link: get parent quota fail, parentID(%v) err(%v)", parentID, err) return nil, syscall.ENOENT @@ -1880,8 +1868,8 @@ func (mw *MetaWrapper) GetMultipart_ll(path, multipartId string) (info *proto.Mu return multipartInfo, nil } -func (mw *MetaWrapper) AddMultipartPart_ll(path, multipartId string, partId uint16, size uint64, md5 string, - inodeInfo *proto.InodeInfo) (oldInode uint64, updated bool, err error) { +func (mw *MetaWrapper) AddMultipartPart_ll(path, multipartId string, partId uint16, size uint64, md5 string, inodeInfo *proto.InodeInfo, +) (oldInode uint64, updated bool, err error) { var ( mpId uint64 found bool @@ -1985,7 +1973,6 @@ func (mw *MetaWrapper) ListMultipart_ll(prefix, delimiter, keyMarker string, mul if err != nil || status != statusOK { log.LogErrorf("ListMultipart: partition list multipart fail, partitionID(%v) err(%v) status(%v)", mp.PartitionID, err, status) - err = statusToErrno(status) return } wl.Lock() @@ -2132,7 +2119,6 @@ func (mw *MetaWrapper) UpdateSummary_ll(parentIno uint64, filesInc int64, dirsIn return } } - return } func (mw *MetaWrapper) ReadDirOnly_ll(parentID uint64) ([]proto.Dentry, error) { @@ -2274,7 +2260,6 @@ func (mw *MetaWrapper) getDirSummary(summaryInfo *SummaryInfo, inodeCh <-chan ui } } close(errch) - return } func (mw *MetaWrapper) getSummaryOrigin(parentIno uint64, summaryCh chan<- SummaryInfo, errCh chan<- error, wg *sync.WaitGroup, currentGoroutineNum *int32, newGoroutine bool, goroutineNum int32) { @@ -2413,7 +2398,7 @@ func (mw *MetaWrapper) refreshSummary(parentIno uint64, errCh chan<- error, wg * func (mw *MetaWrapper) BatchSetInodeQuota_ll(inodes []uint64, quotaId uint32, IsRoot bool) (ret map[uint64]uint8, err error) { batchInodeMap := make(map[uint64][]uint64) - ret = make(map[uint64]uint8, 0) + ret = make(map[uint64]uint8) for _, ino := range inodes { mp := mw.getPartitionByInode(ino) if mp == nil { @@ -2447,7 +2432,7 @@ func (mw *MetaWrapper) GetPartitionByInodeId_ll(inodeId uint64) (mp *MetaPartiti func (mw *MetaWrapper) BatchDeleteInodeQuota_ll(inodes []uint64, quotaId uint32) (ret map[uint64]uint8, err error) { batchInodeMap := make(map[uint64][]uint64) - ret = make(map[uint64]uint8, 0) + ret = make(map[uint64]uint8) for _, ino := range inodes { mp := mw.getPartitionByInode(ino) if mp == nil { diff --git a/sdk/meta/meta.go b/sdk/meta/meta.go index 1a6892fea..5bd1b22ee 100644 --- a/sdk/meta/meta.go +++ b/sdk/meta/meta.go @@ -16,7 +16,6 @@ package meta import ( gerrors "errors" - "fmt" "sync" "syscall" "time" @@ -41,7 +40,7 @@ const ( ) const ( - statusUnknown int = iota + _ int = iota statusOK statusExist statusNoent @@ -219,7 +218,7 @@ func NewMetaWrapper(config *MetaConfig) (*MetaWrapper, error) { mw.forceUpdateLimit = rate.NewLimiter(1, MinForceUpdateMetaPartitionsInterval) mw.EnableSummary = config.EnableSummary mw.DirChildrenNumLimit = proto.DefaultDirChildrenNumLimit - mw.uniqidRangeMap = make(map[uint64]*uniqidRange, 0) + mw.uniqidRangeMap = make(map[uint64]*uniqidRange) mw.qc = NewQuotaCache(DefaultQuotaExpiration, MaxQuotaCache) mw.VerReadSeq = config.VerReadSeq @@ -299,10 +298,6 @@ func (mw *MetaWrapper) LocalIP() string { return mw.localIP } -func (mw *MetaWrapper) exporterKey(act string) string { - return fmt.Sprintf("%s_sdk_meta_%s", mw.cluster, act) -} - // Proto ResultCode to status func parseStatus(result uint8) (status int) { switch result { diff --git a/sdk/meta/operation.go b/sdk/meta/operation.go index 0557dc120..d3d218cbe 100644 --- a/sdk/meta/operation.go +++ b/sdk/meta/operation.go @@ -32,7 +32,8 @@ import ( // // txIcreate create inode and tx together func (mw *MetaWrapper) txIcreate(tx *Transaction, mp *MetaPartition, mode, uid, gid uint32, - target []byte, quotaIds []uint32, fullPath string) (status int, info *proto.InodeInfo, err error) { + target []byte, quotaIds []uint32, fullPath string, +) (status int, info *proto.InodeInfo, err error) { bgTime := stat.BeginStat() defer func() { stat.EndStat("txIcreate", err, bgTime, 1) @@ -103,8 +104,8 @@ func (mw *MetaWrapper) txIcreate(tx *Transaction, mp *MetaPartition, mode, uid, return status, resp.Info, nil } -func (mw *MetaWrapper) quotaIcreate(mp *MetaPartition, mode, uid, gid uint32, target []byte, quotaIds []uint32, fullPath string) (status int, - info *proto.InodeInfo, err error) { +func (mw *MetaWrapper) quotaIcreate(mp *MetaPartition, mode, uid, gid uint32, target []byte, quotaIds []uint32, fullPath string, +) (status int, info *proto.InodeInfo, err error) { bgTime := stat.BeginStat() defer func() { stat.EndStat("icreate", err, bgTime, 1) @@ -163,8 +164,8 @@ func (mw *MetaWrapper) quotaIcreate(mp *MetaPartition, mode, uid, gid uint32, ta return statusOK, resp.Info, nil } -func (mw *MetaWrapper) icreate(mp *MetaPartition, mode, uid, gid uint32, target []byte, fullPath string) (status int, - info *proto.InodeInfo, err error) { +func (mw *MetaWrapper) icreate(mp *MetaPartition, mode, uid, gid uint32, target []byte, fullPath string, +) (status int, info *proto.InodeInfo, err error) { bgTime := stat.BeginStat() defer func() { stat.EndStat("icreate", err, bgTime, 1) @@ -251,7 +252,8 @@ func (mw *MetaWrapper) sendToMetaPartitionWithTx(mp *MetaPartition, req *proto.P } func (mw *MetaWrapper) SendTxPack(req proto.TxPack, resp interface{}, Opcode uint8, mp *MetaPartition, - checkStatusFunc func(int, *proto.Packet) error) (status int, err error, packet *proto.Packet) { + checkStatusFunc func(int, *proto.Packet) error, +) (status int, err error, packet *proto.Packet) { packet = proto.NewPacketReqID() packet.Opcode = Opcode packet.PartitionID = mp.PartitionID @@ -521,7 +523,8 @@ func (mw *MetaWrapper) txDcreate(tx *Transaction, mp *MetaPartition, parentID ui } func (mw *MetaWrapper) quotaDcreate(mp *MetaPartition, parentID uint64, name string, inode uint64, mode uint32, - quotaIds []uint32, fullPath string) (status int, err error) { + quotaIds []uint32, fullPath string, +) (status int, err error) { bgTime := stat.BeginStat() defer func() { stat.EndStat("dcreate", err, bgTime, 1) @@ -888,8 +891,8 @@ func (mw *MetaWrapper) canDeleteInode(mp *MetaPartition, info *proto.InodeInfo, return true, nil } -func (mw *MetaWrapper) ddeletes(mp *MetaPartition, parentID uint64, dentries []proto.Dentry, fullPaths []string) (status int, - resp *proto.BatchDeleteDentryResponse, err error) { +func (mw *MetaWrapper) ddeletes(mp *MetaPartition, parentID uint64, dentries []proto.Dentry, fullPaths []string, +) (status int, resp *proto.BatchDeleteDentryResponse, err error) { bgTime := stat.BeginStat() defer func() { stat.EndStat("ddeletes", err, bgTime, 1) @@ -2481,8 +2484,8 @@ func (mw *MetaWrapper) updateXAttrs(mp *MetaPartition, inode uint64, filesInc in return nil } -func (mw *MetaWrapper) batchSetInodeQuota(mp *MetaPartition, inodes []uint64, quotaId uint32, - IsRoot bool) (resp *proto.BatchSetMetaserverQuotaResponse, err error) { +func (mw *MetaWrapper) batchSetInodeQuota(mp *MetaPartition, inodes []uint64, quotaId uint32, IsRoot bool, +) (resp *proto.BatchSetMetaserverQuotaResponse, err error) { bgTime := stat.BeginStat() defer func() { stat.EndStat("batchSetInodeQuota", err, bgTime, 1) @@ -2521,7 +2524,7 @@ func (mw *MetaWrapper) batchSetInodeQuota(mp *MetaPartition, inodes []uint64, qu return } resp = new(proto.BatchSetMetaserverQuotaResponse) - resp.InodeRes = make(map[uint64]uint8, 0) + resp.InodeRes = make(map[uint64]uint8) if err = packet.UnmarshalData(resp); err != nil { log.LogErrorf("batchSetInodeQuota: packet(%v) mp(%v) req(%v) err(%v) PacketData(%v)", packet, mp, *req, err, string(packet.Data)) return @@ -2530,8 +2533,8 @@ func (mw *MetaWrapper) batchSetInodeQuota(mp *MetaPartition, inodes []uint64, qu return } -func (mw *MetaWrapper) batchDeleteInodeQuota(mp *MetaPartition, inodes []uint64, - quotaId uint32) (resp *proto.BatchDeleteMetaserverQuotaResponse, err error) { +func (mw *MetaWrapper) batchDeleteInodeQuota(mp *MetaPartition, inodes []uint64, quotaId uint32, +) (resp *proto.BatchDeleteMetaserverQuotaResponse, err error) { bgTime := stat.BeginStat() defer func() { stat.EndStat("batchDeleteInodeQuota", err, bgTime, 1) @@ -2568,7 +2571,7 @@ func (mw *MetaWrapper) batchDeleteInodeQuota(mp *MetaPartition, inodes []uint64, return } resp = new(proto.BatchDeleteMetaserverQuotaResponse) - resp.InodeRes = make(map[uint64]uint8, 0) + resp.InodeRes = make(map[uint64]uint8) if err = packet.UnmarshalData(resp); err != nil { log.LogErrorf("batchSetInodeQuota: packet(%v) mp(%v) req(%v) err(%v) PacketData(%v)", packet, mp, *req, err, string(packet.Data)) return @@ -2636,7 +2639,8 @@ func (mw *MetaWrapper) getInodeQuota(mp *MetaPartition, inode uint64) (quotaInfo } func (mw *MetaWrapper) applyQuota(parentIno uint64, quotaId uint32, totalInodeCount *uint64, curInodeCount *uint64, inodes *[]uint64, - maxInodes uint64, first bool) (err error) { + maxInodes uint64, first bool, +) (err error) { if first { var rootInodes []uint64 var ret map[uint64]uint8 @@ -2707,7 +2711,8 @@ func (mw *MetaWrapper) applyQuota(parentIno uint64, quotaId uint32, totalInodeCo } func (mw *MetaWrapper) revokeQuota(parentIno uint64, quotaId uint32, totalInodeCount *uint64, curInodeCount *uint64, inodes *[]uint64, - maxInodes uint64, first bool) (err error) { + maxInodes uint64, first bool, +) (err error) { if first { var rootInodes []uint64 rootInodes = append(rootInodes, parentIno) diff --git a/sdk/meta/partition.go b/sdk/meta/partition.go index b4f969883..381dddf87 100644 --- a/sdk/meta/partition.go +++ b/sdk/meta/partition.go @@ -65,7 +65,6 @@ func (mw *MetaWrapper) replaceOrInsertPartition(mp *MetaPartition) { } mw.addPartition(mp) - return } func (mw *MetaWrapper) getPartitionByID(id uint64) *MetaPartition { @@ -120,25 +119,3 @@ func (mw *MetaWrapper) getRWPartitions() []*MetaPartition { } return rwPartitions } - -// GetConnect the partition whose Start is Larger than ino. -// Return nil if no successive partition. -func (mw *MetaWrapper) getNextPartition(ino uint64) *MetaPartition { - var mp *MetaPartition - mw.RLock() - defer mw.RUnlock() - - pivot := &MetaPartition{Start: ino + 1} - mw.ranges.AscendGreaterOrEqual(pivot, func(i btree.Item) bool { - mp = i.(*MetaPartition) - return false - }) - - return mp -} - -func (mw *MetaWrapper) getLatestPartition() *MetaPartition { - mw.RLock() - defer mw.RUnlock() - return mw.ranges.Max().(*MetaPartition) -} diff --git a/sdk/meta/view.go b/sdk/meta/view.go index cbd08a6d6..7a40a9719 100644 --- a/sdk/meta/view.go +++ b/sdk/meta/view.go @@ -429,7 +429,7 @@ func (mw *MetaWrapper) IsQuotaLimited(quotaIds []uint32) bool { } func (mw *MetaWrapper) GetQuotaFullPaths() (fullPaths []string) { - fullPaths = make([]string, 0, 0) + fullPaths = make([]string, 0) mw.QuotaLock.RLock() defer mw.QuotaLock.RUnlock() for _, info := range mw.QuotaInfoMap { diff --git a/snapshot/cmd/clean.go b/snapshot/cmd/clean.go index 860108b91..fd9f04e57 100644 --- a/snapshot/cmd/clean.go +++ b/snapshot/cmd/clean.go @@ -37,6 +37,12 @@ const snapshotFullPath = "(Snapshot Cmd Unsupported)" var gMetaWrapper *meta.MetaWrapper +// TODO: unused +var ( + _ = readSnapshot + _ = doUnlinkInode +) + func newCleanCmd() *cobra.Command { c := &cobra.Command{ Use: "clean", @@ -237,7 +243,6 @@ func doUnlinkInode(inode *Inode) error { if err != syscall.ENOENT { return err } - err = nil } err = gMetaWrapper.Evict(inode.Inode, snapshotFullPath) diff --git a/snapshot/cmd/root.go b/snapshot/cmd/root.go index e29f68c78..e550b76b5 100644 --- a/snapshot/cmd/root.go +++ b/snapshot/cmd/root.go @@ -31,7 +31,7 @@ func NewRootCmd() *cobra.Command { Args: cobra.MinimumNArgs(0), Run: func(cmd *cobra.Command, args []string) { if optShowVersion { - _, _ = fmt.Fprintf(os.Stdout, proto.DumpVersion("SNAPSHOT")) + fmt.Fprintln(os.Stdout, proto.DumpVersion("SNAPSHOT")) return } }, diff --git a/storage/extent_store.go b/storage/extent_store.go index 7d74db5fa..5558476b3 100644 --- a/storage/extent_store.go +++ b/storage/extent_store.go @@ -38,9 +38,6 @@ import ( "github.com/cubefs/cubefs/util/log" ) -//TODO: remove this later. -//go:generate golangci-lint run --issues-exit-code=1 -D errcheck -E bodyclose ./... - const ( ExtCrcHeaderFileName = "EXTENT_CRC" ExtBaseExtentIDFileName = "EXTENT_META" diff --git a/util/btree/btree_test.go b/util/btree/btree_test.go index 4dacdd9bf..dc7aee0a4 100644 --- a/util/btree/btree_test.go +++ b/util/btree/btree_test.go @@ -17,6 +17,7 @@ package btree import ( "flag" "fmt" + "io" "math/rand" "reflect" "sort" @@ -161,6 +162,7 @@ func TestDeleteMin(t *testing.T) { for _, v := range perm(100) { tr.ReplaceOrInsert(v) } + tr.root.print(io.Discard, 2) var got []Item for v := tr.DeleteMin(); v != nil; v = tr.DeleteMin() { got = append(got, v) diff --git a/util/buf/bcache_pool.go b/util/buf/bcache_pool.go index eb9f0d1b2..cf160538c 100644 --- a/util/buf/bcache_pool.go +++ b/util/buf/bcache_pool.go @@ -50,5 +50,5 @@ func (fileCachePool *FileBCachePool) Get() []byte { func (fileCachePool *FileBCachePool) Put(data []byte) { atomic.AddInt64(&bcacheCount, -1) - fileCachePool.pool.Put(data) + fileCachePool.pool.Put(data) // nolint: staticcheck } diff --git a/util/buf/buffer_pool.go b/util/buf/buffer_pool.go index 0b49c7228..bccd28b04 100644 --- a/util/buf/buffer_pool.go +++ b/util/buf/buffer_pool.go @@ -193,7 +193,7 @@ func (bufferP *BufferPool) putHead(index int, data []byte) { case bufferP.headPools[index] <- data: return default: - bufferP.headPool.Put(data) + bufferP.headPool.Put(data) // nolint: staticcheck } } @@ -202,7 +202,7 @@ func (bufferP *BufferPool) putHeadVer(index int, data []byte) { case bufferP.headVerPools[index] <- data: return default: - bufferP.headVerPool.Put(data) + bufferP.headVerPool.Put(data) // nolint: staticcheck } } @@ -211,7 +211,7 @@ func (bufferP *BufferPool) putNormal(index int, data []byte) { case bufferP.normalPools[index] <- data: return default: - bufferP.normalPool.Put(data) + bufferP.normalPool.Put(data) // nolint: staticcheck } } @@ -234,7 +234,7 @@ func (bufferP *BufferPool) Put(data []byte) { id := atomic.AddUint64(&normalBufFreecId, 1) bufferP.putNormal(int(id%slotCnt), data) } else if size == util.DefaultTinySizeLimit { - bufferP.tinyPool.Put(data) + bufferP.tinyPool.Put(data) // nolint: staticcheck atomic.AddInt64(&tinyBuffersCount, -1) } } diff --git a/util/buf/cache_pool.go b/util/buf/cache_pool.go index fbcfdcbee..7435e9ae6 100644 --- a/util/buf/cache_pool.go +++ b/util/buf/cache_pool.go @@ -51,5 +51,5 @@ func (fileCachePool *FileCachePool) Put(data []byte) { log.LogInfof("action[FileCachePool.put] %v", fileCachePool) log.LogInfof("action[FileCachePool.put] pool %v", fileCachePool.pool) atomic.AddInt64(&cacheCount, -1) - fileCachePool.pool.Put(data) + fileCachePool.pool.Put(data) // nolint: staticcheck } diff --git a/util/log/log.go b/util/log/log.go index 6ffc06951..a5b221a30 100644 --- a/util/log/log.go +++ b/util/log/log.go @@ -21,6 +21,7 @@ import ( "fmt" "io/ioutil" "log" + syslog "log" "math" "net/http" "os" @@ -35,7 +36,6 @@ import ( "time" blog "github.com/cubefs/cubefs/blobstore/util/log" - syslog "log" ) type Level uint8 @@ -98,7 +98,6 @@ func setBlobLogLevel(loglevel Level) { case ErrorLevel: blevel = blog.Lerror default: - blevel = blog.Lwarn } blog.SetOutputLevel(blevel) } diff --git a/util/smux_conn_pool.go b/util/smux_conn_pool.go index 40103a645..c4f749de5 100644 --- a/util/smux_conn_pool.go +++ b/util/smux_conn_pool.go @@ -381,14 +381,11 @@ func (p *SmuxPool) callCreate() (createCall *createSessCall) { if createCall == nil { goto tryCreateNewSess } - select { - case <-createCall.notify: - if time.Now().UnixNano()-createCall.idle > defaultCreateInterval { - goto tryCreateNewSess - } else { - return - } - // default: + <-createCall.notify + if time.Now().UnixNano()-createCall.idle > defaultCreateInterval { + goto tryCreateNewSess + } else { + return } tryCreateNewSess: prev := createCall diff --git a/util/smux_conn_pool_test.go b/util/smux_conn_pool_test.go index 4e423bf37..4179348e3 100644 --- a/util/smux_conn_pool_test.go +++ b/util/smux_conn_pool_test.go @@ -514,7 +514,7 @@ func TestConcurrentGetConn(t *testing.T) { defer wg.Done() stream, err := pool.GetConnect(addr) if err != nil { - t.Fatal(err) + panic(err) } streamsCh <- stream }() @@ -559,7 +559,7 @@ func TestConcurrentGetPutConn(t *testing.T) { defer wg.Done() stream, err := pool.GetConnect(addr) if err != nil { - t.Fatal(err) + panic(err) } time.Sleep(time.Millisecond * time.Duration(rand.Intn(10)+1)) diff --git a/util/unboundedchan/unbounded_chan_test.go b/util/unboundedchan/unbounded_chan_test.go index ca778a1d7..7eea87a98 100644 --- a/util/unboundedchan/unbounded_chan_test.go +++ b/util/unboundedchan/unbounded_chan_test.go @@ -15,6 +15,7 @@ package unboundedchan import ( + "fmt" "sync" "testing" ) @@ -43,17 +44,17 @@ func TestWriteReadUnboundedChan(t *testing.T) { t.Logf("val(%v), ok(%v)", val, ok) v1, ok := values[val] if ok { - t.Fatalf("value(%v) is not expected to be in UnboundedChan multiple times", v1) + panic(fmt.Sprintf("value(%v) is not expected to be in UnboundedChan multiple times", v1)) } else { values[val] = val } if v1 >= 100 || v1 < 0 { - t.Fatalf("value(%v) is expected in range 0-99", v1) + panic(fmt.Sprintf("value(%v) is expected in range 0-99", v1)) } total++ } if total != 100 { - t.Fatalf("expected total num(%v), got(%v)", 100, total) + panic(fmt.Sprintf("expected total num(%v), got(%v)", 100, total)) } t.Logf("total: %v", total) }()