bootstrap

package
v14.10.5 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvPidFile is the name of the environment variable containing the pid file path
	EnvPidFile = "GITALY_PID_FILE"
	// EnvUpgradesEnabled is an environment variable that when defined gitaly must enable graceful upgrades on SIGHUP
	EnvUpgradesEnabled = "GITALY_UPGRADES_ENABLED"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bootstrap

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

Bootstrap handles graceful upgrades

func New

func New(totalConn *prometheus.CounterVec) (*Bootstrap, error)

New performs tableflip initialization

pidFile is optional, if provided it will always contain the current process PID
upgradesEnabled controls the upgrade process on SIGHUP signal

first boot: * gitaly starts as usual, we will refer to it as p1 * New will build a tableflip.Upgrader, we will refer to it as upg * sockets and files must be opened with upg.Fds * p1 will trap SIGHUP and invoke upg.Upgrade() * when ready to accept incoming connections p1 will call upg.Ready() * upg.Exit() channel will be closed when an upgrades completed successfully and the process must terminate

graceful upgrade:

  • user replaces gitaly binary and/or config file
  • user sends SIGHUP to p1
  • p1 will fork and exec the new gitaly, we will refer to it as p2
  • from now on p1 will ignore other SIGHUP
  • if p2 terminates with a non-zero exit code, SIGHUP handling will be restored
  • p2 will follow the "first boot" sequence but upg.Fds will provide sockets and files from p1, when available
  • when p2 invokes upg.Ready() all the shared file descriptors not claimed by p2 will be closed
  • upg.Exit() channel in p1 will be closed now and p1 can gracefully terminate already accepted connections
  • upgrades cannot starts again if p1 and p2 are both running, an hard termination should be scheduled to overcome freezes during a graceful shutdown

gitaly-wrapper is supposed to set EnvUpgradesEnabled in order to enable graceful upgrades

func (*Bootstrap) RegisterStarter

func (b *Bootstrap) RegisterStarter(starter Starter)

RegisterStarter adds a new starter

func (*Bootstrap) Start

func (b *Bootstrap) Start() error

Start will invoke all the registered starters and wait asynchronously for runtime errors in case a Starter fails then the error is returned and the function is aborted

func (*Bootstrap) Wait

func (b *Bootstrap) Wait(gracePeriodTicker helper.Ticker, stopAction func()) error

Wait will signal process readiness to the parent and than wait for an exit condition SIGTERM, SIGINT and a runtime error will trigger an immediate shutdown in case of an upgrade there will be a grace period to complete the ongoing requests stopAction will be invoked during a graceful stop. It must wait until the shutdown is completed.

type ListenFunc

type ListenFunc func(net, addr string) (net.Listener, error)

ListenFunc is a net.Listener factory

type Listener added in v14.0.12

type Listener interface {
	// RegisterStarter adds starter to the pool.
	RegisterStarter(starter Starter)
	// Start starts all registered starters to accept connections.
	Start() error
	// Wait terminates all registered starters.
	Wait(gracePeriodTicker helper.Ticker, stopAction func()) error
}

Listener is an interface of the bootstrap manager.

type Noop added in v14.0.12

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

Noop is a bootstrapper that does no additional configurations.

func NewNoop added in v14.0.12

func NewNoop(connTotal *prometheus.CounterVec) *Noop

NewNoop returns initialized instance of the *Noop.

func (*Noop) RegisterStarter added in v14.0.12

func (n *Noop) RegisterStarter(starter Starter)

RegisterStarter adds starter to the pool.

func (*Noop) Start added in v14.0.12

func (n *Noop) Start() error

Start starts all registered starters to accept connections.

func (*Noop) Terminate added in v14.0.12

func (n *Noop) Terminate()

Terminate unblocks Wait method and executes stopAction call-back passed into it.

func (*Noop) Wait added in v14.0.12

func (n *Noop) Wait(_ helper.Ticker, stopAction func()) error

Wait terminates all registered starters.

type Starter

type Starter func(ListenFunc, chan<- error, *prometheus.CounterVec) error

Starter is function to initialize a net.Listener it receives a ListenFunc to be used for net.Listener creation and a chan<- error to signal runtime errors It must serve incoming connections asynchronously and signal errors on the channel the return value is for setup errors

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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