Set sets all the nodes in the hash. If there are existing nodes not present in nodes, they will be removed.
(nodes []proto.Node)
| 165 | // Set sets all the nodes in the hash. If there are existing nodes not |
| 166 | // present in nodes, they will be removed. |
| 167 | func (c *Consistent) Set(nodes []proto.Node) (err error) { |
| 168 | c.Lock() |
| 169 | defer c.Unlock() |
| 170 | |
| 171 | err = c.persist.Reset() |
| 172 | if err != nil { |
| 173 | log.WithError(err).Error("reset bucket failed") |
| 174 | return |
| 175 | } |
| 176 | |
| 177 | c.ResetCache() |
| 178 | |
| 179 | for _, v := range nodes { |
| 180 | c.add(v) |
| 181 | } |
| 182 | |
| 183 | return |
| 184 | } |
| 185 | |
| 186 | // need c.Lock() before calling. |
| 187 | func (c *Consistent) add(node proto.Node) (err error) { |