示例#1
0
func (s *MemberlistTestSuite) SetupTest() {
	s.incarnation = util.TimeNowMS()
	s.node = NewNode("test", "127.0.0.1:3001", nil, nil)
	s.m = s.node.memberlist
	s.m.MakeAlive(s.node.Address(), s.incarnation)

	s.changes = []Change{
		Change{
			Address:     "127.0.0.1:3002",
			Status:      Alive,
			Incarnation: s.incarnation,
		},
		Change{
			Address:     "127.0.0.1:3003",
			Status:      Suspect,
			Incarnation: s.incarnation,
		},
		Change{
			Address:     "127.0.0.1:3004",
			Status:      Faulty,
			Incarnation: s.incarnation,
		},
		Change{
			Address:     "127.0.0.1:3005",
			Status:      Leave,
			Incarnation: s.incarnation,
		},
	}
}
示例#2
0
func (s *DisseminatorTestSuite) SetupTest() {
	s.incarnation = util.TimeNowMS()
	s.node = NewNode("test", "127.0.0.1:3001", nil, nil)
	s.node.memberlist.MakeAlive(s.node.Address(), s.incarnation)
	s.d = s.node.disseminator
	s.m = s.node.memberlist
}
示例#3
0
// updates the member list with the slice of changes, applying selectively
func (m *memberlist) Update(changes []Change) (applied []Change) {
	if m.node.Stopped() || len(changes) == 0 {
		return nil
	}

	m.node.emit(MemberlistChangesReceivedEvent{changes})

	m.members.Lock()

	for _, change := range changes {
		member, ok := m.members.byAddress[change.Address]

		// first time member has been seen, take change wholesale
		if !ok {
			m.Apply(change)
			applied = append(applied, change)
			continue
		}

		// if change is local override, reassert member is alive
		if member.localOverride(m.node.Address(), change) {
			overrideChange := Change{
				Source:            change.Source,
				SourceIncarnation: change.SourceIncarnation,
				Address:           change.Address,
				Incarnation:       util.TimeNowMS(),
				Status:            Alive,
				Timestamp:         util.Timestamp(time.Now()),
			}

			m.Apply(overrideChange)
			applied = append(applied, overrideChange)
			continue
		}

		// if non-local override, apply change wholesale
		if member.nonLocalOverride(change) {
			m.Apply(change)
			applied = append(applied, change)
		}
	}

	m.members.Unlock()

	if len(applied) > 0 {
		oldChecksum := m.Checksum()
		m.ComputeChecksum()
		m.node.emit(MemberlistChangesAppliedEvent{
			Changes:     applied,
			OldChecksum: oldChecksum,
			NewChecksum: m.Checksum(),
			NumMembers:  m.NumMembers(),
		})
		m.node.handleChanges(applied)
		m.node.rollup.TrackUpdates(applied)
	}

	return applied
}
func (s *MemberlistIterTestSuite) SetupTest() {
	s.incarnation = util.TimeNowMS()
	s.node = NewNode("test", "127.0.0.1:3001", nil, nil)
	s.m = s.node.memberlist
	s.i = s.m.Iter()

	s.m.MakeAlive(s.node.Address(), s.incarnation)
}
示例#5
0
func (s *RollupTestSuite) SetupTest() {
	s.node = NewNode("test", "127.0.0.1:3001", nil, &Options{
		RollupFlushInterval: 10000 * time.Second,
		RollupMaxUpdates:    10000,
	})
	s.r = s.node.rollup
	s.incarnation = util.TimeNowMS()
	s.updates = []Change{
		Change{Address: "one"},
		Change{Address: "two"},
	}
}
示例#6
0
func (s *SuspicionTestSuite) SetupTest() {
	s.incarnation = util.TimeNowMS()
	s.node = NewNode("test", "127.0.0.1:3001", nil, &Options{
		SuspicionTimeout: 1000 * time.Second,
	})
	s.s = s.node.suspicion
	s.m = s.node.memberlist

	s.m.MakeAlive(s.node.Address(), s.incarnation)

	s.suspect = Change{
		Address:     "127.0.0.1:3002",
		Incarnation: s.incarnation,
	}
}
示例#7
0
// makes a change to the member list
func (m *memberlist) MakeChange(address string, incarnation int64, status string) []Change {
	if m.local == nil {
		m.local = &Member{
			Address:     m.node.Address(),
			Incarnation: util.TimeNowMS(),
			Status:      Alive,
		}
	}

	return m.Update([]Change{Change{
		Source:            m.local.Address,
		SourceIncarnation: m.local.Incarnation,
		Address:           address,
		Incarnation:       incarnation,
		Status:            status,
		Timestamp:         util.Timestamp(time.Now()),
	}})
}
示例#8
0
import (
	"fmt"
	"log"
	"sync"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
	"github.com/uber/ringpop-go/swim/util"
	"github.com/uber/tchannel-go"
)

var testNow = time.Now()
var testInc = util.TimeNowMS()

var testSuspect = Change{
	Address:           "127.0.0.1:3002",
	Incarnation:       testInc,
	Source:            "127.0.0.1:3001",
	SourceIncarnation: testInc,
	Status:            Suspect,
	Timestamp:         util.Timestamp(testNow),
}

type dummyIter struct{}

func (dummyIter) Next() (*Member, bool) {
	return &Member{
		Address:     "127.0.0.1:3010",
示例#9
0
func (n *Node) adminJoinHandler(ctx json.Context, req *Arg) (*Status, error) {
	n.memberlist.MakeAlive(n.address, util.TimeNowMS())
	return &Status{Status: "rejoined"}, nil
}
示例#10
0
func (s *PingRequestTestSuite) SetupTest() {
	s.incarnation = util.TimeNowMS()
	s.tnode = newChannelNode(s.T(), "127.0.0.1:3001")
	s.node = s.tnode.node
	s.peers = genChannelNodes(s.T(), genAddresses(1, 2, 3))
}
示例#11
0
// Bootstrap joins a node to a cluster. The channel provided to the node must be
// listening for the bootstrap to complete.
func (n *Node) Bootstrap(opts *BootstrapOptions) ([]string, error) {
	if n.channel == nil {
		return nil, errors.New("channel required")
	}

	if opts == nil {
		opts = &BootstrapOptions{}
	}

	if err := n.seedBootstrapHosts(opts); err != nil {
		return nil, err
	}

	if len(n.bootstrapHosts) == 0 {
		return nil, errors.New("bootstrap hosts required, but none found")
	}

	err := util.CheckLocalMissing(n.address, n.bootstrapHosts[util.CaptureHost(n.address)])
	if err != nil {
		n.log.Warn(err.Error())
	}

	mismatched, err := util.CheckHostnameIPMismatch(n.address, n.bootstrapHosts)
	if err != nil {
		n.log.WithField("mismatched", mismatched).Warn(err.Error())
	}

	n.memberlist.MakeAlive(n.address, util.TimeNowMS())

	joinOpts := &joinOpts{
		timeout:           opts.JoinTimeout,
		size:              opts.JoinSize,
		maxJoinDuration:   opts.MaxJoinDuration,
		parallelismFactor: opts.ParallelismFactor,
	}

	joined, err := sendJoin(n, joinOpts)
	if err != nil {
		n.log.WithFields(log.Fields{
			"err": err.Error(),
		}).Error("bootstrap failed")
		return nil, err
	}

	if n.Destroyed() {
		n.log.Error("destroyed during bootstrap process")
		return nil, errors.New("destroyed during bootstrap process")
	}

	if !opts.Stopped {
		n.gossip.Start()
	}

	n.state.Lock()
	n.state.ready = true
	n.state.Unlock()

	n.startTime = time.Now()

	return joined, nil
}