PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
storage_xlog.h File Reference
#include "access/xlogreader.h"
#include "lib/stringinfo.h"
#include "storage/block.h"
#include "storage/relfilenode.h"
Include dependency graph for storage_xlog.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  xl_smgr_create
 
struct  xl_smgr_truncate
 

Macros

#define XLOG_SMGR_CREATE   0x10
 
#define XLOG_SMGR_TRUNCATE   0x20
 
#define SMGR_TRUNCATE_HEAP   0x0001
 
#define SMGR_TRUNCATE_VM   0x0002
 
#define SMGR_TRUNCATE_FSM   0x0004
 
#define SMGR_TRUNCATE_ALL   (SMGR_TRUNCATE_HEAP|SMGR_TRUNCATE_VM|SMGR_TRUNCATE_FSM)
 

Typedefs

typedef struct xl_smgr_create xl_smgr_create
 
typedef struct xl_smgr_truncate xl_smgr_truncate
 

Functions

void log_smgrcreate (RelFileNode *rnode, ForkNumber forkNum)
 
void smgr_redo (XLogReaderState *record)
 
void smgr_desc (StringInfo buf, XLogReaderState *record)
 
const char * smgr_identify (uint8 info)
 

Macro Definition Documentation

#define SMGR_TRUNCATE_ALL   (SMGR_TRUNCATE_HEAP|SMGR_TRUNCATE_VM|SMGR_TRUNCATE_FSM)

Definition at line 43 of file storage_xlog.h.

Referenced by RelationTruncate().

#define SMGR_TRUNCATE_FSM   0x0004

Definition at line 42 of file storage_xlog.h.

Referenced by smgr_redo().

#define SMGR_TRUNCATE_HEAP   0x0001

Definition at line 40 of file storage_xlog.h.

Referenced by smgr_redo().

#define SMGR_TRUNCATE_VM   0x0002

Definition at line 41 of file storage_xlog.h.

Referenced by pg_truncate_visibility_map(), and smgr_redo().

#define XLOG_SMGR_CREATE   0x10

Definition at line 30 of file storage_xlog.h.

Referenced by extractPageInfo(), log_smgrcreate(), smgr_desc(), smgr_identify(), and smgr_redo().

#define XLOG_SMGR_TRUNCATE   0x20

Typedef Documentation

Function Documentation

void log_smgrcreate ( RelFileNode rnode,
ForkNumber  forkNum 
)

Definition at line 125 of file storage.c.

References xl_smgr_create::forkNum, xl_smgr_create::rnode, XLOG_SMGR_CREATE, XLogBeginInsert(), XLogInsert(), XLogRegisterData(), and XLR_SPECIAL_REL_UPDATE.

Referenced by ATExecSetTableSpace(), heap_create_init_fork(), and RelationCreateStorage().

126 {
127  xl_smgr_create xlrec;
128 
129  /*
130  * Make an XLOG entry reporting the file creation.
131  */
132  xlrec.rnode = *rnode;
133  xlrec.forkNum = forkNum;
134 
135  XLogBeginInsert();
136  XLogRegisterData((char *) &xlrec, sizeof(xlrec));
138 }
#define XLR_SPECIAL_REL_UPDATE
Definition: xlogrecord.h:71
#define XLOG_SMGR_CREATE
Definition: storage_xlog.h:30
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:323
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:415
ForkNumber forkNum
Definition: storage_xlog.h:36
void XLogBeginInsert(void)
Definition: xloginsert.c:120
RelFileNode rnode
Definition: storage_xlog.h:35
void smgr_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 22 of file smgrdesc.c.

References appendStringInfo(), appendStringInfoString(), xl_smgr_truncate::blkno, xl_smgr_truncate::flags, xl_smgr_create::forkNum, MAIN_FORKNUM, pfree(), relpathperm, xl_smgr_create::rnode, xl_smgr_truncate::rnode, XLOG_SMGR_CREATE, XLOG_SMGR_TRUNCATE, XLogRecGetData, XLogRecGetInfo, and XLR_INFO_MASK.

23 {
24  char *rec = XLogRecGetData(record);
25  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
26 
27  if (info == XLOG_SMGR_CREATE)
28  {
29  xl_smgr_create *xlrec = (xl_smgr_create *) rec;
30  char *path = relpathperm(xlrec->rnode, xlrec->forkNum);
31 
32  appendStringInfoString(buf, path);
33  pfree(path);
34  }
35  else if (info == XLOG_SMGR_TRUNCATE)
36  {
37  xl_smgr_truncate *xlrec = (xl_smgr_truncate *) rec;
38  char *path = relpathperm(xlrec->rnode, MAIN_FORKNUM);
39 
40  appendStringInfo(buf, "%s to %u blocks flags %d", path,
41  xlrec->blkno, xlrec->flags);
42  pfree(path);
43  }
44 }
#define relpathperm(rnode, forknum)
Definition: relpath.h:67
unsigned char uint8
Definition: c.h:266
RelFileNode rnode
Definition: storage_xlog.h:49
#define XLOG_SMGR_CREATE
Definition: storage_xlog.h:30
void pfree(void *pointer)
Definition: mcxt.c:950
#define XLogRecGetData(decoder)
Definition: xlogreader.h:218
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:110
void appendStringInfoString(StringInfo str, const char *s)
Definition: stringinfo.c:189
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:214
#define XLOG_SMGR_TRUNCATE
Definition: storage_xlog.h:31
ForkNumber forkNum
Definition: storage_xlog.h:36
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
BlockNumber blkno
Definition: storage_xlog.h:48
RelFileNode rnode
Definition: storage_xlog.h:35
const char* smgr_identify ( uint8  info)

Definition at line 47 of file smgrdesc.c.

References NULL, XLOG_SMGR_CREATE, XLOG_SMGR_TRUNCATE, and XLR_INFO_MASK.

48 {
49  const char *id = NULL;
50 
51  switch (info & ~XLR_INFO_MASK)
52  {
53  case XLOG_SMGR_CREATE:
54  id = "CREATE";
55  break;
56  case XLOG_SMGR_TRUNCATE:
57  id = "TRUNCATE";
58  break;
59  }
60 
61  return id;
62 }
#define XLOG_SMGR_CREATE
Definition: storage_xlog.h:30
#define XLOG_SMGR_TRUNCATE
Definition: storage_xlog.h:31
#define NULL
Definition: c.h:229
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
void smgr_redo ( XLogReaderState record)

Definition at line 477 of file storage.c.

References Assert, xl_smgr_truncate::blkno, CreateFakeRelcacheEntry(), elog, XLogReaderState::EndRecPtr, xl_smgr_truncate::flags, xl_smgr_create::forkNum, FreeFakeRelcacheEntry(), FreeSpaceMapTruncateRel(), FSM_FORKNUM, InvalidBackendId, MAIN_FORKNUM, PANIC, xl_smgr_create::rnode, xl_smgr_truncate::rnode, SMGR_TRUNCATE_FSM, SMGR_TRUNCATE_HEAP, SMGR_TRUNCATE_VM, smgrcreate(), smgrexists(), smgropen(), smgrtruncate(), VISIBILITYMAP_FORKNUM, visibilitymap_truncate(), XLOG_SMGR_CREATE, XLOG_SMGR_TRUNCATE, XLogFlush(), XLogRecGetData, XLogRecGetInfo, XLogRecHasAnyBlockRefs, XLogTruncateRelation(), and XLR_INFO_MASK.

478 {
479  XLogRecPtr lsn = record->EndRecPtr;
480  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
481 
482  /* Backup blocks are not used in smgr records */
483  Assert(!XLogRecHasAnyBlockRefs(record));
484 
485  if (info == XLOG_SMGR_CREATE)
486  {
487  xl_smgr_create *xlrec = (xl_smgr_create *) XLogRecGetData(record);
488  SMgrRelation reln;
489 
490  reln = smgropen(xlrec->rnode, InvalidBackendId);
491  smgrcreate(reln, xlrec->forkNum, true);
492  }
493  else if (info == XLOG_SMGR_TRUNCATE)
494  {
495  xl_smgr_truncate *xlrec = (xl_smgr_truncate *) XLogRecGetData(record);
496  SMgrRelation reln;
497  Relation rel;
498 
499  reln = smgropen(xlrec->rnode, InvalidBackendId);
500 
501  /*
502  * Forcibly create relation if it doesn't exist (which suggests that
503  * it was dropped somewhere later in the WAL sequence). As in
504  * XLogReadBufferForRedo, we prefer to recreate the rel and replay the
505  * log as best we can until the drop is seen.
506  */
507  smgrcreate(reln, MAIN_FORKNUM, true);
508 
509  /*
510  * Before we perform the truncation, update minimum recovery point to
511  * cover this WAL record. Once the relation is truncated, there's no
512  * going back. The buffer manager enforces the WAL-first rule for
513  * normal updates to relation files, so that the minimum recovery
514  * point is always updated before the corresponding change in the data
515  * file is flushed to disk. We have to do the same manually here.
516  *
517  * Doing this before the truncation means that if the truncation fails
518  * for some reason, you cannot start up the system even after restart,
519  * until you fix the underlying situation so that the truncation will
520  * succeed. Alternatively, we could update the minimum recovery point
521  * after truncation, but that would leave a small window where the
522  * WAL-first rule could be violated.
523  */
524  XLogFlush(lsn);
525 
526  if ((xlrec->flags & SMGR_TRUNCATE_HEAP) != 0)
527  {
528  smgrtruncate(reln, MAIN_FORKNUM, xlrec->blkno);
529 
530  /* Also tell xlogutils.c about it */
531  XLogTruncateRelation(xlrec->rnode, MAIN_FORKNUM, xlrec->blkno);
532  }
533 
534  /* Truncate FSM and VM too */
535  rel = CreateFakeRelcacheEntry(xlrec->rnode);
536 
537  if ((xlrec->flags & SMGR_TRUNCATE_FSM) != 0 &&
538  smgrexists(reln, FSM_FORKNUM))
539  FreeSpaceMapTruncateRel(rel, xlrec->blkno);
540  if ((xlrec->flags & SMGR_TRUNCATE_VM) != 0 &&
542  visibilitymap_truncate(rel, xlrec->blkno);
543 
545  }
546  else
547  elog(PANIC, "smgr_redo: unknown op code %u", info);
548 }
void XLogTruncateRelation(RelFileNode rnode, ForkNumber forkNum, BlockNumber nblocks)
Definition: xlogutils.c:637
#define SMGR_TRUNCATE_HEAP
Definition: storage_xlog.h:40
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition: smgr.c:376
unsigned char uint8
Definition: c.h:266
#define SMGR_TRUNCATE_FSM
Definition: storage_xlog.h:42
void smgrtruncate(SMgrRelation reln, ForkNumber forknum, BlockNumber nblocks)
Definition: smgr.c:684
RelFileNode rnode
Definition: storage_xlog.h:49
bool smgrexists(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:287
#define PANIC
Definition: elog.h:53
void XLogFlush(XLogRecPtr record)
Definition: xlog.c:2754
#define XLOG_SMGR_CREATE
Definition: storage_xlog.h:30
XLogRecPtr EndRecPtr
Definition: xlogreader.h:115
#define XLogRecGetData(decoder)
Definition: xlogreader.h:218
Relation CreateFakeRelcacheEntry(RelFileNode rnode)
Definition: xlogutils.c:551
void FreeSpaceMapTruncateRel(Relation rel, BlockNumber nblocks)
Definition: freespace.c:299
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:214
SMgrRelation smgropen(RelFileNode rnode, BackendId backend)
Definition: smgr.c:137
#define XLOG_SMGR_TRUNCATE
Definition: storage_xlog.h:31
void FreeFakeRelcacheEntry(Relation fakerel)
Definition: xlogutils.c:592
#define InvalidBackendId
Definition: backendid.h:23
ForkNumber forkNum
Definition: storage_xlog.h:36
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:675
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
void visibilitymap_truncate(Relation rel, BlockNumber nheapblocks)
#define SMGR_TRUNCATE_VM
Definition: storage_xlog.h:41
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:220
BlockNumber blkno
Definition: storage_xlog.h:48
#define elog
Definition: elog.h:219
RelFileNode rnode
Definition: storage_xlog.h:35