Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/libmongoc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,6 @@ set (MONGOC_SOURCES
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-change-stream.c
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-cmd-deprecated.c
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-find.c
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-find-cmd.c
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-find-opquery.c
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: before closing CDRIVER-4722, set PHP Team Attention Needed: Needed. I expect the file removal will require an update to the PHP driver build listing of source files: https://github.com/mongodb/mongo-php-driver/blob/5bf907601604618556de9698ed26a4b5a4ad54b4/config.m4#L363

${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-legacy.c
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-array.c
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-database.c
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-error.c
Expand Down
82 changes: 8 additions & 74 deletions src/libmongoc/src/mongoc/mongoc-cursor-cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,52 +19,12 @@

#include <mongoc/mongoc.h>

typedef enum { NONE, CMD_RESPONSE, OP_GETMORE_RESPONSE } reading_from_t;
typedef enum { UNKNOWN, GETMORE_CMD, OP_GETMORE } getmore_type_t;
typedef struct _data_cmd_t {
/* Two paths:
* - Mongo 3.2+, sent "getMore" cmd, we're reading reply's "nextBatch" array
* - Mongo 2.6 to 3, after "aggregate" or similar command we sent OP_GETMORE,
* we're reading the raw reply from a stream
*/
mongoc_cursor_response_t response;
mongoc_cursor_response_legacy_t response_legacy;
reading_from_t reading_from;
getmore_type_t getmore_type; /* cache after first getmore. */
bson_t cmd;
} data_cmd_t;


static getmore_type_t
_getmore_type(mongoc_cursor_t *cursor)
{
mongoc_server_stream_t *server_stream;
int32_t wire_version;
data_cmd_t *data = (data_cmd_t *)cursor->impl.data;
if (data->getmore_type != UNKNOWN) {
return data->getmore_type;
}
const mongoc_ss_log_context_t ss_log_context = {
.operation = "getMore", .has_operation_id = true, .operation_id = cursor->operation_id};
server_stream = _mongoc_cursor_fetch_stream(cursor, &ss_log_context);
if (!server_stream) {
return UNKNOWN;
}
wire_version = server_stream->sd->max_wire_version;
mongoc_server_stream_cleanup(server_stream);

// CDRIVER-4722: always GETMORE_CMD once WIRE_VERSION_MIN >=
// WIRE_VERSION_4_2.
if (_mongoc_cursor_use_op_msg(cursor, wire_version)) {
data->getmore_type = GETMORE_CMD;
} else {
data->getmore_type = OP_GETMORE;
}

return data->getmore_type;
}


static mongoc_cursor_state_t
_prime(mongoc_cursor_t *cursor)
{
Expand All @@ -79,7 +39,6 @@ _prime(mongoc_cursor_t *cursor)
/* server replies to aggregate/listIndexes/listCollections with:
* {cursor: {id: N, firstBatch: []}} */
_mongoc_cursor_response_refresh(cursor, &data->cmd, &copied_opts, &data->response);
data->reading_from = CMD_RESPONSE;
bson_destroy(&copied_opts);
return IN_BATCH;
}
Expand All @@ -90,18 +49,8 @@ _pop_from_batch(mongoc_cursor_t *cursor)
{
data_cmd_t *data = (data_cmd_t *)cursor->impl.data;

switch (data->reading_from) {
case CMD_RESPONSE:
_mongoc_cursor_response_read(cursor, &data->response, &cursor->current);
break;
case OP_GETMORE_RESPONSE:
cursor->current = bson_reader_read(data->response_legacy.reader, NULL);
break;
case NONE:
default:
fprintf(stderr, "trying to pop from an uninitialized cursor reader.\n");
BSON_ASSERT(false);
}
_mongoc_cursor_response_read(cursor, &data->response, &cursor->current);

if (cursor->current) {
return IN_BATCH;
} else {
Expand All @@ -115,23 +64,12 @@ _get_next_batch(mongoc_cursor_t *cursor)
{
data_cmd_t *data = (data_cmd_t *)cursor->impl.data;
bson_t getmore_cmd;
getmore_type_t getmore_type = _getmore_type(cursor);

switch (getmore_type) {
case GETMORE_CMD:
_mongoc_cursor_prepare_getmore_command(cursor, &getmore_cmd);
_mongoc_cursor_response_refresh(cursor, &getmore_cmd, NULL /* opts */, &data->response);
bson_destroy(&getmore_cmd);
data->reading_from = CMD_RESPONSE;
return IN_BATCH;
case OP_GETMORE:
_mongoc_cursor_op_getmore(cursor, &data->response_legacy);
data->reading_from = OP_GETMORE_RESPONSE;
return IN_BATCH;
case UNKNOWN:
default:
return DONE;
}

_mongoc_cursor_prepare_getmore_command(cursor, &getmore_cmd);
_mongoc_cursor_response_refresh(cursor, &getmore_cmd, NULL /* opts */, &data->response);
bson_destroy(&getmore_cmd);

return IN_BATCH;
}


Expand All @@ -141,7 +79,6 @@ _destroy(mongoc_cursor_impl_t *impl)
data_cmd_t *data = (data_cmd_t *)impl->data;
bson_destroy(&data->response.reply);
bson_destroy(&data->cmd);
_mongoc_cursor_response_legacy_destroy(&data->response_legacy);
bson_free(data);
}

Expand All @@ -152,7 +89,6 @@ _clone(mongoc_cursor_impl_t *dst, const mongoc_cursor_impl_t *src)
data_cmd_t *data_src = (data_cmd_t *)src->data;
data_cmd_t *data_dst = BSON_ALIGNED_ALLOC0(data_cmd_t);
bson_init(&data_dst->response.reply);
_mongoc_cursor_response_legacy_init(&data_dst->response_legacy);
bson_copy_to(&data_src->cmd, &data_dst->cmd);
dst->data = data_dst;
}
Expand All @@ -173,7 +109,6 @@ _mongoc_cursor_cmd_new(mongoc_client_t *client,
data_cmd_t *data = BSON_ALIGNED_ALLOC0(data_cmd_t);

cursor = _mongoc_cursor_new_with_opts(client, db_and_coll, opts, user_prefs, default_prefs, read_concern);
_mongoc_cursor_response_legacy_init(&data->response_legacy);
_mongoc_cursor_check_and_copy_to(cursor, "command", cmd, &data->cmd);
bson_init(&data->response.reply);
cursor->impl.prime = _prime;
Expand All @@ -194,7 +129,6 @@ _mongoc_cursor_cmd_new_from_reply(mongoc_client_t *client, const bson_t *cmd, co
mongoc_cursor_t *cursor = _mongoc_cursor_cmd_new(client, NULL, cmd, opts, NULL, NULL, NULL);
data_cmd_t *data = (data_cmd_t *)cursor->impl.data;

data->reading_from = CMD_RESPONSE;
cursor->state = IN_BATCH;

bson_destroy(&data->response.reply);
Expand Down
106 changes: 0 additions & 106 deletions src/libmongoc/src/mongoc/mongoc-cursor-find-cmd.c

This file was deleted.

115 changes: 0 additions & 115 deletions src/libmongoc/src/mongoc/mongoc-cursor-find-opquery.c

This file was deleted.

Loading