rafty

package module
v0.0.0-...-6de2257 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: BSD-3-Clause Imports: 14 Imported by: 1

README

Rafty

Warning Please don't use it.

A perfectly untested library which leverages the RAFT protocol, a discovery mechanism and a consistent hash algorithm to distribute work across a dynamic cluster of workers.

This project aimed to familiarize myself with RAFT and Consul.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLoggerRequired = fmt.Errorf("logger is required")
)

Functions

func NewRaft

func NewRaft[T any, T2 interfaces.Work[T]](c RaftConfig, ch chan RaftLog[T, T2]) (*raft.Raft, error)

Types

type Option

type Option[T any, T2 interfaces.Work[T]] func(*Rafty[T, T2]) error

func Distributor

func Distributor[T any, T2 interfaces.Work[T]](distrib interfaces.Distributor[T, T2]) Option[T, T2]

func HCLogger

func HCLogger[T any, T2 interfaces.Work[T]](logger hclog.Logger) Option[T, T2]

func Logger

func Logger[T any, T2 interfaces.Work[T]](logger interfaces.Logger) Option[T, T2]

func RaftAdvertisedAddress

func RaftAdvertisedAddress[T any, T2 interfaces.Work[T]](address string) Option[T, T2]

func RaftListeningAddressPort

func RaftListeningAddressPort[T any, T2 interfaces.Work[T]](address string, port int) Option[T, T2]

type RaftConfig

type RaftConfig struct {
	ListeningAddress  string
	ListeningPort     int
	AdvertisedAddress string
	Logger            interfaces.Logger
	HCLogger          hclog.Logger
	ServerID          raft.ServerID
}

type RaftLog

type RaftLog[T any, T2 interfaces.Work[T]] struct {
	Disco map[raft.ServerID][]T2
	// contains filtered or unexported fields
}

func (RaftLog[T, T2]) Diff

func (l RaftLog[T, T2]) Diff(key raft.ServerID, targetLog RaftLog[T, T2]) (removed []int, added []int)

Diff returns the source slice indexes that needs to be removed because they are not present or have been modified in the target slice. It also returns the indexes of the target slice that needs to be added because they are not present in the source slice. This function is nil safe.

type Rafty

type Rafty[T any, T2 interfaces.Work[T]] struct {
	// contains filtered or unexported fields
}

Rafty

func New

func New[T any, T2 interfaces.Work[T]](disco interfaces.Discoverer, foreman interfaces.Foreman[T, T2], start func(context.Context, T2), opts ...Option[T, T2]) (*Rafty[T, T2], error)

func (*Rafty[T, T2]) Done

func (r *Rafty[T, T2]) Done() chan struct{}

func (*Rafty[T, T2]) Start

func (r *Rafty[T, T2]) Start(ctx context.Context) (context.Context, error)

Directories

Path Synopsis
Package discovery contains utility functions for discovery.
Package discovery contains utility functions for discovery.
consul Module
dns Module
nats Module
distributor
consistent Module
modulo Module
examples
Package interfaces provides all the interfaces used in Rafty.
Package interfaces provides all the interfaces used in Rafty.
Package loggers contains default loggers for Rafty.
Package loggers contains default loggers for Rafty.
zerolog Module

Jump to

Keyboard shortcuts

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