Proposal
Only increment egress OP_QUERY counter for each command sent. Do not increment egress OP_QUERY counter for each resolved DNS record. This may result in overcounting.
Background
_mongoc_rpc_gather increments the egress OP_QUERY counter
_mongoc_rpc_gather may be called when constructing hello commands for each DNS record in mongoc_topology_scanner_node_setup_tcp:
LL_FOREACH2 (node->dns_results, iter, ai_next)
|
{
|
_begin_hello_cmd (node,
|
NULL /* stream */,
|
false /* is_setup_done */,
|
iter,
|
delay,
|
true /* use_handshake */);
|
/* each subsequent DNS result will have an additional 250ms delay. */
|
delay += HAPPY_EYEBALLS_DELAY_MS;
|
}
|
_mongoc_rpc_gather is called through this call path:
test-libmongoc!_mongoc_rpc_gather (/Users/kevin.albertson/review/mongo-c-driver-1242/src/libmongoc/src/mongoc/mongoc-rpc.c:606)
|
test-libmongoc!_mongoc_async_cmd_init_send (/Users/kevin.albertson/review/mongo-c-driver-1242/src/libmongoc/src/mongoc/mongoc-async-cmd.c:168)
|
test-libmongoc!mongoc_async_cmd_new (/Users/kevin.albertson/review/mongo-c-driver-1242/src/libmongoc/src/mongoc/mongoc-async-cmd.c:232)
|
test-libmongoc!_begin_hello_cmd (/Users/kevin.albertson/review/mongo-c-driver-1242/src/libmongoc/src/mongoc/mongoc-topology-scanner.c:431)
|
test-libmongoc!mongoc_topology_scanner_node_setup_tcp (/Users/kevin.albertson/review/mongo-c-driver-1242/src/libmongoc/src/mongoc/mongoc-topology-scanner.c:975)
|
The egress OP_QUERY counter is documented as "The number of sent Query operations."
The expected behavior is to only increment egress OP_QUERY when an OP_QUERY is sent, not just constructed.
Here is a test that shows the issue:
static void
|
test_overcounting_opquery (void *unused)
|
{
|
BSON_UNUSED (unused);
|
|
bson_error_t error = {0};
|
// Connect to exactly one host that resolves to both IPv4 and IPv6.
|
mongoc_client_t *const client = mongoc_client_new ("mongodb://ipv4_and_ipv6.test.build.10gen.cc:27017");
|
|
mongoc_counter_op_egress_query_reset ();
|
|
ASSERT_OR_PRINT (
|
mongoc_client_get_server_status (client, NULL, NULL, &error), error);
|
|
const int32_t sent_queries = mongoc_counter_op_egress_query_count ();
|
// Expect one OP_QUERY for handshake.
|
ASSERT_WITH_MSG (
|
sent_queries == 1,
|
"expected exactly one OP_QUERY requests, but observed %" PRId32
|
" requests",
|
sent_queries);
|
// May fail with: 'expected exactly one OP_QUERY requests, but observed 2
|
// requests' if 'localhost' resolves to more than one DNS record.
|
mongoc_client_destroy (client);
|
}
|
For assistance with testing:
- localhost.test.build.10gen.cc only resolves to IPv4 127.0.0.1
- ipv4_and_ipv6.test.build.10gen.cc resolves to both IPv4 12 127.0.0.1 and IPv6 ::1
|