server

package
v0.0.0-...-3680e65 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2017 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LEADER    = 0
	FOLLOWER  = 1
	CANDIDATE = 2
	OBSERVER  = 3
)
View Source
const (
	NODE_JOIN  = 0
	REG_NODE   = 1
	NEW_CLIENT = 2
	NEW_GROUP  = 3
)
View Source
const (
	LOG_ENTRIES    = 0
	GROUP_PEERS    = 1
	GROUP_META     = 2
	HOST_LIST      = 3
	GROUP_LAST_IDX = 4
	SERVER_CONF    = 100
)
View Source
const (
	HOST_LIST_GROUP = 1
	CONFIG_GROUP    = 0
)

Variables

This section is empty.

Functions

func AppendLogEntrySignData

func AppendLogEntrySignData(groupId uint64, term uint64, prevIndex uint64, prevTerm uint64) []byte

func ApproveAppendSignData

func ApproveAppendSignData(res *pb.ApproveAppendResponse) []byte

func ComposeKeyPrefix

func ComposeKeyPrefix(group uint64, t uint32) []byte

func EB

func EB(b bool) byte

func GetConfig

func GetConfig(kv *badger.DB) (*pb.ServerConfig, error)

func GetGroupFromKV

func GetGroupFromKV(txn *badger.Txn, groupId uint64) *pb.RaftGroup

func GetGroupPeersFromKV

func GetGroupPeersFromKV(txn *badger.Txn, group uint64) map[uint64]*pb.Peer

func GetMembersSignData

func GetMembersSignData(members []*pb.GroupMember) []byte

func InitDatabase

func InitDatabase(dbPath string)

func InvitationSignature

func InvitationSignature(inv *pb.GroupInvitation) []byte

func ItemValue

func ItemValue(item *badger.Item) *[]byte

func LogEntryFromKVItem

func LogEntryFromKVItem(item *badger.Item) *pb.LogEntry

func LogEntryKey

func LogEntryKey(groupId uint64, entryIndex uint64) []byte

func RandomTimeout

func RandomTimeout(mult float32) int

func RequestVoteRequestSignData

func RequestVoteRequestSignData(req *pb.RequestVoteRequest) []byte

func RequestVoteResponseSignData

func RequestVoteResponseSignData(res *pb.RequestVoteResponse) []byte

Types

type BFTRaftServer

type BFTRaftServer struct {
	Id   uint64
	Opts Options
	DB   *badger.DB
	// first 10 is reserved for the alpha group
	FuncReg          map[uint64]func(arg *[]byte, entry *pb.LogEntry) []byte
	GroupsOnboard    cmap.ConcurrentMap
	GroupInvitations map[uint64]chan *pb.GroupInvitation
	PendingNewGroups map[uint64]chan error
	Groups           *cache.Cache
	Hosts            *cache.Cache
	NodePublicKeys   *cache.Cache
	ClientPublicKeys *cache.Cache
	Client           *client.BFTRaftClient
	PrivateKey       *rsa.PrivateKey
	ClientRPCs       ClientStore
	// contains filtered or unexported fields
}

func GetServer

func GetServer(serverOpts Options) (*BFTRaftServer, error)

func (*BFTRaftServer) AppendEntries

func (*BFTRaftServer) ApproveAppend

func (*BFTRaftServer) ColdStart

func (s *BFTRaftServer) ColdStart()

func (*BFTRaftServer) ExecCommand

func (s *BFTRaftServer) ExecCommand(ctx context.Context, cmd *pb.CommandRequest) (*pb.CommandResponse, error)

func (*BFTRaftServer) GetGroup

func (s *BFTRaftServer) GetGroup(txn *badger.Txn, groupId uint64) *pb.RaftGroup

func (*BFTRaftServer) GetGroupContent

func (s *BFTRaftServer) GetGroupContent(ctx context.Context, req *pb.GroupId) (*pb.RaftGroup, error)

func (*BFTRaftServer) GetGroupHosts

func (s *BFTRaftServer) GetGroupHosts(txn *badger.Txn, groupId uint64) []*pb.Host

func (*BFTRaftServer) GetGroupHostsNTXN

func (s *BFTRaftServer) GetGroupHostsNTXN(groupId uint64) []*pb.Host

func (*BFTRaftServer) GetGroupLeader

func (s *BFTRaftServer) GetGroupLeader(ctx context.Context, req *pb.GroupId) (*pb.GroupLeader, error)

func (*BFTRaftServer) GetGroupNTXN

func (s *BFTRaftServer) GetGroupNTXN(groupId uint64) *pb.RaftGroup

func (*BFTRaftServer) GetHost

func (s *BFTRaftServer) GetHost(txn *badger.Txn, nodeId uint64) *pb.Host

func (*BFTRaftServer) GetHostNTXN

func (s *BFTRaftServer) GetHostNTXN(nodeId uint64) *pb.Host

func (*BFTRaftServer) GetHostPublicKey

func (s *BFTRaftServer) GetHostPublicKey(nodeId uint64) *rsa.PublicKey

func (*BFTRaftServer) GetOnboardGroup

func (s *BFTRaftServer) GetOnboardGroup(id uint64) *RTGroup

func (*BFTRaftServer) GroupHosts

func (s *BFTRaftServer) GroupHosts(ctx context.Context, request *pb.GroupId) (*pb.GroupNodesResponse, error)

func (*BFTRaftServer) GroupLeader

func (s *BFTRaftServer) GroupLeader(groupId uint64) *pb.GroupLeader

func (*BFTRaftServer) GroupMembers

func (s *BFTRaftServer) GroupMembers(ctx context.Context, req *pb.GroupId) (*pb.GroupMembersResponse, error)

this function should be called only on group members

func (*BFTRaftServer) NewGroup

func (s *BFTRaftServer) NewGroup(group *pb.RaftGroup) error

func (*BFTRaftServer) NodeJoin

func (s *BFTRaftServer) NodeJoin(groupId uint64) error

func (*BFTRaftServer) PeerApprovedAppend

func (s *BFTRaftServer) PeerApprovedAppend(groupId uint64, logIndex uint64, peer uint64, group_peers []*pb.Peer, isApproved bool)

func (*BFTRaftServer) PullGroupLogs

func (s *BFTRaftServer) PullGroupLogs(ctx context.Context, req *pb.PullGroupLogsResuest) (*pb.LogEntries, error)

TODO: Signature

func (*BFTRaftServer) RegHost

func (s *BFTRaftServer) RegHost() error

func (*BFTRaftServer) RegisterMembershipCommands

func (s *BFTRaftServer) RegisterMembershipCommands()

func (*BFTRaftServer) RegisterRaftFunc

func (s *BFTRaftServer) RegisterRaftFunc(func_id uint64, fn func(arg *[]byte, entry *pb.LogEntry) []byte)

func (*BFTRaftServer) RequestVote

func (*BFTRaftServer) SMNewClient

func (s *BFTRaftServer) SMNewClient(arg *[]byte, entry *pb.LogEntry) []byte

func (*BFTRaftServer) SMNewGroup

func (s *BFTRaftServer) SMNewGroup(arg *[]byte, entry *pb.LogEntry) []byte

func (*BFTRaftServer) SMNodeJoin

func (s *BFTRaftServer) SMNodeJoin(arg *[]byte, entry *pb.LogEntry) []byte

func (*BFTRaftServer) SMRegHost

func (s *BFTRaftServer) SMRegHost(arg *[]byte, entry *pb.LogEntry) []byte

Register a node into the network The node may be new or it was rejoined with new address

func (*BFTRaftServer) SaveGroup

func (s *BFTRaftServer) SaveGroup(txn *badger.Txn, group *pb.RaftGroup) error

func (*BFTRaftServer) SaveGroupNTXN

func (s *BFTRaftServer) SaveGroupNTXN(group *pb.RaftGroup) error

func (*BFTRaftServer) SaveHost

func (s *BFTRaftServer) SaveHost(txn *badger.Txn, node *pb.Host) error

func (*BFTRaftServer) SaveHostNTXN

func (s *BFTRaftServer) SaveHostNTXN(node *pb.Host) error

func (*BFTRaftServer) SavePeer

func (s *BFTRaftServer) SavePeer(txn *badger.Txn, peer *pb.Peer) error

func (*BFTRaftServer) ScanHostedGroups

func (s *BFTRaftServer) ScanHostedGroups(serverId uint64) map[uint64]*RTGroup

func (*BFTRaftServer) SendGroupInvitation

func (s *BFTRaftServer) SendGroupInvitation(ctx context.Context, inv *pb.GroupInvitation) (*pb.Nothing, error)

func (*BFTRaftServer) SetOnboardGroup

func (s *BFTRaftServer) SetOnboardGroup(meta *RTGroup)

func (*BFTRaftServer) Sign

func (s *BFTRaftServer) Sign(data []byte) []byte

func (*BFTRaftServer) StartServer

func (s *BFTRaftServer) StartServer() error

func (*BFTRaftServer) SyncAlphaGroup

func (s *BFTRaftServer) SyncAlphaGroup()

func (*BFTRaftServer) VerifyCommandSign

func (s *BFTRaftServer) VerifyCommandSign(cmd *pb.CommandRequest) bool

type Client

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

type ClientStore

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

func NewClientStore

func NewClientStore() ClientStore

func (*ClientStore) Get

func (cs *ClientStore) Get(serverAddr string) (*Client, error)

type FileConfig

type FileConfig struct {
	Db         string
	Address    string
	Bootstraps []string
}

func ReadConfigFile

func ReadConfigFile(path string) FileConfig

type LogEntryIterator

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

func (*LogEntryIterator) Close

func (liter *LogEntryIterator) Close()

func (*LogEntryIterator) Current

func (liter *LogEntryIterator) Current() *pb.LogEntry

func (*LogEntryIterator) Next

func (liter *LogEntryIterator) Next() *pb.LogEntry

type NodeIterator

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

type Options

type Options struct {
	DBPath           string
	Address          string
	Bootstrap        []string
	ConsensusTimeout time.Duration
}

type RTGroup

type RTGroup struct {
	Server            *BFTRaftServer
	Leader            uint64
	LastVotedTo       uint64
	LastVotedTerm     uint64
	GroupPeers        map[uint64]*pb.Peer
	Group             *pb.RaftGroup
	Timeout           time.Time
	Role              int
	Votes             []*pb.RequestVoteResponse
	SendVotesForPeers map[uint64]bool // key is peer id
	IsBusy            *abool.AtomicBool
	Lock              recmutex.RecursiveMutex
	VoteLock          sync.Mutex
}

func NewRTGroup

func NewRTGroup(
	server *BFTRaftServer,
	leader uint64,
	groupPeers map[uint64]*pb.Peer,
	group *pb.RaftGroup, role int,
) *RTGroup

func (*RTGroup) AppendEntries

func (m *RTGroup) AppendEntries(ctx context.Context, req *pb.AppendEntriesRequest) (*pb.AppendEntriesResponse, error)

func (*RTGroup) AppendEntryToLocal

func (m *RTGroup) AppendEntryToLocal(txn *badger.Txn, entry *pb.LogEntry) error

func (*RTGroup) ApproveAppend

func (m *RTGroup) ApproveAppend(ctx context.Context, req *pb.AppendEntriesResponse) (*pb.ApproveAppendResponse, error)

func (*RTGroup) BecomeCandidate

func (m *RTGroup) BecomeCandidate()

func (*RTGroup) BecomeFollower

func (m *RTGroup) BecomeFollower(appendEntryReq *pb.AppendEntriesRequest) bool

func (*RTGroup) BecomeLeader

func (m *RTGroup) BecomeLeader()

func (*RTGroup) CommitGroupLog

func (m *RTGroup) CommitGroupLog(entry *pb.LogEntry) *[]byte

func (*RTGroup) ExpectedHonestPeers

func (m *RTGroup) ExpectedHonestPeers() int

func (*RTGroup) GetLogEntry

func (m *RTGroup) GetLogEntry(txn *badger.Txn, entryIndex uint64) *pb.LogEntry

func (*RTGroup) LastEntryHash

func (m *RTGroup) LastEntryHash(txn *badger.Txn) []byte

func (*RTGroup) LastEntryHashNTXN

func (m *RTGroup) LastEntryHashNTXN() []byte

func (*RTGroup) LastEntryIndex

func (m *RTGroup) LastEntryIndex(txn *badger.Txn) uint64

func (*RTGroup) LastEntryIndexNTXN

func (m *RTGroup) LastEntryIndexNTXN() uint64

func (*RTGroup) LastLogEntry

func (m *RTGroup) LastLogEntry(txn *badger.Txn) *pb.LogEntry

func (*RTGroup) LastLogEntryNTXN

func (m *RTGroup) LastLogEntryNTXN() *pb.LogEntry

func (*RTGroup) OnboardGroupPeersSlice

func (m *RTGroup) OnboardGroupPeersSlice() []*pb.Peer

func (*RTGroup) PeerUncommittedLogEntries

func (m *RTGroup) PeerUncommittedLogEntries(peer *pb.Peer) ([]*pb.LogEntry, *pb.LogEntry)

func (*RTGroup) PullAndCommitGroupLogs

func (m *RTGroup) PullAndCommitGroupLogs()

func (*RTGroup) RPCGroupMembers

func (m *RTGroup) RPCGroupMembers(ctx context.Context, req *pb.GroupId) (*pb.GroupMembersResponse, error)

func (*RTGroup) RefreshTimer

func (m *RTGroup) RefreshTimer(mult float32)

func (*RTGroup) RequestVote

func (m *RTGroup) RequestVote(ctx context.Context, req *pb.RequestVoteRequest) (*pb.RequestVoteResponse, error)

func (*RTGroup) ResetTerm

func (m *RTGroup) ResetTerm(term uint64)

func (*RTGroup) ReversedLogIterator

func (m *RTGroup) ReversedLogIterator(txn *badger.Txn) LogEntryIterator

func (*RTGroup) SendFollowersHeartbeat

func (m *RTGroup) SendFollowersHeartbeat(ctx context.Context)

func (*RTGroup) SetLogAppended

func (m *RTGroup) SetLogAppended(groupId uint64, logIndex uint64, isApproved bool)

func (*RTGroup) StartTimeWheel

func (m *RTGroup) StartTimeWheel()

func (*RTGroup) WaitLogApproved

func (m *RTGroup) WaitLogApproved(logIndex uint64) bool

Jump to

Keyboard shortcuts

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