You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-07 00:35:37 +02:00
Refactor PostgreSQL interface to remove most code duplication.
Having a copy per version worked well until it was time to add new features or modify existing functions. Then it was necessary to modify every version and try to keep them all in sync. Consolidate all the PostgreSQL types into a single file using #if for type versions. Many types do not change or change infrequently so this cuts down on duplication. In addition, it is far easier to see what has changed when a new version is added. Use macros to write the interface functions. There is still duplication here since some changes require a new copy of the macro, but it is far less than before.
This commit is contained in:
@ -1,125 +1,10 @@
|
||||
/***********************************************************************************************************************************
|
||||
PostgreSQL 9.5 Interface
|
||||
|
||||
See postgres/interface.c for documentation.
|
||||
See postgres/interface/version.intern.h for documentation.
|
||||
***********************************************************************************************************************************/
|
||||
#include "common/debug.h"
|
||||
#include "common/log.h"
|
||||
#include "postgres/interface/v095.h"
|
||||
#define PG_VERSION PG_VERSION_95
|
||||
|
||||
#include "postgres/interface/v095.auto.c"
|
||||
#include "postgres/interface/version.intern.h"
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
bool
|
||||
pgInterfaceControlIs095(const Buffer *controlFile)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(BUFFER, controlFile);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(controlFile != NULL);
|
||||
|
||||
ControlFileData *controlData = (ControlFileData *)bufPtr(controlFile);
|
||||
|
||||
FUNCTION_TEST_RETURN(
|
||||
controlData->pg_control_version == PG_CONTROL_VERSION && controlData->catalog_version_no == CATALOG_VERSION_NO);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
PgControl
|
||||
pgInterfaceControl095(const Buffer *controlFile)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||
FUNCTION_LOG_PARAM(BUFFER, controlFile);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(controlFile != NULL);
|
||||
ASSERT(pgInterfaceControlIs095(controlFile));
|
||||
|
||||
PgControl result = {0};
|
||||
ControlFileData *controlData = (ControlFileData *)bufPtr(controlFile);
|
||||
|
||||
result.systemId = controlData->system_identifier;
|
||||
result.controlVersion = controlData->pg_control_version;
|
||||
result.catalogVersion = controlData->catalog_version_no;
|
||||
|
||||
result.pageSize = controlData->blcksz;
|
||||
result.walSegmentSize = controlData->xlog_seg_size;
|
||||
|
||||
result.pageChecksum = controlData->data_checksum_version != 0;
|
||||
|
||||
FUNCTION_LOG_RETURN(PG_CONTROL, result);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
bool
|
||||
pgInterfaceWalIs095(const Buffer *walFile)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(BUFFER, controlFile);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ASSERT(walFile != NULL);
|
||||
|
||||
FUNCTION_TEST_RETURN(((XLogPageHeaderData *)bufPtr(walFile))->xlp_magic == XLOG_PAGE_MAGIC);
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
PgWal
|
||||
pgInterfaceWal095(const Buffer *walFile)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelTrace);
|
||||
FUNCTION_LOG_PARAM(BUFFER, walFile);
|
||||
FUNCTION_LOG_END();
|
||||
|
||||
ASSERT(walFile != NULL);
|
||||
ASSERT(pgInterfaceWalIs095(walFile));
|
||||
|
||||
PgWal result = {0};
|
||||
|
||||
result.systemId = ((XLogLongPageHeaderData *)bufPtr(walFile))->xlp_sysid;
|
||||
|
||||
FUNCTION_LOG_RETURN(PG_WAL, result);
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
pgInterfaceControlTest095(PgControl pgControl, Buffer *buffer)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(PG_CONTROL, pgControl);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
ControlFileData *controlData = (ControlFileData *)bufPtr(buffer);
|
||||
|
||||
controlData->system_identifier = pgControl.systemId;
|
||||
controlData->pg_control_version = pgControl.controlVersion == 0 ? PG_CONTROL_VERSION : pgControl.controlVersion;
|
||||
controlData->catalog_version_no = pgControl.catalogVersion == 0 ? CATALOG_VERSION_NO : pgControl.catalogVersion;
|
||||
|
||||
controlData->blcksz = pgControl.pageSize;
|
||||
controlData->xlog_seg_size = pgControl.walSegmentSize;
|
||||
|
||||
controlData->data_checksum_version = pgControl.pageChecksum;
|
||||
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
pgInterfaceWalTest095(PgWal pgWal, Buffer *buffer)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(PG_WAL, pgWal);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
XLogLongPageHeaderData *walData = (XLogLongPageHeaderData *)bufPtr(buffer);
|
||||
|
||||
walData->std.xlp_magic = XLOG_PAGE_MAGIC;
|
||||
walData->xlp_sysid = pgWal.systemId;
|
||||
|
||||
FUNCTION_TEST_RETURN_VOID();
|
||||
}
|
||||
|
||||
#endif
|
||||
PG_INTERFACE(095);
|
||||
|
Reference in New Issue
Block a user