]> granicus.if.org Git - postgresql/commitdiff
Comments about GetFreeXLBuffer().
authorVadim B. Mikheev <vadim4o@yahoo.com>
Tue, 13 Feb 2001 20:40:25 +0000 (20:40 +0000)
committerVadim B. Mikheev <vadim4o@yahoo.com>
Tue, 13 Feb 2001 20:40:25 +0000 (20:40 +0000)
GetFreeXLBuffer(): use Insert->LgwrResult instead of private LgwrResult
copy if it's more fresh (attempt to avoid acquiring info_lck/lgwr_lck).

src/backend/access/transam/xlog.c

index 8b701a85dfcc185039750420cd983aabcb7363c5..7c18f0ff5a69564c0b6b12d16d875f4086b88abf 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.52 2001/02/13 08:44:09 vadim Exp $
+ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.53 2001/02/13 20:40:25 vadim Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -612,6 +612,7 @@ begin:;
        if (updrqst)
        {
                S_LOCK(&(XLogCtl->info_lck));
+               LgwrResult = XLogCtl->LgwrResult;
                if (XLByteLT(XLogCtl->LgwrRqst.Write, LgwrRqst.Write))
                        XLogCtl->LgwrRqst.Write = LgwrRqst.Write;
                S_UNLOCK(&(XLogCtl->info_lck));
@@ -760,6 +761,10 @@ XLogFlush(XLogRecPtr record)
 
 }
 
+/*
+ * We use this routine when Insert->curridx block is full and the next XLOG
+ * buffer looks as unwritten to OS' cache. insert_lck is assumed here.
+ */
 static void
 GetFreeXLBuffer()
 {
@@ -768,12 +773,24 @@ GetFreeXLBuffer()
        uint16          curridx = NextBufIdx(Insert->curridx);
        unsigned        spins = 0;
 
+       /* Use Insert->LgwrResult copy if it's more fresh */
+       if (XLByteLT(LgwrResult.Write, Insert->LgwrResult.Write))
+       {
+               LgwrResult = Insert->LgwrResult;
+               if (XLByteLE(XLogCtl->xlblocks[curridx], LgwrResult.Write))
+               {
+                       InitXLBuffer(curridx);
+                       return;
+               }
+       }
+
        LgwrRqst.Write = XLogCtl->xlblocks[Insert->curridx];
        for (;;)
        {
                if (!TAS(&(XLogCtl->info_lck)))
                {
                        LgwrResult = XLogCtl->LgwrResult;
+                       /* LgwrRqst.Write GE XLogCtl->LgwrRqst.Write */
                        XLogCtl->LgwrRqst.Write = LgwrRqst.Write;
                        S_UNLOCK(&(XLogCtl->info_lck));
                        if (XLByteLE(XLogCtl->xlblocks[curridx], LgwrResult.Write))