41. 41
More Reading
• The spec author Jess Jiryu Davis has a collection of links and his better
version of this talk
https://emptysqua.re/blog/server-discovery-and-monitoring-in-mongodb-
drivers/
• The full server discovery and monitoring spec is on GitHub
https://github.com/mongodb/specifications/blob/master/source/server-
discovery-and-monitoring/server-discovery-and-monitoring.rst
42.
43. 43
insert_one
• Stages
– Parse the parameters
– Get a socket to write data on
– Add the object Id
– Convert the whole insert command and parameters to a SON object
– Apply the writeConcern to the command
– Encode the message into a BSON object
– Send the message to the server via the socket (TCP/IP)
– Check for writeErrors (e.g. DuplicateKeyError)
– Check for writeConcernErrors (e.g.writeTimeout)
– Return Result object
45. 45
Bulk Write
• Create Bulker object
• Accumulate operations
• Each operation is created as a SON object
• The operations are accumulated in a list
• Once execute is called
– For ordered execute in order added
– For unordered execute INSERT, UPDATEs then DELETE
• Errors will abort the whole batch unless no write concern specified
Notes de l'éditeur
Primary secondary, secondary
Primary secondary, secondary
Primary secondary, secondary
Primary secondary, secondary
Primary secondary, secondary
Present a native language interface - converts python types to BSON objects
Convert the JSON query language into commands for the database
Convert JSON data into BSON data and vice-versa
Handles interfacing to different MongoDB topologies
Helps recover from server side outages/network errors
Manages the client side connection pool
The pymongo driver code is on Github (Apache License)
Present a native language interface - converts python types to BSON objects
Convert the JSON query language into commands for the database
Convert JSON data into BSON data and vice-versa
Handles interfacing to different MongoDB topologies
Helps recover from server side outages/network errors
Manages the client side connection pool
The pymongo driver code is on Github (Apache License)
Calls i
Calls i
State machine, full set of states defined in spec.
Calls i
Calls i
Calls i
Needs a primary to complete a write.
Needs a primary to complete a write.
Needs a primary to complete a write.
Needs a primary to complete a write.
Each thread wakes every 10 seconds. Runs ismaster, sleeps.
We use ismaster to check latency.
Keep topology description up to date.
Each thread wakes every 10 seconds. Runs ismaster, sleeps.
We use ismaster to check latency.
Keep topology description up to date.
Each thread wakes every 10 seconds. Runs ismaster, sleeps.
We use ismaster to check latency.
Keep topology description up to date.
Primary is marked as unknown
Wakes up all monitor threads to check for a primary.
Primary is marked as unknown
Wakes up all monitor threads to check for a primary every half second.
Primary is marked as unknown
Wakes up all monitor threads to check for a primary every half second.
Each thread wakes every 10 seconds. Runs ismaster, sleeps.
We use ismaster to check latency.
Keep topology description up to date.
Try once. This will accomdate elections. Other errore should be propagated.
Try once. This will accomdate elections. Other errore should be propagated.
Can you afford to over or under count.
Operations need to be idempotent.
Turn an update into a write of a document, cf EventSourcing.
Then aggregate on the server.
How long should a connection wait before timing out and sleeping for 10 seconds.
How long should a connection wait before timing out and sleeping for 10 seconds.