View previous topic :: View next topic |
Author |
Message |
Jesore Apprentice
Joined: 17 Jul 2002 Posts: 232 Location: Nürnberg Germany
|
Posted: Wed Nov 26, 2003 6:56 pm Post subject: mysql replication |
|
|
I've read myself a bit into mysql replication and have a question. is it possible to have an equal servers setup instead of master/slave? It would really help with my task if I could do update queries on both servers.
Another dbms is not possible at the moment as the whole system already runs on an mysql/php basis and we don't have the resources to start from scratch (or do some extensive reprogramming).
Before I forget - the servers are in different locations (actually different countries)
Any ideas?
Jesore |
|
Back to top |
|
|
kashani Advocate
Joined: 02 Sep 2002 Posts: 2032 Location: San Francisco
|
Posted: Wed Nov 26, 2003 10:41 pm Post subject: |
|
|
Here's the scenario
mysql0 is the master
mysql1 is a slave
mysql2 is a slave
mysql3 is a slave
You can do any data reads (like SELECT) from any machine, generally you'd want to only do them on the slaves.
You can only do writes (DELETE INSERT) only on the master.
That's as good as it gets without changing your db and throwing some serious money at the problem.
kashani _________________ Will personally fix your server in exchange for motorcycle related shop tools in good shape. |
|
Back to top |
|
|
Jesore Apprentice
Joined: 17 Jul 2002 Posts: 232 Location: Nürnberg Germany
|
Posted: Thu Nov 27, 2003 8:18 am Post subject: |
|
|
this is ... not good.
The scenario is the following. At the moment we have a single server used for writing tests online (like LPI certification - basically). All training centers use the same server.
As the number of centers grows (and the tests with it) a backup would be nice, so if one server dies we could just move to another and write the test there. Ideally in the middle of the test with all already answered questions there. That's where the need of writes comes in.
Hmm, would it be possible to switch the roles of the servers fast in case of an emergency? Turn the slave into a single server, write tests there and when the old server is back write all new datsa back and then turn it into the master again.
I'm no expert in this field yet (got the task yesterday) so if this is a stupid idea bear with me.
Jesore |
|
Back to top |
|
|
Kirigoe Tux's lil' helper
Joined: 10 Jan 2003 Posts: 147 Location: concrete hut, sweden
|
Posted: Thu Nov 27, 2003 10:59 am Post subject: |
|
|
quoting http://www.mysql.com/doc/en/Replication_FAQ.html:
Quote: | MySQL replication currently does not support any locking protocol between master and slave to guarantee the atomicity of a distributed (cross-server) update. In other words, it is possible for client A to make an update to co-master 1, and in the meantime, before it propagates to co-master 2, client B could make an update to co-master 2 that will make the update of client A work differently than it did on co-master 1. Thus, when the update of client A will make it to co-master 2, it will produce tables that are different than what you have on co-master 1, even after all the updates from co-master 2 have also propagated. So you should not co-chain two servers in a two-way replication relationship, unless you are sure that your updates can safely happen in any order, or unless you take care of mis-ordered updates somehow in the client code. |
so there's no native support (yet) for having several masters. what i would recommend you do is design your php application to be able to fail over to one of the slaves. i dont know your scenario but i think it's a decent solution to ping the slaves continuously and randomize any read-only queries out to the ones online, load-balancing for short, or use a fail-over method of choosing slave, and if the master becomes unresponsive, deny all write queries in the php application with a warning to the user, send an email to the administrator (you) to fix the master, and if you can't, you've got some time to setup one of the slaves as a master instead.
so unless your php application is very much depending on write queries (INSERT, UPDATE), then i think you would come a long way with this, without having to deal with synchronizing mysql servers, that basically means locking any other write requests while checking if the databases are up-to-date.
oh, and if you're in los angeles, watch out how you use the term master/slave
hope it helps![/url] _________________ + adopt an unanswered post today!
+ kimono network monitor
+ downshift.org |
|
Back to top |
|
|
Jesore Apprentice
Joined: 17 Jul 2002 Posts: 232 Location: Nürnberg Germany
|
Posted: Thu Nov 27, 2003 1:39 pm Post subject: |
|
|
The database gets updated each time one user answeres a question. With 50 questions/user and a rising number of tests written simultaniously, there are quite a lot of writes.
Basically without inserts/updates the application stops working.
Btw. do you think they'd come over to europe to arrest me because I used master/slave |
|
Back to top |
|
|
kashani Advocate
Joined: 02 Sep 2002 Posts: 2032 Location: San Francisco
|
Posted: Thu Nov 27, 2003 8:39 pm Post subject: |
|
|
You might think about having your PHP write to flat file initially. Then have a second process handle the db logic every 10 minutes or so. You could lose a bit of data if a server failed, but breaking it out like this might allow you to play db games in the background without having to get fancy.
kashani _________________ Will personally fix your server in exchange for motorcycle related shop tools in good shape. |
|
Back to top |
|
|
Jesore Apprentice
Joined: 17 Jul 2002 Posts: 232 Location: Nürnberg Germany
|
Posted: Mon Dec 01, 2003 8:11 am Post subject: |
|
|
That would be possible.
But after what I've found out, the boss told me to just setup the master/slave replication for backup purposes. If the master dies we have an exact mirror we can dump and restore to the master.
The whole app will be rewritten from scratch over the next year if all goes well (after all we're trying to hire a java expert - keep fingers crossed that he comes).
jesore |
|
Back to top |
|
|
Wilhelm Tux's lil' helper
Joined: 27 May 2003 Posts: 149
|
Posted: Sun Aug 22, 2004 11:17 am Post subject: |
|
|
Hi guys i was reading this thread because i want a DNS server running MyDNS and thus the master slave thing should work for me since adding entries is not a widespread usage.
To comment on Jesore
With distributed systems it's all down to consistency and it can never be achieved however it depends on what relaxed version of consistency you allow. As i can read your looking for causal consistency on your reads and writes which is possible however mysql doesn't support it as read by the Kirigoe. Causal consistency means that your messages have a natural ordering.
You should think about what reads or writes will disrupt the usage of your system because if not done properly you could get failures causing a reply to a thread to be added whilst the posting was lost which is not at all wanted.
My simple solution for your problem is to attack the problem from the other side. If you stop the master server from going down in the first place you've soleved your problem. By running one expensive server and inexpensive slaves. With expensive i mean
- Redundancy by RAID (hotpluggable disks)
- UPS for power failures (even if nessecary backed up by a generator)
- Multiple CPU's
- etc.
It will be highly unlikely that your server will bork and your system should be running ok and consistent. Only real threat would be hackers but if your master is a pure MySQL machine with no other access but physical or tightly monitored access your safe.
It all depends on the money your willing to invest. |
|
Back to top |
|
|
kashani Advocate
Joined: 02 Sep 2002 Posts: 2032 Location: San Francisco
|
Posted: Sun Aug 22, 2004 6:21 pm Post subject: |
|
|
Wow. Nice little blast from the past.
For something that does very little updating or something that can handle latencies of a sec or so data sync between their databases I would now recommend circular replication.
Master A -> Slave B
Master B -> Slave A
Master A beign also Slave A, etc. There are a number of caveats with circular replication, but with something that's likely to be low impact such as DNS serving I think it would work well and cause very little problems.
On the other hand, as long as you did replication your servers would be fine until you got the master back so maybe it's more trouble than it's worth.
kashani _________________ Will personally fix your server in exchange for motorcycle related shop tools in good shape. |
|
Back to top |
|
|
Wilhelm Tux's lil' helper
Joined: 27 May 2003 Posts: 149
|
Posted: Thu Aug 26, 2004 6:16 pm Post subject: |
|
|
Yes i'm just setting up 1 master and 1 slave. If the master (A) goes down i can either fix it or temporarily make the slave (B) the master.
Circular replication on the otherhand is a kewl idea ... never knew it could be done.
Thnx
PS. Hmm never checked how old those postings were |
|
Back to top |
|
|
|