elector

package module
v0.0.0-...-86a2126 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

README

IoTeX Leader Election

IoTeX server now supports running in active or standby mode. Only when running in active mode, the node will participate into consensus and produce blocks, otherwise, it will only passively listen to the blocks. This could be controlled by using the adming endpoint (e.g. http://localhost:9009/ha). Given this, it's easier to setup a backup node, which could use the same operator key. You only need to manually make one node run in active mode and the others run in standby mode.

A more advanced way is use leader election service to do the aforementioned orchestration automatically. This repo provides a proxy to use etcd to do leader election, and control iotex server to run in either active or standby mode in a high availability (HA) cluster.

In the HA cluster, all nodes are using the same key, but only one node will actively participant into consensus, while the others will only sync blocks.

Usage

  • Local:
make build
bin/elector -etcd=[etcd endpoint] -iotexAdmin=[iotex admin endpoint] iotexProbe=[iotex health endpoint] -key=[e.g., /iotex-server] -value=[identifier in the cluster]
  • Docker:
docker run -d zjshen/iotex-leader-election:latest elector -etcd=[etcd endpoint] -iotexAdmin=[iotex admin endpoint] iotexProbe=[iotex health endpoint] -key=[e.g., /iotex-server] -value=[identifier in the cluster]

Examples

Here are the examples about how to use elector together with iotex server to deploy the HA delegate cluster:

Dependency

The leader election solution here depends on etcd, you need to deploy it to orchestrate the HA delegate cluster.

I deployed etcd via helm chart, but there are many other way to deploy it.

Misc

IoTeX's HA feature is orthogonal to the leader election service. You can build similar solution based on Kubernetes election, Zookeeper and etc.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Elector

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

Elector is a proxy to control the iotex node to run in active or standby mode in a high availability cluster. It uses etcd to do the leader election. When the proxy wins the election campaign, it will signal iotex node to run in active mode. When it resigns, it will signal iotex node to switch back to standby mode

func New

func New(etcdEndpoints []string, iotexAdminEndpoint string, iotexHealthEndpoint string) *Elector

New constructs an election proxy

func (*Elector) Campaign

func (e *Elector) Campaign(ctx context.Context, key string, val string)

Campaign makes the proxy to campaign for the leader election. It's blocking until the proxy is elected.

func (*Elector) Resign

func (e *Elector) Resign(ctx context.Context)

Resign resigns the proxy from the leader if it is

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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