We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
If there are no members in the hashring, calling the AverageLoad() function results in a "divide-by-zero" panic.
AverageLoad()
Example, this will result in a panic:
panic
package main import ( "fmt" "github.com/buraksezer/consistent" "github.com/cespare/xxhash" ) type myMember string func (m myMember) String() string { return string(m) } type hasher struct{} func (h hasher) Sum64(data []byte) uint64 { return xxhash.Sum64(data) } func main() { cfg := consistent.Config{ PartitionCount: 7, ReplicationFactor: 20, Load: 1.25, Hasher: hasher{}, } c := consistent.New(nil, cfg) fmt.Printf("average load: %f", c.AverageLoad()) }
The AverageLoad() function should check if the number of members is > 0, and if it is not simply return a fixed value (such as 0 or -1).
The text was updated successfully, but these errors were encountered:
+1
// AverageLoad exposes the current average load. func (c *Consistent) AverageLoad() float64 { avgLoad := float64(c.partitionCount/uint64(len(c.members))) * c.config.Load return math.Ceil(avgLoad) }
len(c.members) may be equal to zero
Sorry, something went wrong.
fix: AverageLoad() function panics with "divide by zero" when no memb…
dc3cf9d
…ers are in the hash ring #19
buraksezer
Successfully merging a pull request may close this issue.
If there are no members in the hashring, calling the
AverageLoad()
function results in a "divide-by-zero" panic.Example, this will result in a
panic
:The
AverageLoad()
function should check if the number of members is > 0, and if it is not simply return a fixed value (such as 0 or -1).The text was updated successfully, but these errors were encountered: