mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-08-19 13:46:58 +00:00
math/rand/v2
This commit is contained in:
@@ -91,7 +91,7 @@ func waitForS3Service(t *testing.T, client *s3.Client, timeout time.Duration) {
|
||||
func getNewBucketName() string {
|
||||
timestamp := time.Now().UnixNano()
|
||||
// Add random suffix to prevent collisions when tests run quickly
|
||||
randomSuffix := mathrand.Intn(100000)
|
||||
randomSuffix := mathrand.IntN(100000)
|
||||
return fmt.Sprintf("%s%d-%d", defaultConfig.BucketPrefix, timestamp, randomSuffix)
|
||||
}
|
||||
|
||||
|
||||
@@ -656,7 +656,7 @@ func (f *S3IAMTestFramework) GenerateUniqueBucketName(prefix string) string {
|
||||
testName = strings.ReplaceAll(testName, "_", "-")
|
||||
|
||||
// Add random suffix to handle parallel tests
|
||||
randomSuffix := mathrand.Intn(10000)
|
||||
randomSuffix := mathrand.IntN(10000)
|
||||
|
||||
return fmt.Sprintf("%s-%s-%d", prefix, testName, randomSuffix)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func main() {
|
||||
f, err := os.Create(fmt.Sprintf("%s/file%05d", *toDir, i))
|
||||
check(err)
|
||||
|
||||
fileSize := *minSize + rand.Intn(*maxSize-*minSize)
|
||||
fileSize := *minSize + rand.IntN(*maxSize-*minSize)
|
||||
startTime := time.Now()
|
||||
|
||||
fmt.Printf("write %s %d bytes: ", f.Name(), fileSize)
|
||||
|
||||
@@ -71,7 +71,7 @@ func TestRandomFileChunksCompact(t *testing.T) {
|
||||
|
||||
var chunks []*filer_pb.FileChunk
|
||||
for i := 0; i < 15; i++ {
|
||||
start, stop := rand.Intn(len(data)), rand.Intn(len(data))
|
||||
start, stop := rand.IntN(len(data)), rand.IntN(len(data))
|
||||
if start > stop {
|
||||
start, stop = stop, start
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package mount
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -110,7 +110,7 @@ func NewSeaweedFileSystem(option *Option) *WFS {
|
||||
fhLockTable: util.NewLockTable[FileHandleId](),
|
||||
}
|
||||
|
||||
wfs.option.filerIndex = int32(rand.Intn(len(option.FilerAddresses)))
|
||||
wfs.option.filerIndex = int32(rand.IntN(len(option.FilerAddresses)))
|
||||
wfs.option.setupUniqueCacheDirectory()
|
||||
if option.CacheSizeMBForRead > 0 {
|
||||
wfs.chunkCache = chunk_cache.NewTieredChunkCache(256, option.getUniqueCacheDirForRead(), option.CacheSizeMBForRead, 1024*1024)
|
||||
|
||||
@@ -3,12 +3,13 @@ package broker
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand/v2"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
|
||||
"io"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
// BrokerConnectToBalancer connects to the broker balancer and sends stats
|
||||
@@ -61,7 +62,7 @@ func (b *MessageQueueBroker) BrokerConnectToBalancer(brokerBalancer string, stop
|
||||
}
|
||||
// glog.V(3).Infof("sent stats: %+v", stats)
|
||||
|
||||
time.Sleep(time.Millisecond*5000 + time.Duration(rand.Intn(1000))*time.Millisecond)
|
||||
time.Sleep(time.Millisecond*5000 + time.Duration(rand.IntN(1000))*time.Millisecond)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"net"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@@ -71,7 +71,7 @@ func (b *MessageQueueBroker) PublishMessage(stream mq_pb.SeaweedMessaging_Publis
|
||||
var isClosed bool
|
||||
|
||||
// process each published messages
|
||||
clientName := fmt.Sprintf("%v-%4d", findClientAddress(stream.Context()), rand.Intn(10000))
|
||||
clientName := fmt.Sprintf("%v-%4d", findClientAddress(stream.Context()), rand.IntN(10000))
|
||||
publisher := topic.NewLocalPublisher()
|
||||
localTopicPartition.Publishers.AddPublisher(clientName, publisher)
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package pub_balancer
|
||||
|
||||
import (
|
||||
"math/rand/v2"
|
||||
"time"
|
||||
|
||||
cmap "github.com/orcaman/concurrent-map/v2"
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/mq_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/schema_pb"
|
||||
"math/rand"
|
||||
"time"
|
||||
)
|
||||
|
||||
func AllocateTopicPartitions(brokers cmap.ConcurrentMap[string, *BrokerStats], partitionCount int32) (assignments []*mq_pb.BrokerPartitionAssignment) {
|
||||
@@ -43,7 +44,7 @@ func pickBrokers(brokers cmap.ConcurrentMap[string, *BrokerStats], count int32)
|
||||
}
|
||||
pickedBrokers := make([]string, 0, count)
|
||||
for i := int32(0); i < count; i++ {
|
||||
p := rand.Intn(len(candidates))
|
||||
p := rand.IntN(len(candidates))
|
||||
pickedBrokers = append(pickedBrokers, candidates[p])
|
||||
}
|
||||
return pickedBrokers
|
||||
@@ -59,7 +60,7 @@ func pickBrokersExcluded(brokers []string, count int, excludedLeadBroker string,
|
||||
if len(pickedBrokers) < count {
|
||||
pickedBrokers = append(pickedBrokers, broker)
|
||||
} else {
|
||||
j := rand.Intn(i + 1)
|
||||
j := rand.IntN(i + 1)
|
||||
if j < count {
|
||||
pickedBrokers[j] = broker
|
||||
}
|
||||
@@ -69,7 +70,7 @@ func pickBrokersExcluded(brokers []string, count int, excludedLeadBroker string,
|
||||
// shuffle the picked brokers
|
||||
count = len(pickedBrokers)
|
||||
for i := 0; i < count; i++ {
|
||||
j := rand.Intn(count)
|
||||
j := rand.IntN(count)
|
||||
pickedBrokers[i], pickedBrokers[j] = pickedBrokers[j], pickedBrokers[i]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package pub_balancer
|
||||
|
||||
import (
|
||||
"math/rand/v2"
|
||||
|
||||
cmap "github.com/orcaman/concurrent-map/v2"
|
||||
"github.com/seaweedfs/seaweedfs/weed/mq/topic"
|
||||
"math/rand"
|
||||
)
|
||||
|
||||
func BalanceTopicPartitionOnBrokers(brokers cmap.ConcurrentMap[string, *BrokerStats]) BalanceAction {
|
||||
@@ -28,7 +29,7 @@ func BalanceTopicPartitionOnBrokers(brokers cmap.ConcurrentMap[string, *BrokerSt
|
||||
maxPartitionCountPerBroker = brokerStats.Val.TopicPartitionCount
|
||||
sourceBroker = brokerStats.Key
|
||||
// select a random partition from the source broker
|
||||
randomePartitionIndex := rand.Intn(int(brokerStats.Val.TopicPartitionCount))
|
||||
randomePartitionIndex := rand.IntN(int(brokerStats.Val.TopicPartitionCount))
|
||||
index := 0
|
||||
for topicPartitionStats := range brokerStats.Val.TopicPartitionStats.IterBuffered() {
|
||||
if index == randomePartitionIndex {
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package pub_balancer
|
||||
|
||||
import (
|
||||
"math/rand/v2"
|
||||
"sort"
|
||||
|
||||
cmap "github.com/orcaman/concurrent-map/v2"
|
||||
"github.com/seaweedfs/seaweedfs/weed/mq/topic"
|
||||
"math/rand"
|
||||
"modernc.org/mathutil"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func (balancer *PubBalancer) RepairTopics() []BalanceAction {
|
||||
@@ -56,7 +57,7 @@ func RepairMissingTopicPartitions(brokers cmap.ConcurrentMap[string, *BrokerStat
|
||||
Topic: t,
|
||||
Partition: partition,
|
||||
},
|
||||
TargetBroker: candidates[rand.Intn(len(candidates))],
|
||||
TargetBroker: candidates[rand.IntN(len(candidates))],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package auth
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/sftpd/user"
|
||||
@@ -47,7 +47,7 @@ func (a *PasswordAuthenticator) Authenticate(conn ssh.ConnMetadata, password []b
|
||||
}
|
||||
|
||||
// Add delay to prevent brute force attacks
|
||||
time.Sleep(time.Duration(100+rand.Intn(100)) * time.Millisecond)
|
||||
time.Sleep(time.Duration(100+rand.IntN(100)) * time.Millisecond)
|
||||
|
||||
return nil, fmt.Errorf("authentication failed")
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
@@ -22,7 +22,7 @@ func NewUser(username string) *User {
|
||||
// Generate a random UID/GID between 1000 and 60000
|
||||
// This range is typically safe for regular users in most systems
|
||||
// 0-999 are often reserved for system users
|
||||
randomId := 1000 + rand.Intn(59000)
|
||||
randomId := 1000 + rand.IntN(59000)
|
||||
|
||||
return &User{
|
||||
Username: username,
|
||||
|
||||
@@ -3,19 +3,20 @@ package shell
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/seaweedfs/seaweedfs/weed/cluster"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util/grace"
|
||||
"io"
|
||||
"math/rand"
|
||||
"math/rand/v2"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/seaweedfs/seaweedfs/weed/cluster"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/master_pb"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util"
|
||||
"github.com/seaweedfs/seaweedfs/weed/util/grace"
|
||||
|
||||
"github.com/peterh/liner"
|
||||
)
|
||||
|
||||
@@ -69,7 +70,7 @@ func RunShell(options ShellOptions) {
|
||||
fmt.Printf("master: %s ", *options.Masters)
|
||||
if len(filers) > 0 {
|
||||
fmt.Printf("filers: %v", filers)
|
||||
commandEnv.option.FilerAddress = filers[rand.Intn(len(filers))]
|
||||
commandEnv.option.FilerAddress = filers[rand.IntN(len(filers))]
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ func doSomeWritesDeletes(i int, v *Volume, t *testing.T, infos []*needleInfo) {
|
||||
}
|
||||
// println("written file", i, "checksum", n.Checksum.Value(), "size", size)
|
||||
if rand.Float64() < 0.03 {
|
||||
toBeDeleted := rand.Intn(i) + 1
|
||||
toBeDeleted := rand.IntN(i) + 1
|
||||
oldNeedle := newEmptyNeedle(uint64(toBeDeleted))
|
||||
v.deleteNeedle2(oldNeedle)
|
||||
// println("deleted file", toBeDeleted)
|
||||
@@ -175,7 +175,7 @@ type needleInfo struct {
|
||||
|
||||
func newRandomNeedle(id uint64) *needle.Needle {
|
||||
n := new(needle.Needle)
|
||||
n.Data = make([]byte, rand.Intn(1024))
|
||||
n.Data = make([]byte, rand.IntN(1024))
|
||||
rand.Read(n.Data)
|
||||
|
||||
n.Checksum = needle.NewCRC(n.Data)
|
||||
|
||||
@@ -235,11 +235,11 @@ func TestFindGreaterOrEqual(t *testing.T) {
|
||||
list = New(memStore)
|
||||
|
||||
for i := 0; i < maxN; i++ {
|
||||
list.InsertByKey(Element(rand.Intn(maxNumber)), 0, Element(i))
|
||||
list.InsertByKey(Element(rand.IntN(maxNumber)), 0, Element(i))
|
||||
}
|
||||
|
||||
for i := 0; i < maxN; i++ {
|
||||
key := Element(rand.Intn(maxNumber))
|
||||
key := Element(rand.IntN(maxNumber))
|
||||
if _, v, ok, _ := list.FindGreaterOrEqual(key); ok {
|
||||
// if f is v should be bigger than the element before
|
||||
if v.Prev != nil && bytes.Compare(key, v.Prev.Key) < 0 {
|
||||
|
||||
Reference in New Issue
Block a user