commit b3fb176a4e4f09f7436f2df8c3411b4b51c71906 Author: Jacob Champion Date: Tue Apr 5 10:18:16 2022 -0700 squash! Allow parallel workers to use pg_session_authn_id() Update name to MyParallelProcInfo. diff --git a/src/backend/access/transam/parallel.c b/src/backend/access/transam/parallel.c index c88eab0933..27eda766b1 100644 --- a/src/backend/access/transam/parallel.c +++ b/src/backend/access/transam/parallel.c @@ -76,7 +76,7 @@ #define PARALLEL_KEY_REINDEX_STATE UINT64CONST(0xFFFFFFFFFFFF000C) #define PARALLEL_KEY_RELMAPPER_STATE UINT64CONST(0xFFFFFFFFFFFF000D) #define PARALLEL_KEY_UNCOMMITTEDENUMS UINT64CONST(0xFFFFFFFFFFFF000E) -#define PARALLEL_KEY_SHAREDPORT UINT64CONST(0xFFFFFFFFFFFF000F) +#define PARALLEL_KEY_PROCINFO UINT64CONST(0xFFFFFFFFFFFF000F) /* Fixed-size parallel state. */ typedef struct FixedParallelState @@ -213,7 +213,7 @@ InitializeParallelDSM(ParallelContext *pcxt) Size reindexlen = 0; Size relmapperlen = 0; Size uncommittedenumslen = 0; - Size sharedportlen = 0; + Size procinfolen = 0; Size segsize = 0; int i; FixedParallelState *fps; @@ -274,8 +274,8 @@ InitializeParallelDSM(ParallelContext *pcxt) shm_toc_estimate_chunk(&pcxt->estimator, relmapperlen); uncommittedenumslen = EstimateUncommittedEnumsSpace(); shm_toc_estimate_chunk(&pcxt->estimator, uncommittedenumslen); - sharedportlen = EstimateSharedPortSpace(); - shm_toc_estimate_chunk(&pcxt->estimator, sharedportlen); + procinfolen = EstimateParallelProcInfoSpace(); + shm_toc_estimate_chunk(&pcxt->estimator, procinfolen); /* If you add more chunks here, you probably need to add keys. */ shm_toc_estimate_keys(&pcxt->estimator, 12); @@ -356,7 +356,7 @@ InitializeParallelDSM(ParallelContext *pcxt) char *session_dsm_handle_space; char *entrypointstate; char *uncommittedenumsspace; - char *sharedportspace; + char *procinfospace; Size lnamelen; /* Serialize shared libraries we have loaded. */ @@ -427,11 +427,11 @@ InitializeParallelDSM(ParallelContext *pcxt) shm_toc_insert(pcxt->toc, PARALLEL_KEY_UNCOMMITTEDENUMS, uncommittedenumsspace); - /* Serialize our SharedPort. */ - sharedportspace = shm_toc_allocate(pcxt->toc, sharedportlen); - SerializeSharedPort(sharedportlen, sharedportspace); - shm_toc_insert(pcxt->toc, PARALLEL_KEY_SHAREDPORT, - sharedportspace); + /* Serialize our ParallelProcInfo. */ + procinfospace = shm_toc_allocate(pcxt->toc, procinfolen); + SerializeParallelProcInfo(procinfolen, procinfospace); + shm_toc_insert(pcxt->toc, PARALLEL_KEY_PROCINFO, + procinfospace); /* Allocate space for worker information. */ pcxt->worker = palloc0(sizeof(ParallelWorkerInfo) * pcxt->nworkers); @@ -1281,7 +1281,7 @@ ParallelWorkerMain(Datum main_arg) char *reindexspace; char *relmapperspace; char *uncommittedenumsspace; - char *sharedportspace; + char *procinfospace; StringInfoData msgbuf; char *session_dsm_handle_space; Snapshot tsnapshot; @@ -1491,9 +1491,9 @@ ParallelWorkerMain(Datum main_arg) false); RestoreUncommittedEnums(uncommittedenumsspace); - /* Restore the SharedPort. */ - sharedportspace = shm_toc_lookup(toc, PARALLEL_KEY_SHAREDPORT, false); - RestoreSharedPort(sharedportspace); + /* Restore the ParallelProcInfo. */ + procinfospace = shm_toc_lookup(toc, PARALLEL_KEY_PROCINFO, false); + RestoreParallelProcInfo(procinfospace); /* Attach to the leader's serializable transaction, if SERIALIZABLE. */ AttachSerializableXact(fps->serializable_xact_handle); diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c index bceda9755a..2e5fe2cc19 100644 --- a/src/backend/libpq/auth.c +++ b/src/backend/libpq/auth.c @@ -342,15 +342,15 @@ auth_failed(Port *port, int status, const char *logdetail) * authorization will fail later. * * The provided string will be copied into TopMemoryContext, to match the - * lifetime of MyProcShared, so it is safe to pass a string that is managed by - * an external library. + * lifetime of MyParallelProcInfo, so it is safe to pass a string that is + * managed by an external library. */ static void set_authn_id(Port *port, const char *id) { Assert(id); - if (MyProcShared.authn_id) + if (MyParallelProcInfo.authn_id) { /* * An existing authn_id should never be overwritten; that means two @@ -361,17 +361,17 @@ set_authn_id(Port *port, const char *id) ereport(FATAL, (errmsg("authentication identifier set more than once"), errdetail_log("previous identifier: \"%s\"; new identifier: \"%s\"", - MyProcShared.authn_id, id))); + MyParallelProcInfo.authn_id, id))); } - MyProcShared.authn_id = MemoryContextStrdup(TopMemoryContext, id); + MyParallelProcInfo.authn_id = MemoryContextStrdup(TopMemoryContext, id); if (Log_connections) { ereport(LOG, errmsg("connection authenticated: identity=\"%s\" method=%s " "(%s:%d)", - MyProcShared.authn_id, + MyParallelProcInfo.authn_id, hba_authname(port->hba->auth_method), HbaFileName, port->hba->linenumber)); } @@ -1910,7 +1910,7 @@ auth_peer(hbaPort *port) set_authn_id(port, pw->pw_name); ret = check_usermap(port->hba->usermap, port->user_name, - MyProcShared.authn_id, false); + MyParallelProcInfo.authn_id, false); return ret; #else diff --git a/src/backend/utils/adt/name.c b/src/backend/utils/adt/name.c index 6d497e63d9..24a06bf933 100644 --- a/src/backend/utils/adt/name.c +++ b/src/backend/utils/adt/name.c @@ -275,10 +275,10 @@ session_user(PG_FUNCTION_ARGS) Datum pg_session_authn_id(PG_FUNCTION_ARGS) { - if (!MyProcShared.authn_id) + if (!MyParallelProcInfo.authn_id) PG_RETURN_NULL(); - PG_RETURN_TEXT_P(cstring_to_text(MyProcShared.authn_id)); + PG_RETURN_TEXT_P(cstring_to_text(MyParallelProcInfo.authn_id)); } diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index 0afab3e142..91b3347398 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -930,50 +930,50 @@ GetUserNameFromId(Oid roleid, bool noerr) } /* ------------------------------------------------------------------------ - * "Shared" connection state + * Parallel connection state * - * MyProcShared contains pieces of information about the client that need to be - * synced to parallel workers when they initialize. Over time, this list will - * probably grow, and may subsume some of the "user state" variables above. + * MyParallelProcInfo contains pieces of information about the client that need + * to be synced to parallel workers when they initialize. Over time, this list + * will probably grow, and may subsume some of the "user state" variables above. *------------------------------------------------------------------------- */ -SharedPort MyProcShared; +ParallelProcInfo MyParallelProcInfo; /* - * Calculate the space needed to serialize MyProcShared. + * Calculate the space needed to serialize MyParallelProcInfo. */ Size -EstimateSharedPortSpace(void) +EstimateParallelProcInfoSpace(void) { Size size = 1; - if (MyProcShared.authn_id) - size = add_size(size, strlen(MyProcShared.authn_id) + 1); + if (MyParallelProcInfo.authn_id) + size = add_size(size, strlen(MyParallelProcInfo.authn_id) + 1); return size; } /* - * Serialize MyProcShared for use by parallel workers. + * Serialize MyParallelProcInfo for use by parallel workers. */ void -SerializeSharedPort(Size maxsize, char *start_address) +SerializeParallelProcInfo(Size maxsize, char *start_address) { /* * First byte is an indication of whether or not authn_id has been set to * non-NULL, to differentiate that case from the empty string. */ Assert(maxsize > 0); - start_address[0] = MyProcShared.authn_id ? 1 : 0; + start_address[0] = MyParallelProcInfo.authn_id ? 1 : 0; start_address++; maxsize--; - if (MyProcShared.authn_id) + if (MyParallelProcInfo.authn_id) { Size len; - len = strlcpy(start_address, MyProcShared.authn_id, maxsize) + 1; + len = strlcpy(start_address, MyParallelProcInfo.authn_id, maxsize) + 1; Assert(len <= maxsize); maxsize -= len; start_address += len; @@ -981,22 +981,22 @@ SerializeSharedPort(Size maxsize, char *start_address) } /* - * Restore MyProcShared from its serialized representation. + * Restore MyParallelProcInfo from its serialized representation. */ void -RestoreSharedPort(char *sharedport) +RestoreParallelProcInfo(char *procinfo) { - if (sharedport[0] == 0) + if (procinfo[0] == 0) { - MyProcShared.authn_id = NULL; - sharedport++; + MyParallelProcInfo.authn_id = NULL; + procinfo++; } else { - sharedport++; - MyProcShared.authn_id = MemoryContextStrdup(TopMemoryContext, - sharedport); - sharedport += strlen(sharedport) + 1; + procinfo++; + MyParallelProcInfo.authn_id = MemoryContextStrdup(TopMemoryContext, + procinfo); + procinfo += strlen(procinfo) + 1; } } diff --git a/src/include/libpq/libpq-be.h b/src/include/libpq/libpq-be.h index 911b8246ce..5cc4091216 100644 --- a/src/include/libpq/libpq-be.h +++ b/src/include/libpq/libpq-be.h @@ -101,10 +101,10 @@ typedef struct /* * Fields from Port that need to be copied over to parallel workers go into the - * SharedPort. The same rules apply for allocations here as for Port (must be - * malloc'd or palloc'd in TopMemoryContext). + * ParallelProcInfo. The same rules apply for allocations here as for Port (must + * be malloc'd or palloc'd in TopMemoryContext). */ -typedef struct SharedPort +typedef struct { /* * Authenticated identity. The meaning of this identifier is dependent on @@ -118,7 +118,7 @@ typedef struct SharedPort * example if the "trust" auth method is in use. */ const char *authn_id; -} SharedPort; +} ParallelProcInfo; /* * This is used by the postmaster in its communication with frontends. It @@ -336,7 +336,7 @@ extern ssize_t be_gssapi_write(Port *port, void *ptr, size_t len); #endif /* ENABLE_GSS */ extern ProtocolVersion FrontendProtocol; -extern SharedPort MyProcShared; +extern ParallelProcInfo MyParallelProcInfo; /* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */ diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h index 68cc1517a0..7a08a73b85 100644 --- a/src/include/miscadmin.h +++ b/src/include/miscadmin.h @@ -481,9 +481,9 @@ extern void process_session_preload_libraries(void); extern void pg_bindtextdomain(const char *domain); extern bool has_rolreplication(Oid roleid); -extern Size EstimateSharedPortSpace(void); -extern void SerializeSharedPort(Size maxsize, char *start_address); -extern void RestoreSharedPort(char *sharedport); +extern Size EstimateParallelProcInfoSpace(void); +extern void SerializeParallelProcInfo(Size maxsize, char *start_address); +extern void RestoreParallelProcInfo(char *procinfo); /* in access/transam/xlog.c */ extern bool BackupInProgress(void);