quorum.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // 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. package quorum
  15. import (
  16. "math"
  17. "strconv"
  18. )
  19. // Index is a Raft log position.
  20. type Index uint64
  21. func (i Index) String() string {
  22. if i == math.MaxUint64 {
  23. return "∞"
  24. }
  25. return strconv.FormatUint(uint64(i), 10)
  26. }
  27. // AckedIndexer allows looking up a commit index for a given ID of a voter
  28. // from a corresponding MajorityConfig.
  29. type AckedIndexer interface {
  30. AckedIndex(voterID uint64) (idx Index, found bool)
  31. }
  32. type mapAckIndexer map[uint64]Index
  33. func (m mapAckIndexer) AckedIndex(id uint64) (Index, bool) {
  34. idx, ok := m[id]
  35. return idx, ok
  36. }
  37. // VoteResult indicates the outcome of a vote.
  38. //
  39. //go:generate stringer -type=VoteResult
  40. type VoteResult uint8
  41. const (
  42. // VotePending indicates that the decision of the vote depends on future
  43. // votes, i.e. neither "yes" or "no" has reached quorum yet.
  44. VotePending VoteResult = 1 + iota
  45. // VoteLost indicates that the quorum has voted "no".
  46. VoteLost
  47. // VoteWon indicates that the quorum has voted "yes".
  48. VoteWon
  49. )