Promote longest-waiting B session via max_connect_time fold#5825
Conversation
…me fold Under sustained contention ProcessAllSessions_Partition leaves the B (CONNECTING_SERVER) band unordered, so the pass can serve newer waiters ahead of older ones until they hit connect_timeout_server_max and abort. Track the oldest waiter during the classifier's is_B arm (no second pass) and swap it to running_end. Key on max_connect_time, which the is_B test already loads -- the min-compare is a register compare with no extra memory access, and the smallest value is the waiter closest to the timeout abort. Gated by |B| > PARTITION_FAIRNESS_MIN_B (=4) and partition_active.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📜 Recent review details🧰 Additional context used📓 Path-based instructions (3)**/*.{cpp,h,hpp}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
include/**/*.{h,hpp}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
{lib,src}/**/*.{cpp,h,hpp}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🔇 Additional comments (5)
📝 WalkthroughWalkthroughThe pull request introduces session fairness promotion to the partition processing logic. A public fairness threshold constant is defined, and the partitioning method now tracks the longest-waiting B-band session by earliest connection time and swaps it to the running boundary when the B-band is sufficiently large, ensuring it is served first. ChangesSession Fairness Promotion in Partitioning
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a fairness mechanism in the session partitioning logic. It tracks the longest-waiting B session (the one with the smallest max_connect_time) and promotes it to the front of the B-band (at running_end) so that it is served first during the connection phase, gated by a minimum band size to prevent unnecessary churn. I have no feedback to provide as there are no review comments to assess.
|



Summary
Follow-on to the partition gate. Under sustained backend-pool contention,
ProcessAllSessions_Partitionleft the B band (sessions inCONNECTING_SERVER, waiting on the pool) in unordered storage order, so the CONNECTING_SERVER pass could keep serving newer waiters ahead of older ones — letting the unlucky oldest waiters sit until they hitconnect_timeout_server_max(default 10s) and abort. This promotes the longest-waiting session to the front of the B band each tick so it's served first.What changed
is_Barm, track the session with the smallestmax_connect_time(no second pass over B), then swap it torunning_endafter the pass.
|B| > PARTITION_FAIRNESS_MIN_B (=4)and the existingpartition_activegate — a no-op on small bands / low contention.lib/Base_Thread.cpp(+25), one constant ininclude/Base_Thread.h(+1). Shared template, so it applies to both MySQLand PgSQL.
Why
max_connect_timeThe
is_Btest already loadss->mybe->server_myds->max_connect_time, so the min-compare is a register compare with no extra memory access (vsCurrentQuery.start_time, a separate cache line).max_connect_time = connect_start + connect_timeout, so the smallest value is the earliest waiter — the session closest to the abort being prevented — a more direct target than query start, and identical ordering when the connect timeout is uniform.Behavior / risk
untouched.
locks (per-thread state only).
Summary by CodeRabbit