PostgreSQL Source Code git master
decode.h File Reference
Include dependency graph for decode.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  XLogRecordBuffer
 

Typedefs

typedef struct XLogRecordBuffer XLogRecordBuffer
 

Functions

void xlog_decode (LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
 
void heap_decode (LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
 
void heap2_decode (LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
 
void xact_decode (LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
 
void standby_decode (LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
 
void logicalmsg_decode (LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
 
void LogicalDecodingProcessRecord (LogicalDecodingContext *ctx, XLogReaderState *record)
 

Typedef Documentation

◆ XLogRecordBuffer

Function Documentation

◆ heap2_decode()

void heap2_decode ( LogicalDecodingContext ctx,
XLogRecordBuffer buf 
)

Definition at line 400 of file decode.c.

401{
402 uint8 info = XLogRecGetInfo(buf->record) & XLOG_HEAP_OPMASK;
403 TransactionId xid = XLogRecGetXid(buf->record);
404 SnapBuild *builder = ctx->snapshot_builder;
405
406 ReorderBufferProcessXid(ctx->reorder, xid, buf->origptr);
407
408 /*
409 * If we don't have snapshot or we are just fast-forwarding, there is no
410 * point in decoding data changes. However, it's crucial to build the base
411 * snapshot during fast-forward mode (as is done in
412 * SnapBuildProcessChange()) because we require the snapshot's xmin when
413 * determining the candidate catalog_xmin for the replication slot. See
414 * SnapBuildProcessRunningXacts().
415 */
417 return;
418
419 switch (info)
420 {
422 if (SnapBuildProcessChange(builder, xid, buf->origptr) &&
423 !ctx->fast_forward)
425 break;
427 if (!ctx->fast_forward)
428 {
429 xl_heap_new_cid *xlrec;
430
431 xlrec = (xl_heap_new_cid *) XLogRecGetData(buf->record);
432 SnapBuildProcessNewCid(builder, xid, buf->origptr, xlrec);
433
434 break;
435 }
437
438 /*
439 * Although these records only exist to serve the needs of logical
440 * decoding, all the work happens as part of crash or archive
441 * recovery, so we don't need to do anything here.
442 */
443 break;
444
445 /*
446 * Everything else here is just low level physical stuff we're not
447 * interested in.
448 */
454 break;
455 default:
456 elog(ERROR, "unexpected RM_HEAP2_ID record type: %u", info);
457 }
458}
uint8_t uint8
Definition: c.h:550
uint32 TransactionId
Definition: c.h:672
static void DecodeMultiInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:1107
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
#define XLOG_HEAP2_MULTI_INSERT
Definition: heapam_xlog.h:64
#define XLOG_HEAP2_REWRITE
Definition: heapam_xlog.h:59
#define XLOG_HEAP_OPMASK
Definition: heapam_xlog.h:42
#define XLOG_HEAP2_PRUNE_VACUUM_SCAN
Definition: heapam_xlog.h:61
#define XLOG_HEAP2_LOCK_UPDATED
Definition: heapam_xlog.h:65
#define XLOG_HEAP2_PRUNE_ON_ACCESS
Definition: heapam_xlog.h:60
#define XLOG_HEAP2_NEW_CID
Definition: heapam_xlog.h:66
#define XLOG_HEAP2_PRUNE_VACUUM_CLEANUP
Definition: heapam_xlog.h:62
#define XLOG_HEAP2_VISIBLE
Definition: heapam_xlog.h:63
static char buf[DEFAULT_XLOG_SEG_SIZE]
Definition: pg_test_fsync.c:71
void ReorderBufferProcessXid(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
bool SnapBuildProcessChange(SnapBuild *builder, TransactionId xid, XLogRecPtr lsn)
Definition: snapbuild.c:638
SnapBuildState SnapBuildCurrentState(SnapBuild *builder)
Definition: snapbuild.c:277
void SnapBuildProcessNewCid(SnapBuild *builder, TransactionId xid, XLogRecPtr lsn, xl_heap_new_cid *xlrec)
Definition: snapbuild.c:688
@ SNAPBUILD_FULL_SNAPSHOT
Definition: snapbuild.h:43
struct SnapBuild * snapshot_builder
Definition: logical.h:44
struct ReorderBuffer * reorder
Definition: logical.h:43
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:409
#define XLogRecGetData(decoder)
Definition: xlogreader.h:414
#define XLogRecGetXid(decoder)
Definition: xlogreader.h:411

References buf, DecodeMultiInsert(), elog, ERROR, LogicalDecodingContext::fast_forward, LogicalDecodingContext::reorder, ReorderBufferProcessXid(), SNAPBUILD_FULL_SNAPSHOT, SnapBuildCurrentState(), SnapBuildProcessChange(), SnapBuildProcessNewCid(), LogicalDecodingContext::snapshot_builder, XLOG_HEAP2_LOCK_UPDATED, XLOG_HEAP2_MULTI_INSERT, XLOG_HEAP2_NEW_CID, XLOG_HEAP2_PRUNE_ON_ACCESS, XLOG_HEAP2_PRUNE_VACUUM_CLEANUP, XLOG_HEAP2_PRUNE_VACUUM_SCAN, XLOG_HEAP2_REWRITE, XLOG_HEAP2_VISIBLE, XLOG_HEAP_OPMASK, XLogRecGetData, XLogRecGetInfo, and XLogRecGetXid.

◆ heap_decode()

void heap_decode ( LogicalDecodingContext ctx,
XLogRecordBuffer buf 
)

Definition at line 464 of file decode.c.

465{
466 uint8 info = XLogRecGetInfo(buf->record) & XLOG_HEAP_OPMASK;
467 TransactionId xid = XLogRecGetXid(buf->record);
468 SnapBuild *builder = ctx->snapshot_builder;
469
470 ReorderBufferProcessXid(ctx->reorder, xid, buf->origptr);
471
472 /*
473 * If we don't have snapshot or we are just fast-forwarding, there is no
474 * point in decoding data changes. However, it's crucial to build the base
475 * snapshot during fast-forward mode (as is done in
476 * SnapBuildProcessChange()) because we require the snapshot's xmin when
477 * determining the candidate catalog_xmin for the replication slot. See
478 * SnapBuildProcessRunningXacts().
479 */
481 return;
482
483 switch (info)
484 {
485 case XLOG_HEAP_INSERT:
486 if (SnapBuildProcessChange(builder, xid, buf->origptr) &&
487 !ctx->fast_forward)
488 DecodeInsert(ctx, buf);
489 break;
490
491 /*
492 * Treat HOT update as normal updates. There is no useful
493 * information in the fact that we could make it a HOT update
494 * locally and the WAL layout is compatible.
495 */
497 case XLOG_HEAP_UPDATE:
498 if (SnapBuildProcessChange(builder, xid, buf->origptr) &&
499 !ctx->fast_forward)
500 DecodeUpdate(ctx, buf);
501 break;
502
503 case XLOG_HEAP_DELETE:
504 if (SnapBuildProcessChange(builder, xid, buf->origptr) &&
505 !ctx->fast_forward)
506 DecodeDelete(ctx, buf);
507 break;
508
510 if (SnapBuildProcessChange(builder, xid, buf->origptr) &&
511 !ctx->fast_forward)
512 DecodeTruncate(ctx, buf);
513 break;
514
516
517 /*
518 * Inplace updates are only ever performed on catalog tuples and
519 * can, per definition, not change tuple visibility. Since we
520 * also don't decode catalog tuples, we're not interested in the
521 * record's contents.
522 */
523 break;
524
526 if (SnapBuildProcessChange(builder, xid, buf->origptr) &&
527 !ctx->fast_forward)
529 break;
530
531 case XLOG_HEAP_LOCK:
532 /* we don't care about row level locks for now */
533 break;
534
535 default:
536 elog(ERROR, "unexpected RM_HEAP_ID record type: %u", info);
537 break;
538 }
539}
static void DecodeDelete(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:1015
static void DecodeInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:889
static void DecodeTruncate(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:1069
static void DecodeUpdate(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:948
static void DecodeSpecConfirm(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
Definition: decode.c:1211
#define XLOG_HEAP_HOT_UPDATE
Definition: heapam_xlog.h:37
#define XLOG_HEAP_DELETE
Definition: heapam_xlog.h:34
#define XLOG_HEAP_TRUNCATE
Definition: heapam_xlog.h:36
#define XLOG_HEAP_UPDATE
Definition: heapam_xlog.h:35
#define XLOG_HEAP_INPLACE
Definition: heapam_xlog.h:40
#define XLOG_HEAP_LOCK
Definition: heapam_xlog.h:39
#define XLOG_HEAP_INSERT
Definition: heapam_xlog.h:33
#define XLOG_HEAP_CONFIRM
Definition: heapam_xlog.h:38

References buf, DecodeDelete(), DecodeInsert(), DecodeSpecConfirm(), DecodeTruncate(), DecodeUpdate(), elog, ERROR, LogicalDecodingContext::fast_forward, LogicalDecodingContext::reorder, ReorderBufferProcessXid(), SNAPBUILD_FULL_SNAPSHOT, SnapBuildCurrentState(), SnapBuildProcessChange(), LogicalDecodingContext::snapshot_builder, XLOG_HEAP_CONFIRM, XLOG_HEAP_DELETE, XLOG_HEAP_HOT_UPDATE, XLOG_HEAP_INPLACE, XLOG_HEAP_INSERT, XLOG_HEAP_LOCK, XLOG_HEAP_OPMASK, XLOG_HEAP_TRUNCATE, XLOG_HEAP_UPDATE, XLogRecGetInfo, and XLogRecGetXid.

◆ LogicalDecodingProcessRecord()

void LogicalDecodingProcessRecord ( LogicalDecodingContext ctx,
XLogReaderState record 
)

Definition at line 88 of file decode.c.

89{
91 TransactionId txid;
92 RmgrData rmgr;
93
94 buf.origptr = ctx->reader->ReadRecPtr;
95 buf.endptr = ctx->reader->EndRecPtr;
96 buf.record = record;
97
98 txid = XLogRecGetTopXid(record);
99
100 /*
101 * If the top-level xid is valid, we need to assign the subxact to the
102 * top-level xact. We need to do this for all records, hence we do it
103 * before the switch.
104 */
105 if (TransactionIdIsValid(txid))
106 {
108 txid,
109 XLogRecGetXid(record),
110 buf.origptr);
111 }
112
113 rmgr = GetRmgr(XLogRecGetRmid(record));
114
115 if (rmgr.rm_decode != NULL)
116 rmgr.rm_decode(ctx, &buf);
117 else
118 {
119 /* just deal with xid, and done */
121 buf.origptr);
122 }
123}
void ReorderBufferAssignChild(ReorderBuffer *rb, TransactionId xid, TransactionId subxid, XLogRecPtr lsn)
XLogReaderState * reader
Definition: logical.h:42
void(* rm_decode)(struct LogicalDecodingContext *ctx, struct XLogRecordBuffer *buf)
XLogRecPtr EndRecPtr
Definition: xlogreader.h:206
XLogRecPtr ReadRecPtr
Definition: xlogreader.h:205
#define TransactionIdIsValid(xid)
Definition: transam.h:41
static RmgrData GetRmgr(RmgrId rmid)
#define XLogRecGetRmid(decoder)
Definition: xlogreader.h:410
#define XLogRecGetTopXid(decoder)
Definition: xlogreader.h:413

References buf, XLogReaderState::EndRecPtr, GetRmgr(), LogicalDecodingContext::reader, XLogReaderState::ReadRecPtr, LogicalDecodingContext::reorder, ReorderBufferAssignChild(), ReorderBufferProcessXid(), RmgrData::rm_decode, TransactionIdIsValid, XLogRecGetRmid, XLogRecGetTopXid, and XLogRecGetXid.

Referenced by DecodingContextFindStartpoint(), LogicalReplicationSlotHasPendingWal(), LogicalSlotAdvanceAndCheckSnapState(), pg_logical_slot_get_changes_guts(), and XLogSendLogical().

◆ logicalmsg_decode()

void logicalmsg_decode ( LogicalDecodingContext ctx,
XLogRecordBuffer buf 
)

Definition at line 581 of file decode.c.

582{
583 SnapBuild *builder = ctx->snapshot_builder;
584 XLogReaderState *r = buf->record;
586 uint8 info = XLogRecGetInfo(r) & ~XLR_INFO_MASK;
587 RepOriginId origin_id = XLogRecGetOrigin(r);
588 Snapshot snapshot = NULL;
589 xl_logical_message *message;
590
591 if (info != XLOG_LOGICAL_MESSAGE)
592 elog(ERROR, "unexpected RM_LOGICALMSG_ID record type: %u", info);
593
595
596 /* If we don't have snapshot, there is no point in decoding messages */
598 return;
599
600 message = (xl_logical_message *) XLogRecGetData(r);
601
602 if (message->dbId != ctx->slot->data.database ||
603 FilterByOrigin(ctx, origin_id))
604 return;
605
606 if (message->transactional &&
607 !SnapBuildProcessChange(builder, xid, buf->origptr))
608 return;
609 else if (!message->transactional &&
611 SnapBuildXactNeedsSkip(builder, buf->origptr)))
612 return;
613
614 /*
615 * We also skip decoding in fast_forward mode. This check must be last
616 * because we don't want to set the processing_required flag unless we
617 * have a decodable message.
618 */
619 if (ctx->fast_forward)
620 {
621 /*
622 * We need to set processing_required flag to notify the message's
623 * existence to the caller. Usually, the flag is set when either the
624 * COMMIT or ABORT records are decoded, but this must be turned on
625 * here because the non-transactional logical message is decoded
626 * without waiting for these records.
627 */
628 if (!message->transactional)
629 ctx->processing_required = true;
630
631 return;
632 }
633
634 /*
635 * If this is a non-transactional change, get the snapshot we're expected
636 * to use. We only get here when the snapshot is consistent, and the
637 * change is not meant to be skipped.
638 *
639 * For transactional changes we don't need a snapshot, we'll use the
640 * regular snapshot maintained by ReorderBuffer. We just leave it NULL.
641 */
642 if (!message->transactional)
643 snapshot = SnapBuildGetOrBuildSnapshot(builder);
644
645 ReorderBufferQueueMessage(ctx->reorder, xid, snapshot, buf->endptr,
646 message->transactional,
647 message->message, /* first part of message is
648 * prefix */
649 message->message_size,
650 message->message + message->prefix_size);
651}
static bool FilterByOrigin(LogicalDecodingContext *ctx, RepOriginId origin_id)
Definition: decode.c:569
#define XLOG_LOGICAL_MESSAGE
Definition: message.h:37
void ReorderBufferQueueMessage(ReorderBuffer *rb, TransactionId xid, Snapshot snap, XLogRecPtr lsn, bool transactional, const char *prefix, Size message_size, const char *message)
bool SnapBuildXactNeedsSkip(SnapBuild *builder, XLogRecPtr ptr)
Definition: snapbuild.c:304
Snapshot SnapBuildGetOrBuildSnapshot(SnapBuild *builder)
Definition: snapbuild.c:578
@ SNAPBUILD_CONSISTENT
Definition: snapbuild.h:50
ReplicationSlot * slot
Definition: logical.h:39
ReplicationSlotPersistentData data
Definition: slot.h:210
bool transactional
Definition: message.h:23
char message[FLEXIBLE_ARRAY_MEMBER]
Definition: message.h:27
uint16 RepOriginId
Definition: xlogdefs.h:69
#define XLogRecGetOrigin(decoder)
Definition: xlogreader.h:412

References buf, ReplicationSlot::data, ReplicationSlotPersistentData::database, xl_logical_message::dbId, elog, ERROR, LogicalDecodingContext::fast_forward, FilterByOrigin(), xl_logical_message::message, xl_logical_message::message_size, xl_logical_message::prefix_size, LogicalDecodingContext::processing_required, LogicalDecodingContext::reorder, ReorderBufferProcessXid(), ReorderBufferQueueMessage(), LogicalDecodingContext::slot, SNAPBUILD_CONSISTENT, SNAPBUILD_FULL_SNAPSHOT, SnapBuildCurrentState(), SnapBuildGetOrBuildSnapshot(), SnapBuildProcessChange(), SnapBuildXactNeedsSkip(), LogicalDecodingContext::snapshot_builder, xl_logical_message::transactional, XLOG_LOGICAL_MESSAGE, XLogRecGetData, XLogRecGetInfo, XLogRecGetOrigin, and XLogRecGetXid.

◆ standby_decode()

void standby_decode ( LogicalDecodingContext ctx,
XLogRecordBuffer buf 
)

Definition at line 354 of file decode.c.

355{
356 SnapBuild *builder = ctx->snapshot_builder;
357 XLogReaderState *r = buf->record;
358 uint8 info = XLogRecGetInfo(r) & ~XLR_INFO_MASK;
359
361
362 switch (info)
363 {
365 {
367
368 SnapBuildProcessRunningXacts(builder, buf->origptr, running);
369
370 /*
371 * Abort all transactions that we keep track of, that are
372 * older than the record's oldestRunningXid. This is the most
373 * convenient spot for doing so since, in contrast to shutdown
374 * or end-of-recovery checkpoints, we have information about
375 * all running transactions which includes prepared ones,
376 * while shutdown checkpoints just know that no non-prepared
377 * transactions are in progress.
378 */
380 }
381 break;
383 break;
385
386 /*
387 * We are processing the invalidations at the command level via
388 * XLOG_XACT_INVALIDATIONS. So we don't need to do anything here.
389 */
390 break;
391 default:
392 elog(ERROR, "unexpected RM_STANDBY_ID record type: %u", info);
393 }
394}
void ReorderBufferAbortOld(ReorderBuffer *rb, TransactionId oldestRunningXid)
void SnapBuildProcessRunningXacts(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *running)
Definition: snapbuild.c:1135
#define XLOG_INVALIDATIONS
Definition: standbydefs.h:36
#define XLOG_STANDBY_LOCK
Definition: standbydefs.h:34
#define XLOG_RUNNING_XACTS
Definition: standbydefs.h:35
TransactionId oldestRunningXid
Definition: standbydefs.h:53

References buf, elog, ERROR, xl_running_xacts::oldestRunningXid, LogicalDecodingContext::reorder, ReorderBufferAbortOld(), ReorderBufferProcessXid(), SnapBuildProcessRunningXacts(), LogicalDecodingContext::snapshot_builder, XLOG_INVALIDATIONS, XLOG_RUNNING_XACTS, XLOG_STANDBY_LOCK, XLogRecGetData, XLogRecGetInfo, and XLogRecGetXid.

◆ xact_decode()

void xact_decode ( LogicalDecodingContext ctx,
XLogRecordBuffer buf 
)

Definition at line 196 of file decode.c.

197{
198 SnapBuild *builder = ctx->snapshot_builder;
199 ReorderBuffer *reorder = ctx->reorder;
200 XLogReaderState *r = buf->record;
202
203 /*
204 * If the snapshot isn't yet fully built, we cannot decode anything, so
205 * bail out.
206 */
208 return;
209
210 switch (info)
211 {
212 case XLOG_XACT_COMMIT:
214 {
215 xl_xact_commit *xlrec;
217 TransactionId xid;
218 bool two_phase = false;
219
220 xlrec = (xl_xact_commit *) XLogRecGetData(r);
221 ParseCommitRecord(XLogRecGetInfo(buf->record), xlrec, &parsed);
222
224 xid = XLogRecGetXid(r);
225 else
226 xid = parsed.twophase_xid;
227
228 /*
229 * We would like to process the transaction in a two-phase
230 * manner iff output plugin supports two-phase commits and
231 * doesn't filter the transaction at prepare time.
232 */
233 if (info == XLOG_XACT_COMMIT_PREPARED)
234 two_phase = !(FilterPrepare(ctx, xid,
235 parsed.twophase_gid));
236
237 DecodeCommit(ctx, buf, &parsed, xid, two_phase);
238 break;
239 }
240 case XLOG_XACT_ABORT:
242 {
243 xl_xact_abort *xlrec;
245 TransactionId xid;
246 bool two_phase = false;
247
248 xlrec = (xl_xact_abort *) XLogRecGetData(r);
249 ParseAbortRecord(XLogRecGetInfo(buf->record), xlrec, &parsed);
250
252 xid = XLogRecGetXid(r);
253 else
254 xid = parsed.twophase_xid;
255
256 /*
257 * We would like to process the transaction in a two-phase
258 * manner iff output plugin supports two-phase commits and
259 * doesn't filter the transaction at prepare time.
260 */
261 if (info == XLOG_XACT_ABORT_PREPARED)
262 two_phase = !(FilterPrepare(ctx, xid,
263 parsed.twophase_gid));
264
265 DecodeAbort(ctx, buf, &parsed, xid, two_phase);
266 break;
267 }
269
270 /*
271 * We assign subxact to the toplevel xact while processing each
272 * record if required. So, we don't need to do anything here. See
273 * LogicalDecodingProcessRecord.
274 */
275 break;
277 {
278 TransactionId xid;
279 xl_xact_invals *invals;
280
281 xid = XLogRecGetXid(r);
282 invals = (xl_xact_invals *) XLogRecGetData(r);
283
284 /*
285 * Execute the invalidations for xid-less transactions,
286 * otherwise, accumulate them so that they can be processed at
287 * the commit time.
288 */
289 if (TransactionIdIsValid(xid))
290 {
291 if (!ctx->fast_forward)
293 buf->origptr,
294 invals->nmsgs,
295 invals->msgs);
297 buf->origptr);
298 }
299 else if (!ctx->fast_forward)
301 invals->nmsgs,
302 invals->msgs);
303
304 break;
305 }
307 {
309 xl_xact_prepare *xlrec;
310
311 /* ok, parse it */
312 xlrec = (xl_xact_prepare *) XLogRecGetData(r);
314 xlrec, &parsed);
315
316 /*
317 * We would like to process the transaction in a two-phase
318 * manner iff output plugin supports two-phase commits and
319 * doesn't filter the transaction at prepare time.
320 */
321 if (FilterPrepare(ctx, parsed.twophase_xid,
322 parsed.twophase_gid))
323 {
325 buf->origptr);
326 break;
327 }
328
329 /*
330 * Note that if the prepared transaction has locked [user]
331 * catalog tables exclusively then decoding prepare can block
332 * till the main transaction is committed because it needs to
333 * lock the catalog tables.
334 *
335 * XXX Now, this can even lead to a deadlock if the prepare
336 * transaction is waiting to get it logically replicated for
337 * distributed 2PC. This can be avoided by disallowing
338 * preparing transactions that have locked [user] catalog
339 * tables exclusively but as of now, we ask users not to do
340 * such an operation.
341 */
342 DecodePrepare(ctx, buf, &parsed);
343 break;
344 }
345 default:
346 elog(ERROR, "unexpected RM_XACT_ID record type: %u", info);
347 }
348}
static void DecodeAbort(LogicalDecodingContext *ctx, XLogRecordBuffer *buf, xl_xact_parsed_abort *parsed, TransactionId xid, bool two_phase)
Definition: decode.c:833
static bool FilterPrepare(LogicalDecodingContext *ctx, TransactionId xid, const char *gid)
Definition: decode.c:546
static void DecodeCommit(LogicalDecodingContext *ctx, XLogRecordBuffer *buf, xl_xact_parsed_commit *parsed, TransactionId xid, bool two_phase)
Definition: decode.c:662
static void DecodePrepare(LogicalDecodingContext *ctx, XLogRecordBuffer *buf, xl_xact_parsed_prepare *parsed)
Definition: decode.c:758
static bool two_phase
void ReorderBufferXidSetCatalogChanges(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn)
void ReorderBufferAddInvalidations(ReorderBuffer *rb, TransactionId xid, XLogRecPtr lsn, Size nmsgs, SharedInvalidationMessage *msgs)
void ReorderBufferImmediateInvalidation(ReorderBuffer *rb, uint32 ninvalidations, SharedInvalidationMessage *invalidations)
SharedInvalidationMessage msgs[FLEXIBLE_ARRAY_MEMBER]
Definition: xact.h:306
int nmsgs
Definition: xact.h:305
TransactionId twophase_xid
Definition: xact.h:428
char twophase_gid[GIDSIZE]
Definition: xact.h:429
TransactionId twophase_xid
Definition: xact.h:398
char twophase_gid[GIDSIZE]
Definition: xact.h:399
#define XLOG_XACT_COMMIT_PREPARED
Definition: xact.h:173
#define XLOG_XACT_INVALIDATIONS
Definition: xact.h:176
#define XLOG_XACT_PREPARE
Definition: xact.h:171
#define XLOG_XACT_COMMIT
Definition: xact.h:170
#define XLOG_XACT_OPMASK
Definition: xact.h:180
#define XLOG_XACT_ABORT
Definition: xact.h:172
#define XLOG_XACT_ASSIGNMENT
Definition: xact.h:175
#define XLOG_XACT_ABORT_PREPARED
Definition: xact.h:174
void ParseCommitRecord(uint8 info, xl_xact_commit *xlrec, xl_xact_parsed_commit *parsed)
Definition: xactdesc.c:35
void ParseAbortRecord(uint8 info, xl_xact_abort *xlrec, xl_xact_parsed_abort *parsed)
Definition: xactdesc.c:141
void ParsePrepareRecord(uint8 info, xl_xact_prepare *xlrec, xl_xact_parsed_prepare *parsed)
Definition: xactdesc.c:239

References buf, DecodeAbort(), DecodeCommit(), DecodePrepare(), elog, ERROR, LogicalDecodingContext::fast_forward, FilterPrepare(), xl_xact_invals::msgs, xl_xact_invals::nmsgs, ParseAbortRecord(), ParseCommitRecord(), ParsePrepareRecord(), LogicalDecodingContext::reorder, ReorderBufferAddInvalidations(), ReorderBufferImmediateInvalidation(), ReorderBufferProcessXid(), ReorderBufferXidSetCatalogChanges(), SNAPBUILD_FULL_SNAPSHOT, SnapBuildCurrentState(), LogicalDecodingContext::snapshot_builder, TransactionIdIsValid, two_phase, xl_xact_parsed_commit::twophase_gid, xl_xact_parsed_abort::twophase_gid, xl_xact_parsed_commit::twophase_xid, xl_xact_parsed_abort::twophase_xid, XLOG_XACT_ABORT, XLOG_XACT_ABORT_PREPARED, XLOG_XACT_ASSIGNMENT, XLOG_XACT_COMMIT, XLOG_XACT_COMMIT_PREPARED, XLOG_XACT_INVALIDATIONS, XLOG_XACT_OPMASK, XLOG_XACT_PREPARE, XLogRecGetData, XLogRecGetInfo, and XLogRecGetXid.

◆ xlog_decode()

void xlog_decode ( LogicalDecodingContext ctx,
XLogRecordBuffer buf 
)

Definition at line 129 of file decode.c.

130{
131 SnapBuild *builder = ctx->snapshot_builder;
132 uint8 info = XLogRecGetInfo(buf->record) & ~XLR_INFO_MASK;
133
135 buf->origptr);
136
137 switch (info)
138 {
139 /* this is also used in END_OF_RECOVERY checkpoints */
142 SnapBuildSerializationPoint(builder, buf->origptr);
143
144 break;
146
147 /*
148 * a RUNNING_XACTS record will have been logged near to this, we
149 * can restart from there.
150 */
151 break;
153 {
154 bool logical_decoding;
155
156 memcpy(&logical_decoding, XLogRecGetData(buf->record), sizeof(bool));
157
158 /*
159 * Error out as we should not decode this WAL record.
160 *
161 * Logical decoding is disabled, and existing logical slots on
162 * the standby are invalidated when this WAL record is
163 * replayed. No logical decoder can process this WAL record
164 * until replay completes, and by then the slots are already
165 * invalidated. Furthermore, no new logical slots can be
166 * created while logical decoding is disabled. This cannot
167 * occur even on primary either, since it will not restart
168 * with wal_level < replica if any logical slots exist.
169 */
170 elog(ERROR, "unexpected logical decoding status change %d",
171 logical_decoding);
172
173 break;
174 }
175 case XLOG_NOOP:
176 case XLOG_NEXTOID:
177 case XLOG_SWITCH:
178 case XLOG_BACKUP_END:
181 case XLOG_FPW_CHANGE:
183 case XLOG_FPI:
186 break;
187 default:
188 elog(ERROR, "unexpected RM_XLOG_ID record type: %u", info);
189 }
190}
#define XLOG_RESTORE_POINT
Definition: pg_control.h:76
#define XLOG_FPW_CHANGE
Definition: pg_control.h:77
#define XLOG_CHECKPOINT_REDO
Definition: pg_control.h:83
#define XLOG_OVERWRITE_CONTRECORD
Definition: pg_control.h:82
#define XLOG_FPI
Definition: pg_control.h:80
#define XLOG_FPI_FOR_HINT
Definition: pg_control.h:79
#define XLOG_NEXTOID
Definition: pg_control.h:72
#define XLOG_NOOP
Definition: pg_control.h:71
#define XLOG_CHECKPOINT_SHUTDOWN
Definition: pg_control.h:69
#define XLOG_SWITCH
Definition: pg_control.h:73
#define XLOG_BACKUP_END
Definition: pg_control.h:74
#define XLOG_PARAMETER_CHANGE
Definition: pg_control.h:75
#define XLOG_LOGICAL_DECODING_STATUS_CHANGE
Definition: pg_control.h:84
#define XLOG_CHECKPOINT_ONLINE
Definition: pg_control.h:70
#define XLOG_END_OF_RECOVERY
Definition: pg_control.h:78
void SnapBuildSerializationPoint(SnapBuild *builder, XLogRecPtr lsn)
Definition: snapbuild.c:1483

References buf, elog, ERROR, LogicalDecodingContext::reorder, ReorderBufferProcessXid(), SnapBuildSerializationPoint(), LogicalDecodingContext::snapshot_builder, XLOG_BACKUP_END, XLOG_CHECKPOINT_ONLINE, XLOG_CHECKPOINT_REDO, XLOG_CHECKPOINT_SHUTDOWN, XLOG_END_OF_RECOVERY, XLOG_FPI, XLOG_FPI_FOR_HINT, XLOG_FPW_CHANGE, XLOG_LOGICAL_DECODING_STATUS_CHANGE, XLOG_NEXTOID, XLOG_NOOP, XLOG_OVERWRITE_CONTRECORD, XLOG_PARAMETER_CHANGE, XLOG_RESTORE_POINT, XLOG_SWITCH, XLogRecGetData, XLogRecGetInfo, and XLogRecGetXid.