Skip to content

Commit 026cec7

Browse files
committed
PR updates
1 parent 3083b64 commit 026cec7

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

driver-core/src/main/com/mongodb/internal/operation/AsyncCommandBatchCursor.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
import static com.mongodb.internal.operation.CommandBatchCursorHelper.MESSAGE_IF_CONCURRENT_OPERATION;
5656
import static com.mongodb.internal.operation.CommandBatchCursorHelper.NEXT_BATCH;
5757
import static com.mongodb.internal.operation.CommandBatchCursorHelper.NO_OP_FIELD_NAME_VALIDATOR;
58-
import static com.mongodb.internal.operation.CommandBatchCursorHelper.getCommandCursorResult;
58+
import static com.mongodb.internal.operation.CommandBatchCursorHelper.logCommandCursorResult;
5959
import static com.mongodb.internal.operation.CommandBatchCursorHelper.getKillCursorsCommand;
6060
import static com.mongodb.internal.operation.CommandBatchCursorHelper.getMoreCommandDocument;
6161
import static com.mongodb.internal.operation.CommandBatchCursorHelper.translateCommandException;
@@ -233,7 +233,9 @@ private void getMoreLoop(final AsyncConnection connection, final ServerCursor se
233233

234234
private CommandCursorResult<T> toCommandCursorResult(final ServerAddress serverAddress, final String fieldNameContainingBatch,
235235
final BsonDocument commandCursorDocument) {
236-
CommandCursorResult<T> commandCursorResult = getCommandCursorResult(serverAddress, fieldNameContainingBatch, commandCursorDocument);
236+
CommandCursorResult<T> commandCursorResult = new CommandCursorResult<>(serverAddress, fieldNameContainingBatch,
237+
commandCursorDocument);
238+
logCommandCursorResult(commandCursorResult);
237239
this.count.addAndGet(commandCursorResult.getResults().size());
238240
return commandCursorResult;
239241
}
@@ -279,7 +281,6 @@ void doClose() {
279281
}
280282

281283
if (getServerCursor() != null) {
282-
// Don't handle corrupted connections
283284
getConnection((connection, t) -> {
284285
if (connection != null) {
285286
releaseServerAndClientResources(connection, (r, t1) -> connection.release());
@@ -299,11 +300,11 @@ <R> void executeWithConnection(final AsyncCallableConnectionWithCallback<R> call
299300
callback.onResult(null, t);
300301
return;
301302
}
302-
callable.call(connection, (result, t1) -> {
303+
callable.call(assertNotNull(connection), (result, t1) -> {
303304
if (t1 instanceof MongoSocketException) {
304305
onCorruptedConnection(connection, (MongoSocketException) t1);
305306
}
306-
assertNotNull(connection).release();
307+
connection.release();
307308
callback.onResult(result, t1);
308309
});
309310
});

driver-core/src/main/com/mongodb/internal/operation/AsyncOperationHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ interface AsyncCallableWithConnection {
6262
}
6363

6464
interface AsyncCallableConnectionWithCallback<T> {
65-
void call(@Nullable AsyncConnection connection, SingleResultCallback<T> callback);
65+
void call(AsyncConnection connection, SingleResultCallback<T> callback);
6666
}
6767

6868
interface AsyncCallableWithSource {

driver-core/src/main/com/mongodb/internal/operation/CommandBatchCursor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
import static com.mongodb.internal.operation.CommandBatchCursorHelper.NEXT_BATCH;
5454
import static com.mongodb.internal.operation.CommandBatchCursorHelper.NO_OP_FIELD_NAME_VALIDATOR;
5555
import static com.mongodb.internal.operation.CommandBatchCursorHelper.getKillCursorsCommand;
56-
import static com.mongodb.internal.operation.CommandBatchCursorHelper.getCommandCursorResult;
56+
import static com.mongodb.internal.operation.CommandBatchCursorHelper.logCommandCursorResult;
5757
import static com.mongodb.internal.operation.CommandBatchCursorHelper.getMoreCommandDocument;
5858
import static com.mongodb.internal.operation.CommandBatchCursorHelper.translateCommandException;
5959

@@ -272,7 +272,9 @@ private void getMore() {
272272

273273
private CommandCursorResult<T> toCommandCursorResult(final ServerAddress serverAddress, final String fieldNameContainingBatch,
274274
final BsonDocument commandCursorDocument) {
275-
CommandCursorResult<T> commandCursorResult = getCommandCursorResult(serverAddress, fieldNameContainingBatch, commandCursorDocument);
275+
CommandCursorResult<T> commandCursorResult = new CommandCursorResult<>(serverAddress, fieldNameContainingBatch,
276+
commandCursorDocument);
277+
logCommandCursorResult(commandCursorResult);
276278
this.nextBatch = commandCursorResult.getResults().isEmpty() ? null : commandCursorResult.getResults();
277279
this.count += commandCursorResult.getResults().size();
278280
return commandCursorResult;
@@ -323,7 +325,6 @@ void doClose() {
323325
}
324326
try {
325327
if (getServerCursor() != null) {
326-
// Don't handle corrupted connections
327328
Connection connection = getConnection();
328329
try {
329330
releaseServerResources(connection);

driver-core/src/main/com/mongodb/internal/operation/CommandBatchCursorHelper.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.mongodb.MongoCursorNotFoundException;
2121
import com.mongodb.MongoNamespace;
2222
import com.mongodb.MongoQueryException;
23-
import com.mongodb.ServerAddress;
2423
import com.mongodb.ServerCursor;
2524
import com.mongodb.connection.ConnectionDescription;
2625
import com.mongodb.internal.validator.NoOpFieldNameValidator;
@@ -70,10 +69,7 @@ static BsonDocument getMoreCommandDocument(
7069
return document;
7170
}
7271

73-
static <T> CommandCursorResult<T> getCommandCursorResult(final ServerAddress serverAddress, final String fieldNameContainingBatch,
74-
final BsonDocument commandCursorDocument) {
75-
CommandCursorResult<T> commandCursorResult = new CommandCursorResult<>(serverAddress, fieldNameContainingBatch,
76-
commandCursorDocument);
72+
static <T> CommandCursorResult<T> logCommandCursorResult(final CommandCursorResult<T> commandCursorResult) {
7773
if (LOGGER.isDebugEnabled()) {
7874
LOGGER.debug(format("Received batch of %d documents with cursorId %d from server %s", commandCursorResult.getResults().size(),
7975
commandCursorResult.getCursorId(), commandCursorResult.getServerAddress()));

0 commit comments

Comments
 (0)