Ticket #5584: wait-schemalock.patch
File wait-schemalock.patch, 4.9 KB (added by , 16 years ago) |
---|
-
dbutil.cpp
205 205 return true; 206 206 } 207 207 208 // HACK: If an upgrade failed, the schemalock table may still be locked. 209 // Both backup commands currently try to lock all tables, 210 // and thus will silently sit waiting forever. 211 if (isSchemaLocked()) 212 { 213 MythTimer elapsedTimer; 214 elapsedTimer.start(); 215 216 do 217 { 218 VERBOSE(VB_IMPORTANT, "Database schema are locked. Waiting..."); 219 sleep(1); 220 } 221 while (isSchemaLocked() && (elapsedTimer.elapsed() < 10000)); 222 223 if (isSchemaLocked()) 224 { 225 VERBOSE(VB_IMPORTANT, "Still locked. Cannot backup/upgrade DB"); 226 return false; 227 } 228 } 229 208 230 QString backupScript = GetShareDir() + "mythconverg_backup.pl"; 209 231 backupScript = gContext->GetSetting("DatabaseBackupScript", backupScript); 210 232 … … 680 702 return count; 681 703 } 682 704 705 bool DBUtil::IsTableLocked(const QString &name) 706 { 707 DatabaseParams dbParams = gContext->GetDatabaseParams(); 708 MSqlQuery query(MSqlQuery::InitCon()); 709 710 query.exec("SHOW OPEN TABLES FROM " + dbParams.dbName); 711 while (query.next()) 712 if (query.value(1).toString() == name && query.value(2).toInt() > 0) 713 return true; 714 715 return false; 716 } 717 683 718 /** 684 719 * \brief Try to get a lock on the table schemalock. 685 720 * … … 713 748 query.exec("UNLOCK TABLES;"); // Should this _just_ unlock schemalock? 714 749 } 715 750 751 bool DBUtil::isSchemaLocked(void) 752 { 753 return IsTableLocked("schemalock"); 754 } 755 716 756 /* vim: set expandtab tabstop=4 shiftwidth=4: */ -
dbutil.h
34 34 static bool IsNewDatabase(void); 35 35 static bool IsBackupInProgress(void); 36 36 static int CountClients(void); 37 static bool IsTableLocked(const QString &); 37 38 38 39 static bool lockSchema(MSqlQuery &); 39 40 static void unlockSchema(MSqlQuery &); 41 static bool isSchemaLocked(void); 40 42 41 42 43 static const int kUnknownVersionNumber; 43 44 44 45 protected: -
schemawizard.cpp
105 105 VERBOSE(VB_IMPORTANT, "Database schema is old." 106 106 " Waiting to see if DB is being upgraded."); 107 107 108 MSqlQuery query(MSqlQuery::InitCon());109 108 bool backupRunning = false; 110 109 bool upgradeRunning = false; 111 110 … … 127 126 continue; 128 127 } 129 128 130 if ( !lockSchema(query))129 if (isSchemaLocked()) 131 130 { 132 131 VERBOSE(VB_IMPORTANT, 133 132 "Waiting for Database Upgrade to complete."); … … 140 139 } 141 140 142 141 Compare(); 143 unlockSchema(query);144 142 145 143 if (m_expertMode) // Experts don't like to wait around :-) 146 144 break; … … 187 185 { 188 186 bool connections; // Are (other) FE/BEs connected? 189 187 bool gui; // Was gContext Init'ed gui=true? 188 bool locked; // Database schemalock 190 189 bool upgradable; // Can/should we upgrade? 191 190 bool validDBMS; // Do we measure up to minDBMS* ? 192 191 QString warnOldDBMS; 193 192 QString warnOtherCl; 193 QString warnSchLock; 194 194 195 195 196 196 … … 205 205 206 206 connections = CountClients() > 1; 207 207 gui = GetMythUI()->IsScreenSetup(); 208 locked = isSchemaLocked(); 208 209 validDBMS = (minDBMSmajor == 0) // If the caller provided no version, 209 210 ? true // the upgrade code can't be fussy! 210 211 : CompareDBMSVersion(minDBMSmajor, 211 212 minDBMSminor, minDBMSpoint) >= 0; 212 213 upgradable = validDBMS && (versionsBehind > 0) 214 && !locked 213 215 && (upgradeAllowed || m_expertMode); 214 216 215 217 … … 223 225 " You seem to be running MySQL version %5.") 224 226 .arg(name).arg(minDBMSmajor).arg(minDBMSminor) 225 227 .arg(minDBMSpoint).arg(GetDBMSVersion()); 228 if (locked) 229 warnSchLock = tr("Error: It appears that an earlier schema upgrade" 230 " has crashed. (TABLE schemlock is locked) " 231 " Please check all backend logs."); 226 232 227 233 228 229 234 // 230 235 // 1. Deal with the trivial cases (No user prompting required) 231 236 // … … 291 296 " but that may cause problems."); 292 297 } 293 298 } 299 else if (locked) 300 { 301 message = warnSchLock; 302 returnValue = MYTH_SCHEMA_ERROR; 303 } 294 304 else if (!validDBMS) 295 305 { 296 306 message = warnOldDBMS;