Revert "Avoid re-assigning the global pid for client backends when the application_name changes"

This reverts commit 1bd0ed8d82.
pull/7791/head
Onur Tirtir 2024-12-18 19:56:43 +03:00
parent 1bd0ed8d82
commit c6c6d9ffcb
1 changed files with 9 additions and 20 deletions

View File

@ -2890,25 +2890,14 @@ ApplicationNameAssignHook(const char *newval, void *extra)
DetermineCitusBackendType(newval); DetermineCitusBackendType(newval);
/* /*
* We use StartupCitusBackend to initialize the global pid after catalogs * AssignGlobalPID might read from catalog tables to get the the local
* are available. After that happens this hook becomes responsible to update * nodeid. But ApplicationNameAssignHook might be called before catalog
* the global pid on later application_name changes. So we set the * access is available to the backend (such as in early stages of
* FinishedStartupCitusBackend flag in StartupCitusBackend to indicate when * authentication). We use StartupCitusBackend to initialize the global pid
* this responsibility handoff has happened. * after catalogs are available. After that happens this hook becomes
* * responsible to update the global pid on later application_name changes.
* Also note that when application_name changes, we don't actually need to * So we set the FinishedStartupCitusBackend flag in StartupCitusBackend to
* try re-assigning the global pid for external client backends because * indicate when this responsibility handoff has happened.
* application_name doesn't affect the global pid for such backends. Plus,
* trying to re-assign the global pid for external client backends would
* unnecessarily cause performing a catalog access when the cached local
* node id is invalidated. However, accessing to the catalog tables is
* dangerous in certain situations like when we're not in a transaction
* block. And for the other types of backends, i.e., the Citus internal
* backends, we need to re-assign the global pid when the application_name
* changes because for such backends we simply extract the global pid
* inherited from the originating backend from the application_name -that's
* specified by originating backend when openning that connection- and this
* doesn't require catalog access.
* *
* Another solution to the catalog table acccess problem would be to update * Another solution to the catalog table acccess problem would be to update
* global pid lazily, like we do for HideShards. But that's not possible * global pid lazily, like we do for HideShards. But that's not possible
@ -2918,7 +2907,7 @@ ApplicationNameAssignHook(const char *newval, void *extra)
* as reasonably possible, which is also why we extract global pids in the * as reasonably possible, which is also why we extract global pids in the
* AuthHook already (extracting doesn't require catalog access). * AuthHook already (extracting doesn't require catalog access).
*/ */
if (FinishedStartupCitusBackend && !IsExternalClientBackend()) if (FinishedStartupCitusBackend)
{ {
AssignGlobalPID(newval); AssignGlobalPID(newval);
} }