MCPcopy Create free account
hub / github.com/apache/cloudberry / DecodeUpdate

Function DecodeUpdate

src/backend/replication/logical/decode.c:906–966  ·  view source on GitHub ↗

* Parse XLOG_HEAP_UPDATE and XLOG_HEAP_HOT_UPDATE, which have the same layout * in the record, from wal into proper tuplebufs. * * Updates can possibly contain a new tuple and the old primary key. */

Source from the content-addressed store, hash-verified

904 * Updates can possibly contain a new tuple and the old primary key.
905 */
906static void
907DecodeUpdate(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
908{
909 XLogReaderState *r = buf->record;
910 xl_heap_update *xlrec;
911 ReorderBufferChange *change;
912 char *data;
913 RelFileNode target_node;
914
915 xlrec = (xl_heap_update *) XLogRecGetData(r);
916
917 /* only interested in our database */
918 XLogRecGetBlockTag(r, 0, &target_node, NULL, NULL);
919 if (target_node.dbNode != ctx->slot->data.database)
920 return;
921
922 /* output plugin doesn't look for this origin, no need to queue */
923 if (FilterByOrigin(ctx, XLogRecGetOrigin(r)))
924 return;
925
926 change = ReorderBufferGetChange(ctx->reorder);
927 change->action = REORDER_BUFFER_CHANGE_UPDATE;
928 change->origin_id = XLogRecGetOrigin(r);
929 memcpy(&change->data.tp.relnode, &target_node, sizeof(RelFileNode));
930
931 if (xlrec->flags & XLH_UPDATE_CONTAINS_NEW_TUPLE)
932 {
933 Size datalen;
934 Size tuplelen;
935
936 data = XLogRecGetBlockData(r, 0, &datalen);
937
938 tuplelen = datalen - SizeOfHeapHeader;
939
940 change->data.tp.newtuple =
941 ReorderBufferGetTupleBuf(ctx->reorder, tuplelen);
942
943 DecodeXLogTuple(data, datalen, change->data.tp.newtuple);
944 }
945
946 if (xlrec->flags & XLH_UPDATE_CONTAINS_OLD)
947 {
948 Size datalen;
949 Size tuplelen;
950
951 /* caution, remaining data in record is not aligned */
952 data = XLogRecGetData(r) + SizeOfHeapUpdate;
953 datalen = XLogRecGetDataLen(r) - SizeOfHeapUpdate;
954 tuplelen = datalen - SizeOfHeapHeader;
955
956 change->data.tp.oldtuple =
957 ReorderBufferGetTupleBuf(ctx->reorder, tuplelen);
958
959 DecodeXLogTuple(data, datalen, change->data.tp.oldtuple);
960 }
961
962 change->data.tp.clear_toast_afterwards = true;
963

Callers 1

heap_decodeFunction · 0.85

Calls 7

XLogRecGetBlockTagFunction · 0.85
FilterByOriginFunction · 0.85
ReorderBufferGetChangeFunction · 0.85
XLogRecGetBlockDataFunction · 0.85
ReorderBufferGetTupleBufFunction · 0.85
DecodeXLogTupleFunction · 0.85
ReorderBufferQueueChangeFunction · 0.85

Tested by

no test coverage detected