GetNeighbor returns an node close to where name hashes to in the circle.
(name string)
| 229 | |
| 230 | // GetNeighbor returns an node close to where name hashes to in the circle. |
| 231 | func (c *Consistent) GetNeighbor(name string) (proto.Node, error) { |
| 232 | c.RLock() |
| 233 | defer c.RUnlock() |
| 234 | c.cacheLock.RLock() |
| 235 | defer c.cacheLock.RUnlock() |
| 236 | |
| 237 | if len(c.circle) == 0 { |
| 238 | return proto.Node{}, ErrEmptyCircle |
| 239 | } |
| 240 | key := hashKey(name) |
| 241 | i := c.search(key) |
| 242 | return *c.circle[c.sortedHashes[i]], nil |
| 243 | } |
| 244 | |
| 245 | // GetNode returns an node by its node id. |
| 246 | func (c *Consistent) GetNode(name string) (*proto.Node, error) { |