Fix bug introduced by #6412 (#6590)

In #6412 I made a change to not re-assign the global PID if it was
already set. This inadvertently introduced a regression where `userId`
and `databaseId` would not be set on the backend data when the global
PID was assigned in the authentication hook.

This fixes it by doing two things:
1. Removing `userId` from `BackendData`, since it's not used anywhere
   anyway.
2. Move assignment of `databaseId` to dedicated
   `SetBackendDataDatabaseId` function, that isn't a no-op when global
   pid is already set.

Since #6412 is not released yet this does not need a description.
pull/6613/head
Jelte Fennema 2023-01-10 16:21:57 +01:00 committed by GitHub
parent 17775dad5d
commit 34df853bda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 6 deletions

View File

@ -678,6 +678,8 @@ StartupCitusBackend(void)
* the gpid from the application_name. * the gpid from the application_name.
*/ */
AssignGlobalPID(); AssignGlobalPID();
SetBackendDataDatabaseId();
RegisterConnectionCleanup(); RegisterConnectionCleanup();
} }

View File

@ -765,7 +765,6 @@ UnSetGlobalPID(void)
MyBackendData->globalPID = 0; MyBackendData->globalPID = 0;
MyBackendData->databaseId = 0; MyBackendData->databaseId = 0;
MyBackendData->userId = 0;
MyBackendData->distributedCommandOriginator = false; MyBackendData->distributedCommandOriginator = false;
SpinLockRelease(&MyBackendData->mutex); SpinLockRelease(&MyBackendData->mutex);
@ -923,19 +922,31 @@ AssignGlobalPID(void)
globalPID = ExtractGlobalPID(application_name); globalPID = ExtractGlobalPID(application_name);
} }
Oid userId = GetUserId();
SpinLockAcquire(&MyBackendData->mutex); SpinLockAcquire(&MyBackendData->mutex);
MyBackendData->globalPID = globalPID; MyBackendData->globalPID = globalPID;
MyBackendData->distributedCommandOriginator = distributedCommandOriginator; MyBackendData->distributedCommandOriginator = distributedCommandOriginator;
MyBackendData->databaseId = MyDatabaseId;
MyBackendData->userId = userId;
SpinLockRelease(&MyBackendData->mutex); SpinLockRelease(&MyBackendData->mutex);
} }
/*
* SetBackendDataDatabaseId sets the databaseId in the backend data.
*
* NOTE: this needs to be run after the auth hook, because in the auth hook the
* database is not known yet.
*/
void
SetBackendDataDatabaseId(void)
{
Assert(MyDatabaseId != InvalidOid);
SpinLockAcquire(&MyBackendData->mutex);
MyBackendData->databaseId = MyDatabaseId;
SpinLockRelease(&MyBackendData->mutex);
}
/* /*
* SetBackendDataDistributedCommandOriginator is used to set the distributedCommandOriginator * SetBackendDataDistributedCommandOriginator is used to set the distributedCommandOriginator
* field on MyBackendData. * field on MyBackendData.

View File

@ -36,7 +36,6 @@
typedef struct BackendData typedef struct BackendData
{ {
Oid databaseId; Oid databaseId;
Oid userId;
slock_t mutex; slock_t mutex;
bool cancelledDueToDeadlock; bool cancelledDueToDeadlock;
uint64 globalPID; uint64 globalPID;
@ -60,6 +59,7 @@ extern void AssignDistributedTransactionId(void);
extern void AssignGlobalPID(void); extern void AssignGlobalPID(void);
extern void SetBackendDataGlobalPID(uint64 globalPID); extern void SetBackendDataGlobalPID(uint64 globalPID);
extern uint64 GetGlobalPID(void); extern uint64 GetGlobalPID(void);
extern void SetBackendDataDatabaseId(void);
extern void SetBackendDataDistributedCommandOriginator(bool extern void SetBackendDataDistributedCommandOriginator(bool
distributedCommandOriginator); distributedCommandOriginator);
extern uint64 ExtractGlobalPID(const char *applicationName); extern uint64 ExtractGlobalPID(const char *applicationName);