Repository navigation
Give Poco::Net::SocketAddress a noexcept move constructor - #115030
alexey-milovidov merged 1 commit into
Conversation
SystemLogQueue::push() appends to a std::vector<LogElement> while holding the queue mutex, so crossing capacity reallocates inside the critical section. libc++ relocates with std::move_if_noexcept, which yields a const lvalue reference (and therefore copies) for a type that is not nothrow-move-constructible. QueryLogElement was not nothrow-move-constructible for exactly one reason: Poco::Net::SocketAddress declared copy operations only, so its implicit move fell back to the copy, and that copy heap-allocates a new SocketAddressImpl via newIPv4/newIPv6/newLocal. ClientInfo carries three such addresses. One push() therefore deep-copied the whole queue with several allocations per element, under the mutex. On a Stateless tests (amd_tsan, flaky check) run this held the query_log mutex for 177 of 181 seconds with 31 threads blocked in the same push, including every hung-check liveness probe, so the job was reported as Server died: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=110479&sha=038667a9c024695126415fe5f37b76f7a06662fa&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20flaky%20check%29 Add a genuine noexcept move constructor and move assignment that transfer _pImpl. The moves of ClientInfo and of the log elements stay implicit, so their nothrow-move trait is derived from the members rather than asserted into existence; an explicit noexcept on the wrappers would have satisfied the assertion while still copying, and would have converted a throw into terminate(). The transfer uses AutoPtr::swap rather than assignment because Poco::AutoPtr declares no move operations either: assigning it binds to assign(const AutoPtr &), which calls duplicate() and leaves the source non-null. AutoPtr::swap is std::swap on the raw pointer, so it is genuinely noexcept and allocation-free. Four SystemLog element types were affected: QueryLog, QueryThreadLog and SessionLog through ClientInfo, and ZooKeeperLog through a bare SocketAddress member. All 29 element types pass the trait after this change. Measured over one reallocation of 8192 elements carrying three optional<SocketAddress> members: 32769 allocations before, 1 after. Two static_asserts guard the property: one beside QueryLogElement, and a generic one in SystemLogQueue that enumerates every element type at build time. Both fail the build on the unpatched tree. A moved-from SocketAddress has a null _pImpl. That state was already supported: pImpl() null-checks and throws Poco::NullPointerException, and all seven accessors route through it, so reading a moved-from address is defined rather than undefined behaviour. Not addressed here: the slow query_log flush that triggered the reallocation is a separate performance question, and adding a move to Poco::AutoPtr would be the broader fix.
Internal second-model review (click to expand)Two independent reviews of this diff: a cold read of the resulting code, then a second model
Checked and clean, with the reasoning recorded rather than asserted:
|
|
Workflow [PR], commit [6004c1f] Summary: ✅
AI ReviewSummaryThis PR makes Final Verdict✅ No actionable findings. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 0/0 (nothing coverable) · Uncovered code |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260816-150400 |
|
cc @thevar1able @pamarcos, could you review this? |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Object file sizes31 object files changed (-69.57 KiB total), 0 added.
737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units1614 translation units recompiled, 9256 s compile time in total, 1614 of them have a recent master baseline. |
|
📊 Cloud Performance Report 🟢 AI verdict: This PR gives Poco's SocketAddress a noexcept move constructor/assignment, which makes QueryLogElement nothrow-move-constructible; the SystemLogQueue then relocates entries by move instead of deep-copying them while holding its mutex, shrinking a critical section that was O(queue size). Because every query writes to query_log, that overhead reduction shows up as a broad, consistent speedup: roughly 6-25% across most ClickBench queries, with the largest relative gains on the fastest queries where fixed overhead dominates. We kept all improvement verdicts — the uniform, operator-agnostic pattern is exactly what this fix predicts. The two very large outliers (TPC-H Q7 at ×8.2 faster, ClickBench Q23 at ×2.2 with noisy history) are directionally trustworthy but their exact magnitude likely also reflects co-location/measurement effects, so read the scale there with some caution. clickbench🟢 12 improved Flagged queries (12 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 2 improved Flagged queries (2 of 22)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. Debug info
|
CI finish ledger - 6004c1fCI has fully finished on this head and there are no failures to own: 158 OK, 20 skipped, 0 failed.
The two Corroborated from two independent sources at this SHA: CIDB (344,608 success rows, 0 FAIL/ERROR rows Session id: cron:our-pr-ci-monitor:20260817-030000 |
0dcf023
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Appending to a system log queue no longer deep-copies the whole queue when it grows.
Poco::Net::SocketAddresshad no move constructor, which madeQueryLogElementand three other element types not nothrow-move-constructible, so astd::vectorreallocation copied every element (allocating per address) while the queue mutex was held, blocking every query that writes tosystem.query_log.Description
Found while investigating a server that accepted and planned queries but executed none for 3.5 minutes on
Stateless tests (amd_tsan, flaky check): CI report. The sampling profiler shows one thread insideSystemLogQueue<QueryLogElement>::pushfor 177 of 181 seconds, invector::__emplace_back_slow_path, with 31 threads blocked onstd::mutex::lock()in the same call.push()appends undermutex, so astd::vectorreallocation happens in the critical section. libc++ relocates withstd::move_if_noexcept, which falls back to copying every element when the type is not nothrow-move-constructible.QueryLogElementwas not, for one reason:Poco::Net::SocketAddressdeclared copy operations only, and its copy heap-allocates a newSocketAddressImpl.ClientInfoholds three of those.The fix belongs in Poco because that is where the cause is: a refcounted-pointer wrapper whose move is nothing but a pointer transfer. The moves of
ClientInfoand the log elements stay implicit, so their trait is derived.AutoPtr::swapis used becauseAutoPtralso declares no move, so assignment would bump the refcount and leave the source non-null.Measured over one reallocation of 8192 elements: 32769 allocations before, 1 after. Four element types were affected (
QueryLog,QueryThreadLog,SessionLog,ZooKeeperLog); astatic_assertinSystemLogQueuenow enumerates every element type at build time (30 here, 32 in a cloud build) and fails on the unpatched tree.A moved-from
SocketAddresshas a null_pImpl; all seven accessors already route throughpImpl(), which throwsNullPointerException, so that state stays defined.Left out deliberately: the slow
query_logflush that triggered the reallocation is a separate question, and a move onPoco::AutoPtrwould be the broader fix. This is one mechanism proven on one artifact, not a claim about everyServer diedreport. No SQL test, because a C++ relocation trait is not observable from SQL.