blob: 2899e46c96dca3427174871b2e45e73e6096527a [file] [log] [blame]
Scott Baker8461e152019-10-01 14:44:30 -07001// Copyright 2019 The etcd Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package quorum
16
17import (
18 "math"
19 "strconv"
20)
21
22// Index is a Raft log position.
23type Index uint64
24
25func (i Index) String() string {
26 if i == math.MaxUint64 {
27 return "∞"
28 }
29 return strconv.FormatUint(uint64(i), 10)
30}
31
32// AckedIndexer allows looking up a commit index for a given ID of a voter
33// from a corresponding MajorityConfig.
34type AckedIndexer interface {
35 AckedIndex(voterID uint64) (idx Index, found bool)
36}
37
38type mapAckIndexer map[uint64]Index
39
40func (m mapAckIndexer) AckedIndex(id uint64) (Index, bool) {
41 idx, ok := m[id]
42 return idx, ok
43}
44
45// VoteResult indicates the outcome of a vote.
46//
47//go:generate stringer -type=VoteResult
48type VoteResult uint8
49
50const (
51 // VotePending indicates that the decision of the vote depends on future
52 // votes, i.e. neither "yes" or "no" has reached quorum yet.
53 VotePending VoteResult = 1 + iota
54 // VoteLost indicates that the quorum has voted "no".
55 VoteLost
56 // VoteWon indicates that the quorum has voted "yes".
57 VoteWon
58)