Repository navigation
osd/OSDMap: don't abort on float rounding in read balancer - #71772
Conversation
|
Thank you for your contribution. Since you are not yet a member of the Ceph organization with write permissions on ceph/ceph.git, our CI will not automatically run. Any member of the Ceph organization may label this PR |
|
In progress reviewing. I requested the osdmap on the ticket for further verification of the fix. |
|
Attached the osdmap from my vstart reproduction to the tracker, with the osdmaptool one-liner that aborts on main and exits 0 with this branch. |
| // factor is mathematically >= 1.0 (distribution_sum <= pg_num), but | ||
| // float rounding of the per-OSD terms can push distribution_sum a | ||
| // fraction above pg_num; clamp instead of asserting on rounding noise | ||
| ceph_assert(factor >= 1.0 - 1e-6); | ||
| factor = std::max(factor, 1.0); |
There was a problem hiding this comment.
If distribution_sum ends up being slightly more than pg_num (ideally distribution_sum <= pg_num) due to float rounding, then factor ends up being slightly less than 1, when it should always be >= 1.
Change the assert to be tolerant of any rounding (even though floats were already replaced by doubles) so the factor is confirmed >= slightly less than 1. THEN pin the factor to either 1.0 (no stretch needed) or the larger computed value (primary_affinity was less than 1 for some OSDs, so we need to stretch/increase the primary PG load on the other OSDs).
ACK
There was a problem hiding this comment.
I think it would even be OK to remove the assert altogether and change it into an error log message at debug 10. Then the function can return -EINVAL. The original assumption was that this value would always be true, but given the limitations with C++ primitive data types, I think a log message is appropriate.
The worst that would happen in this case is that the error message would be logged, and the pool would be skipped.
| double factor = (double)pool->get_pg_num() / distribution_sum; | ||
| double distribution_sum_desired = 0.0; |
There was a problem hiding this comment.
Change these values to doubles to lessen float rounding impacts on larger PGs.
ACK
| for (auto & [osd, osd_primary_count] : desired_primary_distribution) { | ||
| double scaled = (double)osd_primary_count * factor; | ||
| osd_primary_count = (float)scaled; | ||
| distribution_sum_desired += scaled; | ||
| } |
There was a problem hiding this comment.
Instead of iterating through desired_primary_distribution in const/read-only mode, only to end up changing the values within the loop, this area removes const and uses osd_primary_count from the for loop to update desired_primary_distribution. It also names the calculation beforehand scaled. IIUC this is all just for better readability but not really addressing the bug (aside from float-->double changes).
ACK
| ceph_assert(fabs(distribution_sum_desired - pool->get_pg_num()) < | ||
| std::max(0.01, (double)pool->get_pg_num() * 1e-4)); |
There was a problem hiding this comment.
Adds more tolerance so the absolute value. ACK
Same with the above assert; I think this is appropriate to change into a debug 10 error message if the condition is not met.
| } | ||
| } | ||
|
|
||
| TEST_F(OSDMapTest, read_balance_large_pg_num) { |
There was a problem hiding this comment.
Tests look good. In addition, verified against the osdmaptool with a map provided in the tracker (this tripped the assert on the old code):
[lflores@folio01 build]$ ./bin/osdmaptool ~/osdmap-60osd-65536pg-pgp60800.bin --read /tmp/read.out --read-pool bigpool
./bin/osdmaptool: osdmap file '/home/lflores/osdmap-60osd-65536pg-pgp60800.bin'
writing upmap command output to: /tmp/read.out
---------- BEFORE ------------
osd.0 | primary affinity: 1 | number of prims: 1040
osd.1 | primary affinity: 1 | number of prims: 1092
osd.2 | primary affinity: 1 | number of prims: 1109
osd.3 | primary affinity: 1 | number of prims: 1132
osd.4 | primary affinity: 1 | number of prims: 1084
osd.5 | primary affinity: 1 | number of prims: 1055
osd.6 | primary affinity: 1 | number of prims: 1100
osd.7 | primary affinity: 1 | number of prims: 1144
osd.8 | primary affinity: 1 | number of prims: 1168
osd.9 | primary affinity: 1 | number of prims: 1078
osd.10 | primary affinity: 1 | number of prims: 1077
osd.11 | primary affinity: 1 | number of prims: 1081
osd.12 | primary affinity: 1 | number of prims: 1101
osd.13 | primary affinity: 1 | number of prims: 1134
osd.14 | primary affinity: 1 | number of prims: 1063
osd.15 | primary affinity: 1 | number of prims: 1069
osd.16 | primary affinity: 1 | number of prims: 1109
osd.17 | primary affinity: 1 | number of prims: 1123
osd.18 | primary affinity: 1 | number of prims: 1073
osd.19 | primary affinity: 1 | number of prims: 1088
osd.20 | primary affinity: 1 | number of prims: 1137
osd.21 | primary affinity: 1 | number of prims: 1073
osd.22 | primary affinity: 1 | number of prims: 1105
osd.23 | primary affinity: 1 | number of prims: 1088
osd.24 | primary affinity: 1 | number of prims: 1155
osd.25 | primary affinity: 1 | number of prims: 1106
osd.26 | primary affinity: 1 | number of prims: 1066
osd.27 | primary affinity: 1 | number of prims: 1081
osd.28 | primary affinity: 1 | number of prims: 1086
osd.29 | primary affinity: 1 | number of prims: 1140
osd.30 | primary affinity: 1 | number of prims: 1047
osd.31 | primary affinity: 1 | number of prims: 1059
osd.32 | primary affinity: 1 | number of prims: 1111
osd.33 | primary affinity: 1 | number of prims: 1072
osd.34 | primary affinity: 1 | number of prims: 1058
osd.35 | primary affinity: 1 | number of prims: 1094
osd.36 | primary affinity: 1 | number of prims: 1080
osd.37 | primary affinity: 1 | number of prims: 1072
osd.38 | primary affinity: 1 | number of prims: 1102
osd.39 | primary affinity: 1 | number of prims: 1136
osd.40 | primary affinity: 1 | number of prims: 1121
osd.41 | primary affinity: 1 | number of prims: 1062
osd.42 | primary affinity: 1 | number of prims: 1136
osd.43 | primary affinity: 1 | number of prims: 1073
osd.44 | primary affinity: 1 | number of prims: 1090
osd.45 | primary affinity: 1 | number of prims: 1063
osd.46 | primary affinity: 1 | number of prims: 1065
osd.47 | primary affinity: 1 | number of prims: 1087
osd.48 | primary affinity: 1 | number of prims: 1082
osd.49 | primary affinity: 1 | number of prims: 1103
osd.50 | primary affinity: 1 | number of prims: 1064
osd.51 | primary affinity: 1 | number of prims: 1072
osd.52 | primary affinity: 1 | number of prims: 1119
osd.53 | primary affinity: 1 | number of prims: 1093
osd.54 | primary affinity: 1 | number of prims: 1093
osd.55 | primary affinity: 1 | number of prims: 1133
osd.56 | primary affinity: 1 | number of prims: 1143
osd.57 | primary affinity: 1 | number of prims: 1044
osd.58 | primary affinity: 1 | number of prims: 1048
osd.59 | primary affinity: 1 | number of prims: 1057
read_balance_score of 'bigpool': 1.07
---------- AFTER ------------
osd.0 | primary affinity: 1 | number of prims: 1101
osd.1 | primary affinity: 1 | number of prims: 1094
osd.2 | primary affinity: 1 | number of prims: 1091
osd.3 | primary affinity: 1 | number of prims: 1107
osd.4 | primary affinity: 1 | number of prims: 1068
osd.5 | primary affinity: 1 | number of prims: 1116
osd.6 | primary affinity: 1 | number of prims: 1095
osd.7 | primary affinity: 1 | number of prims: 1089
osd.8 | primary affinity: 1 | number of prims: 1101
osd.9 | primary affinity: 1 | number of prims: 1107
osd.10 | primary affinity: 1 | number of prims: 1111
osd.11 | primary affinity: 1 | number of prims: 1071
osd.12 | primary affinity: 1 | number of prims: 1077
osd.13 | primary affinity: 1 | number of prims: 1105
osd.14 | primary affinity: 1 | number of prims: 1085
osd.15 | primary affinity: 1 | number of prims: 1073
osd.16 | primary affinity: 1 | number of prims: 1087
osd.17 | primary affinity: 1 | number of prims: 1118
osd.18 | primary affinity: 1 | number of prims: 1077
osd.19 | primary affinity: 1 | number of prims: 1119
osd.20 | primary affinity: 1 | number of prims: 1110
osd.21 | primary affinity: 1 | number of prims: 1102
osd.22 | primary affinity: 1 | number of prims: 1094
osd.23 | primary affinity: 1 | number of prims: 1088
osd.24 | primary affinity: 1 | number of prims: 1120
osd.25 | primary affinity: 1 | number of prims: 1125
osd.26 | primary affinity: 1 | number of prims: 1082
osd.27 | primary affinity: 1 | number of prims: 1084
osd.28 | primary affinity: 1 | number of prims: 1110
osd.29 | primary affinity: 1 | number of prims: 1081
osd.30 | primary affinity: 1 | number of prims: 1074
osd.31 | primary affinity: 1 | number of prims: 1077
osd.32 | primary affinity: 1 | number of prims: 1094
osd.33 | primary affinity: 1 | number of prims: 1069
osd.34 | primary affinity: 1 | number of prims: 1077
osd.35 | primary affinity: 1 | number of prims: 1094
osd.36 | primary affinity: 1 | number of prims: 1066
osd.37 | primary affinity: 1 | number of prims: 1072
osd.38 | primary affinity: 1 | number of prims: 1098
osd.39 | primary affinity: 1 | number of prims: 1110
osd.40 | primary affinity: 1 | number of prims: 1067
osd.41 | primary affinity: 1 | number of prims: 1090
osd.42 | primary affinity: 1 | number of prims: 1114
osd.43 | primary affinity: 1 | number of prims: 1099
osd.44 | primary affinity: 1 | number of prims: 1070
osd.45 | primary affinity: 1 | number of prims: 1078
osd.46 | primary affinity: 1 | number of prims: 1071
osd.47 | primary affinity: 1 | number of prims: 1096
osd.48 | primary affinity: 1 | number of prims: 1095
osd.49 | primary affinity: 1 | number of prims: 1105
osd.50 | primary affinity: 1 | number of prims: 1099
osd.51 | primary affinity: 1 | number of prims: 1073
osd.52 | primary affinity: 1 | number of prims: 1113
osd.53 | primary affinity: 1 | number of prims: 1101
osd.54 | primary affinity: 1 | number of prims: 1069
osd.55 | primary affinity: 1 | number of prims: 1103
osd.56 | primary affinity: 1 | number of prims: 1104
osd.57 | primary affinity: 1 | number of prims: 1094
osd.58 | primary affinity: 1 | number of prims: 1091
osd.59 | primary affinity: 1 | number of prims: 1085
read_balance_score of 'bigpool': 1.03
num changes: 967
calc_desired_primary_distribution_simple() scales the per-OSD desired primary counts so that they sum to pg_num, then re-sums them into a float and asserts the total is within 0.01 of pg_num. The quantity is an algebraic identity, but the float accumulator rounds once per OSD while the tolerance stays absolute, so the accumulated rounding error exceeds 0.01 on large pools and the assert aborts the active mgr's balancer thread. With the balancer in upmap-read or read mode every standby mgr aborts in turn on its next tick, leaving the cluster with no mgr until the balancer mode is changed. At pg_num 65536 a float only resolves 0.0078125, so the 0.01 tolerance is barely more than one rounding step: on a 60-OSD pool of that size the re-sum lands at 65535.98828125 while distribution_sum and factor are still exactly 65536 and 1.0. The sibling ceph_assert(factor >= 1.0) is fragile the same way: with uniform primary affinity 1 the exact factor is 1.0, and rounding in distribution_sum can push the computed value just below it. Compute the stretch factor and both accumulators in double, tolerate tiny negative rounding on factor before clamping it back to 1.0, and scale the sum tolerance with pg_num. Neither condition is worth aborting the process over: when a check still fails, log it at debug level 10 and return -EINVAL, which the caller already treats as "skip this pool" for the current balancer round. The two new tests use OSD count / pg_num combinations (500/32768 and 100/131072) that deterministically trip the old asserts. Fixes: https://tracker.ceph.com/issues/80443 Reported-by: Armsby Li Signed-off-by: Lumir Sliva <[email protected]>
466c2ee to
9425ea2
Compare
Done, both of them. Each check now logs at debug 10 with the pool name, the offending sum and the tolerance, and returns Also the exact numbers from
A float at magnitude 65536 has a resolution of 0.0078125, so the old 0.01 tolerance was barely one rounding step. That's why it trips with every OSD at primary affinity 1. Re-verified with the new commit: |
|
This PR has been added to wip-bharath17-testing-20260919.063401-main. |
With the balancer in
upmap-readorreadmode, the active mgr can abort inthe balancer thread at
in
OSDMap::calc_desired_primary_distribution_simple(). Each standby mgr thenaborts the same way on its own next balancer tick, so the cluster loses all mgr
daemons in a rotating crash loop until the balancer mode is changed. This
happens on perfectly healthy clusters (all PGs active+clean, every OSD at
primary affinity 1) once a pool is large enough.
The asserted quantity is an algebraic identity: the per-OSD desired primary
counts are scaled so that they sum to pg_num, and the assert merely re-sums
them. The re-summation, however, used a float accumulator, which rounds once
per OSD, while the tolerance stayed a fixed absolute 0.01. The accumulated
rounding error grows with both pg_num and OSD count, so the check becomes
progressively unsatisfiable as clusters grow. The sibling
ceph_assert(factor >= 1.0)is fragile the same way: with uniform primaryaffinity 1 the exact factor is 1.0, and rounding can push the computed value
just below it.
Fix: compute the stretch factor and both accumulators in double, tolerate tiny
negative rounding on the factor before clamping it back to 1.0, and scale the
sum tolerance with pg_num. The two new regression tests use OSD count / pg_num
combinations (500/32768 and 100/131072) that deterministically trip the old
asserts.
Validated beyond the unit tests on a 60-OSD vstart cluster with a size-3
pool at pg_num 65536: on an osdmap that trips the old assert, enabling
balancer mode upmap-readaborts the active mgr within one balancer tickwith the reported backtrace, while the patched mgr on the same map
completes the optimization and applies the pg_upmap_primary entries.
Fixes: https://tracker.ceph.com/issues/80443
Checklist