Allow citus_internal application_name with additional suffix (#6282)

Co-authored-by: Marco Slot <marco.slot@gmail.com>
pull/6301/head
Marco Slot 2022-09-01 14:26:43 +02:00 committed by Marco Slot
parent 0a11da1291
commit 5f57d77899
3 changed files with 31 additions and 8 deletions

View File

@ -1017,16 +1017,16 @@ ExtractGlobalPID(char *applicationName)
return INVALID_CITUS_INTERNAL_BACKEND_GPID;
}
/* are the remaining characters of the application name numbers */
uint64 numberOfRemainingChars = strlen(applicationNameCopy) - prefixLength;
if (numberOfRemainingChars <= 0 ||
!strisdigit_s(applicationNameCopy + prefixLength, numberOfRemainingChars))
{
return INVALID_CITUS_INTERNAL_BACKEND_GPID;
}
char *globalPIDString = &applicationNameCopy[prefixLength];
uint64 globalPID = strtoul(globalPIDString, NULL, 10);
if (globalPID == 0)
{
/*
* INVALID_CITUS_INTERNAL_BACKEND_GPID is 0, but just to be explicit
* about how we handle strtoul errors.
*/
return INVALID_CITUS_INTERNAL_BACKEND_GPID;
}
return globalPID;
}

View File

@ -108,6 +108,22 @@ BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;
SET application_name to 'citus_internal gpid=not a correct gpid';
SELECT citus_internal_add_partition_metadata ('test_2'::regclass, 'h', 'col_1', 0, 's');
ERROR: This is an internal Citus function can only be used in a distributed transaction
ROLLBACK;
-- application_name with suffix is ok (e.g. pgbouncer might add this)
BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT assign_distributed_transaction_id(0, 8, '2021-07-09 15:41:55.542377+02');
assign_distributed_transaction_id
---------------------------------------------------------------------
(1 row)
SET application_name to 'citus_internal gpid=10000000001 - from 10.12.14.16:10370';
SELECT citus_internal_add_partition_metadata ('test_2'::regclass, 'h', 'col_1', 0, 's');
citus_internal_add_partition_metadata
---------------------------------------------------------------------
(1 row)
ROLLBACK;
-- application_name with empty gpid
BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;

View File

@ -75,6 +75,13 @@ BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT citus_internal_add_partition_metadata ('test_2'::regclass, 'h', 'col_1', 0, 's');
ROLLBACK;
-- application_name with suffix is ok (e.g. pgbouncer might add this)
BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT assign_distributed_transaction_id(0, 8, '2021-07-09 15:41:55.542377+02');
SET application_name to 'citus_internal gpid=10000000001 - from 10.12.14.16:10370';
SELECT citus_internal_add_partition_metadata ('test_2'::regclass, 'h', 'col_1', 0, 's');
ROLLBACK;
-- application_name with empty gpid
BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED;
SELECT assign_distributed_transaction_id(0, 8, '2021-07-09 15:41:55.542377+02');