1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-01 00:25:06 +02:00

Migrate page checksum filter to C.

This filter exactly mimics the behavior of the Perl filter so is a drop-in replacement.

The filter is not integrated yet since it requires the Perl-to-C storage layer interface coming in a future commit.
This commit is contained in:
David Steele
2019-06-17 07:52:03 -04:00
parent 892f35a728
commit ceafd8e19d
10 changed files with 457 additions and 13 deletions

View File

@ -14,13 +14,6 @@ PostgreSQL Interface
#include "postgres/version.h"
#include "storage/helper.h"
/***********************************************************************************************************************************
Define default page size
Page size can only be changed at compile time and is not known to be well-tested, so only the default page size is supported.
***********************************************************************************************************************************/
#define PG_PAGE_SIZE_DEFAULT ((unsigned int)(8 * 1024))
/***********************************************************************************************************************************
Define default wal segment size

View File

@ -17,6 +17,21 @@ Defines for various Postgres paths and files
#define PG_PATH_ARCHIVE_STATUS "archive_status"
#define PG_PATH_GLOBAL "global"
/***********************************************************************************************************************************
Define default page size
Page size can only be changed at compile time and is not known to be well-tested, so only the default page size is supported.
***********************************************************************************************************************************/
#define PG_PAGE_SIZE_DEFAULT ((unsigned int)(8 * 1024))
/***********************************************************************************************************************************
Define default segment size and pages per segment
Segment size can only be changed at compile time and is not known to be well-tested, so only the default segment size is supported.
***********************************************************************************************************************************/
#define PG_SEGMENT_SIZE_DEFAULT ((unsigned int)(1 * 1024 * 1024 * 1024))
#define PG_SEGMENT_PAGE_DEFAULT (PG_SEGMENT_SIZE_DEFAULT / PG_PAGE_SIZE_DEFAULT)
/***********************************************************************************************************************************
PostgreSQL Control File Info
***********************************************************************************************************************************/

View File

@ -69,6 +69,7 @@ minimize register spilling. For less sophisticated compilers it might be benefic
#include "common/debug.h"
#include "common/error.h"
#include "common/log.h"
#include "postgres/interface.h"
#include "postgres/pageChecksum.h"
/***********************************************************************************************************************************
@ -203,6 +204,20 @@ pageChecksum(const unsigned char *page, unsigned int blockNo, unsigned int pageS
FUNCTION_TEST_RETURN((uint16_t)(checksum % 65535 + 1));
}
/***********************************************************************************************************************************
Return the lsn for a page
***********************************************************************************************************************************/
uint64_t
pageLsn(const unsigned char *page)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM_P(UCHARDATA, page);
FUNCTION_TEST_END();
// Reduce to a uint16 with an offset of one. That avoids checksums of zero, which seems like a good idea.
FUNCTION_TEST_RETURN((uint64_t)((PageHeader)page)->pd_lsn.walid << 32 | ((PageHeader)page)->pd_lsn.xrecoff);
}
/***********************************************************************************************************************************
pageChecksumTest - test if checksum is valid for a single page
***********************************************************************************************************************************/
@ -225,8 +240,8 @@ pageChecksumTest(
((PageHeader)page)->pd_upper == 0 ||
// LSN is after the backup started so checksum is not tested because pages may be torn
(((PageHeader)page)->pd_lsn.walid >= ignoreWalId && ((PageHeader)page)->pd_lsn.xrecoff >= ignoreWalOffset) ||
// Checksum is valid
((PageHeader)page)->pd_checksum == pageChecksum(page, blockNo, pageSize));
// Checksum is valid if a full page
(pageSize == PG_PAGE_SIZE_DEFAULT && ((PageHeader)page)->pd_checksum == pageChecksum(page, blockNo, pageSize)));
}
/***********************************************************************************************************************************

View File

@ -10,6 +10,7 @@ Checksum Implementation for Data Pages
Functions
***********************************************************************************************************************************/
uint16_t pageChecksum(const unsigned char *page, unsigned int blockNo, unsigned int pageSize);
uint64_t pageLsn(const unsigned char *page);
bool pageChecksumTest(
const unsigned char *page, unsigned int blockNo, unsigned int pageSize, uint32_t ignoreWalId, uint32_t ignoreWalOffset);
bool pageChecksumBufferTest(