1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2026-05-22 10:15:16 +02:00

Allow custom type/message for errRetryAdd().

It may be useful to customize the message or add a message that was never thrown. The latter case will be used in an upcoming commit.
This commit is contained in:
David Steele
2023-11-28 16:35:37 -03:00
parent 85bc9f27d8
commit 70e15dacc7
6 changed files with 38 additions and 22 deletions
+13 -7
View File
@@ -84,28 +84,34 @@ errRetryMessage(const ErrorRetry *const this)
/**********************************************************************************************************************************/
FN_EXTERN void
errRetryAdd(ErrorRetry *const this)
errRetryAdd(ErrorRetry *const this, const ErrRetryAddParam param)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ERROR_RETRY, this);
FUNCTION_TEST_PARAM(ERROR_TYPE, param.type);
FUNCTION_TEST_PARAM(STRING, param.message);
FUNCTION_TEST_END();
// Set defaults
const ErrorType *const type = param.type == NULL ? errorType() : param.type;
const char *const message = param.message == NULL ? errorMessage() : strZ(param.message);
// Set type on first error
if (this->pub.type == NULL)
{
MEM_CONTEXT_OBJ_BEGIN(this)
{
this->pub.type = errorType();
this->message = strNewZ(errorMessage());
this->pub.type = type;
this->message = strNewZ(message);
}
MEM_CONTEXT_OBJ_END();
}
else
{
// If error is not found then add it
const String *const message = STR(errorMessage());
const String *const messageFind = STR(message);
const TimeMSec retryTime = timeMSec() - this->timeBegin;
ErrorRetryItem *const error = lstFind(this->list, &message);
ErrorRetryItem *const error = lstFind(this->list, &messageFind);
if (error == NULL)
{
@@ -113,9 +119,9 @@ errRetryAdd(ErrorRetry *const this)
{
const ErrorRetryItem errorNew =
{
.type = errorType(),
.type = type,
.total = 1,
.message = strDup(message),
.message = strDup(messageFind),
.retryFirst = retryTime,
.retryLast = retryTime,
};
+16 -6
View File
@@ -22,12 +22,6 @@ Constructor
***********************************************************************************************************************************/
FN_EXTERN ErrorRetry *errRetryNew(void);
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
// Add retry error
FN_EXTERN void errRetryAdd(ErrorRetry *this);
/***********************************************************************************************************************************
Getters/Setters
***********************************************************************************************************************************/
@@ -46,6 +40,22 @@ errRetryType(const ErrorRetry *const this)
// Get error message
FN_EXTERN String *errRetryMessage(const ErrorRetry *this);
/***********************************************************************************************************************************
Functions
***********************************************************************************************************************************/
// Add error
typedef struct ErrRetryAddParam
{
VAR_PARAM_HEADER;
const ErrorType *type; // Error type (defaults to errorType())
const String *message; // Error message (defaults to errorMessage())
} ErrRetryAddParam;
#define errRetryAddP(this, ...) \
errRetryAdd(this, (ErrRetryAddParam){VAR_PARAM_INIT, __VA_ARGS__})
FN_EXTERN void errRetryAdd(ErrorRetry *const this, ErrRetryAddParam param);
/***********************************************************************************************************************************
Destructor
***********************************************************************************************************************************/
+1 -1
View File
@@ -154,7 +154,7 @@ httpRequestProcess(HttpRequest *this, bool waitForResponse, bool contentCache)
CATCH_ANY()
{
// Add the error retry info
errRetryAdd(errRetry);
errRetryAddP(errRetry);
// Sleep and then retry unless the total wait time has expired
if (waitMore(wait))
+1 -1
View File
@@ -116,7 +116,7 @@ sckClientOpen(THIS_VOID)
close(fd);
// Add the error retry info
errRetryAdd(errRetry);
errRetryAddP(errRetry);
// Increment address info index and reset if the end has been reached. When the end has been reached sleep for a bit
// to hopefully have better chance at succeeding, otherwise continue right to the next address.
+1 -1
View File
@@ -203,7 +203,7 @@ protocolServerProcess(
CATCH_ANY()
{
// Add the error retry info
errRetryAdd(errRetry);
errRetryAddP(errRetry);
// On first error record the stack trace. Only the first error will contain a stack trace since
// the first error is most likely to contain valuable information.
+6 -6
View File
@@ -25,7 +25,7 @@ testRun(void)
}
CATCH_ANY()
{
TEST_RESULT_VOID(errRetryAdd(retry), "add retry");
TEST_RESULT_VOID(errRetryAddP(retry), "add retry");
}
TRY_END();
@@ -35,7 +35,7 @@ testRun(void)
}
CATCH_ANY()
{
TEST_RESULT_VOID(errRetryAdd(retry), "add retry");
TEST_RESULT_VOID(errRetryAddP(retry, errorType(), STR(errorMessage())), "add retry");
}
TRY_END();
@@ -63,7 +63,7 @@ testRun(void)
}
CATCH_ANY()
{
TEST_RESULT_VOID(errRetryAdd(retry), "add retry");
TEST_RESULT_VOID(errRetryAddP(retry), "add retry");
}
TRY_END();
@@ -73,7 +73,7 @@ testRun(void)
}
CATCH_ANY()
{
TEST_RESULT_VOID(errRetryAdd(retry), "add retry");
TEST_RESULT_VOID(errRetryAddP(retry), "add retry");
}
TRY_END();
@@ -83,7 +83,7 @@ testRun(void)
}
CATCH_ANY()
{
TEST_RESULT_VOID(errRetryAdd(retry), "add retry");
TEST_RESULT_VOID(errRetryAddP(retry), "add retry");
}
TRY_END();
@@ -93,7 +93,7 @@ testRun(void)
}
CATCH_ANY()
{
TEST_RESULT_VOID(errRetryAdd(retry), "add retry");
TEST_RESULT_VOID(errRetryAddP(retry), "add retry");
}
TRY_END();