Skip to content

Commit 3c3019b

Browse files
committed
CDRIVER-789 remove topology scanner's "seen" list
1 parent 9b294e0 commit 3c3019b

7 files changed

+34
-143
lines changed

src/mongoc/mongoc-host-list.c

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,6 @@
1717
#include "mongoc-host-list.h"
1818
#include "mongoc-util-private.h"
1919

20-
/*
21-
*--------------------------------------------------------------------------
22-
*
23-
* mongoc_host_list_new --
24-
*
25-
* Empty new host list.
26-
*
27-
* Side effects:
28-
* None.
29-
*
30-
*--------------------------------------------------------------------------
31-
*/
32-
mongoc_host_list_t *
33-
mongoc_host_list_new (void)
34-
{
35-
return (mongoc_host_list_t *) bson_malloc0 (sizeof (mongoc_host_list_t));
36-
}
3720

3821
/*
3922
*--------------------------------------------------------------------------
@@ -57,95 +40,6 @@ mongoc_host_list_equal (const mongoc_host_list_t *host_a,
5740
}
5841

5942

60-
/*
61-
*--------------------------------------------------------------------------
62-
*
63-
* mongoc_host_list_find --
64-
*
65-
* Search for an equal mongoc_host_list_t in a list of them.
66-
*
67-
* Returns:
68-
* Pointer to an entry in "list", or NULL.
69-
*
70-
* Side effects:
71-
* None.
72-
*
73-
*--------------------------------------------------------------------------
74-
*/
75-
const mongoc_host_list_t *
76-
mongoc_host_list_find (const mongoc_host_list_t *list,
77-
const mongoc_host_list_t *needle)
78-
{
79-
while (list) {
80-
if (mongoc_host_list_equal (list, needle)) {
81-
return list;
82-
}
83-
84-
list = list->next;
85-
}
86-
87-
return NULL;
88-
}
89-
90-
91-
/*
92-
*--------------------------------------------------------------------------
93-
*
94-
* mongoc_host_list_count --
95-
*
96-
* Return number of items in the host list.
97-
*
98-
* Returns:
99-
* 0 or greater.
100-
*
101-
* Side effects:
102-
* None.
103-
*
104-
*--------------------------------------------------------------------------
105-
*/
106-
size_t
107-
mongoc_host_list_count (const mongoc_host_list_t *list)
108-
{
109-
size_t count = 0;
110-
111-
while (list) {
112-
count++;
113-
list = list->next;
114-
}
115-
116-
return count;
117-
}
118-
119-
120-
/*
121-
*--------------------------------------------------------------------------
122-
*
123-
* host_list_copy --
124-
*
125-
* Make a copy of "host" with next set to "next".
126-
*
127-
* Returns:
128-
* New copy.
129-
*
130-
* Side effects:
131-
* None.
132-
*
133-
*--------------------------------------------------------------------------
134-
*/
135-
mongoc_host_list_t *
136-
mongoc_host_list_copy (const mongoc_host_list_t *host,
137-
mongoc_host_list_t *next)
138-
{
139-
mongoc_host_list_t *copy;
140-
141-
copy = mongoc_host_list_new ();
142-
memcpy ((void *) copy, (void *) host, sizeof (mongoc_host_list_t));
143-
copy->next = next;
144-
145-
return copy;
146-
}
147-
148-
14943
/*
15044
*--------------------------------------------------------------------------
15145
*

src/mongoc/mongoc-host-list.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,9 @@ struct _mongoc_host_list_t
5151
void *padding [4];
5252
};
5353

54-
mongoc_host_list_t *mongoc_host_list_new (void);
55-
5654
bool mongoc_host_list_equal (const mongoc_host_list_t *host_a,
5755
const mongoc_host_list_t *host_b);
5856

59-
const mongoc_host_list_t *mongoc_host_list_find (const mongoc_host_list_t *list,
60-
const mongoc_host_list_t *needle);
61-
62-
size_t mongoc_host_list_count (const mongoc_host_list_t *list);
63-
64-
mongoc_host_list_t *mongoc_host_list_copy (const mongoc_host_list_t *host,
65-
mongoc_host_list_t *next);
66-
6757
void mongoc_host_list_destroy_all (mongoc_host_list_t *host);
6858

6959
BSON_END_DECLS

src/mongoc/mongoc-topology-scanner-private.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ typedef struct mongoc_topology_scanner
7171
mongoc_async_cmd_setup_t setup;
7272
mongoc_stream_initiator_t initiator;
7373
void *initiator_context;
74-
mongoc_host_list_t *seen;
7574

7675
#ifdef MONGOC_ENABLE_SSL
7776
mongoc_ssl_opt_t *ssl_opts;
@@ -120,6 +119,10 @@ mongoc_topology_scanner_node_t *
120119
mongoc_topology_scanner_get_node (mongoc_topology_scanner_t *ts,
121120
uint32_t id);
122121

122+
bool
123+
mongoc_topology_scanner_has_node_for_host (mongoc_topology_scanner_t *ts,
124+
mongoc_host_list_t *host);
125+
123126
void
124127
mongoc_topology_scanner_set_stream_initiator (mongoc_topology_scanner_t *ts,
125128
mongoc_stream_initiator_t si,

src/mongoc/mongoc-topology-scanner.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ mongoc_topology_scanner_destroy (mongoc_topology_scanner_t *ts)
9292
mongoc_async_destroy (ts->async);
9393
bson_destroy (&ts->ismaster_cmd);
9494

95-
mongoc_host_list_destroy_all (ts->seen);
96-
9795
bson_free (ts);
9896
}
9997

@@ -104,15 +102,6 @@ mongoc_topology_scanner_add (mongoc_topology_scanner_t *ts,
104102
{
105103
mongoc_topology_scanner_node_t *node;
106104

107-
if (mongoc_host_list_find (ts->seen, host)) {
108-
/* already seen this host -- avoid pathological case like two primaries
109-
* pointing at each other, each invalidating itself and trying to add the
110-
* other on each check within the same blocking scan, see
111-
* test_topology_scanner_oscillate
112-
*/
113-
return NULL;
114-
}
115-
116105
node = (mongoc_topology_scanner_node_t *) bson_malloc0 (sizeof (*node));
117106

118107
memcpy (&node->host, host, sizeof (*host));
@@ -123,8 +112,6 @@ mongoc_topology_scanner_add (mongoc_topology_scanner_t *ts,
123112

124113
DL_APPEND(ts->nodes, node);
125114

126-
ts->seen = mongoc_host_list_copy (host, ts->seen);
127-
128115
return node;
129116
}
130117

@@ -221,6 +208,31 @@ mongoc_topology_scanner_get_node (mongoc_topology_scanner_t *ts,
221208
return NULL;
222209
}
223210

211+
/*
212+
*--------------------------------------------------------------------------
213+
*
214+
* mongoc_topology_scanner_has_node_for_host --
215+
*
216+
* Whether the scanner has a node for the given host and port.
217+
*
218+
*--------------------------------------------------------------------------
219+
*/
220+
bool
221+
mongoc_topology_scanner_has_node_for_host (mongoc_topology_scanner_t *ts,
222+
mongoc_host_list_t *host)
223+
{
224+
mongoc_topology_scanner_node_t *ele, *tmp;
225+
226+
DL_FOREACH_SAFE (ts->nodes, ele, tmp)
227+
{
228+
if (mongoc_host_list_equal (&ele->host, host)) {
229+
return true;
230+
}
231+
}
232+
233+
return false;
234+
}
235+
224236
/*
225237
*-----------------------------------------------------------------------
226238
*
@@ -549,9 +561,6 @@ mongoc_topology_scanner_reset (mongoc_topology_scanner_t *ts)
549561
mongoc_topology_scanner_node_destroy (node, true);
550562
}
551563
}
552-
553-
mongoc_host_list_destroy_all (ts->seen);
554-
ts->seen = NULL;
555564
}
556565

557566
void

src/mongoc/mongoc-topology.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ _mongoc_topology_reconcile_add_nodes (void *item,
3838
mongoc_topology_t *topology = (mongoc_topology_t *)ctx;
3939
mongoc_topology_scanner_t *scanner = topology->scanner;
4040

41-
if (! mongoc_topology_scanner_get_node (scanner, sd->id)) {
41+
/* quickly search by id, then check if a node for this host was retired in
42+
* this scan. */
43+
if (! mongoc_topology_scanner_get_node (scanner, sd->id) &&
44+
! mongoc_topology_scanner_has_node_for_host (scanner, &sd->host)) {
4245
mongoc_topology_scanner_add_and_scan (scanner, &sd->host, sd->id,
4346
topology->connect_timeout_msec);
4447
}

tests/test-mongoc-topology-reconcile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ _test_topology_reconcile_rs (bool pooled)
176176
*/
177177
RS_RESPONSE_TO_ISMASTER (server0, true, true, server0); /* server1 absent */
178178

179-
assert (selects_server (client, tag_read_prefs, server1));
179+
assert (selects_server (client, tag_read_prefs, server0));
180180
assert (!client->topology->stale);
181181

182182
if (!pooled) {

tests/test-mongoc-topology-scanner.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,12 @@ test_topology_scanner_discovery ()
183183

184184
/* a single scan discovers *and* checks the secondary */
185185
AWAIT (scanner->async->ncmds == 1);
186-
ASSERT_CMPINT (1, ==, (int) mongoc_host_list_count (scanner->seen));
187186
request = mock_server_receives_ismaster (primary);
188187
mock_server_replies_simple (request, primary_response);
189188
request_destroy (request);
190189

191190
/* let client process that response */
192191
_mongoc_usleep (250 * 1000);
193-
ASSERT_CMPINT (2, ==, (int) mongoc_host_list_count (scanner->seen));
194192

195193
/* a check of the secondary is scheduled in this scan */
196194
AWAIT (scanner->async->ncmds == 1);
@@ -205,9 +203,6 @@ test_topology_scanner_discovery ()
205203
ASSERT_CMPSTR (sd->host.host_and_port,
206204
mock_server_get_host_and_port (secondary));
207205

208-
/* "seen" is reset */
209-
ASSERT_CMPINT (0, ==, (int) mongoc_host_list_count (scanner->seen));
210-
211206
mongoc_server_description_destroy (sd);
212207
future_destroy (future);
213208
request_destroy (request);
@@ -288,9 +283,6 @@ test_topology_scanner_oscillate ()
288283
assert (!future_get_mongoc_server_description_ptr (future));
289284
assert (scanner->async->ncmds == 0);
290285

291-
/* "seen" is reset */
292-
ASSERT_CMPINT (0, ==, (int) mongoc_host_list_count (scanner->seen));
293-
294286
future_destroy (future);
295287
request_destroy (request);
296288
mongoc_read_prefs_destroy (primary_pref);

0 commit comments

Comments
 (0)