1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-03 00:26:59 +02:00

Add pgLsnFromWalSegment().

Provides the reverse operation for pgLsnToWalSegment().
This commit is contained in:
David Steele
2020-07-08 12:25:39 -04:00
parent a27ff7c335
commit dd9e14b628
4 changed files with 35 additions and 2 deletions

View File

@ -627,6 +627,23 @@ pgLsnToWalSegment(uint32_t timeline, uint64_t lsn, unsigned int walSegmentSize)
strNewFmt("%08X%08X%08X", timeline, (unsigned int)(lsn >> 32), (unsigned int)(lsn & 0xFFFFFFFF) / walSegmentSize));
}
uint64_t
pgLsnFromWalSegment(const String *walSegment, unsigned int walSegmentSize)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(STRING, walSegment);
FUNCTION_TEST_PARAM(UINT, walSegmentSize);
FUNCTION_TEST_END();
ASSERT(walSegment != NULL);
ASSERT(strSize(walSegment) == 24);
ASSERT(walSegmentSize > 0);
FUNCTION_TEST_RETURN(
(cvtZToUInt64Base(strPtr(strSubN(walSegment, 8, 8)), 16) << 32) +
(cvtZToUInt64Base(strPtr(strSubN(walSegment, 16, 8)), 16) * walSegmentSize));
}
/**********************************************************************************************************************************/
StringList *
pgLsnRangeToWalSegmentList(

View File

@ -137,8 +137,9 @@ String *pgTablespaceId(unsigned int pgVersion);
uint64_t pgLsnFromStr(const String *lsn);
String *pgLsnToStr(uint64_t lsn);
// Convert a timeline and lsn to a wal segment
// Convert a timeline and lsn to a wal segment and vice versa
String *pgLsnToWalSegment(uint32_t timeline, uint64_t lsn, unsigned int walSegmentSize);
uint64_t pgLsnFromWalSegment(const String *walSegment, unsigned int walSegmentSize);
// Convert a timeline and lsn range to a list of wal segments
StringList *pgLsnRangeToWalSegmentList(