1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00

Move archiveIdComparator() to archive/common module.

This commit is contained in:
Cynthia Shang 2020-09-08 12:28:56 -04:00 committed by David Steele
parent 9fd31913a8
commit b8efb13bcb
6 changed files with 35 additions and 31 deletions

View File

@ -284,6 +284,18 @@ archiveAsyncExec(ArchiveMode archiveMode, const StringList *commandExec)
FUNCTION_LOG_RETURN_VOID(); FUNCTION_LOG_RETURN_VOID();
} }
/**********************************************************************************************************************************/
int
archiveIdComparator(const void *item1, const void *item2)
{
StringList *archiveSort1 = strLstNewSplitZ(*(String **)item1, "-");
StringList *archiveSort2 = strLstNewSplitZ(*(String **)item2, "-");
int int1 = atoi(strZ(strLstGet(archiveSort1, 1)));
int int2 = atoi(strZ(strLstGet(archiveSort2, 1)));
return (int1 - int2);
}
/**********************************************************************************************************************************/ /**********************************************************************************************************************************/
bool bool
walIsPartial(const String *walSegment) walIsPartial(const String *walSegment)

View File

@ -75,6 +75,9 @@ void archiveAsyncStatusErrorWrite(ArchiveMode archiveMode, const String *walSegm
// Execute the async process. This function will only return in the calling process and the implementation is platform depedent. // Execute the async process. This function will only return in the calling process and the implementation is platform depedent.
void archiveAsyncExec(ArchiveMode archiveMode, const StringList *commandExec); void archiveAsyncExec(ArchiveMode archiveMode, const StringList *commandExec);
// Comparator function for sorting archive ids by the database history id (the number after the dash) e.g. 9.4-1, 10-2
int archiveIdComparator(const void *item1, const void *item2);
// Is the segment partial? // Is the segment partial?
bool walIsPartial(const String *walSegment); bool walIsPartial(const String *walSegment);

View File

@ -29,17 +29,6 @@ typedef struct ArchiveExpired
String *stop; String *stop;
} ArchiveExpired; } ArchiveExpired;
static int
archiveIdComparator(const void *item1, const void *item2)
{
StringList *archiveSort1 = strLstNewSplitZ(*(String **)item1, "-");
StringList *archiveSort2 = strLstNewSplitZ(*(String **)item2, "-");
int int1 = atoi(strZ(strLstGet(archiveSort1, 1)));
int int2 = atoi(strZ(strLstGet(archiveSort2, 1)));
return (int1 - int2);
}
typedef struct ArchiveRange typedef struct ArchiveRange
{ {
const String *start; const String *start;

View File

@ -566,7 +566,7 @@ unit:
test: test:
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: archive-common - name: archive-common
total: 8 total: 9
coverage: coverage:
command/archive/common: full command/archive/common: full
@ -645,7 +645,7 @@ unit:
# ---------------------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------------------------------------------------------------------------------
- name: expire - name: expire
total: 9 total: 8
coverage: coverage:
command/expire/expire: full command/expire/expire: full

View File

@ -333,5 +333,23 @@ testRun(void)
"get range >= 11/1MB"); "get range >= 11/1MB");
} }
// *****************************************************************************************************************************
if (testBegin("archiveIdComparator()"))
{
//--------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("archiveId comparator sorting");
StringList *list = strLstComparatorSet(strLstNew(), archiveIdComparator);
strLstAddZ(list, "10-4");
strLstAddZ(list, "11-10");
strLstAddZ(list, "9.6-1");
TEST_RESULT_STR_Z(strLstJoin(strLstSort(list, sortOrderAsc), ", "), "9.6-1, 10-4, 11-10", "sort ascending");
strLstAddZ(list, "9.4-2");
TEST_RESULT_STR_Z(strLstJoin(strLstSort(list, sortOrderDesc), ", "), "11-10, 10-4, 9.4-2, 9.6-1", "sort descending");
}
FUNCTION_HARNESS_RESULT_VOID(); FUNCTION_HARNESS_RESULT_VOID();
} }

View File

@ -2040,23 +2040,5 @@ testRun(void)
harnessLogLevelReset(); harnessLogLevelReset();
} }
// *****************************************************************************************************************************
if (testBegin("archiveIdComparator()"))
{
//--------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("archiveId comparator sorting");
StringList *list = strLstComparatorSet(strLstNew(), archiveIdComparator);
strLstAddZ(list, "10-4");
strLstAddZ(list, "11-10");
strLstAddZ(list, "9.6-1");
TEST_RESULT_STR_Z(strLstJoin(strLstSort(list, sortOrderAsc), ", "), "9.6-1, 10-4, 11-10", "sort ascending");
strLstAddZ(list, "9.4-2");
TEST_RESULT_STR_Z(strLstJoin(strLstSort(list, sortOrderDesc), ", "), "11-10, 10-4, 9.4-2, 9.6-1", "sort descending");
}
FUNCTION_HARNESS_RESULT_VOID(); FUNCTION_HARNESS_RESULT_VOID();
} }