Skip to content

Commit

Permalink
Merge branch 'feature/membership-package' into feature/extensible-has…
Browse files Browse the repository at this point in the history
…hring
  • Loading branch information
Menno Pruijssers committed Dec 15, 2016
2 parents 4310b0d + fb81d89 commit 60515d0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
12 changes: 6 additions & 6 deletions hashring/rbtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,28 +261,28 @@ func (n *redBlackNode) search(key keytype) (valuetype, bool) {
return nil, false
}

// walk Walks the tree in sorted order invoking `walker` for each node. If the
// walker function returns `false`, walking is stopped and no more nodes will be
// traverseUntil traverses the nodes in the tree in-order invoking `traverse` for each node. If the
// traverse function returns `false`, traversal is stopped and no more nodes will be
// visited. Returns `true` if all nodes are visited; `false` if not.
func (n *redBlackNode) walk(walker func(*redBlackNode) bool) bool {
func (n *redBlackNode) traverseUntil(traverse func(*redBlackNode) bool) bool {
if n == nil {
// the end of the tree does not signal the end of walking, but we can't
// walk this node (nil) nor left or right anymore
return true
}

// walk left first
if !n.left.walk(walker) {
if !n.left.traverseUntil(traverse) {
// stop if walker indicated to break
return false
}
// now visit this node
if !walker(n) {
if !traverse(n) {
// stop if walker indicated to break
return false
}
// lastly visit right
if !n.right.walk(walker) {
if !n.right.traverseUntil(traverse) {
// stop if walker indicated to break
return false
}
Expand Down
8 changes: 4 additions & 4 deletions hashring/rbtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ func TestBig(t *testing.T) {
assert.NoError(t, err, "expected tree to be a valid red black tree")
}

func TestWalkInOrder(t *testing.T) {
func TestTraverseOrder(t *testing.T) {
tree := makeTree()

// 4,B
Expand All @@ -650,7 +650,7 @@ func TestWalkInOrder(t *testing.T) {

var last keytype

tree.root.walk(func(n *redBlackNode) bool {
tree.root.traverseUntil(func(n *redBlackNode) bool {
current := n.key
if last != nil {
assert.True(t, current.Compare(last) > 0, "expected walk to walk the nodes in natural order as dictated by the Compare function")
Expand All @@ -660,7 +660,7 @@ func TestWalkInOrder(t *testing.T) {
})
}

func TestWalkEscape(t *testing.T) {
func TestTraverseEscape(t *testing.T) {
tree := makeTree()

// 4,B
Expand All @@ -673,7 +673,7 @@ func TestWalkEscape(t *testing.T) {

var visited []int

tree.root.walk(func(n *redBlackNode) bool {
tree.root.traverseUntil(func(n *redBlackNode) bool {
number := int(n.key.(treeTestInt))
visited = append(visited, number)
// stop at node 5, it should exit on a left, right and visiting node,
Expand Down
22 changes: 11 additions & 11 deletions swim/memberlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,26 +415,26 @@ func (m *memberlist) RemoveLocalLabels(keys ...string) bool {
// made changes, only if changes are made the incarnation number will be bumped
// and the new state will be gossiped to the peers
func (m *memberlist) updateLocalMember(update func(*Member) bool) {
var changes []Change

m.members.Lock()

before := *m.local
didUpdate := update(m.local)
if didUpdate {
// bump incarnation number if the member has been updated
change := m.bumpIncarnation()
changes = append(changes, change)
}
after := *m.local

m.members.Unlock()

// exit if the update didn't change anything
if !didUpdate {
// exit if the update didn't change anything
m.members.Unlock()
return
}

// bump incarnation number if the member has been updated
change := m.bumpIncarnation()

changes := []Change{change}

after := *m.local

m.members.Unlock()

// since we changed our local state we need to update our checksum
m.ComputeChecksum()

Expand Down

0 comments on commit 60515d0

Please sign in to comment.