当前位置:网站首页>There are some limitations in cluster expansion and contraction

There are some limitations in cluster expansion and contraction

2022-06-23 08:13:00 User 7737280

such as : A server node is down , The calculation formula starts from hash(key)% 3 Turned into hash(key)% 2, The results will change , At this point, you want to access a key, This key Open selection The approximate cache location rate will change , So before caching key The data will also lose its function and significance .

A large number of caches fail at the same time , Avalanche causing cache , This leads to the unavailability of the whole cache system , This is basically unacceptable , In order to solve and optimize the above situation , Uniformity hash The algorithm came into being ~ that , How does the consistent hash algorithm solve the above problems ?

The server maps to hash Ring At this time, the calculation formula starts from hash(key)% N Turned into **hash( The server ip)% 232**, Use the server IP address hash Calculation , Use the hash result to 232 modulus , The result must be a 0 To 2^32-1 Integer between , And this integer is mapped to hash The position on the ring represents a server , In turn node0node1node2 Open selection Three cache servers are mapped to hash On the ring . How does it optimize the addition and reduction of nodes in the cluster ,http://www.gongxuanwang.com Cache service caused by common modulo algorithm , The problem of large area unavailability ?

Let's take a look at the scenario of capacity expansion , If business volume surges , The system needs to be expanded to add a server node-4, just node-4 Mapped to node-1 and node-2 Between , Object mapping nodes in a clockwise direction , Found originally cached in node-2 On the object key-4key-5 Is remapped to node-4 On , Open selection However, during the whole expansion process, only node-4 and node-1 A small amount of data between nodes . Uniformity Hash The algorithm introduces a Virtual node Mechanism , That is, calculate multiple for each server node hash value , They all map to hash On the ring , Objects mapped to these virtual nodes key, It will eventually be cached on the real node .

Virtual node hash The calculation can usually adopt , Of the corresponding node IP Address plus number suffix hash(10.24.23.227#1) The way , for instance ,node-1 node IP by 10.24.23.227, Normal calculation node-1http://www.gongxuanwang.com Of hash value .

  • hash(10.24.23.227#1)% 2^32 Suppose we give node-1 Set up three virtual nodes ,node-1#1node-1#2node-1#3, Carry them on hash Take the mold after .
原网站

版权声明
本文为[User 7737280]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/01/202201121800095055.html