Skip to content

Commit 6dbd8d8

Browse files
bjorihanumantmk
authored andcommitted
CDRIVER-465: Add mongoc_client_kill_cursor()
A good samaritan should clean after himself using mongoc_cursor_destroy(cursor), but you may not always have the cursor instance. You are just trying to cleanup after a broken process, and all you got is the cursorid, which you retrieved from db.currentOp() Closes #121
1 parent 0807e04 commit 6dbd8d8

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

src/mongoc/mongoc-client.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,6 +1257,30 @@ mongoc_client_command_simple (mongoc_client_t *client,
12571257
return ret;
12581258
}
12591259

1260+
void
1261+
mongoc_client_kill_cursor (mongoc_client_t *client,
1262+
int64_t cursor_id)
1263+
{
1264+
mongoc_rpc_t rpc = {{ 0 }};
1265+
1266+
ENTRY;
1267+
1268+
bson_return_if_fail(client);
1269+
bson_return_if_fail(cursor_id);
1270+
1271+
rpc.kill_cursors.msg_len = 0;
1272+
rpc.kill_cursors.request_id = 0;
1273+
rpc.kill_cursors.response_to = 0;
1274+
rpc.kill_cursors.opcode = MONGOC_OPCODE_KILL_CURSORS;
1275+
rpc.kill_cursors.zero = 0;
1276+
rpc.kill_cursors.cursors = &cursor_id;
1277+
rpc.kill_cursors.n_cursors = 1;
1278+
1279+
_mongoc_client_sendv (client, &rpc, 1, 0, NULL, NULL, NULL);
1280+
1281+
EXIT;
1282+
}
1283+
12601284

12611285
char **
12621286
mongoc_client_get_database_names (mongoc_client_t *client,

src/mongoc/mongoc-client.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ mongoc_cursor_t *mongoc_client_command (mongoc_client
9292
const bson_t *query,
9393
const bson_t *fields,
9494
const mongoc_read_prefs_t *read_prefs);
95+
void mongoc_client_kill_cursor (mongoc_client_t *client,
96+
int64_t cursor_id);
9597
bool mongoc_client_command_simple (mongoc_client_t *client,
9698
const char *db_name,
9799
const bson_t *command,

src/mongoc/mongoc-cursor.c

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -318,31 +318,6 @@ _mongoc_cursor_new (mongoc_client_t *client,
318318
}
319319

320320

321-
static void
322-
_mongoc_cursor_kill_cursor (mongoc_cursor_t *cursor,
323-
int64_t cursor_id)
324-
{
325-
mongoc_rpc_t rpc = {{ 0 }};
326-
327-
ENTRY;
328-
329-
bson_return_if_fail(cursor);
330-
bson_return_if_fail(cursor_id);
331-
332-
rpc.kill_cursors.msg_len = 0;
333-
rpc.kill_cursors.request_id = 0;
334-
rpc.kill_cursors.response_to = 0;
335-
rpc.kill_cursors.opcode = MONGOC_OPCODE_KILL_CURSORS;
336-
rpc.kill_cursors.zero = 0;
337-
rpc.kill_cursors.cursors = &cursor_id;
338-
rpc.kill_cursors.n_cursors = 1;
339-
340-
_mongoc_client_sendv (cursor->client, &rpc, 1, 0, NULL, NULL, NULL);
341-
342-
EXIT;
343-
}
344-
345-
346321
void
347322
mongoc_cursor_destroy (mongoc_cursor_t *cursor)
348323
{
@@ -373,7 +348,7 @@ _mongoc_cursor_destroy (mongoc_cursor_t *cursor)
373348
&cursor->client->cluster.nodes[cursor->hint - 1]);
374349
}
375350
} else if (cursor->rpc.reply.cursor_id) {
376-
_mongoc_cursor_kill_cursor(cursor, cursor->rpc.reply.cursor_id);
351+
mongoc_client_kill_cursor(cursor->client, cursor->rpc.reply.cursor_id);
377352
}
378353

379354
if (cursor->reader) {
@@ -1079,3 +1054,4 @@ mongoc_cursor_get_hint (const mongoc_cursor_t *cursor)
10791054

10801055
return cursor->hint;
10811056
}
1057+

0 commit comments

Comments
 (0)