You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-29 08:21:11 +03:00
Add pgLsnFromStr(), pgLsnToStr(), and pgLsnToWalSegment().
This commit is contained in:
@ -571,6 +571,53 @@ pgTablespaceId(unsigned int pgVersion)
|
|||||||
FUNCTION_TEST_RETURN(result);
|
FUNCTION_TEST_RETURN(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**********************************************************************************************************************************/
|
||||||
|
uint64_t
|
||||||
|
pgLsnFromStr(const String *lsn)
|
||||||
|
{
|
||||||
|
FUNCTION_TEST_BEGIN();
|
||||||
|
FUNCTION_TEST_PARAM(STRING, lsn);
|
||||||
|
FUNCTION_TEST_END();
|
||||||
|
|
||||||
|
uint64_t result = 0;
|
||||||
|
|
||||||
|
MEM_CONTEXT_TEMP_BEGIN()
|
||||||
|
{
|
||||||
|
StringList *lsnPart = strLstNewSplit(lsn, FSLASH_STR);
|
||||||
|
|
||||||
|
CHECK(strLstSize(lsnPart) == 2);
|
||||||
|
|
||||||
|
result = (cvtZToUInt64Base(strPtr(strLstGet(lsnPart, 0)), 16) << 32) + cvtZToUInt64Base(strPtr(strLstGet(lsnPart, 1)), 16);
|
||||||
|
}
|
||||||
|
MEM_CONTEXT_TEMP_END();
|
||||||
|
|
||||||
|
FUNCTION_TEST_RETURN(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
String *
|
||||||
|
pgLsnToStr(uint64_t lsn)
|
||||||
|
{
|
||||||
|
FUNCTION_TEST_BEGIN();
|
||||||
|
FUNCTION_TEST_PARAM(UINT64, lsn);
|
||||||
|
FUNCTION_TEST_END();
|
||||||
|
|
||||||
|
FUNCTION_TEST_RETURN(strNewFmt("%x/%x", (unsigned int)(lsn >> 32), (unsigned int)(lsn & 0xFFFFFFFF)));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**********************************************************************************************************************************/
|
||||||
|
String *
|
||||||
|
pgLsnToWalSegment(uint32_t timeline, uint64_t lsn, unsigned int walSegmentSize)
|
||||||
|
{
|
||||||
|
FUNCTION_TEST_BEGIN();
|
||||||
|
FUNCTION_TEST_PARAM(UINT, timeline);
|
||||||
|
FUNCTION_TEST_PARAM(UINT64, lsn);
|
||||||
|
FUNCTION_TEST_PARAM(UINT, walSegmentSize);
|
||||||
|
FUNCTION_TEST_END();
|
||||||
|
|
||||||
|
FUNCTION_TEST_RETURN(
|
||||||
|
strNewFmt("%08X%08X%08X", timeline, (unsigned int)(lsn >> 32), (unsigned int)(lsn & 0xFFFFFFFF / walSegmentSize)));
|
||||||
|
}
|
||||||
|
|
||||||
/**********************************************************************************************************************************/
|
/**********************************************************************************************************************************/
|
||||||
const String *
|
const String *
|
||||||
pgLsnName(unsigned int pgVersion)
|
pgLsnName(unsigned int pgVersion)
|
||||||
|
@ -125,6 +125,13 @@ PgWal pgWalFromBuffer(const Buffer *walBuffer);
|
|||||||
// Get the tablespace identifier used to distinguish versions in a tablespace directory, e.g. PG_9.0_201008051
|
// Get the tablespace identifier used to distinguish versions in a tablespace directory, e.g. PG_9.0_201008051
|
||||||
String *pgTablespaceId(unsigned int pgVersion);
|
String *pgTablespaceId(unsigned int pgVersion);
|
||||||
|
|
||||||
|
// Convert a string to an lsn and vice versa
|
||||||
|
uint64_t pgLsnFromStr(const String *lsn);
|
||||||
|
String *pgLsnToStr(uint64_t lsn);
|
||||||
|
|
||||||
|
// Convert a timeline and lsn to a wal segment
|
||||||
|
String *pgLsnToWalSegment(uint32_t timeline, uint64_t lsn, unsigned int walSegmentSize);
|
||||||
|
|
||||||
// Get name used for lsn in functions (this was changed in PostgreSQL 10 for consistency since lots of names were changing)
|
// Get name used for lsn in functions (this was changed in PostgreSQL 10 for consistency since lots of names were changing)
|
||||||
const String *pgLsnName(unsigned int pgVersion);
|
const String *pgLsnName(unsigned int pgVersion);
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ unit:
|
|||||||
|
|
||||||
# ----------------------------------------------------------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------------------------------------------------------
|
||||||
- name: interface
|
- name: interface
|
||||||
total: 7
|
total: 8
|
||||||
|
|
||||||
coverage:
|
coverage:
|
||||||
postgres/interface: full
|
postgres/interface: full
|
||||||
|
@ -101,6 +101,21 @@ testRun(void)
|
|||||||
TEST_RESULT_INT(info.version, PG_VERSION_83, " check version");
|
TEST_RESULT_INT(info.version, PG_VERSION_83, " check version");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// *****************************************************************************************************************************
|
||||||
|
if (testBegin("pgLsnFromStr(), pgLsnToStr(), and pgLsnToWalSegment()"))
|
||||||
|
{
|
||||||
|
TEST_RESULT_UINT(pgLsnFromStr(STRDEF("1/1")), 0x0000000100000001, "lsn to string");
|
||||||
|
TEST_RESULT_UINT(pgLsnFromStr(STRDEF("ffffffff/ffffffff")), 0xFFFFFFFFFFFFFFFF, "lsn to string");
|
||||||
|
TEST_RESULT_UINT(pgLsnFromStr(STRDEF("ffffffff/aaaaaaaa")), 0xFFFFFFFFAAAAAAAA, "lsn to string");
|
||||||
|
|
||||||
|
TEST_RESULT_STR_Z(pgLsnToStr(0xFFFFFFFFAAAAAAAA), "ffffffff/aaaaaaaa", "string to lsn");
|
||||||
|
TEST_RESULT_STR_Z(pgLsnToStr(0x0000000000000000), "0/0", "string to lsn");
|
||||||
|
TEST_RESULT_STR_Z(pgLsnToStr(0x0000000100000002), "1/2", "string to lsn");
|
||||||
|
|
||||||
|
TEST_RESULT_STR_Z(pgLsnToWalSegment(1, 0xFFFFFFFFAAAAAAAA, 0x1000000), "00000001FFFFFFFF000000AA", "lsn to wal segment");
|
||||||
|
TEST_RESULT_STR_Z(pgLsnToWalSegment(1, 0xFFFFFFFFAAAAAAAA, 0x40000000), "00000001FFFFFFFF00000002", "lsn to wal segment");
|
||||||
|
}
|
||||||
|
|
||||||
// *****************************************************************************************************************************
|
// *****************************************************************************************************************************
|
||||||
if (testBegin("pgLsnName(), pgTablespaceId(), pgWalName(), and pgXactPath()"))
|
if (testBegin("pgLsnName(), pgTablespaceId(), pgWalName(), and pgXactPath()"))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user