Merge pull request #1365 from citusdata/fix_size

Check whether relation ID exists in DistributedTableSize
pull/1349/head
Marco Slot 2017-04-28 16:51:41 -07:00 committed by GitHub
commit b0fdd5963d
3 changed files with 33 additions and 0 deletions

View File

@ -134,6 +134,7 @@ citus_relation_size(PG_FUNCTION_ARGS)
static uint64 static uint64
DistributedTableSize(Oid relationId, char *sizeQuery) DistributedTableSize(Oid relationId, char *sizeQuery)
{ {
Relation relation = NULL;
Relation pgDistNode = NULL; Relation pgDistNode = NULL;
List *workerNodeList = NULL; List *workerNodeList = NULL;
ListCell *workerNodeCell = NULL; ListCell *workerNodeCell = NULL;
@ -146,6 +147,9 @@ DistributedTableSize(Oid relationId, char *sizeQuery)
" blocks which contain multi-shard data modifications"))); " blocks which contain multi-shard data modifications")));
} }
/* try to open relation, will error out if the relation does not exist */
relation = relation_open(relationId, AccessShareLock);
ErrorIfNotSuitableToGetSize(relationId); ErrorIfNotSuitableToGetSize(relationId);
pgDistNode = heap_open(DistNodeRelationId(), AccessShareLock); pgDistNode = heap_open(DistNodeRelationId(), AccessShareLock);
@ -161,6 +165,7 @@ DistributedTableSize(Oid relationId, char *sizeQuery)
} }
heap_close(pgDistNode, NoLock); heap_close(pgDistNode, NoLock);
heap_close(relation, AccessShareLock);
return totalRelationSize; return totalRelationSize;
} }

View File

@ -6,6 +6,22 @@
-- citus_total_relation_size are also tested. -- citus_total_relation_size are also tested.
ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 1390000; ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 1390000;
ALTER SEQUENCE pg_catalog.pg_dist_jobid_seq RESTART 1390000; ALTER SEQUENCE pg_catalog.pg_dist_jobid_seq RESTART 1390000;
-- Tests with invalid relation IDs
SELECT citus_table_size(1);
ERROR: could not open relation with OID 1
SELECT citus_relation_size(1);
ERROR: could not open relation with OID 1
SELECT citus_total_relation_size(1);
ERROR: could not open relation with OID 1
-- Tests with non-distributed table
CREATE TABLE non_distributed_table (x int);
SELECT citus_table_size('non_distributed_table');
ERROR: cannot calculate the size because relation 'non_distributed_table' is not distributed
SELECT citus_relation_size('non_distributed_table');
ERROR: cannot calculate the size because relation 'non_distributed_table' is not distributed
SELECT citus_total_relation_size('non_distributed_table');
ERROR: cannot calculate the size because relation 'non_distributed_table' is not distributed
DROP TABLE non_distributed_table;
-- Tests on distributed table with replication factor > 1 -- Tests on distributed table with replication factor > 1
SELECT citus_table_size('lineitem_hash_part'); SELECT citus_table_size('lineitem_hash_part');
ERROR: cannot calculate the size because replication factor is greater than 1 ERROR: cannot calculate the size because replication factor is greater than 1

View File

@ -8,6 +8,18 @@
ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 1390000; ALTER SEQUENCE pg_catalog.pg_dist_shardid_seq RESTART 1390000;
ALTER SEQUENCE pg_catalog.pg_dist_jobid_seq RESTART 1390000; ALTER SEQUENCE pg_catalog.pg_dist_jobid_seq RESTART 1390000;
-- Tests with invalid relation IDs
SELECT citus_table_size(1);
SELECT citus_relation_size(1);
SELECT citus_total_relation_size(1);
-- Tests with non-distributed table
CREATE TABLE non_distributed_table (x int);
SELECT citus_table_size('non_distributed_table');
SELECT citus_relation_size('non_distributed_table');
SELECT citus_total_relation_size('non_distributed_table');
DROP TABLE non_distributed_table;
-- Tests on distributed table with replication factor > 1 -- Tests on distributed table with replication factor > 1
SELECT citus_table_size('lineitem_hash_part'); SELECT citus_table_size('lineitem_hash_part');
SELECT citus_relation_size('lineitem_hash_part'); SELECT citus_relation_size('lineitem_hash_part');