1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-01 00:25:06 +02:00

Add pgLsnRangeToWalSegmentList() to convert lsn range to wal segments.

This commit is contained in:
David Steele
2019-12-12 16:43:34 -05:00
parent 81295fd388
commit 8acfb6adf4
3 changed files with 101 additions and 1 deletions

View File

@ -622,6 +622,66 @@ pgLsnToWalSegment(uint32_t timeline, uint64_t lsn, unsigned int walSegmentSize)
strNewFmt("%08X%08X%08X", timeline, (unsigned int)(lsn >> 32), (unsigned int)(lsn & 0xFFFFFFFF) / walSegmentSize));
}
/**********************************************************************************************************************************/
StringList *
pgLsnRangeToWalSegmentList(
unsigned int pgVersion, uint32_t timeline, uint64_t lsnStart, uint64_t lsnStop, unsigned int walSegmentSize)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(UINT, pgVersion);
FUNCTION_TEST_PARAM(UINT, timeline);
FUNCTION_TEST_PARAM(UINT64, lsnStart);
FUNCTION_TEST_PARAM(UINT64, lsnStop);
FUNCTION_TEST_PARAM(UINT, walSegmentSize);
FUNCTION_TEST_END();
ASSERT(pgVersion != 0);
ASSERT(timeline != 0);
ASSERT(lsnStart <= lsnStop);
ASSERT(walSegmentSize != 0);
ASSERT(pgVersion > PG_VERSION_92 || walSegmentSize == PG_WAL_SEGMENT_SIZE_DEFAULT);
StringList *result = NULL;
MEM_CONTEXT_TEMP_BEGIN()
{
result = strLstNew();
// Skip the FF segment when PostgreSQL <= 9.2 (in this case segment size should always be 16MB)
bool skipFF = pgVersion <= PG_VERSION_92;
// Calculate the start and stop segments
unsigned int startMajor = (unsigned int)(lsnStart >> 32);
unsigned int startMinor = (unsigned int)(lsnStart & 0xFFFFFFFF) / walSegmentSize;
unsigned int stopMajor = (unsigned int)(lsnStop >> 32);
unsigned int stopMinor = (unsigned int)(lsnStop & 0xFFFFFFFF) / walSegmentSize;
unsigned int minorPerMajor = 0xFFFFFFFF / walSegmentSize;
// Create list
strLstAdd(result, strNewFmt("%08X%08X%08X", timeline, startMajor, startMinor));
while (!(startMajor == stopMajor && startMinor == stopMinor))
{
startMinor++;
if ((skipFF && startMinor == 0xFF) || (!skipFF && startMinor > minorPerMajor))
{
startMajor++;
startMinor = 0;
}
strLstAdd(result, strNewFmt("%08X%08X%08X", timeline, startMajor, startMinor));
}
strLstMove(result, MEM_CONTEXT_OLD());
}
MEM_CONTEXT_TEMP_END();
FUNCTION_TEST_RETURN(result);
}
/**********************************************************************************************************************************/
const String *
pgLsnName(unsigned int pgVersion)