[CDRIVER-4078] Make server description immutable Created: 14/Jul/21  Updated: 15/Apr/22

Status: Backlog
Project: C Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Unknown
Reporter: Kevin Albertson Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: CDRIVER-4107

 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.


Generated at Wed Feb 07 21:19:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.