mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-12 10:04:14 +02:00
Add pgLsnFromWalSegment().
Provides the reverse operation for pgLsnToWalSegment().
This commit is contained in:
parent
a27ff7c335
commit
dd9e14b628
@ -118,6 +118,14 @@
|
||||
|
||||
<p>Inline <code>strPtr()</code> to increase profiling accuracy.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<release-item-contributor-list>
|
||||
<release-item-reviewer id="cynthia.shang"/>
|
||||
</release-item-contributor-list>
|
||||
|
||||
<p>Add <code>pgLsnFromWalSegment()</code>.</p>
|
||||
</release-item>
|
||||
</release-development-list>
|
||||
</release-core-list>
|
||||
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
@ -105,7 +105,7 @@ testRun(void)
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("pgLsnFromStr(), pgLsnToStr(), pgLsnToWalSegment(), and pgLsnRangeToWalSegmentList()"))
|
||||
if (testBegin("pgLsnFromStr(), pgLsnToStr(), pgLsnToWalSegment(), pgLsnFromWalSegment(), and pgLsnRangeToWalSegmentList()"))
|
||||
{
|
||||
TEST_RESULT_UINT(pgLsnFromStr(STRDEF("1/1")), 0x0000000100000001, "lsn to string");
|
||||
TEST_RESULT_UINT(pgLsnFromStr(STRDEF("ffffffff/ffffffff")), 0xFFFFFFFFFFFFFFFF, "lsn to string");
|
||||
@ -119,6 +119,13 @@ testRun(void)
|
||||
TEST_RESULT_STR_Z(pgLsnToWalSegment(1, 0xFFFFFFFFAAAAAAAA, 0x40000000), "00000001FFFFFFFF00000002", "lsn to wal segment");
|
||||
TEST_RESULT_STR_Z(pgLsnToWalSegment(1, 0xFFFFFFFF40000000, 0x40000000), "00000001FFFFFFFF00000001", "lsn to wal segment");
|
||||
|
||||
TEST_RESULT_UINT(
|
||||
pgLsnFromWalSegment(STRDEF("00000001FFFFFFFF000000AA"), 0x1000000), 0xFFFFFFFFAA000000, "16M wal segment to lsn");
|
||||
TEST_RESULT_UINT(
|
||||
pgLsnFromWalSegment(STRDEF("00000001FFFFFFFF00000002"), 0x40000000), 0xFFFFFFFF80000000, "1G wal segment to lsn");
|
||||
TEST_RESULT_UINT(
|
||||
pgLsnFromWalSegment(STRDEF("00000001FFFFFFFF00000001"), 0x40000000), 0xFFFFFFFF40000000, "1G wal segment to lsn");
|
||||
|
||||
TEST_RESULT_STR_Z(
|
||||
strLstJoin(
|
||||
pgLsnRangeToWalSegmentList(
|
||||
|
Loading…
Reference in New Issue
Block a user