Details
-
Improvement
-
Resolution: Unresolved
-
Unknown
-
None
-
None
-
None
-
None
Description
Background & Motivation
Server descriptions are used throughout the codebase. They have been the source of several bugs. I believe making server descriptions immutable would help maintainability.
CDRIVER-3653 describes an issue of attaching an incorrect server description to server streams. This resulted in CDRIVER-3404 and likely is the root cause of CDRIVER-4077 and CDRIVER-3563.
Confusing error processing in mongoc_server_description_handle_hello is the cause of CDRIVER-3696.
SDAM currently recommends treating a server description as immutable:
Multi-threaded drivers should treat ServerDescriptions and TopologyDescriptions as immutable: the client replaces them, rather than modifying them, in response to new information about the topology. Thus readers of these data structures can simply acquire a reference to the current one and read it, without holding a lock that would block a monitor from making further updates.
Scope
Remove mutable state from mongoc_server_description_t:
- generation: This represents a generation counter to expire connections in pooled clients, emulating the behavior of clearing the connection pool described in Clearing a Connection Pool. It is only accessed from server descriptions associated with a connection.
- generation_map: This stores the latest generation in the server. It is mapped from service IDs in load balanced mode. It is only accessed from server descriptions stored in the shared topology description.
- opened: This tracks whether a ServerOpening event has been emitted
Investigate whether removing the struct definition of mongoc_server_description_t from mongoc-server-description-private.h would be helpful.
Investigate what new internal API we would need to for constructing and copying server descriptions.