package manager

import "github.com/containerd/nydus-snapshotter/pkg/manager"

Index

Types

type DaemonCache

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

Daemon state cache to speed up access.

func (*DaemonCache) Add

func (s *DaemonCache) Add(daemon *daemon.Daemon) *daemon.Daemon

Return nil if the daemon is never inserted or managed, otherwise returns the previously inserted daemon pointer. Allowing replace an existed daemon since some fields in Daemon can change after restarting nydusd.

func (*DaemonCache) GetByDaemonID

func (s *DaemonCache) GetByDaemonID(id string, op func(d *daemon.Daemon)) *daemon.Daemon

func (*DaemonCache) List

func (s *DaemonCache) List() []*daemon.Daemon

func (*DaemonCache) Remove

func (s *DaemonCache) Remove(d *daemon.Daemon) *daemon.Daemon

func (*DaemonCache) RemoveByDaemonID

func (s *DaemonCache) RemoveByDaemonID(id string) *daemon.Daemon

func (*DaemonCache) Size

func (s *DaemonCache) Size() int

func (*DaemonCache) Update

func (s *DaemonCache) Update(d *daemon.Daemon)

Also recover daemon runtime state here

type FD

type FD = uintptr

type LivenessMonitor

type LivenessMonitor interface {
	// Subscribe death event of a nydusd daemon.
	// `path` is where the monitor is listening on.
	Subscribe(id string, path string, notifier chan<- deathEvent) error
	// Unsubscribe death event of a nydusd daemon.
	Unsubscribe(id string) error
	// Run the monitor, wait for nydusd death event.
	Run()
	// Stop the monitor and release all the resources.
	Destroy()
}

LivenessMonitor liveness of a nydusd daemon.

type Manager

type Manager struct {
	FsDriver string

	DaemonConfig *daemonconfig.DaemonConfig // Daemon configuration template.
	CgroupMgr    *cgroup.Manager

	LivenessNotifier chan deathEvent // TODO: Close me
	NydusdBinaryPath string
	RecoverPolicy    config.DaemonRecoverPolicy
	SupervisorSet    *supervisor.SupervisorsSet
	// contains filtered or unexported fields
}

Manage RAFS filesystem instances and nydusd daemons.

func NewManager

func NewManager(opt Opt) (*Manager, error)

func (*Manager) AddDaemon

func (m *Manager) AddDaemon(daemon *daemon.Daemon) error

Add an instantiated daemon to be managed by the manager.

Return ErrAlreadyExists if a daemon with the same daemon ID already exists.

func (*Manager) AddRafsInstance

func (m *Manager) AddRafsInstance(r *rafs.Rafs) error

func (*Manager) BuildDaemonCommand

func (m *Manager) BuildDaemonCommand(d *daemon.Daemon, bin string, upgrade bool) (*exec.Cmd, error)

Build commandline according to nydusd daemon configuration.

func (*Manager) CacheDir

func (m *Manager) CacheDir() string

func (*Manager) DeleteDaemon

func (m *Manager) DeleteDaemon(daemon *daemon.Daemon) error

func (*Manager) DestroyDaemon

func (m *Manager) DestroyDaemon(d *daemon.Daemon) error

FIXME: should handle the inconsistent status caused by any step in the function that returns an error.

func (*Manager) GetByDaemonID

func (m *Manager) GetByDaemonID(id string) *daemon.Daemon

func (*Manager) ListDaemons

func (m *Manager) ListDaemons() []*daemon.Daemon

func (*Manager) Lock

func (m *Manager) Lock()

func (*Manager) Recover

func (m *Manager) Recover(ctx context.Context,
	recoveringDaemons *map[string]*daemon.Daemon, liveDaemons *map[string]*daemon.Daemon) error

Recover nydusd daemons and RAFS instances on startup.

To be safe: - Never ever delete any records from DB - Only cache daemon information from DB, do not actually start/create daemons - Only cache RAFS instance information from DB, do not actually recover RAFS runtime state.

func (*Manager) RemoveRafsInstance

func (m *Manager) RemoveRafsInstance(snapshotID string) error

func (*Manager) StartDaemon

func (m *Manager) StartDaemon(d *daemon.Daemon) error

Spawn a nydusd daemon to serve the daemon instance.

When returning from `StartDaemon()` with out error:

func (*Manager) SubscribeDaemonEvent

func (m *Manager) SubscribeDaemonEvent(d *daemon.Daemon) error

func (*Manager) Unlock

func (m *Manager) Unlock()

func (*Manager) UnsubscribeDaemonEvent

func (m *Manager) UnsubscribeDaemonEvent(d *daemon.Daemon) error

func (*Manager) UpdateDaemon

func (m *Manager) UpdateDaemon(daemon *daemon.Daemon) error

func (*Manager) UpdateDaemonLocked

func (m *Manager) UpdateDaemonLocked(daemon *daemon.Daemon) error

Notice: updating daemon states cache and DB should be protect by `mu` lock

type Opt

type Opt struct {
	CacheDir         string
	CgroupMgr        *cgroup.Manager
	DaemonConfig     *daemonconfig.DaemonConfig
	Database         *store.Database
	FsDriver         string
	NydusdBinaryPath string
	RecoverPolicy    config.DaemonRecoverPolicy
	RootDir          string // Nydus-snapshotter work directory
}

type Store

type Store interface {
	// If the daemon is inserted to DB before, return error ErrAlreadyExisted.
	AddDaemon(d *daemon.Daemon) error
	UpdateDaemon(d *daemon.Daemon) error
	DeleteDaemon(id string) error
	WalkDaemons(ctx context.Context, cb func(*daemon.ConfigState) error) error
	CleanupDaemons(ctx context.Context) error

	AddRafsInstance(r *rafs.Rafs) error
	DeleteRafsInstance(snapshotID string) error
	WalkRafsInstances(ctx context.Context, cb func(*rafs.Rafs) error) error

	NextInstanceSeq() (uint64, error)
}

Nydus daemons and fs instances persistence storage.

Source Files

daemon_adaptor.go daemon_cache.go daemon_event.go manager.go monitor.go store.go

Version
v0.15.1 (latest)
Published
Jan 26, 2025
Platform
linux/amd64
Imports
28 packages
Last checked
5 days ago

Tools for package owners.