8000 Per previous discussions, get rid of use of sync(2) in favor of · postgrespro/postgres@9b17855 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b17855

Browse files
committed
Per previous discussions, get rid of use of sync(2) in favor of
explicitly fsync'ing every (non-temp) file we have written since the last checkpoint. In the vast majority of cases, the burden of the fsyncs should fall on the bgwriter process not on backends. (To this end, we assume that an fsync issued by the bgwriter will force out blocks written to the same file by other processes using other file descriptors. Anyone have a problem with that?) This makes the world safe for WIN32, which ain't even got sync(2), and really makes the world safe for Unixen as well, because sync(2) never had the semantics we need: it offers no way to wait for the requested I/O to finish. Along the way, fix a bug I recently introduced in xlog recovery: file truncation replay failed to clear bufmgr buffers for the dropped blocks, which could result in 'PANIC: heap_delete_redo: no block' later on in xlog replay.
1 parent f024086 commit 9b17855

File tree

13 files changed

+766
-237
lines changed
  • include
  • 13 files changed

    +766
    -237
    lines changed

    src/backend/access/transam/clog.c

    Lines changed: 13 additions & 13 deletions
    Original file line numberDiff line numberDiff line change
    @@ -13,7 +13,7 @@
    1313
    * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
    1414
    * Portions Copyright (c) 1994, Regents of the University of California
    1515
    *
    16-
    * $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.19 2003/11/29 19:51:40 pgsql Exp $
    16+
    * $PostgreSQL: pgsql/src/backend/access/transam/clog.c,v 1.20 2004/05/31 03:47:54 tgl Exp $
    1717
    *
    1818
    *-------------------------------------------------------------------------
    1919
    */
    @@ -97,7 +97,7 @@ TransactionIdSetStatus(TransactionId xid, XidStatus status)
    9797
    Assert(status == TRANSACTION_STATUS_COMMITTED ||
    9898
    status == TRANSACTION_STATUS_ABORTED);
    9999

    100-
    LWLockAcquire(ClogCtl->locks->ControlLock, LW_EXCLUSIVE);
    100+
    LWLockAcquire(ClogCtl->ControlLock, LW_EXCLUSIVE);
    101101

    102102
    byteptr = SimpleLruReadPage(ClogCtl, pageno, xid, true);
    103103
    byteptr += byteno;
    @@ -110,7 +110,7 @@ TransactionIdSetStatus(TransactionId xid, XidStatus status)
    110110

    111111
    /* ...->page_status[slotno] = CLOG_PAGE_DIRTY; already done */
    112112

    113-
    LWLockRelease(ClogCtl->locks->ControlLock);
    113+
    LWLockRelease(ClogCtl->ControlLock);
    114114
    }
    115115

    116116
    /*
    @@ -128,14 +128,14 @@ TransactionIdGetStatus(TransactionId xid)
    128128
    char *byteptr;
    129129
    XidStatus status;
    130130

    131-
    LWLockAcquire(ClogCtl->locks->ControlLock, LW_EXCLUSIVE);
    131+
    LWLockAcquire(ClogCtl->ControlLock, LW_EXCLUSIVE);
    132132

    133133
    byteptr = SimpleLruReadPage(ClogCtl, pageno, xid, false);
    134134
    byteptr += byteno;
    135135

    136136
    status = (*byteptr >> bshift) & CLOG_XACT_BITMASK;
    137137

    138-
    LWLockRelease(ClogCtl->locks->ControlLock);
    138+
    LWLockRelease(ClogCtl->ControlLock);
    139139

    140140
    return status;
    141141
    }
    @@ -169,16 +169,16 @@ BootStrapCLOG(void)
    169169
    {
    170170
    int slotno;
    171171

    172-
    LWLockAcquire(ClogCtl->locks->ControlLock, LW_EXCLUSIVE);
    172+
    LWLockAcquire(ClogCtl->ControlLock, LW_EXCLUSIVE);
    173173

    174174
    /* Create and zero the first page of the commit log */
    175175
    slotno = ZeroCLOGPage(0, false);
    176176

    177177
    /* Make sure it's written out */
    178-
    SimpleLruWritePage(ClogCtl, slotno);
    178+
    SimpleLruWritePage(ClogCtl, slotno, NULL);
    179179
    /* Assert(ClogCtl->page_status[slotno] == CLOG_PAGE_CLEAN); */
    180180

    181-
    LWLockRelease(ClogCtl->locks->ControlLock);
    181+
    LWLockRelease(ClogCtl->ControlLock);
    182182
    }
    183183

    184184
    /*
    @@ -256,12 +256,12 @@ ExtendCLOG(TransactionId newestXact)
    256256

    257257
    pageno = TransactionIdToPage(newestXact);
    258258

    259-
    LWLockAcquire(ClogCtl->locks->ControlLock, LW_EXCLUSIVE);
    259+
    LWLockAcquire(ClogCtl->ControlLock, LW_EXCLUSIVE);
    260260

    261261
    /* Zero the page and make an XLOG entry about it */
    262262
    ZeroCLOGPage(pageno, true);
    263263

    264-
    LWLockRelease(ClogCtl->locks->ControlLock);
    264+
    LWLockRelease(ClogCtl->ControlLock);
    265265
    }
    266266

    267267

    @@ -351,13 +351,13 @@ clog_redo(XLogRecPtr lsn, XLogRecord *record)
    351351

    352352
    memcpy(&pageno, XLogRecGetData(record), sizeof(int));
    353353

    354-
    LWLockAcquire(ClogCtl->locks->ControlLock, LW_EXCLUSIVE);
    354+
    LWLockAcquire(ClogCtl->ControlLock, LW_EXCLUSIVE);
    355355

    356356
    slotno = ZeroCLOGPage(pageno, false);
    357-
    SimpleLruWritePage(ClogCtl, slotno);
    357+
    SimpleLruWritePage(ClogCtl, slotno, NULL);
    358358
    /* Assert(ClogCtl->page_status[slotno] == SLRU_PAGE_CLEAN); */
    359359

    360-
    LWLockRelease(ClogCtl->locks->ControlLock);
    360+
    LWLockRelease(ClogCtl->ControlLock);
    361361
    }
    362362
    }
    363363

    0 commit comments

    Comments
     (0)
    0