Skip to content

Commit 94940a5

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 66d759b commit 94940a5

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/main/com/mongodb/MultiServerCluster.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,14 @@ private void onChange(final ChangeEvent<ServerDescription> event) {
123123
boolean shouldUpdateDescription = true;
124124
synchronized (this) {
125125
ServerDescription newDescription = event.getNewValue();
126+
127+
LOGGER.fine(format("Handling description changed event for server %s with description %s",
128+
newDescription.getAddress(), newDescription));
129+
126130
ServerTuple serverTuple = addressToServerTupleMap.get(newDescription.getAddress());
127131
if (serverTuple == null) {
132+
LOGGER.fine(format("Ignoring description changed event for removed server %s",
133+
newDescription.getAddress()));
128134
return;
129135
}
130136

@@ -188,18 +194,26 @@ private boolean handleReplicaSetMemberChanged(final ServerDescription newDescrip
188194
ensureServers(newDescription);
189195

190196
if (newDescription.getCanonicalAddress() != null && !newDescription.getAddress().sameHost(newDescription.getCanonicalAddress())) {
197+
LOGGER.info(format("Canonical address %s does not match server address. Removing %s from client view of cluster",
198+
newDescription.getCanonicalAddress(), newDescription.getAddress()));
191199
removeServer(newDescription.getAddress());
192200
return true;
193201
}
194202

195203
if (newDescription.isPrimary()) {
196204
if (newDescription.getElectionId() != null) {
197205
if (maxElectionId != null && maxElectionId.compareTo(newDescription.getElectionId()) > 0) {
206+
LOGGER.info(format("Invalidating potential primary %s whose election id %s is less than the max election id seen so "
207+
+ "far %s", newDescription.getAddress(), newDescription.getElectionId(), maxElectionId));
198208
addressToServerTupleMap.get(newDescription.getAddress()).server.invalidate();
199209
return false;
200210
}
201211

202-
maxElectionId = newDescription.getElectionId();
212+
if (!newDescription.getElectionId().equals(maxElectionId)) {
213+
LOGGER.info(format("Setting max election id to %s from replica set primary %s", newDescription.getElectionId(),
214+
newDescription.getAddress()));
215+
maxElectionId = newDescription.getElectionId();
216+
}
203217
}
204218

205219
if (isNotAlreadyPrimary(newDescription.getAddress())) {

0 commit comments

Comments
 (0)