Skip to content

Commit

Permalink
Sort lists where it might help performance.
Browse files Browse the repository at this point in the history
Most of these lists should be quite small with the exception of the list in get.c, but it doesn't cost much to sort them and may help in corner cases we have not thought of.
  • Loading branch information
dwsteele committed Sep 29, 2019
1 parent a58635a commit 33ec5a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/command/archive/get/get.c
Expand Up @@ -88,6 +88,8 @@ queueNeed(const String *walSegment, bool found, uint64_t queueSize, size_t walSe
}

// Generate a list of the WAL that are needed by removing kept WAL from the ideal queue
strLstSort(keepQueue, sortOrderAsc);

for (unsigned int idealQueueIdx = 0; idealQueueIdx < strLstSize(idealQueue); idealQueueIdx++)
{
if (!strLstExists(keepQueue, strLstGet(idealQueue, idealQueueIdx)))
Expand Down
8 changes: 8 additions & 0 deletions src/command/restore/restore.c
Expand Up @@ -285,6 +285,7 @@ restoreManifestMap(Manifest *manifest)
if (tablespaceMap != NULL)
{
const VariantList *tablespaceMapList = kvKeyList(tablespaceMap);
strLstSort(tablespaceRemapped, sortOrderAsc);

for (unsigned int tablespaceMapIdx = 0; tablespaceMapIdx < varLstSize(tablespaceMapList); tablespaceMapIdx++)
{
Expand Down Expand Up @@ -369,6 +370,7 @@ restoreManifestMap(Manifest *manifest)
if (linkMap != NULL)
{
const VariantList *linkMapList = kvKeyList(linkMap);
strLstSort(linkRemapped, sortOrderAsc);

for (unsigned int linkMapIdx = 0; linkMapIdx < varLstSize(linkMapList); linkMapIdx++)
{
Expand Down Expand Up @@ -796,6 +798,8 @@ restoreCleanBuild(Manifest *manifest)
}
}

strLstSort(cleanData->fileIgnore, sortOrderAsc);

// Check that the path exists. If not, there's no need to do any cleaning and we'll attempt to create it later.
// Don't log check for the same path twice. There can be multiple links to files in the same path, but logging it more
// than once makes the logs noisy and looks like a bug.
Expand Down Expand Up @@ -1035,6 +1039,8 @@ restoreSelectiveExpression(Manifest *manifest)
strLstAddIfMissing(dbList, strBase(strPath(file->name)));
}

strLstSort(dbList, sortOrderAsc);

// If no databases were found then this backup is not a valid cluster
if (strLstSize(dbList) == 0)
THROW(FormatError, "no databases found for selective restore\nHINT: is this a valid cluster?");
Expand Down Expand Up @@ -1159,6 +1165,8 @@ restoreRecoveryOption(unsigned int pgVersion)

kvPut(result, VARSTR(key), VARSTR(value));
}

strLstSort(recoveryOptionKey, sortOrderAsc);
}

// Write restore_command
Expand Down

0 comments on commit 33ec5a3

Please sign in to comment.