MDEV-22992 Refactor VIO into layered transports and filters - #5584
Open
vaintroub wants to merge 1 commit into
Open
MDEV-22992 Refactor VIO into layered transports and filters#5584vaintroub wants to merge 1 commit into
vaintroub wants to merge 1 commit into
Conversation
Copilot stopped reviewing on behalf of
vaintroub due to an error
August 21, 2026 15:22
vaintroub
force-pushed
the
main-MDEV-22992
branch
from
August 24, 2026 12:08
59740b2 to
30a7a51
Compare
vaintroub
requested
a lite review from Copilot
and removed request for
Copilot
August 24, 2026 18:42
Copilot stopped reviewing on behalf of
vaintroub due to an error
August 24, 2026 19:03
vaintroub
force-pushed
the
main-MDEV-22992
branch
4 times, most recently
from
August 24, 2026 22:28
6912e7f to
13f5709
Compare
Replace the function-pointer VIO implementation with an abstract C++ interface while retaining the procedural C entry points. Implement socket and named-pipe transports and composable filters for client read-ahead, Windows thread-pool prefetch, and TLS. OpenSSL uses a custom BIO, while wolfSSL uses callbacks that perform I/O through the VIO below the TLS filter. This keeps waits and timeouts in the transport layer. Keep sockets nonblocking and implement timed I/O with transport waits. Named pipes use overlapped I/O for timeout-aware waits and report blocking waits through the same scheduler callbacks as sockets. Semi-sync temporarily changes the real VIO read timeout instead of copying VIO state. Hide transport and TLS implementation state behind accessors. Expose the TLS handle opaquely and update callers that previously accessed VIO fields directly. Compile the VIO implementations as C++ and retain PSI memory accounting for VIO allocations. Adapt Windows thread-pool pre-read to a Prefetched_vio filter inserted above the transport so both plain and TLS connections consume prefetched bytes through the same layered VIO path. Clean header files so that vio headers no longer include OpenSSL or wolfSSL headers. Remove some legacy functionality: - vio_close() with its double-close guards appeared hard to maintain in the class hierarchy, and had been unnecessary for the last 15 years -- we consistently have used vio_shutdown() for waking up threads stuck in network IO. Associated things that are also gone: preprocessor definition SIGNAL_WITH_VIO_CLOSE (always defined), VIO_STATE_CLOSED. The VIO_CLOSED type, which was used as a sentinel, was renamed to VIO_TYPE_INVALID. - vio_io_wait() used in a single place, replaced by read with timeout. - vio_reset() to create SSL, replaced by vio_wrap. Assisted-by: Claude:claude-sonnet-5
vaintroub
force-pushed
the
main-MDEV-22992
branch
from
August 25, 2026 22:54
7cfc549 to
fc0ad15
Compare
vaintroub
requested
a lite review from Copilot
and removed request for
Copilot
August 26, 2026 12:15
There was a problem hiding this comment.
Pull request overview
Refactors the VIO subsystem from a function-pointer-based C struct into a layered C++ transport/filter hierarchy, while preserving the existing C entry points via thin wrappers. This enables composable filters (e.g., TLS, read-ahead, Windows prefetch) and centralizes timeout/wait behavior in transport layers.
Changes:
- Introduces a C++
Viointerface (include/vio.h) plus C wrappers (vio/vio_wrapper.cc) and migrates core VIO implementation to C++ (vio/vio.cc,vio/viosocket.cc,vio/viossl.cc). - Implements/ports transports and waits: nonblocking socket transport with timed waits, and Windows named-pipe transport using overlapped I/O (
vio/viopipe.cc). - Updates server/client call sites to use new opaque TLS/VIO accessors (
vio_ssl_handle,vio_remote_addr,vio_mysql_socket_ptr, etc.) and adjusts threadpool + semi-sync ACK receiver behavior accordingly.
Reviewed changes
Copilot reviewed 44 out of 44 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| vio/viotest-ssl.c | Updates SSL handshake calls; file still uses legacy struct st_vio layout (now invalid). |
| vio/viosslfactories.c | Updates wolfSSL callbacks to perform I/O via underlying VIO beneath TLS filter. |
| vio/viossl.cc | Reworks TLS layer into Ssl_vio filter; adds OpenSSL custom BIO path; updates sslaccept/sslconnect to return wrapped VIO. |
| vio/viosocket.cc | Migrates socket VIO to Socket_vio transport; adds wait begin/end hooks; nonblocking + timed waits. |
| vio/viopipe.cc | Adds Windows named-pipe transport as C++ overlapped-I/O Named_pipe_vio. |
| vio/viopipe.c | Removes legacy C named-pipe implementation. |
| vio/vio.cc | Adds C++ VIO core, PSI memory registration, socket VIO construction, buffered read filter, and vio_delete. |
| vio/vio.c | Removes legacy C VIO core (function-pointer struct initialization, reset, blocking toggles, etc.). |
| vio/vio_wrapper.cc | Adds C ABI wrappers over the C++ VIO hierarchy; tracks per-thread timeout classification. |
| vio/vio_priv.h | Introduces C++ transport/filter class declarations and new internal helpers (vio_get_underlying, wait hooks). |
| vio/test-sslserver.c | Updates sslaccept call; file still uses legacy struct st_vio fields/function pointers (now invalid). |
| vio/test-sslclient.c | Updates sslconnect call; file still uses legacy struct st_vio fields (now invalid). |
| vio/test-ssl.c | Updates sslconnect/sslaccept calls; file still uses legacy struct st_vio layout/function pointers (now invalid). |
| vio/CMakeLists.txt | Switches VIO build to C++ sources; adds viopipe.cc on Windows. |
| storage/perfschema/pfs_instr.cc | Adjusts default connection type enum value to VIO_TYPE_INVALID. |
| sql/threadpool.h | Changes Windows init_vio contract to take st_vio ** (allows inserting filters). |
| sql/threadpool_winsockets.h | Adapts AIO socket wrapper to insert a VIO filter instead of swapping function pointers. |
| sql/threadpool_winsockets.cc | Implements Prefetched_vio filter and wraps it into the VIO chain for Windows prefetch. |
| sql/threadpool_win.cc | Propagates init_vio(st_vio **) signature change. |
| sql/threadpool_generic.h | Propagates init_vio(st_vio **) signature change for Windows builds. |
| sql/threadpool_generic.cc | Updates assertions to VIO_TYPE_INVALID. |
| sql/threadpool_common.cc | Updates socket PSI ownership and data checks to use new VIO wrapper functions. |
| sql/sql_connect.h | Updates CONNECT destructor assertion to VIO_TYPE_INVALID. |
| sql/sql_connect.cc | Updates TLS detection, peer address access, and thread-owner instrumentation via new accessors. |
| sql/sql_class.h | Removes SIGNAL_WITH_VIO_CLOSE gating; keeps active_vio always present. |
| sql/sql_class.cc | Adjusts wake/disconnect logic to shutdown active VIO instead of closing it directly. |
| sql/sql_audit.h | Moves TLS version extraction into a .cc implementation using new TLS handle accessor. |
| sql/sql_audit.cc | Implements TLS version extraction using vio_ssl_handle(). |
| sql/sql_acl.cc | Updates SSL accept call and SSL checks to use vio_ssl_handle() instead of struct field access. |
| sql/slave.cc | Removes SIGNAL_WITH_VIO_CLOSE gating around active-vio clearing/setting. |
| sql/semisync_master_ack_receiver.h | Changes Slave to store Vio * (shared) instead of copying Vio by value. |
| sql/semisync_master_ack_receiver.cc | Uses scoped temporary read-timeout + suppresses PFS attribution via PSI thread swap. |
| sql/net_serv.cc | Removes blocking/fastsend toggles; updates type/state logging and proxy-protocol address access. |
| sql/mysqld.cc | Updates PSI socket state setting and SSL context casts; switches TLS access to vio_ssl_handle(). |
| sql/item_strfunc.cc | Adds missing OpenSSL EVP include (for HKDF / digest usage paths). |
| sql-common/client.c | Updates TLS handle usage, transport-type selection, SSL connect signature, and connect-timeout read behavior. |
| plugin/feedback/url_http.cc | Updates sslconnect usage and SSL_CTX cast/free for opaque context type. |
| mysys_ssl/my_md5.cc | Adjusts wolfSSL MD5 compatibility typedefs/sizing. |
| mysql-test/main/kill_debug.test | Replaces disconnect with dirty_close to avoid deadlock under new wake/shutdown behavior. |
| include/violite.h | Redefines VIO public C API as wrappers over C++ VIO; updates enums and SSL function signatures; adds new accessors. |
| include/vio.h | Adds the new C++ Vio interface and Vio_filter base + wrapping helpers. |
| include/ssl_compat.h | Adds pragma-once and ensures OpenSSL headers are included centrally. |
| configure.cmake | Removes SIGNAL_WITH_VIO_CLOSE definition. |
| config.h.cmake | Removes SIGNAL_WITH_VIO_CLOSE configure define. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
100
to
+105
| client_vio = (Vio*)my_malloc(sizeof(struct st_vio),MYF(0)); | ||
| client_vio->sd = sv[0]; | ||
| sslconnect(ssl_connector,client_vio,&ssl_error); | ||
| sslconnect(ssl_connector,&client_vio,&ssl_error); | ||
| server_vio = (Vio*)my_malloc(sizeof(struct st_vio),MYF(0)); | ||
| server_vio->sd = sv[1]; | ||
| sslaccept(ssl_acceptor,server_vio,&ssl_error); | ||
| sslaccept(ssl_acceptor,&server_vio,&ssl_error); |
Comment on lines
99
to
103
| client_vio = (struct st_vio*)my_malloc(sizeof(struct st_vio),MYF(0)); | ||
| client_vio->sd = sv[0]; | ||
| client_vio->vioblocking(client_vio, 0, &unused); | ||
| sslconnect(ssl_connector,client_vio,60L,&ssl_error); | ||
| sslconnect(ssl_connector,&client_vio,60L,&ssl_error); | ||
| server_vio = (struct st_vio*)my_malloc(sizeof(struct st_vio),MYF(0)); |
Comment on lines
82
to
89
| err = connect(client_vio->sd, (struct sockaddr*) &sa, | ||
| sizeof(sa)); | ||
|
|
||
| /* ----------------------------------------------- */ | ||
| /* Now we have TCP conncetion. Start SSL negotiation. */ | ||
| read(client_vio->sd,xbuf, sizeof(xbuf)); | ||
| sslconnect(ssl_connector,client_vio,60L,&ssl_error); | ||
| sslconnect(ssl_connector,&client_vio,60L,&ssl_error); | ||
| err = vio_read(client_vio,xbuf, sizeof(xbuf)); |
Comment on lines
58
to
66
| server_vio = vio_new(args->sd, VIO_TYPE_TCPIP, TRUE); | ||
|
|
||
| /* ----------------------------------------------- */ | ||
| /* TCP connection is ready. Do server side SSL. */ | ||
|
|
||
| err = write(server_vio->sd,(uchar*)s, strlen(s)); | ||
| sslaccept(args->ssl_acceptor,server_vio,60L,&ssl_error); | ||
| sslaccept(args->ssl_acceptor,&server_vio,60L,&ssl_error); | ||
| err = server_vio->write(server_vio,(uchar*)s, strlen(s)); | ||
| DBUG_VOID_RETURN; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the function-pointer VIO implementation with an abstract C++ interface while retaining the procedural C entry points.
Implement socket and named-pipe transports and composable filters for client read-ahead, Windows thread-pool prefetch, and TLS. OpenSSL uses a custom BIO, while wolfSSL uses callbacks that perform I/O through the VIO below the TLS filter. This keeps waits and timeouts in the transport layer.
Keep sockets nonblocking and implement timed I/O with transport waits. Named pipes use overlapped I/O for timeout-aware waits and report blocking waits through the same scheduler callbacks as sockets. Semi-sync temporarily changes the real VIO read timeout instead of copying VIO state.
Hide transport and TLS implementation state behind accessors. Expose the TLS handle opaquely and update callers that previously accessed VIO fields directly. Compile the VIO implementations as C++ and retain PSI memory accounting for VIO allocations.
Adapt Windows thread-pool pre-read to a Prefetched_vio filter inserted above the transport so both plain and TLS connections consume prefetched bytes through the same layered VIO path.