PostgreSQL Source Code git master
Loading...
Searching...
No Matches
storage_xlog.h File Reference
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 (const RelFileLocator *rlocator, ForkNumber forkNum)
 
void smgr_redo (XLogReaderState *record)
 
void smgr_desc (StringInfo buf, XLogReaderState *record)
 
const charsmgr_identify (uint8 info)
 

Macro Definition Documentation

◆ SMGR_TRUNCATE_ALL

Definition at line 43 of file storage_xlog.h.

46{
47 BlockNumber blkno;
48 RelFileLocator rlocator;
49 int flags;
51
52extern void log_smgrcreate(const RelFileLocator *rlocator, ForkNumber forkNum);
53
54extern void smgr_redo(XLogReaderState *record);
55extern void smgr_desc(StringInfo buf, XLogReaderState *record);
56extern const char *smgr_identify(uint8 info);
57
58#endif /* STORAGE_XLOG_H */
uint32 BlockNumber
Definition block.h:31
uint8_t uint8
Definition c.h:544
static char buf[DEFAULT_XLOG_SEG_SIZE]
ForkNumber
Definition relpath.h:56
const char * smgr_identify(uint8 info)
Definition smgrdesc.c:44
void smgr_desc(StringInfo buf, XLogReaderState *record)
Definition smgrdesc.c:21
void smgr_redo(XLogReaderState *record)
Definition storage.c:981
void log_smgrcreate(const RelFileLocator *rlocator, ForkNumber forkNum)
Definition storage.c:187

◆ SMGR_TRUNCATE_FSM

#define SMGR_TRUNCATE_FSM   0x0004

Definition at line 42 of file storage_xlog.h.

◆ SMGR_TRUNCATE_HEAP

#define SMGR_TRUNCATE_HEAP   0x0001

Definition at line 40 of file storage_xlog.h.

◆ SMGR_TRUNCATE_VM

#define SMGR_TRUNCATE_VM   0x0002

Definition at line 41 of file storage_xlog.h.

◆ XLOG_SMGR_CREATE

#define XLOG_SMGR_CREATE   0x10

Definition at line 30 of file storage_xlog.h.

◆ XLOG_SMGR_TRUNCATE

#define XLOG_SMGR_TRUNCATE   0x20

Definition at line 31 of file storage_xlog.h.

Typedef Documentation

◆ xl_smgr_create

◆ xl_smgr_truncate

Function Documentation

◆ log_smgrcreate()

void log_smgrcreate ( const RelFileLocator rlocator,
ForkNumber  forkNum 
)
extern

Definition at line 187 of file storage.c.

188{
190
191 /*
192 * Make an XLOG entry reporting the file creation.
193 */
194 xlrec.rlocator = *rlocator;
195 xlrec.forkNum = forkNum;
196
198 XLogRegisterData(&xlrec, sizeof(xlrec));
200}
static int fb(int x)
#define XLOG_SMGR_CREATE
RelFileLocator rlocator
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition xloginsert.c:478
void XLogRegisterData(const void *data, uint32 len)
Definition xloginsert.c:368
void XLogBeginInsert(void)
Definition xloginsert.c:152
#define XLR_SPECIAL_REL_UPDATE
Definition xlogrecord.h:82

References fb(), xl_smgr_create::rlocator, XLOG_SMGR_CREATE, XLogBeginInsert(), XLogInsert(), XLogRegisterData(), and XLR_SPECIAL_REL_UPDATE.

Referenced by CreateAndCopyRelationData(), fill_seq_with_data(), heapam_relation_copy_data(), heapam_relation_set_new_filelocator(), index_build(), index_copy_data(), and RelationCreateStorage().

◆ smgr_desc()

void smgr_desc ( StringInfo  buf,
XLogReaderState record 
)
extern

Definition at line 21 of file smgrdesc.c.

22{
23 char *rec = XLogRecGetData(record);
24 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
25
26 if (info == XLOG_SMGR_CREATE)
27 {
29
31 relpathperm(xlrec->rlocator, xlrec->forkNum).str);
32 }
33 else if (info == XLOG_SMGR_TRUNCATE)
34 {
36
37 appendStringInfo(buf, "%s to %u blocks flags %d",
38 relpathperm(xlrec->rlocator, MAIN_FORKNUM).str,
39 xlrec->blkno, xlrec->flags);
40 }
41}
@ MAIN_FORKNUM
Definition relpath.h:58
#define relpathperm(rlocator, forknum)
Definition relpath.h:146
#define XLOG_SMGR_TRUNCATE
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void appendStringInfoString(StringInfo str, const char *s)
Definition stringinfo.c:230
#define XLogRecGetInfo(decoder)
Definition xlogreader.h:409
#define XLogRecGetData(decoder)
Definition xlogreader.h:414

References appendStringInfo(), appendStringInfoString(), buf, fb(), MAIN_FORKNUM, relpathperm, XLOG_SMGR_CREATE, XLOG_SMGR_TRUNCATE, XLogRecGetData, and XLogRecGetInfo.

◆ smgr_identify()

const char * smgr_identify ( uint8  info)
extern

Definition at line 44 of file smgrdesc.c.

45{
46 const char *id = NULL;
47
48 switch (info & ~XLR_INFO_MASK)
49 {
51 id = "CREATE";
52 break;
54 id = "TRUNCATE";
55 break;
56 }
57
58 return id;
59}
#define XLR_INFO_MASK
Definition xlogrecord.h:62

References fb(), XLOG_SMGR_CREATE, XLOG_SMGR_TRUNCATE, and XLR_INFO_MASK.

◆ smgr_redo()

void smgr_redo ( XLogReaderState record)
extern

Definition at line 981 of file storage.c.

982{
983 XLogRecPtr lsn = record->EndRecPtr;
984 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
985
986 /* Backup blocks are not used in smgr records */
988
989 if (info == XLOG_SMGR_CREATE)
990 {
993
995 smgrcreate(reln, xlrec->forkNum, true);
996 }
997 else if (info == XLOG_SMGR_TRUNCATE)
998 {
1001 Relation rel;
1003 BlockNumber blocks[MAX_FORKNUM];
1005 int nforks = 0;
1006 bool need_fsm_vacuum = false;
1007
1008 reln = smgropen(xlrec->rlocator, INVALID_PROC_NUMBER);
1009
1010 /*
1011 * Forcibly create relation if it doesn't exist (which suggests that
1012 * it was dropped somewhere later in the WAL sequence). As in
1013 * XLogReadBufferForRedo, we prefer to recreate the rel and replay the
1014 * log as best we can until the drop is seen.
1015 */
1017
1018 /*
1019 * Before we perform the truncation, update minimum recovery point to
1020 * cover this WAL record. Once the relation is truncated, there's no
1021 * going back. The buffer manager enforces the WAL-first rule for
1022 * normal updates to relation files, so that the minimum recovery
1023 * point is always updated before the corresponding change in the data
1024 * file is flushed to disk. We have to do the same manually here.
1025 *
1026 * Doing this before the truncation means that if the truncation fails
1027 * for some reason, you cannot start up the system even after restart,
1028 * until you fix the underlying situation so that the truncation will
1029 * succeed. Alternatively, we could update the minimum recovery point
1030 * after truncation, but that would leave a small window where the
1031 * WAL-first rule could be violated.
1032 */
1033 XLogFlush(lsn);
1034
1035 /* Prepare for truncation of MAIN fork */
1036 if ((xlrec->flags & SMGR_TRUNCATE_HEAP) != 0)
1037 {
1040 blocks[nforks] = xlrec->blkno;
1041 nforks++;
1042
1043 /* Also tell xlogutils.c about it */
1044 XLogTruncateRelation(xlrec->rlocator, MAIN_FORKNUM, xlrec->blkno);
1045 }
1046
1047 /* Prepare for truncation of FSM and VM too */
1048 rel = CreateFakeRelcacheEntry(xlrec->rlocator);
1049
1050 if ((xlrec->flags & SMGR_TRUNCATE_FSM) != 0 &&
1052 {
1053 blocks[nforks] = FreeSpaceMapPrepareTruncateRel(rel, xlrec->blkno);
1054 if (BlockNumberIsValid(blocks[nforks]))
1055 {
1058 nforks++;
1059 need_fsm_vacuum = true;
1060 }
1061 }
1062 if ((xlrec->flags & SMGR_TRUNCATE_VM) != 0 &&
1064 {
1065 blocks[nforks] = visibilitymap_prepare_truncate(rel, xlrec->blkno);
1066 if (BlockNumberIsValid(blocks[nforks]))
1067 {
1070 nforks++;
1071 }
1072 }
1073
1074 /* Do the real work to truncate relation forks */
1075 if (nforks > 0)
1076 {
1080 }
1081
1082 /*
1083 * Update upper-level FSM pages to account for the truncation. This is
1084 * important because the just-truncated pages were likely marked as
1085 * all-free, and would be preferentially selected.
1086 */
1087 if (need_fsm_vacuum)
1088 FreeSpaceMapVacuumRange(rel, xlrec->blkno,
1090
1092 }
1093 else
1094 elog(PANIC, "smgr_redo: unknown op code %u", info);
1095}
#define InvalidBlockNumber
Definition block.h:33
static bool BlockNumberIsValid(BlockNumber blockNumber)
Definition block.h:71
#define Assert(condition)
Definition c.h:873
#define PANIC
Definition elog.h:42
#define elog(elevel,...)
Definition elog.h:226
void FreeSpaceMapVacuumRange(Relation rel, BlockNumber start, BlockNumber end)
Definition freespace.c:377
BlockNumber FreeSpaceMapPrepareTruncateRel(Relation rel, BlockNumber nblocks)
Definition freespace.c:275
#define START_CRIT_SECTION()
Definition miscadmin.h:150
#define END_CRIT_SECTION()
Definition miscadmin.h:152
#define INVALID_PROC_NUMBER
Definition procnumber.h:26
@ FSM_FORKNUM
Definition relpath.h:59
@ VISIBILITYMAP_FORKNUM
Definition relpath.h:60
#define MAX_FORKNUM
Definition relpath.h:70
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
Definition smgr.c:819
SMgrRelation smgropen(RelFileLocator rlocator, ProcNumber backend)
Definition smgr.c:240
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition smgr.c:481
void smgrtruncate(SMgrRelation reln, ForkNumber *forknum, int nforks, BlockNumber *old_nblocks, BlockNumber *nblocks)
Definition smgr.c:875
bool smgrexists(SMgrRelation reln, ForkNumber forknum)
Definition smgr.c:462
#define SMGR_TRUNCATE_VM
#define SMGR_TRUNCATE_HEAP
#define SMGR_TRUNCATE_FSM
XLogRecPtr EndRecPtr
Definition xlogreader.h:206
BlockNumber visibilitymap_prepare_truncate(Relation rel, BlockNumber nheapblocks)
void XLogFlush(XLogRecPtr record)
Definition xlog.c:2783
uint64 XLogRecPtr
Definition xlogdefs.h:21
#define XLogRecHasAnyBlockRefs(decoder)
Definition xlogreader.h:416
void FreeFakeRelcacheEntry(Relation fakerel)
Definition xlogutils.c:618
void XLogTruncateRelation(RelFileLocator rlocator, ForkNumber forkNum, BlockNumber nblocks)
Definition xlogutils.c:660
Relation CreateFakeRelcacheEntry(RelFileLocator rlocator)
Definition xlogutils.c:571

References Assert, BlockNumberIsValid(), CreateFakeRelcacheEntry(), elog, END_CRIT_SECTION, XLogReaderState::EndRecPtr, fb(), FreeFakeRelcacheEntry(), FreeSpaceMapPrepareTruncateRel(), FreeSpaceMapVacuumRange(), FSM_FORKNUM, INVALID_PROC_NUMBER, InvalidBlockNumber, MAIN_FORKNUM, MAX_FORKNUM, PANIC, SMGR_TRUNCATE_FSM, SMGR_TRUNCATE_HEAP, SMGR_TRUNCATE_VM, smgrcreate(), smgrexists(), smgrnblocks(), smgropen(), smgrtruncate(), START_CRIT_SECTION, VISIBILITYMAP_FORKNUM, visibilitymap_prepare_truncate(), XLOG_SMGR_CREATE, XLOG_SMGR_TRUNCATE, XLogFlush(), XLogRecGetData, XLogRecGetInfo, XLogRecHasAnyBlockRefs, and XLogTruncateRelation().