Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Mythtv mariadb issue: recordings disappear: mariadb change
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Multimedia
View previous topic :: View next topic  
Author Message
RayDude
Advocate
Advocate


Joined: 29 May 2004
Posts: 2050
Location: San Jose, CA

PostPosted: Fri Jun 04, 2021 4:21 am    Post subject: Mythtv mariadb issue: recordings disappear: mariadb change Reply with quote

I've run into a problem with the latest mythtv in portage. This fix works for mysql. I am testing with mariadb right now. I'll post tomorrow to let everyone know if it worked.

Here's the thread on mythtv.org where this is being discussed: https://forum.mythtv.org/viewtopic.php?f=36&t=4453&p=22039#p22039

Thanks to Bill6502 for giving me the patch.

Code:
diff -ur mythtva/libs/libmythbase/mythdbcon.cpp mythtvb/libs/libmythbase/mythdbcon.cpp
--- mythtva/libs/libmythbase/mythdbcon.cpp   2021-02-25 10:23:07.000000000 -0800
+++ mythtvb/libs/libmythbase/mythdbcon.cpp   2021-06-03 21:07:33.026311525 -0700
@@ -638,12 +638,7 @@
     bool result = QSqlQuery::exec();
     qint64 elapsed = timer.elapsed();
 
-    // if the query failed with "MySQL server has gone away"
-    // Close and reopen the database connection and retry the query if it
-    // connects again
-    if (!result
-        && QSqlQuery::lastError().nativeErrorCode() == "2006"
-        && Reconnect())
+    if (!result && lostConnectionCheck())
         result = QSqlQuery::exec();
 
     if (!result)
@@ -727,12 +722,7 @@
 
     bool result = QSqlQuery::exec(query);
 
-    // if the query failed with "MySQL server has gone away"
-    // Close and reopen the database connection and retry the query if it
-    // connects again
-    if (!result
-        && QSqlQuery::lastError().nativeErrorCode() == "2006"
-        && Reconnect())
+    if (!result && lostConnectionCheck())
         result = QSqlQuery::exec(query);
 
     LOG(VB_DATABASE, LOG_INFO,
@@ -830,12 +820,7 @@
 
     bool ok = QSqlQuery::prepare(query);
 
-    // if the prepare failed with "MySQL server has gone away"
-    // Close and reopen the database connection and retry the query if it
-    // connects again
-    if (!ok
-        && QSqlQuery::lastError().nativeErrorCode() == "2006"
-        && Reconnect())
+    if (!ok && lostConnectionCheck())
         ok = true;
 
     if (!ok && !(GetMythDB()->SuppressDBMessages()))
@@ -904,6 +889,26 @@
     return true;
 }
 
+bool MSqlQuery::lostConnectionCheck()
+{
+    // MySQL: Error number: 2006; Symbol: CR_SERVER_GONE_ERROR
+    // MySQL: Error number: 2013; Symbol: CR_SERVER_LOST
+    // MySQL: Error number: 4031; Symbol: ER_CLIENT_INTERACTION_TIMEOUT
+    // Note: In MariaDB, 4031 = ER_REFERENCED_TRG_DOES_NOT_EXIST
+
+    static QStringList kLostConnectionCodes = { "2006", "2013", "4031" };
+
+    QString error_code = QSqlQuery::lastError().nativeErrorCode();
+
+    // Make capturing of new 'lost connection' like error codes easy.
+    LOG(VB_GENERAL, LOG_DEBUG, QString("SQL Native Error Code: %1")
+        .arg(error_code));
+
+    // If the query failed with any of the error codes that say the server
+    // is gone, close and reopen the database connection.
+    return (kLostConnectionCodes.contains(error_code) && Reconnect());
+}
+
 void MSqlAddMoreBindings(MSqlBindings &output, MSqlBindings &addfrom)
 {
     MSqlBindings::Iterator it;
diff -ur mythtva/libs/libmythbase/mythdbcon.h mythtvb/libs/libmythbase/mythdbcon.h
--- mythtva/libs/libmythbase/mythdbcon.h   2021-02-25 10:23:07.000000000 -0800
+++ mythtvb/libs/libmythbase/mythdbcon.h   2021-06-03 21:06:32.102439399 -0700
@@ -194,6 +194,10 @@
     /// query.
     bool Reconnect(void);
 
+    /// lostConnectionCheck tests for SQL error codes that indicate the
+    /// connection to the server has been lost.
+    bool lostConnectionCheck(void);
+
     // Thunks that allow us to make QSqlQuery private
     QVariant value(int i) const { return QSqlQuery::value(i); }
     QString executedQuery(void) const { return QSqlQuery::executedQuery(); }



Place that file in/etc/portage/patches/media-tv/mythtv-31.0_p20210225/mythtv-31.0_p20210225_mysql.diff

Shutdown mythbackend, re-emerge mythtv, then restart mariadb (mysql) and start mythbackend.

Like I said above, it works for mysql, I'm checking mariadb now.

Update: After more than 24 hours the schedule is still working, so it looks like the patch works.
_________________
Some day there will only be free software.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Multimedia All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum