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

Commita975ff4

Browse files
committed
Remove backwards compat ugliness in snapbuild.c.
In955a684 we fixed a bug in initial snapshot creation. In thecourse of which several members of struct SnapBuild were obsoleted. AsSnapBuild is serialized to disk we couldn't change the memory layout.Unfortunately I subsequently forgot about removing the backward compatgunk, but luckily Heikki just reminded me.This commit bumps SNAPBUILD_VERSION, therefore breaking existingslots (which is fine in a major release).Author: Andres FreundReminded-By: Heikki Linnakangas <hlinnaka@iki.fi>Discussion:https://postgr.es/m/c94be044-818f-15e3-1ad3-7a7ae2dfed0a@iki.fi
1 parent0e52903 commita975ff4

File tree

1 file changed

+18
-85
lines changed

1 file changed

+18
-85
lines changed

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

Lines changed: 18 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -189,24 +189,11 @@ struct SnapBuild
189189
ReorderBuffer*reorder;
190190

191191
/*
192-
*Outdated: This struct isn't used for its original purpose anymore, but
193-
*can't be removed / changed in a minor version, because it's stored
194-
*on-disk.
192+
*TransactionId at which the next phase of initial snapshot building will
193+
*happen. InvalidTransactionId if not known (i.e. SNAPBUILD_START), or
194+
*when no next phase necessary (SNAPBUILD_CONSISTENT).
195195
*/
196-
struct
197-
{
198-
/*
199-
* NB: This field is misused, until a major version can break on-disk
200-
* compatibility. See SnapBuildNextPhaseAt() /
201-
* SnapBuildStartNextPhaseAt().
202-
*/
203-
TransactionIdwas_xmin;
204-
TransactionIdwas_xmax;
205-
206-
size_twas_xcnt;/* number of used xip entries */
207-
size_twas_xcnt_space;/* allocated size of xip */
208-
TransactionId*was_xip;/* running xacts array, xidComparator-sorted */
209-
}was_running;
196+
TransactionIdnext_phase_at;
210197

211198
/*
212199
* Array of transactions which could have catalog changes that committed
@@ -272,34 +259,6 @@ static void SnapBuildWaitSnapshot(xl_running_xacts *running, TransactionId cutof
272259
staticvoidSnapBuildSerialize(SnapBuild*builder,XLogRecPtrlsn);
273260
staticboolSnapBuildRestore(SnapBuild*builder,XLogRecPtrlsn);
274261

275-
/*
276-
* Return TransactionId after which the next phase of initial snapshot
277-
* building will happen.
278-
*/
279-
staticinlineTransactionId
280-
SnapBuildNextPhaseAt(SnapBuild*builder)
281-
{
282-
/*
283-
* For backward compatibility reasons this has to be stored in the wrongly
284-
* named field. Will be fixed in next major version.
285-
*/
286-
returnbuilder->was_running.was_xmax;
287-
}
288-
289-
/*
290-
* Set TransactionId after which the next phase of initial snapshot building
291-
* will happen.
292-
*/
293-
staticinlinevoid
294-
SnapBuildStartNextPhaseAt(SnapBuild*builder,TransactionIdat)
295-
{
296-
/*
297-
* For backward compatibility reasons this has to be stored in the wrongly
298-
* named field. Will be fixed in next major version.
299-
*/
300-
builder->was_running.was_xmax=at;
301-
}
302-
303262
/*
304263
* Allocate a new snapshot builder.
305264
*
@@ -728,7 +687,7 @@ SnapBuildProcessChange(SnapBuild *builder, TransactionId xid, XLogRecPtr lsn)
728687
* we got into the SNAPBUILD_FULL_SNAPSHOT state.
729688
*/
730689
if (builder->state<SNAPBUILD_CONSISTENT&&
731-
TransactionIdPrecedes(xid,SnapBuildNextPhaseAt(builder)))
690+
TransactionIdPrecedes(xid,builder->next_phase_at))
732691
return false;
733692

734693
/*
@@ -945,7 +904,7 @@ SnapBuildCommitTxn(SnapBuild *builder, XLogRecPtr lsn, TransactionId xid,
945904
*/
946905
if (builder->state==SNAPBUILD_START||
947906
(builder->state==SNAPBUILD_BUILDING_SNAPSHOT&&
948-
TransactionIdPrecedes(xid,SnapBuildNextPhaseAt(builder))))
907+
TransactionIdPrecedes(xid,builder->next_phase_at)))
949908
{
950909
/* ensure that only commits after this are getting replayed */
951910
if (builder->start_decoding_at <=lsn)
@@ -1267,7 +1226,7 @@ SnapBuildFindSnapshot(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *runn
12671226
Assert(TransactionIdIsNormal(builder->xmax));
12681227

12691228
builder->state=SNAPBUILD_CONSISTENT;
1270-
SnapBuildStartNextPhaseAt(builder,InvalidTransactionId);
1229+
builder->next_phase_at=InvalidTransactionId;
12711230

12721231
ereport(LOG,
12731232
(errmsg("logical decoding found consistent point at %X/%X",
@@ -1299,7 +1258,7 @@ SnapBuildFindSnapshot(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *runn
12991258
elseif (builder->state==SNAPBUILD_START)
13001259
{
13011260
builder->state=SNAPBUILD_BUILDING_SNAPSHOT;
1302-
SnapBuildStartNextPhaseAt(builder,running->nextXid);
1261+
builder->next_phase_at=running->nextXid;
13031262

13041263
/*
13051264
* Start with an xmin/xmax that's correct for future, when all the
@@ -1331,11 +1290,11 @@ SnapBuildFindSnapshot(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *runn
13311290
* be decoded. Switch to FULL_SNAPSHOT.
13321291
*/
13331292
elseif (builder->state==SNAPBUILD_BUILDING_SNAPSHOT&&
1334-
TransactionIdPrecedesOrEquals(SnapBuildNextPhaseAt(builder),
1293+
TransactionIdPrecedesOrEquals(builder->next_phase_at,
13351294
running->oldestRunningXid))
13361295
{
13371296
builder->state=SNAPBUILD_FULL_SNAPSHOT;
1338-
SnapBuildStartNextPhaseAt(builder,running->nextXid);
1297+
builder->next_phase_at=running->nextXid;
13391298

13401299
ereport(LOG,
13411300
(errmsg("logical decoding found initial consistent point at %X/%X",
@@ -1356,11 +1315,11 @@ SnapBuildFindSnapshot(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *runn
13561315
* collected. Switch to CONSISTENT.
13571316
*/
13581317
elseif (builder->state==SNAPBUILD_FULL_SNAPSHOT&&
1359-
TransactionIdPrecedesOrEquals(SnapBuildNextPhaseAt(builder),
1318+
TransactionIdPrecedesOrEquals(builder->next_phase_at,
13601319
running->oldestRunningXid))
13611320
{
13621321
builder->state=SNAPBUILD_CONSISTENT;
1363-
SnapBuildStartNextPhaseAt(builder,InvalidTransactionId);
1322+
builder->next_phase_at=InvalidTransactionId;
13641323

13651324
ereport(LOG,
13661325
(errmsg("logical decoding found consistent point at %X/%X",
@@ -1463,7 +1422,7 @@ typedef struct SnapBuildOnDisk
14631422
offsetof(SnapBuildOnDisk, version)
14641423

14651424
#defineSNAPBUILD_MAGIC 0x51A1E001
1466-
#defineSNAPBUILD_VERSION2
1425+
#defineSNAPBUILD_VERSION3
14671426

14681427
/*
14691428
* Store/Load a snapshot from disk, depending on the snapshot builder's state.
@@ -1508,6 +1467,9 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
15081467
if (builder->state<SNAPBUILD_CONSISTENT)
15091468
return;
15101469

1470+
/* consistent snapshots have no next phase */
1471+
Assert(builder->next_phase_at==InvalidTransactionId);
1472+
15111473
/*
15121474
* We identify snapshots by the LSN they are valid for. We don't need to
15131475
* include timelines in the name as each LSN maps to exactly one timeline
@@ -1596,9 +1558,6 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
15961558
&ondisk->builder,
15971559
sizeof(SnapBuild));
15981560

1599-
/* there shouldn't be any running xacts */
1600-
Assert(builder->was_running.was_xcnt==0);
1601-
16021561
/* copy committed xacts */
16031562
sz=sizeof(TransactionId)*builder->committed.xcnt;
16041563
memcpy(ondisk_c,builder->committed.xip,sz);
@@ -1801,34 +1760,6 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
18011760
}
18021761
COMP_CRC32C(checksum,&ondisk.builder,sizeof(SnapBuild));
18031762

1804-
/* restore running xacts (dead, but kept for backward compat) */
1805-
sz=sizeof(TransactionId)*ondisk.builder.was_running.was_xcnt_space;
1806-
ondisk.builder.was_running.was_xip=
1807-
MemoryContextAllocZero(builder->context,sz);
1808-
pgstat_report_wait_start(WAIT_EVENT_SNAPBUILD_READ);
1809-
readBytes=read(fd,ondisk.builder.was_running.was_xip,sz);
1810-
pgstat_report_wait_end();
1811-
if (readBytes!=sz)
1812-
{
1813-
intsave_errno=errno;
1814-
1815-
CloseTransientFile(fd);
1816-
1817-
if (readBytes<0)
1818-
{
1819-
errno=save_errno;
1820-
ereport(ERROR,
1821-
(errcode_for_file_access(),
1822-
errmsg("could not read file \"%s\": %m",path)));
1823-
}
1824-
else
1825-
ereport(ERROR,
1826-
(errcode(ERRCODE_DATA_CORRUPTED),
1827-
errmsg("could not read file \"%s\": read %d of %zu",
1828-
path,readBytes,sz)));
1829-
}
1830-
COMP_CRC32C(checksum,ondisk.builder.was_running.was_xip,sz);
1831-
18321763
/* restore committed xacts information */
18331764
sz=sizeof(TransactionId)*ondisk.builder.committed.xcnt;
18341765
ondisk.builder.committed.xip=MemoryContextAllocZero(builder->context,sz);
@@ -1890,6 +1821,8 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
18901821
if (TransactionIdPrecedes(ondisk.builder.xmin,builder->initial_xmin_horizon))
18911822
gotosnapshot_not_interesting;
18921823

1824+
/* consistent snapshots have no next phase */
1825+
Assert(ondisk.builder.next_phase_at==InvalidTransactionId);
18931826

18941827
/* ok, we think the snapshot is sensible, copy over everything important */
18951828
builder->xmin=ondisk.builder.xmin;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp