-
Notifications
You must be signed in to change notification settings - Fork 292
CP-28406: improve logging and error checking in clustering functions #3614
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
Merged
minishrink
merged 3 commits into
xapi-project:feature/REQ477/master
from
edwintorok:debugging
Jun 7, 2018
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -50,7 +50,7 @@ let call_api_function_with_alert ~__context ~msg ~cls ~obj_uuid ~body | |
|
||
(* Create xapi db object for cluster_host, resync_host calls clusterd *) | ||
let create_internal ~__context ~cluster ~host ~pIF : API.ref_Cluster_host = | ||
with_clustering_lock (fun () -> | ||
with_clustering_lock __LOC__ (fun () -> | ||
assert_operation_host_target_is_localhost ~__context ~host; | ||
assert_pif_attached_to ~host ~pIF ~__context; | ||
assert_cluster_host_can_be_created ~__context ~host; | ||
|
@@ -63,7 +63,7 @@ let create_internal ~__context ~cluster ~host ~pIF : API.ref_Cluster_host = | |
|
||
(* Helper function atomically enables clusterd and joins the cluster_host *) | ||
let join_internal ~__context ~self = | ||
with_clustering_lock (fun () -> | ||
with_clustering_lock __LOC__ (fun () -> | ||
|
||
let pIF = Db.Cluster_host.get_PIF ~__context ~self in | ||
fix_pif_prerequisites ~__context pIF; | ||
|
@@ -127,43 +127,39 @@ let create ~__context ~cluster ~host ~pif = | |
resync_host ~__context ~host; | ||
cluster_host | ||
|
||
let destroy_op ~__context ~self meth = | ||
with_clustering_lock __LOC__ (fun () -> | ||
let dbg = Context.string_of_task __context in | ||
let host = Db.Cluster_host.get_host ~__context ~self in | ||
assert_operation_host_target_is_localhost ~__context ~host; | ||
assert_cluster_host_has_no_attached_sr_which_requires_cluster_stack ~__context ~self; | ||
let result = Cluster_client.LocalClient.destroy (rpc ~__context) dbg in | ||
match result with | ||
| Result.Ok () -> | ||
Db.Cluster_host.destroy ~__context ~self; | ||
debug "Cluster_host.%s was successful" meth; | ||
Xapi_clustering.Daemon.disable ~__context | ||
| Result.Error error -> | ||
warn "Error occurred during Cluster_host.%s" meth; | ||
handle_error error) | ||
|
||
let force_destroy ~__context ~self = | ||
let dbg = Context.string_of_task __context in | ||
let host = Db.Cluster_host.get_host ~__context ~self in | ||
assert_operation_host_target_is_localhost ~__context ~host; | ||
assert_cluster_host_has_no_attached_sr_which_requires_cluster_stack ~__context ~self; | ||
let result = Cluster_client.LocalClient.destroy (rpc ~__context) dbg in | ||
match result with | ||
| Result.Ok () -> | ||
Db.Cluster_host.destroy ~__context ~self; | ||
debug "Cluster_host.force_destroy was successful"; | ||
Xapi_clustering.Daemon.disable ~__context | ||
| Result.Error error -> | ||
warn "Error occurred during Cluster_host.force_destroy"; | ||
handle_error error | ||
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. Also nicely done! |
||
destroy_op ~__context ~self "force_destroy" | ||
|
||
let destroy ~__context ~self = | ||
let dbg = Context.string_of_task __context in | ||
let host = Db.Cluster_host.get_host ~__context ~self in | ||
assert_operation_host_target_is_localhost ~__context ~host; | ||
assert_cluster_host_has_no_attached_sr_which_requires_cluster_stack ~__context ~self; | ||
assert_cluster_host_enabled ~__context ~self ~expected:true; | ||
let result = Cluster_client.LocalClient.leave (rpc ~__context) dbg in | ||
match result with | ||
(* can't include refs in case those were successfully destroyed *) | ||
| Result.Ok () -> | ||
Db.Cluster_host.destroy ~__context ~self; | ||
debug "Cluster_host.destroy was successful"; | ||
Xapi_clustering.Daemon.disable ~__context | ||
| Result.Error error -> | ||
warn "Error occurred during Cluster_host.destroy"; | ||
handle_error error | ||
|
||
let cluster = Db.Cluster_host.get_cluster ~__context ~self in | ||
let () = match Db.Cluster.get_cluster_hosts ~__context ~self:cluster with | ||
| [ _ ] -> | ||
raise Api_errors.(Server_error (cluster_does_not_have_one_node, ["1"])) | ||
| _ -> () | ||
in | ||
destroy_op ~__context ~self "destroy" | ||
|
||
let ip_of_str str = Cluster_interface.IPv4 str | ||
|
||
let forget ~__context ~self = | ||
with_clustering_lock (fun () -> | ||
with_clustering_lock __LOC__ (fun () -> | ||
let dbg = Context.string_of_task __context in | ||
let cluster = Db.Cluster_host.get_cluster ~__context ~self in | ||
let pif = Db.Cluster_host.get_PIF ~__context ~self in | ||
|
@@ -187,7 +183,7 @@ let forget ~__context ~self = | |
) | ||
|
||
let enable ~__context ~self = | ||
with_clustering_lock (fun () -> | ||
with_clustering_lock __LOC__ (fun () -> | ||
let dbg = Context.string_of_task __context in | ||
let host = Db.Cluster_host.get_host ~__context ~self in | ||
assert_operation_host_target_is_localhost ~__context ~host; | ||
|
@@ -213,7 +209,7 @@ let enable ~__context ~self = | |
) | ||
|
||
let disable ~__context ~self = | ||
with_clustering_lock (fun () -> | ||
with_clustering_lock __LOC__ (fun () -> | ||
let dbg = Context.string_of_task __context in | ||
let host = Db.Cluster_host.get_host ~__context ~self in | ||
assert_operation_host_target_is_localhost ~__context ~host; | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
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.
This is good, we were unnecessarily duplicating code.