paxos

package module
v0.0.0-...-17369de Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2019 License: Apache-2.0 Imports: 28 Imported by: 5

README

go-paxos --- Go 多组 Paxos 库

关于

go-paxos 是一个 Go 实现的多组Paxos共识算法库

特性

  • 基于Lamport的 Paxos Made Simple 进行工程化,不进行任何算法变种。
  • 每次写盘使用fsync严格保证正确性。
  • 在一个节点上一次 Propose 的Latency为一次RTT。
  • 节点主动向其他节点进行点对点快速学习。

待完成

  • snapshot。
  • 运行过程中节点的动态变更。
  • master 选举。

性能

运行环境
OS: Ubuntu 18.04
CPU: Intel Core i5-7500@ 4x 3.8GHz
内存:8GB
硬盘:Intel P4510 2TB

性能测试结果(qps)

48个group:37596 

Acknowledgments

Documentation

Index

Examples

Constants

View Source
const (
	//PaxosMajor ...
	PaxosMajor = 0
	//PaxosMinor ...
	PaxosMinor = 0
	//PaxosPatch ...
	PaxosPatch = 1
	// DEVVersion is a boolean value to indicate whether this is a dev version
	DEVVersion = true
)

Variables

View Source
var (
	ErrGroupNotFound        = errors.New("group not found")
	ErrGroupAlreadyExist    = errors.New("group already exist")
	ErrInvalidGroupSettings = errors.New("group settings are invalid")
	ErrDeadlineNotSet       = errors.New("deadline not set")
	ErrInvalidDeadline      = errors.New("invalid deadline")
)
View Source
var (
	// ErrInvalidSession indicates that the specified client session is invalid.
	ErrInvalidSession = errors.New("invalid session")
	// ErrTimeoutTooSmall indicates that the specified timeout value is too small.
	ErrTimeoutTooSmall = errors.New("specified timeout value is too small")
	// ErrPayloadTooBig indicates that the payload is too big.
	ErrPayloadTooBig = errors.New("payload is too big")
	// ErrSystemBusy indicates that the system is too busy to handle the request.
	ErrSystemBusy = errors.New("system is too busy try again later")
	// ErrGroupClosed indicates that the requested cluster is being shut down.
	ErrGroupClosed = errors.New("paxos group already closed")
	// ErrBadKey indicates that the key is bad, retry the request is recommended.
	ErrBadKey = errors.New("bad key try again later")
	// ErrPendingConfigChangeExist indicates that there is already a pending
	// membership change exist in the system.
	ErrPendingConfigChangeExist = errors.New("pending config change request exist")
	// ErrTimeout indicates that the operation timed out.
	ErrTimeout = errors.New("timeout")
	// ErrSystemStopped indicates that the system is being shut down.
	ErrSystemStopped = errors.New("system stopped")
	// ErrCanceled indicates that the request has been canceled.
	ErrCanceled = errors.New("request canceled")
	// ErrRejected indicates that the request has been rejected.
	ErrRejected = errors.New("request rejected")
)

Functions

func IsTempError

func IsTempError(err error) bool

IsTempError returns a boolean value indicating whether the specified error is a temporary error that worth to be retried later with the exact same input, potentially on a more suitable NodeHost instance.

Types

type ICompleteHandler

type ICompleteHandler interface {
	Notify(RequestResult)
	Release()
}

ICompleteHandler is a handler interface that will be invoked when the request in completed. This interface is used by the language bindings, applications are not expected to directly use this interface.

type INodeUser

type INodeUser interface {
	Propose(groupID uint64, cmd []byte,
		timeout time.Duration) (*RequestState, error)
}

INodeUser is the interface implemented by a Paxos node user type. A Paxos node user can be used to directly initiate proposals operations without locating the Paxos node in NodeHost's node list first. It is useful when doing bulk load operations on selected groups.

type NodeHost

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

NodeHost ...

func NewNodeHost

func NewNodeHost(nhConfig config.NodeHostConfig) *NodeHost

NewNodeHost ...

Example
nhc := config.NodeHostConfig{
	WALDir:         "wal",
	NodeHostDir:    "go-paxos",
	RTTMillisecond: 200,
	PaxosAddress:   "myhostname:5012",
}
nh := NewNodeHost(nhc)
log.Printf("nodehost created, running on %s", nh.PaxosAddress())
Output:

func (*NodeHost) GetNodeUser

func (nh *NodeHost) GetNodeUser(groupID uint64) (INodeUser, error)

GetNodeUser returns an INodeUser instance ready to be used to directly make proposals.

func (*NodeHost) HasNodeInfo

func (nh *NodeHost) HasNodeInfo(groupID uint64, nodeID uint64) bool

HasNodeInfo returns a boolean value indicating whether the specified node has been bootstrapped on the current NodeHost instance.

func (*NodeHost) NodeHostConfig

func (nh *NodeHost) NodeHostConfig() config.NodeHostConfig

NodeHostConfig ...

func (*NodeHost) PaxosAddress

func (nh *NodeHost) PaxosAddress() string

PaxosAddress ...

func (*NodeHost) Propose

func (nh *NodeHost) Propose(grouID uint64, cmd []byte,
	timeout time.Duration) (*RequestState, error)

Propose ...

func (*NodeHost) ReadLocalNode

func (nh *NodeHost) ReadLocalNode(groupID uint64, query []byte) ([]byte, error)

ReadLocalNode queries the paxos node identified by the input RequestState instance.

func (*NodeHost) StartGroup

func (nh *NodeHost) StartGroup(nodes map[uint64]string, join bool,
	createStateMachine func(uint64, uint64) statemachine.IStateMachine,
	config config.Config) error

StartGroup ...

Example
nhc := config.NodeHostConfig{
	WALDir:         "wal",
	NodeHostDir:    "go-paxos",
	RTTMillisecond: 200,
	PaxosAddress:   "myhostname:5012",
}
// Creates a nodehost instance using the above NodeHostConfig instnace.
nh := NewNodeHost(nhc)
// config for paxos
rc := config.Config{
	NodeID:         1,
	GroupID:        1,
	AskForLearnRTT: 10,
}
peers := make(map[uint64]string)
peers[100] = "myhostname1:5012"
peers[200] = "myhostname2:5012"
peers[300] = "myhostname3:5012"
// Use this NO-OP data store in this example
NewStateMachine := func(clusterID uint64, nodeID uint64) statemachine.IStateMachine {
	return &tests.NoOP{}
}
if err := nh.StartGroup(peers, false, NewStateMachine, rc); err != nil {
	log.Fatalf("failed to add group, %v\n", err)
}
Output:

func (*NodeHost) Stop

func (nh *NodeHost) Stop()

Stop ...

func (*NodeHost) StopGroup

func (nh *NodeHost) StopGroup(groupID uint64) error

StopGroup ...

func (*NodeHost) StopNode

func (nh *NodeHost) StopNode(groupID uint64, nodeID uint64) error

StopNode ...

func (*NodeHost) SyncPropose

func (nh *NodeHost) SyncPropose(ctx context.Context, groupID uint64,
	cmd []byte) (uint64, error)

SyncPropose ...

type RequestResult

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

RequestResult is the result struct returned for the request.

func (*RequestResult) Completed

func (rr *RequestResult) Completed() bool

Completed returns a boolean value indicating the request request completed successfully. For proposals, it means the proposal has been committed by the Raft cluster and applied on the local node. For ReadIndex operation, it means the cluster is now ready for a local read.

func (*RequestResult) GetResult

func (rr *RequestResult) GetResult() uint64

GetResult returns the result value of the request. When making a proposal, the returned result is the value returned by the Update method of the IStateMachine instance.

func (*RequestResult) Rejected

func (rr *RequestResult) Rejected() bool

Rejected returns a boolean value indicating the request is rejected. For a proposal, it means that the used client session instance is not registered or it has been evicted on the server side. When requesting a client session to be registered, Rejected means the another client session with the same client ID has already been registered. When requesting a client session to be unregistered, Rejected means the specified client session is not found on the server side. For a membership change request, it means the request is out of order and thus ignored. Note that the out-of-order check when making membership changes is only imposed when IMasterClient is used in NodeHost.

func (*RequestResult) Terminated

func (rr *RequestResult) Terminated() bool

Terminated returns a boolean value indicating the request terminated due to the requested Raft cluster is being shut down.

func (*RequestResult) Timeout

func (rr *RequestResult) Timeout() bool

Timeout returns a boolean value indicating whether the Request timed out.

type RequestResultCode

type RequestResultCode int

RequestResultCode is the result code returned to the client to indicate the outcome of the request.

func (RequestResultCode) String

func (c RequestResultCode) String() string

type RequestState

type RequestState struct {

	// CompleteC is a channel for delivering request result to users.
	CompletedC chan RequestResult
	// contains filtered or unexported fields
}

RequestState is the object used to provide request result to users.

func (*RequestState) Release

func (r *RequestState) Release()

Release puts the RequestState object back to the sync.Pool pool.

Directories

Path Synopsis
example
internal
logdb/gorocksdb
Package gorocksdb provides the ability to create and access RocksDB databases.
Package gorocksdb provides the ability to create and access RocksDB databases.
logdb/levigo
Package levigo provides the ability to create and access LevelDB databases.
Package levigo provides the ability to create and access LevelDB databases.
rsm
utils/netutil/cenk/backoff
Package backoff implements backoff algorithms for retrying operations.
Package backoff implements backoff algorithms for retrying operations.
utils/netutil/rubyist/circuitbreaker
Package circuit implements the Circuit Breaker pattern.
Package circuit implements the Circuit Breaker pattern.
Package logger manages loggers used in dragonboat.
Package logger manages loggers used in dragonboat.
Package statemachine contains the definition of the IStateMachine interface required to be implemented by dragonboat based applications.
Package statemachine contains the definition of the IStateMachine interface required to be implemented by dragonboat based applications.
tools

Jump to

Keyboard shortcuts

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