swogrp

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

README

SWO Group

The swogrp package handles orchestrating the state and transitions of the SWO process. The state of the cluster can be determined by following the sequence in the message log, which is the source of truth.

Cluster State

sequenceDiagram
actor admin as Admin
participant api as API Node
participant log as Message Log
participant engine as Engine Node


note over admin,engine: Cluster State: **Unknown**
admin ->> api : Click(Reset)
activate api
api ->> log : "cancel"
api ->> api : DisableTriggers()
api ->> log : "reset"
api -->> admin: OK
deactivate api

note over admin,engine: Cluster State: **Resetting**

engine ->> log: "hello"
activate engine
note over engine: Becomes Leader
api ->> log: "hello"
engine ->> engine: Wait 3s for "hello" messages
engine ->> log: "reset-end"
deactivate engine
note over admin,engine: Cluster State: **Idle**

admin ->> api: Click(Execute)
activate api
api ->> log: "execute"
api -->> admin: OK
deactivate api

note over admin,engine: Cluster State: **Syncing**

log -->> engine: "execute"
activate engine
engine ->> engine: EnableTriggers()
engine ->> engine: InitialSync()
engine ->> engine: LogicalSync() x10
engine ->> log: "pause"
deactivate engine

note over admin,engine: Cluster State: **Pausing**
engine ->> engine: Pause()
engine ->> log: "paused"
api ->> api: Pause()
api ->> log: "paused"

note over admin,engine: Cluster State: **Executing**
log -->> engine: 2/2 "paused"
activate engine
engine ->> engine: LogicalSync() x10
engine ->> engine: FinalSync()
engine ->> log: "done"
deactivate engine

note over admin,engine: Cluster State: **Done**

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClusterState

type ClusterState int

ClusterState represents the current state of the SWO cluster.

const (
	ClusterStateUnknown ClusterState = iota
	ClusterStateResetting
	ClusterStateIdle
	ClusterStateSyncing
	ClusterStatePausing
	ClusterStateExecuting
	ClusterStateDone
)

type Config

type Config struct {
	// NodeID is the unique ID of the current node.
	NodeID uuid.UUID

	// CanExec indicates this member is allowed to execute tasks.
	CanExec bool

	// OldID and NewID represents the database IDs of the old and new databases, respectively.
	OldID, NewID uuid.UUID

	Logger   *log.Logger
	Messages *swomsg.Log

	PauseFunc  TaskFn
	ResumeFunc TaskFn

	Executor Executor
}

Config is the configuration for a switchover group.

type Executor

type Executor interface {
	Sync(context.Context) error
	Exec(context.Context) error

	Cancel()
}

type Node

type Node struct {
	ID uuid.UUID

	CanExec bool

	OldID uuid.UUID
	NewID uuid.UUID

	StartedAt time.Time
}

Node represents a single node in the switchover group.

type Status

type Status struct {
	State      ClusterState
	Nodes      []Node
	LeaderID   uuid.UUID
	LastStatus string
	LastError  string
}

Status represents the current status of the switchover process.

type TaskFn

type TaskFn func(context.Context) error

type TaskMgr

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

func NewTaskMgr

func NewTaskMgr(ctx context.Context, cfg Config) (*TaskMgr, error)

func (*TaskMgr) Cancel

func (t *TaskMgr) Cancel(ctx context.Context) error

func (*TaskMgr) Execute

func (t *TaskMgr) Execute(ctx context.Context) error

func (*TaskMgr) Init

func (t *TaskMgr) Init()

func (*TaskMgr) Reset

func (t *TaskMgr) Reset(ctx context.Context) error

func (*TaskMgr) Status

func (t *TaskMgr) Status() Status

Status returns the current status of the switchover process.

func (*TaskMgr) Statusf

func (t *TaskMgr) Statusf(ctx context.Context, format string, args ...interface{})

Jump to

Keyboard shortcuts

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