79
79
#define MONGOC_LOG_DOMAIN "client"
80
80
81
81
82
- static void
83
- _mongoc_client_op_killcursors (mongoc_cluster_t * cluster ,
84
- mongoc_server_stream_t * server_stream ,
85
- int64_t cursor_id ,
86
- int64_t operation_id ,
87
- const char * db ,
88
- const char * collection );
89
-
90
82
static void
91
83
_mongoc_client_killcursors_command (mongoc_cluster_t * cluster ,
92
84
mongoc_server_stream_t * server_stream ,
@@ -2098,6 +2090,8 @@ _mongoc_client_kill_cursor (mongoc_client_t *client,
2098
2090
ENTRY ;
2099
2091
2100
2092
BSON_ASSERT_PARAM (client );
2093
+ BSON_ASSERT_PARAM (db );
2094
+ BSON_ASSERT_PARAM (collection );
2101
2095
BSON_ASSERT (cursor_id );
2102
2096
2103
2097
/* don't attempt reconnect if server unavailable, and ignore errors */
@@ -2108,209 +2102,14 @@ _mongoc_client_kill_cursor (mongoc_client_t *client,
2108
2102
return ;
2109
2103
}
2110
2104
2111
- if (db && collection ) {
2112
- _mongoc_client_killcursors_command (& client -> cluster , server_stream , cursor_id , db , collection , cs );
2113
- } else {
2114
- _mongoc_client_op_killcursors (& client -> cluster , server_stream , cursor_id , operation_id , db , collection );
2115
- }
2105
+ _mongoc_client_killcursors_command (& client -> cluster , server_stream , cursor_id , db , collection , cs );
2116
2106
2117
2107
mongoc_server_stream_cleanup (server_stream );
2118
2108
2119
2109
EXIT ;
2120
2110
}
2121
2111
2122
2112
2123
- static void
2124
- _mongoc_client_monitor_op_killcursors (mongoc_cluster_t * cluster ,
2125
- mongoc_server_stream_t * server_stream ,
2126
- int64_t cursor_id ,
2127
- int64_t operation_id ,
2128
- const char * db ,
2129
- const char * collection )
2130
- {
2131
- bson_t doc ;
2132
- mongoc_apm_command_started_t event ;
2133
-
2134
- ENTRY ;
2135
-
2136
- mongoc_client_t * client = cluster -> client ;
2137
- const mongoc_log_and_monitor_instance_t * log_and_monitor = & client -> topology -> log_and_monitor ;
2138
-
2139
- if (!log_and_monitor -> apm_callbacks .started ) {
2140
- return ;
2141
- }
2142
-
2143
- bson_init (& doc );
2144
- _mongoc_client_prepare_killcursors_command (cursor_id , collection , & doc );
2145
- mongoc_apm_command_started_init (& event ,
2146
- & doc ,
2147
- db ,
2148
- "killCursors" ,
2149
- cluster -> request_id ,
2150
- operation_id ,
2151
- & server_stream -> sd -> host ,
2152
- server_stream -> sd -> id ,
2153
- & server_stream -> sd -> service_id ,
2154
- server_stream -> sd -> server_connection_id ,
2155
- NULL ,
2156
- log_and_monitor -> apm_context );
2157
-
2158
- log_and_monitor -> apm_callbacks .started (& event );
2159
- mongoc_apm_command_started_cleanup (& event );
2160
- bson_destroy (& doc );
2161
-
2162
- EXIT ;
2163
- }
2164
-
2165
-
2166
- static void
2167
- _mongoc_client_monitor_op_killcursors_succeeded (mongoc_cluster_t * cluster ,
2168
- int64_t duration ,
2169
- mongoc_server_stream_t * server_stream ,
2170
- int64_t cursor_id ,
2171
- int64_t operation_id ,
2172
- const char * db )
2173
- {
2174
- bson_t doc ;
2175
- bson_array_builder_t * cursors_unknown ;
2176
- mongoc_apm_command_succeeded_t event ;
2177
-
2178
- ENTRY ;
2179
-
2180
- mongoc_client_t * client = cluster -> client ;
2181
- const mongoc_log_and_monitor_instance_t * log_and_monitor = & client -> topology -> log_and_monitor ;
2182
-
2183
- if (!log_and_monitor -> apm_callbacks .succeeded ) {
2184
- EXIT ;
2185
- }
2186
-
2187
- /* fake server reply to killCursors command: {ok: 1, cursorsUnknown: [42]} */
2188
- bson_init (& doc );
2189
- bson_append_int32 (& doc , "ok" , 2 , 1 );
2190
- bson_append_array_builder_begin (& doc , "cursorsUnknown" , 14 , & cursors_unknown );
2191
- bson_array_builder_append_int64 (cursors_unknown , cursor_id );
2192
- bson_append_array_builder_end (& doc , cursors_unknown );
2193
-
2194
- mongoc_apm_command_succeeded_init (& event ,
2195
- duration ,
2196
- & doc ,
2197
- "killCursors" ,
2198
- db ,
2199
- cluster -> request_id ,
2200
- operation_id ,
2201
- & server_stream -> sd -> host ,
2202
- server_stream -> sd -> id ,
2203
- & server_stream -> sd -> service_id ,
2204
- server_stream -> sd -> server_connection_id ,
2205
- false,
2206
- log_and_monitor -> apm_context );
2207
-
2208
- log_and_monitor -> apm_callbacks .succeeded (& event );
2209
-
2210
- mongoc_apm_command_succeeded_cleanup (& event );
2211
- bson_destroy (& doc );
2212
- }
2213
-
2214
-
2215
- static void
2216
- _mongoc_client_monitor_op_killcursors_failed (mongoc_cluster_t * cluster ,
2217
- int64_t duration ,
2218
- mongoc_server_stream_t * server_stream ,
2219
- const bson_error_t * error ,
2220
- int64_t operation_id ,
2221
- const char * db )
2222
- {
2223
- bson_t doc ;
2224
- mongoc_apm_command_failed_t event ;
2225
-
2226
- ENTRY ;
2227
-
2228
- mongoc_client_t * client = cluster -> client ;
2229
- const mongoc_log_and_monitor_instance_t * log_and_monitor = & client -> topology -> log_and_monitor ;
2230
-
2231
- if (!log_and_monitor -> apm_callbacks .failed ) {
2232
- EXIT ;
2233
- }
2234
-
2235
- /* fake server reply to killCursors command: {ok: 0} */
2236
- bson_init (& doc );
2237
- bson_append_int32 (& doc , "ok" , 2 , 0 );
2238
-
2239
- mongoc_apm_command_failed_init (& event ,
2240
- duration ,
2241
- "killCursors" ,
2242
- db ,
2243
- error ,
2244
- & doc ,
2245
- cluster -> request_id ,
2246
- operation_id ,
2247
- & server_stream -> sd -> host ,
2248
- server_stream -> sd -> id ,
2249
- & server_stream -> sd -> service_id ,
2250
- server_stream -> sd -> server_connection_id ,
2251
- false,
2252
- log_and_monitor -> apm_context );
2253
-
2254
- log_and_monitor -> apm_callbacks .failed (& event );
2255
-
2256
- mongoc_apm_command_failed_cleanup (& event );
2257
- bson_destroy (& doc );
2258
- }
2259
-
2260
-
2261
- static void
2262
- _mongoc_client_op_killcursors (mongoc_cluster_t * cluster ,
2263
- mongoc_server_stream_t * server_stream ,
2264
- int64_t cursor_id ,
2265
- int64_t operation_id ,
2266
- const char * db ,
2267
- const char * collection )
2268
- {
2269
- BSON_ASSERT_PARAM (cluster );
2270
- BSON_ASSERT_PARAM (server_stream );
2271
- BSON_OPTIONAL_PARAM (db );
2272
- BSON_OPTIONAL_PARAM (collection );
2273
-
2274
- const bool has_ns = db && collection ;
2275
- const int64_t started = bson_get_monotonic_time ();
2276
-
2277
- mcd_rpc_message * const rpc = mcd_rpc_message_new ();
2278
-
2279
- {
2280
- int32_t message_length = 0 ;
2281
-
2282
- message_length += mcd_rpc_header_set_message_length (rpc , 0 );
2283
- message_length += mcd_rpc_header_set_request_id (rpc , ++ cluster -> request_id );
2284
- message_length += mcd_rpc_header_set_response_to (rpc , 0 );
2285
- message_length += mcd_rpc_header_set_op_code (rpc , MONGOC_OP_CODE_KILL_CURSORS );
2286
-
2287
- message_length += sizeof (int32_t ); // ZERO
2288
- message_length += mcd_rpc_op_kill_cursors_set_cursor_ids (rpc , & cursor_id , 1 );
2289
-
2290
- mcd_rpc_message_set_length (rpc , message_length );
2291
- }
2292
-
2293
- if (has_ns ) {
2294
- _mongoc_client_monitor_op_killcursors (cluster , server_stream , cursor_id , operation_id , db , collection );
2295
- }
2296
-
2297
- bson_error_t error ;
2298
- const bool res = mongoc_cluster_legacy_rpc_sendv_to_server (cluster , rpc , server_stream , & error );
2299
-
2300
- if (has_ns ) {
2301
- if (res ) {
2302
- _mongoc_client_monitor_op_killcursors_succeeded (
2303
- cluster , bson_get_monotonic_time () - started , server_stream , cursor_id , operation_id , db );
2304
- } else {
2305
- _mongoc_client_monitor_op_killcursors_failed (
2306
- cluster , bson_get_monotonic_time () - started , server_stream , & error , operation_id , db );
2307
- }
2308
- }
2309
-
2310
- mcd_rpc_message_destroy (rpc );
2311
- }
2312
-
2313
-
2314
2113
static void
2315
2114
_mongoc_client_killcursors_command (mongoc_cluster_t * cluster ,
2316
2115
mongoc_server_stream_t * server_stream ,
@@ -2343,75 +2142,6 @@ _mongoc_client_killcursors_command (mongoc_cluster_t *cluster,
2343
2142
}
2344
2143
2345
2144
2346
- /*
2347
- *--------------------------------------------------------------------------
2348
- *
2349
- * mongoc_client_kill_cursor --
2350
- *
2351
- * Destroy a cursor on the server.
2352
- *
2353
- * NOTE: this is only reliable when connected to a single mongod or
2354
- * mongos. If connected to a replica set, the driver attempts to
2355
- * kill the cursor on the primary. If connected to multiple mongoses
2356
- * the kill-cursors message is sent to a *random* mongos.
2357
- *
2358
- * If no primary, mongos, or standalone server is known, return
2359
- * without attempting to reconnect.
2360
- *
2361
- * Returns:
2362
- * None.
2363
- *
2364
- * Side effects:
2365
- * None.
2366
- *
2367
- *--------------------------------------------------------------------------
2368
- */
2369
-
2370
- void
2371
- mongoc_client_kill_cursor (mongoc_client_t * client , int64_t cursor_id )
2372
- {
2373
- BSON_ASSERT_PARAM (client );
2374
-
2375
- mongoc_topology_t * const topology = BSON_ASSERT_PTR_INLINE (client )-> topology ;
2376
- mongoc_server_description_t const * selected_server ;
2377
- mongoc_read_prefs_t * read_prefs ;
2378
- bson_error_t error ;
2379
- uint32_t server_id = 0 ;
2380
- mc_shared_tpld td = mc_tpld_take_ref (topology );
2381
-
2382
- read_prefs = mongoc_read_prefs_new (MONGOC_READ_PRIMARY );
2383
-
2384
- if (!mongoc_topology_compatible (td .ptr , NULL , & error )) {
2385
- MONGOC_ERROR ("Could not kill cursor: %s" , error .message );
2386
- mc_tpld_drop_ref (& td );
2387
- mongoc_read_prefs_destroy (read_prefs );
2388
- return ;
2389
- }
2390
-
2391
- /* see if there's a known writable server - do no I/O or retries */
2392
- selected_server = mongoc_topology_description_select (td .ptr ,
2393
- MONGOC_SS_WRITE ,
2394
- read_prefs ,
2395
- NULL /* chosen read mode */ ,
2396
- NULL /* deprioritized servers */ ,
2397
- topology -> local_threshold_msec );
2398
-
2399
- if (selected_server ) {
2400
- server_id = selected_server -> id ;
2401
- }
2402
-
2403
- if (server_id ) {
2404
- _mongoc_client_kill_cursor (
2405
- client , server_id , cursor_id , 0 /* operation_id */ , NULL /* db */ , NULL /* collection */ , NULL /* session */ );
2406
- } else {
2407
- MONGOC_INFO ("No server available for mongoc_client_kill_cursor" );
2408
- }
2409
-
2410
- mongoc_read_prefs_destroy (read_prefs );
2411
- mc_tpld_drop_ref (& td );
2412
- }
2413
-
2414
-
2415
2145
char * *
2416
2146
mongoc_client_get_database_names (mongoc_client_t * client , bson_error_t * error )
2417
2147
{
0 commit comments