7. Why Replication?
• How many have faced node failures?
• How many have been woken up from sleep to do a
fail-over(s)?
• How many have experienced issues due to network
latency?
• Different uses for data
– Normal processing
– Simple analytics
23. Tagging
• Control where data is written to, and read from
• Each member can have one or more tags
– tags: {dc: "ny"}
– tags: {dc: "ny", subnet: "192.168", rack:
"row3rk7"}
• Replica set defines rules for write concerns
• Rules can change without changing app code
26. Read Preference Modes
• 5 modes
– primary (only) - Default
– primaryPreferred
– secondary
– secondaryPreferred
– Nearest
When more than one node is possible, closest node is used
for reads (all modes but primary)
27. Tagged Read Preference
• Custom read preferences
• Control where you read from by (node) tags
– E.g. { "disk": "ssd", "use": "reporting" }
• Use in conjunction with standard read
preferences
– Except primary
28. Our application
//connect to a replica set, with auto-discovery of the primary, supply a seed
list of members
MongoClient mongoClient = new MongoClient(Arrays.asList(new
ServerAddress("localhost", 27017),
new ServerAddress("localhost", 27018),
new ServerAddress("localhost", 27019)));
DB db = mongoClient.getDB( "mydb" );
60. Shard Key
• Shard key is immutable
• Shard key values are immutable
• Shard key must be indexed
• Shard key limited to 512 bytes in size
• Shard key used to route queries
– Choose a field commonly used in queries
• Only shard key can be unique across shards
– `_id` field is only unique within individual shard
Basic explanation
2 or more nodes form the set
Quorum
Initialize -> Election
Primary + data replication from primary to secondary
Primary down/network failure
Automatic election of new primary if majority exists
New primary elected
Replication established from new primary
Down node comes up
Rejoins sets
Recovery and then secondary
Consistency
Write preferences
Read preferences
Not really fire and forget.
This return arrow is to confirm that the network successfully transferred the packet(s) of data.
This confirms that the TCP ACK response was received.
_id could be unique across shards if used as shard key.
we could only guarantee uniqueness of (any) attributes if the keys are used as shard keys with unique attribute equals true