Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f1d8dd3

Browse files
committed
Code review for logical decoding patch.
Post-commit review identified a number of places where addition was used instead of multiplication or memory wasn't zeroed where it should have been. This commit also fixes one case where a structure member was mis-initialized, and moves another memory allocation closer to the place where the allocated storage is used for clarity. Andres Freund
1 parent b2dada8 commit f1d8dd3

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

src/backend/replication/logical/reorderbuffer.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,15 +2064,15 @@ ReorderBufferSerializeChange(ReorderBuffer *rb, ReorderBufferTXN *txn,
20642064
if (snap->xcnt)
20652065
{
20662066
memcpy(data, snap->xip,
2067-
sizeof(TransactionId) + snap->xcnt);
2068-
data += sizeof(TransactionId) + snap->xcnt;
2067+
sizeof(TransactionId) * snap->xcnt);
2068+
data += sizeof(TransactionId) * snap->xcnt;
20692069
}
20702070

20712071
if (snap->subxcnt)
20722072
{
20732073
memcpy(data, snap->subxip,
2074-
sizeof(TransactionId) + snap->subxcnt);
2075-
data += sizeof(TransactionId) + snap->subxcnt;
2074+
sizeof(TransactionId) * snap->subxcnt);
2075+
data += sizeof(TransactionId) * snap->subxcnt;
20762076
}
20772077
break;
20782078
}
@@ -2168,15 +2168,12 @@ ReorderBufferRestoreChanges(ReorderBuffer *rb, ReorderBufferTXN *txn,
21682168

21692169
}
21702170

2171-
ReorderBufferSerializeReserve(rb, sizeof(ReorderBufferDiskChange));
2172-
2173-
21742171
/*
21752172
* Read the statically sized part of a change which has information
21762173
* about the total size. If we couldn't read a record, we're at the
21772174
* end of this file.
21782175
*/
2179-
2176+
ReorderBufferSerializeReserve(rb, sizeof(ReorderBufferDiskChange));
21802177
readBytes = read(*fd, rb->outbuf, sizeof(ReorderBufferDiskChange));
21812178

21822179
/* eof */

src/backend/replication/logical/snapbuild.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,7 @@ AllocateSnapshotBuilder(ReorderBuffer *reorder,
307307
builder->committed.xip =
308308
palloc0(builder->committed.xcnt_space * sizeof(TransactionId));
309309
builder->committed.includes_all_transactions = true;
310-
builder->committed.xip =
311-
palloc0(builder->committed.xcnt_space * sizeof(TransactionId));
310+
312311
builder->initial_xmin_horizon = xmin_horizon;
313312
builder->transactions_after = start_lsn;
314313

@@ -1691,7 +1690,7 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
16911690

16921691
/* restore running xacts information */
16931692
sz = sizeof(TransactionId) * ondisk.builder.running.xcnt_space;
1694-
ondisk.builder.running.xip = MemoryContextAlloc(builder->context, sz);
1693+
ondisk.builder.running.xip = MemoryContextAllocZero(builder->context, sz);
16951694
readBytes = read(fd, ondisk.builder.running.xip, sz);
16961695
if (readBytes != sz)
16971696
{
@@ -1705,7 +1704,7 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
17051704

17061705
/* restore committed xacts information */
17071706
sz = sizeof(TransactionId) * ondisk.builder.committed.xcnt;
1708-
ondisk.builder.committed.xip = MemoryContextAlloc(builder->context, sz);
1707+
ondisk.builder.committed.xip = MemoryContextAllocZero(builder->context, sz);
17091708
readBytes = read(fd, ondisk.builder.committed.xip, sz);
17101709
if (readBytes != sz)
17111710
{
@@ -1763,10 +1762,10 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
17631762
}
17641763
ondisk.builder.committed.xip = NULL;
17651764

1766-
builder->running.xcnt = ondisk.builder.committed.xcnt;
1765+
builder->running.xcnt = ondisk.builder.running.xcnt;
17671766
if (builder->running.xip)
17681767
pfree(builder->running.xip);
1769-
builder->running.xcnt_space = ondisk.builder.committed.xcnt_space;
1768+
builder->running.xcnt_space = ondisk.builder.running.xcnt_space;
17701769
builder->running.xip = ondisk.builder.running.xip;
17711770

17721771
/* our snapshot is not interesting anymore, build a new one */

0 commit comments

Comments
 (0)