Skip to content
New issue

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

what is the meaning of reallocate for hashes #14

Open
andyxning opened this issue Dec 8, 2015 · 1 comment
Open

what is the meaning of reallocate for hashes #14

andyxning opened this issue Dec 8, 2015 · 1 comment

Comments

@andyxning
Copy link

i can not find the meaning of reallocating and what is the judgement about.
Can someone explain it?

    //reallocate if we're holding on to too much (1/4th)
    if cap(c.sortedHashes)/(c.NumberOfReplicas*4) > len(c.circle) {
        hashes = nil
    }
@superfrink
Copy link

updateSortedHashes() uses append() so c.sortedHashes will grow over time as members are added and removed. When the slice is using too much memory this code creates a new slice and the memory for the old slice is freed.

I didn't write it so if I understand correctly too-much is defined as when the allocated memory is 4 times the amount being used. But it is also adjusted based on the expected number of members (c.NumberOfReplicas). The adjustment would prevent extra reallocations if say most replicas went offline for a breif period of time and then came back again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants