-
Notifications
You must be signed in to change notification settings - Fork 284
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
CP-48676: Reuse pool sessions on slave logins #6258
base: master
Are you sure you want to change the base?
Conversation
Prevent this reusable pool session from being destroyed so that it remains valid. This feature can be toggled with the flag reuse-pool-sessions. This commit has been reworked to use Atomic instead of a mutex to prevent a deadlock as shown in CA-400339. Signed-off-by: Steven Woods <steven.woods@citrix.com>
Add a new flag validate-reusable-pool-session to xapi globs which skips the reusable pool session validity check if it is false. This saves time as we are no longer calling pool.get_all for each session. Signed-off-by: Steven Woods <steven.woods@citrix.com>
81c5fd5
to
f17fb1b
Compare
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.
Some minor style issues. The general approach seems quite sensible, even if a race can cause xapi to use more than one session (to avoid a loop when getting an invalid resusable session)
ignore (Client.Pool.get_all ~rpc ~session_id) ; | ||
true | ||
with Api_errors.Server_error (err, _) -> | ||
info "Invalid session: %s" err ; |
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 should be debug loglevel, or be removed
ocaml/xapi/xapi_session.ml
Outdated
in | ||
let rec get_session () = | ||
let session = Atomic.get reusable_pool_session in | ||
if session <> Ref.null && is_valid_session session then ( |
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.
I recommend changing this to
if session <> Ref.null && is_valid_session session then ( | |
if is_valid session then ( |
And add the null check to is_valid
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.
The issue is that in the next commit, where we only validate if validate_reusable_pool_session is true, we want to always do the null check but only do validation if the flag is set. We want to skip validation as it saves a lot of time.
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.
The validation can (and should) encapsulate all this logic
if session <> Ref.null && is_valid_session session then ( | ||
if | ||
session <> Ref.null | ||
&& ((not !Xapi_globs.validate_reusable_pool_session) |
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.
Please add the flag check to is_valid
as well
@@ -1065,6 +1065,10 @@ let pool_recommendations_dir = ref "/etc/xapi.pool-recommendations.d" | |||
|
|||
let disable_webserver = ref false | |||
|
|||
let reuse_pool_sessions = ref true |
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.
The comment from the PR could go here as a comment to document the semantics.
; ( "validate-reusable-pool-session" | ||
, Arg.Set validate_reusable_pool_session | ||
, (fun () -> string_of_bool !validate_reusable_pool_session) | ||
, "Enable the reuse of pool sessions" |
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.
The documentation is not accurate.
This was first introduced in #5986 but was later reverted as the mutex it introduced caused a deadlock with the DB mutex. This PR has now been reworked to use an Atomic variable, removing the need for the mutex.
This PR allows pool sessions to be reused (if the flag is turned on, which it is by default). This greatly speeds up communications between hosts which is important for repetitive calls e.g. one customer was running get_servertime frequently on all hosts in a pool which was causing problems due to the length of each call.
When we get this reusable session, we can optionally validate the session before using it but this increases the duration of the call, so this is off by default. Excepting a toolstack restart, the reusable session should always be valid as it is excluded from deletion in destroy_db_session