manager

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package manager предоставляет gRPC-сервис для обмена состоянием между репликами.

Это самый сложный и важный gRPC-сервис в кластере.

Использует Bidi-стримы для:

  1. Обмена метаданными (Meta)
  2. Обмена состоянием (State)
  3. Поддержания соединения с репликами

Каждая реплика открывает Bidi-стрим к другим репликам и отправляет:

  • Meta — при подключении
  • State — периодически (через Process)

Index

Constants

This section is empty.

Variables

View Source
var Component = compogo.Component{
	Dependencies: compogo.Components{
		&grpcServer.Component,
		&grpcClientConfig.Component,
		&manager.Component,
		&repeater.Component,
	},
	Init: compogo.StepFunc(func(container compogo.Container) error {
		return container.Provide(NewService)
	}),
	PreExecute: compogo.StepFunc(func(container compogo.Container) error {
		return container.Invoke(func(
			r repeater.Repeater,
			s *Service,
			grpc *grpcServer.Server,
			delayConfig *manager.Delay,
			m cluster.Manager,
		) error {

			service.RegisterPeerServer(grpc.GetGRPC(), s)

			m.OnAddPeer().Subscribe(s.onAddPeer)

			return r.AddProcess(repeater.NewUnlockTask(
				"cluster.grpc.replica",
				delayConfig.SyncState,
				s.Process,
			))
		})
	}),
}

Component — компонент для регистрации gRPC-сервиса Peer.

Жизненный цикл:

  1. Init — регистрирует конструктор Service в DI-контейнере.
  2. PreExecute — подписывается на добавление Peer'ов и запускает задачу рассылки состояния.

Особенности:

  • onAddPeer — создаёт Bidi-стрим к новому Peer.
  • Process — периодически рассылает состояние всем Peer'ам.
View Source
var PeerAlreadyExistsError = errors.New("peer already exists")

Functions

This section is empty.

Types

type Service

type Service struct {
	service.UnimplementedPeerServer
	// contains filtered or unexported fields
}

Service — реализация gRPC-сервиса Peer.

func NewService

func NewService(
	m cluster.Manager,
	delayConfig *managerConfig.Delay,
	grpcConfig *grpcClientConfig.Config,
	logger compogo.Logger,
	closer compogo.Closer,
) *Service

NewService создаёт новый сервис Peer.

func (*Service) Process

func (s *Service) Process(_ context.Context) error

Process — периодическая задача для рассылки состояния.

Отправляет текущее состояние всем подключённым репликам. Запускается через Repeater с интервалом delayConfig.SyncState.

func (*Service) Subscribe

Subscribe — обработчик подключения реплики.

Это Bidi-стрим, через который реплики обмениваются состоянием.

Алгоритм:

  1. Получает Meta от подключающейся реплики.
  2. Создаёт или обновляет Peer.
  3. Добавляет Peer в менеджер.
  4. Отправляет своё Meta обратно.
  5. Запускает обработку входящих сообщений.

Jump to

Keyboard shortcuts

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