@@ -117,8 +117,6 @@ private void onChange(final ChangeEvent<ServerDescription> event) {
117
117
return ;
118
118
}
119
119
120
- serverTuple .description = newDescription ;
121
-
122
120
if (event .getNewValue ().isOk ()) {
123
121
if (clusterType == Unknown ) {
124
122
clusterType = newDescription .getClusterType ();
@@ -139,6 +137,8 @@ private void onChange(final ChangeEvent<ServerDescription> event) {
139
137
break ;
140
138
}
141
139
}
140
+
141
+ serverTuple .description = newDescription ;
142
142
updateDescription ();
143
143
}
144
144
fireChangeEvent ();
@@ -178,10 +178,18 @@ private void handleReplicaSetMemberChanged(final ServerDescription newDescriptio
178
178
}
179
179
180
180
if (newDescription .isPrimary ()) {
181
+ if (isNotAlreadyPrimary (newDescription .getAddress ())) {
182
+ LOGGER .info (format ("Discovered replica set primary %s" , newDescription .getAddress ()));
183
+ }
181
184
invalidateOldPrimaries (newDescription .getAddress ());
182
185
}
183
186
}
184
187
188
+ private boolean isNotAlreadyPrimary (final ServerAddress address ) {
189
+ ServerTuple serverTuple = addressToServerTupleMap .get (address );
190
+ return serverTuple == null || !serverTuple .description .isPrimary ();
191
+ }
192
+
185
193
private void handleShardRouterChanged (final ServerDescription newDescription ) {
186
194
if (newDescription .getClusterType () != Sharded ) {
187
195
LOGGER .severe (format ("Expecting a %s, but found a %s. Removing %s from client view of cluster." ,
@@ -213,7 +221,6 @@ private void removeServer(final ServerAddress serverAddress) {
213
221
}
214
222
215
223
private void invalidateOldPrimaries (final ServerAddress newPrimary ) {
216
- LOGGER .info (format ("Replica set primary has changed to %s" , newPrimary ));
217
224
for (ServerTuple serverTuple : addressToServerTupleMap .values ()) {
218
225
if (!serverTuple .description .getAddress ().equals (newPrimary ) && serverTuple .description .isPrimary ()) {
219
226
LOGGER .info (format ("Rediscovering type of existing primary %s" , serverTuple .description .getAddress ()));
0 commit comments