Skip to content

Commit e536028

Browse files
committed
Remove MongoDB 3.4 support
* Remove wire version check for including cursor field in aggregate command * Remove wire version check for retryable reads and writes * Remove wire version check for use OP_INSERT/UPDATE/DELETE for unacknowledged writes * Remove dead code that supported OP_INSERT/UPDATE/DELETE * Simplify CommandMessage to assume OP_QUERY is not used with payloads (because it's not only used to send the isMaster command) JAVA-4299
1 parent 1213bcf commit e536028

File tree

50 files changed

+104
-2335
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+104
-2335
lines changed

.evergreen/.evg.yml

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,10 +1503,6 @@ axes:
15031503
display_name: "3.6"
15041504
variables:
15051505
VERSION: "3.6"
1506-
- id: "3.4"
1507-
display_name: "3.4"
1508-
variables:
1509-
VERSION: "3.4"
15101506
- id: os
15111507
display_name: OS
15121508
values:
@@ -1689,18 +1685,14 @@ buildvariants:
16891685
- name: "static-analysis"
16901686

16911687
- matrix_name: "tests-zlib-compression"
1692-
matrix_spec: { compressor : "zlib", auth: "noauth", ssl: "nossl", jdk: "jdk8",
1693-
version: ["3.6", "4.0", "4.2", "4.4", "5.0", "6.0", "latest"],
1694-
topology: "standalone", os: "linux" }
1688+
matrix_spec: { compressor : "zlib", auth: "noauth", ssl: "nossl", jdk: "jdk8", version: "*", topology: "standalone", os: "linux" }
16951689
display_name: "${version} ${compressor} ${topology} ${auth} ${ssl} ${jdk} ${os} "
16961690
tags: ["tests-variant"]
16971691
tasks:
16981692
- name: "test"
16991693

17001694
- matrix_name: "tests-snappy-compression"
1701-
matrix_spec: { compressor : "snappy", auth: "noauth", ssl: "nossl", jdk: "jdk8",
1702-
version: ["3.4", "3.6", "4.0", "4.2", "4.4", "5.0", "6.0", "latest"],
1703-
topology: "standalone", os: "linux" }
1695+
matrix_spec: { compressor : "snappy", auth: "noauth", ssl: "nossl", jdk: "jdk8", version: "*", topology: "standalone", os: "linux" }
17041696
display_name: "${version} ${compressor} ${topology} ${auth} ${ssl} ${jdk} ${os} "
17051697
tags: ["tests-variant"]
17061698
tasks:
@@ -1715,13 +1707,6 @@ buildvariants:
17151707
tasks:
17161708
- name: "test"
17171709

1718-
- matrix_name: "tests-jdk8-unsecure"
1719-
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: "jdk8", version: ["3.4"], topology: "*", os: "linux" }
1720-
display_name: "${version} ${topology} ${auth} ${ssl} ${jdk} ${os} "
1721-
tags: ["tests-variant"]
1722-
tasks:
1723-
- name: "test"
1724-
17251710
- matrix_name: "tests-jdk8-unsecure-standalone"
17261711
matrix_spec: { auth: "noauth", ssl: "nossl", jdk: "jdk8", version: ["3.6", "4.0", "4.2", "4.4", "5.0", "6.0", "latest"],
17271712
topology: "standalone", os: "linux" }

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public class ServerDescription {
5252
* The minimum supported driver server version
5353
* @since 3.8
5454
*/
55-
public static final String MIN_DRIVER_SERVER_VERSION = "3.4";
55+
public static final String MIN_DRIVER_SERVER_VERSION = "3.6";
5656
/**
5757
* The minimum supported driver wire version
5858
* @since 3.8
5959
*/
60-
public static final int MIN_DRIVER_WIRE_VERSION = 5;
60+
public static final int MIN_DRIVER_WIRE_VERSION = 6;
6161
/**
6262
* The maximum supported driver wire version
6363
* @since 3.8

driver-core/src/main/com/mongodb/internal/connection/AsyncConnection.java

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@
1616

1717
package com.mongodb.internal.connection;
1818

19-
import com.mongodb.MongoNamespace;
2019
import com.mongodb.ReadPreference;
2120
import com.mongodb.RequestContext;
2221
import com.mongodb.ServerApi;
23-
import com.mongodb.WriteConcernResult;
2422
import com.mongodb.annotations.ThreadSafe;
2523
import com.mongodb.connection.ConnectionDescription;
2624
import com.mongodb.internal.async.SingleResultCallback;
2725
import com.mongodb.internal.binding.ReferenceCounted;
28-
import com.mongodb.internal.bulk.DeleteRequest;
29-
import com.mongodb.internal.bulk.InsertRequest;
30-
import com.mongodb.internal.bulk.UpdateRequest;
3126
import com.mongodb.internal.session.SessionContext;
3227
import org.bson.BsonDocument;
3328
import org.bson.FieldNameValidator;
@@ -55,36 +50,6 @@ public interface AsyncConnection extends ReferenceCounted {
5550
*/
5651
ConnectionDescription getDescription();
5752

58-
/**
59-
* Insert the documents using the insert wire protocol and apply the write concern asynchronously.
60-
* @param namespace the namespace
61-
* @param ordered whether the writes are ordered
62-
* @param insertRequest the insert request
63-
* @param callback the callback to be passed the write result
64-
*/
65-
void insertAsync(MongoNamespace namespace, boolean ordered, InsertRequest insertRequest, RequestContext requestContext,
66-
SingleResultCallback<WriteConcernResult> callback);
67-
68-
/**
69-
* Update the documents using the update wire protocol and apply the write concern asynchronously.
70-
* @param namespace the namespace
71-
* @param ordered whether the writes are ordered
72-
* @param updateRequest the update request
73-
* @param callback the callback to be passed the write result
74-
*/
75-
void updateAsync(MongoNamespace namespace, boolean ordered, UpdateRequest updateRequest, RequestContext requestContext,
76-
SingleResultCallback<WriteConcernResult> callback);
77-
78-
/**
79-
* Delete the documents using the delete wire protocol and apply the write concern asynchronously.
80-
* @param namespace the namespace
81-
* @param ordered whether the writes are ordered
82-
* @param deleteRequest the delete request
83-
* @param callback the callback to be passed the write result
84-
*/
85-
void deleteAsync(MongoNamespace namespace, boolean ordered, DeleteRequest deleteRequest, RequestContext requestContext,
86-
SingleResultCallback<WriteConcernResult> callback);
87-
8853
/**
8954
* Execute the command.
9055
*

driver-core/src/main/com/mongodb/internal/connection/CommandHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ private static CommandMessage getCommandMessage(final String database, final Bso
112112
// Note: server version will be 0.0 at this point when called from InternalConnectionInitializer,
113113
// which means OP_MSG will not be used
114114
.maxWireVersion(internalConnection.getDescription().getMaxWireVersion())
115+
.serverType(internalConnection.getDescription().getServerType())
115116
.build(),
116117
clusterConnectionMode, serverApi);
117118
}

driver-core/src/main/com/mongodb/internal/connection/CommandMessage.java

Lines changed: 10 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import com.mongodb.ServerApi;
2323
import com.mongodb.connection.ClusterConnectionMode;
2424
import com.mongodb.internal.session.SessionContext;
25-
import com.mongodb.internal.validator.MappedFieldNameValidator;
2625
import com.mongodb.lang.Nullable;
2726
import org.bson.BsonArray;
2827
import org.bson.BsonBinaryWriter;
@@ -31,16 +30,12 @@
3130
import org.bson.BsonElement;
3231
import org.bson.BsonInt64;
3332
import org.bson.BsonString;
34-
import org.bson.BsonWriter;
3533
import org.bson.FieldNameValidator;
36-
import org.bson.codecs.EncoderContext;
3734
import org.bson.io.BsonOutput;
3835

3936
import java.nio.charset.StandardCharsets;
4037
import java.util.ArrayList;
41-
import java.util.HashMap;
4238
import java.util.List;
43-
import java.util.Map;
4439

4540
import static com.mongodb.ReadPreference.primary;
4641
import static com.mongodb.ReadPreference.primaryPreferred;
@@ -117,7 +112,7 @@ BsonDocument getCommandDocument(final ByteBufferBsonOutput bsonOutput) {
117112
getEncodingMetadata().getFirstDocumentPosition());
118113
BsonDocument commandBsonDocument;
119114

120-
if (useOpMsg() && containsPayload()) {
115+
if (containsPayload()) {
121116
commandBsonDocument = byteBufBsonDocument.toBaseBsonDocument();
122117

123118
int payloadStartPosition = getEncodingMetadata().getFirstDocumentPosition()
@@ -131,10 +126,7 @@ BsonDocument getCommandDocument(final ByteBufferBsonOutput bsonOutput) {
131126
commandBsonDocument = byteBufBsonDocument;
132127
}
133128

134-
if (commandBsonDocument.containsKey("$query")) {
135-
commandBsonDocument = commandBsonDocument.getDocument("$query");
136-
}
137-
return commandBsonDocument;
129+
return commandBsonDocument;
138130
}
139131

140132
boolean containsPayload() {
@@ -160,7 +152,7 @@ protected EncodingMetadata encodeMessageBodyWithMetadata(final BsonOutput bsonOu
160152
bsonOutput.writeByte(0); // payload type
161153
commandStartPosition = bsonOutput.getPosition();
162154

163-
addDocument(getCommandToEncode(), bsonOutput, commandFieldNameValidator, getExtraElements(sessionContext));
155+
addDocument(command, bsonOutput, commandFieldNameValidator, getExtraElements(sessionContext));
164156

165157
if (payload != null) {
166158
bsonOutput.writeByte(1); // payload type
@@ -177,48 +169,24 @@ protected EncodingMetadata encodeMessageBodyWithMetadata(final BsonOutput bsonOu
177169
// Write the flag bits
178170
bsonOutput.writeInt32(flagPosition, getOpMsgFlagBits());
179171
} else {
180-
bsonOutput.writeInt32(getOpQueryFlagBits());
172+
bsonOutput.writeInt32(0);
181173
bsonOutput.writeCString(namespace.getFullName());
182174
bsonOutput.writeInt32(0);
183175
bsonOutput.writeInt32(-1);
184176

185177
commandStartPosition = bsonOutput.getPosition();
186178

187-
if (payload == null) {
188-
List<BsonElement> elements = null;
189-
if (serverApi != null) {
190-
elements = new ArrayList<>(3);
191-
addServerApiElements(elements);
192-
}
193-
addDocument(getCommandToEncode(), bsonOutput, commandFieldNameValidator, elements);
194-
} else {
195-
// We're not concerned with adding ServerApi elements here. The only reason we do it for OP_QUERY-based commands is that
196-
// OP_QUERY is always used for the handshake, and we have to pass ServerApi elements in the handshake. Other than that,
197-
// all servers that support ServerApi also support OP_MSG, so this code path should never be hit.
198-
addDocumentWithPayload(bsonOutput, messageStartPosition);
179+
List<BsonElement> elements = null;
180+
if (serverApi != null) {
181+
elements = new ArrayList<>(3);
182+
addServerApiElements(elements);
199183
}
184+
addDocument(command, bsonOutput, commandFieldNameValidator, elements);
200185
}
201186
return new EncodingMetadata(commandStartPosition);
202187
}
203188

204-
private FieldNameValidator getPayloadArrayFieldNameValidator() {
205-
Map<String, FieldNameValidator> rootMap = new HashMap<String, FieldNameValidator>();
206-
rootMap.put(payload.getPayloadName(), payloadFieldNameValidator);
207-
return new MappedFieldNameValidator(commandFieldNameValidator, rootMap);
208-
}
209-
210-
private void addDocumentWithPayload(final BsonOutput bsonOutput, final int messageStartPosition) {
211-
BsonBinaryWriter bsonBinaryWriter = new BsonBinaryWriter(bsonOutput, getPayloadArrayFieldNameValidator());
212-
BsonWriter bsonWriter = new SplittablePayloadBsonWriter(bsonBinaryWriter, bsonOutput, messageStartPosition, getSettings(), payload);
213-
BsonDocument commandToEncode = getCommandToEncode();
214-
getCodec(commandToEncode).encode(bsonWriter, commandToEncode, EncoderContext.builder().build());
215-
}
216-
217189
private int getOpMsgFlagBits() {
218-
return getOpMsgResponseExpectedFlagBit();
219-
}
220-
221-
private int getOpMsgResponseExpectedFlagBit() {
222190
int flagBits = 0;
223191
if (!requireOpMsgResponse()) {
224192
flagBits = 1 << 1;
@@ -237,22 +205,6 @@ private boolean requireOpMsgResponse() {
237205
}
238206
}
239207

240-
private int getOpQueryFlagBits() {
241-
return getOpQuerySecondaryOkFlagBit();
242-
}
243-
244-
private int getOpQuerySecondaryOkFlagBit() {
245-
if (isSecondaryOk()) {
246-
return 1 << 2;
247-
} else {
248-
return 0;
249-
}
250-
}
251-
252-
private boolean isSecondaryOk() {
253-
return (readPreference != null && readPreference.isSecondaryOk()) || isDirectConnectionToReplicaSetMember();
254-
}
255-
256208
private boolean isDirectConnectionToReplicaSetMember() {
257209
return clusterConnectionMode == SINGLE
258210
&& getSettings().getServerType() != SHARD_ROUTER
@@ -263,16 +215,8 @@ private boolean useOpMsg() {
263215
return getOpCode().equals(OpCode.OP_MSG);
264216
}
265217

266-
private BsonDocument getCommandToEncode() {
267-
BsonDocument commandToEncode = command;
268-
if (!useOpMsg() && readPreference != null && !readPreference.equals(primary())) {
269-
commandToEncode = new BsonDocument("$query", command).append("$readPreference", readPreference.toDocument());
270-
}
271-
return commandToEncode;
272-
}
273-
274218
private List<BsonElement> getExtraElements(final SessionContext sessionContext) {
275-
List<BsonElement> extraElements = new ArrayList<BsonElement>();
219+
List<BsonElement> extraElements = new ArrayList<>();
276220
extraElements.add(new BsonElement("$db", new BsonString(new MongoNamespace(getCollectionName()).getDatabaseName())));
277221
if (sessionContext.getClusterTime() != null) {
278222
extraElements.add(new BsonElement("$clusterTime", sessionContext.getClusterTime()));
@@ -345,5 +289,4 @@ private static OpCode getOpCode(final MessageSettings settings, final ClusterCon
345289
private static boolean isServerVersionAtLeastThreeDotSix(final MessageSettings settings) {
346290
return settings.getMaxWireVersion() >= THREE_DOT_SIX_WIRE_VERSION;
347291
}
348-
349292
}

driver-core/src/main/com/mongodb/internal/connection/Connection.java

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,12 @@
1616

1717
package com.mongodb.internal.connection;
1818

19-
import com.mongodb.MongoNamespace;
2019
import com.mongodb.ReadPreference;
2120
import com.mongodb.RequestContext;
2221
import com.mongodb.ServerApi;
23-
import com.mongodb.WriteConcernResult;
2422
import com.mongodb.annotations.ThreadSafe;
2523
import com.mongodb.connection.ConnectionDescription;
2624
import com.mongodb.internal.binding.ReferenceCounted;
27-
import com.mongodb.internal.bulk.DeleteRequest;
28-
import com.mongodb.internal.bulk.InsertRequest;
29-
import com.mongodb.internal.bulk.UpdateRequest;
3025
import com.mongodb.internal.session.SessionContext;
3126
import org.bson.BsonDocument;
3227
import org.bson.FieldNameValidator;
@@ -55,39 +50,6 @@ public interface Connection extends ReferenceCounted {
5550
*/
5651
ConnectionDescription getDescription();
5752

58-
/**
59-
* Insert the documents using the insert wire protocol and apply the write concern.
60-
*
61-
* @param namespace the namespace
62-
* @param ordered whether the writes are ordered
63-
* @param insertRequest the insert request
64-
* @param requestContext the request context
65-
* @return the write concern result
66-
*/
67-
WriteConcernResult insert(MongoNamespace namespace, boolean ordered, InsertRequest insertRequest, RequestContext requestContext);
68-
69-
/**
70-
* Update the documents using the update wire protocol and apply the write concern.
71-
*
72-
* @param namespace the namespace
73-
* @param ordered whether the writes are ordered
74-
* @param updateRequest the update request
75-
* @param requestContext the request context
76-
* @return the write concern result
77-
*/
78-
WriteConcernResult update(MongoNamespace namespace, boolean ordered, UpdateRequest updateRequest, RequestContext requestContext);
79-
80-
/**
81-
* Delete the documents using the delete wire protocol and apply the write concern.
82-
*
83-
* @param namespace the namespace
84-
* @param ordered whether the writes are ordered
85-
* @param deleteRequest the delete request
86-
* @param requestContext the request context
87-
* @return the write concern result
88-
*/
89-
WriteConcernResult delete(MongoNamespace namespace, boolean ordered, DeleteRequest deleteRequest, RequestContext requestContext);
90-
9153
/**
9254
* Execute the command.
9355
*

0 commit comments

Comments
 (0)