@@ -180,10 +180,15 @@ static boolean clientMetadataDocumentTooLarge(final BsonDocument document) {
180
180
new BsonDocumentCodec ().encode (new BsonBinaryWriter (buffer ), document , EncoderContext .builder ().build ());
181
181
return buffer .getPosition () > MAXIMUM_CLIENT_METADATA_ENCODED_SIZE ;
182
182
}
183
-
183
+ /**
184
+ * Modifies the given client metadata document by appending the driver information.
185
+ * Driver name and version are appended atomically to the existing driver name and version if they do not exceed
186
+ * {@value MAXIMUM_CLIENT_METADATA_ENCODED_SIZE} bytes.
187
+ *
188
+ * Platform is appended separately to the existing platform if it does not exceed {@value MAXIMUM_CLIENT_METADATA_ENCODED_SIZE} bytes.
189
+ */
184
190
public static BsonDocument updateClientMedataDocument (final BsonDocument clientMetadataDocument ,
185
191
final MongoDriverInformation mongoDriverInformation ) {
186
- BsonDocument updatedClientMetadataDocument = clientMetadataDocument .clone ();
187
192
BsonDocument driverInformation = clientMetadataDocument .getDocument ("driver" );
188
193
189
194
List <String > driverNamesToAppend = mongoDriverInformation .getDriverNames ();
@@ -203,14 +208,14 @@ public static BsonDocument updateClientMedataDocument(final BsonDocument clientM
203
208
updateDriverPlatforms .add (clientMetadataDocument .getString ("platform" ).getValue ());
204
209
updateDriverPlatforms .addAll (driverPlatformsToAppend );
205
210
206
- tryWithLimit (updatedClientMetadataDocument , d -> {
211
+ tryWithLimit (clientMetadataDocument , d -> {
207
212
putAtPath (d , "driver.name" , listToString (updatedDriverNames ));
208
213
putAtPath (d , "driver.version" , listToString (updatedDriverVersions ));
209
214
});
210
- tryWithLimit (updatedClientMetadataDocument , d -> {
215
+ tryWithLimit (clientMetadataDocument , d -> {
211
216
putAtPath (d , "platform" , listToString (updateDriverPlatforms ));
212
217
});
213
- return updatedClientMetadataDocument ;
218
+ return clientMetadataDocument ;
214
219
}
215
220
216
221
public enum ContainerRuntime {
0 commit comments