mysql::replication (melbourne perl mongers 2011-07)

Download MySQL::Replication (Melbourne Perl Mongers 2011-07)

If you can't read please download the document

Upload: alfie-john

Post on 31-May-2015

4.924 views

Category:

Technology


3 download

TRANSCRIPT

  • 1. MySQL::Replication

2. what is it? 3. It's a replacement for 4. MySQL Replication 5. why? 6. first... 7. what is replication? 8. synchronising data 9. between multiple databases 10. db1 db2 11. why replicate? 12. examples... 13. redundancy 14. database client client client client client client client client 15. database on client client client client client client client client 16. database on fire client client client client client client client client 17. database on fire client client client client client client client client 18. database on fire client client client client client client client client 19. arhhhh! 20. If we had replicated 21. to a hot standby 22. clients could be moved 23. 24. 25. another example 26. performance 27. database client 28. database client client 29. database client client client 30. database client client client client 31. database client client client client client 32. database client client client client client client 33. database client client client client client client client 34. database client client client client client client client client 35. database client client client client client client client client 36. database client client client client client client client client 37. arhhhh! 38. If we replicated 39. for scale out 40. load would be spread 41. 42. 43. 44. 45. 46. 47. 48. 49. so... 50. why replicate? 51. because it gives you benefits 52. compared to having 53. a single database 54. so... 55. how does it work? 56. in particular... 57. how does MySQL Replication work? 58. 59. master 60. master slave 61. master client slave 62. master client binlog slave 63. master client binlog slave relay 64. master client binlog slave relay 65. the cool thing is 66. each slave 67. can be a master 68. to other slaves 69. master slave slave slave 70. master slave slave master/slave slave 71. master master/slave slave master/slave slave slave 72. this works fine 73. but... 74. slaves can only have asinglemaster 75. master master/slave slave master/slave slave slave 76. so? 77. that means... 78. no multiple masters 79. slave master master master 80. slave master master master 81. why not? 82. don't ask me 83. because I don't know 84. but... 85. we canemulatemultiple masters 86. to do this 87. we have to 88. setup a ring topology 89. what? 90. each slave 91. is a master 92. to another slave 93. master slave 94. master slave master/slave 95. master master/slave master/slave slave 96. master/slave master/slave master/slave master/slave 97. 98. so... 99. how does this achieve 100. multiple master replication? 101. by having each master 102. writeallqueries 103. to it's binlog 104. ...including the queries 105. it replicated 106. fromitsmaster 107. huh? 108. queries are passed 109. around the ring 110. kind of like 111. pass the parcel 112. 113. why is this a problem? 114. when the ring breaks 115. 116. 117. 118. 119. 120. arhhhh! 121. so does everything else 122. ...and recovery is hard 123. why? 124. infinite loops! 125. what do you mean? 126. each master 127. is responsible 128. for termination 129. of its own queries 130. around the ring... 131. in other words 132. queries don't replicate infinitely 133. because 134. a master won't relay 135. its own queries twice 136. 137. so... 138. what happens if... 139. a database goes down? 140. we recover by 141. ...reconnecting the links 142. ...and restarting replication 143. ? 144. 145. 146. (OpenOffice doesn't do the arrow I wanted) 147. hang on... 148. who was responsible 149. for terminating 150. the failed database's queries? 151. hrmmm... 152. if there are queries 153. from the failed database 154. still replicating 155. that haven't yet terminated 156. 157. arhhhh 158. Infinite queries, infinitely replicating 159. so... 160. how can I achieve 161. multiple master replication 162. ...that is fault tolerant 163. ...and is easy to recover from? 164. MySQL::Replication 165. It's a replacement 166. for MySQL's built-in replication 167. it's a client/server model 168. each master runs the server 169. slave master master master 170. slave master master server 171. slave server master server 172. slave server server server 173. each slave runs the client 174. ...and the client 175. can run multiple instances 176. (one for each server) 177. (think peer-to-peer) 178. slave server server server 179. client(s) server server server 180. and if something breaks 181. client(s) server server server 182. client(s) server server server 183. client(s) server server server 184. only the peer connection is effected 185. client(s) server server server 186. client(s) server server server 187. and if the failed database recovers 188. we restart from where we left off 189. client(s) server server server 190. client(s) server server server 191. otherwise 192. we just fail it out 193. and can take our time rebuilding 194. it was redundant anyway 195. right? 196. :) 197. ohh 198. ...and no infinite loops 199. why? 200. since we connect 201. directly to the server 202. no intermediary connections 203. can break 204. there's more... 205. relay caching 206. say what? 207. instead of connecting 208. directly to the master 209. the client 210. connects to a local relay 211. if it doesn't have 212. the queries we want 213. it will get them for us 214. example 215. multiple clients 216. in data centerA 217. ...each connect 218. to a server 219. in data centerB 220. ...each download the same queries 221. what a waste 222. ...in bandwidth 223. ...and server load 224. so... 225. instead 226. ...each connect 227. to a local relay 228. now... 229. only a single client (the relay) 230. connects to the server 231. ...saves bandwidth 232. ...saves server load 233. :) 234. so... 235. CPAN? 236. almost ready 237. client/server working in production 238. I just need to do the documentation 239. then I'll put it on CPAN 240. what about the relay stuff? 241. It's nearly complete... 242. I just need to finish 243. ...a couple more test harnesses 244. ...and write the documentation 245. FAQ 246. what happens with collisions? 247. when two databases 248. update the same record 249. It's a race condition 250. solution? 251. solve it at the application layer 252. use a broker for global IDs 253. or shard writes 254. questions? 255. [email_address]