1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2026-06-20 01:17:49 +02:00

Reverse sort order in backup and restore comparators.

Both of these lists were sorted descending so all comparisons in the comparator had to be reversed. This made it hard to reason about sort order.

It makes more sense to sort ascending and have the comparisons also be ascending. The final sort order remains the same.
This commit is contained in:
David Steele
2026-02-14 12:57:35 +07:00
parent 1db52ef9f3
commit 17db234f1b
2 changed files with 20 additions and 20 deletions
+7 -7
View File
@@ -1742,22 +1742,22 @@ backupProcessQueueComparator(const void *const item1, const void *const item2)
file2.size > backupProcessQueueComparatorBundleLimit)
{
if (file1.size < file2.size)
FUNCTION_TEST_RETURN(INT, -1);
else if (file1.size > file2.size)
FUNCTION_TEST_RETURN(INT, 1);
else if (file1.size > file2.size)
FUNCTION_TEST_RETURN(INT, -1);
}
// If bundling order by time ascending so that older files are bundled with older files and newer with newer
// If bundling order by time desc so that older files are bundled with older files and newer with newer
if (backupProcessQueueComparatorBundle)
{
if (file1.timestamp > file2.timestamp)
FUNCTION_TEST_RETURN(INT, -1);
else if (file1.timestamp < file2.timestamp)
FUNCTION_TEST_RETURN(INT, 1);
else if (file1.timestamp < file2.timestamp)
FUNCTION_TEST_RETURN(INT, -1);
}
// If size/time is the same then use name to generate a deterministic ordering (names must be unique)
FUNCTION_TEST_RETURN(INT, strCmp(file1.name, file2.name));
FUNCTION_TEST_RETURN(INT, strCmp(file2.name, file1.name));
}
// Helper to generate the backup queues
@@ -1885,7 +1885,7 @@ backupProcessQueue(const BackupData *const backupData, Manifest *const manifest,
backupProcessQueueComparatorBundleLimit = jobData->bundleLimit;
for (unsigned int queueIdx = 0; queueIdx < lstSize(jobData->queueList); queueIdx++)
lstSort(*(List **)lstGet(jobData->queueList, queueIdx), sortOrderDesc);
lstSort(*(List **)lstGet(jobData->queueList, queueIdx), sortOrderAsc);
// Move process queues to prior context
lstMove(jobData->queueList, memContextPrior());
+13 -13
View File
@@ -23,42 +23,42 @@ restoreProcessQueueComparator(const void *const item1, const void *const item2)
if (file1.size == 0)
{
if (file2.size != 0)
FUNCTION_TEST_RETURN(INT, -1);
FUNCTION_TEST_RETURN(INT, 1);
}
else if (file2.size == 0)
FUNCTION_TEST_RETURN(INT, 1);
FUNCTION_TEST_RETURN(INT, -1);
// If the bundle id differs that is enough to determine order
if (file1.bundleId < file2.bundleId)
FUNCTION_TEST_RETURN(INT, 1);
else if (file1.bundleId > file2.bundleId)
FUNCTION_TEST_RETURN(INT, -1);
else if (file1.bundleId > file2.bundleId)
FUNCTION_TEST_RETURN(INT, 1);
// If the bundle ids are 0
if (file1.bundleId == 0)
{
// If the size differs then that's enough to determine order
if (file1.size < file2.size)
FUNCTION_TEST_RETURN(INT, -1);
else if (file1.size > file2.size)
FUNCTION_TEST_RETURN(INT, 1);
else if (file1.size > file2.size)
FUNCTION_TEST_RETURN(INT, -1);
// If size is the same then use name to generate a deterministic ordering (names must be unique)
ASSERT(!strEq(file1.name, file2.name));
FUNCTION_TEST_RETURN(INT, strCmp(file1.name, file2.name));
FUNCTION_TEST_RETURN(INT, strCmp(file2.name, file1.name));
}
// If the reference differs that is enough to determine order
if (file1.reference == NULL)
{
if (file2.reference != NULL)
FUNCTION_TEST_RETURN(INT, -1);
FUNCTION_TEST_RETURN(INT, 1);
}
else if (file2.reference == NULL)
FUNCTION_TEST_RETURN(INT, 1);
FUNCTION_TEST_RETURN(INT, -1);
else
{
const int backupLabelCmp = strCmp(file1.reference, file2.reference) * -1;
const int backupLabelCmp = strCmp(file2.reference, file1.reference) * -1;
if (backupLabelCmp != 0)
FUNCTION_TEST_RETURN(INT, backupLabelCmp);
@@ -68,9 +68,9 @@ restoreProcessQueueComparator(const void *const item1, const void *const item2)
ASSERT(file1.bundleOffset != file2.bundleOffset);
if (file1.bundleOffset < file2.bundleOffset)
FUNCTION_TEST_RETURN(INT, 1);
FUNCTION_TEST_RETURN(INT, -1);
FUNCTION_TEST_RETURN(INT, -1);
FUNCTION_TEST_RETURN(INT, 1);
}
static uint64_t
@@ -147,7 +147,7 @@ restoreProcessQueue(const Manifest *const manifest, List **const queueList)
restoreProcessQueueComparatorManifest = manifest;
for (unsigned int targetIdx = 0; targetIdx < strLstSize(targetList); targetIdx++)
lstSort(*(List **)lstGet(*queueList, targetIdx), sortOrderDesc);
lstSort(*(List **)lstGet(*queueList, targetIdx), sortOrderAsc);
// Move process queues to prior context
lstMove(*queueList, memContextPrior());