diff options
author | Alexander Korotkov <akorotkov@postgresql.org> | 2024-10-24 14:40:23 +0300 |
---|---|---|
committer | Alexander Korotkov <akorotkov@postgresql.org> | 2024-10-24 15:02:21 +0300 |
commit | e546989a269d5d73d283901aadcfda8c6d98e87b (patch) | |
tree | 64e1c28c70bd3647bd51baa95ca20a41787a986a /src/backend/access/transam/xlogfuncs.c | |
parent | 73da6b8d1b3e8b7541961c3534e584243cb0470e (diff) | |
download | postgresql-e546989a269d5d73d283901aadcfda8c6d98e87b.tar.gz postgresql-e546989a269d5d73d283901aadcfda8c6d98e87b.zip |
Add 'no_error' argument to pg_wal_replay_wait()
This argument allow skipping throwing an error. Instead, the result status
can be obtained using pg_wal_replay_wait_status() function.
Catversion is bumped.
Reported-by: Michael Paquier
Discussion: https://postgr.es/m/ZtUF17gF0pNpwZDI%40paquier.xyz
Reviewed-by: Pavel Borisov
Diffstat (limited to 'src/backend/access/transam/xlogfuncs.c')
-rw-r--r-- | src/backend/access/transam/xlogfuncs.c | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/src/backend/access/transam/xlogfuncs.c b/src/backend/access/transam/xlogfuncs.c index ddca78d3717..bca1d395683 100644 --- a/src/backend/access/transam/xlogfuncs.c +++ b/src/backend/access/transam/xlogfuncs.c @@ -751,15 +751,18 @@ pg_promote(PG_FUNCTION_ARGS) PG_RETURN_BOOL(false); } +static WaitLSNResult lastWaitLSNResult = WAIT_LSN_RESULT_SUCCESS; + /* - * Waits until recovery replays the target LSN with optional timeout. + * Waits until recovery replays the target LSN with optional timeout. Unless + * 'no_error' provided throws an error on failure */ Datum pg_wal_replay_wait(PG_FUNCTION_ARGS) { XLogRecPtr target_lsn = PG_GETARG_LSN(0); int64 timeout = PG_GETARG_INT64(1); - WaitLSNResult result; + bool no_error = PG_GETARG_BOOL(2); if (timeout < 0) ereport(ERROR, @@ -800,13 +803,16 @@ pg_wal_replay_wait(PG_FUNCTION_ARGS) */ Assert(MyProc->xmin == InvalidTransactionId); - result = WaitForLSNReplay(target_lsn, timeout); + lastWaitLSNResult = WaitForLSNReplay(target_lsn, timeout); + + if (no_error) + PG_RETURN_VOID(); /* * Process the result of WaitForLSNReplay(). Throw appropriate error if * needed. */ - switch (result) + switch (lastWaitLSNResult) { case WAIT_LSN_RESULT_SUCCESS: /* Nothing to do on success */ @@ -832,3 +838,27 @@ pg_wal_replay_wait(PG_FUNCTION_ARGS) PG_RETURN_VOID(); } + +Datum +pg_wal_replay_wait_status(PG_FUNCTION_ARGS) +{ + const char *result_string = ""; + + /* Process the result of WaitForLSNReplay(). */ + switch (lastWaitLSNResult) + { + case WAIT_LSN_RESULT_SUCCESS: + result_string = "success"; + break; + + case WAIT_LSN_RESULT_TIMEOUT: + result_string = "timeout"; + break; + + case WAIT_LSN_RESULT_NOT_IN_RECOVERY: + result_string = "not in recovery"; + break; + } + + PG_RETURN_TEXT_P(cstring_to_text(result_string)); +} |