raftmanager

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2024 License: BSD-2-Clause Imports: 9 Imported by: 1

README

raft-manager

RaftAdmin is a gRPC service to invoke methods on https://godoc.org/github.com/hashicorp/raft#Raft. It only works with Hashicorp's Raft implementation.

Usage

r, err := raft.NewRaft(...)
s := grpc.NewServer()
raftmanager.Register(s, r)

Adding the call to raftmanager.Register will register a new gRPC service on your existing server that exposes a bunch of methods so they can be called remotely.

For example, I use this to add servers (voters) after initial bootstrap.

Invocations

$ raftmanager
Usage: raftmanager <host:port> <command> <args...>
Commands: add_nonvoter, add_voter, applied_index, apply_log, await, barrier, demote_voter, forget, get_configuration, last_contact, last_index, leader, leadership_transfer, leadership_transfer_to_server, remove_server, shutdown, snapshot, state, stats, verify_leader

$ raftmanager 127.0.0.1:50051 add_voter serverb 127.0.0.1:50052 0
Invoking AddVoter(id: "serverb" address: "127.0.0.1:50052")
Response: operation_token:  "4a86d2efa417af281ac540bfede8fcb735e0b224"
Invoking Await(operation_token: "4a86d2efa417af281ac540bfede8fcb735e0b224")
Response: index:  3

AddVoter starts a new raft operation and returns once it is enqueued. It returns an operation_token with which you can call Await. Nearly all errors are detected by Await and returns as AwaitResponse.error.

Last, call Forget to make the server forget the operation token and free up the memory.

Inspired

raftadmin

The Jille/raft-grpc-leader-rpc use grpc healthv1 by setting HealthCheckResponse_SERVING to send RPCs to the leader.

func setServingStatus(hs *health.Server, services []string, isLeader bool) {
	v := grpc_health_v1.HealthCheckResponse_NOT_SERVING
	if isLeader {
		v = grpc_health_v1.HealthCheckResponse_SERVING
	}
	for _, srv := range services {
		hs.SetServingStatus(srv, v)
	}
	hs.SetServingStatus("quis.RaftLeader", v)
}

License

raft-example is under the BSD 2-Clause License. See the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get(r *raft.Raft) pb.RaftManagerServer

func Register

func Register(s *grpc.Server, r *raft.Raft)

Types

This section is empty.

Directories

Path Synopsis
cmd
manager
Binary raftadmin is a CLI interface to the RaftAdmin gRPC service.
Binary raftadmin is a CLI interface to the RaftAdmin gRPC service.

Jump to

Keyboard shortcuts

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