fleet

package
v0.0.0-...-3918530 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventSource = "juno/internal"
)

Variables

View Source
var (
	CtrlBroadcastTest               = "CTRL_BROADCAST_TEST"
	CtrlBroadcastLeaderLiveness     = "CTRL_BROADCAST_LEADER_LIVENESS"
	CtrlBroadcastWipRebuildRsm      = "CTRL_BROADCAST_WIP_REBUILD_RSM"
	CtrlBroadcastPaxosPhase1Prepare = "CTRL_BROADCAST_PAXOS_PHASE1_PREPARE"
	CtrlBroadcastPaxosPhase2Accept  = "CTRL_BROADCAST_PAXOS_PHASE2_ACCEPT"
	CtrlBroadcastPaxosSetValue      = "CTRL_BROADCAST_PAXOS_SET_VALUE"
	CtrlBroadcastPaxosLearnValues   = "CTRL_BROADCAST_PAXOS_LEARN_VALUES"
	CtrlBroadcastDoSnapshot         = "CTRL_BROADCAST_DO_SNAPSHOT"
)
View Source
var (
	CmdTypeGetLock     = "CMDTYPE_GET_LOCK"
	CmdTypeExtendLock  = "CMDTYPE_EXTEND_LOCK"
	CmdTypeReleaseLock = "CMDTYPE_RELEASE_LOCK"
	CmdTypeAddToSet    = "CMDTYPE_ADDTOSET"
)
View Source
var (
	ErrClusterOffline = fmt.Errorf("juno: Cluster not running.")
	ErrNoLeader       = fmt.Errorf("juno: Leader unavailable. Please try again later.")
	ErrWipRebuild     = fmt.Errorf("juno: State machine rebuild in progress. Please try again later.")
)
View Source
var (
	CtrlLeaderPingPong       = "CTRL_PING_PONG"
	CtrlLeaderFwdConsensus   = "CTRL_LEADER_FWD_CONSENSUS"
	CtrlLeaderGetLatestRound = "CTRL_LEADER_GET_LATEST_ROUND"
)

Functions

func BroadcastHandler

func BroadcastHandler(data interface{}, msg []byte) ([]byte, error)

func BuildRsm

func BuildRsm(ctx context.Context, fd *FleetData, noBroadcast bool) error

BuildRsm builds the state machine to it's current state from our replicated log.

func EnsureLeaderActive

func EnsureLeaderActive(ctx context.Context, app *appdata.AppData) (bool, error)

func IsLeader

func IsLeader(fd *FleetData) bool

func LeaderHandler

func LeaderHandler(data interface{}, msg []byte) ([]byte, error)

func LeaderLiveness

func LeaderLiveness(ctx context.Context, app *appdata.AppData)

func MonitorRsmDrift

func MonitorRsmDrift(ctx context.Context, fd *FleetData)

MonitorRsmDrift monitors our local replicated log of missing indeces.

func NewRsm

func NewRsm() *rsmT

NewRsm returns an instance of our replicated state machine set.

func NoLeader

func NoLeader(fd *FleetData) bool

func SendToLeader

func SendToLeader(ctx context.Context, app *appdata.AppData, m []byte, extra ...SendToLeaderExtra) ([]byte, error)

Types

type Accept

type Accept struct {
	Round    int64  `json:"round"` // multipaxos round number
	AcceptId int64  `json:"acceptId"`
	NodeId   int64  `json:"nodeId"` // tie-breaker
	Value    string `json:"value"`
}

Phase 2a:

type Accepted

type Accepted struct {
	Error    error `json:"error"` // non-nil = NACK
	Round    int64 `json:"round"` // multipaxos round number
	AcceptId int64 `json:"acceptId"`
	NodeId   int64 `json:"nodeId"` // tie-breaker
}

Phase 2b:

type FleetData

type FleetData struct {
	App *appdata.AppData // global appdata

	StateMachine *rsmT // our replicated state machine

	BuildRsmWip *timedoff.TimedOff // pause ops when active
	BuildRsmOn  int64              // non-zero means someone is rebuilding their RSM

	Online int32 // non-zero mean we are ready to serve

	SetValueMtx       sync.RWMutex
	SetValueHistory   map[int]*SetValueHistoryT // track incoming rounds since online, not complete
	SetValueLastRound int64
	SetValueReady     int32
	// contains filtered or unexported fields
}

type LearnValuesInput

type LearnValuesInput struct {
	Rounds []int `json:"rounds"`
}

type LearnValuesOutput

type LearnValuesOutput struct {
	Value Accept `json:"value"` // reuse
}

type LockState

type LockState struct {
	Name     string
	Token    string
	State    int32     // 1 = locked, > 1 = extended, 0 = available|released
	Start    time.Time // should be Spanner time, not local
	Duration int64     // seconds
	Error    error
}

type MetaT

type MetaT struct {
	Id        string    `json:"id"`
	Round     int64     `json:"round"`
	Value     string    `json:"value"`
	Updated   time.Time `json:"updated"`
	Committed time.Time `json:"committed"`
}

type Prepare

type Prepare struct {
	PrepareId int64 `json:"prepareId"` // proposal
	NodeId    int64 `json:"nodeId"`    // tie-breaker
	Round     int64 `json:"round"`     // multipaxos round number
}

Phase 1a:

type Promise

type Promise struct {
	Error          error  `json:"error"`     // non-nil = NACK
	PrepareId      int64  `json:"prepareId"` // proposal
	NodeId         int64  `json:"nodeId"`    // tie-breaker
	Round          int64  `json:"round"`     // multipaxos round number
	LastPrepareId  int64  `json:"lastPrepareId"`
	LastAcceptedId int64  `json:"lastAcceptedId"`
	Value          string `json:"value"`
}

Phase 1b:

type ReachConsensusInput

type ReachConsensusInput struct {
	FleetData *FleetData `json:"fd,omitempty"`
	CmdType   string     `json:"cmdType,omitempty"`
	Key       string     `json:"key,omitempty"`
	Value     string     `json:"value,omitempty"`
	// contains filtered or unexported fields
}

type ReachConsensusOutput

type ReachConsensusOutput struct {
	Round int64  `json:"round,omitempty"`
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

func ReachConsensus

func ReachConsensus(ctx context.Context, in *ReachConsensusInput) (*ReachConsensusOutput, error)

ReachConsensus is our generic function to reach consensus on a value across a quorum of nodes using the multi-paxos algorithm variant. Normally called by the leader.

type SendToLeaderExtra

type SendToLeaderExtra struct {
	RetryCount int
	BackOff    *gaxv2.Backoff // use if non-nil
}

type SetValueHistoryT

type SetValueHistoryT struct {
	Value   string
	Applied bool
}

Jump to

Keyboard shortcuts

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