Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8b38cf3

Browse files
committed
Port connection pool to master
1 parent a556549 commit 8b38cf3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2386
-373
lines changed

contrib/test_decoding/sql/messages.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'for
2323

2424
-- test db filtering
2525
\set prevdb :DBNAME
26+
show session_pool_size;
27+
show session_pool_ports;
2628
\c template1
2729

2830
SELECT 'otherdb1' FROM pg_logical_emit_message(false, 'test', 'otherdb1');

src/backend/catalog/namespace.c

Lines changed: 84 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ static List *overrideStack = NIL;
178178
* committed its creation, depending on whether myTempNamespace is valid.
179179
*/
180180
static Oid myTempNamespace = InvalidOid;
181-
182181
static Oid myTempToastNamespace = InvalidOid;
183182

184183
static SubTransactionId myTempNamespaceSubID = InvalidSubTransactionId;
@@ -193,6 +192,7 @@ char *namespace_search_path = NULL;
193192
/* Local functions */
194193
static void recomputeNamespacePath(void);
195194
static void InitTempTableNamespace(void);
195+
static Oid GetTempTableNamespace(void);
196196
static void RemoveTempRelations(Oid tempNamespaceId);
197197
static void RemoveTempRelationsCallback(int code, Datum arg);
198198
static void NamespaceCallback(Datum arg, int cacheid, uint32 hashvalue);
@@ -460,9 +460,7 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation)
460460
if (strcmp(newRelation->schemaname, "pg_temp") == 0)
461461
{
462462
/* Initialize temp namespace if first time through */
463-
if (!OidIsValid(myTempNamespace))
464-
InitTempTableNamespace();
465-
return myTempNamespace;
463+
return GetTempTableNamespace();
466464
}
467465
/* use exact schema given */
468466
namespaceId = get_namespace_oid(newRelation->schemaname, false);
@@ -471,9 +469,7 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation)
471469
else if (newRelation->relpersistence == RELPERSISTENCE_TEMP)
472470
{
473471
/* Initialize temp namespace if first time through */
474-
if (!OidIsValid(myTempNamespace))
475-
InitTempTableNamespace();
476-
return myTempNamespace;
472+
return GetTempTableNamespace();
477473
}
478474
else
479475
{
@@ -482,8 +478,7 @@ RangeVarGetCreationNamespace(const RangeVar *newRelation)
482478
if (activeTempCreationPending)
483479
{
484480
/* Need to initialize temp namespace */
485-
InitTempTableNamespace();
486-
return myTempNamespace;
481+
return GetTempTableNamespace();
487482
}
488483
namespaceId = activeCreationNamespace;
489484
if (!OidIsValid(namespaceId))
@@ -2921,9 +2916,7 @@ LookupCreationNamespace(const char *nspname)
29212916
if (strcmp(nspname, "pg_temp") == 0)
29222917
{
29232918
/* Initialize temp namespace if first time through */
2924-
if (!OidIsValid(myTempNamespace))
2925-
InitTempTableNamespace();
2926-
return myTempNamespace;
2919+
return GetTempTableNamespace();
29272920
}
29282921

29292922
namespaceId = get_namespace_oid(nspname, false);
@@ -2986,9 +2979,7 @@ QualifiedNameGetCreationNamespace(List *names, char **objname_p)
29862979
if (strcmp(schemaname, "pg_temp") == 0)
29872980
{
29882981
/* Initialize temp namespace if first time through */
2989-
if (!OidIsValid(myTempNamespace))
2990-
InitTempTableNamespace();
2991-
return myTempNamespace;
2982+
return GetTempTableNamespace();
29922983
}
29932984
/* use exact schema given */
29942985
namespaceId = get_namespace_oid(schemaname, false);
@@ -3001,8 +2992,7 @@ QualifiedNameGetCreationNamespace(List *names, char **objname_p)
30012992
if (activeTempCreationPending)
30022993
{
30032994
/* Need to initialize temp namespace */
3004-
InitTempTableNamespace();
3005-
return myTempNamespace;
2995+
return GetTempTableNamespace();
30062996
}
30072997
namespaceId = activeCreationNamespace;
30082998
if (!OidIsValid(namespaceId))
@@ -3254,16 +3244,28 @@ int
32543244
GetTempNamespaceBackendId(Oid namespaceId)
32553245
{
32563246
int result;
3257-
char *nspname;
3247+
char *nspname,
3248+
*addlevel;
32583249

32593250
/* See if the namespace name starts with "pg_temp_" or "pg_toast_temp_" */
32603251
nspname = get_namespace_name(namespaceId);
32613252
if (!nspname)
32623253
return InvalidBackendId; /* no such namespace? */
32633254
if (strncmp(nspname, "pg_temp_", 8) == 0)
3264-
result = atoi(nspname + 8);
3255+
{
3256+
/* check for session id */
3257+
if ((addlevel = strstr(nspname + 8, "_")) != NULL)
3258+
result = atoi(addlevel + 1);
3259+
else
3260+
result = atoi(nspname + 8);
3261+
}
32653262
else if (strncmp(nspname, "pg_toast_temp_", 14) == 0)
3266-
result = atoi(nspname + 14);
3263+
{
3264+
if ((addlevel = strstr(nspname + 14, "_")) != NULL)
3265+
result = atoi(addlevel + 1);
3266+
else
3267+
result = atoi(nspname + 14);
3268+
}
32673269
else
32683270
result = InvalidBackendId;
32693271
pfree(nspname);
@@ -3309,8 +3311,11 @@ void
33093311
SetTempNamespaceState(Oid tempNamespaceId, Oid tempToastNamespaceId)
33103312
{
33113313
/* Worker should not have created its own namespaces ... */
3312-
Assert(myTempNamespace == InvalidOid);
3313-
Assert(myTempToastNamespace == InvalidOid);
3314+
if (!ActiveSession)
3315+
{
3316+
Assert(myTempNamespace == InvalidOid);
3317+
Assert(myTempToastNamespace == InvalidOid);
3318+
}
33143319
Assert(myTempNamespaceSubID == InvalidSubTransactionId);
33153320

33163321
/* Assign same namespace OIDs that leader has */
@@ -3830,6 +3835,24 @@ recomputeNamespacePath(void)
38303835
list_free(oidlist);
38313836
}
38323837

3838+
static Oid
3839+
GetTempTableNamespace(void)
3840+
{
3841+
if (ActiveSession)
3842+
{
3843+
if (!OidIsValid(ActiveSession->tempNamespace))
3844+
InitTempTableNamespace();
3845+
else
3846+
myTempNamespace = ActiveSession->tempNamespace;
3847+
}
3848+
else
3849+
{
3850+
if (!OidIsValid(myTempNamespace))
3851+
InitTempTableNamespace();
3852+
}
3853+
return myTempNamespace;
3854+
}
3855+
38333856
/*
38343857
* InitTempTableNamespace
38353858
* Initialize temp table namespace on first use in a particular backend
@@ -3841,8 +3864,6 @@ InitTempTableNamespace(void)
38413864
Oid namespaceId;
38423865
Oid toastspaceId;
38433866

3844-
Assert(!OidIsValid(myTempNamespace));
3845-
38463867
/*
38473868
* First, do permission check to see if we are authorized to make temp
38483869
* tables. We use a nonstandard error message here since "databasename:
@@ -3881,7 +3902,12 @@ InitTempTableNamespace(void)
38813902
(errcode(ERRCODE_READ_ONLY_SQL_TRANSACTION),
38823903
errmsg("cannot create temporary tables during a parallel operation")));
38833904

3884-
snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d", MyBackendId);
3905+
if (ActiveSession)
3906+
snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d_%u",
3907+
ActiveSession->id, MyBackendId);
3908+
else
3909+
snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d",
3910+
MyBackendId);
38853911

38863912
namespaceId = get_namespace_oid(namespaceName, true);
38873913
if (!OidIsValid(namespaceId))
@@ -3913,8 +3939,12 @@ InitTempTableNamespace(void)
39133939
* it. (We assume there is no need to clean it out if it does exist, since
39143940
* dropping a parent table should make its toast table go away.)
39153941
*/
3916-
snprintf(namespaceName, sizeof(namespaceName), "pg_toast_temp_%d",
3917-
MyBackendId);
3942+
if (ActiveSession)
3943+
snprintf(namespaceName, sizeof(namespaceName), "pg_toast_temp_%d_%u",
3944+
ActiveSession->id, MyBackendId);
3945+
else
3946+
snprintf(namespaceName, sizeof(namespaceName), "pg_toast_temp_%u",
3947+
MyBackendId);
39183948

39193949
toastspaceId = get_namespace_oid(namespaceName, true);
39203950
if (!OidIsValid(toastspaceId))
@@ -3945,6 +3975,11 @@ InitTempTableNamespace(void)
39453975
*/
39463976
MyProc->tempNamespaceId = namespaceId;
39473977

3978+
if (ActiveSession)
3979+
{
3980+
ActiveSession->tempNamespace = namespaceId;
3981+
ActiveSession->tempToastNamespace = toastspaceId;
3982+
}
39483983
/* It should not be done already. */
39493984
AssertState(myTempNamespaceSubID == InvalidSubTransactionId);
39503985
myTempNamespaceSubID = GetCurrentSubTransactionId();
@@ -3974,6 +4009,11 @@ AtEOXact_Namespace(bool isCommit, bool parallel)
39744009
{
39754010
myTempNamespace = InvalidOid;
39764011
myTempToastNamespace = InvalidOid;
4012+
if (ActiveSession)
4013+
{
4014+
ActiveSession->tempNamespace = InvalidOid;
4015+
ActiveSession->tempToastNamespace = InvalidOid;
4016+
}
39774017
baseSearchPathValid = false; /* need to rebuild list */
39784018

39794019
/*
@@ -4121,13 +4161,16 @@ RemoveTempRelations(Oid tempNamespaceId)
41214161
static void
41224162
RemoveTempRelationsCallback(int code, Datum arg)
41234163
{
4124-
if (OidIsValid(myTempNamespace)) /* should always be true */
4164+
Oid tempNamespace = ActiveSession ?
4165+
ActiveSession->tempNamespace : myTempNamespace;
4166+
4167+
if (OidIsValid(tempNamespace)) /* should always be true */
41254168
{
41264169
/* Need to ensure we have a usable transaction. */
41274170
AbortOutOfAnyTransaction();
41284171
StartTransactionCommand();
41294172

4130-
RemoveTempRelations(myTempNamespace);
4173+
RemoveTempRelations(tempNamespace);
41314174

41324175
CommitTransactionCommand();
41334176
}
@@ -4137,10 +4180,19 @@ RemoveTempRelationsCallback(int code, Datum arg)
41374180
* Remove all temp tables from the temporary namespace.
41384181
*/
41394182
void
4140-
ResetTempTableNamespace(void)
4183+
ResetTempTableNamespace(Oid npc)
41414184
{
4142-
if (OidIsValid(myTempNamespace))
4143-
RemoveTempRelations(myTempNamespace);
4185+
if (OidIsValid(npc))
4186+
{
4187+
AbortOutOfAnyTransaction();
4188+
StartTransactionCommand();
4189+
RemoveTempRelations(npc);
4190+
CommitTransactionCommand();
4191+
}
4192+
else
4193+
/* global */
4194+
if (OidIsValid(myTempNamespace))
4195+
RemoveTempRelations(myTempNamespace);
41444196
}
41454197

41464198

src/backend/catalog/pg_db_role_setting.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "catalog/indexing.h"
1717
#include "catalog/objectaccess.h"
1818
#include "catalog/pg_db_role_setting.h"
19+
#include "storage/proc.h"
1920
#include "utils/fmgroids.h"
2021
#include "utils/rel.h"
2122
#include "utils/tqual.h"

src/backend/catalog/storage.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "access/xlog.h"
2525
#include "access/xloginsert.h"
2626
#include "access/xlogutils.h"
27+
#include "catalog/namespace.h"
2728
#include "catalog/storage.h"
2829
#include "catalog/storage_xlog.h"
2930
#include "storage/freespace.h"

src/backend/commands/copy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2447,7 +2447,7 @@ CopyFrom(CopyState cstate)
24472447
* registers the snapshot it uses.
24482448
*/
24492449
InvalidateCatalogSnapshot();
2450-
if (!ThereAreNoPriorRegisteredSnapshots() || !ThereAreNoReadyPortals())
2450+
if (!ThereAreNoPriorRegisteredSnapshots() || (SessionPoolSize == 0 && !ThereAreNoReadyPortals()))
24512451
ereport(ERROR,
24522452
(errcode(ERRCODE_INVALID_TRANSACTION_STATE),
24532453
errmsg("cannot perform FREEZE because of prior transaction activity")));

src/backend/commands/discard.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ DiscardCommand(DiscardStmt *stmt, bool isTopLevel)
4545
break;
4646

4747
case DISCARD_TEMP:
48-
ResetTempTableNamespace();
48+
ResetTempTableNamespace(InvalidOid);
4949
break;
5050

5151
default:
@@ -73,6 +73,6 @@ DiscardAll(bool isTopLevel)
7373
Async_UnlistenAll();
7474
LockReleaseAll(USER_LOCKMETHOD, true);
7575
ResetPlanCache();
76-
ResetTempTableNamespace();
76+
ResetTempTableNamespace(InvalidOid);
7777
ResetSequenceCaches();
7878
}

0 commit comments

Comments
 (0)