replicating data over 2 servers

Jim Dixon jdd at dixons.org
Tue May 27 15:35:53 PDT 2003


On Tue, 27 May 2003 nbari at unixmexico.com wrote:

> hi all, i have to servers (A, B) with round robin DNS, users enter to
> server A and server B and they write to a txt file, how can i sync the
> file from both server so it can be always the same? for example if a user
> enter to server A and modify some data, replicate that modification to
> server B so when user enter to server B he can see his changes, and the
> same if user modify a file on server B, replicate that file to server A,
> any idea?

We need more information.

How often does the data get changed?  How much delay is tolerable?
Are the two servers on the same LAN or in different places on the
Internet?  Most important, how do you define "the same"?  Is it
tolerable if the servers are out of sync for a few milliseconds?
for a few seconds? minutes?

You probably need a protocol for writing like this:

1	lock local copy of data
2	lock remote copy of data
3	write new values
4	unlock remote copy
5	unlock local copy

This guarantees that data on the two servers will be consistent.  For
better performance (less delay perceived by the user):

1	read-lock local copy (ie, no writing permitted, but reading OK)
2	write-lock remote copy (no reading, no writing)
3	write-lock local copy
4	update values
5	drop local lock to read-lock
6	unlock remote copy
7	unlock local copy

You can elaborate the protocol to allow for server failures.  Dealing
with network failures is more interesting.

You could do this with a Perl script and ssh without much trouble,
assuming that the data was coarse-grained, ideally a single item ;-)

If the data has a complex structure and there is lots of it, then you
probably need a distributed database.

--
Jim Dixon  jdd at dixons.org   tel +44 117 982 0786  mobile +44 797 373 7881




More information about the freebsd-isp mailing list