记一次Mongodb 服务器CPU占用过高的问题排查

某日浏览服务器CPU占用,发现Mongodb的服务器占用CPU达到80%以上。
通过慢查询和当前运行的资源查询,没有找到占用资源过多的查询。
网上爬文也是没有头绪。于是查询Mongodb的日志,发现是日志偏异的警告,并且写日志超时。

2020-11-04T20:26:43.391+0000 W  STORAGE  [FlowControlRefresher] Flow control is engaged and the                   sustainer point is not moving. Please check the health of all secondaries.

这个时候,如果直接以关键字去进行搜索引擎搜索,是查不到任何信息的。根据日志的提示,我们可以知道,问题大概是发生在主从复制上。
于是登录到从服务器查询。服务器架构采用的是replaceSet的架构,主服务器对外提供服务,Secondary服务器用于做数据备份,并没有对外提供服务。

2020-11-06T06:00:28.925+0000 I  CONTROL  [LogicalSessionCacheReap] Failed to reap transaction table: FailedToSatisfyReadPreference: Could not find host matching read preference { mode: "primary" } for set rs1


2020-11-06T06:11:01.675+0000 I  ELECTION [replexec-73] Not starting an election, since we are not electable due to: Not standing for election because I cannot see a majority (mask 0x1)

上述日志,可以说明找不到主库。联想到之前有一次错误的操作过防火墙服务,有可能是此操作导致的找不到主节点。于是重启子节点的Mongodb服务。
重启后,子服务的主从同步正常,主服务器的CPU占用率也下降了。