Skip to content

Commit

Permalink
Merge branch 'fix/maxP'
Browse files Browse the repository at this point in the history
Closes #97
  • Loading branch information
Sever Banesiu committed Feb 10, 2016
2 parents 562a831 + 2f8e4bc commit 0859b4a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
11 changes: 5 additions & 6 deletions swim/disseminator.go
Expand Up @@ -30,6 +30,9 @@ import (

var log10 = math.Log(10)

// defaultPFactor is the piggyback factor value, described in the swim paper.
const defaultPFactor int = 15

// A pChange is a change with a p count representing the number of times the
// change has been propagated to other nodes.
type pChange struct {
Expand Down Expand Up @@ -57,19 +60,15 @@ func newDisseminator(n *Node) *disseminator {
d := &disseminator{
node: n,
changes: make(map[string]*pChange),
maxP: 1,
pFactor: 15,
maxP: defaultPFactor,
pFactor: defaultPFactor,
logger: logging.Logger("disseminator").WithField("local", n.Address()),
}

return d
}

func (d *disseminator) AdjustMaxPropagations() {
if !d.node.Ready() {
return
}

d.Lock()

numPingable := d.node.memberlist.NumPingableMembers()
Expand Down
17 changes: 17 additions & 0 deletions swim/node_bootstrap_test.go
Expand Up @@ -195,6 +195,23 @@ func (s *BootstrapTestSuite) TestMalformedJSONFile() {
s.Error(err, "invalid character 'T' looking for beginning of value", "should fail to unmarhsal JSON")
}

func (s *BootstrapTestSuite) TestDisseminationCounterAfterBootstrap() {
s.peers = genChannelNodes(s.T(), 10)
bootstrapList := bootstrapNodes(s.T(), s.peers...)
waitForConvergence(s.T(), 5*time.Second, s.peers...)

s.Equal(s.node.disseminator.pFactor, s.node.disseminator.maxP, "Initial maxP value should equal pFactor")
s.node.Bootstrap(&BootstrapOptions{
Hosts: bootstrapList,
Stopped: true,
})
waitForConvergence(s.T(), 5*time.Second, append(s.peers, s.tnode)...)

// there are 11 nodes in total, log10(11) rounded up is 2
expected := 2 * s.node.disseminator.pFactor
s.Equal(expected, s.node.disseminator.maxP, "maxP should be a multiple of pFactor")
}

func TestBootstrapTestSuite(t *testing.T) {
suite.Run(t, new(BootstrapTestSuite))
}

0 comments on commit 0859b4a

Please sign in to comment.