1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Revert "Allow on-line enabling and disabling of data checksums"

This reverts the backend sides of commit 1fde38beaa.
I have, at least for now, left the pg_verify_checksums tool in place, as
this tool can be very valuable without the rest of the patch as well,
and since it's a read-only tool that only runs when the cluster is down
it should be a lot safer.
This commit is contained in:
Magnus Hagander
2018-04-09 19:02:42 +02:00
parent 03c11796a9
commit a228cc13ae
39 changed files with 34 additions and 1658 deletions

View File

@ -17,7 +17,6 @@
#include "access/xlog.h"
#include "access/xlog_internal.h"
#include "catalog/pg_control.h"
#include "storage/bufpage.h"
#include "utils/guc.h"
#include "utils/timestamp.h"
@ -138,18 +137,6 @@ xlog_desc(StringInfo buf, XLogReaderState *record)
xlrec.ThisTimeLineID, xlrec.PrevTimeLineID,
timestamptz_to_str(xlrec.end_time));
}
else if (info == XLOG_CHECKSUMS)
{
xl_checksum_state xlrec;
memcpy(&xlrec, rec, sizeof(xl_checksum_state));
if (xlrec.new_checksumtype == PG_DATA_CHECKSUM_VERSION)
appendStringInfo(buf, "on");
else if (xlrec.new_checksumtype == PG_DATA_CHECKSUM_INPROGRESS_VERSION)
appendStringInfo(buf, "inprogress");
else
appendStringInfo(buf, "off");
}
}
const char *
@ -195,9 +182,6 @@ xlog_identify(uint8 info)
case XLOG_FPI_FOR_HINT:
id = "FPI_FOR_HINT";
break;
case XLOG_CHECKSUMS:
id = "CHECKSUMS";
break;
}
return id;

View File

@ -856,7 +856,6 @@ static void SetLatestXTime(TimestampTz xtime);
static void SetCurrentChunkStartTime(TimestampTz xtime);
static void CheckRequiredParameterValues(void);
static void XLogReportParameters(void);
static void XlogChecksums(ChecksumType new_type);
static void checkTimeLineSwitch(XLogRecPtr lsn, TimeLineID newTLI,
TimeLineID prevTLI);
static void LocalSetXLogInsertAllowed(void);
@ -1034,7 +1033,7 @@ XLogInsertRecord(XLogRecData *rdata,
Assert(RedoRecPtr < Insert->RedoRecPtr);
RedoRecPtr = Insert->RedoRecPtr;
}
doPageWrites = (Insert->fullPageWrites || Insert->forcePageWrites || DataChecksumsInProgress());
doPageWrites = (Insert->fullPageWrites || Insert->forcePageWrites);
if (fpw_lsn != InvalidXLogRecPtr && fpw_lsn <= RedoRecPtr && doPageWrites)
{
@ -4674,6 +4673,10 @@ ReadControlFile(void)
(SizeOfXLogLongPHD - SizeOfXLogShortPHD);
CalculateCheckpointSegments();
/* Make the initdb settings visible as GUC variables, too */
SetConfigOption("data_checksums", DataChecksumsEnabled() ? "yes" : "no",
PGC_INTERNAL, PGC_S_OVERRIDE);
}
void
@ -4745,90 +4748,12 @@ GetMockAuthenticationNonce(void)
* Are checksums enabled for data pages?
*/
bool
DataChecksumsNeedWrite(void)
DataChecksumsEnabled(void)
{
Assert(ControlFile != NULL);
return (ControlFile->data_checksum_version > 0);
}
bool
DataChecksumsNeedVerify(void)
{
Assert(ControlFile != NULL);
/*
* Only verify checksums if they are fully enabled in the cluster. In
* inprogress state they are only updated, not verified.
*/
return (ControlFile->data_checksum_version == PG_DATA_CHECKSUM_VERSION);
}
bool
DataChecksumsInProgress(void)
{
Assert(ControlFile != NULL);
return (ControlFile->data_checksum_version == PG_DATA_CHECKSUM_INPROGRESS_VERSION);
}
void
SetDataChecksumsInProgress(void)
{
Assert(ControlFile != NULL);
if (ControlFile->data_checksum_version > 0)
return;
XlogChecksums(PG_DATA_CHECKSUM_INPROGRESS_VERSION);
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
ControlFile->data_checksum_version = PG_DATA_CHECKSUM_INPROGRESS_VERSION;
UpdateControlFile();
LWLockRelease(ControlFileLock);
}
void
SetDataChecksumsOn(void)
{
Assert(ControlFile != NULL);
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
if (ControlFile->data_checksum_version != PG_DATA_CHECKSUM_INPROGRESS_VERSION)
{
LWLockRelease(ControlFileLock);
elog(ERROR, "Checksums not in inprogress mode");
}
ControlFile->data_checksum_version = PG_DATA_CHECKSUM_VERSION;
UpdateControlFile();
LWLockRelease(ControlFileLock);
XlogChecksums(PG_DATA_CHECKSUM_VERSION);
}
void
SetDataChecksumsOff(void)
{
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
ControlFile->data_checksum_version = 0;
UpdateControlFile();
LWLockRelease(ControlFileLock);
XlogChecksums(0);
}
/* guc hook */
const char *
show_data_checksums(void)
{
if (ControlFile->data_checksum_version == PG_DATA_CHECKSUM_VERSION)
return "on";
else if (ControlFile->data_checksum_version == PG_DATA_CHECKSUM_INPROGRESS_VERSION)
return "inprogress";
else
return "off";
}
/*
* Returns a fake LSN for unlogged relations.
*
@ -7863,16 +7788,6 @@ StartupXLOG(void)
*/
CompleteCommitTsInitialization();
/*
* If we reach this point with checksums in inprogress state, we notify
* the user that they need to manually restart the process to enable
* checksums.
*/
if (ControlFile->data_checksum_version == PG_DATA_CHECKSUM_INPROGRESS_VERSION)
ereport(WARNING,
(errmsg("checksum state is \"inprogress\" with no worker"),
errhint("Either disable or enable checksums by calling the pg_disable_data_checksums() or pg_enable_data_checksums() functions.")));
/*
* All done with end-of-recovery actions.
*
@ -9626,22 +9541,6 @@ XLogReportParameters(void)
}
}
/*
* Log the new state of checksums
*/
static void
XlogChecksums(ChecksumType new_type)
{
xl_checksum_state xlrec;
xlrec.new_checksumtype = new_type;
XLogBeginInsert();
XLogRegisterData((char *) &xlrec, sizeof(xl_checksum_state));
XLogInsert(RM_XLOG_ID, XLOG_CHECKSUMS);
}
/*
* Update full_page_writes in shared memory, and write an
* XLOG_FPW_CHANGE record if necessary.
@ -10070,17 +9969,6 @@ xlog_redo(XLogReaderState *record)
/* Keep track of full_page_writes */
lastFullPageWrites = fpw;
}
else if (info == XLOG_CHECKSUMS)
{
xl_checksum_state state;
memcpy(&state, XLogRecGetData(record), sizeof(xl_checksum_state));
LWLockAcquire(ControlFileLock, LW_EXCLUSIVE);
ControlFile->data_checksum_version = state.new_checksumtype;
UpdateControlFile();
LWLockRelease(ControlFileLock);
}
}
#ifdef WAL_DEBUG

View File

@ -24,7 +24,6 @@
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "postmaster/checksumhelper.h"
#include "replication/walreceiver.h"
#include "storage/smgr.h"
#include "utils/builtins.h"
@ -699,61 +698,3 @@ pg_backup_start_time(PG_FUNCTION_ARGS)
PG_RETURN_DATUM(xtime);
}
/*
* Disables checksums for the cluster, unless already disabled.
*
* Has immediate effect - the checksums are set to off right away.
*/
Datum
disable_data_checksums(PG_FUNCTION_ARGS)
{
/*
* If we don't need to write new checksums, then clearly they are already
* disabled.
*/
if (!DataChecksumsNeedWrite())
ereport(ERROR,
(errmsg("data checksums already disabled")));
ShutdownChecksumHelperIfRunning();
SetDataChecksumsOff();
PG_RETURN_VOID();
}
/*
* Enables checksums for the cluster, unless already enabled.
*
* Supports vacuum-like cost-based throttling, to limit system load.
* Starts a background worker that updates checksums on existing data.
*/
Datum
enable_data_checksums(PG_FUNCTION_ARGS)
{
int cost_delay = PG_GETARG_INT32(0);
int cost_limit = PG_GETARG_INT32(1);
if (cost_delay < 0)
ereport(ERROR,
(errmsg("cost delay cannot be less than zero")));
if (cost_limit <= 0)
ereport(ERROR,
(errmsg("cost limit must be a positive value")));
/*
* Allow state change from "off" or from "inprogress", since this is how
* we restart the worker if necessary.
*/
if (DataChecksumsNeedVerify())
ereport(ERROR,
(errmsg("data checksums already enabled")));
SetDataChecksumsInProgress();
if (!StartChecksumHelperLauncher(cost_delay, cost_limit))
ereport(ERROR,
(errmsg("failed to start checksum helper process")));
PG_RETURN_VOID();
}