From 62b28d06264852b5f4da3a20c16454eb6d83c7f6 Mon Sep 17 00:00:00 2001 From: Victor1319 Date: Thu, 24 Apr 2025 17:32:44 +0800 Subject: [PATCH] refactor(fmt): use gofumpt to format code. #1000063488 Signed-off-by: Victor1319 --- blobstore/common/raftserver/proto.pb.go | 26 +++++++++++--- datanode/partition.go | 46 ------------------------- datanode/partition_raft.go | 2 -- datanode/space_manager.go | 3 +- datanode/storage/extent.go | 6 ++-- flashnode/flashnode_op.go | 3 +- master/api_args_parse.go | 13 ------- master/data_partition.go | 13 ------- master/meta_node.go | 4 +-- master/vol.go | 6 ---- metanode/inode.go | 1 - proto/distributed_cache.pb.go | 40 ++++++++++++++++++--- 12 files changed, 67 insertions(+), 96 deletions(-) diff --git a/blobstore/common/raftserver/proto.pb.go b/blobstore/common/raftserver/proto.pb.go index a0e1573c4..d98262634 100644 --- a/blobstore/common/raftserver/proto.pb.go +++ b/blobstore/common/raftserver/proto.pb.go @@ -5,16 +5,19 @@ package raftserver import ( fmt "fmt" - proto "github.com/golang/protobuf/proto" io "io" math "math" math_bits "math/bits" + + proto "github.com/golang/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf +var ( + _ = proto.Marshal + _ = fmt.Errorf + _ = math.Inf +) // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -38,9 +41,11 @@ func (*Member) ProtoMessage() {} func (*Member) Descriptor() ([]byte, []int) { return fileDescriptor_2fcc84b9998d60d8, []int{0} } + func (m *Member) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *Member) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_Member.Marshal(b, m, deterministic) @@ -53,12 +58,15 @@ func (m *Member) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return b[:n], nil } } + func (m *Member) XXX_Merge(src proto.Message) { xxx_messageInfo_Member.Merge(m, src) } + func (m *Member) XXX_Size() int { return m.Size() } + func (m *Member) XXX_DiscardUnknown() { xxx_messageInfo_Member.DiscardUnknown(m) } @@ -111,9 +119,11 @@ func (*SnapshotMeta) ProtoMessage() {} func (*SnapshotMeta) Descriptor() ([]byte, []int) { return fileDescriptor_2fcc84b9998d60d8, []int{1} } + func (m *SnapshotMeta) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *SnapshotMeta) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_SnapshotMeta.Marshal(b, m, deterministic) @@ -126,12 +136,15 @@ func (m *SnapshotMeta) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return b[:n], nil } } + func (m *SnapshotMeta) XXX_Merge(src proto.Message) { xxx_messageInfo_SnapshotMeta.Merge(m, src) } + func (m *SnapshotMeta) XXX_Size() int { return m.Size() } + func (m *SnapshotMeta) XXX_DiscardUnknown() { xxx_messageInfo_SnapshotMeta.DiscardUnknown(m) } @@ -368,6 +381,7 @@ func encodeVarintProto(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } + func (m *Member) Size() (n int) { if m == nil { return 0 @@ -439,9 +453,11 @@ func (m *SnapshotMeta) Size() (n int) { func sovProto(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } + func sozProto(x uint64) (n int) { return sovProto(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } + func (m *Member) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -598,6 +614,7 @@ func (m *Member) Unmarshal(dAtA []byte) error { } return nil } + func (m *SnapshotMeta) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -905,6 +922,7 @@ func (m *SnapshotMeta) Unmarshal(dAtA []byte) error { } return nil } + func skipProto(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/datanode/partition.go b/datanode/partition.go index 7823f0663..762059c72 100644 --- a/datanode/partition.go +++ b/datanode/partition.go @@ -1365,52 +1365,6 @@ func (dp *DataPartition) isNormalType() bool { return proto.IsNormalDp(dp.partitionType) } -type SimpleVolView struct { - vv *proto.SimpleVolView - lastUpdateTime time.Time -} - -type VolMap struct { - sync.Mutex - volMap map[string]*SimpleVolView -} - -var volViews = VolMap{ - Mutex: sync.Mutex{}, - volMap: make(map[string]*SimpleVolView), -} - -func (vo *VolMap) getSimpleVolView(VolumeID string) (vv *proto.SimpleVolView, err error) { - vo.Lock() - if volView, ok := vo.volMap[VolumeID]; ok && time.Since(volView.lastUpdateTime) < 5*time.Minute { - vo.Unlock() - return volView.vv, nil - } - vo.Unlock() - - volView := &SimpleVolView{ - vv: nil, - lastUpdateTime: time.Time{}, - } - - if vv, err = MasterClient.AdminAPI().GetVolumeSimpleInfo(VolumeID); err != nil { - log.LogErrorf("action[GetVolumeSimpleInfo] cannot get vol(%v) from master(%v) err(%v).", - VolumeID, MasterClient.Leader(), err) - return nil, err - } - - log.LogDebugf("get volume info, vol(%s), vol(%v)", vv.Name, volView) - - volView.vv = vv - volView.lastUpdateTime = time.Now() - - vo.Lock() - vo.volMap[VolumeID] = volView - vo.Unlock() - - return -} - func (dp *DataPartition) StopDecommissionRecover(stop bool) { // only work for decommission repair if !dp.isDecommissionRecovering() { diff --git a/datanode/partition_raft.go b/datanode/partition_raft.go index b9635724b..33381fab6 100644 --- a/datanode/partition_raft.go +++ b/datanode/partition_raft.go @@ -210,7 +210,6 @@ func (dp *DataPartition) CanRemoveRaftMember(peer proto.Peer, force bool) error // 2. collect the applied ids from raft members. // 3. based on the minimum applied id to cutoff and delete the saved raft log in order to free the disk space. func (dp *DataPartition) StartRaftLoggingSchedule() { - getAppliedIDTimer := time.NewTimer(time.Second * 1) truncateRaftLogTimer := time.NewTimer(time.Minute * 10) storeAppliedIDTimer := time.NewTimer(time.Second * 10) @@ -389,7 +388,6 @@ func (dp *DataPartition) StartRaftAfterRepair(isLoad bool) { // Add a raft node. func (dp *DataPartition) addRaftNode(req *proto.AddDataPartitionRaftMemberRequest, index uint64) (isUpdated bool, err error) { - var ( heartbeatPort int replicaPort int diff --git a/datanode/space_manager.go b/datanode/space_manager.go index 3a10f69b3..afce23745 100644 --- a/datanode/space_manager.go +++ b/datanode/space_manager.go @@ -323,7 +323,8 @@ func (manager *SpaceManager) reloadDisk(path string) (err error) { rdonlySpace uint64 maxErr int repairLimit bool - }) { + }, + ) { err := manager.LoadDisk( params.path, params.reserved, diff --git a/datanode/storage/extent.go b/datanode/storage/extent.go index 6c035d884..dcf9a1460 100644 --- a/datanode/storage/extent.go +++ b/datanode/storage/extent.go @@ -52,8 +52,10 @@ const ( magicNumber = byte('M') ) -var ErrNonBytecodeEncode = errors.New("non-bytecode serialization method") -var atime uint64 +var ( + ErrNonBytecodeEncode = errors.New("non-bytecode serialization method") + atime uint64 +) func alignment(block []byte, AlignSize int) int { return int(uintptr(unsafe.Pointer(&block[0])) & uintptr(AlignSize-1)) diff --git a/flashnode/flashnode_op.go b/flashnode/flashnode_op.go index 83ecdacdd..da8d7b987 100644 --- a/flashnode/flashnode_op.go +++ b/flashnode/flashnode_op.go @@ -389,7 +389,8 @@ func (f *FlashNode) getValidViewInfo(req *proto.FlashNodeManualTaskRequest) (met } func (f *FlashNode) doStreamReadRequest(ctx context.Context, conn net.Conn, req *proto.CacheReadRequest, p *proto.Packet, - block *cachengine.CacheBlock) (err error) { + block *cachengine.CacheBlock, +) (err error) { const action = "action[doStreamReadRequest]" needReplySize := uint32(req.Size_) offset := int64(req.Offset) diff --git a/master/api_args_parse.go b/master/api_args_parse.go index b005b6f08..a36e607b2 100644 --- a/master/api_args_parse.go +++ b/master/api_args_parse.go @@ -1864,19 +1864,6 @@ func extractUint(r *http.Request, key string) (val int, err error) { return val, nil } -func extractPositiveUint(r *http.Request, key string) (val int, err error) { - var str string - if str = r.FormValue(key); str == "" { - return 0, fmt.Errorf("args [%s] is not legal", key) - } - - if val, err = strconv.Atoi(str); err != nil || val <= 0 { - return 0, fmt.Errorf("args [%s] is not legal, val %s", key, str) - } - - return val, nil -} - func extractUint64(r *http.Request, key string) (val uint64, err error) { var str string if str = r.FormValue(key); str == "" { diff --git a/master/data_partition.go b/master/data_partition.go index 324cb0676..2af7d094a 100644 --- a/master/data_partition.go +++ b/master/data_partition.go @@ -143,19 +143,6 @@ func (partition *DataPartition) resetFilesWithMissingReplica() { partition.FilesWithMissingReplica = make(map[string]int64) } -func (partition *DataPartition) dataNodeStartTime() int64 { - partition.Lock() - defer partition.Unlock() - startTime := int64(0) - for _, replica := range partition.Replicas { - if startTime < replica.dataNode.StartTime { - startTime = replica.dataNode.StartTime - } - } - - return startTime -} - func (partition *DataPartition) addReplica(replica *DataReplica) { for _, r := range partition.Replicas { if replica.Addr == r.Addr { diff --git a/master/meta_node.go b/master/meta_node.go index e60e066e9..ef069aa13 100644 --- a/master/meta_node.go +++ b/master/meta_node.go @@ -187,8 +187,8 @@ func (metaNode *MetaNode) reachesThreshold() bool { return float32(float64(metaNode.Used)/float64(metaNode.Total)) > metaNode.Threshold } -func (metaNode *MetaNode) createHeartbeatTask(masterAddr string, fileStatsEnable bool, - notifyForbidWriteOpOfProtoVer0 bool, RaftPartitionCanUsingDifferentPortEnabled bool, +func (metaNode *MetaNode) createHeartbeatTask(masterAddr string, fileStatsEnable bool, fileStatsThresholds []uint64, + notifyForbidWriteOpOfProtoVer0 bool, metaNodeGOGC int, RaftPartitionCanUsingDifferentPortEnabled bool, ) (task *proto.AdminTask) { request := &proto.HeartBeatRequest{ CurrTime: time.Now().Unix(), diff --git a/master/vol.go b/master/vol.go index 2340506ec..a26a0549b 100644 --- a/master/vol.go +++ b/master/vol.go @@ -725,7 +725,6 @@ func (vol *Vol) checkDataPartitions(c *Cluster) (cnt int) { } } - totalPreloadCapacity := uint64(0) var rwDpCountOfSSD int var rwDpCountOfHDD int @@ -779,10 +778,6 @@ func (vol *Vol) checkDataPartitions(c *Cluster) (cnt int) { dp.checkReplicationTask(c.Name, vol.dataPartitionSize) } - if overSoldFactor > 0 { - totalPreloadCapacity = uint64(float32(totalPreloadCapacity) / overSoldFactor) - } - vol.dataPartitions.setReadWriteDataPartitionCntByMediaType(rwDpCountOfHDD, proto.MediaType_HDD) vol.dataPartitions.setReadWriteDataPartitionCntByMediaType(rwDpCountOfSSD, proto.MediaType_SSD) log.LogInfof("[checkDataPartitions] vol(%v), rwDpCountOfHDD(%v), rwDpCountOfSSD(%v)", @@ -1529,7 +1524,6 @@ func (vol *Vol) deleteDataPartitionFromDataNode(c *Cluster, task *proto.AdminTas _, err = dataNode.TaskManager.syncSendAdminTask(task) if err != nil { log.LogErrorf("action[deleteDataReplica] vol[%v],data partition[%v],err[%v]", dp.VolName, dp.PartitionID, err) - err = nil } dp.Lock() diff --git a/metanode/inode.go b/metanode/inode.go index 12d729b0d..7f310add9 100644 --- a/metanode/inode.go +++ b/metanode/inode.go @@ -109,7 +109,6 @@ func (i *Inode) LeaseNotExpire() bool { } func (i *Inode) GetExtents() *SortedExtents { - if proto.IsStorageClassBlobStore(i.StorageClass) { return NewSortedExtents() } diff --git a/proto/distributed_cache.pb.go b/proto/distributed_cache.pb.go index c9cccadd0..da692132a 100644 --- a/proto/distributed_cache.pb.go +++ b/proto/distributed_cache.pb.go @@ -5,17 +5,20 @@ package proto import ( fmt "fmt" - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/golang/protobuf/proto" io "io" math "math" math_bits "math/bits" + + _ "github.com/gogo/protobuf/gogoproto" + proto "github.com/golang/protobuf/proto" ) // Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf +var ( + _ = proto.Marshal + _ = fmt.Errorf + _ = math.Inf +) // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -40,9 +43,11 @@ func (*DataSource) ProtoMessage() {} func (*DataSource) Descriptor() ([]byte, []int) { return fileDescriptor_9a29821e5022ef34, []int{0} } + func (m *DataSource) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *DataSource) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_DataSource.Marshal(b, m, deterministic) @@ -55,12 +60,15 @@ func (m *DataSource) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { return b[:n], nil } } + func (m *DataSource) XXX_Merge(src proto.Message) { xxx_messageInfo_DataSource.Merge(m, src) } + func (m *DataSource) XXX_Size() int { return m.Size() } + func (m *DataSource) XXX_DiscardUnknown() { xxx_messageInfo_DataSource.DiscardUnknown(m) } @@ -127,9 +135,11 @@ func (*CacheRequest) ProtoMessage() {} func (*CacheRequest) Descriptor() ([]byte, []int) { return fileDescriptor_9a29821e5022ef34, []int{1} } + func (m *CacheRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *CacheRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_CacheRequest.Marshal(b, m, deterministic) @@ -142,12 +152,15 @@ func (m *CacheRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) return b[:n], nil } } + func (m *CacheRequest) XXX_Merge(src proto.Message) { xxx_messageInfo_CacheRequest.Merge(m, src) } + func (m *CacheRequest) XXX_Size() int { return m.Size() } + func (m *CacheRequest) XXX_DiscardUnknown() { xxx_messageInfo_CacheRequest.DiscardUnknown(m) } @@ -217,9 +230,11 @@ func (*CacheReadRequest) ProtoMessage() {} func (*CacheReadRequest) Descriptor() ([]byte, []int) { return fileDescriptor_9a29821e5022ef34, []int{2} } + func (m *CacheReadRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *CacheReadRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_CacheReadRequest.Marshal(b, m, deterministic) @@ -232,12 +247,15 @@ func (m *CacheReadRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, er return b[:n], nil } } + func (m *CacheReadRequest) XXX_Merge(src proto.Message) { xxx_messageInfo_CacheReadRequest.Merge(m, src) } + func (m *CacheReadRequest) XXX_Size() int { return m.Size() } + func (m *CacheReadRequest) XXX_DiscardUnknown() { xxx_messageInfo_CacheReadRequest.DiscardUnknown(m) } @@ -278,9 +296,11 @@ func (*CachePrepareRequest) ProtoMessage() {} func (*CachePrepareRequest) Descriptor() ([]byte, []int) { return fileDescriptor_9a29821e5022ef34, []int{3} } + func (m *CachePrepareRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } + func (m *CachePrepareRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { return xxx_messageInfo_CachePrepareRequest.Marshal(b, m, deterministic) @@ -293,12 +313,15 @@ func (m *CachePrepareRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, return b[:n], nil } } + func (m *CachePrepareRequest) XXX_Merge(src proto.Message) { xxx_messageInfo_CachePrepareRequest.Merge(m, src) } + func (m *CachePrepareRequest) XXX_Size() int { return m.Size() } + func (m *CachePrepareRequest) XXX_DiscardUnknown() { xxx_messageInfo_CachePrepareRequest.DiscardUnknown(m) } @@ -601,6 +624,7 @@ func encodeVarintDistributedCache(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } + func (m *DataSource) Size() (n int) { if m == nil { return 0 @@ -718,9 +742,11 @@ func (m *CachePrepareRequest) Size() (n int) { func sovDistributedCache(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } + func sozDistributedCache(x uint64) (n int) { return sovDistributedCache(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } + func (m *DataSource) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -899,6 +925,7 @@ func (m *DataSource) Unmarshal(dAtA []byte) error { } return nil } + func (m *CacheRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1111,6 +1138,7 @@ func (m *CacheRequest) Unmarshal(dAtA []byte) error { } return nil } + func (m *CacheReadRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1236,6 +1264,7 @@ func (m *CacheReadRequest) Unmarshal(dAtA []byte) error { } return nil } + func (m *CachePrepareRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1355,6 +1384,7 @@ func (m *CachePrepareRequest) Unmarshal(dAtA []byte) error { } return nil } + func skipDistributedCache(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0