0b02a48a10
Current node selection logic (in case of using SelectBySubnet): 1. selects one subnet randomly 2. selects one node randomly from the subnet 3. applies the placement NodeFilters to the node and ignore it, if doesn't match This logic is wrong: 1. Imagine that we have a subnet with two DE and one GB nodes. 2. We would like to select DE nodes 2. In case of GB node is selected (randomly) in step2, step3 will ignore the subnet, even if there are good (DE) nodes in there. Change-Id: I7673f52c89b46e0cc7b20a9b74137dc689d6c17e
67 lines
1.1 KiB
Go
67 lines
1.1 KiB
Go
// Copyright (C) 2023 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"math"
|
|
mathrand "math/rand"
|
|
"os"
|
|
)
|
|
|
|
// main implements a simple (and slow) prime number generator.
|
|
func main() {
|
|
dest := bytes.Buffer{}
|
|
|
|
_, err := dest.WriteString(`// Copyright (C) 2023 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package nodeselection
|
|
|
|
//go:generate go run ./gen
|
|
var primes = []uint64{
|
|
`)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
min := uint64(1 << 32)
|
|
requiredPrimes := 32
|
|
for {
|
|
n := mathrand.Uint64()
|
|
if n < min {
|
|
continue
|
|
}
|
|
prime := true
|
|
squareRoot := uint64(math.Floor(math.Sqrt(float64(n))))
|
|
for i := uint64(2); i < squareRoot; i++ {
|
|
if n%i == 0 {
|
|
prime = false
|
|
break
|
|
}
|
|
|
|
}
|
|
if prime {
|
|
fmt.Println("found a prime", n)
|
|
requiredPrimes--
|
|
_, err = dest.WriteString(fmt.Sprintf(" %d,\n", n))
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|
|
if requiredPrimes == 0 {
|
|
break
|
|
}
|
|
}
|
|
_, err = dest.WriteString("}")
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
err = os.WriteFile("primes.go", dest.Bytes(), 0644)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
}
|