typedef struct XLogRecord
{
uint32 xl_tot_len; /* total len of entire record */
TransactionId xl_xid; /* xact id */
uint32 xl_len; /* total len of rmgr data */
uint8 xl_info; /* flag bits, see below */
RmgrId xl_rmid; /* resource manager for this record */
/* 2 bytes of padding here, initialize to zero */
XLogRecPtr xl_prev; /* ptr to previous record in log */
pg_crc32 xl_crc; /* CRC for this record */
/* If MAXALIGN==8, there are 4 wasted bytes here */
/* ACTUAL LOG DATA FOLLOWS AT END OF STRUCT */
} XLogRecord;
ログレコード(固定長のヘッダ部分)
実際はこのあとにデータが続いて一つのログレコードになっている
/*
* The overall layout of an XLOG record is:
* Fixed-size header (XLogRecord struct)
* rmgr-specific data
* BkpBlock
* backup block data
* BkpBlock
* backup block data
* ...
*/
typedef struct XLogRecData
{
char *data; /* start of rmgr data to include */
uint32 len; /* length of rmgr data to include */
Buffer buffer; /* buffer associated with data, if any */
bool buffer_std; /* buffer has standard pd_lower/pd_upper */
struct XLogRecData *next; /* next struct in chain, or NULL */
} XLogRecData;
XLogInsert()はXLogRecDataのチェーンを受け取って受け取る。
dataフィールドがログレコードのデータへのポインタになっていて、 XLogInsert()でdataをWALバッファにコピーしている。
typedef struct BkpBlock
{
RelFileNode node; /* relation containing block */
ForkNumber fork; /* fork within the relation */
BlockNumber block; /* block number */
uint16 hole_offset; /* number of bytes before "hole" */
uint16 hole_length; /* number of bytes in "hole" */
/* ACTUAL BLOCK DATA FOLLOWS AT END OF STRUCT */
} BkpBlock;
ログレコードのデータの一部。更新するフィールドの数だけBkpBlockがある(?)
一つのログレコードにBkpBlockが一つ以上含まれる。 Backup Blockのデータがこの後に続く。
長いのでリンク
https://www.hpcs.cs.tsukuba.ac.jp/~kamiya/postgresql_9_4_5/S/114.html#L482
XLOGで使われる全ての制御変数を含む構造体
ソースコード中では以下のように記述されており、関数内部から変数XLogCtlを通してアクセスする。
static XLogCtlData *XLogCtl = NULL;
XLogCtlなどXLOGの共有メモリ変数の初期化は
関数XLOGShmemInit()
https://www.hpcs.cs.tsukuba.ac.jp/~kamiya/postgresql_9_4_5/S/114.html#L4835
で行われる。
長いのでリンク
https://www.hpcs.cs.tsukuba.ac.jp/~kamiya/postgresql_9_4_5/S/114.html#L482
XLogInsert関数で使う制御情報を含む構造体
-
uint64 CurrBytePos:WALバッファの末尾の位置(次のレコードはこの位置に追加される)
-
uint64 PrevBytePos:ひとつ前のレコードの開始位置(次のレコードのprev-linkにコピーされる)
-
WALInsertLockPadded *WALInsertLocks:WALInsertLock
以下のようにアクセスされる。
&XLogCtl->Insert;