-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: 2.10.0
-
Component/s: None
-
None
-
Developer Tools
Description
sh.status() counts failed balancer rounds by checking details.errorOccured on the last 5 balancer.round entries in config.actionlog. SERVER-56276 (server 5.1.0, commit dd6a29fcd0) fixed the spelling, and the server now writes details.errorOccurred. That commit also updated the legacy shell (src/mongo/shell/utils_sh.js), but mongosh never got the same change.
So with any server from 5.1 on, including all current LTS releases (6.0, 7.0, 8.0), sh.status() always shows 'Failed balancer rounds in last 5 attempts': 0 and never shows Last reported error or Time of Reported error. This happens even when every recent balancer round has failed.
The check was added in commit 0beb56c8 (MONGOSH-638, released in v0.5.0) and is unchanged on main, in packages/shell-api/src/helpers.ts:
if (r.details.errorOccured) {
Affected versions
| Server | Field written | Legacy mongo shell | mongosh (any version) |
|---|---|---|---|
| ≤ 5.0.x | errorOccured | correct | correct |
| 5.1 and later (6.0, 7.0, 8.0) | errorOccurred | correct 5.1–5.3 (removed in 6.0) | always 0 |
- mongosh: every version from 0.5.0 on. Confirmed on 2.8.x, 2.9.x and 2.10.0.
- Server: confirmed on Percona Server for MongoDB 8.0.34-15, whose mongod binary only contains the string errorOccurred.
Steps to reproduce
- Deploy a sharded cluster on 6.0+ with 3 shards.
- Shard a collection, e.g. sh.shardCollection("percona.percona", {"user.name": 1}), and load data (we used 5M docs). Lower chunksize so the balancer has work to do.
- Make one shard's primary unavailable (we stopped the only node of shard sh03).
- Wait for a few balancer rounds (about 2 minutes).
- Check the actionlog:{{{}db.getSiblingDB("config").actionlog.find(
{what: "balancer.round"}, {_id: 0, time: 1, details: 1}
).sort({time: -1}).limit(5){}}}All 5 entries have errorOccurred: true and errmsg: 'Could not find host matching read preference { mode: "primary" } for set sh03'. - Run sh.status().
Expected vs actual
Expected
{{balancer: {
'Failed balancer rounds in last 5 attempts': 5,
'Last reported error': 'Could not find host ...',
'Time of Reported error': ISODate(...),
...
}}}
Actual
{{balancer: {
'Currently enabled': 'yes',
'Failed balancer rounds in last 5 attempts': 0,
...
}}}
Counting the same 5 documents both ways:
{{const a = db.getSiblingDB("config").actionlog
.find({what: "balancer.round"}).sort({time: -1}).limit(5).toArray();
({ errorOccured: a.filter(d => d.details.errorOccured).length, // 0 <- what mongosh checks
errorOccurred: a.filter(d => d.details.errorOccurred).length }) // 5 <- what the server writes}}
Suggested fix
Accept both spellings so the check keeps working against 5.0 and older servers:
if (r.details.errorOccurred || r.details.errorOccured) {
References
SERVER-56276: correct typo in config.actionlog document field (commit dd6a29fcd0, first released in r5.1.0)MONGOSH-638: Enable sharding methods (commit 0beb56c8)- mongosh helpers.ts on main
Let me know if you need more information