Topic: Install and Sync FA in 2 locations (HQ and branch) for one company

Is it possible to install FA in 2 separate locations for one company, and have both databases synchronize to each other over Internet connection (I'm thinking Master-to-Master replication in MySQL)?

Re: Install and Sync FA in 2 locations (HQ and branch) for one company

As I know this is not possible.

/Joe

Re: Install and Sync FA in 2 locations (HQ and branch) for one company

I have done exactly this. I'm using master/master replication on the MySQL db. I did this because our internet connection in both of our branches is very flakey, and also so that we have an automatic offsite backup that we can use live if a machine goes out for some reason. There is, however, an issue you should know about....

When the internet goes down, if both branches make, say, a general ledger entry then you get a replication error because the primary key is the next one, so both branches use the same number for their GL entries. It's probably the same with sales/purchases, but so far I've only seen the GL issue, and it's a nightmare to correct.

So, the replication works nicely as long as the connection is there, but that's catch 22 because if the connection is there then you don't need the replicated database - you could just work from one instance of FA. If the connection goes down then the 2 locations will be writing different GL data with the same transaction number and you'll get replication errors and lose data.

What we need (in the next version?) is the primary keys written with a machine specific number, i.e 102323, 4, 5 etc from server 1, and 2022323,4,5 etc from server 2.

FA team, this won't take much programming... are you OK to include this in the core? It would be a major feature to have a system that can be replicated and on top of the IT benefit it's like automatic consolidation from a Finance point of view. I am happy to help with the coding if you like.

Re: Install and Sync FA in 2 locations (HQ and branch) for one company

It still won't work.
When both dbs / FA Servers are online, each user is connected to the one server they started out with and hence populating the IDs with their sequence. When the Master-Master synch happens, both servers get their IDs synched and at the end they have both sequences of IDs. The AUTO_INC value will then taken after the highest value of the ID in both cases!

Re: Install and Sync FA in 2 locations (HQ and branch) for one company

Thanks for your input. I think what you are saying is that we are currently using the inbuilt AUTO_INCREMENT functionality of MySQL, and you are quite correct that this won't work as you have explained.

What I'm suggesting is that we hold (perhaps in the config file) a server number. So the config files on each server would be different, with one having  server=1 and the other server=2. Then we physically write the transaction id, instead of auto incrementing and append the server number to the end (I initially proposed prefixing but I think now that a postfix would be better). This could possibly also solve the problems we have with "Reference number already in use" if we adopted the same procedure for reference numbers. It's probably relatively easy to add this code, but I would like hear from you gurus before I even look at it, in case there's a clever way to do it that I haven't thought of.

What I do know is that the ability to have a replicated database is going to enhance FA, and I can give you 10 reasons why someone would want to do it. You probably already know the reasons...

Regards,

Re: Install and Sync FA in 2 locations (HQ and branch) for one company

The reference number of the next transaction is stored in the fa database and each db would have it's own next number.

Have just one db and another that is in Master-Slave Active-Passive replication. When the master goes down swap the master and slave whilst having some sort of backhaul synching between the two possibly on another interface.

Re: Install and Sync FA in 2 locations (HQ and branch) for one company

@Digger the reason why auto increment is used is to prevent a race condition.  Suppose two users both action an insert at the same time.  The only mechanism for serializing the request is the mysql server itself which will put the two requests in sequence.  The server then returns the id that it chose to identify the record it just wrote.  If the php code were to do this then there is the remote possibility that a write would be attempted with two identical keys.

The usual way to code around this is to get a key on creation.  This is called a GUID (or a UUID).  These are typically many bits long and created taking into account things like the local (to the FA web server) ethernet card MAC address and time.

IMHO this is not such a trivial change as you might think.

Cambell https://github.com/cambell-prince

Re: Install and Sync FA in 2 locations (HQ and branch) for one company

@cambell, thanks for your comments. I'm pretty new to this, and that's why input from gurus like yourself and @apmuthu is very much valued (Your O is not H but V).

I am now wondering if I can quite easily avoid replication issues by  "appropriately configuring auto_increment_increment & auto_increment_offset on each master" ? Am I a bit closer to taking the right road now? What are your thoughts on this, mate?

Re: Install and Sync FA in 2 locations (HQ and branch) for one company

@Digger that looks like it would work.  auto_increment_increment = 2 on both machines.  auto_increment_offset = 1 on the first machine and auto_increment_offset = 2 on the second machine.  The first machine would generate 1,3,5,7... the second machine would do 2,4,6,8 etc.

No code change required.  That's a nice easy option :-)

Here's the mySQL reference.

Cambell https://github.com/cambell-prince

10 (edited by apmuthu 08/26/2016 04:33:46 am)

Re: Install and Sync FA in 2 locations (HQ and branch) for one company

@cambell: Thanks for the info.

If the global value of either variable is set, its effects persist until the global value is changed or overridden by setting the session value, or until mysqld is restarted. If the local value is set, the new value affects AUTO_INCREMENT columns for all tables into which new rows are inserted by the current user for the duration of the session, unless the values are changed during that session.

Instructions on synching the lost master to the other master on return online would be useful.

Can these variables be set on a per database and/or per db.field on a permanent basis?

Re: Install and Sync FA in 2 locations (HQ and branch) for one company

@apmuthu,

I am informed that you can set the increment and offset etc/mysql/mysql.conf.d/mysqld.cnf, which will make it permanent and set it across all databases per machine. I am using MySQL 5.7.13 on Ubuntu 16.04. On older versions I seem to remember the config file was etc/mysql/my.cnf.

It says you can also use the functions through the command like in the terminal, but it doesn't say whether the increments would then remain permanent or just for that session. If you need to set this per database instead of per server then it might be worthwhile looking at the command line option, but for me I'm going to go with the config file setup.

I would like to thank you both for your help with this issue, and I'll let you know how it goes when I've tested it.