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>
</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-core-list>
</release>

View File

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

View File

@ -266,7 +266,7 @@ cmdArchivePush(void)
THROW(ParamRequiredError, "WAL segment to push required");
// Test for stop file
lockStopTest(false);
lockStopTest();
// Get the segment name
String *walFile = walPath(strLstGet(commandParam, 0), cfgOptionStr(cfgOptPgPath), STR(cfgCommandName(cfgCommand())));
@ -404,7 +404,7 @@ cmdArchivePushAsync(void)
TRY_BEGIN()
{
// Test for stop file
lockStopTest(false);
lockStopTest();
// Get a list of WAL files that are ready for processing
StringList *walFileList = archivePushProcessList(walPath);

View File

@ -26,32 +26,25 @@ lockStopFileName(const String *stanza)
/***********************************************************************************************************************************
Test for the existence of a stop file
***********************************************************************************************************************************/
bool
lockStopTest(bool expectStanzaStop)
void
lockStopTest(void)
{
FUNCTION_LOG_BEGIN(logLevelDebug);
FUNCTION_LOG_PARAM(BOOL, expectStanzaStop);
FUNCTION_LOG_END();
bool result = false;
FUNCTION_LOG_VOID(logLevelDebug);
MEM_CONTEXT_TEMP_BEGIN()
{
// Check the current stanza (if any)
if (cfgOptionTest(cfgOptStanza))
{
result = storageExistsNP(storageLocal(), lockStopFileName(cfgOptionStr(cfgOptStanza)));
// If the stop file exists and is not expected then error
if (result && !expectStanzaStop)
if (storageExistsNP(storageLocal(), lockStopFileName(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
if (!expectStanzaStop && storageExistsNP(storageLocal(), lockStopFileName(NULL)))
// Check all stanzas
if (storageExistsNP(storageLocal(), lockStopFileName(NULL)))
THROW(StopError, "stop file exists for all stanzas");
}
MEM_CONTEXT_TEMP_END();
FUNCTION_LOG_RETURN(BOOL, result);
FUNCTION_LOG_RETURN_VOID();
}

View File

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

View File

@ -40,7 +40,7 @@ testRun(void)
strLstAddZ(argList, "start");
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();
@ -50,16 +50,13 @@ testRun(void)
strLstAddZ(argList, "start");
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
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");
TEST_RESULT_VOID(lockStopTest(), "no stop files with stanza");
storagePutNP(storageNewWriteNP(storageTest, strNew("all.stop")), NULL);
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");
TEST_ERROR(lockStopTest(), StopError, "stop file exists for all stanzas");
storagePutNP(storageNewWriteNP(storageTest, strNew("db.stop")), NULL);
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");
TEST_ERROR(lockStopTest(), StopError, "stop file exists for stanza db");
}
FUNCTION_HARNESS_RESULT_VOID();