Rename citus stats tenants (#6821)

Rename some objects
`*citus_stats_tenants*` to `*citus_stat_tenants*`
`citus_stats_tenants*` and `citus_stat_tenants*` GUCs to `stat_tenants*`
`MultiTenantMonitoringLogLevel` to `CitusStatTenantsLogLevel`
`multi_tenant_monitoring_log_level` to `citus.stat_tenants_log_level`
`attribute` files to `citus_stat_tenants`
multi-tenant-monitoring-pgbench
Halil Ozan Akgül 2023-04-04 13:52:17 +03:00 committed by Halil Ozan Akgul
parent 2b7482ea0d
commit 14ad3eff54
30 changed files with 336 additions and 336 deletions

View File

@ -97,6 +97,7 @@
#include "distributed/relation_access_tracking.h" #include "distributed/relation_access_tracking.h"
#include "distributed/remote_commands.h" /* to access LogRemoteCommands */ #include "distributed/remote_commands.h" /* to access LogRemoteCommands */
#include "distributed/transaction_management.h" #include "distributed/transaction_management.h"
#include "distributed/utils/citus_stat_tenants.h"
#include "distributed/version_compat.h" #include "distributed/version_compat.h"
#include "distributed/worker_protocol.h" #include "distributed/worker_protocol.h"
#include "executor/tstoreReceiver.h" #include "executor/tstoreReceiver.h"
@ -104,7 +105,6 @@
#include "optimizer/optimizer.h" #include "optimizer/optimizer.h"
#include "nodes/params.h" #include "nodes/params.h"
#include "utils/snapmgr.h" #include "utils/snapmgr.h"
#include "distributed/utils/attribute.h"
/* controlled via a GUC */ /* controlled via a GUC */
bool EnableLocalExecution = true; bool EnableLocalExecution = true;

View File

@ -26,7 +26,7 @@
#include "distributed/multi_physical_planner.h" #include "distributed/multi_physical_planner.h"
#include "distributed/multi_router_planner.h" #include "distributed/multi_router_planner.h"
#include "distributed/shard_utils.h" #include "distributed/shard_utils.h"
#include "distributed/utils/attribute.h" #include "distributed/utils/citus_stat_tenants.h"
#include "distributed/version_compat.h" #include "distributed/version_compat.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"

View File

@ -49,7 +49,7 @@
#include "distributed/recursive_planning.h" #include "distributed/recursive_planning.h"
#include "distributed/shardinterval_utils.h" #include "distributed/shardinterval_utils.h"
#include "distributed/shard_utils.h" #include "distributed/shard_utils.h"
#include "distributed/utils/attribute.h" #include "distributed/utils/citus_stat_tenants.h"
#include "distributed/version_compat.h" #include "distributed/version_compat.h"
#include "distributed/worker_shard_visibility.h" #include "distributed/worker_shard_visibility.h"
#include "executor/executor.h" #include "executor/executor.h"

View File

@ -91,7 +91,7 @@
#include "distributed/resource_lock.h" #include "distributed/resource_lock.h"
#include "distributed/transaction_management.h" #include "distributed/transaction_management.h"
#include "distributed/transaction_recovery.h" #include "distributed/transaction_recovery.h"
#include "distributed/utils/attribute.h" #include "distributed/utils/citus_stat_tenants.h"
#include "distributed/utils/directory.h" #include "distributed/utils/directory.h"
#include "distributed/worker_log_messages.h" #include "distributed/worker_log_messages.h"
#include "distributed/worker_manager.h" #include "distributed/worker_manager.h"
@ -1990,16 +1990,6 @@ RegisterCitusConfigVariables(void)
GUC_STANDARD, GUC_STANDARD,
NULL, NULL, NULL); NULL, NULL, NULL);
DefineCustomEnumVariable(
"citus.multi_tenant_monitoring_log_level",
gettext_noop("Sets the level of multi tenant monitoring log messages"),
NULL,
&MultiTenantMonitoringLogLevel,
CITUS_LOG_LEVEL_OFF, log_level_options,
PGC_USERSET,
GUC_STANDARD,
NULL, NULL, NULL);
DefineCustomIntVariable( DefineCustomIntVariable(
"citus.next_cleanup_record_id", "citus.next_cleanup_record_id",
gettext_noop("Set the next cleanup record ID to use in operation creation."), gettext_noop("Set the next cleanup record ID to use in operation creation."),
@ -2384,6 +2374,37 @@ RegisterCitusConfigVariables(void)
GUC_STANDARD, GUC_STANDARD,
NULL, NULL, NULL); NULL, NULL, NULL);
DefineCustomIntVariable(
"citus.stat_tenants_limit",
gettext_noop("Number of tenants to be shown in citus_stat_tenants."),
NULL,
&StatTenantsLimit,
10, 1, 100,
PGC_POSTMASTER,
GUC_STANDARD,
NULL, NULL, NULL);
DefineCustomEnumVariable(
"citus.stat_tenants_log_level",
gettext_noop("Sets the level of citus_stat_tenants log messages"),
NULL,
&StatTenantsLogLevel,
CITUS_LOG_LEVEL_OFF, log_level_options,
PGC_USERSET,
GUC_STANDARD,
NULL, NULL, NULL);
DefineCustomIntVariable(
"citus.stat_tenants_period",
gettext_noop("Period in seconds to be used for calculating the tenant "
"statistics in citus_stat_tenants."),
NULL,
&StatTenantsPeriod,
60, 1, 1000000000,
PGC_USERSET,
GUC_STANDARD,
NULL, NULL, NULL);
DefineCustomEnumVariable( DefineCustomEnumVariable(
"citus.stat_tenants_track", "citus.stat_tenants_track",
gettext_noop("Enables/Disables the stats collection for citus_stat_tenants."), gettext_noop("Enables/Disables the stats collection for citus_stat_tenants."),
@ -2397,27 +2418,6 @@ RegisterCitusConfigVariables(void)
GUC_STANDARD, GUC_STANDARD,
NULL, NULL, NULL); NULL, NULL, NULL);
DefineCustomIntVariable(
"citus.stats_tenants_limit",
gettext_noop("Number of tenants to be shown in citus_stat_tenants."),
NULL,
&CitusStatsTenantsLimit,
10, 1, 100,
PGC_POSTMASTER,
GUC_STANDARD,
NULL, NULL, NULL);
DefineCustomIntVariable(
"citus.stats_tenants_period",
gettext_noop("Period in seconds to be used for calculating the tenant "
"statistics in citus_stat_tenants."),
NULL,
&CitusStatsTenantsPeriod,
60, 1, 1000000000,
PGC_USERSET,
GUC_STANDARD,
NULL, NULL, NULL);
DefineCustomBoolVariable( DefineCustomBoolVariable(
"citus.subquery_pushdown", "citus.subquery_pushdown",
gettext_noop("Usage of this GUC is highly discouraged, please read the long " gettext_noop("Usage of this GUC is highly discouraged, please read the long "

View File

@ -10,8 +10,8 @@ ALTER TABLE pg_catalog.pg_dist_transaction REPLICA IDENTITY USING INDEX pg_dist_
#include "udfs/worker_drop_all_shell_tables/11.3-1.sql" #include "udfs/worker_drop_all_shell_tables/11.3-1.sql"
#include "udfs/citus_internal_mark_node_not_synced/11.3-1.sql" #include "udfs/citus_internal_mark_node_not_synced/11.3-1.sql"
#include "udfs/citus_stats_tenants_local/11.3-1.sql" #include "udfs/citus_stat_tenants_local/11.3-1.sql"
#include "udfs/citus_stats_tenants/11.3-1.sql" #include "udfs/citus_stat_tenants/11.3-1.sql"
#include "udfs/citus_stats_tenants_local_reset/11.3-1.sql" #include "udfs/citus_stat_tenants_local_reset/11.3-1.sql"
#include "udfs/citus_stats_tenants_reset/11.3-1.sql" #include "udfs/citus_stat_tenants_reset/11.3-1.sql"

View File

@ -21,11 +21,11 @@ ALTER TABLE pg_catalog.pg_dist_transaction REPLICA IDENTITY NOTHING;
DROP PROCEDURE pg_catalog.worker_drop_all_shell_tables(bool); DROP PROCEDURE pg_catalog.worker_drop_all_shell_tables(bool);
DROP FUNCTION pg_catalog.citus_internal_mark_node_not_synced(int, int); DROP FUNCTION pg_catalog.citus_internal_mark_node_not_synced(int, int);
DROP VIEW pg_catalog.citus_stats_tenants_local; DROP VIEW pg_catalog.citus_stat_tenants_local;
DROP FUNCTION pg_catalog.citus_stats_tenants_local(boolean); DROP FUNCTION pg_catalog.citus_stat_tenants_local(boolean);
DROP VIEW pg_catalog.citus_stats_tenants; DROP VIEW pg_catalog.citus_stat_tenants;
DROP FUNCTION pg_catalog.citus_stats_tenants(boolean); DROP FUNCTION pg_catalog.citus_stat_tenants(boolean);
DROP FUNCTION pg_catalog.citus_stats_tenants_local_reset(); DROP FUNCTION pg_catalog.citus_stat_tenants_local_reset();
DROP FUNCTION pg_catalog.citus_stats_tenants_reset(); DROP FUNCTION pg_catalog.citus_stat_tenants_reset();

View File

@ -1,5 +1,5 @@
-- cts in the query is an abbreviation for citus_stats_tenants -- cts in the query is an abbreviation for citus_stat_tenants
CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants ( CREATE OR REPLACE FUNCTION pg_catalog.citus_stat_tenants (
return_all_tenants BOOLEAN DEFAULT FALSE, return_all_tenants BOOLEAN DEFAULT FALSE,
OUT nodeid INT, OUT nodeid INT,
OUT colocation_id INT, OUT colocation_id INT,
@ -18,9 +18,9 @@ BEGIN
array_position(enumvals, 'log') >= array_position(enumvals, setting) array_position(enumvals, 'log') >= array_position(enumvals, setting)
AND setting != 'off' AND setting != 'off'
FROM pg_settings FROM pg_settings
WHERE name = 'citus.multi_tenant_monitoring_log_level' WHERE name = 'citus.stat_tenants_log_level'
THEN THEN
RAISE LOG 'Generating citus_stats_tenants'; RAISE LOG 'Generating citus_stat_tenants';
END IF; END IF;
RETURN QUERY RETURN QUERY
SELECT * SELECT *
@ -36,7 +36,7 @@ BEGIN
$$ $$
SELECT SELECT
coalesce(to_jsonb (array_agg(cstl.*)), '[]'::jsonb) coalesce(to_jsonb (array_agg(cstl.*)), '[]'::jsonb)
FROM citus_stats_tenants_local($$||return_all_tenants||$$) cstl; FROM citus_stat_tenants_local($$||return_all_tenants||$$) cstl;
$$, $$,
parallel:= TRUE, parallel:= TRUE,
give_warning_for_connection_errors:= TRUE) give_warning_for_connection_errors:= TRUE)
@ -54,11 +54,11 @@ AS (
score BIGINT score BIGINT
) )
ORDER BY score DESC ORDER BY score DESC
LIMIT CASE WHEN NOT return_all_tenants THEN current_setting('citus.stats_tenants_limit')::BIGINT END; LIMIT CASE WHEN NOT return_all_tenants THEN current_setting('citus.stat_tenants_limit')::BIGINT END;
END; END;
$function$; $function$;
CREATE OR REPLACE VIEW citus.citus_stats_tenants AS CREATE OR REPLACE VIEW citus.citus_stat_tenants AS
SELECT SELECT
nodeid, nodeid,
colocation_id, colocation_id,
@ -67,12 +67,12 @@ SELECT
read_count_in_last_period, read_count_in_last_period,
query_count_in_this_period, query_count_in_this_period,
query_count_in_last_period query_count_in_last_period
FROM pg_catalog.citus_stats_tenants(FALSE); FROM pg_catalog.citus_stat_tenants(FALSE);
ALTER VIEW citus.citus_stats_tenants SET SCHEMA pg_catalog; ALTER VIEW citus.citus_stat_tenants SET SCHEMA pg_catalog;
REVOKE ALL ON FUNCTION pg_catalog.citus_stats_tenants(BOOLEAN) FROM PUBLIC; REVOKE ALL ON FUNCTION pg_catalog.citus_stat_tenants(BOOLEAN) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pg_catalog.citus_stats_tenants(BOOLEAN) TO pg_monitor; GRANT EXECUTE ON FUNCTION pg_catalog.citus_stat_tenants(BOOLEAN) TO pg_monitor;
REVOKE ALL ON pg_catalog.citus_stats_tenants FROM PUBLIC; REVOKE ALL ON pg_catalog.citus_stat_tenants FROM PUBLIC;
GRANT SELECT ON pg_catalog.citus_stats_tenants TO pg_monitor; GRANT SELECT ON pg_catalog.citus_stat_tenants TO pg_monitor;

View File

@ -1,5 +1,5 @@
-- cts in the query is an abbreviation for citus_stats_tenants -- cts in the query is an abbreviation for citus_stat_tenants
CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants ( CREATE OR REPLACE FUNCTION pg_catalog.citus_stat_tenants (
return_all_tenants BOOLEAN DEFAULT FALSE, return_all_tenants BOOLEAN DEFAULT FALSE,
OUT nodeid INT, OUT nodeid INT,
OUT colocation_id INT, OUT colocation_id INT,
@ -18,9 +18,9 @@ BEGIN
array_position(enumvals, 'log') >= array_position(enumvals, setting) array_position(enumvals, 'log') >= array_position(enumvals, setting)
AND setting != 'off' AND setting != 'off'
FROM pg_settings FROM pg_settings
WHERE name = 'citus.multi_tenant_monitoring_log_level' WHERE name = 'citus.stat_tenants_log_level'
THEN THEN
RAISE LOG 'Generating citus_stats_tenants'; RAISE LOG 'Generating citus_stat_tenants';
END IF; END IF;
RETURN QUERY RETURN QUERY
SELECT * SELECT *
@ -36,7 +36,7 @@ BEGIN
$$ $$
SELECT SELECT
coalesce(to_jsonb (array_agg(cstl.*)), '[]'::jsonb) coalesce(to_jsonb (array_agg(cstl.*)), '[]'::jsonb)
FROM citus_stats_tenants_local($$||return_all_tenants||$$) cstl; FROM citus_stat_tenants_local($$||return_all_tenants||$$) cstl;
$$, $$,
parallel:= TRUE, parallel:= TRUE,
give_warning_for_connection_errors:= TRUE) give_warning_for_connection_errors:= TRUE)
@ -54,11 +54,11 @@ AS (
score BIGINT score BIGINT
) )
ORDER BY score DESC ORDER BY score DESC
LIMIT CASE WHEN NOT return_all_tenants THEN current_setting('citus.stats_tenants_limit')::BIGINT END; LIMIT CASE WHEN NOT return_all_tenants THEN current_setting('citus.stat_tenants_limit')::BIGINT END;
END; END;
$function$; $function$;
CREATE OR REPLACE VIEW citus.citus_stats_tenants AS CREATE OR REPLACE VIEW citus.citus_stat_tenants AS
SELECT SELECT
nodeid, nodeid,
colocation_id, colocation_id,
@ -67,12 +67,12 @@ SELECT
read_count_in_last_period, read_count_in_last_period,
query_count_in_this_period, query_count_in_this_period,
query_count_in_last_period query_count_in_last_period
FROM pg_catalog.citus_stats_tenants(FALSE); FROM pg_catalog.citus_stat_tenants(FALSE);
ALTER VIEW citus.citus_stats_tenants SET SCHEMA pg_catalog; ALTER VIEW citus.citus_stat_tenants SET SCHEMA pg_catalog;
REVOKE ALL ON FUNCTION pg_catalog.citus_stats_tenants(BOOLEAN) FROM PUBLIC; REVOKE ALL ON FUNCTION pg_catalog.citus_stat_tenants(BOOLEAN) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pg_catalog.citus_stats_tenants(BOOLEAN) TO pg_monitor; GRANT EXECUTE ON FUNCTION pg_catalog.citus_stat_tenants(BOOLEAN) TO pg_monitor;
REVOKE ALL ON pg_catalog.citus_stats_tenants FROM PUBLIC; REVOKE ALL ON pg_catalog.citus_stat_tenants FROM PUBLIC;
GRANT SELECT ON pg_catalog.citus_stats_tenants TO pg_monitor; GRANT SELECT ON pg_catalog.citus_stat_tenants TO pg_monitor;

View File

@ -0,0 +1,32 @@
CREATE OR REPLACE FUNCTION pg_catalog.citus_stat_tenants_local(
return_all_tenants BOOLEAN DEFAULT FALSE,
OUT colocation_id INT,
OUT tenant_attribute TEXT,
OUT read_count_in_this_period INT,
OUT read_count_in_last_period INT,
OUT query_count_in_this_period INT,
OUT query_count_in_last_period INT,
OUT score BIGINT)
RETURNS SETOF RECORD
LANGUAGE C
AS 'citus', $$citus_stat_tenants_local$$;
CREATE OR REPLACE VIEW citus.citus_stat_tenants_local AS
SELECT
colocation_id,
tenant_attribute,
read_count_in_this_period,
read_count_in_last_period,
query_count_in_this_period,
query_count_in_last_period
FROM pg_catalog.citus_stat_tenants_local()
ORDER BY score DESC;
ALTER VIEW citus.citus_stat_tenants_local SET SCHEMA pg_catalog;
REVOKE ALL ON FUNCTION pg_catalog.citus_stat_tenants_local(BOOLEAN) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pg_catalog.citus_stat_tenants_local(BOOLEAN) TO pg_monitor;
REVOKE ALL ON pg_catalog.citus_stat_tenants_local FROM PUBLIC;
GRANT SELECT ON pg_catalog.citus_stat_tenants_local TO pg_monitor;

View File

@ -0,0 +1,32 @@
CREATE OR REPLACE FUNCTION pg_catalog.citus_stat_tenants_local(
return_all_tenants BOOLEAN DEFAULT FALSE,
OUT colocation_id INT,
OUT tenant_attribute TEXT,
OUT read_count_in_this_period INT,
OUT read_count_in_last_period INT,
OUT query_count_in_this_period INT,
OUT query_count_in_last_period INT,
OUT score BIGINT)
RETURNS SETOF RECORD
LANGUAGE C
AS 'citus', $$citus_stat_tenants_local$$;
CREATE OR REPLACE VIEW citus.citus_stat_tenants_local AS
SELECT
colocation_id,
tenant_attribute,
read_count_in_this_period,
read_count_in_last_period,
query_count_in_this_period,
query_count_in_last_period
FROM pg_catalog.citus_stat_tenants_local()
ORDER BY score DESC;
ALTER VIEW citus.citus_stat_tenants_local SET SCHEMA pg_catalog;
REVOKE ALL ON FUNCTION pg_catalog.citus_stat_tenants_local(BOOLEAN) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pg_catalog.citus_stat_tenants_local(BOOLEAN) TO pg_monitor;
REVOKE ALL ON pg_catalog.citus_stat_tenants_local FROM PUBLIC;
GRANT SELECT ON pg_catalog.citus_stat_tenants_local TO pg_monitor;

View File

@ -0,0 +1,7 @@
CREATE OR REPLACE FUNCTION pg_catalog.citus_stat_tenants_local_reset()
RETURNS VOID
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$citus_stat_tenants_local_reset$$;
COMMENT ON FUNCTION pg_catalog.citus_stat_tenants_local_reset()
IS 'resets the local tenant statistics';

View File

@ -0,0 +1,7 @@
CREATE OR REPLACE FUNCTION pg_catalog.citus_stat_tenants_local_reset()
RETURNS VOID
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$citus_stat_tenants_local_reset$$;
COMMENT ON FUNCTION pg_catalog.citus_stat_tenants_local_reset()
IS 'resets the local tenant statistics';

View File

@ -0,0 +1,8 @@
CREATE OR REPLACE FUNCTION pg_catalog.citus_stat_tenants_reset()
RETURNS VOID
LANGUAGE plpgsql
AS $function$
BEGIN
PERFORM run_command_on_all_nodes($$SELECT citus_stat_tenants_local_reset()$$);
END;
$function$;

View File

@ -0,0 +1,8 @@
CREATE OR REPLACE FUNCTION pg_catalog.citus_stat_tenants_reset()
RETURNS VOID
LANGUAGE plpgsql
AS $function$
BEGIN
PERFORM run_command_on_all_nodes($$SELECT citus_stat_tenants_local_reset()$$);
END;
$function$;

View File

@ -1,32 +0,0 @@
CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants_local(
return_all_tenants BOOLEAN DEFAULT FALSE,
OUT colocation_id INT,
OUT tenant_attribute TEXT,
OUT read_count_in_this_period INT,
OUT read_count_in_last_period INT,
OUT query_count_in_this_period INT,
OUT query_count_in_last_period INT,
OUT score BIGINT)
RETURNS SETOF RECORD
LANGUAGE C
AS 'citus', $$citus_stats_tenants_local$$;
CREATE OR REPLACE VIEW citus.citus_stats_tenants_local AS
SELECT
colocation_id,
tenant_attribute,
read_count_in_this_period,
read_count_in_last_period,
query_count_in_this_period,
query_count_in_last_period
FROM pg_catalog.citus_stats_tenants_local()
ORDER BY score DESC;
ALTER VIEW citus.citus_stats_tenants_local SET SCHEMA pg_catalog;
REVOKE ALL ON FUNCTION pg_catalog.citus_stats_tenants_local(BOOLEAN) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pg_catalog.citus_stats_tenants_local(BOOLEAN) TO pg_monitor;
REVOKE ALL ON pg_catalog.citus_stats_tenants_local FROM PUBLIC;
GRANT SELECT ON pg_catalog.citus_stats_tenants_local TO pg_monitor;

View File

@ -1,32 +0,0 @@
CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants_local(
return_all_tenants BOOLEAN DEFAULT FALSE,
OUT colocation_id INT,
OUT tenant_attribute TEXT,
OUT read_count_in_this_period INT,
OUT read_count_in_last_period INT,
OUT query_count_in_this_period INT,
OUT query_count_in_last_period INT,
OUT score BIGINT)
RETURNS SETOF RECORD
LANGUAGE C
AS 'citus', $$citus_stats_tenants_local$$;
CREATE OR REPLACE VIEW citus.citus_stats_tenants_local AS
SELECT
colocation_id,
tenant_attribute,
read_count_in_this_period,
read_count_in_last_period,
query_count_in_this_period,
query_count_in_last_period
FROM pg_catalog.citus_stats_tenants_local()
ORDER BY score DESC;
ALTER VIEW citus.citus_stats_tenants_local SET SCHEMA pg_catalog;
REVOKE ALL ON FUNCTION pg_catalog.citus_stats_tenants_local(BOOLEAN) FROM PUBLIC;
GRANT EXECUTE ON FUNCTION pg_catalog.citus_stats_tenants_local(BOOLEAN) TO pg_monitor;
REVOKE ALL ON pg_catalog.citus_stats_tenants_local FROM PUBLIC;
GRANT SELECT ON pg_catalog.citus_stats_tenants_local TO pg_monitor;

View File

@ -1,7 +0,0 @@
CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants_local_reset()
RETURNS VOID
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$citus_stats_tenants_local_reset$$;
COMMENT ON FUNCTION pg_catalog.citus_stats_tenants_local_reset()
IS 'resets the local tenant statistics';

View File

@ -1,7 +0,0 @@
CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants_local_reset()
RETURNS VOID
LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$citus_stats_tenants_local_reset$$;
COMMENT ON FUNCTION pg_catalog.citus_stats_tenants_local_reset()
IS 'resets the local tenant statistics';

View File

@ -1,8 +0,0 @@
CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants_reset()
RETURNS VOID
LANGUAGE plpgsql
AS $function$
BEGIN
PERFORM run_command_on_all_nodes($$SELECT citus_stats_tenants_local_reset()$$);
END;
$function$;

View File

@ -1,8 +0,0 @@
CREATE OR REPLACE FUNCTION pg_catalog.citus_stats_tenants_reset()
RETURNS VOID
LANGUAGE plpgsql
AS $function$
BEGIN
PERFORM run_command_on_all_nodes($$SELECT citus_stats_tenants_local_reset()$$);
END;
$function$;

View File

@ -2,7 +2,7 @@
* *
* citus_stat_tenants.c * citus_stat_tenants.c
* *
* This file contains functions to test citus_stats_tenants. * This file contains functions to test citus_stat_tenants.
* *
* Copyright (c) Citus Data, Inc. * Copyright (c) Citus Data, Inc.
* *
@ -12,7 +12,7 @@
#include "postgres.h" #include "postgres.h"
#include "fmgr.h" #include "fmgr.h"
#include "distributed/utils/attribute.h" #include "distributed/utils/citus_stat_tenants.h"
#include "sys/time.h" #include "sys/time.h"
PG_FUNCTION_INFO_V1(sleep_until_next_period); PG_FUNCTION_INFO_V1(sleep_until_next_period);
@ -27,8 +27,8 @@ sleep_until_next_period(PG_FUNCTION_ARGS)
gettimeofday(&currentTime, NULL); gettimeofday(&currentTime, NULL);
long int nextPeriodStart = currentTime.tv_sec - long int nextPeriodStart = currentTime.tv_sec -
(currentTime.tv_sec % CitusStatsTenantsPeriod) + (currentTime.tv_sec % StatTenantsPeriod) +
CitusStatsTenantsPeriod; StatTenantsPeriod;
long int sleepTime = (nextPeriodStart - currentTime.tv_sec) * 1000000 - long int sleepTime = (nextPeriodStart - currentTime.tv_sec) * 1000000 -
currentTime.tv_usec + 100000; currentTime.tv_usec + 100000;

View File

@ -1,6 +1,6 @@
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* attribute.c * citus_stat_tenants.c
* Routines related to the multi tenant monitor. * Routines related to the multi tenant monitor.
* *
* Copyright (c) Citus Data, Inc. * Copyright (c) Citus Data, Inc.
@ -19,6 +19,7 @@
#include "distributed/colocation_utils.h" #include "distributed/colocation_utils.h"
#include "distributed/tuplestore.h" #include "distributed/tuplestore.h"
#include "distributed/colocation_utils.h" #include "distributed/colocation_utils.h"
#include "distributed/utils/citus_stat_tenants.h"
#include "executor/execdesc.h" #include "executor/execdesc.h"
#include "storage/ipc.h" #include "storage/ipc.h"
#include "storage/lwlock.h" #include "storage/lwlock.h"
@ -27,7 +28,6 @@
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/datetime.h" #include "utils/datetime.h"
#include "utils/json.h" #include "utils/json.h"
#include "distributed/utils/attribute.h"
#include <time.h> #include <time.h>
@ -38,7 +38,7 @@ ExecutorEnd_hook_type prev_ExecutorEnd = NULL;
#define ATTRIBUTE_PREFIX "/*{\"tId\":" #define ATTRIBUTE_PREFIX "/*{\"tId\":"
#define ATTRIBUTE_STRING_FORMAT "/*{\"tId\":%s,\"cId\":%d}*/" #define ATTRIBUTE_STRING_FORMAT "/*{\"tId\":%s,\"cId\":%d}*/"
#define CITUS_STATS_TENANTS_COLUMNS 7 #define STAT_TENANTS_COLUMNS 7
#define ONE_QUERY_SCORE 1000000000 #define ONE_QUERY_SCORE 1000000000
/* TODO maybe needs to be a stack */ /* TODO maybe needs to be a stack */
@ -70,28 +70,28 @@ static char * ExtractTopComment(const char *inputString);
static char * EscapeCommentChars(const char *str); static char * EscapeCommentChars(const char *str);
static char * UnescapeCommentChars(const char *str); static char * UnescapeCommentChars(const char *str);
int MultiTenantMonitoringLogLevel = CITUS_LOG_LEVEL_OFF; int StatTenantsLogLevel = CITUS_LOG_LEVEL_OFF;
int CitusStatsTenantsPeriod = (time_t) 60; int StatTenantsPeriod = (time_t) 60;
int CitusStatsTenantsLimit = 10; int StatTenantsLimit = 10;
int StatTenantsTrack = STAT_TENANTS_TRACK_ALL; int StatTenantsTrack = STAT_TENANTS_TRACK_ALL;
PG_FUNCTION_INFO_V1(citus_stats_tenants_local); PG_FUNCTION_INFO_V1(citus_stat_tenants_local);
PG_FUNCTION_INFO_V1(citus_stats_tenants_local_reset); PG_FUNCTION_INFO_V1(citus_stat_tenants_local_reset);
/* /*
* citus_stats_tenants_local finds, updates and returns the statistics for tenants. * citus_stat_tenants_local finds, updates and returns the statistics for tenants.
*/ */
Datum Datum
citus_stats_tenants_local(PG_FUNCTION_ARGS) citus_stat_tenants_local(PG_FUNCTION_ARGS)
{ {
CheckCitusVersion(ERROR); CheckCitusVersion(ERROR);
/* /*
* We keep more than CitusStatsTenantsLimit tenants in our monitor. * We keep more than StatTenantsLimit tenants in our monitor.
* We do this to not lose data if a tenant falls out of top CitusStatsTenantsLimit in case they need to return soon. * We do this to not lose data if a tenant falls out of top StatTenantsLimit in case they need to return soon.
* Normally we return CitusStatsTenantsLimit tenants but if returnAllTenants is true we return all of them. * Normally we return StatTenantsLimit tenants but if returnAllTenants is true we return all of them.
*/ */
bool returnAllTenants = PG_GETARG_BOOL(0); bool returnAllTenants = PG_GETARG_BOOL(0);
@ -99,8 +99,8 @@ citus_stats_tenants_local(PG_FUNCTION_ARGS)
Tuplestorestate *tupleStore = SetupTuplestore(fcinfo, &tupleDescriptor); Tuplestorestate *tupleStore = SetupTuplestore(fcinfo, &tupleDescriptor);
TimestampTz monitoringTime = GetCurrentTimestamp(); TimestampTz monitoringTime = GetCurrentTimestamp();
Datum values[CITUS_STATS_TENANTS_COLUMNS]; Datum values[STAT_TENANTS_COLUMNS];
bool isNulls[CITUS_STATS_TENANTS_COLUMNS]; bool isNulls[STAT_TENANTS_COLUMNS];
MultiTenantMonitor *monitor = GetMultiTenantMonitor(); MultiTenantMonitor *monitor = GetMultiTenantMonitor();
@ -118,7 +118,7 @@ citus_stats_tenants_local(PG_FUNCTION_ARGS)
} }
else else
{ {
numberOfRowsToReturn = Min(monitor->tenantCount, CitusStatsTenantsLimit); numberOfRowsToReturn = Min(monitor->tenantCount, StatTenantsLimit);
} }
for (int tenantIndex = 0; tenantIndex < monitor->tenantCount; tenantIndex++) for (int tenantIndex = 0; tenantIndex < monitor->tenantCount; tenantIndex++)
@ -156,11 +156,11 @@ citus_stats_tenants_local(PG_FUNCTION_ARGS)
/* /*
* citus_stats_tenants_local_reset resets monitor for tenant statistics * citus_stat_tenants_local_reset resets monitor for tenant statistics
* on the local node. * on the local node.
*/ */
Datum Datum
citus_stats_tenants_local_reset(PG_FUNCTION_ARGS) citus_stat_tenants_local_reset(PG_FUNCTION_ARGS)
{ {
MultiTenantMonitor *monitor = GetMultiTenantMonitor(); MultiTenantMonitor *monitor = GetMultiTenantMonitor();
monitor->tenantCount = 0; monitor->tenantCount = 0;
@ -397,7 +397,7 @@ AttributeMetricsIfApplicable()
static void static void
UpdatePeriodsIfNecessary(TenantStats *tenantStats, TimestampTz queryTime) UpdatePeriodsIfNecessary(TenantStats *tenantStats, TimestampTz queryTime)
{ {
long long int periodInMicroSeconds = CitusStatsTenantsPeriod * USECS_PER_SEC; long long int periodInMicroSeconds = StatTenantsPeriod * USECS_PER_SEC;
TimestampTz periodStart = queryTime - (queryTime % periodInMicroSeconds); TimestampTz periodStart = queryTime - (queryTime % periodInMicroSeconds);
/* /*
@ -438,7 +438,7 @@ UpdatePeriodsIfNecessary(TenantStats *tenantStats, TimestampTz queryTime)
static void static void
ReduceScoreIfNecessary(TenantStats *tenantStats, TimestampTz queryTime) ReduceScoreIfNecessary(TenantStats *tenantStats, TimestampTz queryTime)
{ {
long long int periodInMicroSeconds = CitusStatsTenantsPeriod * USECS_PER_SEC; long long int periodInMicroSeconds = StatTenantsPeriod * USECS_PER_SEC;
TimestampTz periodStart = queryTime - (queryTime % periodInMicroSeconds); TimestampTz periodStart = queryTime - (queryTime % periodInMicroSeconds);
/* /*
@ -475,7 +475,7 @@ ReduceScoreIfNecessary(TenantStats *tenantStats, TimestampTz queryTime)
/* /*
* EvictTenantsIfNecessary sorts and evicts the tenants if the tenant count is more than or * EvictTenantsIfNecessary sorts and evicts the tenants if the tenant count is more than or
* equal to 3 * CitusStatsTenantsLimit. * equal to 3 * StatTenantsLimit.
*/ */
static void static void
EvictTenantsIfNecessary(TimestampTz queryTime) EvictTenantsIfNecessary(TimestampTz queryTime)
@ -483,12 +483,12 @@ EvictTenantsIfNecessary(TimestampTz queryTime)
MultiTenantMonitor *monitor = GetMultiTenantMonitor(); MultiTenantMonitor *monitor = GetMultiTenantMonitor();
/* /*
* We keep up to CitusStatsTenantsLimit * 3 tenants instead of CitusStatsTenantsLimit, * We keep up to StatTenantsLimit * 3 tenants instead of StatTenantsLimit,
* so we don't lose data immediately after a tenant is out of top CitusStatsTenantsLimit * so we don't lose data immediately after a tenant is out of top StatTenantsLimit
* *
* Every time tenant count hits CitusStatsTenantsLimit * 3, we reduce it back to CitusStatsTenantsLimit * 2. * Every time tenant count hits StatTenantsLimit * 3, we reduce it back to StatTenantsLimit * 2.
*/ */
if (monitor->tenantCount >= CitusStatsTenantsLimit * 3) if (monitor->tenantCount >= StatTenantsLimit * 3)
{ {
for (int tenantIndex = 0; tenantIndex < monitor->tenantCount; tenantIndex++) for (int tenantIndex = 0; tenantIndex < monitor->tenantCount; tenantIndex++)
{ {
@ -496,7 +496,7 @@ EvictTenantsIfNecessary(TimestampTz queryTime)
} }
SafeQsort(monitor->tenants, monitor->tenantCount, sizeof(TenantStats), SafeQsort(monitor->tenants, monitor->tenantCount, sizeof(TenantStats),
CompareTenantScore); CompareTenantScore);
monitor->tenantCount = CitusStatsTenantsLimit * 2; monitor->tenantCount = StatTenantsLimit * 2;
} }
} }
@ -623,7 +623,7 @@ static int
CreateTenantStats(MultiTenantMonitor *monitor, TimestampTz queryTime) CreateTenantStats(MultiTenantMonitor *monitor, TimestampTz queryTime)
{ {
/* /*
* If the tenant count reached 3 * CitusStatsTenantsLimit, we evict the tenants * If the tenant count reached 3 * StatTenantsLimit, we evict the tenants
* with the lowest score. * with the lowest score.
*/ */
EvictTenantsIfNecessary(queryTime); EvictTenantsIfNecessary(queryTime);
@ -672,13 +672,13 @@ FindTenantStats(MultiTenantMonitor *monitor)
/* /*
* MultiTenantMonitorshmemSize calculates the size of the multi tenant monitor using * MultiTenantMonitorshmemSize calculates the size of the multi tenant monitor using
* CitusStatsTenantsLimit parameter. * StatTenantsLimit parameter.
*/ */
static size_t static size_t
MultiTenantMonitorshmemSize(void) MultiTenantMonitorshmemSize(void)
{ {
Size size = sizeof(MultiTenantMonitor); Size size = sizeof(MultiTenantMonitor);
size = add_size(size, mul_size(sizeof(TenantStats), CitusStatsTenantsLimit * 3)); size = add_size(size, mul_size(sizeof(TenantStats), StatTenantsLimit * 3));
return size; return size;
} }

View File

@ -1,6 +1,6 @@
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* *
* attribute.h * citus_stat_tenants.h
* Routines related to the multi tenant monitor. * Routines related to the multi tenant monitor.
* *
* Copyright (c) Citus Data, Inc. * Copyright (c) Citus Data, Inc.
@ -82,7 +82,7 @@ typedef struct MultiTenantMonitor
/* /*
* tenantCount is the number of items in the tenants array. * tenantCount is the number of items in the tenants array.
* The total length of tenants array is set up at CreateSharedMemoryForMultiTenantMonitor * The total length of tenants array is set up at CreateSharedMemoryForMultiTenantMonitor
* and is 3 * citus.stats_tenants_limit * and is 3 * citus.stat_tenants_limit
*/ */
int tenantCount; int tenantCount;
TenantStats tenants[FLEXIBLE_ARRAY_MEMBER]; TenantStats tenants[FLEXIBLE_ARRAY_MEMBER];
@ -103,9 +103,9 @@ extern void AttributeTask(char *tenantId, int colocationGroupId, CmdType command
extern ExecutorEnd_hook_type prev_ExecutorEnd; extern ExecutorEnd_hook_type prev_ExecutorEnd;
extern int MultiTenantMonitoringLogLevel; extern int StatTenantsLogLevel;
extern int CitusStatsTenantsPeriod; extern int StatTenantsPeriod;
extern int CitusStatsTenantsLimit; extern int StatTenantsLimit;
extern int StatTenantsTrack; extern int StatTenantsTrack;
#endif /*CITUS_ATTRIBUTE_H */ #endif /*CITUS_ATTRIBUTE_H */

View File

@ -1,19 +1,19 @@
CREATE SCHEMA citus_stats_tenants; CREATE SCHEMA citus_stat_tenants;
SET search_path TO citus_stats_tenants; SET search_path TO citus_stat_tenants;
SET citus.next_shard_id TO 5797500; SET citus.next_shard_id TO 5797500;
SET citus.shard_replication_factor TO 1; SET citus.shard_replication_factor TO 1;
CREATE OR REPLACE FUNCTION pg_catalog.sleep_until_next_period() CREATE OR REPLACE FUNCTION pg_catalog.sleep_until_next_period()
RETURNS VOID RETURNS VOID
LANGUAGE C LANGUAGE C
AS 'citus', $$sleep_until_next_period$$; AS 'citus', $$sleep_until_next_period$$;
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
citus_stats_tenants_reset citus_stat_tenants_reset
--------------------------------------------------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
-- set period to a high number to prevent stats from being reset -- set period to a high number to prevent stats from being reset
SELECT result FROM run_command_on_all_nodes('ALTER SYSTEM SET citus.stats_tenants_period TO 1000000000'); SELECT result FROM run_command_on_all_nodes('ALTER SYSTEM SET citus.stat_tenants_period TO 1000000000');
result result
--------------------------------------------------------------------- ---------------------------------------------------------------------
ALTER SYSTEM ALTER SYSTEM
@ -62,7 +62,7 @@ INSERT INTO dist_tbl VALUES (2, 'abcd');
UPDATE dist_tbl SET b = a + 1 WHERE a = 3; UPDATE dist_tbl SET b = a + 1 WHERE a = 3;
UPDATE dist_tbl SET b = a + 1 WHERE a = 4; UPDATE dist_tbl SET b = a + 1 WHERE a = 4;
DELETE FROM dist_tbl WHERE a = 5; DELETE FROM dist_tbl WHERE a = 5;
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants(true) ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants(true) ORDER BY tenant_attribute;
tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 0 | 0 | 1 | 0 1 | 0 | 0 | 1 | 0
@ -72,8 +72,8 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q
5 | 0 | 0 | 1 | 0 5 | 0 | 0 | 1 | 0
(5 rows) (5 rows)
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
citus_stats_tenants_reset citus_stat_tenants_reset
--------------------------------------------------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
@ -92,7 +92,7 @@ SELECT count(*)>=0 FROM ref_tbl WHERE a = 1;
t t
(1 row) (1 row)
SELECT tenant_attribute, query_count_in_this_period FROM citus_stats_tenants(true) ORDER BY tenant_attribute; SELECT tenant_attribute, query_count_in_this_period FROM citus_stat_tenants(true) ORDER BY tenant_attribute;
tenant_attribute | query_count_in_this_period tenant_attribute | query_count_in_this_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
(0 rows) (0 rows)
@ -110,7 +110,7 @@ SELECT count(*)>=0 FROM dist_tbl JOIN dist_tbl_2 ON dist_tbl.a = dist_tbl_2.a WH
t t
(1 row) (1 row)
SELECT tenant_attribute, query_count_in_this_period FROM citus_stats_tenants(true) WHERE tenant_attribute = '1'; SELECT tenant_attribute, query_count_in_this_period FROM citus_stat_tenants(true) WHERE tenant_attribute = '1';
tenant_attribute | query_count_in_this_period tenant_attribute | query_count_in_this_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 2 1 | 2
@ -143,7 +143,7 @@ SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'abcd';
t t
(1 row) (1 row)
SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stats_tenants(true) WHERE nodeid = :worker_2_nodeid ORDER BY score DESC, tenant_attribute; SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stat_tenants(true) WHERE nodeid = :worker_2_nodeid ORDER BY score DESC, tenant_attribute;
tenant_attribute | query_count_in_this_period | score tenant_attribute | query_count_in_this_period | score
--------------------------------------------------------------------- ---------------------------------------------------------------------
2 | 1 | 1000000000 2 | 1 | 1000000000
@ -176,7 +176,7 @@ SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'cdef';
t t
(1 row) (1 row)
SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stats_tenants(true) WHERE nodeid = :worker_2_nodeid ORDER BY score DESC, tenant_attribute; SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stat_tenants(true) WHERE nodeid = :worker_2_nodeid ORDER BY score DESC, tenant_attribute;
tenant_attribute | query_count_in_this_period | score tenant_attribute | query_count_in_this_period | score
--------------------------------------------------------------------- ---------------------------------------------------------------------
abcd | 3 | 3000000000 abcd | 3 | 3000000000
@ -205,7 +205,7 @@ SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'defg';
t t
(1 row) (1 row)
SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stats_tenants(true) WHERE nodeid = :worker_2_nodeid ORDER BY score DESC, tenant_attribute; SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stat_tenants(true) WHERE nodeid = :worker_2_nodeid ORDER BY score DESC, tenant_attribute;
tenant_attribute | query_count_in_this_period | score tenant_attribute | query_count_in_this_period | score
--------------------------------------------------------------------- ---------------------------------------------------------------------
abcd | 3 | 3000000000 abcd | 3 | 3000000000
@ -218,8 +218,8 @@ SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stats_tena
(7 rows) (7 rows)
-- test period passing -- test period passing
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
citus_stats_tenants_reset citus_stat_tenants_reset
--------------------------------------------------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
@ -232,7 +232,7 @@ SELECT count(*)>=0 FROM dist_tbl WHERE a = 1;
INSERT INTO dist_tbl VALUES (5, 'abcd'); INSERT INTO dist_tbl VALUES (5, 'abcd');
\c - - - :worker_1_port \c - - - :worker_1_port
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants_local ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants_local ORDER BY tenant_attribute;
tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 1 | 0 | 1 | 0 1 | 1 | 0 | 1 | 0
@ -240,14 +240,14 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q
(2 rows) (2 rows)
-- simulate passing the period -- simulate passing the period
SET citus.stats_tenants_period TO 2; SET citus.stat_tenants_period TO 2;
SELECT sleep_until_next_period(); SELECT sleep_until_next_period();
sleep_until_next_period sleep_until_next_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants_local ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants_local ORDER BY tenant_attribute;
tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 0 | 1 | 0 | 1 1 | 0 | 1 | 0 | 1
@ -255,50 +255,50 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q
(2 rows) (2 rows)
\c - - - :master_port \c - - - :master_port
SET search_path TO citus_stats_tenants; SET search_path TO citus_stat_tenants;
-- test logs -- test logs
SET client_min_messages TO LOG; SET client_min_messages TO LOG;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
?column? ?column?
--------------------------------------------------------------------- ---------------------------------------------------------------------
t t
(1 row) (1 row)
SET citus.multi_tenant_monitoring_log_level TO ERROR; SET citus.stat_tenants_log_level TO ERROR;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
?column? ?column?
--------------------------------------------------------------------- ---------------------------------------------------------------------
t t
(1 row) (1 row)
SET citus.multi_tenant_monitoring_log_level TO OFF; SET citus.stat_tenants_log_level TO OFF;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
?column? ?column?
--------------------------------------------------------------------- ---------------------------------------------------------------------
t t
(1 row) (1 row)
SET citus.multi_tenant_monitoring_log_level TO LOG; SET citus.stat_tenants_log_level TO LOG;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
LOG: Generating citus_stats_tenants LOG: Generating citus_stat_tenants
CONTEXT: PL/pgSQL function citus_stats_tenants(boolean) line XX at RAISE CONTEXT: PL/pgSQL function citus_stat_tenants(boolean) line XX at RAISE
?column? ?column?
--------------------------------------------------------------------- ---------------------------------------------------------------------
t t
(1 row) (1 row)
SET citus.multi_tenant_monitoring_log_level TO DEBUG; SET citus.stat_tenants_log_level TO DEBUG;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
LOG: Generating citus_stats_tenants LOG: Generating citus_stat_tenants
CONTEXT: PL/pgSQL function citus_stats_tenants(boolean) line XX at RAISE CONTEXT: PL/pgSQL function citus_stat_tenants(boolean) line XX at RAISE
?column? ?column?
--------------------------------------------------------------------- ---------------------------------------------------------------------
t t
(1 row) (1 row)
RESET client_min_messages; RESET client_min_messages;
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
citus_stats_tenants_reset citus_stat_tenants_reset
--------------------------------------------------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
@ -312,13 +312,13 @@ SELECT count(*)>=0 FROM dist_tbl WHERE a = 1;
(1 row) (1 row)
INSERT INTO dist_tbl VALUES (1, 1); INSERT INTO dist_tbl VALUES (1, 1);
SELECT tenant_attribute, query_count_in_this_period FROM citus_stats_tenants; SELECT tenant_attribute, query_count_in_this_period FROM citus_stat_tenants;
tenant_attribute | query_count_in_this_period tenant_attribute | query_count_in_this_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
(0 rows) (0 rows)
SET citus.stat_tenants_track TO "ALL"; SET citus.stat_tenants_track TO "ALL";
SELECT tenant_attribute, query_count_in_this_period FROM citus_stats_tenants; SELECT tenant_attribute, query_count_in_this_period FROM citus_stat_tenants;
tenant_attribute | query_count_in_this_period tenant_attribute | query_count_in_this_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
(0 rows) (0 rows)
@ -330,15 +330,15 @@ SELECT count(*)>=0 FROM dist_tbl WHERE a = 1;
(1 row) (1 row)
INSERT INTO dist_tbl VALUES (1, 1); INSERT INTO dist_tbl VALUES (1, 1);
SELECT tenant_attribute, query_count_in_this_period FROM citus_stats_tenants; SELECT tenant_attribute, query_count_in_this_period FROM citus_stat_tenants;
tenant_attribute | query_count_in_this_period tenant_attribute | query_count_in_this_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
1 | 2 1 | 2
(1 row) (1 row)
-- test special and multibyte characters in tenant attribute -- test special and multibyte characters in tenant attribute
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
citus_stats_tenants_reset citus_stat_tenants_reset
--------------------------------------------------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
@ -405,7 +405,7 @@ SELECT count(*)>=0 FROM dist_tbl_text WHERE a = U&'\0061\0308bc';
(1 row) (1 row)
\c - - - :worker_1_port \c - - - :worker_1_port
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants ORDER BY tenant_attribute;
tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
/*bcde | 1 | 0 | 1 | 0 /*bcde | 1 | 0 | 1 | 0
@ -421,8 +421,8 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q
(10 rows) (10 rows)
\c - - - :worker_2_port \c - - - :worker_2_port
SET search_path TO citus_stats_tenants; SET search_path TO citus_stat_tenants;
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants ORDER BY tenant_attribute;
tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
/*bcde | 1 | 0 | 1 | 0 /*bcde | 1 | 0 | 1 | 0
@ -437,8 +437,8 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q
bcde*/ | 1 | 0 | 1 | 0 bcde*/ | 1 | 0 | 1 | 0
(10 rows) (10 rows)
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
citus_stats_tenants_reset citus_stat_tenants_reset
--------------------------------------------------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
@ -469,7 +469,7 @@ SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde*';
t t
(1 row) (1 row)
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants_local ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants_local ORDER BY tenant_attribute;
tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
/b*c/de | 1 | 0 | 1 | 0 /b*c/de | 1 | 0 | 1 | 0
@ -552,7 +552,7 @@ EXECUTE dist_tbl_text_select_plan('bcde*');
t t
(1 row) (1 row)
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants_local ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants_local ORDER BY tenant_attribute;
tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
/b*c/de | 4 | 0 | 4 | 0 /b*c/de | 4 | 0 | 4 | 0
@ -562,7 +562,7 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q
(4 rows) (4 rows)
\c - - - :master_port \c - - - :master_port
SET search_path TO citus_stats_tenants; SET search_path TO citus_stat_tenants;
PREPARE dist_tbl_text_select_plan (text) AS SELECT count(*)>=0 FROM dist_tbl_text WHERE a = $1; PREPARE dist_tbl_text_select_plan (text) AS SELECT count(*)>=0 FROM dist_tbl_text WHERE a = $1;
EXECUTE dist_tbl_text_select_plan('/b*c/de'); EXECUTE dist_tbl_text_select_plan('/b*c/de');
?column? ?column?
@ -637,8 +637,8 @@ EXECUTE dist_tbl_text_select_plan('bcde*');
(1 row) (1 row)
\c - - - :worker_2_port \c - - - :worker_2_port
SET search_path TO citus_stats_tenants; SET search_path TO citus_stat_tenants;
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants ORDER BY tenant_attribute;
tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
/b*c/de | 7 | 0 | 7 | 0 /b*c/de | 7 | 0 | 7 | 0
@ -648,9 +648,9 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q
(4 rows) (4 rows)
\c - - - :master_port \c - - - :master_port
SET search_path TO citus_stats_tenants; SET search_path TO citus_stat_tenants;
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
citus_stats_tenants_reset citus_stat_tenants_reset
--------------------------------------------------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
@ -661,7 +661,7 @@ SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'thisisaverylooooooooooooooooooo
t t
(1 row) (1 row)
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants ORDER BY tenant_attribute;
tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period tenant_attribute | read_count_in_this_period | read_count_in_last_period | query_count_in_this_period | query_count_in_last_period
--------------------------------------------------------------------- ---------------------------------------------------------------------
thisisaverylooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo | 1 | 0 | 1 | 0 thisisaverylooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo | 1 | 0 | 1 | 0
@ -670,36 +670,36 @@ SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, q
-- test role permissions -- test role permissions
CREATE ROLE stats_non_superuser WITH LOGIN; CREATE ROLE stats_non_superuser WITH LOGIN;
SET ROLE stats_non_superuser; SET ROLE stats_non_superuser;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
ERROR: permission denied for view citus_stats_tenants ERROR: permission denied for view citus_stat_tenants
SELECT count(*)>=0 FROM citus_stats_tenants_local; SELECT count(*)>=0 FROM citus_stat_tenants_local;
ERROR: permission denied for view citus_stats_tenants_local ERROR: permission denied for view citus_stat_tenants_local
SELECT count(*)>=0 FROM citus_stats_tenants(); SELECT count(*)>=0 FROM citus_stat_tenants();
ERROR: permission denied for function citus_stats_tenants ERROR: permission denied for function citus_stat_tenants
SELECT count(*)>=0 FROM citus_stats_tenants_local(); SELECT count(*)>=0 FROM citus_stat_tenants_local();
ERROR: permission denied for function citus_stats_tenants_local ERROR: permission denied for function citus_stat_tenants_local
RESET ROLE; RESET ROLE;
GRANT pg_monitor TO stats_non_superuser; GRANT pg_monitor TO stats_non_superuser;
SET ROLE stats_non_superuser; SET ROLE stats_non_superuser;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
?column? ?column?
--------------------------------------------------------------------- ---------------------------------------------------------------------
t t
(1 row) (1 row)
SELECT count(*)>=0 FROM citus_stats_tenants_local; SELECT count(*)>=0 FROM citus_stat_tenants_local;
?column? ?column?
--------------------------------------------------------------------- ---------------------------------------------------------------------
t t
(1 row) (1 row)
SELECT count(*)>=0 FROM citus_stats_tenants(); SELECT count(*)>=0 FROM citus_stat_tenants();
?column? ?column?
--------------------------------------------------------------------- ---------------------------------------------------------------------
t t
(1 row) (1 row)
SELECT count(*)>=0 FROM citus_stats_tenants_local(); SELECT count(*)>=0 FROM citus_stat_tenants_local();
?column? ?column?
--------------------------------------------------------------------- ---------------------------------------------------------------------
t t
@ -708,4 +708,4 @@ SELECT count(*)>=0 FROM citus_stats_tenants_local();
RESET ROLE; RESET ROLE;
DROP ROLE stats_non_superuser; DROP ROLE stats_non_superuser;
SET client_min_messages TO ERROR; SET client_min_messages TO ERROR;
DROP SCHEMA citus_stats_tenants CASCADE; DROP SCHEMA citus_stat_tenants CASCADE;

View File

@ -1366,14 +1366,14 @@ SELECT * FROM multi_extension.print_extension_changes();
| function citus_internal_mark_node_not_synced(integer,integer) void | function citus_internal_mark_node_not_synced(integer,integer) void
| function citus_internal_start_replication_origin_tracking() void | function citus_internal_start_replication_origin_tracking() void
| function citus_internal_stop_replication_origin_tracking() void | function citus_internal_stop_replication_origin_tracking() void
| function citus_stats_tenants(boolean) SETOF record | function citus_stat_tenants(boolean) SETOF record
| function citus_stats_tenants_local(boolean) SETOF record | function citus_stat_tenants_local(boolean) SETOF record
| function citus_stats_tenants_local_reset() void | function citus_stat_tenants_local_reset() void
| function citus_stats_tenants_reset() void | function citus_stat_tenants_reset() void
| function worker_adjust_identity_column_seq_ranges(regclass) void | function worker_adjust_identity_column_seq_ranges(regclass) void
| function worker_drop_all_shell_tables(boolean) | function worker_drop_all_shell_tables(boolean)
| view citus_stats_tenants | view citus_stat_tenants
| view citus_stats_tenants_local | view citus_stat_tenants_local
(12 rows) (12 rows)
DROP TABLE multi_extension.prev_objects, multi_extension.extension_diff; DROP TABLE multi_extension.prev_objects, multi_extension.extension_diff;

View File

@ -21,8 +21,8 @@ ORDER BY 1;
--------------------------------------------------------------------- ---------------------------------------------------------------------
pg_dist_authinfo pg_dist_authinfo
pg_dist_clock_logical_seq pg_dist_clock_logical_seq
citus_stats_tenants_local citus_stat_tenants_local
citus_stats_tenants citus_stat_tenants
(4 rows) (4 rows)
RESET role; RESET role;

View File

@ -125,10 +125,10 @@ ORDER BY 1;
function citus_stat_activity() function citus_stat_activity()
function citus_stat_statements() function citus_stat_statements()
function citus_stat_statements_reset() function citus_stat_statements_reset()
function citus_stats_tenants(boolean) function citus_stat_tenants(boolean)
function citus_stats_tenants_local(boolean) function citus_stat_tenants_local(boolean)
function citus_stats_tenants_local_reset() function citus_stat_tenants_local_reset()
function citus_stats_tenants_reset() function citus_stat_tenants_reset()
function citus_table_is_visible(oid) function citus_table_is_visible(oid)
function citus_table_size(regclass) function citus_table_size(regclass)
function citus_task_wait(bigint,citus_task_status) function citus_task_wait(bigint,citus_task_status)
@ -326,8 +326,8 @@ ORDER BY 1;
view citus_shards_on_worker view citus_shards_on_worker
view citus_stat_activity view citus_stat_activity
view citus_stat_statements view citus_stat_statements
view citus_stats_tenants view citus_stat_tenants
view citus_stats_tenants_local view citus_stat_tenants_local
view pg_dist_shard_placement view pg_dist_shard_placement
view time_partitions view time_partitions
(322 rows) (322 rows)

View File

@ -105,7 +105,7 @@ test: citus_update_table_statistics
# ---------- # ----------
# Test for tenant statistics # Test for tenant statistics
# ---------- # ----------
test: citus_stats_tenants test: citus_stat_tenants
# ---------- # ----------
# Parallel TPC-H tests to check our distributed execution behavior # Parallel TPC-H tests to check our distributed execution behavior

View File

@ -489,7 +489,7 @@ push(@pgOptions, "citus.enable_manual_changes_to_shards=on");
push(@pgOptions, "citus.allow_unsafe_locks_from_workers=on"); push(@pgOptions, "citus.allow_unsafe_locks_from_workers=on");
push(@pgOptions, "citus.stat_statements_track = 'all'"); push(@pgOptions, "citus.stat_statements_track = 'all'");
push(@pgOptions, "citus.enable_change_data_capture=on"); push(@pgOptions, "citus.enable_change_data_capture=on");
push(@pgOptions, "citus.stats_tenants_limit = 10"); push(@pgOptions, "citus.stat_tenants_limit = 10");
# Some tests look at shards in pg_class, make sure we can usually see them: # Some tests look at shards in pg_class, make sure we can usually see them:
push(@pgOptions, "citus.show_shards_for_app_name_prefixes='pg_regress'"); push(@pgOptions, "citus.show_shards_for_app_name_prefixes='pg_regress'");

View File

@ -1,5 +1,5 @@
CREATE SCHEMA citus_stats_tenants; CREATE SCHEMA citus_stat_tenants;
SET search_path TO citus_stats_tenants; SET search_path TO citus_stat_tenants;
SET citus.next_shard_id TO 5797500; SET citus.next_shard_id TO 5797500;
SET citus.shard_replication_factor TO 1; SET citus.shard_replication_factor TO 1;
@ -8,10 +8,10 @@ RETURNS VOID
LANGUAGE C LANGUAGE C
AS 'citus', $$sleep_until_next_period$$; AS 'citus', $$sleep_until_next_period$$;
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
-- set period to a high number to prevent stats from being reset -- set period to a high number to prevent stats from being reset
SELECT result FROM run_command_on_all_nodes('ALTER SYSTEM SET citus.stats_tenants_period TO 1000000000'); SELECT result FROM run_command_on_all_nodes('ALTER SYSTEM SET citus.stat_tenants_period TO 1000000000');
SELECT result FROM run_command_on_all_nodes('SELECT pg_reload_conf()'); SELECT result FROM run_command_on_all_nodes('SELECT pg_reload_conf()');
CREATE TABLE dist_tbl (a INT, b TEXT); CREATE TABLE dist_tbl (a INT, b TEXT);
@ -32,9 +32,9 @@ UPDATE dist_tbl SET b = a + 1 WHERE a = 3;
UPDATE dist_tbl SET b = a + 1 WHERE a = 4; UPDATE dist_tbl SET b = a + 1 WHERE a = 4;
DELETE FROM dist_tbl WHERE a = 5; DELETE FROM dist_tbl WHERE a = 5;
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants(true) ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants(true) ORDER BY tenant_attribute;
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
-- queries with multiple tenants should not be counted -- queries with multiple tenants should not be counted
SELECT count(*)>=0 FROM dist_tbl WHERE a IN (1, 5); SELECT count(*)>=0 FROM dist_tbl WHERE a IN (1, 5);
@ -42,13 +42,13 @@ SELECT count(*)>=0 FROM dist_tbl WHERE a IN (1, 5);
-- queries with reference tables should not be counted -- queries with reference tables should not be counted
SELECT count(*)>=0 FROM ref_tbl WHERE a = 1; SELECT count(*)>=0 FROM ref_tbl WHERE a = 1;
SELECT tenant_attribute, query_count_in_this_period FROM citus_stats_tenants(true) ORDER BY tenant_attribute; SELECT tenant_attribute, query_count_in_this_period FROM citus_stat_tenants(true) ORDER BY tenant_attribute;
-- queries with multiple tables but one tenant should be counted -- queries with multiple tables but one tenant should be counted
SELECT count(*)>=0 FROM dist_tbl, dist_tbl_2 WHERE dist_tbl.a = 1 AND dist_tbl_2.a = 1; SELECT count(*)>=0 FROM dist_tbl, dist_tbl_2 WHERE dist_tbl.a = 1 AND dist_tbl_2.a = 1;
SELECT count(*)>=0 FROM dist_tbl JOIN dist_tbl_2 ON dist_tbl.a = dist_tbl_2.a WHERE dist_tbl.a = 1; SELECT count(*)>=0 FROM dist_tbl JOIN dist_tbl_2 ON dist_tbl.a = dist_tbl_2.a WHERE dist_tbl.a = 1;
SELECT tenant_attribute, query_count_in_this_period FROM citus_stats_tenants(true) WHERE tenant_attribute = '1'; SELECT tenant_attribute, query_count_in_this_period FROM citus_stat_tenants(true) WHERE tenant_attribute = '1';
-- test scoring -- test scoring
-- all of these distribution column values are from second worker -- all of these distribution column values are from second worker
@ -59,72 +59,72 @@ SELECT count(*)>=0 FROM dist_tbl WHERE a = 3;
SELECT count(*)>=0 FROM dist_tbl WHERE a = 4; SELECT count(*)>=0 FROM dist_tbl WHERE a = 4;
SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'abcd'; SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'abcd';
SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stats_tenants(true) WHERE nodeid = :worker_2_nodeid ORDER BY score DESC, tenant_attribute; SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stat_tenants(true) WHERE nodeid = :worker_2_nodeid ORDER BY score DESC, tenant_attribute;
SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'abcd'; SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'abcd';
SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'abcd'; SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'abcd';
SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde'; SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde';
SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'cdef'; SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'cdef';
SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stats_tenants(true) WHERE nodeid = :worker_2_nodeid ORDER BY score DESC, tenant_attribute; SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stat_tenants(true) WHERE nodeid = :worker_2_nodeid ORDER BY score DESC, tenant_attribute;
SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde'; SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde';
SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde'; SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde';
SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'defg'; SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'defg';
SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stats_tenants(true) WHERE nodeid = :worker_2_nodeid ORDER BY score DESC, tenant_attribute; SELECT tenant_attribute, query_count_in_this_period, score FROM citus_stat_tenants(true) WHERE nodeid = :worker_2_nodeid ORDER BY score DESC, tenant_attribute;
-- test period passing -- test period passing
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
SELECT count(*)>=0 FROM dist_tbl WHERE a = 1; SELECT count(*)>=0 FROM dist_tbl WHERE a = 1;
INSERT INTO dist_tbl VALUES (5, 'abcd'); INSERT INTO dist_tbl VALUES (5, 'abcd');
\c - - - :worker_1_port \c - - - :worker_1_port
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants_local ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants_local ORDER BY tenant_attribute;
-- simulate passing the period -- simulate passing the period
SET citus.stats_tenants_period TO 2; SET citus.stat_tenants_period TO 2;
SELECT sleep_until_next_period(); SELECT sleep_until_next_period();
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants_local ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants_local ORDER BY tenant_attribute;
\c - - - :master_port \c - - - :master_port
SET search_path TO citus_stats_tenants; SET search_path TO citus_stat_tenants;
-- test logs -- test logs
SET client_min_messages TO LOG; SET client_min_messages TO LOG;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
SET citus.multi_tenant_monitoring_log_level TO ERROR; SET citus.stat_tenants_log_level TO ERROR;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
SET citus.multi_tenant_monitoring_log_level TO OFF; SET citus.stat_tenants_log_level TO OFF;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
SET citus.multi_tenant_monitoring_log_level TO LOG; SET citus.stat_tenants_log_level TO LOG;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
SET citus.multi_tenant_monitoring_log_level TO DEBUG; SET citus.stat_tenants_log_level TO DEBUG;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
RESET client_min_messages; RESET client_min_messages;
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
-- test turning monitoring on/off -- test turning monitoring on/off
SET citus.stat_tenants_track TO "NONE"; SET citus.stat_tenants_track TO "NONE";
SELECT count(*)>=0 FROM dist_tbl WHERE a = 1; SELECT count(*)>=0 FROM dist_tbl WHERE a = 1;
INSERT INTO dist_tbl VALUES (1, 1); INSERT INTO dist_tbl VALUES (1, 1);
SELECT tenant_attribute, query_count_in_this_period FROM citus_stats_tenants; SELECT tenant_attribute, query_count_in_this_period FROM citus_stat_tenants;
SET citus.stat_tenants_track TO "ALL"; SET citus.stat_tenants_track TO "ALL";
SELECT tenant_attribute, query_count_in_this_period FROM citus_stats_tenants; SELECT tenant_attribute, query_count_in_this_period FROM citus_stat_tenants;
SELECT count(*)>=0 FROM dist_tbl WHERE a = 1; SELECT count(*)>=0 FROM dist_tbl WHERE a = 1;
INSERT INTO dist_tbl VALUES (1, 1); INSERT INTO dist_tbl VALUES (1, 1);
SELECT tenant_attribute, query_count_in_this_period FROM citus_stats_tenants; SELECT tenant_attribute, query_count_in_this_period FROM citus_stat_tenants;
-- test special and multibyte characters in tenant attribute -- test special and multibyte characters in tenant attribute
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
TRUNCATE TABLE dist_tbl_text; TRUNCATE TABLE dist_tbl_text;
SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/bcde'; SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/bcde';
@ -139,13 +139,13 @@ SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde*/';
SELECT count(*)>=0 FROM dist_tbl_text WHERE a = U&'\0061\0308bc'; SELECT count(*)>=0 FROM dist_tbl_text WHERE a = U&'\0061\0308bc';
\c - - - :worker_1_port \c - - - :worker_1_port
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants ORDER BY tenant_attribute;
\c - - - :worker_2_port \c - - - :worker_2_port
SET search_path TO citus_stats_tenants; SET search_path TO citus_stat_tenants;
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants ORDER BY tenant_attribute;
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
-- test local queries -- test local queries
-- all of these distribution column values are from second worker -- all of these distribution column values are from second worker
@ -155,7 +155,7 @@ SELECT count(*)>=0 FROM dist_tbl_text WHERE a = '/bcde';
SELECT count(*)>=0 FROM dist_tbl_text WHERE a = U&'\0061\0308bc'; SELECT count(*)>=0 FROM dist_tbl_text WHERE a = U&'\0061\0308bc';
SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde*'; SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'bcde*';
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants_local ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants_local ORDER BY tenant_attribute;
-- test local cached queries & prepared statements -- test local cached queries & prepared statements
@ -174,10 +174,10 @@ EXECUTE dist_tbl_text_select_plan('/bcde');
EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc'); EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc');
EXECUTE dist_tbl_text_select_plan('bcde*'); EXECUTE dist_tbl_text_select_plan('bcde*');
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants_local ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants_local ORDER BY tenant_attribute;
\c - - - :master_port \c - - - :master_port
SET search_path TO citus_stats_tenants; SET search_path TO citus_stat_tenants;
PREPARE dist_tbl_text_select_plan (text) AS SELECT count(*)>=0 FROM dist_tbl_text WHERE a = $1; PREPARE dist_tbl_text_select_plan (text) AS SELECT count(*)>=0 FROM dist_tbl_text WHERE a = $1;
@ -195,38 +195,38 @@ EXECUTE dist_tbl_text_select_plan(U&'\0061\0308bc');
EXECUTE dist_tbl_text_select_plan('bcde*'); EXECUTE dist_tbl_text_select_plan('bcde*');
\c - - - :worker_2_port \c - - - :worker_2_port
SET search_path TO citus_stats_tenants; SET search_path TO citus_stat_tenants;
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants ORDER BY tenant_attribute;
\c - - - :master_port \c - - - :master_port
SET search_path TO citus_stats_tenants; SET search_path TO citus_stat_tenants;
SELECT citus_stats_tenants_reset(); SELECT citus_stat_tenants_reset();
SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'thisisaveryloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongname'; SELECT count(*)>=0 FROM dist_tbl_text WHERE a = 'thisisaveryloooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongname';
SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stats_tenants ORDER BY tenant_attribute; SELECT tenant_attribute, read_count_in_this_period, read_count_in_last_period, query_count_in_this_period, query_count_in_last_period FROM citus_stat_tenants ORDER BY tenant_attribute;
-- test role permissions -- test role permissions
CREATE ROLE stats_non_superuser WITH LOGIN; CREATE ROLE stats_non_superuser WITH LOGIN;
SET ROLE stats_non_superuser; SET ROLE stats_non_superuser;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
SELECT count(*)>=0 FROM citus_stats_tenants_local; SELECT count(*)>=0 FROM citus_stat_tenants_local;
SELECT count(*)>=0 FROM citus_stats_tenants(); SELECT count(*)>=0 FROM citus_stat_tenants();
SELECT count(*)>=0 FROM citus_stats_tenants_local(); SELECT count(*)>=0 FROM citus_stat_tenants_local();
RESET ROLE; RESET ROLE;
GRANT pg_monitor TO stats_non_superuser; GRANT pg_monitor TO stats_non_superuser;
SET ROLE stats_non_superuser; SET ROLE stats_non_superuser;
SELECT count(*)>=0 FROM citus_stats_tenants; SELECT count(*)>=0 FROM citus_stat_tenants;
SELECT count(*)>=0 FROM citus_stats_tenants_local; SELECT count(*)>=0 FROM citus_stat_tenants_local;
SELECT count(*)>=0 FROM citus_stats_tenants(); SELECT count(*)>=0 FROM citus_stat_tenants();
SELECT count(*)>=0 FROM citus_stats_tenants_local(); SELECT count(*)>=0 FROM citus_stat_tenants_local();
RESET ROLE; RESET ROLE;
DROP ROLE stats_non_superuser; DROP ROLE stats_non_superuser;
SET client_min_messages TO ERROR; SET client_min_messages TO ERROR;
DROP SCHEMA citus_stats_tenants CASCADE; DROP SCHEMA citus_stat_tenants CASCADE;