PostgreSQL Source Code  git master
ginxlog.h File Reference
#include "access/ginblock.h"
#include "access/itup.h"
#include "access/xlogreader.h"
#include "lib/stringinfo.h"
#include "storage/off.h"
Include dependency graph for ginxlog.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ginxlogCreatePostingTree
 
struct  ginxlogInsert
 
struct  ginxlogInsertEntry
 
struct  ginxlogRecompressDataLeaf
 
struct  ginxlogSegmentAction
 
struct  ginxlogInsertDataInternal
 
struct  ginxlogSplit
 
struct  ginxlogVacuumDataLeafPage
 
struct  ginxlogDeletePage
 
struct  ginxlogUpdateMeta
 
struct  ginxlogInsertListPage
 
struct  ginxlogDeleteListPages
 

Macros

#define XLOG_GIN_CREATE_PTREE   0x10
 
#define XLOG_GIN_INSERT   0x20
 
#define GIN_SEGMENT_UNMODIFIED   0 /* no action (not used in WAL records) */
 
#define GIN_SEGMENT_DELETE   1 /* a whole segment is removed */
 
#define GIN_SEGMENT_INSERT   2 /* a whole segment is added */
 
#define GIN_SEGMENT_REPLACE   3 /* a segment is replaced */
 
#define GIN_SEGMENT_ADDITEMS   4 /* items are added to existing segment */
 
#define XLOG_GIN_SPLIT   0x30
 
#define GIN_INSERT_ISDATA   0x01 /* for both insert and split records */
 
#define GIN_INSERT_ISLEAF   0x02 /* ditto */
 
#define GIN_SPLIT_ROOT   0x04 /* only for split records */
 
#define XLOG_GIN_VACUUM_PAGE   0x40
 
#define XLOG_GIN_VACUUM_DATA_LEAF_PAGE   0x90
 
#define XLOG_GIN_DELETE_PAGE   0x50
 
#define XLOG_GIN_UPDATE_META_PAGE   0x60
 
#define XLOG_GIN_INSERT_LISTPAGE   0x70
 
#define XLOG_GIN_DELETE_LISTPAGE   0x80
 
#define GIN_NDELETE_AT_ONCE   Min(16, XLR_MAX_BLOCK_ID - 1)
 

Typedefs

typedef struct ginxlogCreatePostingTree ginxlogCreatePostingTree
 
typedef struct ginxlogSplit ginxlogSplit
 
typedef struct ginxlogVacuumDataLeafPage ginxlogVacuumDataLeafPage
 
typedef struct ginxlogDeletePage ginxlogDeletePage
 
typedef struct ginxlogUpdateMeta ginxlogUpdateMeta
 
typedef struct ginxlogInsertListPage ginxlogInsertListPage
 
typedef struct ginxlogDeleteListPages ginxlogDeleteListPages
 

Functions

void gin_redo (XLogReaderState *record)
 
void gin_desc (StringInfo buf, XLogReaderState *record)
 
const char * gin_identify (uint8 info)
 
void gin_xlog_startup (void)
 
void gin_xlog_cleanup (void)
 
void gin_mask (char *pagedata, BlockNumber blkno)
 

Macro Definition Documentation

◆ GIN_INSERT_ISDATA

#define GIN_INSERT_ISDATA   0x01 /* for both insert and split records */

Definition at line 124 of file ginxlog.h.

◆ GIN_INSERT_ISLEAF

#define GIN_INSERT_ISLEAF   0x02 /* ditto */

Definition at line 125 of file ginxlog.h.

◆ GIN_NDELETE_AT_ONCE

#define GIN_NDELETE_AT_ONCE   Min(16, XLR_MAX_BLOCK_ID - 1)

Definition at line 202 of file ginxlog.h.

◆ GIN_SEGMENT_ADDITEMS

#define GIN_SEGMENT_ADDITEMS   4 /* items are added to existing segment */

Definition at line 95 of file ginxlog.h.

◆ GIN_SEGMENT_DELETE

#define GIN_SEGMENT_DELETE   1 /* a whole segment is removed */

Definition at line 92 of file ginxlog.h.

◆ GIN_SEGMENT_INSERT

#define GIN_SEGMENT_INSERT   2 /* a whole segment is added */

Definition at line 93 of file ginxlog.h.

◆ GIN_SEGMENT_REPLACE

#define GIN_SEGMENT_REPLACE   3 /* a segment is replaced */

Definition at line 94 of file ginxlog.h.

◆ GIN_SEGMENT_UNMODIFIED

#define GIN_SEGMENT_UNMODIFIED   0 /* no action (not used in WAL records) */

Definition at line 91 of file ginxlog.h.

◆ GIN_SPLIT_ROOT

#define GIN_SPLIT_ROOT   0x04 /* only for split records */

Definition at line 126 of file ginxlog.h.

◆ XLOG_GIN_CREATE_PTREE

#define XLOG_GIN_CREATE_PTREE   0x10

Definition at line 19 of file ginxlog.h.

◆ XLOG_GIN_DELETE_LISTPAGE

#define XLOG_GIN_DELETE_LISTPAGE   0x80

Definition at line 194 of file ginxlog.h.

◆ XLOG_GIN_DELETE_PAGE

#define XLOG_GIN_DELETE_PAGE   0x50

Definition at line 153 of file ginxlog.h.

◆ XLOG_GIN_INSERT

#define XLOG_GIN_INSERT   0x20

Definition at line 35 of file ginxlog.h.

◆ XLOG_GIN_INSERT_LISTPAGE

#define XLOG_GIN_INSERT_LISTPAGE   0x70

Definition at line 180 of file ginxlog.h.

◆ XLOG_GIN_SPLIT

#define XLOG_GIN_SPLIT   0x30

Definition at line 109 of file ginxlog.h.

◆ XLOG_GIN_UPDATE_META_PAGE

#define XLOG_GIN_UPDATE_META_PAGE   0x60

Definition at line 162 of file ginxlog.h.

◆ XLOG_GIN_VACUUM_DATA_LEAF_PAGE

#define XLOG_GIN_VACUUM_DATA_LEAF_PAGE   0x90

Definition at line 141 of file ginxlog.h.

◆ XLOG_GIN_VACUUM_PAGE

#define XLOG_GIN_VACUUM_PAGE   0x40

Definition at line 135 of file ginxlog.h.

Typedef Documentation

◆ ginxlogCreatePostingTree

◆ ginxlogDeleteListPages

◆ ginxlogDeletePage

◆ ginxlogInsertListPage

◆ ginxlogSplit

typedef struct ginxlogSplit ginxlogSplit

◆ ginxlogUpdateMeta

◆ ginxlogVacuumDataLeafPage

Function Documentation

◆ gin_desc()

void gin_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 72 of file gindesc.c.

73 {
74  char *rec = XLogRecGetData(record);
75  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
76 
77  switch (info)
78  {
80  /* no further information */
81  break;
82  case XLOG_GIN_INSERT:
83  {
84  ginxlogInsert *xlrec = (ginxlogInsert *) rec;
85 
86  appendStringInfo(buf, "isdata: %c isleaf: %c",
87  (xlrec->flags & GIN_INSERT_ISDATA) ? 'T' : 'F',
88  (xlrec->flags & GIN_INSERT_ISLEAF) ? 'T' : 'F');
89  if (!(xlrec->flags & GIN_INSERT_ISLEAF))
90  {
91  char *payload = rec + sizeof(ginxlogInsert);
92  BlockNumber leftChildBlkno;
93  BlockNumber rightChildBlkno;
94 
95  leftChildBlkno = BlockIdGetBlockNumber((BlockId) payload);
96  payload += sizeof(BlockIdData);
97  rightChildBlkno = BlockIdGetBlockNumber((BlockId) payload);
98  payload += sizeof(BlockNumber);
99  appendStringInfo(buf, " children: %u/%u",
100  leftChildBlkno, rightChildBlkno);
101  }
102  if (XLogRecHasBlockImage(record, 0))
103  {
104  if (XLogRecBlockImageApply(record, 0))
105  appendStringInfoString(buf, " (full page image)");
106  else
107  appendStringInfoString(buf, " (full page image, for WAL verification)");
108  }
109  else
110  {
111  char *payload = XLogRecGetBlockData(record, 0, NULL);
112 
113  if (!(xlrec->flags & GIN_INSERT_ISDATA))
114  appendStringInfo(buf, " isdelete: %c",
115  (((ginxlogInsertEntry *) payload)->isDelete) ? 'T' : 'F');
116  else if (xlrec->flags & GIN_INSERT_ISLEAF)
118  else
119  {
120  ginxlogInsertDataInternal *insertData =
121  (ginxlogInsertDataInternal *) payload;
122 
123  appendStringInfo(buf, " pitem: %u-%u/%u",
124  PostingItemGetBlockNumber(&insertData->newitem),
125  ItemPointerGetBlockNumber(&insertData->newitem.key),
126  ItemPointerGetOffsetNumber(&insertData->newitem.key));
127  }
128  }
129  }
130  break;
131  case XLOG_GIN_SPLIT:
132  {
133  ginxlogSplit *xlrec = (ginxlogSplit *) rec;
134 
135  appendStringInfo(buf, "isrootsplit: %c",
136  (((ginxlogSplit *) rec)->flags & GIN_SPLIT_ROOT) ? 'T' : 'F');
137  appendStringInfo(buf, " isdata: %c isleaf: %c",
138  (xlrec->flags & GIN_INSERT_ISDATA) ? 'T' : 'F',
139  (xlrec->flags & GIN_INSERT_ISLEAF) ? 'T' : 'F');
140  }
141  break;
143  /* no further information */
144  break;
146  {
147  if (XLogRecHasBlockImage(record, 0))
148  {
149  if (XLogRecBlockImageApply(record, 0))
150  appendStringInfoString(buf, " (full page image)");
151  else
152  appendStringInfoString(buf, " (full page image, for WAL verification)");
153  }
154  else
155  {
157  (ginxlogVacuumDataLeafPage *) XLogRecGetBlockData(record, 0, NULL);
158 
159  desc_recompress_leaf(buf, &xlrec->data);
160  }
161  }
162  break;
164  /* no further information */
165  break;
167  /* no further information */
168  break;
170  /* no further information */
171  break;
173  appendStringInfo(buf, "ndeleted: %d",
174  ((ginxlogDeleteListPages *) rec)->ndeleted);
175  break;
176  }
177 }
uint32 BlockNumber
Definition: block.h:31
struct BlockIdData BlockIdData
static BlockNumber BlockIdGetBlockNumber(const BlockIdData *blockId)
Definition: block.h:103
unsigned char uint8
Definition: c.h:504
#define PostingItemGetBlockNumber(pointer)
Definition: ginblock.h:189
static void desc_recompress_leaf(StringInfo buf, ginxlogRecompressDataLeaf *insertData)
Definition: gindesc.c:21
#define GIN_INSERT_ISDATA
Definition: ginxlog.h:124
#define GIN_INSERT_ISLEAF
Definition: ginxlog.h:125
#define XLOG_GIN_UPDATE_META_PAGE
Definition: ginxlog.h:162
#define GIN_SPLIT_ROOT
Definition: ginxlog.h:126
#define XLOG_GIN_INSERT
Definition: ginxlog.h:35
#define XLOG_GIN_CREATE_PTREE
Definition: ginxlog.h:19
#define XLOG_GIN_VACUUM_PAGE
Definition: ginxlog.h:135
#define XLOG_GIN_DELETE_PAGE
Definition: ginxlog.h:153
#define XLOG_GIN_INSERT_LISTPAGE
Definition: ginxlog.h:180
#define XLOG_GIN_VACUUM_DATA_LEAF_PAGE
Definition: ginxlog.h:141
#define XLOG_GIN_SPLIT
Definition: ginxlog.h:109
#define XLOG_GIN_DELETE_LISTPAGE
Definition: ginxlog.h:194
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
Definition: itemptr.h:124
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
Definition: itemptr.h:103
static char * buf
Definition: pg_test_fsync.c:73
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:182
ItemPointerData key
Definition: ginblock.h:186
uint16 flags
Definition: ginxlog.h:39
uint16 flags
Definition: ginxlog.h:118
ginxlogRecompressDataLeaf data
Definition: ginxlog.h:145
char * XLogRecGetBlockData(XLogReaderState *record, uint8 block_id, Size *len)
Definition: xlogreader.c:2025
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:410
#define XLogRecBlockImageApply(decoder, block_id)
Definition: xlogreader.h:425
#define XLogRecGetData(decoder)
Definition: xlogreader.h:415
#define XLogRecHasBlockImage(decoder, block_id)
Definition: xlogreader.h:423
#define XLR_INFO_MASK
Definition: xlogrecord.h:62

References appendStringInfo(), appendStringInfoString(), BlockIdGetBlockNumber(), buf, ginxlogVacuumDataLeafPage::data, desc_recompress_leaf(), ginxlogInsert::flags, ginxlogSplit::flags, GIN_INSERT_ISDATA, GIN_INSERT_ISLEAF, GIN_SPLIT_ROOT, ItemPointerGetBlockNumber(), ItemPointerGetOffsetNumber(), PostingItem::key, ginxlogInsertDataInternal::newitem, PostingItemGetBlockNumber, XLOG_GIN_CREATE_PTREE, XLOG_GIN_DELETE_LISTPAGE, XLOG_GIN_DELETE_PAGE, XLOG_GIN_INSERT, XLOG_GIN_INSERT_LISTPAGE, XLOG_GIN_SPLIT, XLOG_GIN_UPDATE_META_PAGE, XLOG_GIN_VACUUM_DATA_LEAF_PAGE, XLOG_GIN_VACUUM_PAGE, XLogRecBlockImageApply, XLogRecGetBlockData(), XLogRecGetData, XLogRecGetInfo, XLogRecHasBlockImage, and XLR_INFO_MASK.

◆ gin_identify()

const char* gin_identify ( uint8  info)

Definition at line 180 of file gindesc.c.

181 {
182  const char *id = NULL;
183 
184  switch (info & ~XLR_INFO_MASK)
185  {
187  id = "CREATE_PTREE";
188  break;
189  case XLOG_GIN_INSERT:
190  id = "INSERT";
191  break;
192  case XLOG_GIN_SPLIT:
193  id = "SPLIT";
194  break;
196  id = "VACUUM_PAGE";
197  break;
199  id = "VACUUM_DATA_LEAF_PAGE";
200  break;
202  id = "DELETE_PAGE";
203  break;
205  id = "UPDATE_META_PAGE";
206  break;
208  id = "INSERT_LISTPAGE";
209  break;
211  id = "DELETE_LISTPAGE";
212  break;
213  }
214 
215  return id;
216 }

References XLOG_GIN_CREATE_PTREE, XLOG_GIN_DELETE_LISTPAGE, XLOG_GIN_DELETE_PAGE, XLOG_GIN_INSERT, XLOG_GIN_INSERT_LISTPAGE, XLOG_GIN_SPLIT, XLOG_GIN_UPDATE_META_PAGE, XLOG_GIN_VACUUM_DATA_LEAF_PAGE, XLOG_GIN_VACUUM_PAGE, and XLR_INFO_MASK.

◆ gin_mask()

void gin_mask ( char *  pagedata,
BlockNumber  blkno 
)

Definition at line 793 of file ginxlog.c.

794 {
795  Page page = (Page) pagedata;
796  PageHeader pagehdr = (PageHeader) page;
797  GinPageOpaque opaque;
798 
800  opaque = GinPageGetOpaque(page);
801 
802  mask_page_hint_bits(page);
803 
804  /*
805  * For a GIN_DELETED page, the page is initialized to empty. Hence, mask
806  * the whole page content. For other pages, mask the hole if pd_lower
807  * appears to have been set correctly.
808  */
809  if (opaque->flags & GIN_DELETED)
810  mask_page_content(page);
811  else if (pagehdr->pd_lower > SizeOfPageHeaderData)
812  mask_unused_space(page);
813 }
void mask_page_content(Page page)
Definition: bufmask.c:119
void mask_page_lsn_and_checksum(Page page)
Definition: bufmask.c:31
void mask_unused_space(Page page)
Definition: bufmask.c:71
void mask_page_hint_bits(Page page)
Definition: bufmask.c:46
PageHeaderData * PageHeader
Definition: bufpage.h:170
Pointer Page
Definition: bufpage.h:78
#define SizeOfPageHeaderData
Definition: bufpage.h:213
#define GinPageGetOpaque(page)
Definition: ginblock.h:110
#define GIN_DELETED
Definition: ginblock.h:43
LocationIndex pd_lower
Definition: bufpage.h:162

References GinPageOpaqueData::flags, GIN_DELETED, GinPageGetOpaque, mask_page_content(), mask_page_hint_bits(), mask_page_lsn_and_checksum(), mask_unused_space(), PageHeaderData::pd_lower, and SizeOfPageHeaderData.

◆ gin_redo()

void gin_redo ( XLogReaderState record)

Definition at line 726 of file ginxlog.c.

727 {
728  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
729  MemoryContext oldCtx;
730 
731  /*
732  * GIN indexes do not require any conflict processing. NB: If we ever
733  * implement a similar optimization as we have in b-tree, and remove
734  * killed tuples outside VACUUM, we'll need to handle that here.
735  */
736 
737  oldCtx = MemoryContextSwitchTo(opCtx);
738  switch (info)
739  {
741  ginRedoCreatePTree(record);
742  break;
743  case XLOG_GIN_INSERT:
744  ginRedoInsert(record);
745  break;
746  case XLOG_GIN_SPLIT:
747  ginRedoSplit(record);
748  break;
750  ginRedoVacuumPage(record);
751  break;
754  break;
756  ginRedoDeletePage(record);
757  break;
759  ginRedoUpdateMetapage(record);
760  break;
762  ginRedoInsertListPage(record);
763  break;
765  ginRedoDeleteListPages(record);
766  break;
767  default:
768  elog(PANIC, "gin_redo: unknown op code %u", info);
769  }
770  MemoryContextSwitchTo(oldCtx);
772 }
#define PANIC
Definition: elog.h:42
#define elog(elevel,...)
Definition: elog.h:224
static void ginRedoInsert(XLogReaderState *record)
Definition: ginxlog.c:347
static void ginRedoSplit(XLogReaderState *record)
Definition: ginxlog.c:402
static void ginRedoDeletePage(XLogReaderState *record)
Definition: ginxlog.c:477
static void ginRedoVacuumDataLeafPage(XLogReaderState *record)
Definition: ginxlog.c:452
static void ginRedoDeleteListPages(XLogReaderState *record)
Definition: ginxlog.c:675
static void ginRedoUpdateMetapage(XLogReaderState *record)
Definition: ginxlog.c:528
static void ginRedoInsertListPage(XLogReaderState *record)
Definition: ginxlog.c:620
static MemoryContext opCtx
Definition: ginxlog.c:22
static void ginRedoCreatePTree(XLogReaderState *record)
Definition: ginxlog.c:44
static void ginRedoVacuumPage(XLogReaderState *record)
Definition: ginxlog.c:440
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:383
MemoryContextSwitchTo(old_ctx)

References elog, ginRedoCreatePTree(), ginRedoDeleteListPages(), ginRedoDeletePage(), ginRedoInsert(), ginRedoInsertListPage(), ginRedoSplit(), ginRedoUpdateMetapage(), ginRedoVacuumDataLeafPage(), ginRedoVacuumPage(), MemoryContextReset(), MemoryContextSwitchTo(), opCtx, PANIC, XLOG_GIN_CREATE_PTREE, XLOG_GIN_DELETE_LISTPAGE, XLOG_GIN_DELETE_PAGE, XLOG_GIN_INSERT, XLOG_GIN_INSERT_LISTPAGE, XLOG_GIN_SPLIT, XLOG_GIN_UPDATE_META_PAGE, XLOG_GIN_VACUUM_DATA_LEAF_PAGE, XLOG_GIN_VACUUM_PAGE, XLogRecGetInfo, and XLR_INFO_MASK.

◆ gin_xlog_cleanup()

void gin_xlog_cleanup ( void  )

Definition at line 783 of file ginxlog.c.

784 {
786  opCtx = NULL;
787 }
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:454

References MemoryContextDelete(), and opCtx.

◆ gin_xlog_startup()

void gin_xlog_startup ( void  )

Definition at line 775 of file ginxlog.c.

776 {
778  "GIN recovery temporary context",
780 }
MemoryContext CurrentMemoryContext
Definition: mcxt.c:143
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:160

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, CurrentMemoryContext, and opCtx.