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

Commit 10ed487

Browse files
committed
[PGPRO-4074] Multimaster and temp tables.
1) Allow on request to prepare xacts who manipulated temp tables. We don't have any special handling of related problems, but they don't seem to be too troubling. 2) Disarm autovacuum from dropping mtm temp tables on receiver side. 3) Remove assert that temp nsp is not set during SetTempNamespaceState (also for pooler). 4) Export on_commits. Cherry pick of commit 48de7232ea2eb580c4c349c23245df86d0c08a08 Author: Stas Kelvich <stanconn@gmail.com> Date: Tue Jan 21 19:37:23 2020 +0300 [MM-SUPPORT] rework temp relations handling commit 25ba3642e66b8e814d500ab5c28854644ffbcdd0 Author: Alexey Kondratov <kondratov.aleksey@gmail.com> Date: Fri May 22 19:31:16 2020 +0300 [MM-SUPPORT] Compatibility with d7684c38a5e: save temp tables in MM from autovacuum commit d09da98271d0df71968fa0d8cacf574ad360a54a Author: Stas Kelvich <stanconn@gmail.com> Date: Tue Mar 3 13:05:41 2020 +0300 do not try to estimate relation size for mm temp table at receiver side (cherry picked from commit d09da98271d0df71968fa0d8cacf574ad360a54a) tags: multimaster, connpool (cherry picked from commit 3586623c83aa50629a12131a999fc0eb7764ef04)
1 parent a375951 commit 10ed487

File tree

5 files changed

+56
-4
lines changed

5 files changed

+56
-4
lines changed

src/backend/access/transam/xact.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ TransactionId *ParallelCurrentXids;
118118
*/
119119
int MyXactFlags;
120120

121+
/* MTM-CRUTCH: allow to prepare transactions with temp objects */
122+
bool AllowTempIn2PC;
123+
121124
/*
122125
* transaction states - transaction state from server perspective
123126
*/
@@ -2390,7 +2393,14 @@ PrepareTransaction(void)
23902393
* cases, such as a temp table created and dropped all within the
23912394
* transaction. That seems to require much more bookkeeping though.
23922395
*/
2393-
if ((MyXactFlags & XACT_FLAGS_ACCESSEDTEMPNAMESPACE))
2396+
2397+
/*
2398+
* MTM-CRUTCH: allow to proceed if requested via AllowTempIn2PC.
2399+
* Note that for now we just ignore the problems stated above, there is
2400+
* no special handling for that. Backend who can't exit until xact is
2401+
* resolved is ok in mm: we can't do much while it hangs around anyway.
2402+
*/
2403+
if (!AllowTempIn2PC && (MyXactFlags & XACT_FLAGS_ACCESSEDTEMPNAMESPACE))
23942404
ereport(ERROR,
23952405
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
23962406
errmsg("cannot PREPARE a transaction that has operated on temporary objects")));

src/backend/catalog/namespace.c

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3224,6 +3224,27 @@ isOtherTempNamespace(Oid namespaceId)
32243224
return isAnyTempNamespace(namespaceId);
32253225
}
32263226

3227+
/*
3228+
* MTM-CRUTCH for temp table.
3229+
*
3230+
* From avtovacuum point of view temp schemas in multimaster
3231+
* receivers are not used. Setting proc->tempNamespaceId would not be enough
3232+
* since 'mtm_temp_' schemas can be moved between pool workers.
3233+
*
3234+
* XXX: add cleanup for crashed backends.
3235+
*/
3236+
bool
3237+
isMtmTemp(Oid namespaceId)
3238+
{
3239+
char *nspname;
3240+
3241+
nspname = get_namespace_name(namespaceId);
3242+
if (!nspname)
3243+
return false;
3244+
3245+
return strncmp(nspname, "mtm_tmp_", 8) == 0;
3246+
}
3247+
32273248
/*
32283249
* checkTempNamespaceStatus - is the given namespace owned and actively used
32293250
* by a backend?
@@ -3241,6 +3262,9 @@ checkTempNamespaceStatus(Oid namespaceId)
32413262

32423263
Assert(OidIsValid(MyDatabaseId));
32433264

3265+
if (isMtmTemp(namespaceId))
3266+
return TEMP_NAMESPACE_IN_USE;
3267+
32443268
backendId = GetTempNamespaceBackendId(namespaceId);
32453269

32463270
/* No such namespace, or its name shows it's not temp? */
@@ -3328,9 +3352,13 @@ GetTempNamespaceState(Oid *tempNamespaceId, Oid *tempToastNamespaceId)
33283352
void
33293353
SetTempNamespaceState(Oid tempNamespaceId, Oid tempToastNamespaceId)
33303354
{
3331-
/* Worker should not have created its own namespaces ... */
3332-
Assert(myTempNamespace == InvalidOid);
3333-
Assert(myTempToastNamespace == InvalidOid);
3355+
/*
3356+
* However in case of multimaster or pooler that is legit.
3357+
* MTM-CRUTCH.
3358+
*
3359+
* Assert(myTempNamespace == InvalidOid);
3360+
* Assert(myTempToastNamespace == InvalidOid);
3361+
*/
33343362
Assert(myTempNamespaceSubID == InvalidSubTransactionId);
33353363

33363364
/* Assign same namespace OIDs that leader has */

src/backend/optimizer/util/plancat.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "catalog/catalog.h"
2929
#include "catalog/dependency.h"
3030
#include "catalog/heap.h"
31+
#include "catalog/namespace.h"
3132
#include "catalog/pg_am.h"
3233
#include "catalog/pg_proc.h"
3334
#include "catalog/pg_statistic_ext.h"
@@ -212,6 +213,16 @@ get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent,
212213
continue;
213214
}
214215

216+
/*
217+
* MTM-CRUTCH: Ignore empty index for multimaster temp table on
218+
* receiver.
219+
*/
220+
if (isMtmTemp(RelationGetNamespace(indexRelation)))
221+
{
222+
index_close(indexRelation, NoLock);
223+
continue;
224+
}
225+
215226
/*
216227
* Ignore partitioned indexes, since they are not usable for
217228
* queries.

src/include/access/xact.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ extern int synchronous_commit;
9595
* recording flags.
9696
*/
9797
extern int MyXactFlags;
98+
extern PGDLLIMPORT bool AllowTempIn2PC;
9899

99100
/*
100101
* XACT_FLAGS_ACCESSEDTEMPNAMESPACE - set when a temporary object is accessed.

src/include/catalog/namespace.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,6 @@ extern char *namespace_search_path;
185185
extern List *fetch_search_path(bool includeImplicit);
186186
extern int fetch_search_path_array(Oid *sarray, int sarray_len);
187187

188+
extern bool isMtmTemp(Oid namespaceId);
189+
188190
#endif /* NAMESPACE_H */

0 commit comments

Comments
 (0)