Repository navigation
refactor(core): move the outbound remote adapter operations into core behind remote-adapter feature - #824
refactor(core): move the outbound remote adapter operations into core behind remote-adapter feature#824LiamCarPer wants to merge 1 commit into
Conversation
Moves the duplicated outbound CoreAdapter operations from the redis, postgres and mongodb adapters into socketioxide-core behind the existing remote-adapter feature flag. - RemoteOperations trait with default implementations of broadcast, disconnect_socket, rooms, add_sockets, del_sockets and fetch_sockets. Adapters only provide local(), uid(), server_count(), send_req() and get_res(). - Generic InitRes<E> replacing the three identical copies. - The response count of get_res is now read from RemoteOperations, so the server count logic lives in one place instead of six. broadcast_with_ack stays adapter-local for now: it needs associated types for the response stream and its decoder, and it was recently changed by the ack timeout and response handler leak fixes. One behavior change: postgres and mongodb now target opts.server_id for broadcast and disconnect_socket like redis already did, instead of sending the request to every server. Closes Totodore#804
Merging this PR will not alter performance1 warning
Comparing |
|
Hey, the only red check is The udeps job uses the floating Everything else is green: test, adapter, feature_set, clippy, msrv, format and the socket_io/engine_io suites. If you want i can open a small separate PR to pin the nightly used by the udeps job (or skip the mongodb crate there) until nightly is fixed. |
|
Hey, just a small ping on this one when you have a moment. CI is all green now: the earlier |
Part of #727, closes #804.
Motivation
The outbound half of the
CoreAdapterimpl was still duplicated in the three adapters.broadcast,disconnect_socket,rooms,add_sockets,del_socketsandfetch_socketswere ~95% identical (~450 lines total), and theget_resserver count snippet was copied six times (get_resx3 +broadcast_with_ackx3), which is exactly where the #782 bug came from.Solution
RemoteOperationstrait insocketioxide-corebehindremote-adapter, with default implementations of the six operations. Each adapter only implementslocal(),uid(),server_count(),send_req()andget_res().InitRes<E>in core, replacing the three identical copies (only the error type was different).get_resandbroadcast_with_acknow read the server count fromRemoteOperations::server_count, so that logic lives in one place.broadcast_with_ackstays adapter local for now. It needs associated types for the response stream plus its decoder, and it was just changed by the ack timeout (#822) and response handler leak (#802) fixes, so i would rather do it separately if you think it is worth it.One behavior change: postgres and mongodb now target
opts.server_idforbroadcastanddisconnect_socket(like redis already did) instead of sending the request to every server. It only affects the case where we act on a specific remote socket, where only the target server can have a match anyway.Tests
No new tests: the existing fixture tests of the three adapters already cover every moved operation (broadcast, broadcast with ack, rooms, add/del sockets, fetch sockets, disconnect) and they pass with the shared implementations.