mirror of
https://github.com/postgres/postgres.git
synced 2025-11-09 06:21:09 +03:00
Include the backend ID in the relpath of temporary relations.
This allows us to reliably remove all leftover temporary relation files on cluster startup without reference to system catalogs or WAL; therefore, we no longer include temporary relations in XLOG_XACT_COMMIT and XLOG_XACT_ABORT WAL records. Since these changes require including a backend ID in each SharedInvalSmgrMsg, the size of the SharedInvalidationMessage.id field has been reduced from two bytes to one, and the maximum number of connections has been reduced from INT_MAX / 4 to 2^23-1. It would be possible to remove these restrictions by increasing the size of SharedInvalidationMessage by 4 bytes, but right now that doesn't seem like a good trade-off. Review by Jaime Casanova and Tom Lane.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.62 2010/07/06 19:18:55 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/twophase.c,v 1.63 2010/08/13 20:10:50 rhaas Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Each global transaction is associated with a global transaction
|
||||
@@ -865,8 +865,8 @@ StartPrepare(GlobalTransaction gxact)
|
||||
hdr.prepared_at = gxact->prepared_at;
|
||||
hdr.owner = gxact->owner;
|
||||
hdr.nsubxacts = xactGetCommittedChildren(&children);
|
||||
hdr.ncommitrels = smgrGetPendingDeletes(true, &commitrels, NULL);
|
||||
hdr.nabortrels = smgrGetPendingDeletes(false, &abortrels, NULL);
|
||||
hdr.ncommitrels = smgrGetPendingDeletes(true, &commitrels);
|
||||
hdr.nabortrels = smgrGetPendingDeletes(false, &abortrels);
|
||||
hdr.ninvalmsgs = xactGetCommittedInvalidationMessages(&invalmsgs,
|
||||
&hdr.initfileinval);
|
||||
StrNCpy(hdr.gid, gxact->gid, GIDSIZE);
|
||||
@@ -1320,13 +1320,13 @@ FinishPreparedTransaction(const char *gid, bool isCommit)
|
||||
}
|
||||
for (i = 0; i < ndelrels; i++)
|
||||
{
|
||||
SMgrRelation srel = smgropen(delrels[i]);
|
||||
SMgrRelation srel = smgropen(delrels[i], InvalidBackendId);
|
||||
ForkNumber fork;
|
||||
|
||||
for (fork = 0; fork <= MAX_FORKNUM; fork++)
|
||||
{
|
||||
if (smgrexists(srel, fork))
|
||||
smgrdounlink(srel, fork, false, false);
|
||||
smgrdounlink(srel, fork, false);
|
||||
}
|
||||
smgrclose(srel);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.297 2010/08/13 15:42:21 rhaas Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.298 2010/08/13 20:10:50 rhaas Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -912,7 +912,6 @@ RecordTransactionCommit(void)
|
||||
TransactionId latestXid = InvalidTransactionId;
|
||||
int nrels;
|
||||
RelFileNode *rels;
|
||||
bool haveNonTemp;
|
||||
int nchildren;
|
||||
TransactionId *children;
|
||||
int nmsgs = 0;
|
||||
@@ -920,7 +919,7 @@ RecordTransactionCommit(void)
|
||||
bool RelcacheInitFileInval = false;
|
||||
|
||||
/* Get data needed for commit record */
|
||||
nrels = smgrGetPendingDeletes(true, &rels, &haveNonTemp);
|
||||
nrels = smgrGetPendingDeletes(true, &rels);
|
||||
nchildren = xactGetCommittedChildren(&children);
|
||||
if (XLogStandbyInfoActive())
|
||||
nmsgs = xactGetCommittedInvalidationMessages(&invalMessages,
|
||||
@@ -1048,7 +1047,7 @@ RecordTransactionCommit(void)
|
||||
* asynchronous commit if all to-be-deleted tables are temporary though,
|
||||
* since they are lost anyway if we crash.)
|
||||
*/
|
||||
if (XactSyncCommit || forceSyncCommit || haveNonTemp)
|
||||
if (XactSyncCommit || forceSyncCommit || nrels > 0)
|
||||
{
|
||||
/*
|
||||
* Synchronous commit case:
|
||||
@@ -1334,7 +1333,7 @@ RecordTransactionAbort(bool isSubXact)
|
||||
xid);
|
||||
|
||||
/* Fetch the data we need for the abort record */
|
||||
nrels = smgrGetPendingDeletes(false, &rels, NULL);
|
||||
nrels = smgrGetPendingDeletes(false, &rels);
|
||||
nchildren = xactGetCommittedChildren(&children);
|
||||
|
||||
/* XXX do we really need a critical section here? */
|
||||
@@ -4474,7 +4473,7 @@ xact_redo_commit(xl_xact_commit *xlrec, TransactionId xid, XLogRecPtr lsn)
|
||||
/* Make sure files supposed to be dropped are dropped */
|
||||
for (i = 0; i < xlrec->nrels; i++)
|
||||
{
|
||||
SMgrRelation srel = smgropen(xlrec->xnodes[i]);
|
||||
SMgrRelation srel = smgropen(xlrec->xnodes[i], InvalidBackendId);
|
||||
ForkNumber fork;
|
||||
|
||||
for (fork = 0; fork <= MAX_FORKNUM; fork++)
|
||||
@@ -4482,7 +4481,7 @@ xact_redo_commit(xl_xact_commit *xlrec, TransactionId xid, XLogRecPtr lsn)
|
||||
if (smgrexists(srel, fork))
|
||||
{
|
||||
XLogDropRelation(xlrec->xnodes[i], fork);
|
||||
smgrdounlink(srel, fork, false, true);
|
||||
smgrdounlink(srel, fork, true);
|
||||
}
|
||||
}
|
||||
smgrclose(srel);
|
||||
@@ -4579,7 +4578,7 @@ xact_redo_abort(xl_xact_abort *xlrec, TransactionId xid)
|
||||
/* Make sure files supposed to be dropped are dropped */
|
||||
for (i = 0; i < xlrec->nrels; i++)
|
||||
{
|
||||
SMgrRelation srel = smgropen(xlrec->xnodes[i]);
|
||||
SMgrRelation srel = smgropen(xlrec->xnodes[i], InvalidBackendId);
|
||||
ForkNumber fork;
|
||||
|
||||
for (fork = 0; fork <= MAX_FORKNUM; fork++)
|
||||
@@ -4587,7 +4586,7 @@ xact_redo_abort(xl_xact_abort *xlrec, TransactionId xid)
|
||||
if (smgrexists(srel, fork))
|
||||
{
|
||||
XLogDropRelation(xlrec->xnodes[i], fork);
|
||||
smgrdounlink(srel, fork, false, true);
|
||||
smgrdounlink(srel, fork, true);
|
||||
}
|
||||
}
|
||||
smgrclose(srel);
|
||||
@@ -4661,7 +4660,7 @@ xact_desc_commit(StringInfo buf, xl_xact_commit *xlrec)
|
||||
appendStringInfo(buf, "; rels:");
|
||||
for (i = 0; i < xlrec->nrels; i++)
|
||||
{
|
||||
char *path = relpath(xlrec->xnodes[i], MAIN_FORKNUM);
|
||||
char *path = relpathperm(xlrec->xnodes[i], MAIN_FORKNUM);
|
||||
|
||||
appendStringInfo(buf, " %s", path);
|
||||
pfree(path);
|
||||
@@ -4716,7 +4715,7 @@ xact_desc_abort(StringInfo buf, xl_xact_abort *xlrec)
|
||||
appendStringInfo(buf, "; rels:");
|
||||
for (i = 0; i < xlrec->nrels; i++)
|
||||
{
|
||||
char *path = relpath(xlrec->xnodes[i], MAIN_FORKNUM);
|
||||
char *path = relpathperm(xlrec->xnodes[i], MAIN_FORKNUM);
|
||||
|
||||
appendStringInfo(buf, " %s", path);
|
||||
pfree(path);
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
* Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.71 2010/07/08 16:08:30 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/access/transam/xlogutils.c,v 1.72 2010/08/13 20:10:50 rhaas Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -68,7 +68,7 @@ log_invalid_page(RelFileNode node, ForkNumber forkno, BlockNumber blkno,
|
||||
*/
|
||||
if (log_min_messages <= DEBUG1 || client_min_messages <= DEBUG1)
|
||||
{
|
||||
char *path = relpath(node, forkno);
|
||||
char *path = relpathperm(node, forkno);
|
||||
|
||||
if (present)
|
||||
elog(DEBUG1, "page %u of relation %s is uninitialized",
|
||||
@@ -133,7 +133,7 @@ forget_invalid_pages(RelFileNode node, ForkNumber forkno, BlockNumber minblkno)
|
||||
{
|
||||
if (log_min_messages <= DEBUG2 || client_min_messages <= DEBUG2)
|
||||
{
|
||||
char *path = relpath(hentry->key.node, forkno);
|
||||
char *path = relpathperm(hentry->key.node, forkno);
|
||||
|
||||
elog(DEBUG2, "page %u of relation %s has been dropped",
|
||||
hentry->key.blkno, path);
|
||||
@@ -166,7 +166,7 @@ forget_invalid_pages_db(Oid dbid)
|
||||
{
|
||||
if (log_min_messages <= DEBUG2 || client_min_messages <= DEBUG2)
|
||||
{
|
||||
char *path = relpath(hentry->key.node, hentry->key.forkno);
|
||||
char *path = relpathperm(hentry->key.node, hentry->key.forkno);
|
||||
|
||||
elog(DEBUG2, "page %u of relation %s has been dropped",
|
||||
hentry->key.blkno, path);
|
||||
@@ -200,7 +200,7 @@ XLogCheckInvalidPages(void)
|
||||
*/
|
||||
while ((hentry = (xl_invalid_page *) hash_seq_search(&status)) != NULL)
|
||||
{
|
||||
char *path = relpath(hentry->key.node, hentry->key.forkno);
|
||||
char *path = relpathperm(hentry->key.node, hentry->key.forkno);
|
||||
|
||||
if (hentry->present)
|
||||
elog(WARNING, "page %u of relation %s was uninitialized",
|
||||
@@ -276,7 +276,7 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum,
|
||||
Assert(blkno != P_NEW);
|
||||
|
||||
/* Open the relation at smgr level */
|
||||
smgr = smgropen(rnode);
|
||||
smgr = smgropen(rnode, InvalidBackendId);
|
||||
|
||||
/*
|
||||
* Create the target file if it doesn't already exist. This lets us cope
|
||||
@@ -293,7 +293,7 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum,
|
||||
if (blkno < lastblock)
|
||||
{
|
||||
/* page exists in file */
|
||||
buffer = ReadBufferWithoutRelcache(rnode, false, forknum, blkno,
|
||||
buffer = ReadBufferWithoutRelcache(rnode, forknum, blkno,
|
||||
mode, NULL);
|
||||
}
|
||||
else
|
||||
@@ -312,7 +312,7 @@ XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum,
|
||||
{
|
||||
if (buffer != InvalidBuffer)
|
||||
ReleaseBuffer(buffer);
|
||||
buffer = ReadBufferWithoutRelcache(rnode, false, forknum,
|
||||
buffer = ReadBufferWithoutRelcache(rnode, forknum,
|
||||
P_NEW, mode, NULL);
|
||||
lastblock++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user