@@ -402,6 +402,11 @@ module TraceHelper = struct
402
402
Tracing_propagator.Propagator.Http. inject_into trace_context
403
403
end
404
404
405
+ (* * Once the server functor has been instantiated, xapi sets this reference to the appropriate
406
+ "fake_rpc" (loopback non-HTTP) rpc function.
407
+ This way, internally the coordinator can short-circuit API calls without having to go over the network. *)
408
+ let rpc_fun : (Http.Request.t -> Rpc.call -> Rpc.response) option ref = ref None
409
+
405
410
(* Note that both this and `make_timeboxed_rpc` are almost always
406
411
* partially applied, returning a function of type 'Rpc.request -> Rpc.response'.
407
412
* The body is therefore not evaluated until the RPC call is actually being
@@ -418,18 +423,22 @@ let make_rpc ~__context rpc : Rpc.response =
418
423
in
419
424
let http = xmlrpc ~subtask_of ~version: " 1.1" path in
420
425
let http = TraceHelper. inject_span_into_req tracing http in
421
- let transport =
422
- if Pool_role. is_master () then
423
- Unix Xapi_globs. unix_domain_socket
424
- else
425
- SSL
426
- ( SSL. make ~use_stunnel_cache: true ~verify_cert: (Stunnel_client. pool () )
427
- ()
428
- , Pool_role. get_master_address ()
429
- , ! Constants. https_port
430
- )
431
- in
432
- dorpc ~srcstr: " xapi" ~dststr: " xapi" ~transport ~http rpc
426
+ match ! rpc_fun with
427
+ | Some rpcfun when Pool_role. is_master () ->
428
+ rpcfun http rpc
429
+ | _ ->
430
+ let transport =
431
+ if Pool_role. is_master () then
432
+ Unix Xapi_globs. unix_domain_socket
433
+ else
434
+ SSL
435
+ ( SSL. make ~use_stunnel_cache: true
436
+ ~verify_cert: (Stunnel_client. pool () ) ()
437
+ , Pool_role. get_master_address ()
438
+ , ! Constants. https_port
439
+ )
440
+ in
441
+ dorpc ~srcstr: " xapi" ~dststr: " xapi" ~transport ~http rpc
433
442
434
443
let make_timeboxed_rpc ~__context timeout rpc : Rpc.response =
435
444
let subtask_of = Ref. string_of (Context. get_task_id __context) in
0 commit comments