picker_policy.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2018 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 picker
  15. import "fmt"
  16. // Policy defines balancer picker policy.
  17. type Policy uint8
  18. const (
  19. // TODO: custom picker is not supported yet.
  20. // custom defines custom balancer picker.
  21. custom Policy = iota
  22. // RoundrobinBalanced balance loads over multiple endpoints
  23. // and implements failover in roundrobin fashion.
  24. RoundrobinBalanced Policy = iota
  25. // TODO: only send loads to pinned address "RoundrobinFailover"
  26. // just like how 3.3 client works
  27. //
  28. // TODO: priotize leader
  29. // TODO: health-check
  30. // TODO: weighted roundrobin
  31. // TODO: power of two random choice
  32. )
  33. func (p Policy) String() string {
  34. switch p {
  35. case custom:
  36. panic("'custom' picker policy is not supported yet")
  37. case RoundrobinBalanced:
  38. return "etcd-client-roundrobin-balanced"
  39. default:
  40. panic(fmt.Errorf("invalid balancer picker policy (%d)", p))
  41. }
  42. }