Skip to content

Commit

Permalink
Add GPDB 6 support
Browse files Browse the repository at this point in the history
Add fork version property to the src/build/postgres/postgres.yaml file format.
The default value of the property is PostgreSQL. Add the fork field to
PgInterface structure. Implement the search in the pgInterface array not only
by version, but also by the fork field, the value for comparison with which
will be taken from the --fork command line option or from fork property of
stanza or from the global section. For backward compatibility purposes, the
PostgreSQL interface will be searched without fork option. Add tablespaceId and
walSegmentSizeDefault functions to interface, because tablespace id format and
default WAL segment size are different for PostgreSQL and GPDB. Change
algorithm selection for pg_control checksum calculating, because Greenplum uses
crc32c as in Postgres 9.5+.
  • Loading branch information
andr-sokolov committed Feb 2, 2024
1 parent 1add356 commit 18fea34
Show file tree
Hide file tree
Showing 25 changed files with 513 additions and 76 deletions.
19 changes: 19 additions & 0 deletions src/build/config/config.yaml
Expand Up @@ -303,6 +303,25 @@ option:
command-role:
main: {}

fork:
section: global
type: string-id
allow-list:
- PostgreSQL
- GPDB
default: PostgreSQL
command:
annotate: {}
archive-get: {}
archive-push: {}
backup: {}
check: {}
expire: {}
restore: {}
stanza-create: {}
stanza-upgrade: {}
verify: {}

online:
type: boolean
default: true
Expand Down
15 changes: 15 additions & 0 deletions src/build/help/help.xml
Expand Up @@ -280,6 +280,21 @@
<example>y</example>
</config-key>

<config-key id="fork" name="Fork">
<summary>PostgreSQL fork name.</summary>

<text>
<p>The following forks are supported:</p>

<list>
<list-item><id>PostgreSQL</id> - vanilla</list-item>
<list-item><id>GPDB</id> - Greenplum</list-item>
</list>
</text>

<example>n</example>
</config-key>

<config-key id="io-timeout" name="I/O Timeout">
<summary>I/O timeout.</summary>

Expand Down
33 changes: 23 additions & 10 deletions src/build/postgres/parse.c
Expand Up @@ -7,6 +7,7 @@ Parse PostgreSQL Interface Yaml

#include "build/common/yaml.h"
#include "build/postgres/parse.h"
#include "config/config.auto.h"

/***********************************************************************************************************************************
Parse version list
Expand All @@ -15,6 +16,7 @@ typedef struct BldPgVersionRaw
{
const String *version; // See BldPgVersion for comments
bool release;
StringId fork;
} BldPgVersionRaw;

static List *
Expand All @@ -35,25 +37,35 @@ bldPgVersionList(Yaml *const yaml)

do
{
BldPgVersionRaw pgRaw = {.release = true};
BldPgVersionRaw pgRaw = {.release = true, .fork = CFGOPTVAL_FORK_POSTGRESQL};

if (ver.type == yamlEventTypeMapBegin)
{
pgRaw.version = yamlEventNextCheck(yaml, yamlEventTypeScalar).value;
yamlEventNextCheck(yaml, yamlEventTypeMapBegin);

YamlEvent verDef = yamlEventNextCheck(yaml, yamlEventTypeScalar);
YamlEvent verDefVal = yamlEventNextCheck(yaml, yamlEventTypeScalar);

// Get release setting
if (strEqZ(verDef.value, "release"))
do
{
pgRaw.release = yamlBoolParse(verDefVal);
YamlEvent verDefVal = yamlEventNextCheck(yaml, yamlEventTypeScalar);

// Get release setting
if (strEqZ(verDef.value, "release"))
{
pgRaw.release = yamlBoolParse(verDefVal);
}
else if (strEqZ(verDef.value, "fork"))
{
pgRaw.fork = strIdFromZN(strZ(verDefVal.value), strSize(verDefVal.value), true);
}
else
THROW_FMT(FormatError, "unknown postgres definition '%s'", strZ(verDef.value));

verDef = yamlEventNext(yaml);
}
else
THROW_FMT(FormatError, "unknown postgres definition '%s'", strZ(verDef.value));
while (verDef.type == yamlEventTypeScalar);

yamlEventNextCheck(yaml, yamlEventTypeMapEnd);
yamlEventCheck(verDef, yamlEventTypeMapEnd);
yamlEventNextCheck(yaml, yamlEventTypeMapEnd);
}
else
Expand All @@ -65,7 +77,8 @@ bldPgVersionList(Yaml *const yaml)
const BldPgVersion bldPgVersion =
{
.version = strDup(pgRaw.version),
.release = pgRaw.release
.release = pgRaw.release,
.fork = pgRaw.fork
};

lstAdd(result, &bldPgVersion);
Expand Down
1 change: 1 addition & 0 deletions src/build/postgres/parse.h
Expand Up @@ -13,6 +13,7 @@ typedef struct BldPgVersion
{
const String *version; // Version
bool release; // Is this a released version?
StringId fork; // Supported PostgreSQL fork or PostgreSQL itself
} BldPgVersion;

typedef struct BldPg
Expand Down
5 changes: 4 additions & 1 deletion src/build/postgres/postgres.yaml
Expand Up @@ -3,9 +3,12 @@
# Version interfaces are auto-generated to src/postgres/interface.auto.c.inc.
#
# - 'version' contains a list of all supported versions
# - For a specific version, 'release' marks it as not released (i.e. this should always be false when used)
# - For a specific version, 'release' marks it as not released (i.e. this should always be false when used),
# 'fork' contains name of supported fork based on the version
version:
- 9.4
- 9.4:
fork: GPDB
- 9.5
- 9.6
- 10
Expand Down
21 changes: 16 additions & 5 deletions src/build/postgres/render.c
Expand Up @@ -7,6 +7,7 @@ Render PostgreSQL Interface

#include "build/common/render.h"
#include "build/postgres/render.h"
#include "config/config.auto.h"

/***********************************************************************************************************************************
Render interface.auto.c.inc
Expand All @@ -24,17 +25,21 @@ bldPgRenderInterfaceAutoC(const Storage *const storageRepo, const BldPg bldPg)
for (unsigned int pgIdx = lstSize(bldPg.pgList) - 1; pgIdx < lstSize(bldPg.pgList); pgIdx--)
{
const BldPgVersion *const pgVersion = lstGet(bldPg.pgList, pgIdx);
const char *const versionNoDot = strZ(strLstJoin(strLstNewSplitZ(pgVersion->version, "."), ""));
const String *const pgVersionNoDot = strLstJoin(strLstNewSplitZ(pgVersion->version, "."), "");
const char *const versionNoDot = strZ(strCat(strCat(strNew(), pgVersionNoDot), strIdToStr(pgVersion->fork)));

strCatFmt(
pg,
"\n"
COMMENT_BLOCK_BEGIN "\n"
"PostgreSQL %s interface\n"
"%s %s interface\n"
COMMENT_BLOCK_END "\n"
"#define PG_VERSION PG_VERSION_%s\n"
"#define FORK_%s\n"
"\n",
strZ(pgVersion->version), versionNoDot);
strZ(strIdToStr(pgVersion->fork)), strZ(pgVersion->version),
strZ(pgVersionNoDot),
strZ(strUpper(strIdToStr(pgVersion->fork))));

for (unsigned int typeIdx = 0; typeIdx < strLstSize(bldPg.typeList); typeIdx++)
{
Expand Down Expand Up @@ -75,6 +80,10 @@ bldPgRenderInterfaceAutoC(const Storage *const storageRepo, const BldPg bldPg)

for (unsigned int functionIdx = 0; functionIdx < strLstSize(bldPg.functionList); functionIdx++)
strCatFmt(pg, "#undef %s\n", strZ(strLstGet(bldPg.functionList, functionIdx)));

strCatChr(pg, '\n');

strCatFmt(pg, "#undef FORK_%s\n\n", strZ(strUpper(strIdToStr(pgVersion->fork))));
}

// Interface struct
Expand All @@ -91,14 +100,16 @@ bldPgRenderInterfaceAutoC(const Storage *const storageRepo, const BldPg bldPg)
for (unsigned int pgIdx = lstSize(bldPg.pgList) - 1; pgIdx < lstSize(bldPg.pgList); pgIdx--)
{
const BldPgVersion *const pgVersion = lstGet(bldPg.pgList, pgIdx);
const char *const versionNoDot = strZ(strLstJoin(strLstNewSplitZ(pgVersion->version, "."), ""));
const String *const pgVersionNoDot = strLstJoin(strLstNewSplitZ(pgVersion->version, "."), "");
const char *const versionNoDot = strZ(strCat(strCat(strNew(), pgVersionNoDot), strIdToStr(pgVersion->fork)));

strCatFmt(
pg,
" {\n"
" .version = PG_VERSION_%s,\n"
" .fork = CFGOPTVAL_FORK_%s,\n"
"\n",
versionNoDot);
strZ(pgVersionNoDot), strZ(strUpper(strIdToStr(pgVersion->fork))));

for (unsigned int functionIdx = 0; functionIdx < strLstSize(bldPg.functionList); functionIdx++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/command/archive/common.c
Expand Up @@ -417,7 +417,7 @@ walSegmentNext(const String *walSegment, size_t walSegmentSize, unsigned int pgV
ASSERT(walSegment != NULL);
ASSERT(strSize(walSegment) == 24);
ASSERT(UINT32_MAX % walSegmentSize == walSegmentSize - 1);
ASSERT(pgVersion >= PG_VERSION_11 || walSegmentSize == PG_WAL_SEGMENT_SIZE_DEFAULT);
ASSERT(pgVersion >= PG_VERSION_11 || walSegmentSize == pgWalSegmentSizeDefault(pgVersion));

// Extract WAL parts
uint32_t timeline = 0;
Expand Down
9 changes: 8 additions & 1 deletion src/config/config.auto.h
Expand Up @@ -79,6 +79,7 @@ Option constants
#define CFGOPT_EXPIRE_AUTO "expire-auto"
#define CFGOPT_FILTER "filter"
#define CFGOPT_FORCE "force"
#define CFGOPT_FORK "fork"
#define CFGOPT_IGNORE_MISSING "ignore-missing"
#define CFGOPT_IO_TIMEOUT "io-timeout"
#define CFGOPT_JOB_RETRY "job-retry"
Expand Down Expand Up @@ -136,7 +137,7 @@ Option constants
#define CFGOPT_TYPE "type"
#define CFGOPT_VERBOSE "verbose"

#define CFG_OPTION_TOTAL 179
#define CFG_OPTION_TOTAL 180

/***********************************************************************************************************************************
Option value constants
Expand All @@ -157,6 +158,11 @@ Option value constants
#define CFGOPTVAL_COMPRESS_TYPE_ZST STRID5("zst", 0x527a0)
#define CFGOPTVAL_COMPRESS_TYPE_ZST_Z "zst"

#define CFGOPTVAL_FORK_GPDB STRID6("GPDB", 0x9e9d6c1)
#define CFGOPTVAL_FORK_GPDB_Z "GPDB"
#define CFGOPTVAL_FORK_POSTGRESQL STRID6("PostgreSQL", 0xc76e054875133f51)
#define CFGOPTVAL_FORK_POSTGRESQL_Z "PostgreSQL"

#define CFGOPTVAL_LOG_LEVEL_CONSOLE_DEBUG STRID5("debug", 0x7a88a40)
#define CFGOPTVAL_LOG_LEVEL_CONSOLE_DEBUG_Z "debug"
#define CFGOPTVAL_LOG_LEVEL_CONSOLE_DETAIL STRID5("detail", 0x1890d0a40)
Expand Down Expand Up @@ -419,6 +425,7 @@ typedef enum
cfgOptExpireAuto,
cfgOptFilter,
cfgOptForce,
cfgOptFork,
cfgOptIgnoreMissing,
cfgOptIoTimeout,
cfgOptJobRetry,
Expand Down

0 comments on commit 18fea34

Please sign in to comment.