Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite3e84fd

Browse files
committed
Further improvements toc8f621c.
Coverity and inspection for the issue addressed infd45d16 found somequestionable code.Specifically coverity noticed that the wrong length was added inReorderBufferSerializeChange() - without immediate negative consequencesas the variable isn't used afterwards. During code-review and testing Inoticed that a bit of space was wasted when allocating tuple bufs inseveral places. Thirdly, the debug memset()s inReorderBufferGetTupleBuf() reduce the error checking valgrind can do.Backpatch: 9.4, likec8f621c.
1 parent89f8372 commite3e84fd

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

‎src/backend/replication/logical/decode.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -625,15 +625,16 @@ DecodeInsert(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
625625

626626
if (xlrec->flags&XLOG_HEAP_CONTAINS_NEW_TUPLE)
627627
{
628-
Sizetuplelen=r->xl_len-SizeOfHeapInsert;
628+
Sizedatalen=r->xl_len-SizeOfHeapInsert;
629+
Sizetuplelen=datalen-SizeOfHeapHeader;
629630

630631
Assert(r->xl_len> (SizeOfHeapInsert+SizeOfHeapHeader));
631632

632633
change->data.tp.newtuple=
633634
ReorderBufferGetTupleBuf(ctx->reorder,tuplelen);
634635

635636
DecodeXLogTuple((char*)xlrec+SizeOfHeapInsert,
636-
tuplelen,change->data.tp.newtuple);
637+
datalen,change->data.tp.newtuple);
637638
}
638639

639640
change->data.tp.clear_toast_afterwards= true;
@@ -670,6 +671,7 @@ DecodeUpdate(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
670671

671672
if (xlrec->flags&XLOG_HEAP_CONTAINS_NEW_TUPLE)
672673
{
674+
Sizedatalen;
673675
Sizetuplelen;
674676
xl_heap_header_lenxlhdr;
675677

@@ -678,12 +680,13 @@ DecodeUpdate(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
678680
memcpy(&xlhdr,data,sizeof(xlhdr));
679681
data+= offsetof(xl_heap_header_len,header);
680682

681-
tuplelen=xlhdr.t_len+SizeOfHeapHeader;
683+
datalen=xlhdr.t_len+SizeOfHeapHeader;
684+
tuplelen=xlhdr.t_len;
682685

683686
change->data.tp.newtuple=
684687
ReorderBufferGetTupleBuf(ctx->reorder,tuplelen);
685688

686-
DecodeXLogTuple(data,tuplelen,change->data.tp.newtuple);
689+
DecodeXLogTuple(data,datalen,change->data.tp.newtuple);
687690
/* skip over the rest of the tuple header */
688691
data+=SizeOfHeapHeader;
689692
/* skip over the tuple data */
@@ -692,18 +695,20 @@ DecodeUpdate(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
692695

693696
if (xlrec->flags&XLOG_HEAP_CONTAINS_OLD)
694697
{
698+
Sizedatalen;
695699
Sizetuplelen;
696700
xl_heap_header_lenxlhdr;
697701

698702
memcpy(&xlhdr,data,sizeof(xlhdr));
699703
data+= offsetof(xl_heap_header_len,header);
700704

701-
tuplelen=xlhdr.t_len+SizeOfHeapHeader;
705+
datalen=xlhdr.t_len+SizeOfHeapHeader;
706+
tuplelen=xlhdr.t_len;
702707

703708
change->data.tp.oldtuple=
704709
ReorderBufferGetTupleBuf(ctx->reorder,tuplelen);
705710

706-
DecodeXLogTuple(data,tuplelen,change->data.tp.oldtuple);
711+
DecodeXLogTuple(data,datalen,change->data.tp.oldtuple);
707712
#ifdefNOT_USED
708713
data+=SizeOfHeapHeader;
709714
data+=xlhdr.t_len;
@@ -741,15 +746,16 @@ DecodeDelete(LogicalDecodingContext *ctx, XLogRecordBuffer *buf)
741746
/* old primary key stored */
742747
if (xlrec->flags&XLOG_HEAP_CONTAINS_OLD)
743748
{
744-
Sizelen=r->xl_len-SizeOfHeapDelete;
749+
Sizedatalen=r->xl_len-SizeOfHeapDelete;
750+
Sizetuplelen=datalen-SizeOfHeapHeader;
745751

746752
Assert(r->xl_len> (SizeOfHeapDelete+SizeOfHeapHeader));
747753

748754
change->data.tp.oldtuple=
749-
ReorderBufferGetTupleBuf(ctx->reorder,len);
755+
ReorderBufferGetTupleBuf(ctx->reorder,tuplelen);
750756

751757
DecodeXLogTuple((char*)xlrec+SizeOfHeapDelete,
752-
len,change->data.tp.oldtuple);
758+
datalen,change->data.tp.oldtuple);
753759
}
754760

755761
change->data.tp.clear_toast_afterwards= true;

‎src/backend/replication/logical/reorderbuffer.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,12 +469,15 @@ ReorderBufferGetTupleBuf(ReorderBuffer *rb, Size tuple_len)
469469
rb->nr_cached_tuplebufs--;
470470
tuple=slist_container(ReorderBufferTupleBuf,node,
471471
slist_pop_head_node(&rb->cached_tuplebufs));
472+
Assert(tuple->alloc_tuple_size==MaxHeapTupleSize);
472473
#ifdefUSE_ASSERT_CHECKING
473474
memset(&tuple->tuple,0xa9,sizeof(HeapTupleData));
475+
VALGRIND_MAKE_MEM_UNDEFINED(&tuple->tuple,sizeof(HeapTupleData));
474476
#endif
475477
tuple->tuple.t_data=ReorderBufferTupleBufData(tuple);
476478
#ifdefUSE_ASSERT_CHECKING
477479
memset(tuple->tuple.t_data,0xa8,tuple->alloc_tuple_size);
480+
VALGRIND_MAKE_MEM_UNDEFINED(tuple->tuple.t_data,tuple->alloc_tuple_size);
478481
#endif
479482
}
480483
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp