Documentation
¶
Index ¶
- Constants
- Variables
- func DoAccept(index, proposalNum int, proposalValue string) error
- func DoPrepare(index int, value string, minProposal int) (bool, error)
- func GenerateProposalNum(minProposalNum, ID int) int
- func GetNetwork() string
- func GetPeerNameList() []string
- func GetServerID() int
- func InitAcceptor()
- func InitDB()
- func InitProposerNetwork()
- func ProposerHandleRequst()
- func SendAcceptRequestAndWaitForReply(req *AcceptRequest, done chan struct{}) chan *AcceptResponse
- func SendLearnRequest(req *LearnRequest)
- func SendPrepareRequestAndWaitForReply(req *PrepareRequest, done chan struct{}) chan *PrepareResponse
- func SetBatcher(duration time.Duration, limit int)
- func StartNewInstance(reqs ...Request) error
- type AcceptRequest
- type AcceptResponse
- type Acceptor
- func (acceptor *Acceptor) OnAccept(req *AcceptRequest, resp *AcceptResponse) error
- func (acceptor *Acceptor) OnLearn(req *LearnRequest, resp *LearnResponse) error
- func (acceptor *Acceptor) OnPrepare(req *PrepareRequest, resp *PrepareResponse) error
- func (acceptor *Acceptor) ReDailMe(serverID *int, resp *struct{}) error
- type BatchRequest
- type Batcher
- type LearnRequest
- type LearnResponse
- type LevelDB
- type LogEntry
- type MyComparator
- type PrepareRequest
- type PrepareResponse
- type Proposer
- type Request
- type Store
Constants ¶
View Source
const BatcherDefaultDuration = time.Millisecond
View Source
const BatcherDefaultLimit = 100
View Source
const SHIFT = 3
Variables ¶
View Source
var ErrorBadLogFormat = errors.New("bad log format")
View Source
var ErrorEmptyKey = errors.New("empty key error")
View Source
var ErrorEmptyValue = errors.New("empty value error")
View Source
var ErrorNoPeers = errors.New("nil peers present")
View Source
var ErrorNotFound = errors.New("not found error")
View Source
var ErrorUnkonwCommand = errors.New("unkonw command")
Functions ¶
func DoAccept ¶
DoAccept starts the accept phase sending an accept request to all the Paxos peers including itself
func DoPrepare ¶
DoPrepare可以确定index位置的值 这里的value格式为 [SET key value]或者[DELETE key] 如果成功提交当前value,返回true,否则返回false
func GenerateProposalNum ¶
GenerateProposalNum Generates a proposal number out of minProposalNum and Server ID
func GetPeerNameList ¶
func GetPeerNameList() []string
GetPeerNameList Obtains Peer List From Environment Variable
func GetServerID ¶
func GetServerID() int
func InitAcceptor ¶
func InitAcceptor()
func InitProposerNetwork ¶
func InitProposerNetwork()
func ProposerHandleRequst ¶
func ProposerHandleRequst()
func SendAcceptRequestAndWaitForReply ¶
func SendAcceptRequestAndWaitForReply(req *AcceptRequest, done chan struct{}) chan *AcceptResponse
func SendLearnRequest ¶
func SendLearnRequest(req *LearnRequest)
func SendPrepareRequestAndWaitForReply ¶
func SendPrepareRequestAndWaitForReply(req *PrepareRequest, done chan struct{}) chan *PrepareResponse
func SetBatcher ¶
func StartNewInstance ¶
Prepare starts a Paxos round sending a prepare request to all the Paxos peers including itself 这里发起proposal,直到自己提议的value被chosen,具体的数据传输在doPrepare中完成 oper取值范围为SET DELETE NOP
Types ¶
type AcceptRequest ¶
type AcceptResponse ¶
type AcceptResponse struct {
MinProposal int
}
type Acceptor ¶
type Acceptor struct { }
func GetAcceptorInstance ¶
func GetAcceptorInstance() *Acceptor
func (*Acceptor) OnAccept ¶
func (acceptor *Acceptor) OnAccept(req *AcceptRequest, resp *AcceptResponse) error
OnAccept return minProposal
func (*Acceptor) OnLearn ¶
func (acceptor *Acceptor) OnLearn(req *LearnRequest, resp *LearnResponse) error
func (*Acceptor) OnPrepare ¶
func (acceptor *Acceptor) OnPrepare(req *PrepareRequest, resp *PrepareResponse) error
OnPrepare return acceptedProposal and acceptedValue
type BatchRequest ¶
type BatchRequest struct { Reqs []Request Done chan struct{} }
type Batcher ¶
type Batcher struct { Out chan BatchRequest In chan Request // contains filtered or unexported fields }
func GetBatcherInstance ¶
func GetBatcherInstance() *Batcher
type LearnRequest ¶
type LearnResponse ¶
type LearnResponse struct { }
type LevelDB ¶
type LevelDB struct {
// contains filtered or unexported fields
}
func NewLevelDB ¶
type MyComparator ¶
type MyComparator struct { }
func (MyComparator) Compare ¶
func (cmp MyComparator) Compare(a, b []byte) int
func (MyComparator) Name ¶
func (cmp MyComparator) Name() string
func (MyComparator) Separator ¶
func (cmp MyComparator) Separator(dst, a, b []byte) []byte
func (MyComparator) Successor ¶
func (cmp MyComparator) Successor(dst, b []byte) []byte
type PrepareRequest ¶
type PrepareResponse ¶
Click to show internal directories.
Click to hide internal directories.