mirror of
https://github.com/postgres/postgres.git
synced 2025-10-27 00:12:01 +03:00
Support an optional asynchronous commit mode, in which we don't flush WAL
before reporting a transaction committed. Data consistency is still guaranteed (unlike setting fsync = off), but a crash may lose the effects of the last few transactions. Patch by Simon, some editorialization by Tom.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/clog.h,v 1.19 2007/01/05 22:19:50 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/clog.h,v 1.20 2007/08/01 22:45:09 tgl Exp $
|
||||
*/
|
||||
#ifndef CLOG_H
|
||||
#define CLOG_H
|
||||
@@ -32,8 +32,8 @@ typedef int XidStatus;
|
||||
#define NUM_CLOG_BUFFERS 8
|
||||
|
||||
|
||||
extern void TransactionIdSetStatus(TransactionId xid, XidStatus status);
|
||||
extern XidStatus TransactionIdGetStatus(TransactionId xid);
|
||||
extern void TransactionIdSetStatus(TransactionId xid, XidStatus status, XLogRecPtr lsn);
|
||||
extern XidStatus TransactionIdGetStatus(TransactionId xid, XLogRecPtr *lsn);
|
||||
|
||||
extern Size CLOGShmemSize(void);
|
||||
extern void CLOGShmemInit(void);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/gist_private.h,v 1.26 2007/01/20 18:43:35 neilc Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/gist_private.h,v 1.27 2007/08/01 22:45:09 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -200,8 +200,6 @@ typedef struct GistSplitVector
|
||||
* distributed between left and right pages */
|
||||
} GistSplitVector;
|
||||
|
||||
#define XLogRecPtrIsInvalid( r ) ( (r).xlogid == 0 && (r).xrecoff == 0 )
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Relation r;
|
||||
|
||||
@@ -6,13 +6,14 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/slru.h,v 1.20 2007/01/05 22:19:51 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/slru.h,v 1.21 2007/08/01 22:45:09 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef SLRU_H
|
||||
#define SLRU_H
|
||||
|
||||
#include "access/xlogdefs.h"
|
||||
#include "storage/lwlock.h"
|
||||
|
||||
|
||||
@@ -51,6 +52,17 @@ typedef struct SlruSharedData
|
||||
int *page_lru_count;
|
||||
LWLockId *buffer_locks;
|
||||
|
||||
/*
|
||||
* Optional array of WAL flush LSNs associated with entries in the SLRU
|
||||
* pages. If not zero/NULL, we must flush WAL before writing pages (true
|
||||
* for pg_clog, false for multixact and pg_subtrans). group_lsn[] has
|
||||
* lsn_groups_per_page entries per buffer slot, each containing the
|
||||
* highest LSN known for a contiguous group of SLRU entries on that slot's
|
||||
* page.
|
||||
*/
|
||||
XLogRecPtr *group_lsn;
|
||||
int lsn_groups_per_page;
|
||||
|
||||
/*----------
|
||||
* We mark a page "most recently used" by setting
|
||||
* page_lru_count[slotno] = ++cur_lru_count;
|
||||
@@ -81,8 +93,8 @@ typedef struct SlruCtlData
|
||||
SlruShared shared;
|
||||
|
||||
/*
|
||||
* This flag tells whether to fsync writes (true for pg_clog, false for
|
||||
* pg_subtrans).
|
||||
* This flag tells whether to fsync writes (true for pg_clog and multixact
|
||||
* stuff, false for pg_subtrans).
|
||||
*/
|
||||
bool do_fsync;
|
||||
|
||||
@@ -106,11 +118,12 @@ typedef SlruCtlData *SlruCtl;
|
||||
typedef struct SlruFlushData *SlruFlush;
|
||||
|
||||
|
||||
extern Size SimpleLruShmemSize(int nslots);
|
||||
extern void SimpleLruInit(SlruCtl ctl, const char *name, int nslots,
|
||||
extern Size SimpleLruShmemSize(int nslots, int nlsns);
|
||||
extern void SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns,
|
||||
LWLockId ctllock, const char *subdir);
|
||||
extern int SimpleLruZeroPage(SlruCtl ctl, int pageno);
|
||||
extern int SimpleLruReadPage(SlruCtl ctl, int pageno, TransactionId xid);
|
||||
extern int SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok,
|
||||
TransactionId xid);
|
||||
extern int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno,
|
||||
TransactionId xid);
|
||||
extern void SimpleLruWritePage(SlruCtl ctl, int slotno, SlruFlush fdata);
|
||||
|
||||
@@ -7,13 +7,15 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/transam.h,v 1.60 2007/01/05 22:19:51 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/transam.h,v 1.61 2007/08/01 22:45:09 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef TRANSAM_H
|
||||
#define TRANSAM_H
|
||||
|
||||
#include "access/xlogdefs.h"
|
||||
|
||||
|
||||
/* ----------------
|
||||
* Special transaction ID values
|
||||
@@ -115,14 +117,17 @@ extern VariableCache ShmemVariableCache;
|
||||
extern bool TransactionIdDidCommit(TransactionId transactionId);
|
||||
extern bool TransactionIdDidAbort(TransactionId transactionId);
|
||||
extern void TransactionIdCommit(TransactionId transactionId);
|
||||
extern void TransactionIdAsyncCommit(TransactionId transactionId, XLogRecPtr lsn);
|
||||
extern void TransactionIdAbort(TransactionId transactionId);
|
||||
extern void TransactionIdSubCommit(TransactionId transactionId);
|
||||
extern void TransactionIdCommitTree(int nxids, TransactionId *xids);
|
||||
extern void TransactionIdAsyncCommitTree(int nxids, TransactionId *xids, XLogRecPtr lsn);
|
||||
extern void TransactionIdAbortTree(int nxids, TransactionId *xids);
|
||||
extern bool TransactionIdPrecedes(TransactionId id1, TransactionId id2);
|
||||
extern bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2);
|
||||
extern bool TransactionIdFollows(TransactionId id1, TransactionId id2);
|
||||
extern bool TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2);
|
||||
extern XLogRecPtr TransactionIdGetCommitLSN(TransactionId xid);
|
||||
|
||||
/* in transam/varsup.c */
|
||||
extern TransactionId GetNewTransactionId(bool isSubXact);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/xact.h,v 1.87 2007/04/30 21:01:53 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/xact.h,v 1.88 2007/08/01 22:45:09 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -41,6 +41,9 @@ extern int XactIsoLevel;
|
||||
extern bool DefaultXactReadOnly;
|
||||
extern bool XactReadOnly;
|
||||
|
||||
/* Asynchronous commits */
|
||||
extern bool XactSyncCommit;
|
||||
|
||||
/*
|
||||
* start- and end-of-transaction callbacks for dynamically loaded modules
|
||||
*/
|
||||
@@ -147,6 +150,7 @@ extern void SetCurrentStatementStartTimestamp(void);
|
||||
extern int GetCurrentTransactionNestLevel(void);
|
||||
extern bool TransactionIdIsCurrentTransactionId(TransactionId xid);
|
||||
extern void CommandCounterIncrement(void);
|
||||
extern void ForceSyncCommit(void);
|
||||
extern void StartTransactionCommand(void);
|
||||
extern void CommitTransactionCommand(void);
|
||||
extern void AbortCurrentTransaction(void);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.81 2007/07/24 04:54:09 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/xlog.h,v 1.82 2007/08/01 22:45:09 tgl Exp $
|
||||
*/
|
||||
#ifndef XLOG_H
|
||||
#define XLOG_H
|
||||
@@ -197,8 +197,11 @@ extern CheckpointStatsData CheckpointStats;
|
||||
extern XLogRecPtr XLogInsert(RmgrId rmid, uint8 info, XLogRecData *rdata);
|
||||
extern void XLogFlush(XLogRecPtr RecPtr);
|
||||
extern void XLogBackgroundFlush(void);
|
||||
extern void XLogAsyncCommitFlush(void);
|
||||
extern bool XLogNeedsFlush(XLogRecPtr RecPtr);
|
||||
|
||||
extern void XLogSetAsyncCommitLSN(XLogRecPtr record);
|
||||
|
||||
extern void xlog_redo(XLogRecPtr lsn, XLogRecord *record);
|
||||
extern void xlog_desc(StringInfo buf, uint8 xl_info, char *rec);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $PostgreSQL: pgsql/src/include/access/xlogdefs.h,v 1.17 2007/02/14 05:00:40 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/include/access/xlogdefs.h,v 1.18 2007/08/01 22:45:09 tgl Exp $
|
||||
*/
|
||||
#ifndef XLOG_DEFS_H
|
||||
#define XLOG_DEFS_H
|
||||
@@ -33,6 +33,8 @@ typedef struct XLogRecPtr
|
||||
uint32 xrecoff; /* byte offset of location in log file */
|
||||
} XLogRecPtr;
|
||||
|
||||
#define XLogRecPtrIsInvalid(r) ((r).xrecoff == 0)
|
||||
|
||||
|
||||
/*
|
||||
* Macros for comparing XLogRecPtrs
|
||||
|
||||
Reference in New Issue
Block a user