# 分布式哈希算法

②当不断地向HashMap中添加元素时，HashMap越来越满，当添加的元素达到了装载因子乘以表长时，就需要扩容了。扩容时，原来已经映射到哈希表中的某个位置(桶)的元素需要重新再哈希，然后再把原来的数据复制到新的哈希表中。

key=6时，hash(6)%5 = 1，即Key为6的元素存储在第一个桶中

key=7时，hash(7)%5 = 2，即Key为7的元素存储在第二个桶中

Key=13时，hash(13)%5=3，即Key为13的元素存储在第三个桶中....

key=6时，hash(6)%8 = 6，即Key为6的元素存储在第六个桶中

key=7时，hash(7)%8 = 7，即Key为7的元素存储在第七个桶中

Key=13时，hash(13)%8=5，即key为13的元素存储在第五个桶中....

Each node choose a n-bit ID
Intention is that they be random Though probably a hash of some fixed info IDs are arranged in a ring

Each lookup key is also a n-bit ID
I.e., the hash of the real lookup key
Node IDs and keys occupy the same space!

①如果虚拟机器与物理机器映射得好，某一台物理机器宕机后，其上的数据可由其他若干台物理机器共同分担。

②如果新添加一台机器，它可以对应多个不相邻 环段 上的虚拟节点，从而使得hash的数据存储得更分散。

A node’s finger table contains the IP address of a node halfway around the ID space from it, a quarter-of-the-way , and so forth in powers of two.A node forwards a query for key k to the node in its finger table with the highest ID less than k. The power-of-two structure of the finger table ensures that the node can always forward the query at least half of the remaining ID-space distance to k. As a result Chord lookups use O(log N ) messages.

i        id+2i                    succ

0       1+2^0=2             2

1       1+2^1=3             6

2       1+2^2=5             6

Dynamo can be characterized as a zero-hop DHT,where each node maintains
enough routing information locally to route a request to the appropriate
node directly

https://en.wikipedia.org/wiki/Distributed_hash_table

Distributed Hash Table.pdf  15­441 Spring 2004, Jeff Pang

posted @ 2016-08-11 19:58  hapjin  阅读(...)  评论(...编辑  收藏