Skip to content

Commit 26803d0

Browse files
yeputonsMMeent
authored andcommitted
zenith_test_utils extension: add neon_xlogflush()
This function is to simplify complex WAL generation in neondatabase/neon#1574 `pg_logical_emit_message` is the easiest way to get a big WAL record, but: * If it's transactional, it gets `COMMIT` record right after * If it's not, WAL is not flushed at all. The function helps here, so we don't rely on the background WAL writer. I suspect the plain `xlogflush()` name may collide in the future, hence the prefix.
1 parent bdf91d7 commit 26803d0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

contrib/zenith_test_utils/zenith_test_utils--1.0.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,8 @@ CREATE FUNCTION get_raw_page_at_lsn(tbspc oid, db oid, relfilenode oid, forknum
2222
RETURNS bytea
2323
AS 'MODULE_PATHNAME', 'get_raw_page_at_lsn_ex'
2424
LANGUAGE C PARALLEL UNSAFE;
25+
26+
CREATE FUNCTION neon_xlogflush(lsn pg_lsn)
27+
RETURNS VOID
28+
AS 'MODULE_PATHNAME', 'neon_xlogflush'
29+
LANGUAGE C PARALLEL UNSAFE;

contrib/zenith_test_utils/zenithtest.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "storage/buf_internals.h"
2121
#include "storage/bufmgr.h"
2222
#include "utils/builtins.h"
23+
#include "utils/pg_lsn.h"
2324
#include "utils/rel.h"
2425
#include "utils/varlena.h"
2526
#include "zenith/pagestore_client.h"
@@ -32,6 +33,7 @@ PG_FUNCTION_INFO_V1(test_consume_xids);
3233
PG_FUNCTION_INFO_V1(clear_buffer_cache);
3334
PG_FUNCTION_INFO_V1(get_raw_page_at_lsn);
3435
PG_FUNCTION_INFO_V1(get_raw_page_at_lsn_ex);
36+
PG_FUNCTION_INFO_V1(neon_xlogflush);
3537

3638
/*
3739
* Linkage to functions in zenith module.
@@ -289,3 +291,14 @@ get_raw_page_at_lsn_ex(PG_FUNCTION_ARGS)
289291
PG_RETURN_BYTEA_P(raw_page);
290292
}
291293
}
294+
295+
/*
296+
* Directly calls XLogFlush(lsn) to flush WAL buffers.
297+
*/
298+
Datum
299+
neon_xlogflush(PG_FUNCTION_ARGS)
300+
{
301+
XLogRecPtr lsn = PG_GETARG_LSN(0);
302+
XLogFlush(lsn);
303+
PG_RETURN_VOID();
304+
}

0 commit comments

Comments
 (0)