@@ -277,7 +277,7 @@ func (c *Consistent) GetTwoNeighbors(name string) (proto.Node, proto.Node, error
277277}
278278
279279// GetNeighborsEx returns the N closest distinct nodes to the name input in the circle.
280- func (c * Consistent ) GetNeighborsEx (name string , n int , roles [] proto.ServerRole ) ([]proto.Node , error ) {
280+ func (c * Consistent ) GetNeighborsEx (name string , n int , roles proto.ServerRoles ) ([]proto.Node , error ) {
281281 c .RLock ()
282282 defer c .RUnlock ()
283283
@@ -296,10 +296,13 @@ func (c *Consistent) GetNeighborsEx(name string, n int, roles []proto.ServerRole
296296 res = make ([]proto.Node , 0 , n )
297297 elem = * c.circle [c.sortedHashes [i ]]
298298 )
299+ var noFilter = roles == nil || len (roles ) == 0
299300
300- res = append (res , elem )
301+ if noFilter || roles .Contains (elem .Role ) {
302+ res = append (res , elem )
303+ }
301304
302- if len (res ) == n {
305+ if noFilter && len (res ) == n {
303306 return res , nil
304307 }
305308
@@ -308,8 +311,10 @@ func (c *Consistent) GetNeighborsEx(name string, n int, roles []proto.ServerRole
308311 i = 0
309312 }
310313 elem = * c.circle [c.sortedHashes [i ]]
311- if ! sliceContainsMember (res , elem ) {
312- res = append (res , elem )
314+ if noFilter || roles .Contains (elem .Role ) {
315+ if ! sliceContainsMember (res , elem ) {
316+ res = append (res , elem )
317+ }
313318 }
314319 if len (res ) == n {
315320 break
0 commit comments