mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-04-23 11:58:50 +02:00
Update lockStopTest() to optionally return a result rather than error.
Some commands (e.g. stanza-delete) would prefer to throw a customized error. Contributed by Cynthia Shang.
This commit is contained in:
parent
27b3246e85
commit
a2dcdc0711
@ -33,6 +33,14 @@
|
|||||||
|
|
||||||
<p>Add Perl interface to C storage layer.</p>
|
<p>Add Perl interface to C storage layer.</p>
|
||||||
</release-item>
|
</release-item>
|
||||||
|
|
||||||
|
<release-item>
|
||||||
|
<release-item-contributor-list>
|
||||||
|
<release-item-contributor id="cynthia.shang"/>
|
||||||
|
</release-item-contributor-list>
|
||||||
|
|
||||||
|
<p>Update <code>lockStopTest()</code> to optionally return a result rather than error.</p>
|
||||||
|
</release-item>
|
||||||
</release-development-list>
|
</release-development-list>
|
||||||
</release-core-list>
|
</release-core-list>
|
||||||
</release>
|
</release>
|
||||||
|
@ -136,7 +136,7 @@ archiveGetFile(
|
|||||||
bool compressible = true;
|
bool compressible = true;
|
||||||
|
|
||||||
// Test for stop file
|
// Test for stop file
|
||||||
lockStopTest();
|
lockStopTest(false);
|
||||||
|
|
||||||
MEM_CONTEXT_TEMP_BEGIN()
|
MEM_CONTEXT_TEMP_BEGIN()
|
||||||
{
|
{
|
||||||
|
@ -266,7 +266,7 @@ cmdArchivePush(void)
|
|||||||
THROW(ParamRequiredError, "WAL segment to push required");
|
THROW(ParamRequiredError, "WAL segment to push required");
|
||||||
|
|
||||||
// Test for stop file
|
// Test for stop file
|
||||||
lockStopTest();
|
lockStopTest(false);
|
||||||
|
|
||||||
// Get the segment name
|
// Get the segment name
|
||||||
String *walFile = walPath(strLstGet(commandParam, 0), cfgOptionStr(cfgOptPgPath), STR(cfgCommandName(cfgCommand())));
|
String *walFile = walPath(strLstGet(commandParam, 0), cfgOptionStr(cfgOptPgPath), STR(cfgCommandName(cfgCommand())));
|
||||||
@ -404,7 +404,7 @@ cmdArchivePushAsync(void)
|
|||||||
TRY_BEGIN()
|
TRY_BEGIN()
|
||||||
{
|
{
|
||||||
// Test for stop file
|
// Test for stop file
|
||||||
lockStopTest();
|
lockStopTest(false);
|
||||||
|
|
||||||
// Get a list of WAL files that are ready for processing
|
// Get a list of WAL files that are ready for processing
|
||||||
StringList *walFileList = archivePushProcessList(walPath);
|
StringList *walFileList = archivePushProcessList(walPath);
|
||||||
|
@ -26,25 +26,32 @@ lockStopFileName(const String *stanza)
|
|||||||
/***********************************************************************************************************************************
|
/***********************************************************************************************************************************
|
||||||
Test for the existence of a stop file
|
Test for the existence of a stop file
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
void
|
bool
|
||||||
lockStopTest(void)
|
lockStopTest(bool expectStanzaStop)
|
||||||
{
|
{
|
||||||
FUNCTION_LOG_VOID(logLevelDebug);
|
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||||
|
FUNCTION_LOG_PARAM(BOOL, expectStanzaStop);
|
||||||
|
FUNCTION_LOG_END();
|
||||||
|
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
MEM_CONTEXT_TEMP_BEGIN()
|
MEM_CONTEXT_TEMP_BEGIN()
|
||||||
{
|
{
|
||||||
// Check the current stanza (if any)
|
// Check the current stanza (if any)
|
||||||
if (cfgOptionTest(cfgOptStanza))
|
if (cfgOptionTest(cfgOptStanza))
|
||||||
{
|
{
|
||||||
if (storageExistsNP(storageLocal(), lockStopFileName(cfgOptionStr(cfgOptStanza))))
|
result = storageExistsNP(storageLocal(), lockStopFileName(cfgOptionStr(cfgOptStanza)));
|
||||||
|
|
||||||
|
// If the stop file exists and is not expected then error
|
||||||
|
if (result && !expectStanzaStop)
|
||||||
THROW_FMT(StopError, "stop file exists for stanza %s", strPtr(cfgOptionStr(cfgOptStanza)));
|
THROW_FMT(StopError, "stop file exists for stanza %s", strPtr(cfgOptionStr(cfgOptStanza)));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check all stanzas
|
// If not looking for a specific stanza stop file, then check all stanzas
|
||||||
if (storageExistsNP(storageLocal(), lockStopFileName(NULL)))
|
if (!expectStanzaStop && storageExistsNP(storageLocal(), lockStopFileName(NULL)))
|
||||||
THROW(StopError, "stop file exists for all stanzas");
|
THROW(StopError, "stop file exists for all stanzas");
|
||||||
}
|
}
|
||||||
MEM_CONTEXT_TEMP_END();
|
MEM_CONTEXT_TEMP_END();
|
||||||
|
|
||||||
FUNCTION_LOG_RETURN_VOID();
|
FUNCTION_LOG_RETURN(BOOL, result);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,6 @@ Command Control
|
|||||||
Functions
|
Functions
|
||||||
***********************************************************************************************************************************/
|
***********************************************************************************************************************************/
|
||||||
String *lockStopFileName(const String *stanza);
|
String *lockStopFileName(const String *stanza);
|
||||||
void lockStopTest(void);
|
bool lockStopTest(bool expectStanzaStop);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -40,7 +40,7 @@ testRun(void)
|
|||||||
strLstAddZ(argList, "start");
|
strLstAddZ(argList, "start");
|
||||||
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
|
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
|
||||||
|
|
||||||
TEST_RESULT_VOID(lockStopTest(), "no stop files without stanza");
|
TEST_RESULT_VOID(lockStopTest(false), "no stop files without stanza");
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
argList = strLstNew();
|
argList = strLstNew();
|
||||||
@ -50,13 +50,16 @@ testRun(void)
|
|||||||
strLstAddZ(argList, "start");
|
strLstAddZ(argList, "start");
|
||||||
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
|
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
|
||||||
|
|
||||||
TEST_RESULT_VOID(lockStopTest(), "no stop files with stanza");
|
TEST_RESULT_VOID(lockStopTest(false), "no stop files with stanza");
|
||||||
|
TEST_RESULT_BOOL(lockStopTest(true), false, "no stop file and is expected for the stanza");
|
||||||
|
|
||||||
storagePutNP(storageNewWriteNP(storageTest, strNew("all.stop")), NULL);
|
storagePutNP(storageNewWriteNP(storageTest, strNew("all.stop")), NULL);
|
||||||
TEST_ERROR(lockStopTest(), StopError, "stop file exists for all stanzas");
|
TEST_ERROR(lockStopTest(false), StopError, "stop file exists for all stanzas");
|
||||||
|
TEST_RESULT_BOOL(lockStopTest(true), false, "stop file exists for all stanzas but not the stanza");
|
||||||
|
|
||||||
storagePutNP(storageNewWriteNP(storageTest, strNew("db.stop")), NULL);
|
storagePutNP(storageNewWriteNP(storageTest, strNew("db.stop")), NULL);
|
||||||
TEST_ERROR(lockStopTest(), StopError, "stop file exists for stanza db");
|
TEST_ERROR(lockStopTest(false), StopError, "stop file exists for stanza db");
|
||||||
|
TEST_RESULT_BOOL(lockStopTest(true), true, "stop file exists and is expected for the stanza");
|
||||||
}
|
}
|
||||||
|
|
||||||
FUNCTION_HARNESS_RESULT_VOID();
|
FUNCTION_HARNESS_RESULT_VOID();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user