Re: prevent immature WAL streaming
Alvaro Herrera <alvherre@alvh.no-ip.org>
On 2021-Oct-13, Robert Haas wrote: > On Wed, Oct 13, 2021 at 2:01 AM Amul Sul <sulamul@gmail.com> wrote: > > Instead of abortedRecPtr point, isn't enough to write > > overwrite-contrecord at XLogCtl->lastReplayedEndRecPtr? I think both > > are pointing to the same location then can't we use > > lastReplayedEndRecPtr instead of abortedRecPtr to write > > overwrite-contrecord and remove need of extra global variable, like > > attached? > > I think you mean missingContrecPtr, not abortedRecPtr. If I understand > correctly, abortedRecPtr is going to be the location in some WAL > segment which we replayed where a long record began, but > missingContrecPtr seems like it would have to point to the beginning > of the first segment we were unable to find to continue replay; and > thus it ought to be the same as lastReplayedEndRecPtr. So abortedRecPtr and missingContrecPtr both point to the same long record: the former is the start of the record, and the latter is some intermediate position where we failed to find the contrecord. lastReplayedEndRecPtr is the end+1 of the record *prior* to the long record. > But the committed code doesn't seem to check that these are the same > or verify the relationship between them in any way, so I'm worried > there is some other case here. Yeah, the only reason they are the same is that xlogreader sets both to Invalid when reading a record, and then sets both when a read fails. > The comments in XLogReadRecord also suggest this: > > * We get here when a record that spans multiple pages needs to be > * assembled, but something went wrong -- perhaps a contrecord piece > * was lost. If caller is WAL replay, it will know where the aborted > > Saying that "perhaps" a contrecord piece was lost seems to imply that > other explanations are possible as well, but I'm not sure what. Other explanations are possible. Imagine cosmic rays alter one byte in the last contrecord. WAL replay will stop there, and the contrecord will have been found all right, but CRC check would have failed to pass, so we would set xlogreader->missingContrecPtr to the final contrecord of that record (I didn't actually verify this particular scenario.) In fact, anything that causes xlogreader.c:XLogReadRecord to return NULL after setting "assembled=true" would set both abortedRecPtr and missingContrecPtr -- except DecodeXLogRecord failure, which perhaps should be handled in the same way. -- Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/ "Siempre hay que alimentar a los dioses, aunque la tierra esté seca" (Orual)
Commits
-
Fix determination of broken LSN in OVERWRITTEN_CONTRECORD
- ef41c3fd6c86 13.6 landed
- d24dac954906 14.2 landed
- 9c6ab1ef3382 12.10 landed
- 72cf39d51ade 10.20 landed
- 44bd3ed332d6 15.0 landed
- 2c3fddcbbd8a 11.15 landed
-
Fix instability in 026_overwrite_contrecord.pl test.
- b66767b56b1c 15.0 landed
- 9959a078f2d7 12.10 landed
- 5a3240cf6b2e 13.6 landed
- 4dc2cb74d00e 11.15 landed
- 3aa858c8932e 14.2 landed
- 18ce21768a80 10.20 landed
-
Fix typo
- f914b8badc21 12.9 landed
- c3bda112ebe2 10.19 landed
- 7c0a78f08998 13.5 landed
- 3aa572b8b296 11.14 landed
- 9b6194eb0aa5 9.6.24 landed
-
Change recently added test code for stability
- 79c7fe1af82d 14.1 landed
- 6287b8e195f3 11.14 landed
- 5ec87619bc5d 9.6.24 landed
- 4b7abbe48a11 12.9 landed
- 41cce2326135 10.19 landed
- 2cdf97fd1ec8 13.5 landed
- 010e5233733a 15.0 landed
-
Remove unstable, unnecessary test; fix typo
- d186d233dfde 15.0 landed
- 0ce67bce0071 14.1 landed
-
Repair two portability oversights of new test
- e3731bac52cf 14.1 landed
- d03bca4d70c2 15.0 landed
-
Fix WAL replay in presence of an incomplete record
- 64a8687a6891 14.1 landed
- ff9f111bce24 15.0 landed
- d9fe2cc7dd3e 10.19 landed
- cfedb279a6b8 11.14 landed
- 1df0a914d58f 12.9 landed
- 1d97d3d0867f 13.5 landed
- 148c6ee3be39 9.6.24 landed
-
Document XLOG_INCLUDE_XID a little better
- c1d1ae1db237 14.0 landed
- ade24dab97a2 15.0 landed
-
Revert "Avoid creating archive status ".ready" files too early"
- e456167a8af4 12.9 landed
- c801c3a1ff73 11.14 landed
- aa8bd0890bb2 14.0 landed
- 9aaf7dbff36f 10.19 landed
- 96b665083eb7 15.0 landed
- 518621c40b23 13.5 landed
- 121cdaff1068 9.6.24 landed
-
Avoid creating archive status ".ready" files too early
- 5065aeafb0b7 12.9 cited
-
Fix scenario where streaming standby gets stuck at a continuation record.
- 066871980183 11.0 cited
-
Teach xlogreader to follow timeline switches
- 1148e22a82ed 10.0 cited
-
Forbid using pg_xlogfile_name() and pg_xlogfile_name_offset() during
- 370f770c15a4 9.0.0 cited