You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-03 00:26:59 +02:00
Move logic from postgres/pageChecksum to command/backup/pageChecksum().
The postgres/pageChecksum module was designed as an interface to the C structs for the Perl code. The new C code can do this directly so no need for an interface. Move the remaining test for pgPageChecksum() into the postgres/interface test module.
This commit is contained in:
@ -20,6 +20,9 @@ which could have a large impact on dependencies. Hopefully that won't happen of
|
||||
Note when adding new types it is safer to add them to version.auto.c unless they are needed for code that must be compatible across
|
||||
all versions of PostgreSQL supported by pgBackRest.
|
||||
***********************************************************************************************************************************/
|
||||
#ifndef POSTGRES_INTERFACE_STATICAUTO_H
|
||||
#define POSTGRES_INTERFACE_STATICAUTO_H
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "postgres/interface.h"
|
||||
|
||||
@ -45,6 +48,10 @@ typedef uint16_t uint16;
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef uint32_t uint32;
|
||||
|
||||
// uint64 type
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef uint64_t uint64;
|
||||
|
||||
// TransactionId type
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
typedef uint32 TransactionId;
|
||||
@ -130,6 +137,11 @@ typedef struct
|
||||
uint32 xrecoff; /* low bits */
|
||||
} PageXLogRecPtr;
|
||||
|
||||
// PageXLogRecPtrGet macro
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
#define PageXLogRecPtrGet(val) \
|
||||
((uint64) (val).xlogid << 32 | (val).xrecoff)
|
||||
|
||||
// PageHeaderData type
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
@ -204,3 +216,5 @@ typedef PageHeaderData *PageHeader;
|
||||
* returns true if page has not been initialized (by PageInit)
|
||||
*/
|
||||
#define PageIsNew(page) (((PageHeader) (page))->pd_upper == 0)
|
||||
|
||||
#endif
|
||||
|
@ -40,16 +40,6 @@ typedef int64_t int64;
|
||||
|
||||
#endif
|
||||
|
||||
// uint64 type
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
#if PG_VERSION > PG_VERSION_MAX
|
||||
|
||||
#elif PG_VERSION >= PG_VERSION_83
|
||||
|
||||
typedef uint64_t uint64;
|
||||
|
||||
#endif
|
||||
|
||||
// MultiXactId type
|
||||
// ---------------------------------------------------------------------------------------------------------------------------------
|
||||
#if PG_VERSION > PG_VERSION_MAX
|
||||
|
@ -1,50 +0,0 @@
|
||||
/***********************************************************************************************************************************
|
||||
***********************************************************************************************************************************/
|
||||
#include "build.auto.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "common/debug.h"
|
||||
#include "common/error.h"
|
||||
#include "common/log.h"
|
||||
#include "postgres/interface.h"
|
||||
#include "postgres/interface/static.auto.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Return the lsn for a page
|
||||
***********************************************************************************************************************************/
|
||||
uint64_t
|
||||
pgPageLsn(const unsigned char *page)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM_P(UCHARDATA, page);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
FUNCTION_TEST_RETURN((uint64_t)((PageHeader)page)->pd_lsn.xlogid << 32 | ((PageHeader)page)->pd_lsn.xrecoff);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
pageChecksumTest - test if checksum is valid for a single page
|
||||
***********************************************************************************************************************************/
|
||||
bool
|
||||
pgPageChecksumTest(
|
||||
unsigned char *page, unsigned int blockNo, unsigned int pageSize, uint32_t ignoreWalId, uint32_t ignoreWalOffset)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM_P(UCHARDATA, page);
|
||||
FUNCTION_TEST_PARAM(UINT, blockNo);
|
||||
FUNCTION_TEST_PARAM(UINT, pageSize);
|
||||
FUNCTION_TEST_PARAM(UINT32, ignoreWalId);
|
||||
FUNCTION_TEST_PARAM(UINT32, ignoreWalOffset);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(page != NULL);
|
||||
|
||||
FUNCTION_TEST_RETURN(
|
||||
// This is a new page so don't test checksum
|
||||
((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.xlogid >= ignoreWalId && ((PageHeader)page)->pd_lsn.xrecoff >= ignoreWalOffset) ||
|
||||
// Checksum is valid if a full page
|
||||
(pageSize == PG_PAGE_SIZE_DEFAULT && ((PageHeader)page)->pd_checksum == pgPageChecksum(page, blockNo)));
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
/***********************************************************************************************************************************
|
||||
Checksum Implementation for Data Pages
|
||||
***********************************************************************************************************************************/
|
||||
#ifndef POSTGRES_PAGECHECKSUM_H
|
||||
#define POSTGRES_PAGECHECKSUM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
uint64_t pgPageLsn(const unsigned char *page);
|
||||
bool pgPageChecksumTest(
|
||||
unsigned char *page, unsigned int blockNo, unsigned int pageSize, uint32_t ignoreWalId, uint32_t ignoreWalOffset);
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user