-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[coordinator] [query] Add readiness probe for probing current consistency level achievability #2976
Merged
+662
−31
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fa58b98
[coordinator] [query] Add readiness probe
robskillington 68bf454
Add readiness probe test
robskillington a253785
Fix lint
robskillington 35c913e
Update src/query/api/v1/handler/ready.go
robskillington 773b997
Reuse shard available check in connect code
robskillington d8d55f5
Merge branch 'master' into r/add-readiness-probe
robskillington 2d49b6b
Fix tests
robskillington cdaf69e
Merge branch 'r/add-readiness-probe' of github.com:m3db/m3 into r/add…
robskillington f3e53ba
Fix ready handler
robskillington 269215f
Fix lint
robskillington File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -683,8 +683,6 @@ func (s *session) hostQueues( | |||||||||||||
newQueues = append(newQueues, newQueue) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
shards := topoMap.ShardSet().AllIDs() | ||||||||||||||
minConnectionCount := s.opts.MinConnectionCount() | ||||||||||||||
replicas := topoMap.Replicas() | ||||||||||||||
majority := topoMap.MajorityReplicas() | ||||||||||||||
|
||||||||||||||
|
@@ -731,35 +729,25 @@ func (s *session) hostQueues( | |||||||||||||
return nil, 0, 0, ErrClusterConnectTimeout | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
// Be optimistic | ||||||||||||||
clusterAvailable := true | ||||||||||||||
for _, shardID := range shards { | ||||||||||||||
shardReplicasAvailable := 0 | ||||||||||||||
routeErr := topoMap.RouteShardForEach(shardID, func(idx int, _ shard.Shard, _ topology.Host) { | ||||||||||||||
if queues[idx].ConnectionCount() >= minConnectionCount { | ||||||||||||||
shardReplicasAvailable++ | ||||||||||||||
} | ||||||||||||||
}) | ||||||||||||||
if routeErr != nil { | ||||||||||||||
return nil, 0, 0, routeErr | ||||||||||||||
} | ||||||||||||||
var clusterAvailableForShard bool | ||||||||||||||
switch connectConsistencyLevel { | ||||||||||||||
case topology.ConnectConsistencyLevelAll: | ||||||||||||||
clusterAvailableForShard = shardReplicasAvailable == replicas | ||||||||||||||
case topology.ConnectConsistencyLevelMajority: | ||||||||||||||
clusterAvailableForShard = shardReplicasAvailable >= majority | ||||||||||||||
case topology.ConnectConsistencyLevelOne: | ||||||||||||||
clusterAvailableForShard = shardReplicasAvailable > 0 | ||||||||||||||
default: | ||||||||||||||
return nil, 0, 0, errSessionInvalidConnectClusterConnectConsistencyLevel | ||||||||||||||
} | ||||||||||||||
if !clusterAvailableForShard { | ||||||||||||||
clusterAvailable = false | ||||||||||||||
break | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
var level topology.ConsistencyLevel | ||||||||||||||
switch connectConsistencyLevel { | ||||||||||||||
case topology.ConnectConsistencyLevelAll: | ||||||||||||||
level = topology.ConsistencyLevelAll | ||||||||||||||
case topology.ConnectConsistencyLevelMajority: | ||||||||||||||
level = topology.ConsistencyLevelMajority | ||||||||||||||
case topology.ConnectConsistencyLevelOne: | ||||||||||||||
level = topology.ConsistencyLevelOne | ||||||||||||||
default: | ||||||||||||||
return nil, 0, 0, errSessionInvalidConnectClusterConnectConsistencyLevel | ||||||||||||||
} | ||||||||||||||
if clusterAvailable { // All done | ||||||||||||||
clusterAvailable, err := s.clusterAvailabilityWithQueuesAndMap(level, | ||||||||||||||
queues, topoMap) | ||||||||||||||
if err != nil { | ||||||||||||||
return nil, 0, 0, err | ||||||||||||||
} | ||||||||||||||
if clusterAvailable { | ||||||||||||||
// All done | ||||||||||||||
break | ||||||||||||||
} | ||||||||||||||
time.Sleep(clusterConnectWaitInterval) | ||||||||||||||
|
@@ -769,6 +757,86 @@ func (s *session) hostQueues( | |||||||||||||
return queues, replicas, majority, nil | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
func (s *session) WriteClusterAvailability() (bool, error) { | ||||||||||||||
level := s.opts.WriteConsistencyLevel() | ||||||||||||||
return s.clusterAvailability(level) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
func (s *session) ReadClusterAvailability() (bool, error) { | ||||||||||||||
var convertedConsistencyLevel topology.ConsistencyLevel | ||||||||||||||
level := s.opts.ReadConsistencyLevel() | ||||||||||||||
switch level { | ||||||||||||||
case topology.ReadConsistencyLevelNone: | ||||||||||||||
// Already ready. | ||||||||||||||
return true, nil | ||||||||||||||
case topology.ReadConsistencyLevelOne: | ||||||||||||||
convertedConsistencyLevel = topology.ConsistencyLevelOne | ||||||||||||||
case topology.ReadConsistencyLevelUnstrictMajority: | ||||||||||||||
convertedConsistencyLevel = topology.ConsistencyLevelOne | ||||||||||||||
case topology.ReadConsistencyLevelMajority: | ||||||||||||||
convertedConsistencyLevel = topology.ConsistencyLevelMajority | ||||||||||||||
case topology.ReadConsistencyLevelUnstrictAll: | ||||||||||||||
convertedConsistencyLevel = topology.ConsistencyLevelOne | ||||||||||||||
case topology.ReadConsistencyLevelAll: | ||||||||||||||
convertedConsistencyLevel = topology.ConsistencyLevelAll | ||||||||||||||
default: | ||||||||||||||
return false, fmt.Errorf("unknown consistency level: %d", level) | ||||||||||||||
} | ||||||||||||||
return s.clusterAvailability(convertedConsistencyLevel) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
func (s *session) clusterAvailability( | ||||||||||||||
level topology.ConsistencyLevel, | ||||||||||||||
) (bool, error) { | ||||||||||||||
s.state.RLock() | ||||||||||||||
queues := s.state.queues | ||||||||||||||
topoMap, err := s.topologyMapWithStateRLock() | ||||||||||||||
s.state.RUnlock() | ||||||||||||||
if err != nil { | ||||||||||||||
return false, err | ||||||||||||||
} | ||||||||||||||
return s.clusterAvailabilityWithQueuesAndMap(level, queues, topoMap) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
func (s *session) clusterAvailabilityWithQueuesAndMap( | ||||||||||||||
level topology.ConsistencyLevel, | ||||||||||||||
queues []hostQueue, | ||||||||||||||
topoMap topology.Map, | ||||||||||||||
) (bool, error) { | ||||||||||||||
shards := topoMap.ShardSet().AllIDs() | ||||||||||||||
minConnectionCount := s.opts.MinConnectionCount() | ||||||||||||||
replicas := topoMap.Replicas() | ||||||||||||||
majority := topoMap.MajorityReplicas() | ||||||||||||||
|
||||||||||||||
for _, shardID := range shards { | ||||||||||||||
shardReplicasAvailable := 0 | ||||||||||||||
routeErr := topoMap.RouteShardForEach(shardID, func(idx int, _ shard.Shard, _ topology.Host) { | ||||||||||||||
if queues[idx].ConnectionCount() >= minConnectionCount { | ||||||||||||||
shardReplicasAvailable++ | ||||||||||||||
} | ||||||||||||||
}) | ||||||||||||||
if routeErr != nil { | ||||||||||||||
return false, routeErr | ||||||||||||||
} | ||||||||||||||
var clusterAvailableForShard bool | ||||||||||||||
switch level { | ||||||||||||||
case topology.ConsistencyLevelAll: | ||||||||||||||
clusterAvailableForShard = shardReplicasAvailable == replicas | ||||||||||||||
case topology.ConsistencyLevelMajority: | ||||||||||||||
clusterAvailableForShard = shardReplicasAvailable >= majority | ||||||||||||||
case topology.ConsistencyLevelOne: | ||||||||||||||
clusterAvailableForShard = shardReplicasAvailable > 0 | ||||||||||||||
default: | ||||||||||||||
return false, fmt.Errorf("unknown consistency level: %d", level) | ||||||||||||||
} | ||||||||||||||
if !clusterAvailableForShard { | ||||||||||||||
return false, nil | ||||||||||||||
} | ||||||||||||||
Comment on lines
+832
to
+834
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and then, this would simply be:
Suggested change
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return true, nil | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
func (s *session) setTopologyWithLock(topoMap topology.Map, queues []hostQueue, replicas, majority int) { | ||||||||||||||
prevQueues := s.state.queues | ||||||||||||||
|
||||||||||||||
|
@@ -1879,9 +1947,14 @@ func (s *session) Replicas() int { | |||||||||||||
|
||||||||||||||
func (s *session) TopologyMap() (topology.Map, error) { | ||||||||||||||
s.state.RLock() | ||||||||||||||
topoMap, err := s.topologyMapWithStateRLock() | ||||||||||||||
s.state.RUnlock() | ||||||||||||||
return topoMap, err | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
func (s *session) topologyMapWithStateRLock() (topology.Map, error) { | ||||||||||||||
status := s.state.status | ||||||||||||||
topoMap := s.state.topoMap | ||||||||||||||
s.state.RUnlock() | ||||||||||||||
|
||||||||||||||
// Make sure the session is open, as thats what sets the initial topology. | ||||||||||||||
if status != statusOpen { | ||||||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I would extract this
switch
out of the loop and computeminReplicasRequired
value in it (which would betopoMap.Replicas()
,topoMap.MajorityReplicas()
, or1
, respectively).(not for the sake of performance, but for brevity and reduced nesting)