mirror of https://github.com/citusdata/citus.git
Adds test for pg_dist_database_size
parent
85378b2a5f
commit
f582e9893f
|
@ -74,7 +74,6 @@ citus_internal_database_size(PG_FUNCTION_ARGS)
|
|||
PG_ENSURE_ARGNOTNULL(0, "dbName");
|
||||
|
||||
Name dbName = PG_GETARG_NAME(0);
|
||||
elog(INFO, "citus_internal_database_name: %s", dbName->data);
|
||||
|
||||
StringInfo databaseSizeQuery = makeStringInfo();
|
||||
appendStringInfo(databaseSizeQuery,
|
||||
|
@ -84,7 +83,6 @@ citus_internal_database_size(PG_FUNCTION_ARGS)
|
|||
/*get database oid */
|
||||
bool missingOk = true;
|
||||
Oid databaseOid = get_database_oid(dbName->data, missingOk);
|
||||
elog(INFO, "citus_internal_database_oid: %d", databaseOid);
|
||||
|
||||
/*get group id */
|
||||
int groupId = GroupLookupFromDatabase(databaseOid, missingOk);
|
||||
|
@ -94,26 +92,34 @@ citus_internal_database_size(PG_FUNCTION_ARGS)
|
|||
databaseOid)));
|
||||
PG_RETURN_INT64(-1);
|
||||
}
|
||||
elog(INFO, "group id: %d", groupId);
|
||||
|
||||
WorkerNode *workerNode = LookupNodeForGroup(groupId);
|
||||
|
||||
char *workerNodeName = workerNode->workerName;
|
||||
uint32 workerNodePort = workerNode->workerPort;
|
||||
|
||||
elog(INFO, "workerNodeName: %s", workerNodeName);
|
||||
elog(INFO, "workerNodePort: %d", workerNodePort);
|
||||
|
||||
if (groupId == GetLocalGroupId())
|
||||
{
|
||||
/*local database */
|
||||
elog(INFO, "local database");
|
||||
elog(DEBUG1,
|
||||
"Initiating process to get the size of the local database.\n"
|
||||
"Database Name: %s\n"
|
||||
"Server Group ID: %d\n"
|
||||
"Worker Node Name: %s\n"
|
||||
"Worker Node Port: %d",
|
||||
dbName->data, groupId, workerNodeName, workerNodePort);
|
||||
PG_RETURN_INT64(DirectFunctionCall1(citus_internal_pg_database_size_by_db_name,
|
||||
NameGetDatum(dbName)));
|
||||
}
|
||||
else
|
||||
{
|
||||
elog(INFO, "remote database");
|
||||
elog(DEBUG1,
|
||||
"Initiating process to get the size of the remote database.\n"
|
||||
"Database Name: %s\n"
|
||||
"Server Group ID: %d\n"
|
||||
"Worker Node Name: %s\n"
|
||||
"Worker Node Port: %d",
|
||||
dbName->data, groupId, workerNodeName, workerNodePort);
|
||||
|
||||
/*remote database */
|
||||
MultiConnection *connection = GetNodeConnection(connectionFlag, workerNodeName,
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
-- Test Scenario:
|
||||
-- 1. Create 3 databases: test_group0, test_group1, test_group2 on all nodes.
|
||||
-- 2. Set these as main databases for nodes 1, 2, 3 respectively by inserting
|
||||
-- records into pg_dist_database.
|
||||
-- 3. Create tables: test_table0, test_table1, test_table2 in test_group0,
|
||||
-- test_group1, test_group2 respectively. Insert enough records to make
|
||||
-- the size of each database distinct.
|
||||
-- 4. Check the size of each database. Ensure each size is distinct and that
|
||||
-- pg_dist_database_size returns the size from the correct node.
|
||||
-- 5. Release the resources.
|
||||
set citus.enable_create_database_propagation to true;
|
||||
-- Step 1 creates the databases on all nodes.
|
||||
create database test_group0;
|
||||
create database test_group1;
|
||||
create DATABASE test_group2;
|
||||
-- Get the groupid for each node.
|
||||
SELECT groupid AS worker_1_group FROM pg_dist_node WHERE nodeport = :worker_1_port \gset
|
||||
SELECT groupid AS worker_2_group FROM pg_dist_node WHERE nodeport = :worker_2_port \gset
|
||||
-- Step 2 sets the main database for each node by inserting records into pg_dist_database.
|
||||
\c regression;
|
||||
SELECT result FROM run_command_on_all_nodes('insert into pg_dist_database (databaseid, groupid) select oid, 0 from pg_database where datname = ''test_group0'';');
|
||||
result
|
||||
---------------------------------------------------------------------
|
||||
INSERT 0 1
|
||||
INSERT 0 1
|
||||
INSERT 0 1
|
||||
(3 rows)
|
||||
|
||||
SELECT result FROM run_command_on_all_nodes('insert into pg_dist_database (databaseid, groupid) select oid,' || :worker_1_group || ' from pg_database where datname = ''test_group1'';');
|
||||
result
|
||||
---------------------------------------------------------------------
|
||||
INSERT 0 1
|
||||
INSERT 0 1
|
||||
INSERT 0 1
|
||||
(3 rows)
|
||||
|
||||
SELECT result FROM run_command_on_all_nodes('insert into pg_dist_database (databaseid, groupid) select oid,' || :worker_2_group || ' from pg_database where datname = ''test_group2'';');
|
||||
result
|
||||
---------------------------------------------------------------------
|
||||
INSERT 0 1
|
||||
INSERT 0 1
|
||||
INSERT 0 1
|
||||
(3 rows)
|
||||
|
||||
-- Step 3 creates tables in each database and inserts enough records to make the size of each database distinct.
|
||||
\c test_group0;
|
||||
create table test_table0 (a int);
|
||||
insert into test_table0 select generate_series(1,1000000);
|
||||
\c - - - :worker_1_port;
|
||||
\c test_group1;
|
||||
create table test_table1 (a int);
|
||||
insert into test_table1 select generate_series(1,1000000);
|
||||
\c - - - :worker_2_port;
|
||||
\c test_group2;
|
||||
create table test_table2 (a int);
|
||||
insert into test_table2 select generate_series(1,1000000);
|
||||
\c - - - :master_port;
|
||||
\c regression;
|
||||
select * from pg_dist_database;
|
||||
databaseid | groupid
|
||||
---------------------------------------------------------------------
|
||||
17352 | 0
|
||||
17353 | 14
|
||||
17354 | 16
|
||||
(3 rows)
|
||||
|
||||
-- Step 4 checks the size of each database. Ensure each size is distinct and that pg_dist_database_size returns the size from the correct node.
|
||||
SET client_min_messages TO DEBUG1;
|
||||
select * from pg_dist_node;
|
||||
nodeid | groupid | nodename | nodeport | noderack | hasmetadata | isactive | noderole | nodecluster | metadatasynced | shouldhaveshards
|
||||
---------------------------------------------------------------------
|
||||
18 | 16 | localhost | 57638 | default | t | t | primary | default | t | t
|
||||
16 | 14 | localhost | 57637 | default | t | t | primary | default | t | t
|
||||
17 | 0 | localhost | 57636 | default | t | t | primary | default | t | f
|
||||
(3 rows)
|
||||
|
||||
select pg_size_pretty(pg_dist_database_size('test_group0'));
|
||||
DEBUG: Initiating process to get the size of the local database.
|
||||
Database Name: test_group0
|
||||
Server Group ID: 0
|
||||
Worker Node Name: localhost
|
||||
Worker Node Port: 57636
|
||||
pg_size_pretty
|
||||
---------------------------------------------------------------------
|
||||
42 MB
|
||||
(1 row)
|
||||
|
||||
select pg_size_pretty(pg_dist_database_size('test_group1'));
|
||||
DEBUG: Initiating process to get the size of the remote database.
|
||||
Database Name: test_group1
|
||||
Server Group ID: 14
|
||||
Worker Node Name: localhost
|
||||
Worker Node Port: 57637
|
||||
pg_size_pretty
|
||||
---------------------------------------------------------------------
|
||||
42 MB
|
||||
(1 row)
|
||||
|
||||
select pg_size_pretty(pg_dist_database_size('test_group2'));
|
||||
DEBUG: Initiating process to get the size of the remote database.
|
||||
Database Name: test_group2
|
||||
Server Group ID: 16
|
||||
Worker Node Name: localhost
|
||||
Worker Node Port: 57638
|
||||
pg_size_pretty
|
||||
---------------------------------------------------------------------
|
||||
42 MB
|
||||
(1 row)
|
||||
|
||||
RESET client_min_messages;
|
||||
drop DATABASE test_group0;
|
||||
drop DATABASE test_group1;
|
||||
drop DATABASE test_group2;
|
||||
reset citus.enable_create_database_propagation;
|
|
@ -60,6 +60,8 @@ test: alter_database_propagation
|
|||
|
||||
test: citus_shards
|
||||
|
||||
test: pg_dist_database_size
|
||||
|
||||
# ----------
|
||||
# multi_citus_tools tests utility functions written for citus tools
|
||||
# ----------
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
-- Test Scenario:
|
||||
-- 1. Create 3 databases: test_group0, test_group1, test_group2 on all nodes.
|
||||
-- 2. Set these as main databases for nodes 1, 2, 3 respectively by inserting
|
||||
-- records into pg_dist_database.
|
||||
-- 3. Create tables: test_table0, test_table1, test_table2 in test_group0,
|
||||
-- test_group1, test_group2 respectively. Insert enough records to make
|
||||
-- the size of each database distinct.
|
||||
-- 4. Check the size of each database. Ensure each size is distinct and that
|
||||
-- pg_dist_database_size returns the size from the correct node.
|
||||
-- 5. Release the resources.
|
||||
|
||||
set citus.enable_create_database_propagation to true;
|
||||
|
||||
-- Step 1 creates the databases on all nodes.
|
||||
create database test_group0;
|
||||
|
||||
create database test_group1;
|
||||
|
||||
create DATABASE test_group2;
|
||||
|
||||
|
||||
-- Get the groupid for each node.
|
||||
SELECT groupid AS worker_1_group FROM pg_dist_node WHERE nodeport = :worker_1_port \gset
|
||||
SELECT groupid AS worker_2_group FROM pg_dist_node WHERE nodeport = :worker_2_port \gset
|
||||
|
||||
|
||||
-- Step 2 sets the main database for each node by inserting records into pg_dist_database.
|
||||
\c regression;
|
||||
|
||||
SELECT result FROM run_command_on_all_nodes('insert into pg_dist_database (databaseid, groupid) select oid, 0 from pg_database where datname = ''test_group0'';');
|
||||
SELECT result FROM run_command_on_all_nodes('insert into pg_dist_database (databaseid, groupid) select oid,' || :worker_1_group || ' from pg_database where datname = ''test_group1'';');
|
||||
SELECT result FROM run_command_on_all_nodes('insert into pg_dist_database (databaseid, groupid) select oid,' || :worker_2_group || ' from pg_database where datname = ''test_group2'';');
|
||||
|
||||
|
||||
-- Step 3 creates tables in each database and inserts enough records to make the size of each database distinct.
|
||||
\c test_group0;
|
||||
|
||||
create table test_table0 (a int);
|
||||
insert into test_table0 select generate_series(1,1000000);
|
||||
|
||||
\c - - - :worker_1_port;
|
||||
\c test_group1;
|
||||
|
||||
create table test_table1 (a int);
|
||||
insert into test_table1 select generate_series(1,1000000);
|
||||
|
||||
\c - - - :worker_2_port;
|
||||
\c test_group2;
|
||||
create table test_table2 (a int);
|
||||
insert into test_table2 select generate_series(1,1000000);
|
||||
|
||||
\c - - - :master_port;
|
||||
|
||||
\c regression;
|
||||
|
||||
select * from pg_dist_database;
|
||||
|
||||
-- Step 4 checks the size of each database. Ensure each size is distinct and that pg_dist_database_size returns the size from the correct node.
|
||||
SET client_min_messages TO DEBUG1;
|
||||
select * from pg_dist_node;
|
||||
select pg_size_pretty(pg_dist_database_size('test_group0'));
|
||||
|
||||
select pg_size_pretty(pg_dist_database_size('test_group1'));
|
||||
|
||||
select pg_size_pretty(pg_dist_database_size('test_group2'));
|
||||
|
||||
RESET client_min_messages;
|
||||
|
||||
|
||||
drop DATABASE test_group0;
|
||||
drop DATABASE test_group1;
|
||||
drop DATABASE test_group2;
|
||||
|
||||
reset citus.enable_create_database_propagation;
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue