Add on-demand WAL download to slot funcs (#8705)

## Problem
Currently we can have an issue where if someone does
`pg_logical_slot_advance`, it could fail because it doesn't have the WAL
locally.

## Summary of changes
Adds on-demand WAL download and a test to these slot funcs. Before
adding these, the test fails with
```
requested WAL segment pg_wal/000000010000000000000001 has already been removed
```
After the changes, the test passes


Relies on:
- https://github.com/neondatabase/postgres/pull/466
- https://github.com/neondatabase/postgres/pull/467
- https://github.com/neondatabase/postgres/pull/468
This commit is contained in:
Sasha Krassovsky
2024-08-12 21:54:42 -07:00
committed by GitHub
parent f57c2fe8fb
commit 32aa1fc681
6 changed files with 22 additions and 6 deletions

View File

@@ -599,6 +599,7 @@ _PG_init(void)
pg_init_walproposer();
WalSender_Custom_XLogReaderRoutines = NeonOnDemandXLogReaderRoutines;
LogicalFuncs_Custom_XLogReaderRoutines = NeonOnDemandXLogReaderRoutines;
SlotFuncs_Custom_XLogReaderRoutines = NeonOnDemandXLogReaderRoutines;
InitLogicalReplicationMonitor();

View File

@@ -255,6 +255,21 @@ FROM generate_series(1, 16384) AS seq; -- Inserts enough rows to exceed 16MB of
cur.execute(
"SELECT * FROM pg_logical_slot_peek_binary_changes('slotty_mcslotface', NULL, NULL, 'include-xids', '0')"
)
cur.execute(
"""
INSERT INTO wal_generator (data)
SELECT repeat('A', 1024) -- Generates a kilobyte of data per row
FROM generate_series(1, 16384) AS seq; -- Inserts enough rows to exceed 16MB of data
"""
)
endpoint.stop_and_destroy()
endpoint = env.endpoints.create_start("init")
with endpoint.connect().cursor() as cur:
log.info("advance slot")
cur.execute(
"SELECT * from pg_replication_slot_advance('slotty_mcslotface', pg_current_wal_lsn())"
)
# Tests that walsender correctly blocks until WAL is downloaded from safekeepers

View File

@@ -1,14 +1,14 @@
{
"v16": [
"16.3",
"6434b1499b11ed97dccea5618a055034b83b8e2f"
"5ea106b2583285849784e774b39d62eb2615bd5d"
],
"v15": [
"15.7",
"47c8d462d169367c8979ce628a523be2d94b46be"
"39c51c33b383239c78b86afe561679f980e44842"
],
"v14": [
"14.12",
"ae07734e0ff72759ab425fc8f625d4c1ecb15a50"
"a48faca1d9aef59649dd1bf34bc1b6303fa3489e"
]
}