End the MySQL thread on every poll_host exit - #595
Closed
somethingwithproof wants to merge 5 commits into
Closed
Conversation
poll_host() is 1,926 lines and builds the same six queries twice, once for the main poller and once for a remote one. The bodies differ by 33 of 141 lines, and every difference is the same rule: the main poller reads items that are not deleted, a remote poller reads the items assigned to it. Nothing in that construction was reachable from a test, so a column added to one copy and not the other would not have been caught. Extract the rule as poller_item_scope() and poller_owner_scope(), covered by five cases in test_linked against the shipped poller.o: the deleted filter on the main poller, the ownership filter on a remote one, the empty fragment the main poller needs so callers can interpolate unconditionally, and a degenerate buffer. No call site changes yet. Collapsing the two branches onto these helpers is the next step and is worth its own review, because the shipped query1 spells its tail 'poller_id=%i' while the others spell it 'poller_id = %i', so the unified text will normalise that. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The two branches drifted: the remote copy never picked up the dbonupdate handling the main copy grew, and nothing could have caught that because the construction was not reachable from a test. Captured what both branches emit across the vectors they switch on, collapsed them onto poller_item_scope()/poller_owner_scope(), and diffed. Output is byte-identical except query1 on a remote poller, which now spells its tail 'poller_id = N' rather than 'poller_id=N' to match the other five queries. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
set.dbonupdate is 1 on MySQL 8, which deprecated VALUES() in ON DUPLICATE KEY UPDATE. The main poller switched to the row-alias form; the remote branch kept the deprecated one because it had its own copy of the suffix. Closes Cacti#590. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The construction was 167 lines in the middle of a 1,795-line function, so nothing could reach it. It now takes its inputs as arguments and fills a struct, which is what lets the golden capture become a test that runs instead of a file with instructions attached. poll_host is 1,620 lines, down from 1,927 on develop. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
poll_host() leaves through three places and each spelled its teardown out again. The copies were not in the same order and did not hold the same steps: the device-row-missing path never called mysql_thread_end(), so a device deleted mid-cycle leaked the client library's thread-local state once per cycle. Closes Cacti#594. The two early exits now share poll_host_release(). The normal exit uses error_string after the point where that helper frees it, so it shares only poll_host_release_connections() and keeps its own ordering. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Member
Author
|
Consolidated into #597, which carries this branch's commits unchanged. Every pair of these ten conflicted on Nothing here is dropped. Reopen this if you would rather review it separately. |
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.
Closes #594. Stacked on #589; merge that first.
poll_host()leaves through three places. Two calledmysql_thread_end(), one did not:There is no
mysql_thread_init()in the tree, so the client library sets its thread-local state up on first use andmysql_thread_end()is what releases it.poll_host()has already issueddb_query()before it reaches that branch, so the state exists and is then abandoned. Spine is thread-per-device, so it is once per affected device per cycle.The branch fires when
SELECT ... FROM host WHERE id = %i AND deleted = ''does not return exactly one row: a device deleted or soft-deleted between the poller picking it up and the thread reading it, or a remote poller whosehosttable has not caught up.Why it happened
The teardown was written out three times, six
SPINE_FREEcalls plus the same fourteen-line connection release. The three copies were not in the same order and, as here, did not contain the same steps. Nothing put them side by side.The change
poll_host_release()for the two early exits, taking pointers so the caller's pointers are nulled rather than left dangling.The normal exit could not use it: it calls
buffer_output_errors(error_string, ...)after the point where the helper freeserror_string. Rather than reorder that, it sharespoll_host_release_connections()only and keeps the rest of its sequence. So the fourteen-line connection block is now in one place across all three, and the six frees are shared across the two that can share them.poll_host()drops from 1,620 to 1,570 lines.Verification
This one is not unit-testable:
mysql_thread_end()is a libmysql call with no observable return, and reaching the branch needs a device row to vanish between two queries. Saying so rather than dressing up a weaker test as proof.What was checked: every
returninpoll_host(), and its fall-off-the-end exit, now reachesmysql_thread_end(). Cleanubuntu:24.04build matchingci.yml, same four warnings as develop,make checkgreen on all four binaries, 49 of 49 tests.No
CHANGELOGentry here; #578 is the changelog PR for this batch.