Skip to content

Commit

Permalink
Set a better default for maxP and fix maxP value after bootstrap.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sever Banesiu committed Feb 8, 2016
1 parent f4e384b commit 02870da
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
11 changes: 5 additions & 6 deletions swim/disseminator.go
Original file line number Diff line number Diff line change
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
16 changes: 16 additions & 0 deletions swim/node_bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,22 @@ 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.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)
}

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

0 comments on commit 02870da

Please sign in to comment.