stathat/consistent

what is the meaning of reallocate for hashes

andyxning opened this issue · 1 comments

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
    }

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.