PostgreSQL Source Code  git master
xlogutils.c File Reference
#include "postgres.h"
#include <unistd.h>
#include "access/timeline.h"
#include "access/xlog.h"
#include "access/xlog_internal.h"
#include "access/xlogutils.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "storage/smgr.h"
#include "utils/guc.h"
#include "utils/hsearch.h"
#include "utils/rel.h"
Include dependency graph for xlogutils.c:

Go to the source code of this file.

Data Structures

struct  xl_invalid_page_key
 
struct  xl_invalid_page
 
struct  FakeRelCacheEntryData
 

Typedefs

typedef struct xl_invalid_page_key xl_invalid_page_key
 
typedef struct xl_invalid_page xl_invalid_page
 
typedef FakeRelCacheEntryDataFakeRelCacheEntry
 

Functions

static void report_invalid_page (int elevel, RelFileNode node, ForkNumber forkno, BlockNumber blkno, bool present)
 
static void log_invalid_page (RelFileNode node, ForkNumber forkno, BlockNumber blkno, bool present)
 
static void forget_invalid_pages (RelFileNode node, ForkNumber forkno, BlockNumber minblkno)
 
static void forget_invalid_pages_db (Oid dbid)
 
bool XLogHaveInvalidPages (void)
 
void XLogCheckInvalidPages (void)
 
XLogRedoAction XLogReadBufferForRedo (XLogReaderState *record, uint8 block_id, Buffer *buf)
 
Buffer XLogInitBufferForRedo (XLogReaderState *record, uint8 block_id)
 
XLogRedoAction XLogReadBufferForRedoExtended (XLogReaderState *record, uint8 block_id, ReadBufferMode mode, bool get_cleanup_lock, Buffer *buf)
 
Buffer XLogReadBufferExtended (RelFileNode rnode, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode, Buffer recent_buffer)
 
Relation CreateFakeRelcacheEntry (RelFileNode rnode)
 
void FreeFakeRelcacheEntry (Relation fakerel)
 
void XLogDropRelation (RelFileNode rnode, ForkNumber forknum)
 
void XLogDropDatabase (Oid dbid)
 
void XLogTruncateRelation (RelFileNode rnode, ForkNumber forkNum, BlockNumber nblocks)
 
void XLogReadDetermineTimeline (XLogReaderState *state, XLogRecPtr wantPage, uint32 wantLength)
 
void wal_segment_open (XLogReaderState *state, XLogSegNo nextSegNo, TimeLineID *tli_p)
 
void wal_segment_close (XLogReaderState *state)
 
bool read_local_xlog_page (XLogReaderState *state)
 
void WALReadRaiseError (WALReadError *errinfo)
 

Variables

bool ignore_invalid_pages = false
 
static HTABinvalid_page_tab = NULL
 

Typedef Documentation

◆ FakeRelCacheEntry

Definition at line 552 of file xlogutils.c.

◆ xl_invalid_page

◆ xl_invalid_page_key

Function Documentation

◆ CreateFakeRelcacheEntry()

Relation CreateFakeRelcacheEntry ( RelFileNode  rnode)

Definition at line 569 of file xlogutils.c.

References LockRelId::dbId, RelFileNode::dbNode, InvalidBackendId, LockInfoData::lockRelId, palloc0(), FakeRelCacheEntryData::pgc, RelationData::rd_backend, RelationData::rd_lockInfo, RelationData::rd_node, RelationData::rd_rel, RelationData::rd_smgr, RelationGetRelationName, LockRelId::relId, RelFileNode::relNode, and sprintf.

Referenced by heap_xlog_delete(), heap_xlog_insert(), heap_xlog_lock(), heap_xlog_lock_updated(), heap_xlog_multi_insert(), heap_xlog_update(), heap_xlog_visible(), smgr_redo(), and smgrDoPendingSyncs().

570 {
571  FakeRelCacheEntry fakeentry;
572  Relation rel;
573 
574  /* Allocate the Relation struct and all related space in one block. */
575  fakeentry = palloc0(sizeof(FakeRelCacheEntryData));
576  rel = (Relation) fakeentry;
577 
578  rel->rd_rel = &fakeentry->pgc;
579  rel->rd_node = rnode;
580 
581  /*
582  * We will never be working with temp rels during recovery or while
583  * syncing WAL-skipped files.
584  */
586 
587  /* It must be a permanent table here */
588  rel->rd_rel->relpersistence = RELPERSISTENCE_PERMANENT;
589 
590  /* We don't know the name of the relation; use relfilenode instead */
591  sprintf(RelationGetRelationName(rel), "%u", rnode.relNode);
592 
593  /*
594  * We set up the lockRelId in case anything tries to lock the dummy
595  * relation. Note that this is fairly bogus since relNode may be
596  * different from the relation's OID. It shouldn't really matter though.
597  * In recovery, we are running by ourselves and can't have any lock
598  * conflicts. While syncing, we already hold AccessExclusiveLock.
599  */
600  rel->rd_lockInfo.lockRelId.dbId = rnode.dbNode;
601  rel->rd_lockInfo.lockRelId.relId = rnode.relNode;
602 
603  rel->rd_smgr = NULL;
604 
605  return rel;
606 }
LockRelId lockRelId
Definition: rel.h:44
struct SMgrRelationData * rd_smgr
Definition: rel.h:57
Oid dbId
Definition: rel.h:39
Form_pg_class rd_rel
Definition: rel.h:109
#define sprintf
Definition: port.h:218
struct RelationData * Relation
Definition: relcache.h:27
LockInfoData rd_lockInfo
Definition: rel.h:112
#define RelationGetRelationName(relation)
Definition: rel.h:503
#define InvalidBackendId
Definition: backendid.h:23
void * palloc0(Size size)
Definition: mcxt.c:1093
RelFileNode rd_node
Definition: rel.h:55
BackendId rd_backend
Definition: rel.h:59
FormData_pg_class pgc
Definition: xlogutils.c:549
Oid relId
Definition: rel.h:38

◆ forget_invalid_pages()

static void forget_invalid_pages ( RelFileNode  node,
ForkNumber  forkno,
BlockNumber  minblkno 
)
static

Definition at line 145 of file xlogutils.c.

References xl_invalid_page_key::blkno, DEBUG2, elog, ERROR, xl_invalid_page_key::forkno, HASH_REMOVE, hash_search(), hash_seq_init(), hash_seq_search(), xl_invalid_page::key, message_level_is_interesting(), xl_invalid_page_key::node, pfree(), RelFileNodeEquals, relpathperm, and status().

Referenced by XLogDropRelation(), and XLogTruncateRelation().

146 {
148  xl_invalid_page *hentry;
149 
150  if (invalid_page_tab == NULL)
151  return; /* nothing to do */
152 
154 
155  while ((hentry = (xl_invalid_page *) hash_seq_search(&status)) != NULL)
156  {
157  if (RelFileNodeEquals(hentry->key.node, node) &&
158  hentry->key.forkno == forkno &&
159  hentry->key.blkno >= minblkno)
160  {
162  {
163  char *path = relpathperm(hentry->key.node, forkno);
164 
165  elog(DEBUG2, "page %u of relation %s has been dropped",
166  hentry->key.blkno, path);
167  pfree(path);
168  }
169 
171  (void *) &hentry->key,
172  HASH_REMOVE, NULL) == NULL)
173  elog(ERROR, "hash table corrupted");
174  }
175  }
176 }
#define relpathperm(rnode, forknum)
Definition: relpath.h:83
ForkNumber forkno
Definition: xlogutils.c:50
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
RelFileNode node
Definition: xlogutils.c:49
void pfree(void *pointer)
Definition: mcxt.c:1169
#define ERROR
Definition: elog.h:46
#define DEBUG2
Definition: elog.h:24
bool message_level_is_interesting(int elevel)
Definition: elog.c:270
BlockNumber blkno
Definition: xlogutils.c:51
xl_invalid_page_key key
Definition: xlogutils.c:56
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1436
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1426
#define elog(elevel,...)
Definition: elog.h:232
static HTAB * invalid_page_tab
Definition: xlogutils.c:60
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:227
#define RelFileNodeEquals(node1, node2)
Definition: relfilenode.h:88

◆ forget_invalid_pages_db()

static void forget_invalid_pages_db ( Oid  dbid)
static

Definition at line 180 of file xlogutils.c.

References xl_invalid_page_key::blkno, RelFileNode::dbNode, DEBUG2, elog, ERROR, xl_invalid_page_key::forkno, HASH_REMOVE, hash_search(), hash_seq_init(), hash_seq_search(), xl_invalid_page::key, message_level_is_interesting(), xl_invalid_page_key::node, pfree(), relpathperm, and status().

Referenced by XLogDropDatabase().

181 {
183  xl_invalid_page *hentry;
184 
185  if (invalid_page_tab == NULL)
186  return; /* nothing to do */
187 
189 
190  while ((hentry = (xl_invalid_page *) hash_seq_search(&status)) != NULL)
191  {
192  if (hentry->key.node.dbNode == dbid)
193  {
195  {
196  char *path = relpathperm(hentry->key.node, hentry->key.forkno);
197 
198  elog(DEBUG2, "page %u of relation %s has been dropped",
199  hentry->key.blkno, path);
200  pfree(path);
201  }
202 
204  (void *) &hentry->key,
205  HASH_REMOVE, NULL) == NULL)
206  elog(ERROR, "hash table corrupted");
207  }
208  }
209 }
#define relpathperm(rnode, forknum)
Definition: relpath.h:83
ForkNumber forkno
Definition: xlogutils.c:50
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
RelFileNode node
Definition: xlogutils.c:49
void pfree(void *pointer)
Definition: mcxt.c:1169
#define ERROR
Definition: elog.h:46
#define DEBUG2
Definition: elog.h:24
bool message_level_is_interesting(int elevel)
Definition: elog.c:270
BlockNumber blkno
Definition: xlogutils.c:51
xl_invalid_page_key key
Definition: xlogutils.c:56
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1436
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1426
#define elog(elevel,...)
Definition: elog.h:232
static HTAB * invalid_page_tab
Definition: xlogutils.c:60
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:227

◆ FreeFakeRelcacheEntry()

void FreeFakeRelcacheEntry ( Relation  fakerel)

Definition at line 612 of file xlogutils.c.

References pfree(), RelationData::rd_smgr, and smgrclearowner().

Referenced by heap_xlog_delete(), heap_xlog_insert(), heap_xlog_lock(), heap_xlog_lock_updated(), heap_xlog_multi_insert(), heap_xlog_update(), heap_xlog_visible(), smgr_redo(), and smgrDoPendingSyncs().

613 {
614  /* make sure the fakerel is not referenced by the SmgrRelation anymore */
615  if (fakerel->rd_smgr != NULL)
616  smgrclearowner(&fakerel->rd_smgr, fakerel->rd_smgr);
617  pfree(fakerel);
618 }
void smgrclearowner(SMgrRelation *owner, SMgrRelation reln)
Definition: smgr.c:227
struct SMgrRelationData * rd_smgr
Definition: rel.h:57
void pfree(void *pointer)
Definition: mcxt.c:1169

◆ log_invalid_page()

static void log_invalid_page ( RelFileNode  node,
ForkNumber  forkno,
BlockNumber  blkno,
bool  present 
)
static

Definition at line 81 of file xlogutils.c.

References xl_invalid_page_key::blkno, DEBUG1, elog, HASHCTL::entrysize, xl_invalid_page_key::forkno, HASH_BLOBS, hash_create(), HASH_ELEM, HASH_ENTER, hash_search(), ignore_invalid_pages, sort-test::key, HASHCTL::keysize, message_level_is_interesting(), xl_invalid_page_key::node, PANIC, xl_invalid_page::present, reachedConsistency, report_invalid_page(), and WARNING.

Referenced by XLogReadBufferExtended().

83 {
85  xl_invalid_page *hentry;
86  bool found;
87 
88  /*
89  * Once recovery has reached a consistent state, the invalid-page table
90  * should be empty and remain so. If a reference to an invalid page is
91  * found after consistency is reached, PANIC immediately. This might seem
92  * aggressive, but it's better than letting the invalid reference linger
93  * in the hash table until the end of recovery and PANIC there, which
94  * might come only much later if this is a standby server.
95  */
97  {
98  report_invalid_page(WARNING, node, forkno, blkno, present);
100  "WAL contains references to invalid pages");
101  }
102 
103  /*
104  * Log references to invalid pages at DEBUG1 level. This allows some
105  * tracing of the cause (note the elog context mechanism will tell us
106  * something about the XLOG record that generated the reference).
107  */
109  report_invalid_page(DEBUG1, node, forkno, blkno, present);
110 
111  if (invalid_page_tab == NULL)
112  {
113  /* create hash table when first needed */
114  HASHCTL ctl;
115 
116  ctl.keysize = sizeof(xl_invalid_page_key);
117  ctl.entrysize = sizeof(xl_invalid_page);
118 
119  invalid_page_tab = hash_create("XLOG invalid-page table",
120  100,
121  &ctl,
123  }
124 
125  /* we currently assume xl_invalid_page_key contains no padding */
126  key.node = node;
127  key.forkno = forkno;
128  key.blkno = blkno;
129  hentry = (xl_invalid_page *)
130  hash_search(invalid_page_tab, (void *) &key, HASH_ENTER, &found);
131 
132  if (!found)
133  {
134  /* hash_search already filled in the key */
135  hentry->present = present;
136  }
137  else
138  {
139  /* repeat reference ... leave "present" as it was */
140  }
141 }
#define DEBUG1
Definition: elog.h:25
struct xl_invalid_page xl_invalid_page
#define HASH_ELEM
Definition: hsearch.h:95
Size entrysize
Definition: hsearch.h:76
struct xl_invalid_page_key xl_invalid_page_key
ForkNumber forkno
Definition: xlogutils.c:50
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:954
#define PANIC
Definition: elog.h:50
RelFileNode node
Definition: xlogutils.c:49
static void report_invalid_page(int elevel, RelFileNode node, ForkNumber forkno, BlockNumber blkno, bool present)
Definition: xlogutils.c:65
bool message_level_is_interesting(int elevel)
Definition: elog.c:270
BlockNumber blkno
Definition: xlogutils.c:51
HTAB * hash_create(const char *tabname, long nelem, const HASHCTL *info, int flags)
Definition: dynahash.c:349
bool ignore_invalid_pages
Definition: xlogutils.c:35
#define WARNING
Definition: elog.h:40
#define HASH_BLOBS
Definition: hsearch.h:97
Size keysize
Definition: hsearch.h:75
bool reachedConsistency
Definition: xlog.c:870
#define elog(elevel,...)
Definition: elog.h:232
static HTAB * invalid_page_tab
Definition: xlogutils.c:60

◆ read_local_xlog_page()

bool read_local_xlog_page ( XLogReaderState state)

Definition at line 842 of file xlogutils.c.

References CHECK_FOR_INTERRUPTS, XLogReaderState::currTLI, XLogReaderState::currTLIValidUntil, GetFlushRecPtr(), GetXLogReplayRecPtr(), pg_usleep(), XLogReaderState::readBuf, XLogReaderState::readPagePtr, RecoveryInProgress(), XLogReaderState::reqLen, ThisTimeLineID, wal_segment_close(), wal_segment_open(), WALRead(), WALReadRaiseError(), XLogReadDetermineTimeline(), and XLogReaderSetInputData().

Referenced by create_logical_replication_slot(), pg_logical_replication_slot_advance(), pg_logical_slot_get_changes_guts(), and XlogReadTwoPhaseData().

843 {
844  XLogRecPtr targetPagePtr = state->readPagePtr;
845  int reqLen = state->reqLen;
846  char *cur_page = state->readBuf;
847  XLogRecPtr read_upto,
848  loc;
849  TimeLineID tli;
850  int count;
851  WALReadError errinfo;
852 
853  loc = targetPagePtr + reqLen;
854 
855  /* Loop waiting for xlog to be available if necessary */
856  while (1)
857  {
858  /*
859  * Determine the limit of xlog we can currently read to, and what the
860  * most recent timeline is.
861  *
862  * RecoveryInProgress() will update ThisTimeLineID when it first
863  * notices recovery finishes, so we only have to maintain it for the
864  * local process until recovery ends.
865  */
866  if (!RecoveryInProgress())
867  read_upto = GetFlushRecPtr();
868  else
869  read_upto = GetXLogReplayRecPtr(&ThisTimeLineID);
870  tli = ThisTimeLineID;
871 
872  /*
873  * Check which timeline to get the record from.
874  *
875  * We have to do it each time through the loop because if we're in
876  * recovery as a cascading standby, the current timeline might've
877  * become historical. We can't rely on RecoveryInProgress() because in
878  * a standby configuration like
879  *
880  * A => B => C
881  *
882  * if we're a logical decoding session on C, and B gets promoted, our
883  * timeline will change while we remain in recovery.
884  *
885  * We can't just keep reading from the old timeline as the last WAL
886  * archive in the timeline will get renamed to .partial by
887  * StartupXLOG().
888  *
889  * If that happens after our caller updated ThisTimeLineID but before
890  * we actually read the xlog page, we might still try to read from the
891  * old (now renamed) segment and fail. There's not much we can do
892  * about this, but it can only happen when we're a leaf of a cascading
893  * standby whose primary gets promoted while we're decoding, so a
894  * one-off ERROR isn't too bad.
895  */
896  XLogReadDetermineTimeline(state, targetPagePtr, reqLen);
897 
898  if (state->currTLI == ThisTimeLineID)
899  {
900 
901  if (loc <= read_upto)
902  break;
903 
905  pg_usleep(1000L);
906  }
907  else
908  {
909  /*
910  * We're on a historical timeline, so limit reading to the switch
911  * point where we moved to the next timeline.
912  *
913  * We don't need to GetFlushRecPtr or GetXLogReplayRecPtr. We know
914  * about the new timeline, so we must've received past the end of
915  * it.
916  */
917  read_upto = state->currTLIValidUntil;
918 
919  /*
920  * Setting tli to our wanted record's TLI is slightly wrong; the
921  * page might begin on an older timeline if it contains a timeline
922  * switch, since its xlog segment will have been copied from the
923  * prior timeline. This is pretty harmless though, as nothing
924  * cares so long as the timeline doesn't go backwards. We should
925  * read the page header instead; FIXME someday.
926  */
927  tli = state->currTLI;
928 
929  /* No need to wait on a historical timeline */
930  break;
931  }
932  }
933 
934  if (targetPagePtr + XLOG_BLCKSZ <= read_upto)
935  {
936  /*
937  * more than one block available; read only that block, have caller
938  * come back if they need more.
939  */
940  count = XLOG_BLCKSZ;
941  }
942  else if (targetPagePtr + reqLen > read_upto)
943  {
944  /* not enough data there */
945  XLogReaderSetInputData(state, -1);
946  return false;
947  }
948  else
949  {
950  /* enough bytes available to satisfy the request */
951  count = read_upto - targetPagePtr;
952  }
953 
954  /*
955  * Even though we just determined how much of the page can be validly read
956  * as 'count', read the whole page anyway. It's guaranteed to be
957  * zero-padded up to the page boundary if it's incomplete.
958  */
960  cur_page, targetPagePtr, XLOG_BLCKSZ, tli, &errinfo))
961  WALReadRaiseError(&errinfo);
962 
963  /* number of valid bytes in the buffer */
964  state->readPagePtr = targetPagePtr;
965  XLogReaderSetInputData(state, count);
966  return true;
967 }
void wal_segment_close(XLogReaderState *state)
Definition: xlogutils.c:823
uint32 TimeLineID
Definition: xlogdefs.h:59
void WALReadRaiseError(WALReadError *errinfo)
Definition: xlogutils.c:974
void wal_segment_open(XLogReaderState *state, XLogSegNo nextSegNo, TimeLineID *tli_p)
Definition: xlogutils.c:798
XLogRecPtr GetFlushRecPtr(void)
Definition: xlog.c:8589
bool RecoveryInProgress(void)
Definition: xlog.c:8237
void XLogReadDetermineTimeline(XLogReaderState *state, XLogRecPtr wantPage, uint32 wantLength)
Definition: xlogutils.c:702
void pg_usleep(long microsec)
Definition: signal.c:53
XLogRecPtr GetXLogReplayRecPtr(TimeLineID *replayTLI)
Definition: xlog.c:11728
XLogRecPtr readPagePtr
Definition: xlogreader.h:187
XLogRecPtr currTLIValidUntil
Definition: xlogreader.h:264
TimeLineID ThisTimeLineID
Definition: xlog.c:196
TimeLineID currTLI
Definition: xlogreader.h:254
bool WALRead(XLogReaderState *state, WALSegmentOpenCB segopenfn, WALSegmentCloseCB segclosefn, char *buf, XLogRecPtr startptr, Size count, TimeLineID tli, WALReadError *errinfo)
Definition: xlogreader.c:1660
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:102
static void XLogReaderSetInputData(XLogReaderState *state, int32 len)
Definition: xlogreader.h:304

◆ report_invalid_page()

static void report_invalid_page ( int  elevel,
RelFileNode  node,
ForkNumber  forkno,
BlockNumber  blkno,
bool  present 
)
static

Definition at line 65 of file xlogutils.c.

References elog, pfree(), and relpathperm.

Referenced by log_invalid_page(), and XLogCheckInvalidPages().

67 {
68  char *path = relpathperm(node, forkno);
69 
70  if (present)
71  elog(elevel, "page %u of relation %s is uninitialized",
72  blkno, path);
73  else
74  elog(elevel, "page %u of relation %s does not exist",
75  blkno, path);
76  pfree(path);
77 }
#define relpathperm(rnode, forknum)
Definition: relpath.h:83
void pfree(void *pointer)
Definition: mcxt.c:1169
static int elevel
Definition: vacuumlazy.c:400
#define elog(elevel,...)
Definition: elog.h:232

◆ wal_segment_close()

◆ wal_segment_open()

void wal_segment_open ( XLogReaderState state,
XLogSegNo  nextSegNo,
TimeLineID tli_p 
)

Definition at line 798 of file xlogutils.c.

References BasicOpenFile(), ereport, errcode_for_file_access(), errmsg(), ERROR, MAXPGPATH, PG_BINARY, XLogReaderState::seg, XLogReaderState::segcxt, WALOpenSegment::ws_file, WALSegmentContext::ws_segsize, and XLogFilePath.

Referenced by read_local_xlog_page().

800 {
801  TimeLineID tli = *tli_p;
802  char path[MAXPGPATH];
803 
804  XLogFilePath(path, tli, nextSegNo, state->segcxt.ws_segsize);
805  state->seg.ws_file = BasicOpenFile(path, O_RDONLY | PG_BINARY);
806  if (state->seg.ws_file >= 0)
807  return;
808 
809  if (errno == ENOENT)
810  ereport(ERROR,
812  errmsg("requested WAL segment %s has already been removed",
813  path)));
814  else
815  ereport(ERROR,
817  errmsg("could not open file \"%s\": %m",
818  path)));
819 }
uint32 TimeLineID
Definition: xlogdefs.h:59
#define PG_BINARY
Definition: c.h:1271
WALOpenSegment seg
Definition: xlogreader.h:243
#define ERROR
Definition: elog.h:46
#define MAXPGPATH
int errcode_for_file_access(void)
Definition: elog.c:721
#define ereport(elevel,...)
Definition: elog.h:157
int BasicOpenFile(const char *fileName, int fileFlags)
Definition: fd.c:1033
#define XLogFilePath(path, tli, logSegNo, wal_segsz_bytes)
int errmsg(const char *fmt,...)
Definition: elog.c:909
WALSegmentContext segcxt
Definition: xlogreader.h:242

◆ WALReadRaiseError()

void WALReadRaiseError ( WALReadError errinfo)

Definition at line 974 of file xlogutils.c.

References ereport, errcode(), ERRCODE_DATA_CORRUPTED, errcode_for_file_access(), errmsg(), ERROR, MAXFNAMELEN, wal_segment_size, WALReadError::wre_errno, WALReadError::wre_off, WALReadError::wre_read, WALReadError::wre_req, WALReadError::wre_seg, WALOpenSegment::ws_segno, WALOpenSegment::ws_tli, and XLogFileName.

Referenced by logical_read_xlog_page(), read_local_xlog_page(), and XLogSendPhysical().

975 {
976  WALOpenSegment *seg = &errinfo->wre_seg;
977  char fname[MAXFNAMELEN];
978 
979  XLogFileName(fname, seg->ws_tli, seg->ws_segno, wal_segment_size);
980 
981  if (errinfo->wre_read < 0)
982  {
983  errno = errinfo->wre_errno;
984  ereport(ERROR,
986  errmsg("could not read from log segment %s, offset %u: %m",
987  fname, errinfo->wre_off)));
988  }
989  else if (errinfo->wre_read == 0)
990  {
991  ereport(ERROR,
993  errmsg("could not read from log segment %s, offset %u: read %d of %zu",
994  fname, errinfo->wre_off, errinfo->wre_read,
995  (Size) errinfo->wre_req)));
996  }
997 }
WALOpenSegment wre_seg
Definition: xlogreader.h:358
int wal_segment_size
Definition: xlog.c:121
int errcode(int sqlerrcode)
Definition: elog.c:698
#define ERROR
Definition: elog.h:46
XLogSegNo ws_segno
Definition: xlogreader.h:48
int errcode_for_file_access(void)
Definition: elog.c:721
#define ERRCODE_DATA_CORRUPTED
Definition: pg_basebackup.c:45
#define MAXFNAMELEN
#define ereport(elevel,...)
Definition: elog.h:157
size_t Size
Definition: c.h:540
#define XLogFileName(fname, tli, logSegNo, wal_segsz_bytes)
TimeLineID ws_tli
Definition: xlogreader.h:49
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ XLogCheckInvalidPages()

void XLogCheckInvalidPages ( void  )

Definition at line 223 of file xlogutils.c.

References xl_invalid_page_key::blkno, elog, xl_invalid_page_key::forkno, hash_destroy(), hash_seq_init(), hash_seq_search(), ignore_invalid_pages, xl_invalid_page::key, xl_invalid_page_key::node, PANIC, xl_invalid_page::present, report_invalid_page(), status(), and WARNING.

Referenced by CheckRecoveryConsistency().

224 {
226  xl_invalid_page *hentry;
227  bool foundone = false;
228 
229  if (invalid_page_tab == NULL)
230  return; /* nothing to do */
231 
233 
234  /*
235  * Our strategy is to emit WARNING messages for all remaining entries and
236  * only PANIC after we've dumped all the available info.
237  */
238  while ((hentry = (xl_invalid_page *) hash_seq_search(&status)) != NULL)
239  {
240  report_invalid_page(WARNING, hentry->key.node, hentry->key.forkno,
241  hentry->key.blkno, hentry->present);
242  foundone = true;
243  }
244 
245  if (foundone)
247  "WAL contains references to invalid pages");
248 
250  invalid_page_tab = NULL;
251 }
void hash_destroy(HTAB *hashp)
Definition: dynahash.c:862
ForkNumber forkno
Definition: xlogutils.c:50
#define PANIC
Definition: elog.h:50
RelFileNode node
Definition: xlogutils.c:49
static void report_invalid_page(int elevel, RelFileNode node, ForkNumber forkno, BlockNumber blkno, bool present)
Definition: xlogutils.c:65
BlockNumber blkno
Definition: xlogutils.c:51
xl_invalid_page_key key
Definition: xlogutils.c:56
bool ignore_invalid_pages
Definition: xlogutils.c:35
#define WARNING
Definition: elog.h:40
void * hash_seq_search(HASH_SEQ_STATUS *status)
Definition: dynahash.c:1436
void hash_seq_init(HASH_SEQ_STATUS *status, HTAB *hashp)
Definition: dynahash.c:1426
#define elog(elevel,...)
Definition: elog.h:232
static HTAB * invalid_page_tab
Definition: xlogutils.c:60
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:227

◆ XLogDropDatabase()

void XLogDropDatabase ( Oid  dbid)

Definition at line 638 of file xlogutils.c.

References forget_invalid_pages_db(), and smgrcloseall().

Referenced by dbase_redo().

639 {
640  /*
641  * This is unnecessarily heavy-handed, as it will close SMgrRelation
642  * objects for other databases as well. DROP DATABASE occurs seldom enough
643  * that it's not worth introducing a variant of smgrclose for just this
644  * purpose. XXX: Or should we rather leave the smgr entries dangling?
645  */
646  smgrcloseall();
647 
649 }
static void forget_invalid_pages_db(Oid dbid)
Definition: xlogutils.c:180
void smgrcloseall(void)
Definition: smgr.c:286

◆ XLogDropRelation()

void XLogDropRelation ( RelFileNode  rnode,
ForkNumber  forknum 
)

Definition at line 627 of file xlogutils.c.

References forget_invalid_pages().

Referenced by DropRelationFiles().

628 {
629  forget_invalid_pages(rnode, forknum, 0);
630 }
static void forget_invalid_pages(RelFileNode node, ForkNumber forkno, BlockNumber minblkno)
Definition: xlogutils.c:145

◆ XLogHaveInvalidPages()

bool XLogHaveInvalidPages ( void  )

Definition at line 213 of file xlogutils.c.

References hash_get_num_entries().

Referenced by RecoveryRestartPoint().

214 {
215  if (invalid_page_tab != NULL &&
217  return true;
218  return false;
219 }
long hash_get_num_entries(HTAB *hashp)
Definition: dynahash.c:1382
static HTAB * invalid_page_tab
Definition: xlogutils.c:60

◆ XLogInitBufferForRedo()

◆ XLogReadBufferExtended()

Buffer XLogReadBufferExtended ( RelFileNode  rnode,
ForkNumber  forknum,
BlockNumber  blkno,
ReadBufferMode  mode,
Buffer  recent_buffer 
)

Definition at line 443 of file xlogutils.c.

References Assert, BUFFER_LOCK_UNLOCK, BufferGetBlockNumber(), BufferGetPage, BufferIsValid, InRecovery, InvalidBackendId, InvalidBuffer, LockBuffer(), log_invalid_page(), P_NEW, PageIsNew, RBM_NORMAL, RBM_NORMAL_NO_LOG, RBM_ZERO_AND_CLEANUP_LOCK, RBM_ZERO_AND_LOCK, ReadBufferWithoutRelcache(), ReadRecentBuffer(), ReleaseBuffer(), smgrcreate(), smgrnblocks(), and smgropen().

Referenced by checkXLogConsistency(), XLogReadBufferForRedoExtended(), and XLogRecordPageWithFreeSpace().

446 {
447  BlockNumber lastblock;
448  Buffer buffer;
449  SMgrRelation smgr;
450 
451  Assert(blkno != P_NEW);
452 
453  /* Do we have a clue where the buffer might be already? */
454  if (BufferIsValid(recent_buffer) &&
455  mode == RBM_NORMAL &&
456  ReadRecentBuffer(rnode, forknum, blkno, recent_buffer))
457  {
458  buffer = recent_buffer;
459  goto recent_buffer_fast_path;
460  }
461 
462  /* Open the relation at smgr level */
463  smgr = smgropen(rnode, InvalidBackendId);
464 
465  /*
466  * Create the target file if it doesn't already exist. This lets us cope
467  * if the replay sequence contains writes to a relation that is later
468  * deleted. (The original coding of this routine would instead suppress
469  * the writes, but that seems like it risks losing valuable data if the
470  * filesystem loses an inode during a crash. Better to write the data
471  * until we are actually told to delete the file.)
472  */
473  smgrcreate(smgr, forknum, true);
474 
475  lastblock = smgrnblocks(smgr, forknum);
476 
477  if (blkno < lastblock)
478  {
479  /* page exists in file */
480  buffer = ReadBufferWithoutRelcache(rnode, forknum, blkno,
481  mode, NULL);
482  }
483  else
484  {
485  /* hm, page doesn't exist in file */
486  if (mode == RBM_NORMAL)
487  {
488  log_invalid_page(rnode, forknum, blkno, false);
489  return InvalidBuffer;
490  }
491  if (mode == RBM_NORMAL_NO_LOG)
492  return InvalidBuffer;
493  /* OK to extend the file */
494  /* we do this in recovery only - no rel-extension lock needed */
496  buffer = InvalidBuffer;
497  do
498  {
499  if (buffer != InvalidBuffer)
500  {
503  ReleaseBuffer(buffer);
504  }
505  buffer = ReadBufferWithoutRelcache(rnode, forknum,
506  P_NEW, mode, NULL);
507  }
508  while (BufferGetBlockNumber(buffer) < blkno);
509  /* Handle the corner case that P_NEW returns non-consecutive pages */
510  if (BufferGetBlockNumber(buffer) != blkno)
511  {
514  ReleaseBuffer(buffer);
515  buffer = ReadBufferWithoutRelcache(rnode, forknum, blkno,
516  mode, NULL);
517  }
518  }
519 
520 recent_buffer_fast_path:
521  if (mode == RBM_NORMAL)
522  {
523  /* check that page has been initialized */
524  Page page = (Page) BufferGetPage(buffer);
525 
526  /*
527  * We assume that PageIsNew is safe without a lock. During recovery,
528  * there should be no other backends that could modify the buffer at
529  * the same time.
530  */
531  if (PageIsNew(page))
532  {
533  ReleaseBuffer(buffer);
534  log_invalid_page(rnode, forknum, blkno, true);
535  return InvalidBuffer;
536  }
537  }
538 
539  return buffer;
540 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
#define BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:96
void smgrcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo)
Definition: smgr.c:333
bool InRecovery
Definition: xlog.c:209
#define InvalidBuffer
Definition: buf.h:25
Buffer ReadBufferWithoutRelcache(RelFileNode rnode, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:786
uint32 BlockNumber
Definition: block.h:31
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3784
#define P_NEW
Definition: bufmgr.h:91
bool ReadRecentBuffer(RelFileNode rnode, ForkNumber forkNum, BlockNumber blockNum, Buffer recent_buffer)
Definition: bufmgr.c:621
static void log_invalid_page(RelFileNode node, ForkNumber forkno, BlockNumber blkno, bool present)
Definition: xlogutils.c:81
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
SMgrRelation smgropen(RelFileNode rnode, BackendId backend)
Definition: smgr.c:146
#define InvalidBackendId
Definition: backendid.h:23
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4023
BlockNumber smgrnblocks(SMgrRelation reln, ForkNumber forknum)
Definition: smgr.c:548
#define Assert(condition)
Definition: c.h:804
#define BufferIsValid(bufnum)
Definition: bufmgr.h:123
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:2758
#define PageIsNew(page)
Definition: bufpage.h:229
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:78

◆ XLogReadBufferForRedo()

XLogRedoAction XLogReadBufferForRedo ( XLogReaderState record,
uint8  block_id,
Buffer buf 
)

Definition at line 292 of file xlogutils.c.

References RBM_NORMAL, and XLogReadBufferForRedoExtended().

Referenced by _bt_clear_incomplete_split(), brin_xlog_desummarize_page(), brin_xlog_insert_update(), brin_xlog_revmap_extend(), brin_xlog_samepage_update(), brin_xlog_update(), btree_xlog_dedup(), btree_xlog_delete(), btree_xlog_insert(), btree_xlog_mark_page_halfdead(), btree_xlog_split(), btree_xlog_unlink_page(), generic_redo(), ginRedoClearIncompleteSplit(), ginRedoDeletePage(), ginRedoInsert(), ginRedoSplit(), ginRedoUpdateMetapage(), ginRedoVacuumDataLeafPage(), ginRedoVacuumPage(), gistRedoClearFollowRight(), gistRedoDeleteRecord(), gistRedoPageDelete(), gistRedoPageUpdateRecord(), hash_xlog_add_ovfl_page(), hash_xlog_delete(), hash_xlog_init_bitmap_page(), hash_xlog_insert(), hash_xlog_move_page_contents(), hash_xlog_split_allocate_page(), hash_xlog_split_cleanup(), hash_xlog_split_complete(), hash_xlog_split_page(), hash_xlog_squeeze_page(), hash_xlog_update_meta_page(), hash_xlog_vacuum_one_page(), heap_xlog_confirm(), heap_xlog_delete(), heap_xlog_freeze_page(), heap_xlog_inplace(), heap_xlog_insert(), heap_xlog_lock(), heap_xlog_lock_updated(), heap_xlog_multi_insert(), heap_xlog_update(), heap_xlog_visible(), spgRedoAddLeaf(), spgRedoAddNode(), spgRedoMoveLeafs(), spgRedoPickSplit(), spgRedoSplitTuple(), spgRedoVacuumLeaf(), spgRedoVacuumRedirect(), spgRedoVacuumRoot(), and xlog_redo().

294 {
295  return XLogReadBufferForRedoExtended(record, block_id, RBM_NORMAL,
296  false, buf);
297 }
static char * buf
Definition: pg_test_fsync.c:68
XLogRedoAction XLogReadBufferForRedoExtended(XLogReaderState *record, uint8 block_id, ReadBufferMode mode, bool get_cleanup_lock, Buffer *buf)
Definition: xlogutils.c:329

◆ XLogReadBufferForRedoExtended()

XLogRedoAction XLogReadBufferForRedoExtended ( XLogReaderState record,
uint8  block_id,
ReadBufferMode  mode,
bool  get_cleanup_lock,
Buffer buf 
)

Definition at line 329 of file xlogutils.c.

References Assert, BKPBLOCK_WILL_INIT, BLK_DONE, BLK_NEEDS_REDO, BLK_NOTFOUND, BLK_RESTORED, xl_invalid_page_key::blkno, DecodedXLogRecord::blocks, BUFFER_LOCK_EXCLUSIVE, BufferGetPage, BufferIsValid, elog, XLogReaderState::EndRecPtr, ERROR, DecodedBkpBlock::flags, FlushOneBuffer(), INIT_FORKNUM, LockBuffer(), LockBufferForCleanup(), MarkBufferDirty(), PageGetLSN, PageIsNew, PageSetLSN, PANIC, RBM_ZERO_AND_CLEANUP_LOCK, RBM_ZERO_AND_LOCK, XLogReaderState::record, RestoreBlockImage(), XLogReadBufferExtended(), XLogRecBlockImageApply, XLogRecGetRecentBuffer(), and XLogRecHasBlockImage.

Referenced by btree_xlog_vacuum(), hash_xlog_delete(), hash_xlog_move_page_contents(), hash_xlog_split_allocate_page(), hash_xlog_squeeze_page(), hash_xlog_vacuum_one_page(), heap_xlog_prune(), heap_xlog_vacuum(), heap_xlog_visible(), XLogInitBufferForRedo(), and XLogReadBufferForRedo().

333 {
334  XLogRecPtr lsn = record->EndRecPtr;
335  RelFileNode rnode;
336  ForkNumber forknum;
337  BlockNumber blkno;
338  Buffer recent_buffer;
339  Page page;
340  bool zeromode;
341  bool willinit;
342 
343  if (!XLogRecGetRecentBuffer(record, block_id, &rnode, &forknum, &blkno,
344  &recent_buffer))
345  {
346  /* Caller specified a bogus block_id */
347  elog(PANIC, "failed to locate backup block with ID %d", block_id);
348  }
349 
350  /*
351  * Make sure that if the block is marked with WILL_INIT, the caller is
352  * going to initialize it. And vice versa.
353  */
355  willinit = (record->record->blocks[block_id].flags & BKPBLOCK_WILL_INIT) != 0;
356  if (willinit && !zeromode)
357  elog(PANIC, "block with WILL_INIT flag in WAL record must be zeroed by redo routine");
358  if (!willinit && zeromode)
359  elog(PANIC, "block to be initialized in redo routine must be marked with WILL_INIT flag in the WAL record");
360 
361  /* If it has a full-page image and it should be restored, do it. */
362  if (XLogRecBlockImageApply(record, block_id))
363  {
364  Assert(XLogRecHasBlockImage(record, block_id));
365  *buf = XLogReadBufferExtended(rnode, forknum, blkno,
366  get_cleanup_lock ? RBM_ZERO_AND_CLEANUP_LOCK : RBM_ZERO_AND_LOCK,
367  recent_buffer);
368  page = BufferGetPage(*buf);
369  if (!RestoreBlockImage(record, block_id, page))
370  elog(ERROR, "failed to restore block image");
371 
372  /*
373  * The page may be uninitialized. If so, we can't set the LSN because
374  * that would corrupt the page.
375  */
376  if (!PageIsNew(page))
377  {
378  PageSetLSN(page, lsn);
379  }
380 
382 
383  /*
384  * At the end of crash recovery the init forks of unlogged relations
385  * are copied, without going through shared buffers. So we need to
386  * force the on-disk state of init forks to always be in sync with the
387  * state in shared buffers.
388  */
389  if (forknum == INIT_FORKNUM)
391 
392  return BLK_RESTORED;
393  }
394  else
395  {
396  *buf = XLogReadBufferExtended(rnode, forknum, blkno, mode,
397  recent_buffer);
398  if (BufferIsValid(*buf))
399  {
401  {
402  if (get_cleanup_lock)
404  else
406  }
407  if (lsn <= PageGetLSN(BufferGetPage(*buf)))
408  return BLK_DONE;
409  else
410  return BLK_NEEDS_REDO;
411  }
412  else
413  return BLK_NOTFOUND;
414  }
415 }
static PgChecksumMode mode
Definition: pg_checksums.c:61
void LockBufferForCleanup(Buffer buffer)
Definition: bufmgr.c:4080
#define XLogRecHasBlockImage(decoder, block_id)
Definition: xlogreader.h:390
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1562
uint32 BlockNumber
Definition: block.h:31
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:98
#define PANIC
Definition: elog.h:50
XLogRecPtr EndRecPtr
Definition: xlogreader.h:179
Buffer XLogReadBufferExtended(RelFileNode rnode, ForkNumber forknum, BlockNumber blkno, ReadBufferMode mode, Buffer recent_buffer)
Definition: xlogutils.c:443
#define ERROR
Definition: elog.h:46
static char * buf
Definition: pg_test_fsync.c:68
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
#define BKPBLOCK_WILL_INIT
Definition: xlogrecord.h:182
ForkNumber
Definition: relpath.h:40
DecodedBkpBlock blocks[FLEXIBLE_ARRAY_MEMBER]
Definition: xlogreader.h:149
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4023
DecodedXLogRecord * record
Definition: xlogreader.h:214
bool XLogRecGetRecentBuffer(XLogReaderState *record, uint8 block_id, RelFileNode *rnode, ForkNumber *forknum, BlockNumber *blknum, Buffer *recent_buffer)
Definition: xlogreader.c:2140
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:804
#define BufferIsValid(bufnum)
Definition: bufmgr.h:123
void FlushOneBuffer(Buffer buffer)
Definition: bufmgr.c:3764
bool RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
Definition: xlogreader.c:2198
#define PageGetLSN(page)
Definition: bufpage.h:366
#define PageIsNew(page)
Definition: bufpage.h:229
#define elog(elevel,...)
Definition: elog.h:232
#define XLogRecBlockImageApply(decoder, block_id)
Definition: xlogreader.h:392
#define PageSetLSN(page, lsn)
Definition: bufpage.h:368
int Buffer
Definition: buf.h:23
Pointer Page
Definition: bufpage.h:78

◆ XLogReadDetermineTimeline()

void XLogReadDetermineTimeline ( XLogReaderState state,
XLogRecPtr  wantPage,
uint32  wantLength 
)

Definition at line 702 of file xlogutils.c.

References Assert, XLogReaderState::currTLI, XLogReaderState::currTLIValidUntil, DEBUG3, elog, InvalidXLogRecPtr, list_free_deep(), LSN_FORMAT_ARGS, Min, XLogReaderState::nextTLI, XLogReaderState::page_verified, XLogReaderState::readLen, XLogReaderState::readPagePtr, readTimeLineHistory(), XLogReaderState::segcxt, ThisTimeLineID, tliOfPointInHistory(), tliSwitchPoint(), and WALSegmentContext::ws_segsize.

Referenced by logical_read_xlog_page(), and read_local_xlog_page().

703 {
704  const XLogRecPtr lastReadPage = state->readPagePtr;
705 
706  Assert(wantPage != InvalidXLogRecPtr && wantPage % XLOG_BLCKSZ == 0);
707  Assert(wantLength <= XLOG_BLCKSZ);
708  Assert(state->readLen == 0 || state->readLen <= XLOG_BLCKSZ);
709 
710  /*
711  * If the desired page is currently read in and valid, we have nothing to
712  * do.
713  *
714  * The caller should've ensured that it didn't previously advance readOff
715  * past the valid limit of this timeline, so it doesn't matter if the
716  * current TLI has since become historical.
717  */
718  if (lastReadPage == wantPage &&
719  state->page_verified &&
720  lastReadPage + state->readLen >= wantPage + Min(wantLength, XLOG_BLCKSZ - 1))
721  return;
722 
723  /*
724  * If we're reading from the current timeline, it hasn't become historical
725  * and the page we're reading is after the last page read, we can again
726  * just carry on. (Seeking backwards requires a check to make sure the
727  * older page isn't on a prior timeline).
728  *
729  * ThisTimeLineID might've become historical since we last looked, but the
730  * caller is required not to read past the flush limit it saw at the time
731  * it looked up the timeline. There's nothing we can do about it if
732  * StartupXLOG() renames it to .partial concurrently.
733  */
734  if (state->currTLI == ThisTimeLineID && wantPage >= lastReadPage)
735  {
737  return;
738  }
739 
740  /*
741  * If we're just reading pages from a previously validated historical
742  * timeline and the timeline we're reading from is valid until the end of
743  * the current segment we can just keep reading.
744  */
745  if (state->currTLIValidUntil != InvalidXLogRecPtr &&
746  state->currTLI != ThisTimeLineID &&
747  state->currTLI != 0 &&
748  ((wantPage + wantLength) / state->segcxt.ws_segsize) <
749  (state->currTLIValidUntil / state->segcxt.ws_segsize))
750  return;
751 
752  /*
753  * If we reach this point we're either looking up a page for random
754  * access, the current timeline just became historical, or we're reading
755  * from a new segment containing a timeline switch. In all cases we need
756  * to determine the newest timeline on the segment.
757  *
758  * If it's the current timeline we can just keep reading from here unless
759  * we detect a timeline switch that makes the current timeline historical.
760  * If it's a historical timeline we can read all the segment on the newest
761  * timeline because it contains all the old timelines' data too. So only
762  * one switch check is required.
763  */
764  {
765  /*
766  * We need to re-read the timeline history in case it's been changed
767  * by a promotion or replay from a cascaded replica.
768  */
769  List *timelineHistory = readTimeLineHistory(ThisTimeLineID);
770  XLogRecPtr endOfSegment;
771 
772  endOfSegment = ((wantPage / state->segcxt.ws_segsize) + 1) *
773  state->segcxt.ws_segsize - 1;
774  Assert(wantPage / state->segcxt.ws_segsize ==
775  endOfSegment / state->segcxt.ws_segsize);
776 
777  /*
778  * Find the timeline of the last LSN on the segment containing
779  * wantPage.
780  */
781  state->currTLI = tliOfPointInHistory(endOfSegment, timelineHistory);
782  state->currTLIValidUntil = tliSwitchPoint(state->currTLI, timelineHistory,
783  &state->nextTLI);
784 
786  wantPage + wantLength < state->currTLIValidUntil);
787 
788  list_free_deep(timelineHistory);
789 
790  elog(DEBUG3, "switched to timeline %u valid until %X/%X",
791  state->currTLI,
793  }
794 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
TimeLineID tliOfPointInHistory(XLogRecPtr ptr, List *history)
Definition: timeline.c:552
#define DEBUG3
Definition: elog.h:23
#define Min(x, y)
Definition: c.h:986
List * readTimeLineHistory(TimeLineID targetTLI)
Definition: timeline.c:76
void list_free_deep(List *list)
Definition: list.c:1405
#define LSN_FORMAT_ARGS(lsn)
Definition: xlogdefs.h:43
XLogRecPtr readPagePtr
Definition: xlogreader.h:187
XLogRecPtr currTLIValidUntil
Definition: xlogreader.h:264
TimeLineID nextTLI
Definition: xlogreader.h:270
XLogRecPtr tliSwitchPoint(TimeLineID tli, List *history, TimeLineID *nextTLI)
Definition: timeline.c:580
TimeLineID ThisTimeLineID
Definition: xlog.c:196
TimeLineID currTLI
Definition: xlogreader.h:254
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:804
#define elog(elevel,...)
Definition: elog.h:232
WALSegmentContext segcxt
Definition: xlogreader.h:242
Definition: pg_list.h:50

◆ XLogTruncateRelation()

void XLogTruncateRelation ( RelFileNode  rnode,
ForkNumber  forkNum,
BlockNumber  nblocks 
)

Definition at line 657 of file xlogutils.c.

References forget_invalid_pages().

Referenced by smgr_redo().

659 {
660  forget_invalid_pages(rnode, forkNum, nblocks);
661 }
static void forget_invalid_pages(RelFileNode node, ForkNumber forkno, BlockNumber minblkno)
Definition: xlogutils.c:145

Variable Documentation

◆ ignore_invalid_pages

bool ignore_invalid_pages = false

Definition at line 35 of file xlogutils.c.

Referenced by log_invalid_page(), and XLogCheckInvalidPages().

◆ invalid_page_tab

HTAB* invalid_page_tab = NULL
static

Definition at line 60 of file xlogutils.c.