我不得不为一个mongo DB写一个基本的健康检查,在筛选他们的官方docs和其他资源(如this和this)时,我了解到ping命令是可行的(bc它是轻量级的)。现在我的问题是ping命令的响应是否总是{ok: 1}?在什么情况下,ping响应会返回{ok:0}?有人能解释一下吗?目前,我已经实现了捕获如下所示的异常,但是ping响应将返回OK:0的情况会出现吗
val command: Document = new Document("ping", 1)
// ping the db
val pingResponse = mongoClient.getDatabase("DBNAME").runCommand(command)
// check for the ping response to be {"ok": 1.0 }
if (pingResponse.get("ok").equals(1.0)) { // IS THIS CONDITION NEEDED ?
// WILL THIS BE EVER OK:0 ?
// return healthy
} else {
// DO I NEED THIS CONDITION? EVER?? TO RETURN UNHEALTHY?
// return unHealthy
}
} catch {
case e: Exception =>
// MUCH NEEDED UNHEALTHY CONDITION
// return unHealthy谢谢。
发布于 2021-01-07 13:33:03
如果在无限循环中运行ping并停止服务器,可能会得到InterruptedAtShutdown (代码11600)。
https://stackoverflow.com/questions/65575223
复制相似问题