Skip to content

Commit 8126cd3

Browse files
authored
CDRIVER-4617 Remove legacy mongoc-rpc entities (#1312)
1 parent 621943b commit 8126cd3

20 files changed

+1
-2287
lines changed

src/libmongoc/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,6 @@ set (test-libmongoc-sources
942942
${PROJECT_SOURCE_DIR}/tests/test-mongoc-read-write-concern.c
943943
${PROJECT_SOURCE_DIR}/tests/test-mongoc-retryable-reads.c
944944
${PROJECT_SOURCE_DIR}/tests/test-mongoc-retryable-writes.c
945-
${PROJECT_SOURCE_DIR}/tests/test-mongoc-rpc.c
946945
${PROJECT_SOURCE_DIR}/tests/test-mongoc-sample-commands.c
947946
${PROJECT_SOURCE_DIR}/tests/test-mongoc-scram.c
948947
${PROJECT_SOURCE_DIR}/tests/test-mongoc-sdam-monitoring.c

src/libmongoc/src/mongoc/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
set (src_libmongoc_src_mongoc_DIST_defs
2-
op-delete.def
3-
op-get-more.def
4-
op-header.def
5-
op-insert.def
6-
op-kill-cursors.def
7-
op-msg.def
8-
op-query.def
9-
op-reply.def
10-
op-reply-header.def
11-
op-update.def
12-
op-compressed.def
132
mongoc-counters.defs
143
)
154

src/libmongoc/src/mongoc/mongoc-cluster-private.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,6 @@ _mongoc_cluster_get_auth_cmd_scram (mongoc_crypto_hash_algorithm_t algo,
258258
bson_error_t *error /* OUT */);
259259
#endif /* MONGOC_ENABLE_CRYPTO */
260260

261-
char *
262-
_mongoc_rpc_compress (struct _mongoc_cluster_t *cluster,
263-
int32_t compressor_id,
264-
mongoc_rpc_t *rpc_le,
265-
bson_error_t *error);
266-
bool
267-
_mongoc_rpc_decompress (mongoc_rpc_t *rpc_le, uint8_t *buf, size_t buflen);
268-
269261
bool
270262
mcd_rpc_message_compress (mcd_rpc_message *rpc,
271263
int32_t compressor_id,
@@ -279,11 +271,6 @@ mcd_rpc_message_decompress (mcd_rpc_message *rpc,
279271
void **data,
280272
size_t *data_len);
281273

282-
bool
283-
_mongoc_rpc_decompress_if_necessary (mongoc_rpc_t *rpc,
284-
mongoc_buffer_t *buffer /* IN/OUT */,
285-
bson_error_t *error /* OUT */);
286-
287274
bool
288275
mcd_rpc_message_decompress_if_necessary (mcd_rpc_message *rpc,
289276
void **data,

src/libmongoc/src/mongoc/mongoc-cluster.c

Lines changed: 0 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -3790,142 +3790,6 @@ mongoc_cluster_run_opmsg (mongoc_cluster_t *cluster,
37903790
}
37913791

37923792

3793-
/*
3794-
*--------------------------------------------------------------------------
3795-
*
3796-
* _mongoc_rpc_compress --
3797-
*
3798-
* Takes a (little endian) rpc struct and creates a OP_COMPRESSED
3799-
* compressed opcode based on the provided compressor_id.
3800-
* The in-place updated rpc struct remains little endian.
3801-
*
3802-
* Side effects:
3803-
* Overwrites the RPC, and clears and overwrites the cluster buffer
3804-
* with the compressed results.
3805-
*
3806-
*--------------------------------------------------------------------------
3807-
*/
3808-
3809-
char *
3810-
_mongoc_rpc_compress (struct _mongoc_cluster_t *cluster,
3811-
int32_t compressor_id,
3812-
mongoc_rpc_t *rpc_le,
3813-
bson_error_t *error)
3814-
{
3815-
const size_t allocate = BSON_UINT32_FROM_LE (rpc_le->header.msg_len) - 16u;
3816-
BSON_ASSERT (allocate > 0u);
3817-
3818-
char *const data = bson_malloc0 (allocate);
3819-
const size_t size = _mongoc_cluster_buffer_iovec (
3820-
cluster->iov.data, cluster->iov.len, 16, data);
3821-
size_t output_length =
3822-
mongoc_compressor_max_compressed_length (compressor_id, size);
3823-
3824-
if (!output_length) {
3825-
bson_set_error (error,
3826-
MONGOC_ERROR_COMMAND,
3827-
MONGOC_ERROR_COMMAND_INVALID_ARG,
3828-
"Could not determine compression bounds for %s",
3829-
mongoc_compressor_id_to_name (compressor_id));
3830-
bson_free (data);
3831-
return NULL;
3832-
}
3833-
3834-
int32_t compression_level = -1;
3835-
3836-
if (compressor_id == MONGOC_COMPRESSOR_ZLIB_ID) {
3837-
compression_level = mongoc_uri_get_option_as_int32 (
3838-
cluster->uri, MONGOC_URI_ZLIBCOMPRESSIONLEVEL, -1);
3839-
}
3840-
3841-
BSON_ASSERT (size > 0u);
3842-
3843-
char *const output = (char *) bson_malloc0 (output_length);
3844-
if (mongoc_compress (compressor_id,
3845-
compression_level,
3846-
data,
3847-
size,
3848-
output,
3849-
&output_length)) {
3850-
rpc_le->header.msg_len = 0;
3851-
rpc_le->compressed.original_opcode =
3852-
BSON_UINT32_FROM_LE (rpc_le->header.opcode);
3853-
rpc_le->header.opcode = MONGOC_OPCODE_COMPRESSED;
3854-
rpc_le->header.request_id =
3855-
BSON_UINT32_FROM_LE (rpc_le->header.request_id);
3856-
rpc_le->header.response_to =
3857-
BSON_UINT32_FROM_LE (rpc_le->header.response_to);
3858-
3859-
BSON_ASSERT (bson_in_range_unsigned (int32_t, size));
3860-
BSON_ASSERT (bson_in_range_unsigned (int32_t, output_length));
3861-
3862-
rpc_le->compressed.uncompressed_size = (int32_t) size;
3863-
rpc_le->compressed.compressor_id = compressor_id;
3864-
rpc_le->compressed.compressed_message = (const uint8_t *) output;
3865-
rpc_le->compressed.compressed_message_len = (int32_t) output_length;
3866-
bson_free (data);
3867-
3868-
3869-
_mongoc_array_destroy (&cluster->iov);
3870-
_mongoc_array_init (&cluster->iov, sizeof (mongoc_iovec_t));
3871-
_mongoc_rpc_gather (rpc_le, &cluster->iov);
3872-
_mongoc_rpc_swab_to_le (rpc_le);
3873-
return output;
3874-
} else {
3875-
MONGOC_WARNING ("Could not compress data with %s",
3876-
mongoc_compressor_id_to_name (compressor_id));
3877-
}
3878-
bson_free (data);
3879-
bson_free (output);
3880-
return NULL;
3881-
}
3882-
3883-
/*
3884-
*--------------------------------------------------------------------------
3885-
*
3886-
* _mongoc_rpc_decompress --
3887-
*
3888-
* Takes a (little endian) rpc struct assumed to be OP_COMPRESSED
3889-
* and decompresses the opcode into its original opcode.
3890-
* The in-place updated rpc struct remains little endian.
3891-
*
3892-
* Side effects:
3893-
* Overwrites the RPC, along with the provided buf with the
3894-
* compressed results.
3895-
*
3896-
*--------------------------------------------------------------------------
3897-
*/
3898-
3899-
bool
3900-
_mongoc_rpc_decompress (mongoc_rpc_t *rpc_le, uint8_t *buf, size_t buflen)
3901-
{
3902-
size_t uncompressed_size =
3903-
BSON_UINT32_FROM_LE (rpc_le->compressed.uncompressed_size);
3904-
bool ok;
3905-
size_t msg_len = BSON_UINT32_TO_LE (buflen);
3906-
const size_t original_uncompressed_size = uncompressed_size;
3907-
3908-
BSON_ASSERT (uncompressed_size <= buflen);
3909-
memcpy (buf, (void *) (&msg_len), 4);
3910-
memcpy (buf + 4, (void *) (&rpc_le->header.request_id), 4);
3911-
memcpy (buf + 8, (void *) (&rpc_le->header.response_to), 4);
3912-
memcpy (buf + 12, (void *) (&rpc_le->compressed.original_opcode), 4);
3913-
3914-
ok = mongoc_uncompress (rpc_le->compressed.compressor_id,
3915-
rpc_le->compressed.compressed_message,
3916-
rpc_le->compressed.compressed_message_len,
3917-
buf + 16,
3918-
&uncompressed_size);
3919-
3920-
BSON_ASSERT (original_uncompressed_size == uncompressed_size);
3921-
3922-
if (ok) {
3923-
return _mongoc_rpc_scatter (rpc_le, buf, buflen);
3924-
}
3925-
3926-
return false;
3927-
}
3928-
39293793
bool
39303794
mcd_rpc_message_compress (mcd_rpc_message *rpc,
39313795
int32_t compressor_id,
@@ -4107,46 +3971,6 @@ mcd_rpc_message_decompress (mcd_rpc_message *rpc, void **data, size_t *data_len)
41073971
return mcd_rpc_message_from_data_in_place (rpc, *data, *data_len, NULL);
41083972
}
41093973

4110-
4111-
/* If rpc is OP_COMPRESSED, decompress it into buffer.
4112-
*
4113-
* Assumes rpc is still in network little-endian representation (i.e.
4114-
* _mongoc_rpc_swab_to_le has not been called).
4115-
* Returns true if rpc is not OP_COMPRESSED (and is a no-op) or if decompression
4116-
* succeeds.
4117-
* Return false and sets error otherwise.
4118-
*/
4119-
bool
4120-
_mongoc_rpc_decompress_if_necessary (mongoc_rpc_t *rpc,
4121-
mongoc_buffer_t *buffer /* IN/OUT */,
4122-
bson_error_t *error /* OUT */)
4123-
{
4124-
uint8_t *buf = NULL;
4125-
size_t len;
4126-
4127-
if (BSON_UINT32_FROM_LE (rpc->header.opcode) != MONGOC_OPCODE_COMPRESSED) {
4128-
return true;
4129-
}
4130-
4131-
len = BSON_UINT32_FROM_LE (rpc->compressed.uncompressed_size) +
4132-
sizeof (mongoc_rpc_header_t);
4133-
4134-
buf = bson_malloc0 (len);
4135-
if (!_mongoc_rpc_decompress (rpc, buf, len)) {
4136-
bson_free (buf);
4137-
bson_set_error (error,
4138-
MONGOC_ERROR_PROTOCOL,
4139-
MONGOC_ERROR_PROTOCOL_INVALID_REPLY,
4140-
"Could not decompress server reply");
4141-
return false;
4142-
}
4143-
4144-
_mongoc_buffer_destroy (buffer);
4145-
_mongoc_buffer_init (buffer, buf, len, NULL, NULL);
4146-
4147-
return true;
4148-
}
4149-
41503974
bool
41513975
mcd_rpc_message_decompress_if_necessary (mcd_rpc_message *rpc,
41523976
void **data,

src/libmongoc/src/mongoc/mongoc-rpc-private.h

Lines changed: 0 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -19,152 +19,18 @@
1919

2020
#include "mongoc-prelude.h"
2121

22-
#include "mongoc-array-private.h"
23-
#include "mongoc-iovec.h"
24-
2522
#include "mcd-rpc.h"
2623

2724
#include <bson/bson.h>
2825

2926
#include <stdbool.h>
30-
#include <stddef.h>
3127
#include <stdint.h>
3228

3329
BSON_BEGIN_DECLS
3430

35-
typedef struct _mongoc_rpc_section_t {
36-
uint8_t payload_type;
37-
union {
38-
/* payload_type == 0 */
39-
const uint8_t *bson_document;
40-
/* payload_type == 1 */
41-
struct {
42-
int32_t size;
43-
uint32_t size_le;
44-
const char *identifier;
45-
const uint8_t *bson_documents;
46-
} sequence;
47-
} payload;
48-
} mongoc_rpc_section_t;
49-
50-
#define RPC(_name, _code) \
51-
typedef struct { \
52-
_code \
53-
} mongoc_rpc_##_name##_t;
54-
#define ENUM_FIELD(_name) uint32_t _name;
55-
#define INT32_FIELD(_name) int32_t _name;
56-
#define UINT8_FIELD(_name) uint8_t _name;
57-
#define INT64_FIELD(_name) int64_t _name;
58-
#define INT64_ARRAY_FIELD(_len, _name) \
59-
int32_t _len; \
60-
int64_t *_name;
61-
#define CSTRING_FIELD(_name) const char *_name;
62-
#define BSON_FIELD(_name) const uint8_t *_name;
63-
#define BSON_ARRAY_FIELD(_name) \
64-
const uint8_t *_name; \
65-
int32_t _name##_len;
66-
#define IOVEC_ARRAY_FIELD(_name) \
67-
const mongoc_iovec_t *_name; \
68-
int32_t n_##_name; \
69-
mongoc_iovec_t _name##_recv;
70-
#define SECTION_ARRAY_FIELD(_name) \
71-
mongoc_rpc_section_t _name[2]; \
72-
int32_t n_##_name;
73-
#define RAW_BUFFER_FIELD(_name) \
74-
const uint8_t *_name; \
75-
int32_t _name##_len;
76-
#define BSON_OPTIONAL(_check, _code) _code
77-
#define CHECKSUM_FIELD(_name) uint32_t _name;
78-
79-
80-
#pragma pack(1)
81-
#include "op-delete.def"
82-
#include "op-get-more.def"
83-
#include "op-header.def"
84-
#include "op-insert.def"
85-
#include "op-kill-cursors.def"
86-
#include "op-query.def"
87-
#include "op-reply.def"
88-
#include "op-reply-header.def"
89-
#include "op-update.def"
90-
#include "op-compressed.def"
91-
/* restore default packing */
92-
#pragma pack()
93-
94-
#include "op-msg.def"
95-
96-
typedef union {
97-
mongoc_rpc_delete_t delete_;
98-
mongoc_rpc_get_more_t get_more;
99-
mongoc_rpc_header_t header;
100-
mongoc_rpc_insert_t insert;
101-
mongoc_rpc_kill_cursors_t kill_cursors;
102-
mongoc_rpc_msg_t msg;
103-
mongoc_rpc_query_t query;
104-
mongoc_rpc_reply_t reply;
105-
mongoc_rpc_reply_header_t reply_header;
106-
mongoc_rpc_update_t update;
107-
mongoc_rpc_compressed_t compressed;
108-
int32_t _init; // Used only for initialization.
109-
} mongoc_rpc_t;
110-
111-
112-
BSON_STATIC_ASSERT2 (sizeof_rpc_header, sizeof (mongoc_rpc_header_t) == 16);
113-
BSON_STATIC_ASSERT2 (offsetof_rpc_header,
114-
offsetof (mongoc_rpc_header_t, opcode) ==
115-
offsetof (mongoc_rpc_reply_t, opcode));
116-
BSON_STATIC_ASSERT2 (sizeof_reply_header,
117-
sizeof (mongoc_rpc_reply_header_t) == 36);
118-
119-
120-
#undef RPC
121-
#undef ENUM_FIELD
122-
#undef UINT8_FIELD
123-
#undef INT32_FIELD
124-
#undef INT64_FIELD
125-
#undef INT64_ARRAY_FIELD
126-
#undef CSTRING_FIELD
127-
#undef BSON_FIELD
128-
#undef BSON_ARRAY_FIELD
129-
#undef IOVEC_ARRAY_FIELD
130-
#undef SECTION_ARRAY_FIELD
131-
#undef BSON_OPTIONAL
132-
#undef RAW_BUFFER_FIELD
133-
#undef CHECKSUM_FIELD
134-
135-
136-
void
137-
_mongoc_rpc_gather (mongoc_rpc_t *rpc, mongoc_array_t *array);
138-
void
139-
_mongoc_rpc_op_egress_inc (const mongoc_rpc_t *rpc);
140-
void
141-
_mongoc_rpc_swab_to_le (mongoc_rpc_t *rpc);
142-
void
143-
_mongoc_rpc_swab_from_le (mongoc_rpc_t *rpc);
144-
void
145-
_mongoc_rpc_printf (mongoc_rpc_t *rpc);
146-
bool
147-
_mongoc_rpc_scatter (mongoc_rpc_t *rpc, const uint8_t *buf, size_t buflen);
148-
bool
149-
_mongoc_rpc_scatter_reply_header_only (mongoc_rpc_t *rpc,
150-
const uint8_t *buf,
151-
size_t buflen);
152-
15331
bool
15432
mcd_rpc_message_get_body (const mcd_rpc_message *rpc, bson_t *reply);
15533

156-
bool
157-
_mongoc_rpc_get_first_document (mongoc_rpc_t *rpc, bson_t *reply);
158-
bool
159-
_mongoc_rpc_reply_get_first (mongoc_rpc_reply_t *reply, bson_t *bson);
160-
bool
161-
_mongoc_rpc_reply_get_first_msg (mongoc_rpc_msg_t *reply, bson_t *bson);
162-
bool
163-
_mongoc_rpc_check_ok (mongoc_rpc_t *rpc,
164-
int32_t error_api_version,
165-
bson_error_t *error /* OUT */,
166-
bson_t *error_doc /* OUT */);
167-
16834
bool
16935
mcd_rpc_message_check_ok (mcd_rpc_message *rpc,
17036
int32_t error_api_version,

0 commit comments

Comments
 (0)