NewOp constructs new Operation with given "healthy" states for operation, and optional function to extend replica set. Result of calling shouldExtendReplicaSet is cached.
(healthyStates []InstanceState, shouldExtendReplicaSet func(s InstanceState) bool)
| 1010 | // NewOp constructs new Operation with given "healthy" states for operation, and optional function to extend replica set. |
| 1011 | // Result of calling shouldExtendReplicaSet is cached. |
| 1012 | func NewOp(healthyStates []InstanceState, shouldExtendReplicaSet func(s InstanceState) bool) Operation { |
| 1013 | op := Operation(0) |
| 1014 | for _, s := range healthyStates { |
| 1015 | op |= (1 << s) |
| 1016 | } |
| 1017 | |
| 1018 | if shouldExtendReplicaSet != nil { |
| 1019 | for _, s := range []InstanceState{ACTIVE, LEAVING, PENDING, JOINING, LEFT, READONLY} { |
| 1020 | if shouldExtendReplicaSet(s) { |
| 1021 | op |= (0x10000 << s) |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | return op |
| 1027 | } |
| 1028 | |
| 1029 | // IsInstanceInStateHealthy is used during "filtering" phase to remove undesired instances based on their state. |
| 1030 | func (op Operation) IsInstanceInStateHealthy(s InstanceState) bool { |