leaderless

package
v0.0.0-...-0253919 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

README

leaderless

Package leaderless implements leader election without the need for coordination. It does this using a highly stable set of peers and a hash ring. Since we know that each node shares the same view of the world, then we know that the computed hash ring will be the same between instances. However, if peer knowledge is not stable (for example, members come and go freely) then leaderless can result in a split brain state where some nodes share a different view of the world until the other nodes "catch up".

This package is loosely inspired by Uber's ringpop system which seems like it's used quite extensively.

import go.pitz.tech/lib/leaderless

Usage

type Director
type Director struct {
}

Director contains logic for routing requests to a leader or set of replicas.

func New
func New() *Director

New returns a Director that can aid in the coordination of work within a cluster.

func (*Director) GetLeader
func (d *Director) GetLeader(key string) (string, bool)

GetLeader returns the current "leader" for a given key.

func (*Director) GetReplicas
func (d *Director) GetReplicas(key string, replicas int) ([]string, bool)

GetReplicas returns a list of peers to replicate information to given a key.

func (*Director) Start
func (d *Director) Start(ctx context.Context, membership *cluster.Membership) error

Start begins the director by observing membership changes in the cluster.

Documentation

Overview

Package leaderless implements leader election without the need for coordination. It does this using a highly stable set of peers and a hash ring. Since we know that each node shares the same view of the world, then we know that the computed hash ring will be the same between instances. However, if peer knowledge is not stable (for example, members come and go freely) then leaderless can result in a split brain state where some nodes share a different view of the world until the other nodes "catch up".

This package is loosely inspired by Uber's ringpop system which seems like it's used quite extensively.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Director

type Director struct {
	// contains filtered or unexported fields
}

Director contains logic for routing requests to a leader or set of replicas.

func New

func New() *Director

New returns a Director that can aid in the coordination of work within a cluster.

func (*Director) GetLeader

func (d *Director) GetLeader(key string) (string, bool)

GetLeader returns the current "leader" for a given key.

func (*Director) GetReplicas

func (d *Director) GetReplicas(key string, replicas int) ([]string, bool)

GetReplicas returns a list of peers to replicate information to given a key.

func (*Director) Start

func (d *Director) Start(ctx context.Context, membership *cluster.Membership) error

Start begins the director by observing membership changes in the cluster.

Jump to

Keyboard shortcuts

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