Skip to content

Commit f2bd51e

Browse files
authored
Skip nodeset update on relayed isMaster response (ReactiveMongo#1235)
1 parent 5903f48 commit f2bd51e

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

driver/src/main/scala/core/actors/MongoDBSystem.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,8 +1317,8 @@ private[reactivemongo] trait MongoDBSystem extends Actor { selfSystem =>
13171317

13181318
val updated = {
13191319
val respTo = response.header.responseTo
1320-
@inline def event =
1321-
s"IsMaster(${isMaster.isMaster}, ${respTo}, ${_nodeSet.toShortString})"
1320+
1321+
@inline def event = s"IsMasterResponse(${isMaster.isMaster}, ${respTo}, ${_nodeSet.toShortString})"
13221322

13231323
updateNodeSet(event) { nodeSet =>
13241324
val nodeSetWasReachable = nodeSet.isReachable
@@ -1327,8 +1327,14 @@ private[reactivemongo] trait MongoDBSystem extends Actor { selfSystem =>
13271327
val nanow = System.nanoTime()
13281328

13291329
// Update the details of the node corresponding to the response chan
1330-
val prepared =
1331-
nodeSet.updateNodeByChannelId(response.info.channelId) { node =>
1330+
import nodeSet.{updateNodeByChannelId=>updateNode}
1331+
1332+
val prepared = updateNode(response.info.channelId) { node =>
1333+
if (respTo < node.pingInfo.lastIsMasterId) {
1334+
warn(s"Skip node update for delated response #$respTo < last #${node.pingInfo.lastIsMasterId}")
1335+
1336+
node
1337+
} else {
13321338
val pingTime: Long = {
13331339
if (node.pingInfo.lastIsMasterId == respTo) {
13341340
nanow - node.pingInfo.lastIsMasterTime
@@ -1389,6 +1395,7 @@ private[reactivemongo] trait MongoDBSystem extends Actor { selfSystem =>
13891395

13901396
n
13911397
}
1398+
}
13921399

13931400
val discoveredNodes = isMaster.replicaSet.toSeq.flatMap {
13941401
_.hosts.collect {

driver/src/main/scala/core/nodeset/Node.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,15 @@ private[reactivemongo] final class Node(
195195
}
196196

197197
lazy val toShortString = {
198-
def latency = {
199-
import pingInfo.{ ping => ns }
200-
198+
def hns(ns: Long): String = {
201199
if (ns < 1000L) s"${ns.toString}ns"
202200
else if (ns < 100000000L) s"${(ns / 1000000L).toString}ms"
203201
else s"${(ns / 1000000000L).toString}s"
204202
}
205203

206-
s"""Node[$name: $status<${statusChanged}ns> (${authenticatedConnections.size}/${connected.size}/${connections
204+
s"""Node[$name: $status<${hns(statusChanged)}> (${authenticatedConnections.size}/${connected.size}/${connections
207205
.filterNot(_.signaling)
208-
.size} available connections), latency=${latency}, authenticated={${authenticated
206+
.size} available connections), latency=${hns(pingInfo.ping)}, authenticated={${authenticated
209207
.map(_.toShortString) mkString ", "}}]"""
210208
}
211209

0 commit comments

Comments
 (0)