From a4b25a642d6b2ed6056496ffddce864100932f3d Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 29 Aug 2024 09:52:21 -0700 Subject: [PATCH] math/rand => math/rand/v2 --- weed/operation/lookup.go | 4 ++-- weed/operation/submit.go | 4 ++-- weed/pb/grpc_client_server.go | 2 +- weed/server/filer_server_handlers_proxy.go | 6 +++--- weed/server/master_grpc_server_admin.go | 4 ++-- weed/server/master_grpc_server_cluster.go | 6 +++--- weed/server/master_grpc_server_volume.go | 2 +- weed/server/master_server_handlers_admin.go | 4 ++-- weed/server/raft_hashicorp.go | 2 +- weed/server/raft_server.go | 2 +- weed/topology/node.go | 4 ++-- weed/topology/topology.go | 2 +- weed/topology/topology_event_handling.go | 2 +- weed/topology/volume_growth.go | 6 +++--- weed/topology/volume_layout.go | 4 ++-- 15 files changed, 27 insertions(+), 27 deletions(-) diff --git a/weed/operation/lookup.go b/weed/operation/lookup.go index 6c89c17b1..9e9c719b5 100644 --- a/weed/operation/lookup.go +++ b/weed/operation/lookup.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/seaweedfs/seaweedfs/weed/pb" "google.golang.org/grpc" - "math/rand" + "math/rand/v2" "strings" "time" @@ -51,7 +51,7 @@ func LookupFileId(masterFn GetMasterFn, grpcDialOption grpc.DialOption, fileId s if len(lookup.Locations) == 0 { return "", jwt, errors.New("File Not Found") } - return "http://" + lookup.Locations[rand.Intn(len(lookup.Locations))].Url + "/" + fileId, lookup.Jwt, nil + return "http://" + lookup.Locations[rand.IntN(len(lookup.Locations))].Url + "/" + fileId, lookup.Jwt, nil } func LookupVolumeId(masterFn GetMasterFn, grpcDialOption grpc.DialOption, vid string) (*LookupResult, error) { diff --git a/weed/operation/submit.go b/weed/operation/submit.go index 66d5542af..73e50cc48 100644 --- a/weed/operation/submit.go +++ b/weed/operation/submit.go @@ -4,7 +4,7 @@ import ( "context" "github.com/seaweedfs/seaweedfs/weed/pb" "io" - "math/rand" + "math/rand/v2" "mime" "net/url" "os" @@ -236,7 +236,7 @@ func genFileUrl(ret *AssignResult, id string, usePublicUrl bool) string { fileUrl = "http://" + ret.PublicUrl + "/" + id } for _, replica := range ret.Replicas { - if rand.Intn(len(ret.Replicas)+1) == 0 { + if rand.IntN(len(ret.Replicas)+1) == 0 { fileUrl = "http://" + replica.Url + "/" + id if usePublicUrl { fileUrl = "http://" + replica.PublicUrl + "/" + id diff --git a/weed/pb/grpc_client_server.go b/weed/pb/grpc_client_server.go index 2df2be70f..777dfb402 100644 --- a/weed/pb/grpc_client_server.go +++ b/weed/pb/grpc_client_server.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "google.golang.org/grpc/metadata" - "math/rand" + "math/rand/v2" "net/http" "strconv" "strings" diff --git a/weed/server/filer_server_handlers_proxy.go b/weed/server/filer_server_handlers_proxy.go index c1a26ca11..ca445ef9a 100644 --- a/weed/server/filer_server_handlers_proxy.go +++ b/weed/server/filer_server_handlers_proxy.go @@ -3,11 +3,11 @@ package weed_server import ( "github.com/seaweedfs/seaweedfs/weed/glog" "github.com/seaweedfs/seaweedfs/weed/security" + util_http "github.com/seaweedfs/seaweedfs/weed/util/http" "github.com/seaweedfs/seaweedfs/weed/util/mem" "io" - "math/rand" + "math/rand/v2" "net/http" - util_http "github.com/seaweedfs/seaweedfs/weed/util/http" ) func (fs *FilerServer) maybeAddVolumeJwtAuthorization(r *http.Request, fileId string, isWrite bool) { @@ -44,7 +44,7 @@ func (fs *FilerServer) proxyToVolumeServer(w http.ResponseWriter, r *http.Reques return } - proxyReq, err := http.NewRequest(r.Method, urlStrings[rand.Intn(len(urlStrings))], r.Body) + proxyReq, err := http.NewRequest(r.Method, urlStrings[rand.IntN(len(urlStrings))], r.Body) if err != nil { glog.Errorf("NewRequest %s: %v", urlStrings[0], err) w.WriteHeader(http.StatusInternalServerError) diff --git a/weed/server/master_grpc_server_admin.go b/weed/server/master_grpc_server_admin.go index 7a28e0ed6..d8b63b5da 100644 --- a/weed/server/master_grpc_server_admin.go +++ b/weed/server/master_grpc_server_admin.go @@ -4,7 +4,7 @@ import ( "context" "fmt" "github.com/seaweedfs/seaweedfs/weed/stats" - "math/rand" + "math/rand/v2" "sync" "time" @@ -108,7 +108,7 @@ func (locks *AdminLocks) generateToken(lockName string, clientName string) (ts t locks.Lock() defer locks.Unlock() lock := &AdminLock{ - accessSecret: rand.Int63(), + accessSecret: rand.Int64(), accessLockTime: time.Now(), lastClient: clientName, } diff --git a/weed/server/master_grpc_server_cluster.go b/weed/server/master_grpc_server_cluster.go index 62f5da09e..5c99fd00d 100644 --- a/weed/server/master_grpc_server_cluster.go +++ b/weed/server/master_grpc_server_cluster.go @@ -5,7 +5,7 @@ import ( "github.com/seaweedfs/seaweedfs/weed/cluster" "github.com/seaweedfs/seaweedfs/weed/pb" "github.com/seaweedfs/seaweedfs/weed/pb/master_pb" - "math/rand" + "math/rand/v2" ) func (ms *MasterServer) ListClusterNodes(ctx context.Context, req *master_pb.ListClusterNodesRequest) (*master_pb.ListClusterNodesResponse, error) { @@ -31,7 +31,7 @@ func (ms *MasterServer) GetOneFiler(filerGroup cluster.FilerGroupName) pb.Server filers := ms.Cluster.ListClusterNode(filerGroup, cluster.FilerType) if len(filers) > 0 { - return filers[rand.Intn(len(filers))].Address + return filers[rand.IntN(len(filers))].Address } return "localhost:8888" } @@ -42,7 +42,7 @@ func limitTo(nodes []*cluster.ClusterNode, limit int32) (selected []*cluster.Clu } selectedSet := make(map[pb.ServerAddress]*cluster.ClusterNode) for i := 0; i < int(limit)*3; i++ { - x := rand.Intn(len(nodes)) + x := rand.IntN(len(nodes)) if _, found := selectedSet[nodes[x].Address]; found { continue } diff --git a/weed/server/master_grpc_server_volume.go b/weed/server/master_grpc_server_volume.go index 73f2b24cd..55912fda9 100644 --- a/weed/server/master_grpc_server_volume.go +++ b/weed/server/master_grpc_server_volume.go @@ -3,7 +3,7 @@ package weed_server import ( "context" "fmt" - "math/rand" + "math/rand/v2" "reflect" "strings" "sync" diff --git a/weed/server/master_server_handlers_admin.go b/weed/server/master_server_handlers_admin.go index 47bc1918a..452a4194e 100644 --- a/weed/server/master_server_handlers_admin.go +++ b/weed/server/master_server_handlers_admin.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/seaweedfs/seaweedfs/weed/pb" "github.com/seaweedfs/seaweedfs/weed/pb/master_pb" - "math/rand" + "math/rand/v2" "net/http" "strconv" @@ -113,7 +113,7 @@ func (ms *MasterServer) redirectHandler(w http.ResponseWriter, r *http.Request) collection := r.FormValue("collection") location := ms.findVolumeLocation(collection, vid) if location.Error == "" { - loc := location.Locations[rand.Intn(len(location.Locations))] + loc := location.Locations[rand.IntN(len(location.Locations))] url, _ := util_http.NormalizeUrl(loc.PublicUrl) if r.URL.RawQuery != "" { url = url + r.URL.Path + "?" + r.URL.RawQuery diff --git a/weed/server/raft_hashicorp.go b/weed/server/raft_hashicorp.go index 299df323a..c019082f0 100644 --- a/weed/server/raft_hashicorp.go +++ b/weed/server/raft_hashicorp.go @@ -5,7 +5,7 @@ package weed_server import ( "fmt" - "math/rand" + "math/rand/v2" "os" "path" "path/filepath" diff --git a/weed/server/raft_server.go b/weed/server/raft_server.go index 4bcd808c2..dc409aa35 100644 --- a/weed/server/raft_server.go +++ b/weed/server/raft_server.go @@ -3,7 +3,7 @@ package weed_server import ( "encoding/json" "io" - "math/rand" + "math/rand/v2" "os" "path" "time" diff --git a/weed/topology/node.go b/weed/topology/node.go index 851e71385..7e443533f 100644 --- a/weed/topology/node.go +++ b/weed/topology/node.go @@ -2,7 +2,7 @@ package topology import ( "errors" - "math/rand" + "math/rand/v2" "strings" "sync" "sync/atomic" @@ -83,7 +83,7 @@ func (n *NodeImpl) PickNodesByWeight(numberOfNodes int, option *VolumeGrowOption //pick nodes randomly by weights, the node picked earlier has higher final weights sortedCandidates := make([]Node, 0, len(candidates)) for i := 0; i < len(candidates); i++ { - weightsInterval := rand.Int63n(totalWeights) + weightsInterval := rand.Int64N(totalWeights) lastWeights := int64(0) for k, weights := range candidatesWeights { if (weightsInterval >= lastWeights) && (weightsInterval < lastWeights+weights) { diff --git a/weed/topology/topology.go b/weed/topology/topology.go index 6a149bd56..6bfd912cb 100644 --- a/weed/topology/topology.go +++ b/weed/topology/topology.go @@ -4,7 +4,7 @@ import ( "encoding/json" "errors" "fmt" - "math/rand" + "math/rand/v2" "sync" "time" diff --git a/weed/topology/topology_event_handling.go b/weed/topology/topology_event_handling.go index 60459d7b7..ff1c642a6 100644 --- a/weed/topology/topology_event_handling.go +++ b/weed/topology/topology_event_handling.go @@ -1,7 +1,7 @@ package topology import ( - "math/rand" + "math/rand/v2" "time" "github.com/seaweedfs/seaweedfs/weed/stats" diff --git a/weed/topology/volume_growth.go b/weed/topology/volume_growth.go index ff516599d..7f8684753 100644 --- a/weed/topology/volume_growth.go +++ b/weed/topology/volume_growth.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" "github.com/seaweedfs/seaweedfs/weed/pb/master_pb" - "math/rand" + "math/rand/v2" "sync" "time" @@ -222,7 +222,7 @@ func (vg *VolumeGrowth) findEmptySlotsForOneVolume(topo *Topology, option *Volum servers = append(servers, server.(*DataNode)) } for _, rack := range otherRacks { - r := rand.Int63n(rack.AvailableSpaceFor(option)) + r := rand.Int64N(rack.AvailableSpaceFor(option)) if server, e := rack.ReserveOneVolume(r, option); e == nil { servers = append(servers, server) } else { @@ -230,7 +230,7 @@ func (vg *VolumeGrowth) findEmptySlotsForOneVolume(topo *Topology, option *Volum } } for _, datacenter := range otherDataCenters { - r := rand.Int63n(datacenter.AvailableSpaceFor(option)) + r := rand.Int64N(datacenter.AvailableSpaceFor(option)) if server, e := datacenter.ReserveOneVolume(r, option); e == nil { servers = append(servers, server) } else { diff --git a/weed/topology/volume_layout.go b/weed/topology/volume_layout.go index 3fab74843..89378ba97 100644 --- a/weed/topology/volume_layout.go +++ b/weed/topology/volume_layout.go @@ -3,7 +3,7 @@ package topology import ( "fmt" "github.com/seaweedfs/seaweedfs/weed/stats" - "math/rand" + "math/rand/v2" "sync" "sync/atomic" "time" @@ -296,7 +296,7 @@ func (vl *VolumeLayout) PickForWrite(count uint64, option *VolumeGrowOption) (vi return 0, 0, nil, true, fmt.Errorf("%s in volume layout", noWritableVolumes) } if option.DataCenter == "" && option.Rack == "" && option.DataNode == "" { - vid := vl.writables[rand.Intn(lenWriters)] + vid := vl.writables[rand.IntN(lenWriters)] locationList = vl.vid2location[vid] if locationList == nil || len(locationList.list) == 0 { return 0, 0, nil, false, fmt.Errorf("Strangely vid %s is on no machine!", vid.String())