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

Commit 393e345

Browse files
tvondraCommitfest Bot
authored and
Commitfest Bot
committed
reworks
1 parent 3934fbb commit 393e345

File tree

6 files changed

+51
-43
lines changed

6 files changed

+51
-43
lines changed

src/backend/access/transam/xlog.c

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -661,12 +661,15 @@ static bool updateMinRecoveryPoint = true;
661661
static uint32 LocalDataChecksumVersion = 0;
662662

663663
/*
664-
* Flag to remember if the procsignalbarrier being absorbed for enabling
665-
* checksums is the first one or not. The first procsignalbarrier can in rare
666-
* circumstances cause a transition from 'on' to 'on' when a new process is
664+
* Flag to remember if the procsignalbarrier being absorbed for checksums
665+
* is the first one. The first procsignalbarrier can in rare cases be for
666+
* the state we've initialized, i.e. a duplicate. This may happen for any
667+
* data_checksum_version value, but for PG_DATA_CHECKSUM_ON_VERSION this
668+
* would trigger an assert failure (this is the only transition with an
669+
* assert) when processing the barrier. This may happen if the process is
667670
* spawned between the update of XLogCtl->data_checksum_version and the
668-
* barrier being emitted. This can only happen on the very first barrier so
669-
* mark that with this flag.
671+
* barrier being emitted. This can only happen on the very first barrier
672+
* so mark that with this flag.
670673
*/
671674
static bool InitialDataChecksumTransition = true;
672675

@@ -4938,6 +4941,7 @@ SetDataChecksumsOff(void)
49384941
bool
49394942
AbsorbChecksumsOnInProgressBarrier(void)
49404943
{
4944+
/* XXX can't we check we're in OFF or INPROGRESSS_ON? */
49414945
SetLocalDataChecksumVersion(PG_DATA_CHECKSUM_INPROGRESS_ON_VERSION);
49424946
return true;
49434947
}
@@ -4950,29 +4954,27 @@ AbsorbChecksumsOnBarrier(void)
49504954
* barrier it will have seen the updated value, so for the first barrier
49514955
* we accept both "on" and "inprogress-on".
49524956
*/
4953-
if (InitialDataChecksumTransition)
4954-
{
4955-
Assert((LocalDataChecksumVersion == PG_DATA_CHECKSUM_INPROGRESS_ON_VERSION) ||
4956-
(LocalDataChecksumVersion == PG_DATA_CHECKSUM_VERSION));
4957-
InitialDataChecksumTransition = false;
4958-
}
4959-
else
4960-
Assert(LocalDataChecksumVersion == PG_DATA_CHECKSUM_INPROGRESS_ON_VERSION);
4957+
Assert((LocalDataChecksumVersion == PG_DATA_CHECKSUM_INPROGRESS_ON_VERSION) ||
4958+
(InitialDataChecksumTransition &&
4959+
(LocalDataChecksumVersion == PG_DATA_CHECKSUM_VERSION)));
49614960

49624961
SetLocalDataChecksumVersion(PG_DATA_CHECKSUM_VERSION);
4962+
InitialDataChecksumTransition = false;
49634963
return true;
49644964
}
49654965

49664966
bool
49674967
AbsorbChecksumsOffInProgressBarrier(void)
49684968
{
4969+
/* XXX can't we check we're in ON or INPROGRESSS_OFF? */
49694970
SetLocalDataChecksumVersion(PG_DATA_CHECKSUM_INPROGRESS_OFF_VERSION);
49704971
return true;
49714972
}
49724973

49734974
bool
49744975
AbsorbChecksumsOffBarrier(void)
49754976
{
4977+
/* XXX can't we check we're in INPROGRESSS_OFF? */
49764978
SetLocalDataChecksumVersion(0);
49774979
return true;
49784980
}
@@ -4986,7 +4988,7 @@ AbsorbChecksumsOffBarrier(void)
49864988
* purpose enough to handle future cases.
49874989
*/
49884990
void
4989-
InitLocalControldata(void)
4991+
InitLocalDataChecksumVersion(void)
49904992
{
49914993
SpinLockAcquire(&XLogCtl->info_lck);
49924994
SetLocalDataChecksumVersion(XLogCtl->data_checksum_version);
@@ -5024,21 +5026,6 @@ SetLocalDataChecksumVersion(uint32 data_checksum_version)
50245026
}
50255027
}
50265028

5027-
/*
5028-
* Initialize the various data checksum values - GUC, local, ....
5029-
*/
5030-
void
5031-
InitLocalDataChecksumVersion(void)
5032-
{
5033-
uint32 data_checksum_version;
5034-
5035-
SpinLockAcquire(&XLogCtl->info_lck);
5036-
data_checksum_version = XLogCtl->data_checksum_version;
5037-
SpinLockRelease(&XLogCtl->info_lck);
5038-
5039-
SetLocalDataChecksumVersion(data_checksum_version);
5040-
}
5041-
50425029
/*
50435030
* Get the local data_checksum_version (cached XLogCtl value).
50445031
*/

src/backend/postmaster/auxprocess.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <unistd.h>
1616
#include <signal.h>
1717

18+
#include "access/xlog.h"
1819
#include "miscadmin.h"
1920
#include "pgstat.h"
2021
#include "postmaster/auxprocess.h"
@@ -68,6 +69,24 @@ AuxiliaryProcessMainCommon(void)
6869

6970
ProcSignalInit(false, 0);
7071

72+
/*
73+
* Initialize a local cache of the data_checksum_version, to be updated
74+
* by the procsignal-based barriers.
75+
*
76+
* This intentionally happens after initializing the procsignal, otherwise
77+
* we might miss a state change. This means we can get a barrier for the
78+
* state we've just initialized - but it can happen only once.
79+
*
80+
* The postmaster (which is what gets forked into the new child process)
81+
* does not handle barriers, therefore it may not have the current value
82+
* of LocalDataChecksumVersion value (it'll have the value read from the
83+
* control file, which may be arbitrarily old).
84+
*
85+
* NB: Even if the postmaster handled barriers, the value might still be
86+
* stale, as it might have changed after this process forked.
87+
*/
88+
InitLocalDataChecksumVersion();
89+
7190
/*
7291
* Auxiliary processes don't run transactions, but they may need a
7392
* resource owner anyway to manage buffer pins acquired outside

src/backend/postmaster/launch_backend.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,16 +285,6 @@ postmaster_child_launch(BackendType child_type, int child_slot,
285285
memcpy(MyClientSocket, client_sock, sizeof(ClientSocket));
286286
}
287287

288-
/*
289-
* update the LocalProcessControlFile to match XLogCtl->data_checksum_version
290-
*
291-
* XXX It seems the postmaster (which is what gets forked into the new
292-
* child process) does not absorb the checksum barriers, therefore it
293-
* does not update the value (except after a restart). Not sure if there
294-
* is some sort of race condition.
295-
*/
296-
InitLocalDataChecksumVersion();
297-
298288
/*
299289
* Run the appropriate Main function
300290
*/

src/backend/utils/init/postinit.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,22 @@ InitPostgres(const char *in_dbname, Oid dboid,
749749
ProcSignalInit(MyCancelKeyValid, MyCancelKey);
750750

751751
/*
752-
* Set up backend local cache of Controldata values.
752+
* Initialize a local cache of the data_checksum_version, to be updated
753+
* by the procsignal-based barriers.
754+
*
755+
* This intentionally happens after initializing the procsignal, otherwise
756+
* we might miss a state change. This means we can get a barrier for the
757+
* state we've just initialized - but it can happen only once.
758+
*
759+
* The postmaster (which is what gets forked into the new child process)
760+
* does not handle barriers, therefore it may not have the current value
761+
* of LocalDataChecksumVersion value (it'll have the value read from the
762+
* control file, which may be arbitrarily old).
763+
*
764+
* NB: Even if the postmaster handled barriers, the value might still be
765+
* stale, as it might have changed after this process forked.
753766
*/
754-
InitLocalControldata();
767+
InitLocalDataChecksumVersion();
755768

756769
/*
757770
* Also set up timeout handlers needed for backend operation. We need

src/include/access/xlog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ extern bool AbsorbChecksumsOffInProgressBarrier(void);
243243
extern bool AbsorbChecksumsOnBarrier(void);
244244
extern bool AbsorbChecksumsOffBarrier(void);
245245
extern const char *show_data_checksums(void);
246-
extern void InitLocalControldata(void);
246+
extern void InitLocalDataChecksumVersion(void);
247247
extern bool GetDefaultCharSignedness(void);
248248
extern XLogRecPtr GetFakeLSNForUnloggedRel(void);
249249
extern Size XLOGShmemSize(void);

src/include/miscadmin.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,6 @@ extern void RestoreClientConnectionInfo(char *conninfo);
542542

543543
extern uint32 GetLocalDataChecksumVersion(void);
544544
extern uint32 GetCurrentDataChecksumVersion(void);
545-
extern void InitLocalDataChecksumVersion(void);
546545

547546
/* in executor/nodeHash.c */
548547
extern size_t get_hash_memory_limit(void);

0 commit comments

Comments
 (0)