raftnode

package module
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: May 15, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package raftnode provides an optional Dragonboat multi-group Raft adapter for Vale.

Index

Constants

View Source
const (
	MetadataGroupName     = "metadata"
	MetadataGroupID       = uint64(1)
	DataGroupName         = "data"
	DataGroupID           = uint64(2)
	CertificatesGroupName = "certificates"
	CertificatesGroupID   = uint64(3)
	DefaultGroupName      = DataGroupName
	DefaultGroupID        = DataGroupID
)
View Source
const (
	CommandTypeSnapshotUpdate         = "snapshot_update"
	CommandTypeRouteSync              = "route_sync"
	CommandTypeCertificateStore       = "certificate_store"
	CommandTypeCertificateDelete      = "certificate_delete"
	CommandTypeCertificateLockAcquire = "certificate_lock_acquire"
	CommandTypeCertificateLockRelease = "certificate_lock_release"
)
View Source
const (
	DefaultGossipBindAddr = "127.0.0.1:17100"
)

Variables

View Source
var ErrNotRunning = errors.New("raft node is not running")

ErrNotRunning is returned when a membership operation targets a stopped node.

Functions

func NodeHostConfig added in v0.1.1

func NodeHostConfig(cfg Config) dragonconfig.NodeHostConfig

NodeHostConfig returns the Dragonboat NodeHost configuration used by Vale when Config.NodeHost is not supplied.

Types

type CertificateLockCommand added in v0.1.1

type CertificateLockCommand struct {
	Name        string    `json:"name"`
	Owner       string    `json:"owner"`
	RequestedAt time.Time `json:"requested_at,omitzero"`
	ExpiresAt   time.Time `json:"expires_at,omitzero"`
}

type CertificateLockRecord added in v0.1.1

type CertificateLockRecord struct {
	Name      string    `json:"name"`
	Owner     string    `json:"owner"`
	ExpiresAt time.Time `json:"expires_at,omitzero"`
}

type CertificateRecord added in v0.1.1

type CertificateRecord struct {
	Key      string    `json:"key"`
	Value    []byte    `json:"value,omitempty"`
	Modified time.Time `json:"modified,omitzero"`
}

type Command

type Command struct {
	Type        string                            `json:"type"`
	Snapshot    *SnapshotUpdate                   `json:"snapshot,omitempty"`
	Routes      *collectionlist.List[RouteRecord] `json:"routes,omitempty"`
	Certificate *CertificateRecord                `json:"certificate,omitempty"`
	Lock        *CertificateLockCommand           `json:"lock,omitempty"`
	Raw         json.RawMessage                   `json:"raw,omitempty"`
}

type CommandResult added in v0.1.1

type CommandResult struct {
	OK      bool   `json:"ok"`
	Reason  string `json:"reason,omitempty"`
	Version uint64 `json:"version,omitempty"`
}

type Config

type Config struct {
	NodeID         string
	BindAddr       string
	DataDir        string
	Bootstrap      bool
	DeploymentID   uint64
	RTTMillisecond uint64
	NodeHost       *dragonboat.NodeHost
	LogDB          dragonconfig.LogDBConfig
	Groups         *collectionlist.List[GroupConfig]
	Discovery      Discovery

	DiscoveryReconcileInterval time.Duration
	DiscoveryJoinTimeout       time.Duration
}

func DefaultConfig

func DefaultConfig() Config

type Discovery added in v0.1.1

type Discovery interface {
	Start(ctx context.Context, local DiscoveryNode, onChange func()) error
	Peers() *collectionlist.List[DiscoveryNode]
	Shutdown() error
}

type DiscoveryNode added in v0.1.1

type DiscoveryNode struct {
	ID           string
	RaftAddress  string
	DeploymentID uint64
	Groups       *collectionlist.List[string]
}

type GroupConfig added in v0.1.1

type GroupConfig struct {
	Name           string
	ID             uint64
	Bootstrap      bool
	Join           bool
	InitialMembers *mapping.Map[string, string]
}

type MemberlistDiscovery added in v0.1.1

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

func NewMemberlistDiscovery added in v0.1.1

func NewMemberlistDiscovery(config MemberlistDiscoveryConfig, logger *slog.Logger) *MemberlistDiscovery

func (*MemberlistDiscovery) GetBroadcasts added in v0.1.1

func (d *MemberlistDiscovery) GetBroadcasts(_, _ int) [][]byte

func (*MemberlistDiscovery) LocalState added in v0.1.1

func (d *MemberlistDiscovery) LocalState(bool) []byte

func (*MemberlistDiscovery) MergeRemoteState added in v0.1.1

func (d *MemberlistDiscovery) MergeRemoteState([]byte, bool)

func (*MemberlistDiscovery) NodeMeta added in v0.1.1

func (d *MemberlistDiscovery) NodeMeta(limit int) []byte

func (*MemberlistDiscovery) NotifyJoin added in v0.1.1

func (d *MemberlistDiscovery) NotifyJoin(node *memberlist.Node)

func (*MemberlistDiscovery) NotifyLeave added in v0.1.1

func (d *MemberlistDiscovery) NotifyLeave(node *memberlist.Node)

func (*MemberlistDiscovery) NotifyMsg added in v0.1.1

func (d *MemberlistDiscovery) NotifyMsg([]byte)

func (*MemberlistDiscovery) NotifyUpdate added in v0.1.1

func (d *MemberlistDiscovery) NotifyUpdate(node *memberlist.Node)

func (*MemberlistDiscovery) Peers added in v0.1.1

func (*MemberlistDiscovery) Shutdown added in v0.1.1

func (d *MemberlistDiscovery) Shutdown() error

func (*MemberlistDiscovery) Start added in v0.1.1

func (d *MemberlistDiscovery) Start(ctx context.Context, local DiscoveryNode, onChange func()) error

type MemberlistDiscoveryConfig added in v0.1.1

type MemberlistDiscoveryConfig struct {
	BindAddr      string
	AdvertiseAddr string
	Seeds         *collectionlist.List[string]
	JoinInterval  time.Duration
}

type Node

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

func New

func New(config Config, logger *slog.Logger) (*Node, error)

func (*Node) AddGroupVoter added in v0.1.1

func (n *Node) AddGroupVoter(group, id, address string, timeout time.Duration) error

func (*Node) AddVoter

func (n *Node) AddVoter(id, address string, timeout time.Duration) error

func (*Node) AppliedGroupState added in v0.1.1

func (n *Node) AppliedGroupState(group string) State

func (*Node) AppliedGroupStateJSON added in v0.1.1

func (n *Node) AppliedGroupStateJSON(group string, timeout time.Duration) ([]byte, error)

func (*Node) AppliedState

func (n *Node) AppliedState() State

func (*Node) Apply

func (n *Node) Apply(data []byte, timeout time.Duration) error

func (*Node) ApplyGroup added in v0.1.1

func (n *Node) ApplyGroup(group string, data []byte, timeout time.Duration) error

func (*Node) GroupPeers added in v0.1.1

func (n *Node) GroupPeers(group string) (*collectionlist.List[*Peer], error)

func (*Node) IsEnabled

func (n *Node) IsEnabled() bool

func (*Node) IsGroupLeader added in v0.1.1

func (n *Node) IsGroupLeader(group string) bool

func (*Node) IsLeader

func (n *Node) IsLeader() bool

func (*Node) Peers

func (n *Node) Peers() (*collectionlist.List[*Peer], error)

func (*Node) ProposeGroup added in v0.1.1

func (n *Node) ProposeGroup(group string, data []byte, timeout time.Duration) ([]byte, error)

func (*Node) RemoveGroupServer added in v0.1.1

func (n *Node) RemoveGroupServer(group, id string, timeout time.Duration) error

func (*Node) RemoveServer

func (n *Node) RemoveServer(id string, timeout time.Duration) error

func (*Node) Shutdown

func (n *Node) Shutdown() error

func (*Node) Status

func (n *Node) Status() *mapping.Map[string, any]

type Peer

type Peer = mapping.Map[string, string]

type RouteRecord

type RouteRecord struct {
	Name       string `json:"name"`
	Entrypoint string `json:"entrypoint"`
	Host       string `json:"host,omitempty"`
	PathPrefix string `json:"path_prefix,omitempty"`
	Method     string `json:"method,omitempty"`
	Service    string `json:"service"`
}

type SnapshotUpdate

type SnapshotUpdate struct {
	BuiltAt     string `json:"built_at"`
	Services    int    `json:"services"`
	Routes      int    `json:"routes"`
	ProxyEngine string `json:"proxy_engine"`
}

type State

type State struct {
	Version      uint64                                      `json:"version"`
	AppliedAt    time.Time                                   `json:"applied_at"`
	Snapshot     *SnapshotUpdate                             `json:"snapshot,omitempty"`
	Routes       *collectionlist.List[RouteRecord]           `json:"routes,omitempty"`
	Certificates *collectionlist.List[CertificateRecord]     `json:"certificates,omitempty"`
	Locks        *collectionlist.List[CertificateLockRecord] `json:"locks,omitempty"`
	Raw          json.RawMessage                             `json:"raw,omitempty"`
}

Jump to

Keyboard shortcuts

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