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.

Referenced by gin_desc(), ginPlaceToPage(), and ginRedoInsert().

◆ GIN_INSERT_ISLEAF

#define GIN_INSERT_ISLEAF   0x02 /* ditto */

Definition at line 125 of file ginxlog.h.

Referenced by gin_desc(), ginPlaceToPage(), ginRedoInsert(), and ginRedoSplit().

◆ GIN_NDELETE_AT_ONCE

#define GIN_NDELETE_AT_ONCE   Min(16, XLR_MAX_BLOCK_ID - 1)

Definition at line 202 of file ginxlog.h.

Referenced by shiftList().

◆ GIN_SEGMENT_ADDITEMS

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

◆ GIN_SEGMENT_DELETE

◆ GIN_SEGMENT_INSERT

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

◆ GIN_SEGMENT_REPLACE

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

◆ GIN_SEGMENT_UNMODIFIED

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

◆ GIN_SPLIT_ROOT

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

Definition at line 126 of file ginxlog.h.

Referenced by gin_desc(), ginPlaceToPage(), and ginRedoSplit().

◆ XLOG_GIN_CREATE_PTREE

#define XLOG_GIN_CREATE_PTREE   0x10

Definition at line 19 of file ginxlog.h.

Referenced by createPostingTree(), gin_desc(), gin_identify(), and gin_redo().

◆ XLOG_GIN_DELETE_LISTPAGE

#define XLOG_GIN_DELETE_LISTPAGE   0x80

Definition at line 194 of file ginxlog.h.

Referenced by gin_desc(), gin_identify(), gin_redo(), and shiftList().

◆ XLOG_GIN_DELETE_PAGE

#define XLOG_GIN_DELETE_PAGE   0x50

Definition at line 153 of file ginxlog.h.

Referenced by gin_desc(), gin_identify(), gin_redo(), and ginDeletePage().

◆ XLOG_GIN_INSERT

#define XLOG_GIN_INSERT   0x20

Definition at line 35 of file ginxlog.h.

Referenced by gin_desc(), gin_identify(), gin_redo(), and ginPlaceToPage().

◆ XLOG_GIN_INSERT_LISTPAGE

#define XLOG_GIN_INSERT_LISTPAGE   0x70

Definition at line 180 of file ginxlog.h.

Referenced by gin_desc(), gin_identify(), gin_redo(), and writeListPage().

◆ XLOG_GIN_SPLIT

#define XLOG_GIN_SPLIT   0x30

Definition at line 109 of file ginxlog.h.

Referenced by gin_desc(), gin_identify(), gin_redo(), and ginPlaceToPage().

◆ XLOG_GIN_UPDATE_META_PAGE

#define XLOG_GIN_UPDATE_META_PAGE   0x60

Definition at line 162 of file ginxlog.h.

Referenced by gin_desc(), gin_identify(), gin_redo(), ginHeapTupleFastInsert(), and ginUpdateStats().

◆ XLOG_GIN_VACUUM_DATA_LEAF_PAGE

#define XLOG_GIN_VACUUM_DATA_LEAF_PAGE   0x90

Definition at line 141 of file ginxlog.h.

Referenced by gin_desc(), gin_identify(), gin_redo(), and ginVacuumPostingTreeLeaf().

◆ XLOG_GIN_VACUUM_PAGE

#define XLOG_GIN_VACUUM_PAGE   0x40

Definition at line 135 of file ginxlog.h.

Referenced by gin_desc(), gin_identify(), gin_redo(), and xlogVacuumPage().

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 74 of file gindesc.c.

References appendStringInfo(), appendStringInfoString(), BlockIdGetBlockNumber, 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.

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

◆ gin_identify()

const char* gin_identify ( uint8  info)

Definition at line 182 of file gindesc.c.

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.

183 {
184  const char *id = NULL;
185 
186  switch (info & ~XLR_INFO_MASK)
187  {
189  id = "CREATE_PTREE";
190  break;
191  case XLOG_GIN_INSERT:
192  id = "INSERT";
193  break;
194  case XLOG_GIN_SPLIT:
195  id = "SPLIT";
196  break;
198  id = "VACUUM_PAGE";
199  break;
201  id = "VACUUM_DATA_LEAF_PAGE";
202  break;
204  id = "DELETE_PAGE";
205  break;
207  id = "UPDATE_META_PAGE";
208  break;
210  id = "INSERT_LISTPAGE";
211  break;
213  id = "DELETE_LISTPAGE";
214  break;
215  }
216 
217  return id;
218 }
#define XLOG_GIN_INSERT_LISTPAGE
Definition: ginxlog.h:180
#define XLOG_GIN_CREATE_PTREE
Definition: ginxlog.h:19
#define XLOG_GIN_UPDATE_META_PAGE
Definition: ginxlog.h:162
#define XLOG_GIN_VACUUM_DATA_LEAF_PAGE
Definition: ginxlog.h:141
#define XLOG_GIN_VACUUM_PAGE
Definition: ginxlog.h:135
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
#define XLOG_GIN_INSERT
Definition: ginxlog.h:35
#define XLOG_GIN_DELETE_PAGE
Definition: ginxlog.h:153
#define XLOG_GIN_SPLIT
Definition: ginxlog.h:109
#define XLOG_GIN_DELETE_LISTPAGE
Definition: ginxlog.h:194

◆ gin_mask()

void gin_mask ( char *  pagedata,
BlockNumber  blkno 
)

Definition at line 793 of file ginxlog.c.

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.

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 }
#define GIN_DELETED
Definition: ginblock.h:42
void mask_page_hint_bits(Page page)
Definition: bufmask.c:46
#define GinPageGetOpaque(page)
Definition: ginblock.h:110
#define SizeOfPageHeaderData
Definition: bufpage.h:216
void mask_unused_space(Page page)
Definition: bufmask.c:71
void mask_page_content(Page page)
Definition: bufmask.c:119
void mask_page_lsn_and_checksum(Page page)
Definition: bufmask.c:31
PageHeaderData * PageHeader
Definition: bufpage.h:166
Pointer Page
Definition: bufpage.h:78
LocationIndex pd_lower
Definition: bufpage.h:158

◆ gin_redo()

void gin_redo ( XLogReaderState record)

Definition at line 726 of file ginxlog.c.

References elog, ginRedoCreatePTree(), ginRedoDeleteListPages(), ginRedoDeletePage(), ginRedoInsert(), ginRedoInsertListPage(), ginRedoSplit(), ginRedoUpdateMetapage(), ginRedoVacuumDataLeafPage(), ginRedoVacuumPage(), MemoryContextReset(), MemoryContextSwitchTo(), 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.

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 }
static void ginRedoUpdateMetapage(XLogReaderState *record)
Definition: ginxlog.c:528
static void ginRedoSplit(XLogReaderState *record)
Definition: ginxlog.c:402
static MemoryContext opCtx
Definition: ginxlog.c:22
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
unsigned char uint8
Definition: c.h:356
void MemoryContextReset(MemoryContext context)
Definition: mcxt.c:136
#define PANIC
Definition: elog.h:53
#define XLOG_GIN_INSERT_LISTPAGE
Definition: ginxlog.h:180
static void ginRedoDeleteListPages(XLogReaderState *record)
Definition: ginxlog.c:675
#define XLOG_GIN_CREATE_PTREE
Definition: ginxlog.h:19
static void ginRedoVacuumDataLeafPage(XLogReaderState *record)
Definition: ginxlog.c:452
#define XLOG_GIN_UPDATE_META_PAGE
Definition: ginxlog.h:162
static void ginRedoCreatePTree(XLogReaderState *record)
Definition: ginxlog.c:44
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:242
#define XLOG_GIN_VACUUM_DATA_LEAF_PAGE
Definition: ginxlog.h:141
#define XLOG_GIN_VACUUM_PAGE
Definition: ginxlog.h:135
static void ginRedoInsert(XLogReaderState *record)
Definition: ginxlog.c:347
static void ginRedoVacuumPage(XLogReaderState *record)
Definition: ginxlog.c:440
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
#define XLOG_GIN_INSERT
Definition: ginxlog.h:35
#define elog(elevel,...)
Definition: elog.h:226
static void ginRedoDeletePage(XLogReaderState *record)
Definition: ginxlog.c:477
static void ginRedoInsertListPage(XLogReaderState *record)
Definition: ginxlog.c:620
#define XLOG_GIN_DELETE_PAGE
Definition: ginxlog.h:153
#define XLOG_GIN_SPLIT
Definition: ginxlog.h:109
#define XLOG_GIN_DELETE_LISTPAGE
Definition: ginxlog.h:194

◆ gin_xlog_cleanup()

void gin_xlog_cleanup ( void  )

Definition at line 783 of file ginxlog.c.

References MemoryContextDelete().

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

◆ gin_xlog_startup()

void gin_xlog_startup ( void  )

Definition at line 775 of file ginxlog.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, and CurrentMemoryContext.

776 {
778  "GIN recovery temporary context",
780 }
#define AllocSetContextCreate
Definition: memutils.h:170
static MemoryContext opCtx
Definition: ginxlog.c:22
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:192
MemoryContext CurrentMemoryContext
Definition: mcxt.c:38