@@ -189,24 +189,11 @@ struct SnapBuild
189
189
ReorderBuffer *reorder;
190
190
191
191
/*
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) .
195
195
*/
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
- TransactionId was_xmin;
204
- TransactionId was_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
+ TransactionId next_phase_at;
210
197
211
198
/*
212
199
* Array of transactions which could have catalog changes that committed
@@ -272,34 +259,6 @@ static void SnapBuildWaitSnapshot(xl_running_xacts *running, TransactionId cutof
272
259
static void SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn);
273
260
static bool SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn);
274
261
275
- /*
276
- * Return TransactionId after which the next phase of initial snapshot
277
- * building will happen.
278
- */
279
- static inline TransactionId
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
- return builder->was_running.was_xmax;
287
- }
288
-
289
- /*
290
- * Set TransactionId after which the next phase of initial snapshot building
291
- * will happen.
292
- */
293
- static inline void
294
- SnapBuildStartNextPhaseAt(SnapBuild *builder, TransactionId at)
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
-
303
262
/*
304
263
* Allocate a new snapshot builder.
305
264
*
@@ -728,7 +687,7 @@ SnapBuildProcessChange(SnapBuild *builder, TransactionId xid, XLogRecPtr lsn)
728
687
* we got into the SNAPBUILD_FULL_SNAPSHOT state.
729
688
*/
730
689
if (builder->state < SNAPBUILD_CONSISTENT &&
731
- TransactionIdPrecedes(xid,SnapBuildNextPhaseAt( builder) ))
690
+ TransactionIdPrecedes(xid, builder->next_phase_at ))
732
691
return false;
733
692
734
693
/*
@@ -945,7 +904,7 @@ SnapBuildCommitTxn(SnapBuild *builder, XLogRecPtr lsn, TransactionId xid,
945
904
*/
946
905
if (builder->state == SNAPBUILD_START ||
947
906
(builder->state == SNAPBUILD_BUILDING_SNAPSHOT &&
948
- TransactionIdPrecedes(xid,SnapBuildNextPhaseAt( builder) )))
907
+ TransactionIdPrecedes(xid, builder->next_phase_at )))
949
908
{
950
909
/* ensure that only commits after this are getting replayed */
951
910
if (builder->start_decoding_at <= lsn)
@@ -1267,7 +1226,7 @@ SnapBuildFindSnapshot(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *runn
1267
1226
Assert(TransactionIdIsNormal(builder->xmax));
1268
1227
1269
1228
builder->state = SNAPBUILD_CONSISTENT;
1270
- SnapBuildStartNextPhaseAt( builder, InvalidTransactionId) ;
1229
+ builder->next_phase_at = InvalidTransactionId;
1271
1230
1272
1231
ereport(LOG,
1273
1232
(errmsg("logical decoding found consistent point at %X/%X",
@@ -1299,7 +1258,7 @@ SnapBuildFindSnapshot(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *runn
1299
1258
else if (builder->state == SNAPBUILD_START)
1300
1259
{
1301
1260
builder->state = SNAPBUILD_BUILDING_SNAPSHOT;
1302
- SnapBuildStartNextPhaseAt( builder, running->nextXid) ;
1261
+ builder->next_phase_at = running->nextXid;
1303
1262
1304
1263
/*
1305
1264
* 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
1331
1290
* be decoded. Switch to FULL_SNAPSHOT.
1332
1291
*/
1333
1292
else if (builder->state == SNAPBUILD_BUILDING_SNAPSHOT &&
1334
- TransactionIdPrecedesOrEquals(SnapBuildNextPhaseAt( builder) ,
1293
+ TransactionIdPrecedesOrEquals(builder->next_phase_at ,
1335
1294
running->oldestRunningXid))
1336
1295
{
1337
1296
builder->state = SNAPBUILD_FULL_SNAPSHOT;
1338
- SnapBuildStartNextPhaseAt( builder, running->nextXid) ;
1297
+ builder->next_phase_at = running->nextXid;
1339
1298
1340
1299
ereport(LOG,
1341
1300
(errmsg("logical decoding found initial consistent point at %X/%X",
@@ -1356,11 +1315,11 @@ SnapBuildFindSnapshot(SnapBuild *builder, XLogRecPtr lsn, xl_running_xacts *runn
1356
1315
* collected. Switch to CONSISTENT.
1357
1316
*/
1358
1317
else if (builder->state == SNAPBUILD_FULL_SNAPSHOT &&
1359
- TransactionIdPrecedesOrEquals(SnapBuildNextPhaseAt( builder) ,
1318
+ TransactionIdPrecedesOrEquals(builder->next_phase_at ,
1360
1319
running->oldestRunningXid))
1361
1320
{
1362
1321
builder->state = SNAPBUILD_CONSISTENT;
1363
- SnapBuildStartNextPhaseAt( builder, InvalidTransactionId) ;
1322
+ builder->next_phase_at = InvalidTransactionId;
1364
1323
1365
1324
ereport(LOG,
1366
1325
(errmsg("logical decoding found consistent point at %X/%X",
@@ -1463,7 +1422,7 @@ typedef struct SnapBuildOnDisk
1463
1422
offsetof(SnapBuildOnDisk, version)
1464
1423
1465
1424
#define SNAPBUILD_MAGIC 0x51A1E001
1466
- #define SNAPBUILD_VERSION2
1425
+ #define SNAPBUILD_VERSION3
1467
1426
1468
1427
/*
1469
1428
* Store/Load a snapshot from disk, depending on the snapshot builder's state.
@@ -1508,6 +1467,9 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
1508
1467
if (builder->state < SNAPBUILD_CONSISTENT)
1509
1468
return;
1510
1469
1470
+ /* consistent snapshots have no next phase */
1471
+ Assert(builder->next_phase_at == InvalidTransactionId);
1472
+
1511
1473
/*
1512
1474
* We identify snapshots by the LSN they are valid for. We don't need to
1513
1475
* include timelines in the name as each LSN maps to exactly one timeline
@@ -1596,9 +1558,6 @@ SnapBuildSerialize(SnapBuild *builder, XLogRecPtr lsn)
1596
1558
&ondisk->builder,
1597
1559
sizeof(SnapBuild));
1598
1560
1599
- /* there shouldn't be any running xacts */
1600
- Assert(builder->was_running.was_xcnt == 0);
1601
-
1602
1561
/* copy committed xacts */
1603
1562
sz = sizeof(TransactionId) * builder->committed.xcnt;
1604
1563
memcpy(ondisk_c, builder->committed.xip, sz);
@@ -1801,34 +1760,6 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
1801
1760
}
1802
1761
COMP_CRC32C(checksum, &ondisk.builder, sizeof(SnapBuild));
1803
1762
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
-
1832
1763
/* restore committed xacts information */
1833
1764
sz = sizeof(TransactionId) * ondisk.builder.committed.xcnt;
1834
1765
ondisk.builder.committed.xip = MemoryContextAllocZero(builder->context, sz);
@@ -1890,6 +1821,8 @@ SnapBuildRestore(SnapBuild *builder, XLogRecPtr lsn)
1890
1821
if (TransactionIdPrecedes(ondisk.builder.xmin, builder->initial_xmin_horizon))
1891
1822
goto snapshot_not_interesting;
1892
1823
1824
+ /* consistent snapshots have no next phase */
1825
+ Assert(ondisk.builder.next_phase_at == InvalidTransactionId);
1893
1826
1894
1827
/* ok, we think the snapshot is sensible, copy over everything important */
1895
1828
builder->xmin = ondisk.builder.xmin;