2004-08-24 01:22:45 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
2003-06-12 00:37:46 +02:00
|
|
|
*
|
2004-08-24 01:22:45 +02:00
|
|
|
* slru.h
|
|
|
|
* Simple LRU buffering for transaction status logfiles
|
2003-06-12 00:37:46 +02:00
|
|
|
*
|
2007-01-05 23:20:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
|
2003-06-12 00:37:46 +02:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
|
|
|
*
|
2007-01-05 23:20:05 +01:00
|
|
|
* $PostgreSQL: pgsql/src/include/access/slru.h,v 1.20 2007/01/05 22:19:51 momjian Exp $
|
2004-08-24 01:22:45 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
2003-06-12 00:37:46 +02:00
|
|
|
*/
|
|
|
|
#ifndef SLRU_H
|
|
|
|
#define SLRU_H
|
|
|
|
|
2004-05-31 05:48:10 +02:00
|
|
|
#include "storage/lwlock.h"
|
2003-06-12 00:37:46 +02:00
|
|
|
|
|
|
|
|
2005-11-05 22:19:47 +01:00
|
|
|
/*
|
|
|
|
* Page status codes. Note that these do not include the "dirty" bit.
|
|
|
|
* page_dirty can be TRUE only in the VALID or WRITE_IN_PROGRESS states;
|
|
|
|
* in the latter case it implies that the page has been re-dirtied since
|
|
|
|
* the write started.
|
|
|
|
*/
|
2004-08-24 01:22:45 +02:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
SLRU_PAGE_EMPTY, /* buffer is not in use */
|
|
|
|
SLRU_PAGE_READ_IN_PROGRESS, /* page is being read in */
|
2005-11-05 22:19:47 +01:00
|
|
|
SLRU_PAGE_VALID, /* page is valid and not being written */
|
2004-08-24 01:22:45 +02:00
|
|
|
SLRU_PAGE_WRITE_IN_PROGRESS /* page is being written out */
|
|
|
|
} SlruPageStatus;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Shared-memory state
|
|
|
|
*/
|
|
|
|
typedef struct SlruSharedData
|
|
|
|
{
|
|
|
|
LWLockId ControlLock;
|
|
|
|
|
2005-12-07 00:08:34 +01:00
|
|
|
/* Number of buffers managed by this SLRU structure */
|
|
|
|
int num_slots;
|
|
|
|
|
2004-08-24 01:22:45 +02:00
|
|
|
/*
|
2005-12-07 00:08:34 +01:00
|
|
|
* Arrays holding info for each buffer slot. Page number is undefined
|
|
|
|
* when status is EMPTY, as is page_lru_count.
|
2004-08-24 01:22:45 +02:00
|
|
|
*/
|
2005-12-07 00:08:34 +01:00
|
|
|
char **page_buffer;
|
|
|
|
SlruPageStatus *page_status;
|
|
|
|
bool *page_dirty;
|
|
|
|
int *page_number;
|
|
|
|
int *page_lru_count;
|
|
|
|
LWLockId *buffer_locks;
|
2004-08-24 01:22:45 +02:00
|
|
|
|
2005-12-06 19:10:06 +01:00
|
|
|
/*----------
|
|
|
|
* We mark a page "most recently used" by setting
|
|
|
|
* page_lru_count[slotno] = ++cur_lru_count;
|
|
|
|
* The oldest page is therefore the one with the highest value of
|
|
|
|
* cur_lru_count - page_lru_count[slotno]
|
|
|
|
* The counts will eventually wrap around, but this calculation still
|
|
|
|
* works as long as no page's age exceeds INT_MAX counts.
|
|
|
|
*----------
|
|
|
|
*/
|
|
|
|
int cur_lru_count;
|
|
|
|
|
2004-08-24 01:22:45 +02:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* 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.
|
2004-08-24 01:22:45 +02:00
|
|
|
*/
|
|
|
|
int latest_page_number;
|
|
|
|
} SlruSharedData;
|
|
|
|
|
|
|
|
typedef SlruSharedData *SlruShared;
|
2003-06-12 00:37:46 +02:00
|
|
|
|
2004-05-28 07:13:32 +02:00
|
|
|
/*
|
|
|
|
* SlruCtlData is an unshared structure that points to the active information
|
|
|
|
* in shared memory.
|
|
|
|
*/
|
2003-06-12 00:37:46 +02:00
|
|
|
typedef struct SlruCtlData
|
|
|
|
{
|
2004-05-31 05:48:10 +02:00
|
|
|
SlruShared shared;
|
|
|
|
|
2004-05-28 07:13:32 +02:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* This flag tells whether to fsync writes (true for pg_clog, false for
|
|
|
|
* pg_subtrans).
|
2004-05-28 07:13:32 +02:00
|
|
|
*/
|
2004-08-24 01:22:45 +02:00
|
|
|
bool do_fsync;
|
2003-08-04 02:43:34 +02:00
|
|
|
|
2004-05-28 07:13:32 +02:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* Decide which of two page numbers is "older" for truncation purposes. We
|
|
|
|
* need to use comparison of TransactionIds here in order to do the right
|
|
|
|
* thing with wraparound XID arithmetic.
|
2004-05-28 07:13:32 +02:00
|
|
|
*/
|
2003-08-04 02:43:34 +02:00
|
|
|
bool (*PagePrecedes) (int, int);
|
2003-06-12 00:37:46 +02:00
|
|
|
|
2004-08-24 01:22:45 +02:00
|
|
|
/*
|
2005-10-15 04:49:52 +02:00
|
|
|
* 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.
|
2004-08-24 01:22:45 +02:00
|
|
|
*/
|
2005-07-04 06:51:52 +02:00
|
|
|
char Dir[64];
|
2003-08-08 23:42:59 +02:00
|
|
|
} SlruCtlData;
|
2004-05-31 05:48:10 +02:00
|
|
|
|
2003-06-12 00:37:46 +02:00
|
|
|
typedef SlruCtlData *SlruCtl;
|
|
|
|
|
2004-08-24 01:22:45 +02:00
|
|
|
/* Opaque struct known only in slru.c */
|
|
|
|
typedef struct SlruFlushData *SlruFlush;
|
|
|
|
|
2004-05-31 05:48:10 +02:00
|
|
|
|
2005-12-07 00:08:34 +01:00
|
|
|
extern Size SimpleLruShmemSize(int nslots);
|
|
|
|
extern void SimpleLruInit(SlruCtl ctl, const char *name, int nslots,
|
2004-08-29 07:07:03 +02:00
|
|
|
LWLockId ctllock, const char *subdir);
|
2003-06-12 00:37:46 +02:00
|
|
|
extern int SimpleLruZeroPage(SlruCtl ctl, int pageno);
|
2004-08-24 01:22:45 +02:00
|
|
|
extern int SimpleLruReadPage(SlruCtl ctl, int pageno, TransactionId xid);
|
2006-10-04 02:30:14 +02:00
|
|
|
extern int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno,
|
|
|
|
TransactionId xid);
|
2004-05-31 05:48:10 +02:00
|
|
|
extern void SimpleLruWritePage(SlruCtl ctl, int slotno, SlruFlush fdata);
|
2003-06-12 00:37:46 +02:00
|
|
|
extern void SimpleLruFlush(SlruCtl ctl, bool checkpoint);
|
|
|
|
extern void SimpleLruTruncate(SlruCtl ctl, int cutoffPage);
|
2004-08-24 01:22:45 +02:00
|
|
|
extern bool SlruScanDirectory(SlruCtl ctl, int cutoffPage, bool doDeletions);
|
2004-07-01 02:52:04 +02:00
|
|
|
|
2003-06-12 00:37:46 +02:00
|
|
|
#endif /* SLRU_H */
|