Hi,
We are heavily using Kamailio in our product Sipwise NGCP and currently testing possibility to provide rollback for the customers with the huge systems as the last resort functionality in case if upgrade went wrong. We hope never use it on practice but prefer to have such possibility.
The main logic here is to change DB in 'backward compatible' way. So OLD code must work with NEW DB schema (but NOT a vice verse).
We have some rules which helps us care about it, like "Do not drop columns, just discontinue them" and "All new fields should have defaults", etc.
Also we have separated 'code', 'configs' and 'data' parts of our product and rollback 'code'/'configs' only, while 'data' (e.g. MySQL DB) stays in new state. Otherwise rollback will require a lot if time to revert all DB statements and sometimes it is just not possible.
While every time we have to upgrade Kamailio we have a problems with rollback possibility. The point here that Kamailio checks DB table_version and doesn't start if the version mismatch found.
Q: What about to add Kamailio possibility to work in backward compatible mode?
Sample for upgrade Kamailio 4.3.x -> 4.4.x (the versions here as an example only!) https://www.kamailio.org/wiki/install/upgrade/4.3.x-to-4.4.0 We have 3 DB statements there which are adding new columns to 3 tables, like
-- table: active_watchers ALTER TABLE active_watchers ADD COLUMN flags INT(11) NOT NULL DEFAULT '0', ADD COLUMN user_agent VARCHAR(255) NOT NULL; DELETE FROM version WHERE TABLE_NAME='active_watchers'; INSERT INTO version (`table_name`, `table_version`) VALUES
('active_watchers','12');
Problem here is missed default for column 'user_agent' which can be empty value as for me. So, lets assume we have it there. Then we can add new column to table 'version', like that:
mysql> select * from version where table_name='active_watchers'; +-----------------+---------------+---------------------+ | table_name | table_version | table_compatibility | +-----------------+---------------+---------------------+ | active_watchers | 12 | 11 | +-----------------+---------------+---------------------+ 1 row in set (0.00 sec)
Currently: - module presence version 4.4.x starts check required version and refuse to load if table_version!=12
Proposed behaviour: - module presence version 4.4.x starts check required version and refuse to load if table_version!=12 and compatibility option is not set - if compatibility option is set, check value of table_compatibility and refuse to load if current version less then table_compatibility value
From the sample above I would say module presence in Kamailio 4.4.x is
compatible with Kamailio 4.3.x if we define default value for the field 'user_agent'.
Having that will allow us to rollback on previous NGCP release and _temporary_ work on Kamailio 4.3.x having new Kamailio DB 4.4.x
P.S. This is just a question to check Kamailio community vision here and reality is more complex as described, so some additional checks/limitations will be in place.
P.P.S Compatibility Kamailio option can/should be disabled by default. Field 'table_compatibility' can be outside table 'version', e.g. in separate table. Complete compatibility logic can be some separate Kamailio 'compatibility' module.
Thank you!
Alex Lutay writes:
The point here that Kamailio checks DB table_version and doesn't start if the version mismatch found.
Yes, it makes sense to be able to run older version of k on newer table versions as long as newer versions of tables are backwards compatible, e.g., a new field has been added which is not used by older version.
-- Juha
I personally am against this 'version' table concept altogether. It just makes life difficult for expert users without meaningfully solving the problem it seeks to solve.
It's just an arbitrary table; what guarantees does it offer that the version of the definition of table X corresponds to the version identifier in the version table? And the fact that it's called 'version' and can only be called 'version' and must reside in the same schema and database as that which corresponds to the db_url of certain DB-backed modules is an additional source of pain in certain situations.
At the very least, it ought to be possible to turn the whole concept off, globally, with a modparam or a core directive. Ideally it should be gotten rid of altogether. It doesn't stop anyone from using wrong versions of table definitions--a noble and laudable goal. It just adds this annoying dependency that has to be maintained constantly.
It's possible to validate table definitions by inspecting schematic metadata (in major RDBMs), but I can understand why interest in implementing something so DBM-specific in the DB APIs may be limited. Maybe something like inserting a test row and then selecting * and doing an MD5 sum on it can work too. Or maybe the program can just trust that everyone's a big kid and can manage their DB tables, as they do with other applications that also change versions, alter their table definitions over time, etc. :-)
-- Alex Balashov | Principal | Evariste Systems LLC 1447 Peachtree Street NE, Suite 700 Atlanta, GA 30309 United States
Tel: +1-800-250-5920 (toll-free) / +1-678-954-0671 (direct) Web: http://www.evaristesys.com/, http://www.csrpswitch.com/
Sent from my BlackBerry.
On dinsdag 12 april 2016 11:42:53 CEST Alex Lutay wrote:
The point here that Kamailio checks DB table_version and doesn't start if the version mismatch found.
As long as table versions are backwards compatible, just use a separate "version" table for each Kamailio version you deploy. Set the table version to the one expected by the corresponding kamailio version.