election

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: 10 Imported by: 0

Documentation

Overview

Package election предоставляет gRPC-сервис для выборов лидера.

Этот сервис используется репликами для обмена term и бюллетенями.

Методы:

  • Election — синхронизация term (возраста) между репликами
  • Vote — обмен бюллетенями для голосования

Index

Constants

This section is empty.

Variables

View Source
var Component = compogo.Component{
	Dependencies: compogo.Components{
		&election.Component,
		&grpcServer.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(grpc *grpcServer.Server, s *Service) {

			service.RegisterElectionServer(grpc.GetGRPC(), s)
		})
	}),
}

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

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

  1. Init — регистрирует конструктор Service в DI-контейнере.
  2. PreExecute — регистрирует Service в gRPC-сервере.

Зависимости:

  • election.Component — бизнес-логика выборов
  • grpcServer.Component — gRPC-сервер

Functions

This section is empty.

Types

type Service

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

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

Регистрируется в gRPC-сервере и обрабатывает запросы от других реплик.

func NewService

func NewService(election *election.Election, m cluster.Manager) *Service

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

func (*Service) Election

func (s *Service) Election(_ context.Context, age *model.Age) (*model.Age, error)

Election — обработчик синхронизации term.

Вызывается другой репликой для синхронизации term.

Параметры:

  • age — содержит term и хост реплики, которая запрашивает синхронизацию

Возвращает:

  • Age — с текущим term текущей реплики и её хостом

Примечание: при получении term запускаются новые выборы (через AgeSync).

func (*Service) Vote

func (s *Service) Vote(_ context.Context, bulletin *model.Bulletin) (*model.Bulletin, error)

Vote — обработчик голосования.

Вызывается другой репликой для отправки бюллетеня.

Параметры:

  • bulletin — бюллетень от другой реплики (term и candidateId)

Возвращает:

  • Bulletin — текущий бюллетень текущей реплики

Jump to

Keyboard shortcuts

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