Permalink
Browse files

mongo-sync: Support passive secondaries.

Secondaries with priority 0 do not appear in ismaster's 'host' array,
but they're present in 'passives'. Since for reading, these passives
are perfectly fine, append them to our host set.

This means that passives are automatically discovered aswell, and the
library treats them as any other server. Which in turn makes the
connection pool work even when there's a master and passives.

No test cases were written, as testing this requires external setup.
  • Loading branch information...
1 parent f7ed02d commit fc77655e0a39a2b313762b4f458ea801dd9b9ee1 @algernon committed Jun 17, 2011
Showing with 23 additions and 1 deletion.
  1. +4 −0 NEWS
  2. +19 −1 src/mongo-sync.c
View
4 NEWS
@@ -8,6 +8,10 @@ and returned whatever already arrived at the time of reading.
This has been corrected, mongo_packet_recv() correctly blocks now.
+** Implemented support for passive secondaries.
+Support was added for passive secondaries, they're now automatically
+discovered too.
+
* 0.1.1 - <2011-06-16 Thu>
** Cursor-based query iterator API
View
@@ -1208,7 +1208,6 @@ mongo_sync_cmd_is_master (mongo_sync_connection *conn)
return b;
}
bson_cursor_free (c);
- bson_free (res);
bson_finish (hosts);
/* Delete the old host list. */
@@ -1231,6 +1230,25 @@ mongo_sync_cmd_is_master (mongo_sync_connection *conn)
bson_cursor_free (c);
bson_free (hosts);
+ c = bson_find (res, "passives");
+ if (bson_cursor_get_array (c, &hosts))
+ {
+ bson_cursor_free (c);
+ bson_finish (hosts);
+
+ c = bson_cursor_new (hosts);
+ while (bson_cursor_next (c))
+ {
+ const gchar *s;
+
+ if (bson_cursor_get_string (c, &s))
+ conn->rs.hosts = g_list_append (conn->rs.hosts, g_strdup (s));
+ }
+ bson_free (hosts);
+ }
+ bson_cursor_free (c);
+
+ bson_free (res);
errno = 0;
return b;
}

0 comments on commit fc77655

Please sign in to comment.