forked from pgbackrest/pgbackrest
-
Notifications
You must be signed in to change notification settings - Fork 3
ADBM-2913: Implement repo-push command #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
52987da
repo-push command template
dkovalev1 1e024b9
File upload
dkovalev1 1ea4411
Push file to the manifest
dkovalev1 ceab358
implement test
dkovalev1 e42ad9a
remove encryption and make compression test, format code
dkovalev1 0024bb6
changes from review
dkovalev1 e020e95
Fix format
dkovalev1 0afd9bd
Remove comressed size from the test as it vary on different platforms
dkovalev1 1b42983
Optimization, formatting, new test cases and check for ending slash i…
dkovalev1 0c29416
Add unit tests
dkovalev1 650fb05
fix typo
dkovalev1 906d35e
tests number
dkovalev1 3810fab
typo
dkovalev1 240089b
try to use ubuntu 22 for documentation build
dkovalev1 979840c
try to suppress Azurite API version checking in documentation builds.
dkovalev1 6737811
rollback
dkovalev1 ff2dea0
change upload path due to SRS update
dkovalev1 57da285
forgotten comment
dkovalev1 b818d95
fix
dkovalev1 d16d344
Change error message
dkovalev1 e665bdc
Merge branch '2.54-ci' into ADBM-2913
dkovalev1 09d3abc
Use <REPO:BACKUP> to build path
dkovalev1 ad98bc3
Merge branch '2.54-ci' into ADBM-2913
dkovalev1 739be0b
Merge branch '2.54-ci' into ADBM-2913
dkovalev1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,208 @@ | ||
| /*********************************************************************************************************************************** | ||
| Repository Put Command | ||
| ***********************************************************************************************************************************/ | ||
| #include "build.auto.h" | ||
|
|
||
| #include <unistd.h> | ||
|
|
||
| #include "command/repo/common.h" | ||
| #include "common/compress/helper.h" | ||
| #include "common/debug.h" | ||
| #include "common/io/fdRead.h" | ||
| #include "common/io/filter/size.h" | ||
| #include "common/io/io.h" | ||
| #include "common/log.h" | ||
| #include "common/memContext.h" | ||
| #include "common/type/string.h" | ||
| #include "config/config.h" | ||
| #include "info/manifest.h" | ||
| #include "storage/helper.h" | ||
|
|
||
| static String * | ||
| composeDestinationPath(const String *backupLabel, const String *fileName) | ||
| { | ||
| FUNCTION_LOG_BEGIN(logLevelDebug); | ||
| FUNCTION_LOG_PARAM(STRING, backupLabel); | ||
| FUNCTION_LOG_PARAM(STRING, fileName); | ||
| FUNCTION_LOG_END(); | ||
|
|
||
| String *const result = strNewFmt(STORAGE_REPO_BACKUP "/%s/%s", strZ(backupLabel), strZ(fileName)); | ||
|
|
||
| FUNCTION_LOG_RETURN(STRING, result); | ||
| } | ||
|
|
||
| /*********************************************************************************************************************************** | ||
| Write source IO to destination file | ||
| ***********************************************************************************************************************************/ | ||
| static void | ||
| storagePushProcess(const String *file, CompressType compressType, int compressLevel) | ||
| { | ||
| FUNCTION_LOG_BEGIN(logLevelDebug); | ||
| FUNCTION_LOG_PARAM(STRING, file); | ||
| FUNCTION_LOG_PARAM(ENUM, compressType); | ||
| FUNCTION_LOG_PARAM(INT, compressLevel); | ||
| FUNCTION_LOG_END(); | ||
|
|
||
| // Ensure that the file exists and readable | ||
| MEM_CONTEXT_TEMP_BEGIN() | ||
| { | ||
| // Normalize source file path | ||
| // Get current working dir | ||
| char currentWorkDir[1024]; | ||
| THROW_ON_SYS_ERROR(getcwd(currentWorkDir, sizeof(currentWorkDir)) == NULL, FormatError, "unable to get cwd"); | ||
bandetto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| String *sourcePath = strPathAbsolute(file, strNewZ(currentWorkDir)); | ||
|
|
||
| // Repository Path Formation | ||
|
|
||
| const String *backupLabel = cfgOptionStr(cfgOptSet); | ||
|
|
||
| String *destFilename = strCat(strNew(), strFileName(file)); | ||
silent-observer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| compressExtCat(destFilename, compressType); | ||
|
|
||
| String *destPath = composeDestinationPath(backupLabel, destFilename); | ||
|
|
||
| // Is path valid for repo? | ||
| destPath = repoPathIsValid(destPath); | ||
|
|
||
| bool repoChecksum = false; | ||
| const Storage *storage = storageRepoWrite(); | ||
| const StorageWrite *const destination = storageNewWriteP(storage, destPath); | ||
|
|
||
| IoRead *const sourceIo = storageReadIo(storageNewReadP(storageLocal(), sourcePath)); | ||
| IoWrite *const destinationIo = storageWriteIo(destination); | ||
|
|
||
| IoFilterGroup *const readFilterGroup = ioReadFilterGroup(sourceIo); | ||
| IoFilterGroup *const writeFilterGroup = ioWriteFilterGroup(destinationIo); | ||
|
|
||
| const String *manifestFileName = strNewFmt(STORAGE_REPO_BACKUP "/%s/" BACKUP_MANIFEST_FILE, strZ(backupLabel)); | ||
| Manifest *manifest = manifestLoadFile( | ||
| storage, manifestFileName, | ||
| cipherTypeNone, NULL); | ||
|
|
||
| // Add SHA1 filter | ||
| ioFilterGroupAdd(writeFilterGroup, cryptoHashNew(hashTypeSha1)); | ||
|
|
||
| // Add compression | ||
| if (compressType != compressTypeNone) | ||
| { | ||
| ioFilterGroupAdd( | ||
| writeFilterGroup, | ||
| compressFilterP(compressType, compressLevel)); | ||
|
|
||
| repoChecksum = true; | ||
| } | ||
|
|
||
| // Capture checksum of file stored in the repo if filters that modify the output have been applied | ||
| if (repoChecksum) | ||
| ioFilterGroupAdd(writeFilterGroup, cryptoHashNew(hashTypeSha1)); | ||
|
|
||
| // Add size filter last to calculate repo size | ||
| ioFilterGroupAdd(writeFilterGroup, ioSizeNew()); | ||
|
|
||
| // Add size filter last to calculate source file size | ||
| ioFilterGroupAdd(readFilterGroup, ioSizeNew()); | ||
|
|
||
| // Open source and destination | ||
| ioReadOpen(sourceIo); | ||
| ioWriteOpen(destinationIo); | ||
|
|
||
| // Copy data from source to destination | ||
| ioCopyP(sourceIo, destinationIo); | ||
|
|
||
| // Close the source and destination | ||
| ioReadClose(sourceIo); | ||
| ioWriteClose(destinationIo); | ||
|
|
||
| // Use base path to set ownership and mode | ||
| const ManifestPath *const basePath = manifestPathFind(manifest, MANIFEST_TARGET_PGDATA_STR); | ||
|
|
||
| // Add to manifest | ||
| uint64_t rsize = pckReadU64P(ioFilterGroupResultP(readFilterGroup, SIZE_FILTER_TYPE)); | ||
| uint64_t wsize = pckReadU64P(ioFilterGroupResultP(writeFilterGroup, SIZE_FILTER_TYPE)); | ||
| ManifestFile customFile = | ||
| { | ||
| .name = destFilename, | ||
| .mode = basePath->mode & (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH), | ||
| .size = wsize, | ||
| .sizeOriginal = rsize, | ||
| .sizeRepo = wsize, | ||
| .timestamp = time(NULL), | ||
| .checksumSha1 = bufPtr(pckReadBinP(ioFilterGroupResultP(writeFilterGroup, CRYPTO_HASH_FILTER_TYPE, .idx = 0))), | ||
| }; | ||
|
|
||
| if (repoChecksum) | ||
| { | ||
| PackRead *packRead = ioFilterGroupResultP(writeFilterGroup, CRYPTO_HASH_FILTER_TYPE, .idx = 1); | ||
| ASSERT(packRead != NULL); | ||
| customFile.checksumRepoSha1 = bufPtr(pckReadBinP(packRead)); | ||
| } | ||
|
|
||
| bool found = false; | ||
|
|
||
| for (unsigned int fileIdx = 0; fileIdx < manifestCustomFileTotal(manifest); fileIdx++) | ||
| { | ||
| ManifestFile manifestFile = manifestCustomFile(manifest, fileIdx); | ||
|
|
||
| if (strCmp(manifestFile.name, destFilename) == 0){ | ||
silent-observer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| manifestFile.mode = customFile.mode; | ||
| manifestFile.size = customFile.size; | ||
| manifestFile.sizeOriginal = customFile.sizeOriginal; | ||
| manifestFile.sizeRepo = customFile.sizeRepo; | ||
| manifestFile.timestamp = customFile.timestamp; | ||
| manifestFile.checksumSha1 = customFile.checksumSha1; | ||
|
|
||
| manifestCustomFileUpdate(manifest, &manifestFile); | ||
| found = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!found) | ||
| manifestCustomFileAdd(manifest, &customFile); | ||
|
|
||
| // Save manifest | ||
| IoWrite *const manifestWrite = storageWriteIo( | ||
| storageNewWriteP( | ||
| storageRepoWrite(), | ||
| manifestFileName | ||
| )); | ||
|
|
||
| manifestSave(manifest, manifestWrite); | ||
| } | ||
| MEM_CONTEXT_TEMP_END(); | ||
|
|
||
| FUNCTION_LOG_RETURN_VOID(); | ||
| } | ||
|
|
||
| /**********************************************************************************************************************************/ | ||
| FN_EXTERN void | ||
| cmdStoragePush(void) | ||
| { | ||
| FUNCTION_LOG_VOID(logLevelDebug); | ||
|
|
||
| MEM_CONTEXT_TEMP_BEGIN() | ||
| { | ||
| const StringList *params = cfgCommandParam(); | ||
|
|
||
| if (strLstSize(params) != 1) | ||
| THROW(ParamInvalidError, "exactly one parameter is required"); | ||
|
|
||
| String *filename = strLstGet(params, 0); | ||
|
|
||
| // Check that the filename does not end with a slash | ||
| if (strEndsWith(filename, FSLASH_STR)) | ||
| THROW(ParamInvalidError, "file parameter should not end with a slash"); | ||
|
|
||
| LOG_INFO_FMT( | ||
| "push file %s to the archive.", | ||
| strZ(filename)); | ||
|
|
||
| storagePushProcess(filename, | ||
| compressTypeEnum(cfgOptionStrId(cfgOptCompressType)), | ||
| cfgOptionInt(cfgOptCompressLevel)); | ||
| } | ||
| MEM_CONTEXT_TEMP_END(); | ||
|
|
||
| FUNCTION_LOG_RETURN_VOID(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| /*********************************************************************************************************************************** | ||
| Repository Push Command | ||
| ***********************************************************************************************************************************/ | ||
| #ifndef COMMAND_STORAGE_PUSH_H | ||
| #define COMMAND_STORAGE_PUSH_H | ||
|
|
||
| /*********************************************************************************************************************************** | ||
| Functions | ||
| ***********************************************************************************************************************************/ | ||
| // Push a metadata file into the repository | ||
| FN_EXTERN void cmdStoragePush(void); | ||
|
|
||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.