mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-17 02:53:51 +08:00
Fix some issues with num_dist_tables
This change fixes a couple issues with the num_dist_tables column of the timescaledb_information.data_node view. The first fix will allow the column to correctly report 0 when no tables are yet created (it currently will count a NULL table as 1 in this case). The second fix addresses a bug in the dist_util_remote_hypertable_info function which was causing the code to only see the first hypertable returned. This second bug will also cause incorrect results for many of our usage reporting views and utilities when there are multiple distributed hypertables.
This commit is contained in:
parent
76237a4413
commit
3d3824dbc1
@ -249,7 +249,7 @@ AS
|
||||
|
||||
CREATE OR REPLACE VIEW timescaledb_information.data_node AS
|
||||
SELECT s.node_name, s.owner, s.options, s.node_up,
|
||||
COUNT(s.node_name) AS num_dist_tables,
|
||||
COUNT(size.table_name) AS num_dist_tables,
|
||||
SUM(size.num_chunks) AS num_dist_chunks,
|
||||
pg_size_pretty(SUM(size.total_bytes)) AS total_dist_size
|
||||
FROM (SELECT srvname AS node_name, srvowner::regrole::name AS owner, srvoptions AS options, _timescaledb_internal.ping_data_node(srvname) AS node_up
|
||||
|
@ -178,7 +178,7 @@ dist_util_remote_hypertable_info(PG_FUNCTION_ARGS)
|
||||
funcctx = SRF_PERCALL_SETUP();
|
||||
result = ts_dist_cmd_get_data_node_result(funcctx->user_fctx, node_name);
|
||||
|
||||
if (funcctx->call_cntr < PQntuples((PGresult *) funcctx->user_fctx))
|
||||
if (funcctx->call_cntr < PQntuples(result))
|
||||
{
|
||||
HeapTuple tuple;
|
||||
char **fields = palloc(sizeof(char *) * PQnfields(result));
|
||||
|
@ -91,10 +91,10 @@ NOTICE: adding user mapping for "default_cluster_user" to connect to "data_node
|
||||
SELECT * FROM timescaledb_information.data_node;
|
||||
node_name | owner | options | node_up | num_dist_tables | num_dist_chunks | total_dist_size
|
||||
-------------+----------------------+------------------------------------------------+---------+-----------------+-----------------+-----------------
|
||||
data_node_3 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_3} | t | 1 | |
|
||||
data_node_4 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_4} | t | 1 | |
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 1 | |
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 1 | |
|
||||
data_node_3 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_3} | t | 0 | |
|
||||
data_node_4 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_4} | t | 0 | |
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 0 | |
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 0 | |
|
||||
(4 rows)
|
||||
|
||||
RESET ROLE;
|
||||
@ -132,9 +132,9 @@ NOTICE: drop cascades to user mapping for default_cluster_user on server data_n
|
||||
SELECT * FROM timescaledb_information.data_node;
|
||||
node_name | owner | options | node_up | num_dist_tables | num_dist_chunks | total_dist_size
|
||||
-------------+----------------------+------------------------------------------------+---------+-----------------+-----------------+-----------------
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 1 | |
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 1 | |
|
||||
data_node_4 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_4} | t | 1 | |
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 0 | |
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 0 | |
|
||||
data_node_4 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_4} | t | 0 | |
|
||||
(3 rows)
|
||||
|
||||
RESET ROLE;
|
||||
@ -166,9 +166,9 @@ NOTICE: data node "data_node_3" does not exist, skipping
|
||||
SELECT * FROM timescaledb_information.data_node;
|
||||
node_name | owner | options | node_up | num_dist_tables | num_dist_chunks | total_dist_size
|
||||
-------------+----------------------+------------------------------------------------+---------+-----------------+-----------------+-----------------
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 1 | |
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 1 | |
|
||||
data_node_4 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_4} | t | 1 | |
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 0 | |
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 0 | |
|
||||
data_node_4 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_4} | t | 0 | |
|
||||
(3 rows)
|
||||
|
||||
DROP SERVER data_node_1 CASCADE;
|
||||
@ -234,9 +234,9 @@ NOTICE: adding user mapping for "default_cluster_user" to connect to "data_node
|
||||
SELECT * FROM timescaledb_information.data_node;
|
||||
node_name | owner | options | node_up | num_dist_tables | num_dist_chunks | total_dist_size
|
||||
-------------+----------------------+------------------------------------------------+---------+-----------------+-----------------+-----------------
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 1 | |
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 1 | |
|
||||
data_node_4 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_4} | t | 1 | |
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 0 | |
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 0 | |
|
||||
data_node_4 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_4} | t | 0 | |
|
||||
(3 rows)
|
||||
|
||||
-- Switch to default user
|
||||
|
@ -59,6 +59,15 @@ NOTICE: adding user mapping for "default_cluster_user" to connect to "data_node
|
||||
data_node_3 | localhost | 15432 | data_node_3 | t | t | t
|
||||
(1 row)
|
||||
|
||||
-- Verify lack of tables
|
||||
SELECT * FROM timescaledb_information.data_node;
|
||||
node_name | owner | options | node_up | num_dist_tables | num_dist_chunks | total_dist_size
|
||||
-------------+----------------------+------------------------------------------------+---------+-----------------+-----------------+-----------------
|
||||
data_node_3 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_3} | t | 0 | |
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 0 | |
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 0 | |
|
||||
(3 rows)
|
||||
|
||||
-- Create distributed hypertables. Add a trigger and primary key
|
||||
-- constraint to test how those work
|
||||
CREATE TABLE disttable(time timestamptz, device int CHECK (device > 0), color int, temp float, PRIMARY KEY (time,device));
|
||||
@ -388,9 +397,9 @@ Sun Jul 01 08:01:00 2018 PDT| 29| 1.5
|
||||
SELECT * FROM timescaledb_information.data_node;
|
||||
node_name | owner | options | node_up | num_dist_tables | num_dist_chunks | total_dist_size
|
||||
-------------+----------------------+------------------------------------------------+---------+-----------------+-----------------+-----------------
|
||||
data_node_3 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_3} | t | 1 | 2 | 112 kB
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 1 | 2 | 112 kB
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 1 | 2 | 112 kB
|
||||
data_node_3 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_3} | t | 2 | 2 | 112 kB
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 2 | 2 | 112 kB
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 2 | 2 | 112 kB
|
||||
(3 rows)
|
||||
|
||||
SELECT * FROM hypertable_data_node_relation_size('disttable');
|
||||
@ -1207,7 +1216,7 @@ ORDER BY table_schema, table_name;
|
||||
table_schema | table_name | table_owner | num_dimensions | num_chunks | table_size | index_size | toast_size | total_size | distributed
|
||||
--------------+-----------------+----------------------+----------------+------------+------------+------------+------------+------------+-------------
|
||||
public | disttable | default_cluster_user | 2 | 9 | 72 kB | 720 kB | | 792 kB | t
|
||||
public | underreplicated | default_cluster_user | 1 | 1 | | | | | t
|
||||
public | underreplicated | default_cluster_user | 1 | 1 | 24 kB | 48 kB | | 72 kB | t
|
||||
(2 rows)
|
||||
|
||||
-- Test distributed hypertable creation with many parameters
|
||||
|
@ -59,6 +59,15 @@ NOTICE: adding user mapping for "default_cluster_user" to connect to "data_node
|
||||
data_node_3 | localhost | 15432 | data_node_3 | t | t | t
|
||||
(1 row)
|
||||
|
||||
-- Verify lack of tables
|
||||
SELECT * FROM timescaledb_information.data_node;
|
||||
node_name | owner | options | node_up | num_dist_tables | num_dist_chunks | total_dist_size
|
||||
-------------+----------------------+------------------------------------------------+---------+-----------------+-----------------+-----------------
|
||||
data_node_3 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_3} | t | 0 | |
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 0 | |
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 0 | |
|
||||
(3 rows)
|
||||
|
||||
-- Create distributed hypertables. Add a trigger and primary key
|
||||
-- constraint to test how those work
|
||||
CREATE TABLE disttable(time timestamptz, device int CHECK (device > 0), color int, temp float, PRIMARY KEY (time,device));
|
||||
@ -388,9 +397,9 @@ Sun Jul 01 08:01:00 2018 PDT| 29| 1.5
|
||||
SELECT * FROM timescaledb_information.data_node;
|
||||
node_name | owner | options | node_up | num_dist_tables | num_dist_chunks | total_dist_size
|
||||
-------------+----------------------+------------------------------------------------+---------+-----------------+-----------------+-----------------
|
||||
data_node_3 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_3} | t | 1 | 2 | 112 kB
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 1 | 2 | 112 kB
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 1 | 2 | 112 kB
|
||||
data_node_3 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_3} | t | 2 | 2 | 112 kB
|
||||
data_node_1 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_1} | t | 2 | 2 | 112 kB
|
||||
data_node_2 | default_cluster_user | {host=localhost,port=15432,dbname=data_node_2} | t | 2 | 2 | 112 kB
|
||||
(3 rows)
|
||||
|
||||
SELECT * FROM hypertable_data_node_relation_size('disttable');
|
||||
@ -1207,7 +1216,7 @@ ORDER BY table_schema, table_name;
|
||||
table_schema | table_name | table_owner | num_dimensions | num_chunks | table_size | index_size | toast_size | total_size | distributed
|
||||
--------------+-----------------+----------------------+----------------+------------+------------+------------+------------+------------+-------------
|
||||
public | disttable | default_cluster_user | 2 | 9 | 72 kB | 720 kB | | 792 kB | t
|
||||
public | underreplicated | default_cluster_user | 1 | 1 | | | | | t
|
||||
public | underreplicated | default_cluster_user | 1 | 1 | 24 kB | 48 kB | | 72 kB | t
|
||||
(2 rows)
|
||||
|
||||
-- Test distributed hypertable creation with many parameters
|
||||
|
@ -40,6 +40,9 @@ SELECT * FROM add_data_node('data_node_3',
|
||||
bootstrap_user => :'ROLE_CLUSTER_SUPERUSER',
|
||||
bootstrap_password => :'ROLE_CLUSTER_SUPERUSER_PASS');
|
||||
|
||||
-- Verify lack of tables
|
||||
SELECT * FROM timescaledb_information.data_node;
|
||||
|
||||
-- Create distributed hypertables. Add a trigger and primary key
|
||||
-- constraint to test how those work
|
||||
CREATE TABLE disttable(time timestamptz, device int CHECK (device > 0), color int, temp float, PRIMARY KEY (time,device));
|
||||
|
Loading…
x
Reference in New Issue
Block a user