Giter Club home page Giter Club logo

multibully's Introduction

MultiBully

MultiBully is a Go library for distributed leadership election on a UDP multicast enabled network, like a LAN. It uses the Bully algorithm, a relatively simply mechanism which may not be suitable for a large numbers of nodes.

I think there are some bugs and inefficiencies in my implementation of it. It always manages to converge on the correct leader, but it sometimes takes a few goes round. Please feel free to help!

Usage

The Bully algorithm elects the node with the largest pid to be leader. The pid doesn't necessarily need to be the process ID in the operating system โ€“ you could choose for this to be a timestamp or a fixed integer for each node. In this implementation, the combination of pid and IP address must be unique, so you can run multiple instances on a single host.

While MultiBully uses multicast UDP for communication between nodes, it transmits the non-multicast IP of each node in the communication packet, so you can point the follower at the new leader.

Example

package main

import (
	"github.com/tomtaylor/multibully"
	"log"
	"os"
	"net"
)

func main() {
	address := "224.0.0.0:9999"
	iface := "en0"
	stop := make(chan struct{})
	pid := uint64(os.Getpid())

	p, err := multibully.NewParticipant(address, iface, pid, func(state int, ip *net.IP) {
		switch state {
		case multibully.Follower:
			log.Println("* Became Follower of", ip)
		case multibully.Leader:
			log.Println("* Became Leader")
		}
	})

	if err != nil {
		log.Fatal(err)
	}

	go p.StartElection()
	p.RunLoop(stop)
}

Thanks

Thanks to oaStuff for their sample code which helped me understand how to implement the Bully algorithm.

multibully's People

Contributors

tomtaylor avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

multibully's Issues

Election Error

When I run example code in 4 linux:

func main() {
	address := "224.0.0.0:9999"
	iface := "en0"
	stop := make(chan struct{})
	pid := uint64(os.Getpid())

	p, err := multibully.NewParticipant(address, iface, pid, func(state int, ip *net.IP) {
		switch state {
		case multibully.Follower:
			log.Println("* Became Follower of", ip)
		case multibully.Leader:
			log.Println("* Became Leader")
		}
	})

	if err != nil {
		log.Fatal(err)
	}

	go p.StartElection()
	p.RunLoop(stop)
}

soneone will Became Leader

Then I stop Leader linux and someone Follower linux at the same time, ( Now is running two follower )

The election will stop !!!???

I dont konw why ? How to fix it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.