mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-01-18 04:58:51 +02:00
Add sck-block option.
This option puts sockets into blocking mode. It is only intended for internal use and is not included in the test matrix.
This commit is contained in:
parent
5d25e508ae
commit
21a1cf9a2f
@ -150,6 +150,7 @@ use constant CFGOPT_IO_TIMEOUT => 'io-timeo
|
||||
use constant CFGOPT_NEUTRAL_UMASK => 'neutral-umask';
|
||||
use constant CFGOPT_PROTOCOL_TIMEOUT => 'protocol-timeout';
|
||||
use constant CFGOPT_PROCESS_MAX => 'process-max';
|
||||
use constant CFGOPT_SCK_BLOCK => 'sck-block';
|
||||
use constant CFGOPT_SCK_KEEP_ALIVE => 'sck-keep-alive';
|
||||
use constant CFGOPT_TCP_KEEP_ALIVE_COUNT => 'tcp-keep-alive-count';
|
||||
use constant CFGOPT_TCP_KEEP_ALIVE_IDLE => 'tcp-keep-alive-idle';
|
||||
@ -1122,6 +1123,15 @@ my %hConfigDefine =
|
||||
}
|
||||
},
|
||||
|
||||
&CFGOPT_SCK_BLOCK =>
|
||||
{
|
||||
&CFGDEF_SECTION => CFGDEF_SECTION_GLOBAL,
|
||||
&CFGDEF_INTERNAL => true,
|
||||
&CFGDEF_TYPE => CFGDEF_TYPE_BOOLEAN,
|
||||
&CFGDEF_DEFAULT => false,
|
||||
&CFGDEF_COMMAND => CFGOPT_BUFFER_SIZE,
|
||||
},
|
||||
|
||||
&CFGOPT_SCK_KEEP_ALIVE =>
|
||||
{
|
||||
&CFGDEF_SECTION => CFGDEF_SECTION_GLOBAL,
|
||||
|
@ -32,9 +32,10 @@ static struct SocketLocal
|
||||
|
||||
/**********************************************************************************************************************************/
|
||||
void
|
||||
sckInit(bool keepAlive, int tcpKeepAliveCount, int tcpKeepAliveIdle, int tcpKeepAliveInterval)
|
||||
sckInit(bool block, bool keepAlive, int tcpKeepAliveCount, int tcpKeepAliveIdle, int tcpKeepAliveInterval)
|
||||
{
|
||||
FUNCTION_LOG_BEGIN(logLevelDebug);
|
||||
FUNCTION_LOG_PARAM(BOOL, block);
|
||||
FUNCTION_LOG_PARAM(BOOL, keepAlive);
|
||||
FUNCTION_LOG_PARAM(INT, tcpKeepAliveCount);
|
||||
FUNCTION_LOG_PARAM(INT, tcpKeepAliveIdle);
|
||||
@ -46,7 +47,7 @@ sckInit(bool keepAlive, int tcpKeepAliveCount, int tcpKeepAliveIdle, int tcpKeep
|
||||
ASSERT(tcpKeepAliveInterval >= 0);
|
||||
|
||||
socketLocal.init = true;
|
||||
socketLocal.block = false;
|
||||
socketLocal.block = block;
|
||||
socketLocal.keepAlive = keepAlive;
|
||||
socketLocal.tcpKeepAliveCount = tcpKeepAliveCount;
|
||||
socketLocal.tcpKeepAliveIdle = tcpKeepAliveIdle;
|
||||
|
@ -13,7 +13,7 @@ Socket Common Functions
|
||||
Functions
|
||||
***********************************************************************************************************************************/
|
||||
// Initialize settings for socket connections (some are used only for TCP)
|
||||
void sckInit(bool keepAlive, int tcpKeepAliveCount, int tcpKeepAliveIdle, int tcpKeepAliveInterval);
|
||||
void sckInit(bool block, bool keepAlive, int tcpKeepAliveCount, int tcpKeepAliveIdle, int tcpKeepAliveInterval);
|
||||
|
||||
// Set options on a socket
|
||||
void sckOptionSet(int fd);
|
||||
|
@ -448,6 +448,7 @@ STRING_EXTERN(CFGOPT_REPO1_S3_URI_STYLE_STR, CFGOPT_REPO1
|
||||
STRING_EXTERN(CFGOPT_REPO1_S3_VERIFY_TLS_STR, CFGOPT_REPO1_S3_VERIFY_TLS);
|
||||
STRING_EXTERN(CFGOPT_REPO1_TYPE_STR, CFGOPT_REPO1_TYPE);
|
||||
STRING_EXTERN(CFGOPT_RESUME_STR, CFGOPT_RESUME);
|
||||
STRING_EXTERN(CFGOPT_SCK_BLOCK_STR, CFGOPT_SCK_BLOCK);
|
||||
STRING_EXTERN(CFGOPT_SCK_KEEP_ALIVE_STR, CFGOPT_SCK_KEEP_ALIVE);
|
||||
STRING_EXTERN(CFGOPT_SET_STR, CFGOPT_SET);
|
||||
STRING_EXTERN(CFGOPT_SORT_STR, CFGOPT_SORT);
|
||||
@ -1791,6 +1792,14 @@ static ConfigOptionData configOptionData[CFG_OPTION_TOTAL] = CONFIG_OPTION_LIST
|
||||
CONFIG_OPTION_DEFINE_ID(cfgDefOptResume)
|
||||
)
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
CONFIG_OPTION
|
||||
(
|
||||
CONFIG_OPTION_NAME(CFGOPT_SCK_BLOCK)
|
||||
CONFIG_OPTION_INDEX(0)
|
||||
CONFIG_OPTION_DEFINE_ID(cfgDefOptSckBlock)
|
||||
)
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
CONFIG_OPTION
|
||||
(
|
||||
|
@ -383,6 +383,8 @@ Option constants
|
||||
STRING_DECLARE(CFGOPT_REPO1_TYPE_STR);
|
||||
#define CFGOPT_RESUME "resume"
|
||||
STRING_DECLARE(CFGOPT_RESUME_STR);
|
||||
#define CFGOPT_SCK_BLOCK "sck-block"
|
||||
STRING_DECLARE(CFGOPT_SCK_BLOCK_STR);
|
||||
#define CFGOPT_SCK_KEEP_ALIVE "sck-keep-alive"
|
||||
STRING_DECLARE(CFGOPT_SCK_KEEP_ALIVE_STR);
|
||||
#define CFGOPT_SET "set"
|
||||
@ -418,7 +420,7 @@ Option constants
|
||||
#define CFGOPT_TYPE "type"
|
||||
STRING_DECLARE(CFGOPT_TYPE_STR);
|
||||
|
||||
#define CFG_OPTION_TOTAL 182
|
||||
#define CFG_OPTION_TOTAL 183
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
Command enum
|
||||
@ -617,6 +619,7 @@ typedef enum
|
||||
cfgOptRepoS3VerifyTls,
|
||||
cfgOptRepoType,
|
||||
cfgOptResume,
|
||||
cfgOptSckBlock,
|
||||
cfgOptSckKeepAlive,
|
||||
cfgOptSet,
|
||||
cfgOptSort,
|
||||
|
@ -4270,6 +4270,43 @@ static ConfigDefineOptionData configDefineOptionData[] = CFGDEFDATA_OPTION_LIST
|
||||
)
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
CFGDEFDATA_OPTION
|
||||
(
|
||||
CFGDEFDATA_OPTION_NAME("sck-block")
|
||||
CFGDEFDATA_OPTION_REQUIRED(true)
|
||||
CFGDEFDATA_OPTION_SECTION(cfgDefSectionGlobal)
|
||||
CFGDEFDATA_OPTION_TYPE(cfgDefOptTypeBoolean)
|
||||
CFGDEFDATA_OPTION_INTERNAL(true)
|
||||
|
||||
CFGDEFDATA_OPTION_INDEX_TOTAL(1)
|
||||
CFGDEFDATA_OPTION_SECURE(false)
|
||||
|
||||
CFGDEFDATA_OPTION_COMMAND_LIST
|
||||
(
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdArchiveGet)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdArchivePush)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdBackup)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdCheck)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdExpire)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdInfo)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdRepoCreate)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdRepoGet)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdRepoLs)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdRepoPut)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdRepoRm)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdRestore)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdStanzaCreate)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdStanzaDelete)
|
||||
CFGDEFDATA_OPTION_COMMAND(cfgDefCmdStanzaUpgrade)
|
||||
)
|
||||
|
||||
CFGDEFDATA_OPTION_OPTIONAL_LIST
|
||||
(
|
||||
CFGDEFDATA_OPTION_OPTIONAL_DEFAULT("0")
|
||||
)
|
||||
)
|
||||
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
CFGDEFDATA_OPTION
|
||||
(
|
||||
|
@ -140,6 +140,7 @@ typedef enum
|
||||
cfgDefOptRepoS3VerifyTls,
|
||||
cfgDefOptRepoType,
|
||||
cfgDefOptResume,
|
||||
cfgDefOptSckBlock,
|
||||
cfgDefOptSckKeepAlive,
|
||||
cfgDefOptSet,
|
||||
cfgDefOptSort,
|
||||
|
@ -340,6 +340,7 @@ cfgLoad(unsigned int argListSize, const char *argList[])
|
||||
if (cfgOptionValid(cfgOptSckKeepAlive))
|
||||
{
|
||||
sckInit(
|
||||
cfgOptionBool(cfgOptSckBlock),
|
||||
cfgOptionBool(cfgOptSckKeepAlive),
|
||||
cfgOptionTest(cfgOptTcpKeepAliveCount) ? cfgOptionInt(cfgOptTcpKeepAliveCount) : 0,
|
||||
cfgOptionTest(cfgOptTcpKeepAliveIdle) ? cfgOptionInt(cfgOptTcpKeepAliveIdle) : 0,
|
||||
|
@ -2240,6 +2240,21 @@ static const struct option optionList[] =
|
||||
.val = PARSE_OPTION_FLAG | PARSE_RESET_FLAG | cfgOptResume,
|
||||
},
|
||||
|
||||
// sck-block option
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
.name = CFGOPT_SCK_BLOCK,
|
||||
.val = PARSE_OPTION_FLAG | cfgOptSckBlock,
|
||||
},
|
||||
{
|
||||
.name = "no-" CFGOPT_SCK_BLOCK,
|
||||
.val = PARSE_OPTION_FLAG | PARSE_NEGATE_FLAG | cfgOptSckBlock,
|
||||
},
|
||||
{
|
||||
.name = "reset-" CFGOPT_SCK_BLOCK,
|
||||
.val = PARSE_OPTION_FLAG | PARSE_RESET_FLAG | cfgOptSckBlock,
|
||||
},
|
||||
|
||||
// sck-keep-alive option
|
||||
// -----------------------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
@ -2579,6 +2594,7 @@ static const ConfigOption optionResolveOrder[] =
|
||||
cfgOptRepoRetentionFull,
|
||||
cfgOptRepoType,
|
||||
cfgOptResume,
|
||||
cfgOptSckBlock,
|
||||
cfgOptSckKeepAlive,
|
||||
cfgOptSet,
|
||||
cfgOptSort,
|
||||
|
@ -140,7 +140,7 @@ testRun(void)
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("enable options");
|
||||
|
||||
sckInit(true, 32, 3113, 818);
|
||||
sckInit(false, true, 32, 3113, 818);
|
||||
sckOptionSet(fd);
|
||||
|
||||
TEST_RESULT_INT(fcntl(fd, F_GETFD), FD_CLOEXEC, "check FD_CLOEXEC");
|
||||
@ -189,7 +189,7 @@ testRun(void)
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("disable keep-alive");
|
||||
|
||||
sckInit(false, 0, 0, 0);
|
||||
sckInit(false, false, 0, 0, 0);
|
||||
sckOptionSet(fd);
|
||||
|
||||
TEST_RESULT_INT(keepAliveValue, 1, "check SO_KEEPALIVE");
|
||||
@ -200,7 +200,7 @@ testRun(void)
|
||||
// ---------------------------------------------------------------------------------------------------------------------
|
||||
TEST_TITLE("enable keep-alive but disable options");
|
||||
|
||||
sckInit(true, 0, 0, 0);
|
||||
sckInit(false, true, 0, 0, 0);
|
||||
sckOptionSet(fd);
|
||||
|
||||
TEST_RESULT_INT(keepAliveValue, 1, "check SO_KEEPALIVE");
|
||||
|
@ -353,12 +353,14 @@ testRun(void)
|
||||
argList = strLstNew();
|
||||
strLstAdd(argList, strNew("pgbackrest"));
|
||||
strLstAddZ(argList, "--no-" CFGOPT_SCK_KEEP_ALIVE);
|
||||
strLstAddZ(argList, "--" CFGOPT_SCK_BLOCK);
|
||||
strLstAdd(argList, strNew("info"));
|
||||
|
||||
socketLocal = (struct SocketLocal){.init = false};
|
||||
|
||||
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "load config and don't set umask");
|
||||
TEST_RESULT_BOOL(socketLocal.init, true, " check socketLocal.init");
|
||||
TEST_RESULT_BOOL(socketLocal.block, true, " check socketLocal.block");
|
||||
TEST_RESULT_BOOL(socketLocal.keepAlive, false, " check socketLocal.keepAlive");
|
||||
TEST_RESULT_UINT(ioTimeoutMs(), 60000, " check io timeout");
|
||||
|
||||
@ -450,6 +452,7 @@ testRun(void)
|
||||
TEST_RESULT_VOID(cfgLoad(strLstSize(argList), strLstPtr(argList)), "lock and open log file");
|
||||
TEST_RESULT_INT(lstat(strPtr(strNewFmt("%s/db-backup.log", testPath())), &statLog), 0, " check log file exists");
|
||||
TEST_RESULT_BOOL(socketLocal.init, true, " check socketLocal.init");
|
||||
TEST_RESULT_BOOL(socketLocal.block, false, " check socketLocal.block");
|
||||
TEST_RESULT_BOOL(socketLocal.keepAlive, true, " check socketLocal.keepAlive");
|
||||
TEST_RESULT_INT(socketLocal.tcpKeepAliveCount, 11, " check socketLocal.tcpKeepAliveCount");
|
||||
TEST_RESULT_INT(socketLocal.tcpKeepAliveIdle, 2222, " check socketLocal.tcpKeepAliveIdle");
|
||||
|
@ -73,7 +73,7 @@ main(int argListSize, const char *argList[])
|
||||
int result = 0;
|
||||
|
||||
// Use aggressive keep-alive settings for testing
|
||||
sckInit(true, 2, 5, 5);
|
||||
sckInit(false, true, 2, 5, 5);
|
||||
|
||||
// Set neutral umask for testing
|
||||
umask(0000);
|
||||
|
Loading…
x
Reference in New Issue
Block a user