core

package
v0.0.0-...-b23d9fe Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoEnoughQuorum = errors.New("no enough quorum")
	AcceptorBasePort  = 3333
)
View Source
var File_api_paxos_proto protoreflect.FileDescriptor

Functions

func RegisterPaxosKVServer

func RegisterPaxosKVServer(s *grpc.Server, srv PaxosKVServer)

func ServeAcceptors

func ServeAcceptors(acceptorIds []int64) []*grpc.Server

ServeAcceptors starts a gRPC server for every acceptor.

Types

type Acceptor

type Acceptor struct {

	// the last ballot number the instance knows of.
	LastBal *BallotNum `protobuf:"bytes,1,opt,name=lastBal,proto3" json:"lastBal,omitempty"`
	// the voted value by this Acceptor.
	Val *Value `protobuf:"bytes,2,opt,name=val,proto3" json:"val,omitempty"`
	// the ballot number the Acceptor voted it.
	VBal *BallotNum `protobuf:"bytes,3,opt,name=VBal,proto3" json:"VBal,omitempty"`
	// contains filtered or unexported fields
}

Acceptor is the state of an Acceptor and also serves as the reply of Prepare/Accept.

func (*Acceptor) Descriptor deprecated

func (*Acceptor) Descriptor() ([]byte, []int)

Deprecated: Use Acceptor.ProtoReflect.Descriptor instead.

func (*Acceptor) GetLastBal

func (x *Acceptor) GetLastBal() *BallotNum

func (*Acceptor) GetVBal

func (x *Acceptor) GetVBal() *BallotNum

func (*Acceptor) GetVal

func (x *Acceptor) GetVal() *Value

func (*Acceptor) ProtoMessage

func (*Acceptor) ProtoMessage()

func (*Acceptor) ProtoReflect

func (x *Acceptor) ProtoReflect() protoreflect.Message

func (*Acceptor) Reset

func (x *Acceptor) Reset()

func (*Acceptor) String

func (x *Acceptor) String() string

type BallotNum

type BallotNum struct {
	N          int64 `protobuf:"varint,1,opt,name=N,proto3" json:"N,omitempty"`
	ProposerId int64 `protobuf:"varint,2,opt,name=ProposerId,proto3" json:"ProposerId,omitempty"`
	// contains filtered or unexported fields
}

BallotNum is the ballot number in paxos. It consists of a monotonically incremental number and a university unique ProposerId.

func (*BallotNum) Descriptor deprecated

func (*BallotNum) Descriptor() ([]byte, []int)

Deprecated: Use BallotNum.ProtoReflect.Descriptor instead.

func (*BallotNum) GE

func (a *BallotNum) GE(b *BallotNum) bool

GE compares the ballot number with another BallotNum.

func (*BallotNum) GetN

func (x *BallotNum) GetN() int64

func (*BallotNum) GetProposerId

func (x *BallotNum) GetProposerId() int64

func (*BallotNum) ProtoMessage

func (*BallotNum) ProtoMessage()

func (*BallotNum) ProtoReflect

func (x *BallotNum) ProtoReflect() protoreflect.Message

func (*BallotNum) Reset

func (x *BallotNum) Reset()

func (*BallotNum) String

func (x *BallotNum) String() string

type KVServer

type KVServer struct {
	Storage map[string]Versions
	// contains filtered or unexported fields
}

KVServer implements the paxos Acceptor API, handling Prepare and Accept request.

func (*KVServer) Accept

func (s *KVServer) Accept(c context.Context, r *Proposer) (*Acceptor, error)

Accept handles Accept request.

func (*KVServer) Prepare

func (s *KVServer) Prepare(c context.Context, r *Proposer) (*Acceptor, error)

Prepare handles Prepare request.

type PaxosInstanceId

type PaxosInstanceId struct {

	// the key of the record to operate on.
	Key string `protobuf:"bytes,1,opt,name=Key,proto3" json:"Key,omitempty"`
	// the version of the record to modify.
	Ver int64 `protobuf:"varint,2,opt,name=Ver,proto3" json:"Ver,omitempty"`
	// contains filtered or unexported fields
}

PaxosInstanceId specifies which paxos instance it runs on. A paxos instance is used to determine a specific version of a record.

func (*PaxosInstanceId) Descriptor deprecated

func (*PaxosInstanceId) Descriptor() ([]byte, []int)

Deprecated: Use PaxosInstanceId.ProtoReflect.Descriptor instead.

func (*PaxosInstanceId) GetKey

func (x *PaxosInstanceId) GetKey() string

func (*PaxosInstanceId) GetVer

func (x *PaxosInstanceId) GetVer() int64

func (*PaxosInstanceId) ProtoMessage

func (*PaxosInstanceId) ProtoMessage()

func (*PaxosInstanceId) ProtoReflect

func (x *PaxosInstanceId) ProtoReflect() protoreflect.Message

func (*PaxosInstanceId) Reset

func (x *PaxosInstanceId) Reset()

func (*PaxosInstanceId) String

func (x *PaxosInstanceId) String() string

type PaxosKVClient

type PaxosKVClient interface {
	Prepare(ctx context.Context, in *Proposer, opts ...grpc.CallOption) (*Acceptor, error)
	Accept(ctx context.Context, in *Proposer, opts ...grpc.CallOption) (*Acceptor, error)
}

PaxosKVClient is the client API for PaxosKV service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewPaxosKVClient

func NewPaxosKVClient(cc grpc.ClientConnInterface) PaxosKVClient

type PaxosKVServer

type PaxosKVServer interface {
	Prepare(context.Context, *Proposer) (*Acceptor, error)
	Accept(context.Context, *Proposer) (*Acceptor, error)
}

PaxosKVServer is the server API for PaxosKV service.

type Proposer

type Proposer struct {

	// which paxos instance it runs on.
	Id *PaxosInstanceId `protobuf:"bytes,1,opt,name=Id,proto3" json:"Id,omitempty"`
	// the ballot number of a Proposer.
	Bal *BallotNum `protobuf:"bytes,2,opt,name=Bal,proto3" json:"Bal,omitempty"`
	// the value of a Proposer has chosen.
	Val *Value `protobuf:"bytes,3,opt,name=Val,proto3" json:"Val,omitempty"`
	// contains filtered or unexported fields
}

Proposer is the state of a Proposer and also serves as the request of Prepare/Accept.

func (*Proposer) Descriptor deprecated

func (*Proposer) Descriptor() ([]byte, []int)

Deprecated: Use Proposer.ProtoReflect.Descriptor instead.

func (*Proposer) GetBal

func (x *Proposer) GetBal() *BallotNum

func (*Proposer) GetId

func (x *Proposer) GetId() *PaxosInstanceId

func (*Proposer) GetVal

func (x *Proposer) GetVal() *Value

func (*Proposer) Phase1

func (p *Proposer) Phase1(acceptorIds []int64, quorum int) (*Value, *BallotNum, error)

Phase1 runs paxos phase-1 on the specified acceptorIds. If a higher ballot number is seen and phase-1 failed to constitute a quorum, the highest ballot and a ErrNoEnoughQuorum will be returned.

func (*Proposer) Phase2

func (p *Proposer) Phase2(acceptorIds []int64, quorum int) (*BallotNum, error)

Phase2 runs paxos phase-2 on the specified acceptorIds. If a higher ballot number is seen and phase-1 failed to constitute a quorum, the highest ballot and a ErrNoEnoughQuorum will be returned.

func (*Proposer) ProtoMessage

func (*Proposer) ProtoMessage()

func (*Proposer) ProtoReflect

func (x *Proposer) ProtoReflect() protoreflect.Message

func (*Proposer) Reset

func (x *Proposer) Reset()

func (*Proposer) RunPaxos

func (p *Proposer) RunPaxos(acceptorIds []int64, val *Value) *Value

RunPaxos executes the paxos phase-1 and phase-2 to establish a value. It returns the established value, which may be a voted value that is not `val`.

If `val` is not nil, it acts as a writing operation. If `val` is nil, it acts as a reading operation.

func (*Proposer) String

func (x *Proposer) String() string

type UnimplementedPaxosKVServer

type UnimplementedPaxosKVServer struct {
}

UnimplementedPaxosKVServer can be embedded to have forward compatible implementations.

func (*UnimplementedPaxosKVServer) Accept

func (*UnimplementedPaxosKVServer) Prepare

type Value

type Value struct {
	Vi64 int64 `protobuf:"varint,1,opt,name=Vi64,proto3" json:"Vi64,omitempty"`
	// contains filtered or unexported fields
}

Value is the value part of a key-value record.

func (*Value) Descriptor deprecated

func (*Value) Descriptor() ([]byte, []int)

Deprecated: Use Value.ProtoReflect.Descriptor instead.

func (*Value) GetVi64

func (x *Value) GetVi64() int64

func (*Value) ProtoMessage

func (*Value) ProtoMessage()

func (*Value) ProtoReflect

func (x *Value) ProtoReflect() protoreflect.Message

func (*Value) Reset

func (x *Value) Reset()

func (*Value) String

func (x *Value) String() string

type Version

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

Version defines one modification of a key-value record.

type Versions

type Versions map[int64]*Version

Versions stores all version of a record.

Jump to

Keyboard shortcuts

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