pgbackrest.git / summary / log / commit / refs
commit 8e140ad7e06f7e4abdd2c6fa32018ff463d63a6f
Author: David Steele <david@pgmasters.net>
Date: Sat Jul 25 15:39:24 2020 +0000
Build new manifest inside a temporary context.
There is a fair amount of temporary data that is created during the build and it should not end up as a permanent part of the manifest.
src/info/manifest.c | 247 +++++++++++++++++++++++++++-------------------------
1 file changed, 126 insertions(+), 121 deletions(-)
diff --git a/src/info/manifest.c b/src/info/manifest.c
index 49d1f38eb..9128a45bf 100644
--- a/src/info/manifest.c
+++ b/src/info/manifest.c
@@ -876,154 +876,159 @@ manifestNewBuild(
this->data.backupOptionOnline = online;
this->data.backupOptionChecksumPage = varNewBool(checksumPage);
- // Data needed to build the manifest
- ManifestBuildData buildData =
- {
- .manifest = this,
- .storagePg = storagePg,
- .tablespaceId = pgTablespaceId(pgVersion),
- .online = online,
- .checksumPage = checksumPage,
- .tablespaceList = tablespaceList,
- .manifestParentName = MANIFEST_TARGET_PGDATA_STR,
- .manifestWalName = strNewFmt(MANIFEST_TARGET_PGDATA "/%s", strPtr(pgWalPath(pgVersion))),
- .pgPath = storagePathP(storagePg, NULL),
- };
-
- // We won't identify db paths for PostgreSQL < 9.0. This means that temp relations will not be excluded but it doesn't seem
- // worth supporting this feature on such old versions of PostgreSQL.
- // -------------------------------------------------------------------------------------------------------------------------
- if (pgVersion >= PG_VERSION_90)
+ MEM_CONTEXT_TEMP_BEGIN()
{
- ASSERT(buildData.tablespaceId != NULL);
+ // Data needed to build the manifest
+ ManifestBuildData buildData =
+ {
+ .manifest = this,
+ .storagePg = storagePg,
+ .tablespaceId = pgTablespaceId(pgVersion),
+ .online = online,
+ .checksumPage = checksumPage,
+ .tablespaceList = tablespaceList,
+ .manifestParentName = MANIFEST_TARGET_PGDATA_STR,
+ .manifestWalName = strNewFmt(MANIFEST_TARGET_PGDATA "/%s", strPtr(pgWalPath(pgVersion))),
+ .pgPath = storagePathP(storagePg, NULL),
+ };
- // Expression to identify database paths
- buildData.dbPathExp = regExpNew(strNewFmt("^" DB_PATH_EXP "$", strPtr(buildData.tablespaceId)));
+ // We won't identify db paths for PostgreSQL < 9.0. This means that temp relations will not be excluded but it doesn't
+ // seem worth supporting this feature on such old versions of PostgreSQL.
+ // ---------------------------------------------------------------------------------------------------------------------
+ if (pgVersion >= PG_VERSION_90)
+ {
+ ASSERT(buildData.tablespaceId != NULL);
- // Expression to find temp relations
- buildData.tempRelationExp = regExpNew(STRDEF("^t[0-9]+_" RELATION_EXP "$"));
- }
+ // Expression to identify database paths
+ buildData.dbPathExp = regExpNew(strNewFmt("^" DB_PATH_EXP "$", strPtr(buildData.tablespaceId)));
- // Build expression to identify files that can be copied from the standby when standby backup is supported
- // -------------------------------------------------------------------------------------------------------------------------
- buildData.standbyExp = regExpNew(
- strNewFmt(
- "^((" MANIFEST_TARGET_PGDATA "/(" PG_PATH_BASE "|" PG_PATH_GLOBAL "|%s|" PG_PATH_PGMULTIXACT "))|"
- MANIFEST_TARGET_PGTBLSPC ")/",
- strPtr(pgXactPath(pgVersion))));
+ // Expression to find temp relations
+ buildData.tempRelationExp = regExpNew(STRDEF("^t[0-9]+_" RELATION_EXP "$"));
+ }
- // Build list of exclusions
- // -------------------------------------------------------------------------------------------------------------------------
- if (excludeList != NULL)
- {
- for (unsigned int excludeIdx = 0; excludeIdx < strLstSize(excludeList); excludeIdx++)
+ // Build expression to identify files that can be copied from the standby when standby backup is supported
+ // ---------------------------------------------------------------------------------------------------------------------
+ buildData.standbyExp = regExpNew(
+ strNewFmt(
+ "^((" MANIFEST_TARGET_PGDATA "/(" PG_PATH_BASE "|" PG_PATH_GLOBAL "|%s|" PG_PATH_PGMULTIXACT "))|"
+ MANIFEST_TARGET_PGTBLSPC ")/",
+ strPtr(pgXactPath(pgVersion))));
+
+ // Build list of exclusions
+ // ---------------------------------------------------------------------------------------------------------------------
+ if (excludeList != NULL)
{
- const String *exclude = strNewFmt(MANIFEST_TARGET_PGDATA "/%s", strPtr(strLstGet(excludeList, excludeIdx)));
-
- // If the exclusions refers to the contents of a path
- if (strEndsWithZ(exclude, "/"))
+ for (unsigned int excludeIdx = 0; excludeIdx < strLstSize(excludeList); excludeIdx++)
{
- if (buildData.excludeContent == NULL)
- buildData.excludeContent = strLstNew();
+ const String *exclude = strNewFmt(MANIFEST_TARGET_PGDATA "/%s", strPtr(strLstGet(excludeList, excludeIdx)));
- strLstAdd(buildData.excludeContent, strSubN(exclude, 0, strSize(exclude) - 1));
- }
- // Otherwise exclude a single file/link/path
- else
- {
- if (buildData.excludeSingle == NULL)
- buildData.excludeSingle = strLstNew();
+ // If the exclusions refers to the contents of a path
+ if (strEndsWithZ(exclude, "/"))
+ {
+ if (buildData.excludeContent == NULL)
+ buildData.excludeContent = strLstNew();
+
+ strLstAdd(buildData.excludeContent, strSubN(exclude, 0, strSize(exclude) - 1));
+ }
+ // Otherwise exclude a single file/link/path
+ else
+ {
+ if (buildData.excludeSingle == NULL)
+ buildData.excludeSingle = strLstNew();
- strLstAdd(buildData.excludeSingle, exclude);
+ strLstAdd(buildData.excludeSingle, exclude);
+ }
}
}
- }
-
- // Build manifest
- // -------------------------------------------------------------------------------------------------------------------------
- StorageInfo info = storageInfoP(storagePg, buildData.pgPath, .followLink = true);
-
- ManifestPath path =
- {
- .name = MANIFEST_TARGET_PGDATA_STR,
- .mode = info.mode,
- .user = info.user,
- .group = info.group,
- };
- manifestPathAdd(this, &path);
+ // Build manifest
+ // ---------------------------------------------------------------------------------------------------------------------
+ StorageInfo info = storageInfoP(storagePg, buildData.pgPath, .followLink = true);
- ManifestTarget target =
- {
- .name = MANIFEST_TARGET_PGDATA_STR,
- .path = buildData.pgPath,
- .type = manifestTargetTypePath,
- };
-
- manifestTargetAdd(this, &target);
+ ManifestPath path =
+ {
+ .name = MANIFEST_TARGET_PGDATA_STR,
+ .mode = info.mode,
+ .user = info.user,
+ .group = info.group,
+ };
- // Gather info for the rest of the files/links/paths
- storageInfoListP(
- storagePg, buildData.pgPath, manifestBuildCallback, &buildData, .errorOnMissing = true, .sortOrder = sortOrderAsc);
+ manifestPathAdd(this, &path);
- // These may not be in order even if the incoming data was sorted
- lstSort(this->fileList, sortOrderAsc);
- lstSort(this->linkList, sortOrderAsc);
- lstSort(this->pathList, sortOrderAsc);
- lstSort(this->targetList, sortOrderAsc);
+ ManifestTarget target =
+ {
+ .name = MANIFEST_TARGET_PGDATA_STR,
+ .path = buildData.pgPath,
+ .type = manifestTargetTypePath,
+ };
- // Remove unlogged relations from the manifest. This can't be done during the initial build because of the requirement to
- // check for _init files which will sort after the vast majority of the relation files. We could check storage for each
- // _init file but that would be expensive.
- // -------------------------------------------------------------------------------------------------------------------------
- if (pgVersion >= PG_VERSION_91)
- {
- RegExp *relationExp = regExpNew(strNewFmt("^" DB_PATH_EXP "/" RELATION_EXP "$", strPtr(buildData.tablespaceId)));
- unsigned int fileIdx = 0;
- const String *lastRelationFileId = NULL;
- bool lastRelationFileIdUnlogged = false;
+ manifestTargetAdd(this, &target);
- while (fileIdx < manifestFileTotal(this))
+ // Gather info for the rest of the files/links/paths
+ storageInfoListP(
+ storagePg, buildData.pgPath, manifestBuildCallback, &buildData, .errorOnMissing = true, .sortOrder = sortOrderAsc);
+
+ // These may not be in order even if the incoming data was sorted
+ lstSort(this->fileList, sortOrderAsc);
+ lstSort(this->linkList, sortOrderAsc);
+ lstSort(this->pathList, sortOrderAsc);
+ lstSort(this->targetList, sortOrderAsc);
+
+ // Remove unlogged relations from the manifest. This can't be done during the initial build because of the requirement
+ // to check for _init files which will sort after the vast majority of the relation files. We could check storage for
+ // each _init file but that would be expensive.
+ // -------------------------------------------------------------------------------------------------------------------------
+ if (pgVersion >= PG_VERSION_91)
{
- const ManifestFile *file = manifestFile(this, fileIdx);
+ RegExp *relationExp = regExpNew(strNewFmt("^" DB_PATH_EXP "/" RELATION_EXP "$", strPtr(buildData.tablespaceId)));
+ unsigned int fileIdx = 0;
+ const String *lastRelationFileId = NULL;
+ bool lastRelationFileIdUnlogged = false;
- // If this file looks like a relation. Note that this never matches on _init forks.
- if (regExpMatch(relationExp, file->name))
+ while (fileIdx < manifestFileTotal(this))
{
- String *fileName = strBase(file->name);
- String *relationFileId = strNew("");
-
- // Strip off the numeric part of the relation
- for (unsigned int nameIdx = 0; nameIdx < strSize(fileName); nameIdx++)
- {
- char nameChr = strPtr(fileName)[nameIdx];
-
- if (!isdigit(nameChr))
- break;
+ const ManifestFile *file = manifestFile(this, fileIdx);
- strCatChr(relationFileId, nameChr);
- }
-
- // Store the last relation so it does not need to be found everytime
- if (lastRelationFileId == NULL || !strEq(lastRelationFileId, relationFileId))
+ // If this file looks like a relation. Note that this never matches on _init forks.
+ if (regExpMatch(relationExp, file->name))
{
- // Determine if the relation is unlogged
- const String *relationInit = strNewFmt("%s/%s_init", strPtr(strPath(file->name)), strPtr(relationFileId));
- lastRelationFileId = relationFileId;
- lastRelationFileIdUnlogged = manifestFileFindDefault(this, relationInit, NULL) != NULL;
+ String *fileName = strBase(file->name);
+ String *relationFileId = strNew("");
+
+ // Strip off the numeric part of the relation
+ for (unsigned int nameIdx = 0; nameIdx < strSize(fileName); nameIdx++)
+ {
+ char nameChr = strPtr(fileName)[nameIdx];
+
+ if (!isdigit(nameChr))
+ break;
+
+ strCatChr(relationFileId, nameChr);
+ }
+
+ // Store the last relation so it does not need to be found everytime
+ if (lastRelationFileId == NULL || !strEq(lastRelationFileId, relationFileId))
+ {
+ // Determine if the relation is unlogged
+ const String *relationInit = strNewFmt(
+ "%s/%s_init", strPtr(strPath(file->name)), strPtr(relationFileId));
+ lastRelationFileId = relationFileId;
+ lastRelationFileIdUnlogged = manifestFileFindDefault(this, relationInit, NULL) != NULL;
+ }
+
+ // If relation is unlogged then remove it
+ if (lastRelationFileIdUnlogged)
+ {
+ manifestFileRemove(this, file->name);
+ continue;
+ }
}
- // If relation is unlogged then remove it
- if (lastRelationFileIdUnlogged)
- {
- manifestFileRemove(this, file->name);
- continue;
- }
+ fileIdx++;
}
-
- fileIdx++;
}
}
+ MEM_CONTEXT_TEMP_END();
}
MEM_CONTEXT_NEW_END();
[parent: 8e776cc53711]