1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-05 15:05:48 +02:00

Refactor info modules with inline getters/setters.

Extend the pattern introduced in 79a2d02c to the info modules.
This commit is contained in:
David Steele 2021-04-09 13:48:40 -04:00
parent 4937653a3d
commit 442b2e41b1
16 changed files with 623 additions and 806 deletions

View File

@ -38,9 +38,8 @@ Object types
***********************************************************************************************************************************/
struct Info
{
InfoPub pub; // Publicly accessible variables
MemContext *memContext; // Mem context
const String *backrestVersion; // pgBackRest version
const String *cipherPass; // Cipher passphrase if set
};
struct InfoSave
@ -142,7 +141,7 @@ infoNew(const String *cipherPass)
// Cipher used to encrypt/decrypt subsequent dependent files. Value may be NULL.
infoCipherPassSet(this, cipherPass);
this->backrestVersion = STRDEF(PROJECT_VERSION);
this->pub.backrestVersion = STRDEF(PROJECT_VERSION);
}
MEM_CONTEXT_NEW_END();
@ -219,7 +218,7 @@ infoLoadCallback(void *data, const String *section, const String *key, const Str
{
MEM_CONTEXT_BEGIN(loadData->info->memContext)
{
loadData->info->backrestVersion = strDup(varStr(valueVar));
loadData->info->pub.backrestVersion = strDup(varStr(valueVar));
}
MEM_CONTEXT_END();
}
@ -243,7 +242,7 @@ infoLoadCallback(void *data, const String *section, const String *key, const Str
{
MEM_CONTEXT_BEGIN(loadData->info->memContext)
{
loadData->info->cipherPass = strDup(varStr(valueVar));
loadData->info->pub.cipherPass = strDup(varStr(valueVar));
}
MEM_CONTEXT_END();
}
@ -424,10 +423,10 @@ infoSave(Info *this, IoWrite *write, InfoSaveCallback *callbackFunction, void *c
infoSaveValue(&data, INFO_SECTION_BACKREST_STR, INFO_KEY_VERSION_STR, jsonFromStr(STRDEF(PROJECT_VERSION)));
// Add cipher passphrase if defined
if (this->cipherPass != NULL)
if (infoCipherPass(this) != NULL)
{
callbackFunction(callbackData, INFO_SECTION_CIPHER_STR, &data);
infoSaveValue(&data, INFO_SECTION_CIPHER_STR, INFO_KEY_CIPHER_PASS_STR, jsonFromStr(this->cipherPass));
infoSaveValue(&data, INFO_SECTION_CIPHER_STR, INFO_KEY_CIPHER_PASS_STR, jsonFromStr(infoCipherPass(this)));
}
// Flush out any additional sections
@ -450,18 +449,6 @@ infoSave(Info *this, IoWrite *write, InfoSaveCallback *callbackFunction, void *c
/***********************************************************************************************************************************
Getters/Setters
***********************************************************************************************************************************/
const String *
infoCipherPass(const Info *this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(INFO, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
FUNCTION_TEST_RETURN(this->cipherPass);
}
void
infoCipherPassSet(Info *this, const String *cipherPass)
{
@ -474,25 +461,13 @@ infoCipherPassSet(Info *this, const String *cipherPass)
MEM_CONTEXT_BEGIN(this->memContext)
{
this->cipherPass = strDup(cipherPass);
this->pub.cipherPass = strDup(cipherPass);
}
MEM_CONTEXT_END();
FUNCTION_TEST_RETURN_VOID();
}
const String *
infoBackrestVersion(const Info *this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(INFO, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
FUNCTION_TEST_RETURN(this->backrestVersion);
}
/**********************************************************************************************************************************/
void
infoLoad(const String *error, InfoLoadCallback *callbackFunction, void *callbackData)

View File

@ -42,6 +42,33 @@ Info *infoNew(const String *cipherPassSub);
// Create new object and load contents from a file
Info *infoNewLoad(IoRead *read, InfoLoadNewCallback *callbackFunction, void *callbackData);
/***********************************************************************************************************************************
Getters/Setters
***********************************************************************************************************************************/
typedef struct InfoPub
{
const String *backrestVersion; // pgBackRest version
const String *cipherPass; // Cipher passphrase if set
} InfoPub;
// Cipher passphrase if set
__attribute__((always_inline)) static inline const String *
infoCipherPass(const Info *const this)
{
ASSERT_INLINE(this != NULL);
return ((InfoPub *)this)->cipherPass;
}
void infoCipherPassSet(Info *this, const String *cipherPass);
// pgBackRest version
__attribute__((always_inline)) static inline const String *
infoBackrestVersion(const Info *const this)
{
ASSERT_INLINE(this != NULL);
return ((InfoPub *)this)->backrestVersion;
}
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
@ -54,13 +81,6 @@ bool infoSaveSection(InfoSave *infoSaveData, const String *section, const String
// Save a JSON formatted value and update checksum
void infoSaveValue(InfoSave *infoSaveData, const String *section, const String *key, const String *jsonValue);
/***********************************************************************************************************************************
Getters/Setters
***********************************************************************************************************************************/
const String *infoCipherPass(const Info *this);
void infoCipherPassSet(Info *this, const String *cipherPass);
const String *infoBackrestVersion(const Info *this);
/***********************************************************************************************************************************
Helper functions
***********************************************************************************************************************************/

View File

@ -32,8 +32,7 @@ Object type
***********************************************************************************************************************************/
struct InfoArchive
{
MemContext *memContext; // Mem context
InfoPg *infoPg; // Contents of the DB data
InfoArchivePub pub; // Publicly accessible variables
};
/***********************************************************************************************************************************
@ -47,8 +46,11 @@ infoArchiveNewInternal(void)
InfoArchive *this = memNew(sizeof(InfoArchive));
*this = (InfoArchive)
{
.pub =
{
.memContext = memContextCurrent(),
},
};
FUNCTION_TEST_RETURN(this);
@ -73,7 +75,7 @@ infoArchiveNew(unsigned int pgVersion, uint64_t pgSystemId, const String *cipher
this = infoArchiveNewInternal();
// Initialize the pg data
this->infoPg = infoPgNew(infoPgArchive, cipherPassSub);
this->pub.infoPg = infoPgNew(infoPgArchive, cipherPassSub);
infoArchivePgSet(this, pgVersion, pgSystemId);
}
MEM_CONTEXT_NEW_END();
@ -96,7 +98,7 @@ infoArchiveNewLoad(IoRead *read)
MEM_CONTEXT_NEW_BEGIN("InfoArchive")
{
this = infoArchiveNewInternal();
this->infoPg = infoPgNewLoad(read, infoPgArchive, NULL, NULL);
this->pub.infoPg = infoPgNewLoad(read, infoPgArchive, NULL, NULL);
}
MEM_CONTEXT_NEW_END();
@ -183,45 +185,6 @@ infoArchiveSave(InfoArchive *this, IoWrite *write)
FUNCTION_LOG_RETURN_VOID();
}
/**********************************************************************************************************************************/
const String *
infoArchiveId(const InfoArchive *this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(INFO_ARCHIVE, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
FUNCTION_TEST_RETURN(infoPgArchiveId(this->infoPg, infoPgDataCurrentId(this->infoPg)));
}
/**********************************************************************************************************************************/
const String *
infoArchiveCipherPass(const InfoArchive *this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(INFO_ARCHIVE, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
FUNCTION_TEST_RETURN(infoPgCipherPass(this->infoPg));
}
/**********************************************************************************************************************************/
InfoPg *
infoArchivePg(const InfoArchive *this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(INFO_ARCHIVE, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
FUNCTION_TEST_RETURN(this->infoPg);
}
/**********************************************************************************************************************************/
InfoArchive *
infoArchivePgSet(InfoArchive *this, unsigned int pgVersion, uint64_t pgSystemId)
@ -234,7 +197,7 @@ infoArchivePgSet(InfoArchive *this, unsigned int pgVersion, uint64_t pgSystemId)
ASSERT(this != NULL);
this->infoPg = infoPgSet(this->infoPg, infoPgArchive, pgVersion, pgSystemId, 0);
this->pub.infoPg = infoPgSet(infoArchivePg(this), infoPgArchive, pgVersion, pgSystemId, 0);
FUNCTION_LOG_RETURN(INFO_ARCHIVE, this);
}

View File

@ -34,6 +34,39 @@ InfoArchive *infoArchiveNew(const unsigned int pgVersion, const uint64_t pgSyste
// Create new object and load contents from IoRead
InfoArchive *infoArchiveNewLoad(IoRead *read);
/***********************************************************************************************************************************
Getters/Setters
***********************************************************************************************************************************/
typedef struct InfoArchivePub
{
MemContext *memContext; // Mem context
InfoPg *infoPg; // Contents of the DB data
} InfoArchivePub;
// PostgreSQL info
__attribute__((always_inline)) static inline InfoPg *
infoArchivePg(const InfoArchive *const this)
{
ASSERT_INLINE(this != NULL);
return ((InfoArchivePub *)this)->infoPg;
}
InfoArchive *infoArchivePgSet(InfoArchive *this, unsigned int pgVersion, uint64_t pgSystemId);
// Current archive id
__attribute__((always_inline)) static inline const String *
infoArchiveId(const InfoArchive *const this)
{
return infoPgArchiveId(infoArchivePg(this), infoPgDataCurrentId(infoArchivePg(this)));
}
// Cipher passphrase
__attribute__((always_inline)) static inline const String *
infoArchiveCipherPass(const InfoArchive *const this)
{
return infoPgCipherPass(infoArchivePg(this));
}
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
@ -48,19 +81,6 @@ infoArchiveMove(InfoArchive *this, MemContext *parentNew)
return objMove(this, parentNew);
}
/***********************************************************************************************************************************
Getters/Setters
***********************************************************************************************************************************/
// Current archive id
const String *infoArchiveId(const InfoArchive *this);
// Cipher passphrase
const String *infoArchiveCipherPass(const InfoArchive *this);
// PostgreSQL info
InfoPg *infoArchivePg(const InfoArchive *this);
InfoArchive *infoArchivePgSet(InfoArchive *this, unsigned int pgVersion, uint64_t pgSystemId);
/***********************************************************************************************************************************
Destructor
***********************************************************************************************************************************/

View File

@ -60,9 +60,7 @@ Object type
***********************************************************************************************************************************/
struct InfoBackup
{
MemContext *memContext; // Mem context
InfoPg *infoPg; // Contents of the DB data
List *backup; // List of current backups and their associated data
InfoBackupPub pub; // Publicly accessible variables
};
/***********************************************************************************************************************************
@ -76,9 +74,12 @@ infoBackupNewInternal(void)
InfoBackup *this = memNew(sizeof(InfoBackup));
*this = (InfoBackup)
{
.pub =
{
.memContext = memContextCurrent(),
.backup = lstNewP(sizeof(InfoBackupData), .comparator = lstComparatorStr),
},
};
FUNCTION_TEST_RETURN(this);
@ -104,7 +105,7 @@ infoBackupNew(unsigned int pgVersion, uint64_t pgSystemId, unsigned int pgCatalo
this = infoBackupNewInternal();
// Initialize the pg data
this->infoPg = infoPgNew(infoPgBackup, cipherPassSub);
this->pub.infoPg = infoPgNew(infoPgBackup, cipherPassSub);
infoBackupPgSet(this, pgVersion, pgSystemId, pgCatalogVersion);
}
MEM_CONTEXT_NEW_END();
@ -137,7 +138,7 @@ infoBackupLoadCallback(void *data, const String *section, const String *key, con
{
const KeyValue *backupKv = varKv(value);
MEM_CONTEXT_BEGIN(lstMemContext(infoBackup->backup))
MEM_CONTEXT_BEGIN(lstMemContext(infoBackup->pub.backup))
{
InfoBackupData infoBackupData =
{
@ -174,7 +175,7 @@ infoBackupLoadCallback(void *data, const String *section, const String *key, con
};
// Add the backup data to the list
lstAdd(infoBackup->backup, &infoBackupData);
lstAdd(infoBackup->pub.backup, &infoBackupData);
}
MEM_CONTEXT_END();
}
@ -197,7 +198,7 @@ infoBackupNewLoad(IoRead *read)
MEM_CONTEXT_NEW_BEGIN("InfoBackup")
{
this = infoBackupNewInternal();
this->infoPg = infoPgNewLoad(read, infoPgBackup, infoBackupLoadCallback, this);
this->pub.infoPg = infoPgNewLoad(read, infoPgBackup, infoBackupLoadCallback, this);
}
MEM_CONTEXT_NEW_END();
@ -293,18 +294,6 @@ infoBackupSave(InfoBackup *this, IoWrite *write)
}
/**********************************************************************************************************************************/
InfoPg *
infoBackupPg(const InfoBackup *this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(INFO_BACKUP, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
FUNCTION_TEST_RETURN(this->infoPg);
}
InfoBackup *
infoBackupPgSet(InfoBackup *this, unsigned int pgVersion, uint64_t pgSystemId, unsigned int pgCatalogVersion)
{
@ -315,24 +304,11 @@ infoBackupPgSet(InfoBackup *this, unsigned int pgVersion, uint64_t pgSystemId, u
FUNCTION_LOG_PARAM(UINT, pgCatalogVersion);
FUNCTION_LOG_END();
this->infoPg = infoPgSet(this->infoPg, infoPgBackup, pgVersion, pgSystemId, pgCatalogVersion);
this->pub.infoPg = infoPgSet(infoBackupPg(this), infoPgBackup, pgVersion, pgSystemId, pgCatalogVersion);
FUNCTION_LOG_RETURN(INFO_BACKUP, this);
}
/**********************************************************************************************************************************/
unsigned int
infoBackupDataTotal(const InfoBackup *this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(INFO_BACKUP, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
FUNCTION_TEST_RETURN(lstSize(this->backup));
}
/**********************************************************************************************************************************/
InfoBackupData
infoBackupData(const InfoBackup *this, unsigned int backupDataIdx)
@ -344,22 +320,7 @@ infoBackupData(const InfoBackup *this, unsigned int backupDataIdx)
ASSERT(this != NULL);
FUNCTION_LOG_RETURN(INFO_BACKUP_DATA, *(InfoBackupData *)lstGet(this->backup, backupDataIdx));
}
/**********************************************************************************************************************************/
InfoBackupData *
infoBackupDataByLabel(const InfoBackup *this, const String *backupLabel)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(INFO_BACKUP, this);
FUNCTION_TEST_PARAM(STRING, backupLabel);
FUNCTION_TEST_END();
ASSERT(this != NULL);
ASSERT(backupLabel != NULL);
FUNCTION_TEST_RETURN(lstFind(this->backup, &backupLabel));
FUNCTION_LOG_RETURN(INFO_BACKUP_DATA, *(InfoBackupData *)lstGet(this->pub.backup, backupDataIdx));
}
/**********************************************************************************************************************************/
@ -402,7 +363,7 @@ infoBackupDataAdd(const InfoBackup *this, const Manifest *manifest)
}
}
MEM_CONTEXT_BEGIN(lstMemContext(this->backup))
MEM_CONTEXT_BEGIN(lstMemContext(this->pub.backup))
{
InfoBackupData infoBackupData =
{
@ -439,10 +400,10 @@ infoBackupDataAdd(const InfoBackup *this, const Manifest *manifest)
}
// Add the backup data to the current backup list
lstAdd(this->backup, &infoBackupData);
lstAdd(this->pub.backup, &infoBackupData);
// Ensure the list is sorted ascending by the backupLabel
lstSort(this->backup, sortOrderAsc);
lstSort(this->pub.backup, sortOrderAsc);
}
MEM_CONTEXT_END();
}
@ -467,7 +428,7 @@ infoBackupDataDelete(const InfoBackup *this, const String *backupDeleteLabel)
InfoBackupData backupData = infoBackupData(this, idx);
if (strCmp(backupData.backupLabel, backupDeleteLabel) == 0)
lstRemoveIdx(this->backup, idx);
lstRemoveIdx(this->pub.backup, idx);
}
FUNCTION_LOG_RETURN_VOID();
@ -541,19 +502,6 @@ infoBackupDataDependentList(const InfoBackup *this, const String *backupLabel)
FUNCTION_LOG_RETURN(STRING_LIST, result);
}
/**********************************************************************************************************************************/
const String *
infoBackupCipherPass(const InfoBackup *this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(INFO_BACKUP, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
FUNCTION_TEST_RETURN(infoPgCipherPass(this->infoPg));
}
/**********************************************************************************************************************************/
typedef struct InfoBackupLoadFileData
{
@ -716,14 +664,14 @@ infoBackupLoadFileReconstruct(const Storage *storage, const String *fileName, Ci
{
bool found = false;
const Manifest *manifest = manifestLoadFile(
storage, manifestFileName, cipherType, infoPgCipherPass(infoBackup->infoPg));
storage, manifestFileName, cipherType, infoPgCipherPass(infoBackupPg(infoBackup)));
const ManifestData *manData = manifestData(manifest);
// If the pg data for the manifest exists in the history, then add it to current, but if something doesn't match
// then warn that the backup is not valid
for (unsigned int pgIdx = 0; pgIdx < infoPgDataTotal(infoBackup->infoPg); pgIdx++)
for (unsigned int pgIdx = 0; pgIdx < infoPgDataTotal(infoBackupPg(infoBackup)); pgIdx++)
{
InfoPgData pgHistory = infoPgData(infoBackup->infoPg, pgIdx);
InfoPgData pgHistory = infoPgData(infoBackupPg(infoBackup), pgIdx);
// If there is an exact match with the history, system and version and there is no backup-prior dependency
// or there is a backup-prior and it is in the list, then add this backup to the current backup list

View File

@ -63,6 +63,53 @@ InfoBackup *infoBackupNew(unsigned int pgVersion, uint64_t pgSystemId, unsigned
// Create new object and load contents from IoRead
InfoBackup *infoBackupNewLoad(IoRead *read);
/***********************************************************************************************************************************
Getters/Setters
***********************************************************************************************************************************/
typedef struct InfoBackupPub
{
MemContext *memContext; // Mem context
InfoPg *infoPg; // Contents of the DB data
List *backup; // List of current backups and their associated data
} InfoBackupPub;
// PostgreSQL info
__attribute__((always_inline)) static inline InfoPg *
infoBackupPg(const InfoBackup *const this)
{
ASSERT_INLINE(this != NULL);
return ((InfoBackupPub *)this)->infoPg;
}
InfoBackup *infoBackupPgSet(InfoBackup *this, unsigned int pgVersion, uint64_t pgSystemId, unsigned int pgCatalogVersion);
// Cipher passphrase
__attribute__((always_inline)) static inline const String *
infoBackupCipherPass(const InfoBackup *const this)
{
return infoPgCipherPass(infoBackupPg(this));
}
// Return a structure of the backup data from a specific index
InfoBackupData infoBackupData(const InfoBackup *this, unsigned int backupDataIdx);
// Return a pointer to a structure from the current backup data given a label, else NULL
__attribute__((always_inline)) static inline InfoBackupData *
infoBackupDataByLabel(const InfoBackup *const this, const String *const backupLabel)
{
ASSERT_INLINE(this != NULL);
ASSERT_INLINE(backupLabel != NULL);
return lstFind(((InfoBackupPub *)this)->backup, &backupLabel);
}
// Get total current backups
__attribute__((always_inline)) static inline unsigned int
infoBackupDataTotal(const InfoBackup *const this)
{
ASSERT_INLINE(this != NULL);
return lstSize(((InfoBackupPub *)this)->backup);
}
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
@ -72,6 +119,12 @@ void infoBackupDataAdd(const InfoBackup *this, const Manifest *manifest);
// Delete backup from the current backup list
void infoBackupDataDelete(const InfoBackup *this, const String *backupDeleteLabel);
// Given a backup label, get the dependency list
StringList *infoBackupDataDependentList(const InfoBackup *this, const String *backupLabel);
// Return a list of current backup labels, applying a regex expression if provided
StringList *infoBackupDataLabelList(const InfoBackup *this, const String *expression);
// Move to a new parent mem context
__attribute__((always_inline)) static inline InfoBackup *
infoBackupMove(InfoBackup *this, MemContext *parentNew)
@ -79,31 +132,6 @@ infoBackupMove(InfoBackup *this, MemContext *parentNew)
return objMove(this, parentNew);
}
/***********************************************************************************************************************************
Getters/Setters
***********************************************************************************************************************************/
// Return a list of current backup labels, applying a regex expression if provided
StringList *infoBackupDataLabelList(const InfoBackup *this, const String *expression);
// PostgreSQL info
InfoPg *infoBackupPg(const InfoBackup *this);
InfoBackup *infoBackupPgSet(InfoBackup *this, unsigned int pgVersion, uint64_t pgSystemId, unsigned int pgCatalogVersion);
// Return a structure of the backup data from a specific index
InfoBackupData infoBackupData(const InfoBackup *this, unsigned int backupDataIdx);
// Return a pointer to a structure from the current backup data given a label, else NULL
InfoBackupData *infoBackupDataByLabel(const InfoBackup *this, const String *backupLabel);
// Given a backup label, get the dependency list
StringList *infoBackupDataDependentList(const InfoBackup *this, const String *backupLabel);
// Get total current backups
unsigned int infoBackupDataTotal(const InfoBackup *this);
// Cipher passphrase
const String *infoBackupCipherPass(const InfoBackup *this);
/***********************************************************************************************************************************
Destructor
***********************************************************************************************************************************/

View File

@ -41,10 +41,9 @@ Object type
***********************************************************************************************************************************/
struct InfoPg
{
InfoPgPub pub; // Publicly accessible variables
MemContext *memContext; // Mem context
Info *info; // Info contents
InfoPgType type; // Type of info file being loaded
List *history; // A list of InfoPgData
unsigned int historyCurrent; // Index of the current history item
};
@ -62,9 +61,12 @@ infoPgNewInternal(InfoPgType type)
*this = (InfoPg)
{
.pub =
{
.history = lstNewP(sizeof(InfoPgData)),
},
.memContext = memContextCurrent(),
.type = type,
.history = lstNewP(sizeof(InfoPgData)),
};
FUNCTION_TEST_RETURN(this);
@ -84,7 +86,7 @@ infoPgNew(InfoPgType type, const String *cipherPassSub)
MEM_CONTEXT_NEW_BEGIN("InfoPg")
{
this = infoPgNewInternal(type);
this->info = infoNew(cipherPassSub);
this->pub.info = infoNew(cipherPassSub);
}
MEM_CONTEXT_NEW_END();
@ -142,7 +144,7 @@ infoPgLoadCallback(void *data, const String *section, const String *key, const V
};
// Insert at beginning of list so the history is reverse ordered
lstInsert(loadData->infoPg->history, 0, &infoPgData);
lstInsert(loadData->infoPg->pub.history, 0, &infoPgData);
}
// Callback if set
else if (loadData->callbackFunction != NULL)
@ -182,18 +184,18 @@ infoPgNewLoad(IoRead *read, InfoPgType type, InfoLoadNewCallback *callbackFuncti
.infoPg = this,
};
this->info = infoNewLoad(read, infoPgLoadCallback, &loadData);
this->pub.info = infoNewLoad(read, infoPgLoadCallback, &loadData);
// History must include at least one item or the file is corrupt
CHECK(!lstEmpty(this->history));
CHECK(!lstEmpty(this->pub.history));
// If the current id was not found then the file is corrupt
CHECK(loadData.currentId > 0);
// Find the current history item
for (unsigned int historyIdx = 0; historyIdx < lstSize(this->history); historyIdx++)
for (unsigned int historyIdx = 0; historyIdx < lstSize(this->pub.history); historyIdx++)
{
if (((InfoPgData *)lstGet(this->history, historyIdx))->id == loadData.currentId)
if (((InfoPgData *)lstGet(this->pub.history, historyIdx))->id == loadData.currentId)
this->historyCurrent = historyIdx;
}
@ -217,7 +219,7 @@ infoPgAdd(InfoPg *this, const InfoPgData *infoPgData)
ASSERT(this != NULL);
ASSERT(infoPgData != NULL);
lstInsert(this->history, 0, infoPgData);
lstInsert(this->pub.history, 0, infoPgData);
this->historyCurrent = 0;
FUNCTION_LOG_RETURN_VOID();
@ -394,19 +396,6 @@ infoPgArchiveId(const InfoPg *this, unsigned int pgDataIdx)
FUNCTION_LOG_RETURN(STRING, strNewFmt("%s-%u", strZ(pgVersionToStr(pgData.version)), pgData.id));
}
/**********************************************************************************************************************************/
const String *
infoPgCipherPass(const InfoPg *this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(INFO_PG, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
FUNCTION_TEST_RETURN(infoCipherPass(this->info));
}
/**********************************************************************************************************************************/
InfoPgData
infoPgData(const InfoPg *this, unsigned int pgDataIdx)
@ -418,7 +407,7 @@ infoPgData(const InfoPg *this, unsigned int pgDataIdx)
ASSERT(this != NULL);
FUNCTION_LOG_RETURN(INFO_PG_DATA, *(InfoPgData *)lstGet(this->history, pgDataIdx));
FUNCTION_LOG_RETURN(INFO_PG_DATA, *(InfoPgData *)lstGet(this->pub.history, pgDataIdx));
}
/**********************************************************************************************************************************/
@ -447,32 +436,6 @@ infoPgDataCurrentId(const InfoPg *this)
FUNCTION_LOG_RETURN(UINT, this->historyCurrent);
}
/**********************************************************************************************************************************/
Info *
infoPgInfo(const InfoPg *this)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(INFO_PG, this);
FUNCTION_TEST_END();
ASSERT(this != NULL);
FUNCTION_TEST_RETURN(this->info);
}
/**********************************************************************************************************************************/
unsigned int
infoPgDataTotal(const InfoPg *this)
{
FUNCTION_LOG_BEGIN(logLevelTrace);
FUNCTION_LOG_PARAM(INFO_PG, this);
FUNCTION_LOG_END();
ASSERT(this != NULL);
FUNCTION_LOG_RETURN(UINT, lstSize(this->history));
}
/**********************************************************************************************************************************/
unsigned int
infoPgCurrentDataId(const InfoPg *this)

View File

@ -50,27 +50,32 @@ InfoPg *infoPgNew(InfoPgType type, const String *cipherPassSub);
// Create new object and load contents from a file
InfoPg *infoPgNewLoad(IoRead *read, InfoPgType type, InfoLoadNewCallback *callbackFunction, void *callbackData);
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
// Add Postgres data to the history list at position 0 to ensure the latest history is always first in the list
void infoPgAdd(InfoPg *this, const InfoPgData *infoPgData);
// Save to IO
void infoPgSave(InfoPg *this, IoWrite *write, InfoSaveCallback *callbackFunction, void *callbackData);
// Set the InfoPg object data based on values passed
InfoPg *infoPgSet(
InfoPg *this, InfoPgType type, const unsigned int pgVersion, const uint64_t pgSystemId, const unsigned int pgCatalogVersion);
/***********************************************************************************************************************************
Getters/Setters
***********************************************************************************************************************************/
typedef struct InfoPgPub
{
Info *info; // Info contents
List *history; // A list of InfoPgData
} InfoPgPub;
// Archive id
String *infoPgArchiveId(const InfoPg *this, unsigned int pgDataIdx);
// Base info
__attribute__((always_inline)) static inline Info *
infoPgInfo(const InfoPg *const this)
{
ASSERT_INLINE(this != NULL);
return ((InfoPgPub *)this)->info;
}
// Return the cipher passphrase
const String *infoPgCipherPass(const InfoPg *this);
__attribute__((always_inline)) static inline const String *
infoPgCipherPass(const InfoPg *const this)
{
return infoCipherPass(infoPgInfo(this));
}
// Return current pgId from the history
unsigned int infoPgCurrentDataId(const InfoPg *this);
@ -85,10 +90,25 @@ InfoPgData infoPgDataCurrent(const InfoPg *this);
unsigned int infoPgDataCurrentId(const InfoPg *this);
// Total PostgreSQL data in the history
unsigned int infoPgDataTotal(const InfoPg *this);
__attribute__((always_inline)) static inline unsigned int
infoPgDataTotal(const InfoPg *const this)
{
ASSERT_INLINE(this != NULL);
return lstSize(((InfoPgPub *)this)->history);
}
// Base info
Info *infoPgInfo(const InfoPg *this);
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
// Add Postgres data to the history list at position 0 to ensure the latest history is always first in the list
void infoPgAdd(InfoPg *this, const InfoPgData *infoPgData);
// Save to IO
void infoPgSave(InfoPg *this, IoWrite *write, InfoSaveCallback *callbackFunction, void *callbackData);
// Set the InfoPg object data based on values passed
InfoPg *infoPgSet(
InfoPg *this, InfoPgType type, const unsigned int pgVersion, const uint64_t pgSystemId, const unsigned int pgCatalogVersion);
/***********************************************************************************************************************************
Macros for function logging

File diff suppressed because it is too large Load Diff

View File

@ -33,6 +33,7 @@ typedef struct Manifest Manifest;
#include "common/crypto/hash.h"
#include "common/type/object.h"
#include "info/info.h"
#include "storage/storage.h"
/***********************************************************************************************************************************
@ -157,6 +158,47 @@ Manifest *manifestNewBuild(
// Load a manifest from IO
Manifest *manifestNewLoad(IoRead *read);
/***********************************************************************************************************************************
Getters/Setters
***********************************************************************************************************************************/
typedef struct ManifestPub
{
MemContext *memContext; // Mem context
Info *info; // Base info object
ManifestData data; // Manifest data and options
List *dbList; // List of databases
List *fileList; // List of files
List *linkList; // List of links
List *pathList; // List of paths
List *targetList; // List of targets
} ManifestPub;
// Get/set the cipher subpassphrase
__attribute__((always_inline)) static inline const String *
manifestCipherSubPass(const Manifest *const this)
{
ASSERT_INLINE(this != NULL);
return infoCipherPass(((const ManifestPub *)this)->info);
}
__attribute__((always_inline)) static inline void
manifestCipherSubPassSet(Manifest *const this, const String *const cipherSubPass)
{
ASSERT_INLINE(this != NULL);
infoCipherPassSet(((const ManifestPub *)this)->info, cipherSubPass);
}
// Get manifest configuration and options
__attribute__((always_inline)) static inline const ManifestData *
manifestData(const Manifest *const this)
{
ASSERT_INLINE(this != NULL);
return &(((const ManifestPub *)this)->data);
}
// Set backup label
void manifestBackupLabelSet(Manifest *this, const String *backupLabel);
/***********************************************************************************************************************************
Build functions
***********************************************************************************************************************************/
@ -195,20 +237,61 @@ void manifestValidate(Manifest *this, bool strict);
/***********************************************************************************************************************************
Db functions and getters/setters
***********************************************************************************************************************************/
const ManifestDb *manifestDb(const Manifest *this, unsigned int dbIdx);
__attribute__((always_inline)) static inline const ManifestDb *
manifestDb(const Manifest *const this, const unsigned int dbIdx)
{
ASSERT_INLINE(this != NULL);
return lstGet(((const ManifestPub *)this)->dbList, dbIdx);
}
const ManifestDb *manifestDbFind(const Manifest *this, const String *name);
const ManifestDb *manifestDbFindDefault(const Manifest *this, const String *name, const ManifestDb *dbDefault);
unsigned int manifestDbTotal(const Manifest *this);
// If the database requested is not found in the list, return the default passed rather than throw an error
__attribute__((always_inline)) static inline const ManifestDb *
manifestDbFindDefault(const Manifest *const this, const String *const name, const ManifestDb *const dbDefault)
{
ASSERT_INLINE(this != NULL);
ASSERT_INLINE(name != NULL);
return lstFindDefault(((const ManifestPub *)this)->dbList, &name, (void *)dbDefault);
}
__attribute__((always_inline)) static inline unsigned int
manifestDbTotal(const Manifest *const this)
{
ASSERT_INLINE(this != NULL);
return lstSize(((const ManifestPub *)this)->dbList);
}
/***********************************************************************************************************************************
File functions and getters/setters
***********************************************************************************************************************************/
const ManifestFile *manifestFile(const Manifest *this, unsigned int fileIdx);
__attribute__((always_inline)) static inline const ManifestFile *
manifestFile(const Manifest *const this, const unsigned int fileIdx)
{
ASSERT_INLINE(this != NULL);
return lstGet(((const ManifestPub *)this)->fileList, fileIdx);
}
void manifestFileAdd(Manifest *this, const ManifestFile *file);
const ManifestFile *manifestFileFind(const Manifest *this, const String *name);
const ManifestFile *manifestFileFindDefault(const Manifest *this, const String *name, const ManifestFile *fileDefault);
// If the file requested is not found in the list, return the default passed rather than throw an error
__attribute__((always_inline)) static inline const ManifestFile *
manifestFileFindDefault(const Manifest *const this, const String *const name, const ManifestFile *const fileDefault)
{
ASSERT_INLINE(this != NULL);
ASSERT_INLINE(name != NULL);
return lstFindDefault(((const ManifestPub *)this)->fileList, &name, (void *)fileDefault);
}
void manifestFileRemove(const Manifest *this, const String *name);
unsigned int manifestFileTotal(const Manifest *this);
__attribute__((always_inline)) static inline unsigned int
manifestFileTotal(const Manifest *const this)
{
ASSERT_INLINE(this != NULL);
return lstSize(((const ManifestPub *)this)->fileList);
}
// Update a file with new data
void manifestFileUpdate(
@ -218,55 +301,99 @@ void manifestFileUpdate(
/***********************************************************************************************************************************
Link functions and getters/setters
***********************************************************************************************************************************/
const ManifestLink *manifestLink(const Manifest *this, unsigned int linkIdx);
__attribute__((always_inline)) static inline const ManifestLink *
manifestLink(const Manifest *const this, const unsigned int linkIdx)
{
ASSERT_INLINE(this != NULL);
return lstGet(((const ManifestPub *)this)->linkList, linkIdx);
}
const ManifestLink *manifestLinkFind(const Manifest *this, const String *name);
const ManifestLink *manifestLinkFindDefault(const Manifest *this, const String *name, const ManifestLink *linkDefault);
// If the link requested is not found in the list, return the default passed rather than throw an error
__attribute__((always_inline)) static inline const ManifestLink *
manifestLinkFindDefault(const Manifest *const this, const String *const name, const ManifestLink *const linkDefault)
{
ASSERT_INLINE(this != NULL);
ASSERT_INLINE(name != NULL);
return lstFindDefault(((const ManifestPub *)this)->linkList, &name, (void *)linkDefault);
}
void manifestLinkRemove(const Manifest *this, const String *name);
unsigned int manifestLinkTotal(const Manifest *this);
__attribute__((always_inline)) static inline unsigned int
manifestLinkTotal(const Manifest *const this)
{
ASSERT_INLINE(this != NULL);
return lstSize(((const ManifestPub *)this)->linkList);
}
void manifestLinkUpdate(const Manifest *this, const String *name, const String *path);
/***********************************************************************************************************************************
Path functions and getters/setters
***********************************************************************************************************************************/
const ManifestPath *manifestPath(const Manifest *this, unsigned int pathIdx);
__attribute__((always_inline)) static inline const ManifestPath *
manifestPath(const Manifest *const this, const unsigned int pathIdx)
{
ASSERT_INLINE(this != NULL);
return lstGet(((const ManifestPub *)this)->pathList, pathIdx);
}
const ManifestPath *manifestPathFind(const Manifest *this, const String *name);
const ManifestPath *manifestPathFindDefault(const Manifest *this, const String *name, const ManifestPath *pathDefault);
// If the path requested is not found in the list, return the default passed rather than throw an error
__attribute__((always_inline)) static inline const ManifestPath *
manifestPathFindDefault(const Manifest *const this, const String *const name, const ManifestPath *const pathDefault)
{
ASSERT_INLINE(this != NULL);
ASSERT_INLINE(name != NULL);
return lstFindDefault(((const ManifestPub *)this)->pathList, &name, (void *)pathDefault);
}
// Data directory relative path for any manifest file/link/path/target name
String *manifestPathPg(const String *manifestPath);
unsigned int manifestPathTotal(const Manifest *this);
__attribute__((always_inline)) static inline unsigned int
manifestPathTotal(const Manifest *const this)
{
ASSERT_INLINE(this != NULL);
return lstSize(((const ManifestPub *)this)->pathList);
}
/***********************************************************************************************************************************
Target functions and getters/setters
***********************************************************************************************************************************/
const ManifestTarget *manifestTarget(const Manifest *this, unsigned int targetIdx);
// Base target, i.e. the target that is the data directory
const ManifestTarget *manifestTargetBase(const Manifest *this);
__attribute__((always_inline)) static inline const ManifestTarget *
manifestTarget(const Manifest *const this, const unsigned int targetIdx)
{
ASSERT_INLINE(this != NULL);
return lstGet(((const ManifestPub *)this)->targetList, targetIdx);
}
const ManifestTarget *manifestTargetFind(const Manifest *this, const String *name);
// Base target, i.e. the target that is the data directory
__attribute__((always_inline)) static inline const ManifestTarget *
manifestTargetBase(const Manifest *const this)
{
return manifestTargetFind(this, MANIFEST_TARGET_PGDATA_STR);
}
// Absolute path to the target
String *manifestTargetPath(const Manifest *this, const ManifestTarget *target);
void manifestTargetRemove(const Manifest *this, const String *name);
unsigned int manifestTargetTotal(const Manifest *this);
__attribute__((always_inline)) static inline unsigned int
manifestTargetTotal(const Manifest *const this)
{
ASSERT_INLINE(this != NULL);
return lstSize(((const ManifestPub *)this)->targetList);
}
void manifestTargetUpdate(const Manifest *this, const String *name, const String *path, const String *file);
/***********************************************************************************************************************************
Getters/Setters
***********************************************************************************************************************************/
// Get/set the cipher subpassphrase
const String *manifestCipherSubPass(const Manifest *this);
void manifestCipherSubPassSet(Manifest *this, const String *cipherSubPass);
// Get manifest configuration and options
const ManifestData *manifestData(const Manifest *this);
// Set backup label
void manifestBackupLabelSet(Manifest *this, const String *backupLabel);
/***********************************************************************************************************************************
Destructor
***********************************************************************************************************************************/

View File

@ -1288,10 +1288,10 @@ testRun(void)
TEST_TITLE("cannot resume when pgBackRest version has changed");
Manifest *manifestResume = manifestNewInternal();
manifestResume->info = infoNew(NULL);
manifestResume->data.backupType = backupTypeFull;
manifestResume->data.backupLabel = STRDEF("20191003-105320F");
manifestResume->data.pgVersion = PG_VERSION_12;
manifestResume->pub.info = infoNew(NULL);
manifestResume->pub.data.backupType = backupTypeFull;
manifestResume->pub.data.backupLabel = STRDEF("20191003-105320F");
manifestResume->pub.data.pgVersion = PG_VERSION_12;
manifestTargetAdd(manifestResume, &(ManifestTarget){.name = MANIFEST_TARGET_PGDATA_STR, .path = STRDEF("/pg")});
manifestPathAdd(manifestResume, &(ManifestPath){.name = MANIFEST_TARGET_PGDATA_STR});
@ -1304,8 +1304,8 @@ testRun(void)
storageRepoWrite(), STRDEF(STORAGE_REPO_BACKUP "/20191003-105320F/" BACKUP_MANIFEST_FILE INFO_COPY_EXT))));
Manifest *manifest = manifestNewInternal();
manifest->data.backupType = backupTypeFull;
manifest->data.backrestVersion = STRDEF("BOGUS");
manifest->pub.data.backupType = backupTypeFull;
manifest->pub.data.backrestVersion = STRDEF("BOGUS");
TEST_RESULT_PTR(backupResumeFind(manifest, NULL), NULL, "find resumable backup");
@ -1316,13 +1316,13 @@ testRun(void)
TEST_RESULT_BOOL(
storagePathExistsP(storageRepo(), STRDEF(STORAGE_REPO_BACKUP "/20191003-105320F")), false, "check backup path removed");
manifest->data.backrestVersion = STRDEF(PROJECT_VERSION);
manifest->pub.data.backrestVersion = STRDEF(PROJECT_VERSION);
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("cannot resume when backup labels do not match (resumable is null)");
manifest->data.backupType = backupTypeFull;
manifest->data.backupLabelPrior = STRDEF("20191003-105320F");
manifest->pub.data.backupType = backupTypeFull;
manifest->pub.data.backupLabelPrior = STRDEF("20191003-105320F");
manifestSave(
manifestResume,
@ -1339,13 +1339,13 @@ testRun(void)
TEST_RESULT_BOOL(
storagePathExistsP(storageRepo(), STRDEF(STORAGE_REPO_BACKUP "/20191003-105320F")), false, "check backup path removed");
manifest->data.backupLabelPrior = NULL;
manifest->pub.data.backupLabelPrior = NULL;
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("cannot resume when backup labels do not match (new is null)");
manifest->data.backupType = backupTypeFull;
manifestResume->data.backupLabelPrior = STRDEF("20191003-105320F");
manifest->pub.data.backupType = backupTypeFull;
manifestResume->pub.data.backupLabelPrior = STRDEF("20191003-105320F");
manifestSave(
manifestResume,
@ -1362,12 +1362,12 @@ testRun(void)
TEST_RESULT_BOOL(
storagePathExistsP(storageRepo(), STRDEF(STORAGE_REPO_BACKUP "/20191003-105320F")), false, "check backup path removed");
manifestResume->data.backupLabelPrior = NULL;
manifestResume->pub.data.backupLabelPrior = NULL;
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("cannot resume when compression does not match");
manifestResume->data.backupOptionCompressType = compressTypeGz;
manifestResume->pub.data.backupOptionCompressType = compressTypeGz;
manifestSave(
manifestResume,
@ -1384,7 +1384,7 @@ testRun(void)
TEST_RESULT_BOOL(
storagePathExistsP(storageRepo(), STRDEF(STORAGE_REPO_BACKUP "/20191003-105320F")), false, "check backup path removed");
manifestResume->data.backupOptionCompressType = compressTypeNone;
manifestResume->pub.data.backupOptionCompressType = compressTypeNone;
}
// *****************************************************************************************************************************

View File

@ -114,17 +114,17 @@ testManifestMinimal(const String *label, unsigned int pgVersion, const String *p
MEM_CONTEXT_NEW_BEGIN("Manifest")
{
result = manifestNewInternal();
result->info = infoNew(NULL);
result->pub.info = infoNew(NULL);
result->data.backupLabel = strDup(label);
result->data.pgVersion = pgVersion;
result->pub.data.backupLabel = strDup(label);
result->pub.data.pgVersion = pgVersion;
if (strEndsWithZ(label, "I"))
result->data.backupType = backupTypeIncr;
result->pub.data.backupType = backupTypeIncr;
else if (strEndsWithZ(label, "D"))
result->data.backupType = backupTypeDiff;
result->pub.data.backupType = backupTypeDiff;
else
result->data.backupType = backupTypeFull;
result->pub.data.backupType = backupTypeFull;
ManifestTarget targetBase = {.name = MANIFEST_TARGET_PGDATA_STR, .path = pgPath};
manifestTargetAdd(result, &targetBase);
@ -813,7 +813,7 @@ testRun(void)
"P00 INFO: map tablespace 'pg_tblspc/2' to '/2-3'");
// Remap all tablespaces with tablespace-map-all and update version to 9.2 to test warning
manifest->data.pgVersion = PG_VERSION_92;
manifest->pub.data.pgVersion = PG_VERSION_92;
argList = strLstNew();
strLstAddZ(argList, "--stanza=test1");
@ -1198,7 +1198,7 @@ testRun(void)
TEST_SYSTEM_FMT("rm -rf %s/*", strZ(pgPath));
manifest->data.pgVersion = PG_VERSION_12;
manifest->pub.data.pgVersion = PG_VERSION_12;
TEST_RESULT_VOID(restoreCleanBuild(manifest), "restore");
@ -1268,7 +1268,7 @@ testRun(void)
MEM_CONTEXT_NEW_BEGIN("Manifest")
{
manifest = manifestNewInternal();
manifest->data.pgVersion = PG_VERSION_84;
manifest->pub.data.pgVersion = PG_VERSION_84;
manifestTargetAdd(manifest, &(ManifestTarget){.name = MANIFEST_TARGET_PGDATA_STR, .path = STRDEF("/pg")});
manifestFileAdd(manifest, &(ManifestFile){.name = STRDEF(MANIFEST_TARGET_PGDATA "/" PG_FILE_PGVERSION)});
@ -1283,7 +1283,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("database id is missing on disk");
MEM_CONTEXT_BEGIN(manifest->memContext)
MEM_CONTEXT_BEGIN(manifest->pub.memContext)
{
// Give non-systemId to postgres db
manifestDbAdd(manifest, &(ManifestDb){.name = STRDEF("postgres"), .id = 16385, .lastSystemId = 12168});
@ -1307,7 +1307,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("all databases selected");
MEM_CONTEXT_BEGIN(manifest->memContext)
MEM_CONTEXT_BEGIN(manifest->pub.memContext)
{
manifestFileAdd(
manifest, &(ManifestFile){.name = STRDEF(MANIFEST_TARGET_PGDATA "/" PG_PATH_BASE "/16384/" PG_FILE_PGVERSION)});
@ -1373,7 +1373,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("select database by id");
MEM_CONTEXT_BEGIN(manifest->memContext)
MEM_CONTEXT_BEGIN(manifest->pub.memContext)
{
manifestDbAdd(manifest, &(ManifestDb){.name = STRDEF("test2"), .id = 32768, .lastSystemId = 12168});
manifestFileAdd(
@ -1394,7 +1394,7 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("one database selected without tablespace id");
MEM_CONTEXT_BEGIN(manifest->memContext)
MEM_CONTEXT_BEGIN(manifest->pub.memContext)
{
manifestTargetAdd(
manifest, &(ManifestTarget){
@ -1415,10 +1415,10 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("one database selected with tablespace id");
manifest->data.pgVersion = PG_VERSION_94;
manifest->data.pgCatalogVersion = pgCatalogTestVersion(PG_VERSION_94);
manifest->pub.data.pgVersion = PG_VERSION_94;
manifest->pub.data.pgCatalogVersion = pgCatalogTestVersion(PG_VERSION_94);
MEM_CONTEXT_BEGIN(manifest->memContext)
MEM_CONTEXT_BEGIN(manifest->pub.memContext)
{
manifestDbAdd(manifest, &(ManifestDb){.name = STRDEF("test3"), .id = 65536, .lastSystemId = 12168});
manifestFileAdd(
@ -1854,11 +1854,11 @@ testRun(void)
MEM_CONTEXT_NEW_BEGIN("Manifest")
{
manifest = manifestNewInternal();
manifest->info = infoNew(NULL);
manifest->data.backupLabel = strNew(TEST_LABEL);
manifest->data.pgVersion = PG_VERSION_84;
manifest->data.backupType = backupTypeFull;
manifest->data.backupTimestampCopyStart = 1482182861; // So file timestamps should be less than this
manifest->pub.info = infoNew(NULL);
manifest->pub.data.backupLabel = strNew(TEST_LABEL);
manifest->pub.data.pgVersion = PG_VERSION_84;
manifest->pub.data.backupType = backupTypeFull;
manifest->pub.data.backupTimestampCopyStart = 1482182861; // So file timestamps should be less than this
// Data directory
manifestTargetAdd(manifest, &(ManifestTarget){.name = MANIFEST_TARGET_PGDATA_STR, .path = pgPath});
@ -1916,10 +1916,10 @@ testRun(void)
.group = groupName(), .user = userName()});
// Always sort
lstSort(manifest->targetList, sortOrderAsc);
lstSort(manifest->fileList, sortOrderAsc);
lstSort(manifest->linkList, sortOrderAsc);
lstSort(manifest->pathList, sortOrderAsc);
lstSort(manifest->pub.targetList, sortOrderAsc);
lstSort(manifest->pub.fileList, sortOrderAsc);
lstSort(manifest->pub.linkList, sortOrderAsc);
lstSort(manifest->pub.pathList, sortOrderAsc);
}
MEM_CONTEXT_NEW_END();
@ -2034,7 +2034,7 @@ testRun(void)
symlink("/bogus", strZ(strNewFmt("%s/pg_tblspc/1", strZ(pgPath)))) == -1, FileOpenError,
"unable to create symlink");
MEM_CONTEXT_BEGIN(manifest->memContext)
MEM_CONTEXT_BEGIN(manifest->pub.memContext)
{
// tablespace_map (will be ignored during restore)
manifestFileAdd(
@ -2058,10 +2058,10 @@ testRun(void)
BUFSTRDEF(PG_VERSION_84_STR "\n"));
// Always sort
lstSort(manifest->targetList, sortOrderAsc);
lstSort(manifest->fileList, sortOrderAsc);
lstSort(manifest->linkList, sortOrderAsc);
lstSort(manifest->pathList, sortOrderAsc);
lstSort(manifest->pub.targetList, sortOrderAsc);
lstSort(manifest->pub.fileList, sortOrderAsc);
lstSort(manifest->pub.linkList, sortOrderAsc);
lstSort(manifest->pub.pathList, sortOrderAsc);
}
MEM_CONTEXT_END();
@ -2197,12 +2197,12 @@ testRun(void)
MEM_CONTEXT_NEW_BEGIN("Manifest")
{
manifest = manifestNewInternal();
manifest->info = infoNew(NULL);
manifest->data.backupLabel = strNew(TEST_LABEL);
manifest->data.pgVersion = PG_VERSION_10;
manifest->data.pgCatalogVersion = pgCatalogTestVersion(PG_VERSION_10);
manifest->data.backupType = backupTypeFull;
manifest->data.backupTimestampCopyStart = 1482182861; // So file timestamps should be less than this
manifest->pub.info = infoNew(NULL);
manifest->pub.data.backupLabel = strNew(TEST_LABEL);
manifest->pub.data.pgVersion = PG_VERSION_10;
manifest->pub.data.pgCatalogVersion = pgCatalogTestVersion(PG_VERSION_10);
manifest->pub.data.backupType = backupTypeFull;
manifest->pub.data.backupTimestampCopyStart = 1482182861; // So file timestamps should be less than this
// Data directory
manifestTargetAdd(manifest, &(ManifestTarget){.name = MANIFEST_TARGET_PGDATA_STR, .path = pgPath});
@ -2431,10 +2431,10 @@ testRun(void)
.destination = strNewFmt("%s/ts/1", testPath()), .group = groupName(), .user = userName()});
// Always sort
lstSort(manifest->targetList, sortOrderAsc);
lstSort(manifest->fileList, sortOrderAsc);
lstSort(manifest->linkList, sortOrderAsc);
lstSort(manifest->pathList, sortOrderAsc);
lstSort(manifest->pub.targetList, sortOrderAsc);
lstSort(manifest->pub.fileList, sortOrderAsc);
lstSort(manifest->pub.linkList, sortOrderAsc);
lstSort(manifest->pub.pathList, sortOrderAsc);
}
MEM_CONTEXT_NEW_END();

View File

@ -44,7 +44,7 @@ testRun(void)
MEM_CONTEXT_TEMP_END();
TEST_RESULT_STR_Z(infoArchiveId(info), "9.4-1", " archiveId set");
TEST_RESULT_PTR(infoArchivePg(info), info->infoPg, " infoPg set");
TEST_RESULT_PTR(infoArchivePg(info), info->pub.infoPg, " infoPg set");
TEST_RESULT_STR(infoArchiveCipherPass(info), NULL, " no cipher sub");
// Save info and verify
@ -58,9 +58,9 @@ testRun(void)
TEST_ASSIGN(
info, infoArchiveNew(PG_VERSION_94, 6569239123849665679, NULL), "infoArchiveNew() - no sub cipher");
TEST_RESULT_STR_Z(infoArchiveId(info), "9.4-1", " archiveId set");
TEST_RESULT_PTR(infoArchivePg(info), info->infoPg, " infoPg set");
TEST_RESULT_PTR(infoArchivePg(info), info->pub.infoPg, " infoPg set");
TEST_RESULT_STR(infoArchiveCipherPass(info), NULL, " no cipher sub");
TEST_RESULT_INT(infoPgDataTotal(info->infoPg), 1, " history set");
TEST_RESULT_INT(infoPgDataTotal(infoArchivePg(info)), 1, " history set");
Buffer *contentCompare = bufNew(0);
@ -81,16 +81,16 @@ testRun(void)
TEST_ASSIGN(info, infoArchiveNewLoad(ioBufferReadNew(contentSave)), " load encrypted archive info");
TEST_RESULT_STR_Z(infoArchiveId(info), "10-1", " archiveId set");
TEST_RESULT_PTR(infoArchivePg(info), info->infoPg, " infoPg set");
TEST_RESULT_PTR(infoArchivePg(info), infoArchivePg(info), " infoPg set");
TEST_RESULT_STR_Z(infoArchiveCipherPass(info),
"zWa/6Xtp-IVZC5444yXB+cgFDFl7MxGlgkZSaoPvTGirhPygu4jOKOXf9LO4vjfO", " cipher sub set");
TEST_RESULT_INT(infoPgDataTotal(info->infoPg), 1, " history set");
TEST_RESULT_INT(infoPgDataTotal(infoArchivePg(info)), 1, " history set");
// -------------------------------------------------------------------------------------------------------------------------
InfoPgData infoPgData = {0};
TEST_RESULT_VOID(infoArchivePgSet(info, PG_VERSION_94, 6569239123849665679), "add another infoPg");
TEST_RESULT_INT(infoPgDataTotal(info->infoPg), 2, " history incremented");
TEST_ASSIGN(infoPgData, infoPgDataCurrent(info->infoPg), " get current infoPgData");
TEST_RESULT_INT(infoPgDataTotal(infoArchivePg(info)), 2, " history incremented");
TEST_ASSIGN(infoPgData, infoPgDataCurrent(infoArchivePg(info)), " get current infoPgData");
TEST_RESULT_INT(infoPgData.version, PG_VERSION_94, " version set");
TEST_RESULT_UINT(infoPgData.systemId, 6569239123849665679, " systemId set");
@ -143,10 +143,10 @@ testRun(void)
infoArchiveSaveFile(infoArchive, storageTest, STRDEF(INFO_ARCHIVE_FILE), cipherTypeNone, NULL), "save archive info");
TEST_ASSIGN(infoArchive, infoArchiveLoadFile(storageTest, STRDEF(INFO_ARCHIVE_FILE), cipherTypeNone, NULL), "load main");
TEST_RESULT_UINT(infoPgDataCurrent(infoArchive->infoPg).systemId, 6569239123849665999, " check file loaded");
TEST_RESULT_UINT(infoPgDataCurrent(infoArchivePg(infoArchive)).systemId, 6569239123849665999, " check file loaded");
storageRemoveP(storageTest, STRDEF(INFO_ARCHIVE_FILE), .errorOnMissing = true);
TEST_ASSIGN(infoArchive, infoArchiveLoadFile(storageTest, STRDEF(INFO_ARCHIVE_FILE), cipherTypeNone, NULL), "load copy");
TEST_RESULT_UINT(infoPgDataCurrent(infoArchive->infoPg).systemId, 6569239123849665999, " check file loaded");
TEST_RESULT_UINT(infoPgDataCurrent(infoArchivePg(infoArchive)).systemId, 6569239123849665999, " check file loaded");
}
}

View File

@ -65,7 +65,7 @@ testRun(void)
TEST_RESULT_STR(strNewBuf(contentCompare), strNewBuf(contentSave), " check save");
TEST_ASSIGN(infoBackup, infoBackupNewLoad(ioBufferReadNew(contentCompare)), "load backup info");
TEST_RESULT_PTR(infoBackupPg(infoBackup), infoBackup->infoPg, " infoPg set");
TEST_RESULT_PTR(infoBackupPg(infoBackup), infoBackup->pub.infoPg, " infoPg set");
TEST_RESULT_STR(infoBackupCipherPass(infoBackup), NULL, " cipher sub not set");
TEST_RESULT_INT(infoBackupDataTotal(infoBackup), 0, " infoBackupDataTotal returns 0");
@ -84,10 +84,10 @@ testRun(void)
infoBackup = NULL;
TEST_ASSIGN(infoBackup, infoBackupNewLoad(ioBufferReadNew(contentSave)), " load backup info with cipher sub");
TEST_RESULT_PTR(infoBackupPg(infoBackup), infoBackup->infoPg, " infoPg set");
TEST_RESULT_PTR(infoBackupPg(infoBackup), infoBackupPg(infoBackup), " infoPg set");
TEST_RESULT_STR_Z(infoBackupCipherPass(infoBackup),
"zWa/6Xtp-IVZC5444yXB+cgFDFl7MxGlgkZSaoPvTGirhPygu4jOKOXf9LO4vjfO", " cipher sub set");
TEST_RESULT_INT(infoPgDataTotal(infoBackup->infoPg), 1, " history set");
TEST_RESULT_INT(infoPgDataTotal(infoBackupPg(infoBackup)), 1, " history set");
// Add pg info
// -------------------------------------------------------------------------------------------------------------------------
@ -95,8 +95,8 @@ testRun(void)
TEST_RESULT_VOID(
infoBackupPgSet(infoBackup, PG_VERSION_94, 6569239123849665679, pgCatalogTestVersion(PG_VERSION_94)),
"add another infoPg");
TEST_RESULT_INT(infoPgDataTotal(infoBackup->infoPg), 2, " history incremented");
TEST_ASSIGN(infoPgData, infoPgDataCurrent(infoBackup->infoPg), " get current infoPgData");
TEST_RESULT_INT(infoPgDataTotal(infoBackupPg(infoBackup)), 2, " history incremented");
TEST_ASSIGN(infoPgData, infoPgDataCurrent(infoBackupPg(infoBackup)), " get current infoPgData");
TEST_RESULT_INT(infoPgData.version, PG_VERSION_94, " version set");
TEST_RESULT_UINT(infoPgData.systemId, 6569239123849665679, " systemId set");
TEST_RESULT_UINT(infoPgData.catalogVersion, 201409291, " catalogVersion set");
@ -709,7 +709,7 @@ testRun(void)
infoBackup, infoBackupLoadFile(storageRepo(), INFO_BACKUP_PATH_FILE_STR, cipherTypeNone, NULL),
"get saved backup info");
TEST_RESULT_INT(infoBackupDataTotal(infoBackup), 2, "backup list contains backups to be removed");
TEST_RESULT_INT(infoPgDataTotal(infoBackup->infoPg), 2, "multiple DB history");
TEST_RESULT_INT(infoPgDataTotal(infoBackupPg(infoBackup)), 2, "multiple DB history");
TEST_ASSIGN(
infoBackup, infoBackupLoadFileReconstruct(storageRepo(), INFO_BACKUP_PATH_FILE_STR, cipherTypeNone, NULL),
@ -833,11 +833,11 @@ testRun(void)
infoBackupSaveFile(infoBackup, storageTest, STRDEF(INFO_BACKUP_FILE), cipherTypeNone, NULL), "save backup info");
TEST_ASSIGN(infoBackup, infoBackupLoadFile(storageTest, STRDEF(INFO_BACKUP_FILE), cipherTypeNone, NULL), "load main");
TEST_RESULT_UINT(infoPgDataCurrent(infoBackup->infoPg).systemId, 6569239123849665999, " check file loaded");
TEST_RESULT_UINT(infoPgDataCurrent(infoBackupPg(infoBackup)).systemId, 6569239123849665999, " check file loaded");
storageRemoveP(storageTest, STRDEF(INFO_BACKUP_FILE), .errorOnMissing = true);
TEST_ASSIGN(infoBackup, infoBackupLoadFile(storageTest, STRDEF(INFO_BACKUP_FILE), cipherTypeNone, NULL), "load copy");
TEST_RESULT_UINT(infoPgDataCurrent(infoBackup->infoPg).systemId, 6569239123849665999, " check file loaded");
TEST_RESULT_UINT(infoPgDataCurrent(infoBackupPg(infoBackup)).systemId, 6569239123849665999, " check file loaded");
}
// *****************************************************************************************************************************

View File

@ -124,7 +124,7 @@ testRun(void)
"[db:backup] key=\"value\"\n"
"[later] key=\"value\"\n",
" check callback content");
TEST_RESULT_INT(lstSize(infoPg->history), 1, " history record added");
TEST_RESULT_INT(lstSize(infoPg->pub.history), 1, " history record added");
InfoPgData pgData = infoPgDataCurrent(infoPg);
TEST_RESULT_INT(pgData.id, 1, " id set");

View File

@ -1205,33 +1205,33 @@ testRun(void)
TEST_TITLE("don't check for delta if already enabled and test online timestamp");
Manifest *manifest = manifestNewInternal();
manifest->data.backupOptionOnline = true;
manifest->pub.data.backupOptionOnline = true;
TEST_RESULT_VOID(manifestBuildValidate(manifest, true, 1482182860, false), "validate manifest");
TEST_RESULT_INT(manifest->data.backupTimestampCopyStart, 1482182861, "check copy start");
TEST_RESULT_BOOL(varBool(manifest->data.backupOptionDelta), true, "check delta");
TEST_RESULT_UINT(manifest->data.backupOptionCompressType, compressTypeNone, "check compress");
TEST_RESULT_INT(manifest->pub.data.backupTimestampCopyStart, 1482182861, "check copy start");
TEST_RESULT_BOOL(varBool(manifest->pub.data.backupOptionDelta), true, "check delta");
TEST_RESULT_UINT(manifest->pub.data.backupOptionCompressType, compressTypeNone, "check compress");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("timestamp in past does not force delta");
manifest->data.backupOptionOnline = false;
manifest->pub.data.backupOptionOnline = false;
manifestFileAdd(
manifest,
&(ManifestFile){.name = STRDEF(MANIFEST_TARGET_PGDATA "/" PG_FILE_PGVERSION), .size = 4, .timestamp = 1482182860});
TEST_RESULT_VOID(manifestBuildValidate(manifest, false, 1482182860, false), "validate manifest");
TEST_RESULT_INT(manifest->data.backupTimestampCopyStart, 1482182860, "check copy start");
TEST_RESULT_BOOL(varBool(manifest->data.backupOptionDelta), false, "check delta");
TEST_RESULT_INT(manifest->pub.data.backupTimestampCopyStart, 1482182860, "check copy start");
TEST_RESULT_BOOL(varBool(manifest->pub.data.backupOptionDelta), false, "check delta");
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("timestamp in future forces delta");
TEST_RESULT_VOID(manifestBuildValidate(manifest, false, 1482182859, compressTypeGz), "validate manifest");
TEST_RESULT_INT(manifest->data.backupTimestampCopyStart, 1482182859, "check copy start");
TEST_RESULT_BOOL(varBool(manifest->data.backupOptionDelta), true, "check delta");
TEST_RESULT_UINT(manifest->data.backupOptionCompressType, compressTypeGz, "check compress");
TEST_RESULT_INT(manifest->pub.data.backupTimestampCopyStart, 1482182859, "check copy start");
TEST_RESULT_BOOL(varBool(manifest->pub.data.backupOptionDelta), true, "check delta");
TEST_RESULT_UINT(manifest->pub.data.backupOptionCompressType, compressTypeGz, "check compress");
TEST_RESULT_LOG("P00 WARN: file 'PG_VERSION' has timestamp in the future, enabling delta checksum");
}
@ -1284,10 +1284,10 @@ testRun(void)
TEST_TITLE("delta disabled and not enabled during validation");
Manifest *manifest = manifestNewInternal();
manifest->info = infoNew(NULL);
manifest->data.pgVersion = PG_VERSION_96;
manifest->data.pgCatalogVersion = pgCatalogTestVersion(PG_VERSION_96);
manifest->data.backupOptionDelta = BOOL_FALSE_VAR;
manifest->pub.info = infoNew(NULL);
manifest->pub.data.pgVersion = PG_VERSION_96;
manifest->pub.data.pgCatalogVersion = pgCatalogTestVersion(PG_VERSION_96);
manifest->pub.data.backupOptionDelta = BOOL_FALSE_VAR;
manifestTargetAdd(manifest, &(ManifestTarget){.name = MANIFEST_TARGET_PGDATA_STR, .path = STRDEF("/pg")});
manifestPathAdd(
@ -1315,7 +1315,7 @@ testRun(void)
.mode = 0600, .group = STRDEF("test"), .user = STRDEF("test")});
Manifest *manifestPrior = manifestNewInternal();
manifestPrior->data.backupLabel = strNew("20190101-010101F");
manifestPrior->pub.data.backupLabel = strNew("20190101-010101F");
manifestFileAdd(
manifestPrior,
&(ManifestFile){
@ -1362,8 +1362,8 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("delta enabled before validation");
manifest->data.backupOptionDelta = BOOL_TRUE_VAR;
lstClear(manifest->fileList);
manifest->pub.data.backupOptionDelta = BOOL_TRUE_VAR;
lstClear(manifest->pub.fileList);
manifestFileAdd(
manifest,
&(ManifestFile){
@ -1412,8 +1412,8 @@ testRun(void)
TEST_TITLE("delta enabled by timestamp validation and copy checksum error");
// Clear manifest and add a single file
manifest->data.backupOptionDelta = BOOL_FALSE_VAR;
lstClear(manifest->fileList);
manifest->pub.data.backupOptionDelta = BOOL_FALSE_VAR;
lstClear(manifest->pub.fileList);
manifestFileAdd(
manifest,
@ -1422,7 +1422,7 @@ testRun(void)
.mode = 0600, .group = STRDEF("test"), .user = STRDEF("test")});
// Clear prior manifest and add a single file with later timestamp and checksum error
lstClear(manifestPrior->fileList);
lstClear(manifestPrior->pub.fileList);
VariantList *checksumPageErrorList = varLstNew();
varLstAdd(checksumPageErrorList, varNewUInt(77));
@ -1464,8 +1464,8 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("delta enabled by size validation");
manifest->data.backupOptionDelta = BOOL_FALSE_VAR;
lstClear(manifest->fileList);
manifest->pub.data.backupOptionDelta = BOOL_FALSE_VAR;
lstClear(manifest->pub.fileList);
manifestFileAdd(
manifest,
&(ManifestFile){
@ -1515,8 +1515,8 @@ testRun(void)
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("delta enabled by timeline change");
manifestPrior->data.archiveStop = STRDEF("000000030000000300000003");
manifest->data.backupOptionDelta = BOOL_FALSE_VAR;
manifestPrior->pub.data.archiveStop = STRDEF("000000030000000300000003");
manifest->pub.data.backupOptionDelta = BOOL_FALSE_VAR;
TEST_RESULT_VOID(
manifestBuildIncr(manifest, manifestPrior, backupTypeIncr, STRDEF("000000040000000400000004")), "incremental manifest");
@ -1525,22 +1525,22 @@ testRun(void)
"P00 WARN: a timeline switch has occurred since the 20190101-010101F backup, enabling delta checksum\n"
" HINT: this is normal after restoring from backup or promoting a standby.");
TEST_RESULT_BOOL(varBool(manifest->data.backupOptionDelta), true, "check delta is enabled");
TEST_RESULT_BOOL(varBool(manifest->pub.data.backupOptionDelta), true, "check delta is enabled");
manifest->data.backupOptionDelta = BOOL_FALSE_VAR;
manifest->pub.data.backupOptionDelta = BOOL_FALSE_VAR;
// -------------------------------------------------------------------------------------------------------------------------
TEST_TITLE("delta enabled by online option change");
manifest->data.backupOptionOnline = BOOL_FALSE_VAR;
lstClear(manifest->fileList);
manifest->pub.data.backupOptionOnline = BOOL_FALSE_VAR;
lstClear(manifest->pub.fileList);
manifestFileAdd(
manifest,
&(ManifestFile){
.name = STRDEF(MANIFEST_TARGET_PGDATA "/FILE1"), .size = 6, .sizeRepo = 6, .timestamp = 1482182861,
.mode = 0600, .group = STRDEF("test"), .user = STRDEF("test")});
manifest->data.backupOptionOnline = BOOL_TRUE_VAR;
manifest->pub.data.backupOptionOnline = BOOL_TRUE_VAR;
manifestFileAdd(
manifestPrior,
&(ManifestFile){