1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2024-12-12 10:04:14 +02:00
It is simpler to implement the required logic in stanza-delete rather than add complexity to this function.

Contributed by Cynthia Shang.
This commit is contained in:
Cynthia Shang 2019-07-10 12:04:25 -04:00 committed by David Steele
parent 04646599a7
commit 6a89c1526e
6 changed files with 15 additions and 33 deletions

View File

@ -33,14 +33,6 @@
<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>

View File

@ -136,7 +136,7 @@ archiveGetFile(
bool compressible = true; bool compressible = true;
// Test for stop file // Test for stop file
lockStopTest(false); lockStopTest();
MEM_CONTEXT_TEMP_BEGIN() MEM_CONTEXT_TEMP_BEGIN()
{ {

View File

@ -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(false); lockStopTest();
// 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(false); lockStopTest();
// 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);

View File

@ -26,32 +26,25 @@ lockStopFileName(const String *stanza)
/*********************************************************************************************************************************** /***********************************************************************************************************************************
Test for the existence of a stop file Test for the existence of a stop file
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
bool void
lockStopTest(bool expectStanzaStop) lockStopTest(void)
{ {
FUNCTION_LOG_BEGIN(logLevelDebug); FUNCTION_LOG_VOID(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))
{ {
result = storageExistsNP(storageLocal(), lockStopFileName(cfgOptionStr(cfgOptStanza))); if (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)));
} }
// If not looking for a specific stanza stop file, then check all stanzas // Check all stanzas
if (!expectStanzaStop && storageExistsNP(storageLocal(), lockStopFileName(NULL))) if (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(BOOL, result); FUNCTION_LOG_RETURN_VOID();
} }

View File

@ -10,6 +10,6 @@ Command Control
Functions Functions
***********************************************************************************************************************************/ ***********************************************************************************************************************************/
String *lockStopFileName(const String *stanza); String *lockStopFileName(const String *stanza);
bool lockStopTest(bool expectStanzaStop); void lockStopTest(void);
#endif #endif

View File

@ -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(false), "no stop files without stanza"); TEST_RESULT_VOID(lockStopTest(), "no stop files without stanza");
// ------------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------------
argList = strLstNew(); argList = strLstNew();
@ -50,16 +50,13 @@ testRun(void)
strLstAddZ(argList, "start"); strLstAddZ(argList, "start");
harnessCfgLoad(strLstSize(argList), strLstPtr(argList)); harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
TEST_RESULT_VOID(lockStopTest(false), "no stop files with stanza"); TEST_RESULT_VOID(lockStopTest(), "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(false), StopError, "stop file exists for all stanzas"); TEST_ERROR(lockStopTest(), 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(false), StopError, "stop file exists for stanza db"); TEST_ERROR(lockStopTest(), 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();