mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-22 22:43:33 +08:00
math/rand => math/rand/v2
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ func LookupFileId(masterFn GetMasterFn, grpcDialOption grpc.DialOption, fileId s
|
|||||||
if len(lookup.Locations) == 0 {
|
if len(lookup.Locations) == 0 {
|
||||||
return "", jwt, errors.New("File Not Found")
|
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) {
|
func LookupVolumeId(masterFn GetMasterFn, grpcDialOption grpc.DialOption, vid string) (*LookupResult, error) {
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"mime"
|
"mime"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -236,7 +236,7 @@ func genFileUrl(ret *AssignResult, id string, usePublicUrl bool) string {
|
|||||||
fileUrl = "http://" + ret.PublicUrl + "/" + id
|
fileUrl = "http://" + ret.PublicUrl + "/" + id
|
||||||
}
|
}
|
||||||
for _, replica := range ret.Replicas {
|
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
|
fileUrl = "http://" + replica.Url + "/" + id
|
||||||
if usePublicUrl {
|
if usePublicUrl {
|
||||||
fileUrl = "http://" + replica.PublicUrl + "/" + id
|
fileUrl = "http://" + replica.PublicUrl + "/" + id
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@@ -3,11 +3,11 @@ package weed_server
|
|||||||
import (
|
import (
|
||||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/security"
|
"github.com/seaweedfs/seaweedfs/weed/security"
|
||||||
|
util_http "github.com/seaweedfs/seaweedfs/weed/util/http"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/util/mem"
|
"github.com/seaweedfs/seaweedfs/weed/util/mem"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"net/http"
|
"net/http"
|
||||||
util_http "github.com/seaweedfs/seaweedfs/weed/util/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (fs *FilerServer) maybeAddVolumeJwtAuthorization(r *http.Request, fileId string, isWrite bool) {
|
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
|
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 {
|
if err != nil {
|
||||||
glog.Errorf("NewRequest %s: %v", urlStrings[0], err)
|
glog.Errorf("NewRequest %s: %v", urlStrings[0], err)
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/stats"
|
"github.com/seaweedfs/seaweedfs/weed/stats"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ func (locks *AdminLocks) generateToken(lockName string, clientName string) (ts t
|
|||||||
locks.Lock()
|
locks.Lock()
|
||||||
defer locks.Unlock()
|
defer locks.Unlock()
|
||||||
lock := &AdminLock{
|
lock := &AdminLock{
|
||||||
accessSecret: rand.Int63(),
|
accessSecret: rand.Int64(),
|
||||||
accessLockTime: time.Now(),
|
accessLockTime: time.Now(),
|
||||||
lastClient: clientName,
|
lastClient: clientName,
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,7 @@ import (
|
|||||||
"github.com/seaweedfs/seaweedfs/weed/cluster"
|
"github.com/seaweedfs/seaweedfs/weed/cluster"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_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) {
|
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)
|
filers := ms.Cluster.ListClusterNode(filerGroup, cluster.FilerType)
|
||||||
|
|
||||||
if len(filers) > 0 {
|
if len(filers) > 0 {
|
||||||
return filers[rand.Intn(len(filers))].Address
|
return filers[rand.IntN(len(filers))].Address
|
||||||
}
|
}
|
||||||
return "localhost:8888"
|
return "localhost:8888"
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ func limitTo(nodes []*cluster.ClusterNode, limit int32) (selected []*cluster.Clu
|
|||||||
}
|
}
|
||||||
selectedSet := make(map[pb.ServerAddress]*cluster.ClusterNode)
|
selectedSet := make(map[pb.ServerAddress]*cluster.ClusterNode)
|
||||||
for i := 0; i < int(limit)*3; i++ {
|
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 {
|
if _, found := selectedSet[nodes[x].Address]; found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@ package weed_server
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ func (ms *MasterServer) redirectHandler(w http.ResponseWriter, r *http.Request)
|
|||||||
collection := r.FormValue("collection")
|
collection := r.FormValue("collection")
|
||||||
location := ms.findVolumeLocation(collection, vid)
|
location := ms.findVolumeLocation(collection, vid)
|
||||||
if location.Error == "" {
|
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)
|
url, _ := util_http.NormalizeUrl(loc.PublicUrl)
|
||||||
if r.URL.RawQuery != "" {
|
if r.URL.RawQuery != "" {
|
||||||
url = url + r.URL.Path + "?" + r.URL.RawQuery
|
url = url + r.URL.Path + "?" + r.URL.RawQuery
|
||||||
|
@@ -5,7 +5,7 @@ package weed_server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@@ -3,7 +3,7 @@ package weed_server
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"time"
|
"time"
|
||||||
|
@@ -2,7 +2,7 @@ package topology
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"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
|
//pick nodes randomly by weights, the node picked earlier has higher final weights
|
||||||
sortedCandidates := make([]Node, 0, len(candidates))
|
sortedCandidates := make([]Node, 0, len(candidates))
|
||||||
for i := 0; i < len(candidates); i++ {
|
for i := 0; i < len(candidates); i++ {
|
||||||
weightsInterval := rand.Int63n(totalWeights)
|
weightsInterval := rand.Int64N(totalWeights)
|
||||||
lastWeights := int64(0)
|
lastWeights := int64(0)
|
||||||
for k, weights := range candidatesWeights {
|
for k, weights := range candidatesWeights {
|
||||||
if (weightsInterval >= lastWeights) && (weightsInterval < lastWeights+weights) {
|
if (weightsInterval >= lastWeights) && (weightsInterval < lastWeights+weights) {
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package topology
|
package topology
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/stats"
|
"github.com/seaweedfs/seaweedfs/weed/stats"
|
||||||
|
@@ -4,7 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ func (vg *VolumeGrowth) findEmptySlotsForOneVolume(topo *Topology, option *Volum
|
|||||||
servers = append(servers, server.(*DataNode))
|
servers = append(servers, server.(*DataNode))
|
||||||
}
|
}
|
||||||
for _, rack := range otherRacks {
|
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 {
|
if server, e := rack.ReserveOneVolume(r, option); e == nil {
|
||||||
servers = append(servers, server)
|
servers = append(servers, server)
|
||||||
} else {
|
} else {
|
||||||
@@ -230,7 +230,7 @@ func (vg *VolumeGrowth) findEmptySlotsForOneVolume(topo *Topology, option *Volum
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, datacenter := range otherDataCenters {
|
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 {
|
if server, e := datacenter.ReserveOneVolume(r, option); e == nil {
|
||||||
servers = append(servers, server)
|
servers = append(servers, server)
|
||||||
} else {
|
} else {
|
||||||
|
@@ -3,7 +3,7 @@ package topology
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/seaweedfs/seaweedfs/weed/stats"
|
"github.com/seaweedfs/seaweedfs/weed/stats"
|
||||||
"math/rand"
|
"math/rand/v2"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"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)
|
return 0, 0, nil, true, fmt.Errorf("%s in volume layout", noWritableVolumes)
|
||||||
}
|
}
|
||||||
if option.DataCenter == "" && option.Rack == "" && option.DataNode == "" {
|
if option.DataCenter == "" && option.Rack == "" && option.DataNode == "" {
|
||||||
vid := vl.writables[rand.Intn(lenWriters)]
|
vid := vl.writables[rand.IntN(lenWriters)]
|
||||||
locationList = vl.vid2location[vid]
|
locationList = vl.vid2location[vid]
|
||||||
if locationList == nil || len(locationList.list) == 0 {
|
if locationList == nil || len(locationList.list) == 0 {
|
||||||
return 0, 0, nil, false, fmt.Errorf("Strangely vid %s is on no machine!", vid.String())
|
return 0, 0, nil, false, fmt.Errorf("Strangely vid %s is on no machine!", vid.String())
|
||||||
|
Reference in New Issue
Block a user