Skip to content

Commit 04771de

Browse files
authored
CDRIVER-4722 remove cursor support for legacy opcodes (#2112)
1 parent a7acf25 commit 04771de

File tree

9 files changed

+75
-1327
lines changed

9 files changed

+75
-1327
lines changed

src/libmongoc/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,6 @@ set (MONGOC_SOURCES
568568
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-change-stream.c
569569
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-cmd-deprecated.c
570570
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-find.c
571-
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-find-cmd.c
572-
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-find-opquery.c
573-
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-legacy.c
574571
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-cursor-array.c
575572
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-database.c
576573
${PROJECT_SOURCE_DIR}/src/mongoc/mongoc-error.c

src/libmongoc/src/mongoc/mongoc-cursor-cmd.c

Lines changed: 8 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,12 @@
1919

2020
#include <mongoc/mongoc.h>
2121

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

3727

38-
static getmore_type_t
39-
_getmore_type(mongoc_cursor_t *cursor)
40-
{
41-
mongoc_server_stream_t *server_stream;
42-
int32_t wire_version;
43-
data_cmd_t *data = (data_cmd_t *)cursor->impl.data;
44-
if (data->getmore_type != UNKNOWN) {
45-
return data->getmore_type;
46-
}
47-
const mongoc_ss_log_context_t ss_log_context = {
48-
.operation = "getMore", .has_operation_id = true, .operation_id = cursor->operation_id};
49-
server_stream = _mongoc_cursor_fetch_stream(cursor, &ss_log_context);
50-
if (!server_stream) {
51-
return UNKNOWN;
52-
}
53-
wire_version = server_stream->sd->max_wire_version;
54-
mongoc_server_stream_cleanup(server_stream);
55-
56-
// CDRIVER-4722: always GETMORE_CMD once WIRE_VERSION_MIN >=
57-
// WIRE_VERSION_4_2.
58-
if (_mongoc_cursor_use_op_msg(cursor, wire_version)) {
59-
data->getmore_type = GETMORE_CMD;
60-
} else {
61-
data->getmore_type = OP_GETMORE;
62-
}
63-
64-
return data->getmore_type;
65-
}
66-
67-
6828
static mongoc_cursor_state_t
6929
_prime(mongoc_cursor_t *cursor)
7030
{
@@ -79,7 +39,6 @@ _prime(mongoc_cursor_t *cursor)
7939
/* server replies to aggregate/listIndexes/listCollections with:
8040
* {cursor: {id: N, firstBatch: []}} */
8141
_mongoc_cursor_response_refresh(cursor, &data->cmd, &copied_opts, &data->response);
82-
data->reading_from = CMD_RESPONSE;
8342
bson_destroy(&copied_opts);
8443
return IN_BATCH;
8544
}
@@ -90,18 +49,8 @@ _pop_from_batch(mongoc_cursor_t *cursor)
9049
{
9150
data_cmd_t *data = (data_cmd_t *)cursor->impl.data;
9251

93-
switch (data->reading_from) {
94-
case CMD_RESPONSE:
95-
_mongoc_cursor_response_read(cursor, &data->response, &cursor->current);
96-
break;
97-
case OP_GETMORE_RESPONSE:
98-
cursor->current = bson_reader_read(data->response_legacy.reader, NULL);
99-
break;
100-
case NONE:
101-
default:
102-
fprintf(stderr, "trying to pop from an uninitialized cursor reader.\n");
103-
BSON_ASSERT(false);
104-
}
52+
_mongoc_cursor_response_read(cursor, &data->response, &cursor->current);
53+
10554
if (cursor->current) {
10655
return IN_BATCH;
10756
} else {
@@ -115,23 +64,12 @@ _get_next_batch(mongoc_cursor_t *cursor)
11564
{
11665
data_cmd_t *data = (data_cmd_t *)cursor->impl.data;
11766
bson_t getmore_cmd;
118-
getmore_type_t getmore_type = _getmore_type(cursor);
119-
120-
switch (getmore_type) {
121-
case GETMORE_CMD:
122-
_mongoc_cursor_prepare_getmore_command(cursor, &getmore_cmd);
123-
_mongoc_cursor_response_refresh(cursor, &getmore_cmd, NULL /* opts */, &data->response);
124-
bson_destroy(&getmore_cmd);
125-
data->reading_from = CMD_RESPONSE;
126-
return IN_BATCH;
127-
case OP_GETMORE:
128-
_mongoc_cursor_op_getmore(cursor, &data->response_legacy);
129-
data->reading_from = OP_GETMORE_RESPONSE;
130-
return IN_BATCH;
131-
case UNKNOWN:
132-
default:
133-
return DONE;
134-
}
67+
68+
_mongoc_cursor_prepare_getmore_command(cursor, &getmore_cmd);
69+
_mongoc_cursor_response_refresh(cursor, &getmore_cmd, NULL /* opts */, &data->response);
70+
bson_destroy(&getmore_cmd);
71+
72+
return IN_BATCH;
13573
}
13674

13775

@@ -141,7 +79,6 @@ _destroy(mongoc_cursor_impl_t *impl)
14179
data_cmd_t *data = (data_cmd_t *)impl->data;
14280
bson_destroy(&data->response.reply);
14381
bson_destroy(&data->cmd);
144-
_mongoc_cursor_response_legacy_destroy(&data->response_legacy);
14582
bson_free(data);
14683
}
14784

@@ -152,7 +89,6 @@ _clone(mongoc_cursor_impl_t *dst, const mongoc_cursor_impl_t *src)
15289
data_cmd_t *data_src = (data_cmd_t *)src->data;
15390
data_cmd_t *data_dst = BSON_ALIGNED_ALLOC0(data_cmd_t);
15491
bson_init(&data_dst->response.reply);
155-
_mongoc_cursor_response_legacy_init(&data_dst->response_legacy);
15692
bson_copy_to(&data_src->cmd, &data_dst->cmd);
15793
dst->data = data_dst;
15894
}
@@ -173,7 +109,6 @@ _mongoc_cursor_cmd_new(mongoc_client_t *client,
173109
data_cmd_t *data = BSON_ALIGNED_ALLOC0(data_cmd_t);
174110

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

197-
data->reading_from = CMD_RESPONSE;
198132
cursor->state = IN_BATCH;
199133

200134
bson_destroy(&data->response.reply);

src/libmongoc/src/mongoc/mongoc-cursor-find-cmd.c

Lines changed: 0 additions & 106 deletions
This file was deleted.

src/libmongoc/src/mongoc/mongoc-cursor-find-opquery.c

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)