mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2024-12-12 10:04:14 +02:00
Migrate control functions to detect stop files to C from Perl.
Basic functions to detect the presence of stanza or all stop files and error when they are present. The functionality to detect stop files without error was not migrated. This functionality is only used by stanza-delete and will be migrated with that command.
This commit is contained in:
parent
5bdaa35fa5
commit
6e9b6fdca9
@ -42,6 +42,10 @@
|
||||
<release-item>
|
||||
<p>Migrate <code>walIsPartial()</code>, <code>walIsSegment()</code>, and <code>walSegmentFind()</code> from Perl to C.</p>
|
||||
</release-item>
|
||||
|
||||
<release-item>
|
||||
<p>Migrate control functions to detect stop files to C from Perl.</p>
|
||||
</release-item>
|
||||
</release-development-list>
|
||||
</release-core-list>
|
||||
</release>
|
||||
|
@ -59,6 +59,7 @@ SRCS = \
|
||||
command/archive/push/push.c \
|
||||
command/help/help.c \
|
||||
command/command.c \
|
||||
command/control/control.c \
|
||||
common/debug.c \
|
||||
common/encode.c \
|
||||
common/encode/base64.c \
|
||||
@ -152,6 +153,9 @@ command/archive/push/push.o: command/archive/push/push.c command/archive/common.
|
||||
command/command.o: command/command.c common/assert.h common/debug.h common/error.auto.h common/error.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/time.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h version.h
|
||||
$(CC) $(CFLAGS) -c command/command.c -o command/command.o
|
||||
|
||||
command/control/control.o: command/control/control.c command/control/control.h common/debug.h common/error.auto.h common/error.h common/io/filter/filter.h common/io/filter/group.h common/io/read.h common/io/write.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h storage/driver/posix/driverRead.h storage/driver/posix/driverWrite.h storage/fileRead.h storage/fileWrite.h storage/helper.h storage/info.h storage/storage.h version.h
|
||||
$(CC) $(CFLAGS) -c command/control/control.c -o command/control/control.o
|
||||
|
||||
command/help/help.o: command/help/help.c common/assert.h common/debug.h common/error.auto.h common/error.h common/io/handle.h common/lock.h common/log.h common/logLevel.h common/memContext.h common/stackTrace.h common/type/buffer.h common/type/convert.h common/type/keyValue.h common/type/string.h common/type/stringList.h common/type/variant.h common/type/variantList.h config/config.auto.h config/config.h config/define.auto.h config/define.h version.h
|
||||
$(CC) $(CFLAGS) -c command/help/help.c -o command/help/help.o
|
||||
|
||||
|
48
src/command/control/control.c
Normal file
48
src/command/control/control.c
Normal file
@ -0,0 +1,48 @@
|
||||
/***********************************************************************************************************************************
|
||||
Command Control
|
||||
***********************************************************************************************************************************/
|
||||
#include "command/control/control.h"
|
||||
#include "common/debug.h"
|
||||
#include "config/config.h"
|
||||
#include "storage/helper.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Create the stop filename
|
||||
***********************************************************************************************************************************/
|
||||
String *
|
||||
lockStopFileName(const String *stanza)
|
||||
{
|
||||
FUNCTION_TEST_BEGIN();
|
||||
FUNCTION_TEST_PARAM(STRING, stanza);
|
||||
FUNCTION_TEST_END();
|
||||
|
||||
String *result = strNewFmt("%s/%s.stop", strPtr(cfgOptionStr(cfgOptLockPath)), stanza != NULL ? strPtr(stanza) : "all");
|
||||
|
||||
FUNCTION_TEST_RESULT(STRING, result);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Test for the existence of a stop file
|
||||
***********************************************************************************************************************************/
|
||||
void
|
||||
lockStopTest(void)
|
||||
{
|
||||
FUNCTION_DEBUG_VOID(logLevelDebug);
|
||||
|
||||
MEM_CONTEXT_TEMP_BEGIN()
|
||||
{
|
||||
// Check the current stanza (if any)
|
||||
if (cfgOptionTest(cfgOptStanza))
|
||||
{
|
||||
if (storageExistsNP(storageLocal(), lockStopFileName(cfgOptionStr(cfgOptStanza))))
|
||||
THROW_FMT(StopError, "stop file exists for stanza %s", strPtr(cfgOptionStr(cfgOptStanza)));
|
||||
}
|
||||
|
||||
// Check all stanzas
|
||||
if (storageExistsNP(storageLocal(), lockStopFileName(NULL)))
|
||||
THROW(StopError, "stop file exists for all stanzas");
|
||||
}
|
||||
MEM_CONTEXT_TEMP_END();
|
||||
|
||||
FUNCTION_DEBUG_RESULT_VOID();
|
||||
}
|
15
src/command/control/control.h
Normal file
15
src/command/control/control.h
Normal file
@ -0,0 +1,15 @@
|
||||
/***********************************************************************************************************************************
|
||||
Command Control
|
||||
***********************************************************************************************************************************/
|
||||
#ifndef COMMAND_CONTROL_CONTROL_H
|
||||
#define COMMAND_CONTROL_CONTROL_H
|
||||
|
||||
#include "common/type/string.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
String *lockStopFileName(const String *stanza);
|
||||
void lockStopTest(void);
|
||||
|
||||
#endif
|
@ -587,6 +587,14 @@ unit:
|
||||
coverage:
|
||||
command/command: full
|
||||
|
||||
test:
|
||||
# ----------------------------------------------------------------------------------------------------------------------------
|
||||
- name: control
|
||||
total: 2
|
||||
|
||||
coverage:
|
||||
command/control/control: full
|
||||
|
||||
# ********************************************************************************************************************************
|
||||
- name: archive
|
||||
|
||||
|
61
test/src/module/command/controlTest.c
Normal file
61
test/src/module/command/controlTest.c
Normal file
@ -0,0 +1,61 @@
|
||||
/***********************************************************************************************************************************
|
||||
Test Command Control
|
||||
***********************************************************************************************************************************/
|
||||
#include "common/harnessConfig.h"
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Test Run
|
||||
***********************************************************************************************************************************/
|
||||
void
|
||||
testRun(void)
|
||||
{
|
||||
FUNCTION_HARNESS_VOID();
|
||||
|
||||
// Create default storage object for testing
|
||||
Storage *storageTest = storageNewP(strNew(testPath()), .write = true);
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("lockStopFileName()"))
|
||||
{
|
||||
// Load configuration so lock path is set
|
||||
StringList *argList = strLstNew();
|
||||
strLstAddZ(argList, "pgbackrest");
|
||||
strLstAddZ(argList, "--stanza=db");
|
||||
strLstAddZ(argList, "--lock-path=/path/to/lock");
|
||||
strLstAddZ(argList, "archive-get");
|
||||
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
|
||||
|
||||
TEST_RESULT_STR(strPtr(lockStopFileName(NULL)), "/path/to/lock/all.stop", "stop file for all stanzas");
|
||||
TEST_RESULT_STR(strPtr(lockStopFileName(strNew("db"))), "/path/to/lock/db.stop", "stop file for on stanza");
|
||||
}
|
||||
|
||||
// *****************************************************************************************************************************
|
||||
if (testBegin("lockStopTest()"))
|
||||
{
|
||||
StringList *argList = strLstNew();
|
||||
strLstAddZ(argList, "pgbackrest");
|
||||
strLstAdd(argList, strNewFmt("--lock-path=%s", testPath()));
|
||||
strLstAddZ(argList, "start");
|
||||
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
|
||||
|
||||
TEST_RESULT_VOID(lockStopTest(), "no stop files without stanza");
|
||||
|
||||
// -------------------------------------------------------------------------------------------------------------------------
|
||||
argList = strLstNew();
|
||||
strLstAddZ(argList, "pgbackrest");
|
||||
strLstAddZ(argList, "--stanza=db");
|
||||
strLstAdd(argList, strNewFmt("--lock-path=%s", testPath()));
|
||||
strLstAddZ(argList, "start");
|
||||
harnessCfgLoad(strLstSize(argList), strLstPtr(argList));
|
||||
|
||||
TEST_RESULT_VOID(lockStopTest(), "no stop files with stanza");
|
||||
|
||||
storagePutNP(storageNewWriteNP(storageTest, strNew("all.stop")), NULL);
|
||||
TEST_ERROR(lockStopTest(), StopError, "stop file exists for all stanzas");
|
||||
|
||||
storagePutNP(storageNewWriteNP(storageTest, strNew("db.stop")), NULL);
|
||||
TEST_ERROR(lockStopTest(), StopError, "stop file exists for stanza db");
|
||||
}
|
||||
|
||||
FUNCTION_HARNESS_RESULT_VOID();
|
||||
}
|
Loading…
Reference in New Issue
Block a user