You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Дискуссия посвящена сравнению клиентских API для Leader Election в существующих инструментах.
Для исследования были выбраны инструменты: Etcd, Consul, Zookeeper.
Etcd:
Основные сущности и методы API:
typeElectionstruct {
session*Session// текущая сессияkeyPrefixstring// префиксleaderKeystring// ключ лидера или пустая строкаleaderRevint64// редакция создания лидераleaderSession*Session// сессия лидераhdr*pb.ResponseHeader// заголовок ответа от последних успешных выборов
}
func (e*Election) Campaign(ctx context.Context, valstring) error// Выставляем значениие, как возможное для выборовfunc (e*Election) Proclaim(ctx context.Context, valstring) error// Объявление нового значения без выборовfunc (e*Election) Resign(ctx context.Context) (errerror) // Лидер начинает выборы
// SessionEntry represents a session in consultypeSessionEntrystruct {
CreateIndexuint64IDstringNamestring// позволяет задать имя, которое будет использоваться для distributed lockNodestringLockDelay time.DurationBehaviorstring// поведениеTTLstring// время жизниNamespacestring`json:",omitempty"`// Deprecated for Consul Enterprise in v1.7.0.Checks []string// NodeChecks and ServiceChecks are new in Consul 1.7.0.// When associating checks with sessions, namespaces can be specified for service checks.NodeChecks []stringServiceChecks []ServiceCheck
}
// KV is used to manipulate the K/V APItypeKVstruct {
c*Client
}
func (k*KV) Acquire(p*KVPair, q*WriteOptions) (bool, *WriteMeta, error) // Метод, иницирующий попытку захвата блокировкиfunc (k*KV) Release(p*KVPair, q*WriteOptions) (bool, *WriteMeta, error) // Метод, ответственный за снятие блокировки
// Election is a structure that represents a new instance of a Election. This instance can then// be used to request leadership for a specific resource.typeElectionstruct {
statuschanStatus// Used to communicate state/ status changes to the client// E.g., Client is leader, election is over. It is closed// by Election goroutine (i.e., ElectLeader())resignchanstruct{} // This is a signal channel used by the Client to indicate that// it is resigning from the election. It is closed by Client goroutine.endchanstruct{} // This is a signal channel used by the Client to indicate that// the election is over and should be terminated. It is closed by Client goroutinezkEvents<-chan zk.Event// Used by Zookeeper to send watch events to interested clients.// It will be closed by ZookeepertriggerElectionchanerror// This is used by the ZK watch goroutine to signal that a watched// znode was deleted. This can mean that a followed candidate resigned or that the leader exited// unexpectedly. It will be closed by the Election goroutine (i.e., ElectLeader()).stopZKWatchchanstruct{} // This is a signal channel used to indicate that a ZK watch// goroutine should exit.zkConn*zk.Conn// This is the Zookeeper connection provided by the client.ElectionResourcestring// This is the Zookeeper node that represents the overall election. CandidatesclientNamestring// Client that created the election for instrumentation purposes.// will be children of this node.candidateIDstring// This is the ID assigned by Zookeeper that is associated with the ephemeral node// representing a candidateonce sync.Once// Used to protect operations that should only be executed one time (i.e.,// closing a channel.doneChl<-chan zk.Event// A specific signal that the DONE node, which is created during Delete/EndElection,// was created. This event means that the election should be terminated for the receiving client.
}
funcNewElection(zkConn*zk.Conn, electionResourcestring, clientNamestring) (*Election, error) // создание сущности выборов, которая сможет принимать запросы на участие в нихfunc (le*Election) ElectLeader() // объявление начало выборовfunc (le*Election) ElectLeader() // делает вызывающего кандидатом на выборыfunc (le*Election) EndElection() // окончание выборов
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Дискуссия посвящена сравнению клиентских API для Leader Election в существующих инструментах.
Для исследования были выбраны инструменты: Etcd, Consul, Zookeeper.
Etcd:
Основные сущности и методы API:
Псевдокод для использования:
Документация:
Consul:
Основные сущности и методы API:
Псевдокод для испольвания:
Источник:
Документация:
Zookeeper:
Основные сущности и методы API:
Псевдокод для использования:
Документация:
Библиотека, реализующая возможность выбора лидера для Zookeeper:
Beta Was this translation helpful? Give feedback.
All reactions