-
Notifications
You must be signed in to change notification settings - Fork 11
/
week-4.txt
163 lines (109 loc) · 7.18 KB
/
week-4.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
FAULT TOLERANCE AND AVAILABILITY:
Quiz:
1. Which of the following are considered part of best practices when doing rolling maintenance on a replica set? Check all that apply.
Perform maintenance on one secondary at a time.[T]
Ensure your replica set has a minimum of three data-bearing secondaries.[2 Secondaries are recommended]
Shut down a secondary and restart it without --replSet to perform maintenance.[T]
Restart secondaries on a different port when performing maintenance.[T]
None of the above. MongoDB does not recommend rolling maintenance.
2. Suppose your application is making use of a cursor to read a large amount of data from a sharded cluster. The mongos your application is talking to goes down and the application connects to another mongos. Which of the following will occur?
The new mongos will continue to use the same cursor seamlessly.
The cursor will be lost and an exception will be raised.[T]
The cursor will be reset, and the query will start over at the beginning of the result set when getmore is called next.
The cursor will skip one getmore call, so some documents in the result set will be skipped.
The cursor will behave as if it reached the end of the result set.
3. Which of the following are types of connections you might find in a replica set? Check all that apply.
Heartbeat connections between members
Connections from secondaries to their sync source in order to tail the oplog.
Connections from secondaries to their sync source to keep track of where they are in the oplog
Administrative connections from drivers to all members
Connections from clients reading from secondaries - All are True
4. Suppose you have an application backed by a sharded cluster. Each shard is a three-node replica set in which all nodes are data bearing. Your application is at 80% utilization for the maximum number of connections. Which type of process is the bottleneck in this scenario?
Mongos
Config server
Primary[T]
Secondary
Client
5. In mongodb 2.6, what is the hard limit on the maximum number of connections that a server can have?
10,000
20,000
30,000
40,000
There is no limit[T] - Prior to MongoDB 2.6, the upper limit for maxIncomingConnections for a mongod or mongos was 20,000. Starting with MongoDB 2.6, this is no longer the case. There is no longer an upper limit on what value you can choose as your maxIncomingConnections. http://docs.mongodb.org/manual/reference/configuration-options/#net.maxIncomingConnections
Note: For calculating max. number of mongos connections = maxPrimaryConnections - (numSecondarynodesinaRS * 3) - (numOtherconnections *3) // numMongos
maxPrimaryConnections - are limited by ulimit, memory, caps.
6. Which of the following are true of automatic rollback? Check all that apply.
Automatic rollback occurs only if rollback is less than 300MB.[T]
Manual intervention is always required to restore the data.[T]
Rollback can't occur if w="majority".
==============================================================================================================
H-w 4-1:
Answer:
Formula of max. number of mongos connections = maxPrimaryConnections - (numSecondarynodesinaRS * 3) - (numOtherconnections *3) / numMongos
maxPrimaryConnections - are limited by ulimit, memory, caps.
- Max. Primary Connections = 10,000 (From 10GB the limit here is memory)
- Num. of Secondaries in ReplicaSet = 2 (As each shard is a 3-node ReplicaSet)
- Num. of Other connections = 6 (From question)
- Num. of mongos hosts = 64 (From question)
Max. mongos Connections = (10,000 - (2*3) - (6*3))/64 = 9976/64 = 155.875
- As we have to use 90% of these: 155.875*0.9 = 140.2875
- Rounding: *140*
===============================================================================================================
H-w 4-2:
Answer:
- You can make use of week-3 - 3.1 mongod-{pri,sec,arb} db directories for setting up a RS.
Primary:
mongod --port 30001 --dbpath mongod-pri --replSet CorruptionTest --smallfiles --oplogSize 128
Secondary
mongod --port 30002 --dbpath mongod-sec --replSet CorruptionTest --smallfiles --oplogSize 128
Arbiter
mongod --port 30003 --dbpath mongod-arb --replSet CorruptionTest
- Loging to PRIMARY SHELL and drop the testColl collection:
> mongo --port 30001
> use testDB > db.testColl.drop() or you can delete all the docs in the collection.
- Insert some doc to the same colletion with "a field in the docs":
db.testColl.insert({"a":"Aleksandr"})
db.testColl.insert({"a":"Balakiriev"})
db.testColl.insert({"a":"Balakirevs"})
db.testColl.insert({"a":"Abv"})
- As you've 3 nodes(P,S & A), now takedown the SECONDARY node(Make sure you have the above 4 docs in the testDB.testColl).
mongo --port 30002
> use admin
> db.shutdownServer().
- Start the secondary in standalone mode:
mongod --port 30002 --dbpath mongod-sec
- Connect to this standalone node(which is running on 30002) and create a index on the "a" field:
mongo --port 30002
> use testDB
> db.testColl.ensureIndex({"a":1})
- Shutdown this standalone node and add it back to ReplicaSet:
use admin
> db.shutdownServer()
- Adding back to RS: mongod --port 30002 --dbpath mongod-sec --replSet CorruptionTest --smallfiles --oplogSize 128
- Done, Make sure your MongoProc checks on 30001 port
==============================================================================================================
H-w 4.3:
Answer:
- set up a ReplicaSet like in H-w 3-1.
- Login to PRIMARY and start inserting the data: for(var i = 0; i <= 1000000 ; i++){db.rollback.insert({"a" : i}); sleep(100);}
- Break the replication: kill -SIGSTOP <PID of Mongod running on 30002>
- Then kill -SIGINT <PID of Mongod running on 30001>; kill -SIGCONT <PID of Mongod running on 30002>
- Above command will kill the PRIMARY and will allow the Secondary node to continue. So, the SECONDARY node running on 30002 will be promted as PRIMARY now and the write which have happend while the SECONDARY node was stopped should be rolled back when we add the PRIMARY node(which runs on 30001) back to the set and it will be added as a SECONDARY node.
- To add it back to the ReplicaSet:
*Note:* MongoProc has some bug here and you need to mention the absolute pathname for --dbpath.
mongod --port 30001 --dbpath /home/user/Downloads/4_2/mongod-pri/mongod-pri --replSet CorruptionTest --smallfiles --oplogSize 128
➜ ~ ls -lrt /home/user/Downloads/4_2/mongod-pri/mongod-pri
total 458776
-rw------- 1 user user 16777216 May 7 23:59 testDB.ns
-rw------- 1 user user 67108864 May 7 23:59 testDB.2
-rw------- 1 user user 33554432 May 7 23:59 testDB.1
-rw------- 1 user user 16777216 May 7 23:59 testDB.0
drwxr-xr-x 2 user user 4096 May 8 15:53 journal
-rwxrwxr-x 1 user user 6 May 25 22:35 mongod.lock
drwxrwxr-x 2 user user 4096 May 25 22:35 rollback
-rw------- 1 user user 16777216 May 25 22:35 local.0
-rw------- 1 user user 16777216 May 25 22:35 test.ns
-rw------- 1 user user 16777216 May 25 22:35 test.0
-rw------- 1 user user 16777216 May 25 22:35 local.ns
-rw------- 1 user user 268435456 May 25 22:35 local.1
- You can see the rollback directory here. which is nothing but the bsondump of the writes which had happened while the SECONDARY(which is not PRIMARY) is down. You can restore this dump using the mongorestore command.