PostgreSQL 18 preview - AIO增强 : 增加监控工具、增强测试能力、清理代码、改进错误诊断
PostgreSQL 18 preview - AIO增强 : 增加监控工具、增强测试能力、清理代码、改进错误诊断
AIO 再放patch: 这些补丁都是为了改进 PostgreSQL 的 AIO 子系统,包括增加监控工具、增强测试能力、清理代码和改进错误诊断。这些改进有助于提高 AIO 的稳定性和性能,并方便开发者进行调试和维护。
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=60f566b4f24362f54003569d5f6e24137bcd83fc
aio: Add pg_aios view
author Andres Freund <[email protected]>
Tue, 1 Apr 2025 17:30:33 +0000 (13:30 -0400)
committer Andres Freund <[email protected]>
Tue, 1 Apr 2025 17:30:33 +0000 (13:30 -0400)
commit 60f566b4f24362f54003569d5f6e24137bcd83fc
tree a6ff02f2728f442acb851daf94597a58b4194ca1 tree
parent 46250cdcb037e302ec5f0734ea0d06e2d21193e0 commit | diff
aio: Add pg_aios view The new view lists all IO handles that are currently in use and is mainly
useful for PG developers, but may also be useful when tuning PG.
Bumps catversion.
Reviewed-by: Noah Misch <[email protected]>
Discussion: https://postgr.es/m/uvrtrknj4kdytuboidbhwclo4gxhswwcpgadptsjvjqcluzmah%40brqs62irg4dt
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=93bc3d75d8e1aabdc256ff6da2282266dca82537
aio: Add test_aio module
author Andres Freund <[email protected]>
Tue, 1 Apr 2025 17:47:46 +0000 (13:47 -0400)
committer Andres Freund <[email protected]>
Tue, 1 Apr 2025 17:47:46 +0000 (13:47 -0400)
commit 93bc3d75d8e1aabdc256ff6da2282266dca82537
tree 9edc8a9eb2e202381ac853f4dbbad1ecc0fba3fa tree
parent 60f566b4f24362f54003569d5f6e24137bcd83fc commit | diff
aio: Add test_aio module To make the tests possible, a few functions from bufmgr.c/localbuf.c had to be
exported, via buf_internals.h.
Reviewed-by: Noah Misch <[email protected]>
Co-authored-by: Andres Freund <[email protected]>
Co-authored-by: Nazir Bilal Yavuz <[email protected]>
Discussion: https://postgr.es/m/uvrtrknj4kdytuboidbhwclo4gxhswwcpgadptsjvjqcluzmah%40brqs62irg4dt
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=00066aa1733d84109f7569a7202c3915d8289d3a
md: Add comment & assert to buffer-zeroing path in md[start]readv()
author Andres Freund <[email protected]>
Tue, 1 Apr 2025 17:50:39 +0000 (13:50 -0400)
committer Andres Freund <[email protected]>
Tue, 1 Apr 2025 17:50:39 +0000 (13:50 -0400)
commit 00066aa1733d84109f7569a7202c3915d8289d3a
tree 54bb9bb43ed22986ede2f481ef8cb932ebd15ef1 tree
parent 93bc3d75d8e1aabdc256ff6da2282266dca82537 commit | diff
md: Add comment & assert to buffer-zeroing path in md[start]readv() mdreadv() has a codepath to zero out buffers when a read returns zero bytes,
guarded by a check for zero_damaged_pages || InRecovery.
The InRecovery codepath to zero out buffers in mdreadv() appears to be
unreachable. The only known paths to reach mdreadv()/mdstartreadv() in
recovery are XLogReadBufferExtended(), vm_readbuf(), and fsm_readbuf(), each
of which takes care to extend the relation if necessary. This looks to either
have been the casefor a long time, or the code was never reachable.
The zero_damaged_pages path is incomplete, as missing segments are not
created.
Putting blocks into the buffer-pool that do not exist on disk is rather
problematic, as such blocks will, at least initially, not be found by scans
that rely on smgrnblocks(), as they are beyond EOF. It also can cause weird
problems with relation extension, as relation extension does not expect blocks
beyond EOF to exist.
Therefore we would like to remove that path.
mdstartreadv(), which I added in e5fe570b51c, does not implement this zeroing
logic. I had started a discussion about that a while ago (linked below), but
forgot to act on the conclusion of the discussion, namely to disable the
in-memory-zeroing behavior.
We could certainly implement equivalent zeroing logic in mdstartreadv(), but
it would have to be more complicated due to potential differences in the
zero_damaged_pages setting between the definer and completor of IO. Given that
we want to remove the logic, that does not seem worth implementing the
necessary logic.
For now, put an Assert(false) and comments documenting this choice into
mdreadv() and comments documenting the deprecation of the path in mdreadv()
and the non-implementation of it in mdstartreadv(). If we, during testing,
discover that we do need the path, we can implement it at that time.
Reviewed-by: Noah Misch <[email protected]>
Discussion: https://postgr.es/m/postgr.es/m/[email protected]
Discussion: https://postgr.es/m/postgr.es/m/3qxxsnciyffyf3wyguiz4besdp5t5uxvv3utg75cbcszojlz7p@uibfzmnukkbd
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=b3219c69fc1e161df8d380c464b3f2cce3b6cab9
aio: Add errcontext for processing I/Os for another backend
author Melanie Plageman <[email protected]>
Tue, 1 Apr 2025 23:53:07 +0000 (19:53 -0400)
committer Melanie Plageman <[email protected]>
Tue, 1 Apr 2025 23:53:07 +0000 (19:53 -0400)
commit b3219c69fc1e161df8d380c464b3f2cce3b6cab9
tree 174b07dc1ded069e257aae952e887b727c719dc1 tree
parent b136db07c651e5048d44add0a01d5fc01b6fe0dc commit | diff
aio: Add errcontext for processing I/Os for another backend Push an ErrorContextCallback adding additional detail about the process
performing the I/O and the owner of the I/O when those are not the same.
For io_method worker, this adds context specifying which process owns
the I/O that the I/O worker is processing.
For io_method io_uring, this adds context only when a backend is
*completing* I/O for another backend. It specifies the pid of the owning
process.
Author: Melanie Plageman <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Discussion: https://postgr.es/m/rdml3fpukrqnas7qc5uimtl2fyytrnu6ymc2vjf2zuflbsjuul%40hyizyjsexwmm
AI 解读
好的,这是对这些补丁的解读:
1. aio: Add pg_aios view (aio: 添加 pg_aios 视图)
目的: 添加一个新的系统视图 pg_aios,用于列出当前正在使用的所有 I/O 句柄。作用: PG 开发者调试: 主要用于 PostgreSQL 开发者调试 AIO 子系统。 性能调优: 可能对调整 PostgreSQL 的 AIO 相关参数也有用。 影响: 增加了一个新的系统视图,允许用户监控 AIO 句柄的使用情况。 Bumps catversion表示增加了系统目录版本,需要升级。总结: 这是一个监控工具,方便开发者和 DBA 了解 AIO 的运行状态。
2. aio: Add test_aio module (aio: 添加 test_aio 模块)
目的: 添加一个新的测试模块 test_aio,用于测试 AIO 子系统。作用: AIO 功能测试: 提供了一套测试用例,用于验证 AIO 的正确性和性能。 代码质量保证: 通过自动化测试,提高 AIO 子系统的代码质量。 影响: 增加了一个新的测试模块,增强了 AIO 子系统的测试覆盖率。 为了使测试成为可能,一些来自 bufmgr.c和localbuf.c的函数需要通过buf_internals.h导出。这意味着暴露了一些内部接口,需要谨慎使用。总结: 这是一个重要的补丁,增强了 AIO 子系统的测试能力,有助于发现和修复潜在的 Bug。
3. md: Add comment & assert to buffer-zeroing path in md[start]readv() (md: 在 md[start]readv() 的缓冲区清零路径中添加注释和断言)
目的: 移除 mdreadv()中一个可能无法访问的缓冲区清零代码路径,并记录相关决策。背景: mdreadv()中有一个代码路径,用于在读取返回零字节时清零缓冲区,由zero_damaged_pages || InRecovery控制。作者认为 InRecovery下的清零路径是不可达的,因为在恢复过程中调用mdreadv()/mdstartreadv()的函数都会确保在必要时扩展关系。zero_damaged_pages下的清零路径是不完整的,因为它不会创建缺失的段。将不存在于磁盘上的块放入缓冲池是有问题的,因为这些块可能无法被依赖 smgrnblocks()的扫描找到,并且可能导致关系扩展出现问题。作用: 移除潜在问题: 移除了可能导致数据不一致和程序错误的缓冲区清零代码路径。 代码简化: 简化了 mdreadv()的代码逻辑。明确设计决策: 通过添加注释和断言,明确了移除该代码路径的原因和潜在风险。 影响: mdreadv()中InRecovery下的缓冲区清零代码路径被标记为已弃用,并添加了Assert(false),如果执行到该路径,程序会崩溃。mdstartreadv()没有实现缓冲区清零逻辑,并且明确记录了这一点。总结: 这是一个清理和改进代码的补丁,移除了一个可能存在问题的代码路径,并明确了相关设计决策。
4. aio: Add errcontext for processing I/Os for another backend (aio: 为处理另一个后端的 I/O 添加 errcontext)
目的: 在处理其他后端 I/O 时,添加更详细的错误上下文信息。 作用: 错误诊断: 当一个后端(例如,AIO worker)为另一个后端处理 I/O 时发生错误,可以提供更多关于哪个进程拥有 I/O 以及哪个进程正在执行 I/O 的信息,方便错误诊断。 问题定位: 更容易定位跨进程的 AIO 问题。 影响: 当使用 io_method worker时,错误上下文会包含拥有 I/O 的进程的信息。当使用 io_method io_uring时,只有在后端 完成 另一个后端的 I/O 时,才会添加错误上下文,并包含拥有进程的 PID。总结: 这是一个增强错误诊断能力的补丁,可以帮助开发者更容易地定位和解决 AIO 相关的问题,尤其是在跨进程的场景下。
总的来说,这些补丁都是为了改进 PostgreSQL 的 AIO 子系统,包括增加监控工具、增强测试能力、清理代码和改进错误诊断。这些改进有助于提高 AIO 的稳定性和性能,并方便开发者进行调试和维护。