From a12d07ebb10e98e6caad731e1ff545a9af08d42f Mon Sep 17 00:00:00 2001 From: Pavan Deolasee Date: Sun, 17 Jan 2016 19:31:01 +0530 Subject: [PATCH] WAL log only the actual GID instead of the entire GIDSIZE data While GIDSIZE is set to quite high (actually, in XL its even more than 200 bytes currently defined in PG), in practice, the GID will be much smaller in length. So instead of WAL logging the entire GIDSIZE data, we only log the actual GID string. This shows considerable improvement for XL --- src/backend/access/transam/twophase.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/backend/access/transam/twophase.c b/src/backend/access/transam/twophase.c index 2a5d43ed9c..3feeb74de1 100644 --- a/src/backend/access/transam/twophase.c +++ b/src/backend/access/transam/twophase.c @@ -889,7 +889,7 @@ typedef struct TwoPhaseFileHeader int32 nabortrels; /* number of delete-on-abort rels */ int32 ninvalmsgs; /* number of cache invalidation messages */ bool initfileinval; /* does relcache init file need invalidation? */ - char gid[GIDSIZE]; /* GID for transaction */ + uint32 gidlen; /* length of the GID */ } TwoPhaseFileHeader; /* @@ -1000,9 +1000,10 @@ StartPrepare(GlobalTransaction gxact) hdr.nabortrels = smgrGetPendingDeletes(false, &abortrels); hdr.ninvalmsgs = xactGetCommittedInvalidationMessages(&invalmsgs, &hdr.initfileinval); - StrNCpy(hdr.gid, gxact->gid, GIDSIZE); + hdr.gidlen = strlen(gxact->gid); save_state_data(&hdr, sizeof(TwoPhaseFileHeader)); + save_state_data(gxact->gid, hdr.gidlen); /* * Add the additional info about subxacts, deletable files and cache @@ -1424,6 +1425,7 @@ FinishPreparedTransaction(const char *gid, bool isCommit) hdr = (TwoPhaseFileHeader *) buf; Assert(TransactionIdEquals(hdr->xid, xid)); bufptr = buf + MAXALIGN(sizeof(TwoPhaseFileHeader)); + bufptr += MAXALIGN(hdr->gidlen); children = (TransactionId *) bufptr; bufptr += MAXALIGN(hdr->nsubxacts * sizeof(TransactionId)); commitrels = (RelFileNode *) bufptr; @@ -2004,6 +2006,7 @@ RecoverPreparedTransactions(void) TwoPhaseFileHeader *hdr; TransactionId *subxids; GlobalTransaction gxact; + const char *gid; int i; xid = (TransactionId) strtoul(clde->d_name, NULL, 16); @@ -2036,6 +2039,8 @@ RecoverPreparedTransactions(void) hdr = (TwoPhaseFileHeader *) buf; Assert(TransactionIdEquals(hdr->xid, xid)); bufptr = buf + MAXALIGN(sizeof(TwoPhaseFileHeader)); + gid = (const char *) bufptr; + bufptr += MAXALIGN(hdr->gidlen); subxids = (TransactionId *) bufptr; bufptr += MAXALIGN(hdr->nsubxacts * sizeof(TransactionId)); bufptr += MAXALIGN(hdr->ncommitrels * sizeof(RelFileNode)); @@ -2071,7 +2076,7 @@ RecoverPreparedTransactions(void) * negligible (especially since we know the state file has already * been fsynced). */ - gxact = MarkAsPreparing(xid, hdr->gid, + gxact = MarkAsPreparing(xid, gid, hdr->prepared_at, hdr->owner, hdr->database); GXactLoadSubxactData(gxact, hdr->nsubxacts, subxids); -- 2.39.5