[mythtv-commits] mythtv commits

mythtv at cvs.mythtv.org mythtv at cvs.mythtv.org
Tue Mar 8 01:40:02 UTC 2005


----------------------------------------------------------------------------
Changes committed by cpinkham on Tue Mar  8 01:38:50 2005

Modified Files:
   in mythtv/libs/libmythtv:
        dbcheck.cpp 
Log Message:


Add a wrapper around UpgradeTVDatabaseSchema() to set a lock to make sure
that multiple backends and/or frontends started at almost the same time
do not try to upgrade the database at the same time.  The lock works by
creating a table called "schemalock" and locking that table.  This appeared
to be the easiest way to accomplish exclusive schema update access across
multiple frontends/backends/computers, because of the way that MySQL does
locking.  If I had tried to lock individual tables, all schema updating
would have to be done in a single DB connection.  If this were true, then
any new tables created would also have to be locked which would require
more logic when adding new schema updates.  Locking a non-related table
for exclusive access was an easy way of getting an exclusive lock for
updating the schema.  A warning message is printed before the lock is
acquired warning the user that there could be a long pause if the schema is
being updated elsewhere.  If the schemalock table cannot be created initially
or the lock cannot be acquired, a message is printed along with the MySQL
error.  The Write lock on the schemalock table is exclusive, and is acquired
in the wrapper function before any schema updates are initiated.  The lock 
is not acquired and the warning message is not printed if the DB version
is up to date.

I've been running this on my system for a week or two and have started the
backend and frontend multiple times at the same time and one or the other
always gets locked waiting for the other to finish upgrading the database.
Previously they would both start doing updates and would both potentially
get errors.  My dev box DB gets copied from my production DB every night so
I "upgrade" my dev database at least once a day whenever my production DB is
behind the current CVS DB schema.

Hopefully I explained that well enough to squelch any questions. :)


----------------------------------------------------------------------------


More information about the mythtv-commits mailing list