From dbed2d1edeee1e87478d1b4b1887c078fcae9a9a Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Mon, 11 Nov 2019 18:03:14 +0100 Subject: [PATCH] More scaffolding for latency in diagnostics --- .../CDB_FederatedServerDiagnostics.sql | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/scripts-available/CDB_FederatedServerDiagnostics.sql b/scripts-available/CDB_FederatedServerDiagnostics.sql index 49388c5..2ba9092 100644 --- a/scripts-available/CDB_FederatedServerDiagnostics.sql +++ b/scripts-available/CDB_FederatedServerDiagnostics.sql @@ -97,14 +97,57 @@ AS $$ $$ LANGUAGE SQL VOLATILE PARALLEL UNSAFE; + +-- +-- Get a foreign PG server hostname from the catalog +-- +CREATE OR REPLACE FUNCTION @extschema@.__CDB_FS_Foreign_Server_Host_PG(server_internal name) +RETURNS text +AS $$ +BEGIN + -- TODO: implement + RETURN 'localhost'; +END +$$ +LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE; + + +-- +-- Get a foreign PG server port from the catalog +-- +CREATE OR REPLACE FUNCTION @extschema@.__CDB_FS_Foreign_Server_Port_PG(server_internal name) +RETURNS integer +AS $$ +BEGIN + -- TODO: implement + RETURN 5432; +END +$$ +LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE; + +-- +-- Get one measure of network latency to a remote TCP server +CREATE OR REPLACE FUNCTION @extschema@.__CDB_FS_TCP_Network_Latency(host text, port integer) +RETURNS float +AS $$ + #--TODO implement + return 0.0 +$$ +LANGUAGE plpythonu VOLATILE PARALLEL UNSAFE; + -- -- Get the network latency to a remote PG server -- CREATE OR REPLACE FUNCTION @extschema@.__CDB_FS_Foreign_Server_Latency_PG(server_internal name) RETURNS float AS $$ +DECLARE + remote_server_host text := @extschema@.__CDB_FS_Foreign_Server_Host_PG(server_internal); + remote_server_port integer := @extschema@.__CDB_FS_Foreign_Server_Port_PG(server_internal); -- TODO: best type for ports + latency float; BEGIN - RETURN 0.0; + latency := @extschema@.__CDB_FS_TCP_Network_Latency(host => remote_server_host, port => remote_server_port); + RETURN latency; END $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE;