plenum

package module
v0.0.0-...-ae2d869 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 14 Imported by: 0

README

plenum

Main Go Report Card

A package for membership and consensus that uses Serf and Raft.

Configuration

  • PLENUM_DEBUG: Exposes Serf and Raft logging to stdout

Usage

Package
bindAddress := "10.0.0.10"
bindPort := 6789
members := []string{"10.0.0.20:6789", "10.0.0.30:6789"}

p, err := plenum.Convene(nil, bindAddress, bindPort, members)
if err != nil {
  log.Fatal(err)
}
go p.Procede()

// Wait for, and act on leader designation
go func(*plenum.Plenum) {
  for <-p.IsLeader {
    fmt.Println("Members: ", p.Members())
    fmt.Println("Leader: ", p.Consensus())
    fmt.Println("Elected leader!")
  }
}(p)
Example CLI
  1. Start three members, in three terminals, with different ports:
# Terminal A
go run cmd/plenum/main.go -port 1111

# Terminal B
go run cmd/plenum/main.go -port 2222 -members=127.0.0.1:1111

# Terminal C
go run cmd/plenum/main.go -port 3333 -members=127.0.0.1:2222
  1. Kill the member (CTRL+C) in terminal A, and watch consensus adjust.

  2. Rejoin terminal A with:

go run cmd/plenum/main.go -port 1111 -members=127.0.0.1:2222

Each member also starts an HTTP listener with the followings routes for discovery:

  • /members: Returns list of active membership
  • /leader: Returns active leader

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Plenum

type Plenum struct {
	Procedures chan serf.Event // Exposed channel for handling Serf events

	IsLeader chan bool      // Exposed channel for determining leadership
	IsClosed chan os.Signal // Exposed channel for graceful shutdown
	// contains filtered or unexported fields
}

func Convene

func Convene(
	logger *log.Logger,
	address string,
	port int,
	members []string,
) (*Plenum, error)

Convene creates a new membership and consensus group

func (*Plenum) Consensus

func (p *Plenum) Consensus() string

Consensus returns the current leader of the plenum

func (*Plenum) Membership

func (p *Plenum) Membership() []string

Membership returns the current membership list

func (*Plenum) Procede

func (p *Plenum) Procede()

Procede starts the core consensus loop

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL