Skip to content

Commit 5163aaf

Browse files
committed
JAVA-2051: Add additional logging to MultiServerCluster
* Log all description changed events * Log when an event is ignored from a server that is no longer part of the cluster * Log when an event is ignored from a server whose canonical address does not match * Log when an event is ignored from a primary with an old election id * Log when the max election id changes.
1 parent ada96e7 commit 5163aaf

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

driver-core/src/main/com/mongodb/connection/MultiServerCluster.java

+22
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,18 @@ private void onChange(final ChangeEvent<ServerDescription> event) {
129129
boolean shouldUpdateDescription = true;
130130
synchronized (this) {
131131
ServerDescription newDescription = event.getNewValue();
132+
133+
if (LOGGER.isTraceEnabled()) {
134+
LOGGER.trace(format("Handling description changed event for server %s with description %s",
135+
newDescription.getAddress(), newDescription));
136+
}
137+
132138
ServerTuple serverTuple = addressToServerTupleMap.get(newDescription.getAddress());
133139
if (serverTuple == null) {
140+
if (LOGGER.isTraceEnabled()) {
141+
LOGGER.trace(format("Ignoring description changed event for removed server %s",
142+
newDescription.getAddress()));
143+
}
134144
return;
135145
}
136146

@@ -197,17 +207,29 @@ private boolean handleReplicaSetMemberChanged(final ServerDescription newDescrip
197207
ensureServers(newDescription);
198208

199209
if (newDescription.getCanonicalAddress() != null && !newDescription.getAddress().sameHost(newDescription.getCanonicalAddress())) {
210+
if (LOGGER.isInfoEnabled()) {
211+
LOGGER.info(format("Canonical address %s does not match server address. Removing %s from client view of cluster",
212+
newDescription.getCanonicalAddress(), newDescription.getAddress()));
213+
}
200214
removeServer(newDescription.getAddress());
201215
return true;
202216
}
203217

204218
if (newDescription.isPrimary()) {
205219
if (newDescription.getElectionId() != null) {
206220
if (maxElectionId != null && maxElectionId.compareTo(newDescription.getElectionId()) > 0) {
221+
if (LOGGER.isInfoEnabled()) {
222+
LOGGER.info(format("Invalidating potential primary %s whose election id %s is less than the max election id seen "
223+
+ "so far %s", newDescription.getAddress(), newDescription.getElectionId(), maxElectionId));
224+
}
207225
addressToServerTupleMap.get(newDescription.getAddress()).server.invalidate();
208226
return false;
209227
}
210228

229+
if (LOGGER.isInfoEnabled()) {
230+
LOGGER.info(format("Setting max election id to %s from replica set primary %s", newDescription.getElectionId(),
231+
newDescription.getAddress()));
232+
}
211233
maxElectionId = newDescription.getElectionId();
212234
}
213235

0 commit comments

Comments
 (0)