alphagov/trade-tariff-backend — pull request #19 by sauliusg (2012-10-19 08:28:14+00:00)
Title: DB Locks & Database backed updates

So the effort here is to make Tariff cluster-compatible and make update management easier.

* Adds Db based locks (http://dev.mysql.com/doc/refman/5.1/en/miscellaneous-functions.html#function_get-lock). So any of the backend nodes can run cron jobs. The first one will acquire a lock and proceed with tariff:sync:download and tariff:sync:apply.
* Adds blob column to tariff_updates table and keeps updates there instead of file system. This brings several benefits:
* Less code to manage (no code that deals with file management)
* All nodes see the same updates (no need to rsync/nfs/s3 files)
* DB snapshots are now completely integral (the one I make should continue to run fine on production because it has all updates in).

There is a drawback however: we need to increase max_allowed_packet size in MySQL configuration, because CHIEF updates tend to be bigger than 16Mb (current setting, AFAIK). The biggest we've seen in almost half a year is 18Mb. I think 64Mb would be a good choices, leaves plenty of buffer space. Please mind, this is not frequently read data, it's not that we will be serving images from DB. Ideally it will be written and read just once by background processes.

Also, I think that update download times and content sizes should be measured by Statsd so we would get a general idea about trends but this is for another PR.