1
0
mirror of https://github.com/postgres/postgres.git synced 2025-10-25 13:17:41 +03:00

Rearrange pg_subtrans handling as per recent discussion. pg_subtrans

updates are no longer WAL-logged nor even fsync'd; we do not need to,
since after a crash no old pg_subtrans data is needed again.  We truncate
pg_subtrans to RecentGlobalXmin at each checkpoint.  slru.c's API is
refactored a little bit to separate out the necessary decisions.
This commit is contained in:
Tom Lane
2004-08-23 23:22:45 +00:00
parent 059912ce2e
commit 4dbb880d3c
13 changed files with 387 additions and 436 deletions

View File

@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/access/clog.h,v 1.9 2004/07/01 00:51:38 tgl Exp $
* $PostgreSQL: pgsql/src/include/access/clog.h,v 1.10 2004/08/23 23:22:45 tgl Exp $
*/
#ifndef CLOG_H
#define CLOG_H
@@ -27,9 +27,6 @@ typedef int XidStatus;
#define TRANSACTION_STATUS_ABORTED 0x02
#define TRANSACTION_STATUS_SUB_COMMITTED 0x03
/* exported because lwlock.c needs it */
#define NUM_CLOG_BUFFERS 8
extern void TransactionIdSetStatus(TransactionId xid, XidStatus status);
extern XidStatus TransactionIdGetStatus(TransactionId xid);
@@ -42,6 +39,12 @@ extern void ShutdownCLOG(void);
extern void CheckPointCLOG(void);
extern void ExtendCLOG(TransactionId newestXact);
extern void TruncateCLOG(TransactionId oldestXact);
extern void clog_zeropage_redo(int pageno);
/* XLOG stuff */
#define CLOG_ZEROPAGE 0x00
extern void clog_redo(XLogRecPtr lsn, XLogRecord *record);
extern void clog_undo(XLogRecPtr lsn, XLogRecord *record);
extern void clog_desc(char *buf, uint8 xl_info, char *rec);
#endif /* CLOG_H */

View File

@@ -3,7 +3,7 @@
*
* Resource managers definition
*
* $PostgreSQL: pgsql/src/include/access/rmgr.h,v 1.11 2004/07/01 00:51:38 tgl Exp $
* $PostgreSQL: pgsql/src/include/access/rmgr.h,v 1.12 2004/08/23 23:22:45 tgl Exp $
*/
#ifndef RMGR_H
#define RMGR_H
@@ -16,7 +16,7 @@ typedef uint8 RmgrId;
#define RM_XLOG_ID 0
#define RM_XACT_ID 1
#define RM_SMGR_ID 2
#define RM_SLRU_ID 3
#define RM_CLOG_ID 3
#define RM_HEAP_ID 10
#define RM_BTREE_ID 11
#define RM_HASH_ID 12

View File

@@ -1,23 +1,66 @@
/*
/*-------------------------------------------------------------------------
*
* slru.h
* Simple LRU buffering for transaction status logfiles
*
* Simple LRU
*
* Portions Copyright (c) 2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/access/slru.h,v 1.7 2004/07/01 00:51:38 tgl Exp $
* $PostgreSQL: pgsql/src/include/access/slru.h,v 1.8 2004/08/23 23:22:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef SLRU_H
#define SLRU_H
#include "access/xlog.h"
#include "storage/lwlock.h"
/* Opaque structs known only in slru.c */
typedef struct SlruSharedData *SlruShared;
typedef struct SlruFlushData *SlruFlush;
/*
* Number of page buffers. Ideally this could be different for CLOG and
* SUBTRANS, but the benefit doesn't seem to be worth any additional
* notational cruft.
*/
#define NUM_SLRU_BUFFERS 8
/* Page status codes */
typedef enum
{
SLRU_PAGE_EMPTY, /* buffer is not in use */
SLRU_PAGE_READ_IN_PROGRESS, /* page is being read in */
SLRU_PAGE_CLEAN, /* page is valid and not dirty */
SLRU_PAGE_DIRTY, /* page is valid but needs write */
SLRU_PAGE_WRITE_IN_PROGRESS /* page is being written out */
} SlruPageStatus;
/*
* Shared-memory state
*/
typedef struct SlruSharedData
{
LWLockId ControlLock;
/*
* Info for each buffer slot. Page number is undefined when status is
* EMPTY. lru_count is essentially the number of page switches since
* last use of this page; the page with highest lru_count is the best
* candidate to replace.
*/
char *page_buffer[NUM_SLRU_BUFFERS];
SlruPageStatus page_status[NUM_SLRU_BUFFERS];
int page_number[NUM_SLRU_BUFFERS];
unsigned int page_lru_count[NUM_SLRU_BUFFERS];
LWLockId buffer_locks[NUM_SLRU_BUFFERS];
/*
* latest_page_number is the page number of the current end of the
* log; this is not critical data, since we use it only to avoid
* swapping out the latest page.
*/
int latest_page_number;
} SlruSharedData;
typedef SlruSharedData *SlruShared;
/*
* SlruCtlData is an unshared structure that points to the active information
@@ -27,13 +70,11 @@ typedef struct SlruCtlData
{
SlruShared shared;
LWLockId ControlLock;
/*
* Dir is set during SimpleLruInit and does not change thereafter.
* Since it's always the same, it doesn't need to be in shared memory.
* This flag tells whether to fsync writes (true for pg_clog,
* false for pg_subtrans).
*/
char Dir[MAXPGPATH];
bool do_fsync;
/*
* Decide which of two page numbers is "older" for truncation purposes.
@@ -42,27 +83,27 @@ typedef struct SlruCtlData
*/
bool (*PagePrecedes) (int, int);
/*
* Dir is set during SimpleLruInit and does not change thereafter.
* Since it's always the same, it doesn't need to be in shared memory.
*/
char Dir[MAXPGPATH];
} SlruCtlData;
typedef SlruCtlData *SlruCtl;
/* Opaque struct known only in slru.c */
typedef struct SlruFlushData *SlruFlush;
extern int SimpleLruShmemSize(void);
extern void SimpleLruInit(SlruCtl ctl, const char *name, const char *subdir);
extern void SimpleLruInit(SlruCtl ctl, const char *name,
LWLockId ctllock, const char *subdir);
extern int SimpleLruZeroPage(SlruCtl ctl, int pageno);
extern char *SimpleLruReadPage(SlruCtl ctl, int pageno,
TransactionId xid, bool forwrite);
extern int SimpleLruReadPage(SlruCtl ctl, int pageno, TransactionId xid);
extern void SimpleLruWritePage(SlruCtl ctl, int slotno, SlruFlush fdata);
extern void SimpleLruSetLatestPage(SlruCtl ctl, int pageno);
extern void SimpleLruFlush(SlruCtl ctl, bool checkpoint);
extern void SimpleLruTruncate(SlruCtl ctl, int cutoffPage);
/* XLOG stuff */
#define CLOG_ZEROPAGE 0x00
#define SUBTRANS_ZEROPAGE 0x10
extern void slru_redo(XLogRecPtr lsn, XLogRecord *record);
extern void slru_undo(XLogRecPtr lsn, XLogRecord *record);
extern void slru_desc(char *buf, uint8 xl_info, char *rec);
extern bool SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions);
#endif /* SLRU_H */

View File

@@ -1,22 +1,16 @@
/*
* subtrans.h
*
* PostgreSQL subtrans-log manager
* PostgreSQL subtransaction-log manager
*
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/access/subtrans.h,v 1.2 2004/08/22 02:41:58 tgl Exp $
* $PostgreSQL: pgsql/src/include/access/subtrans.h,v 1.3 2004/08/23 23:22:45 tgl Exp $
*/
#ifndef SUBTRANS_H
#define SUBTRANS_H
#include "access/xlog.h"
/* exported because lwlock.c needs it */
/* cannot be different from NUM_CLOG_BUFFERS without slru.c changes */
#define NUM_SUBTRANS_BUFFERS NUM_CLOG_BUFFERS
extern void SubTransSetParent(TransactionId xid, TransactionId parent);
extern TransactionId SubTransGetParent(TransactionId xid);
extern TransactionId SubTransGetTopmostTransaction(TransactionId xid);
@@ -29,6 +23,5 @@ extern void ShutdownSUBTRANS(void);
extern void CheckPointSUBTRANS(void);
extern void ExtendSUBTRANS(TransactionId newestXact);
extern void TruncateSUBTRANS(TransactionId oldestXact);
extern void subtrans_zeropage_redo(int pageno);
#endif /* SUBTRANS_H */