Browse Source

DatabaseNew crashes on mysql_reconnect

The wait_timeout was exceeded thus not allowing a reconnect.  Database pinging wasn't taking place in DatabaseNew that is now resolved.
Image 4 years ago
parent
commit
dd8747054d

+ 4 - 1
EQ2/source/WorldServer/WorldDatabase.cpp

@@ -97,7 +97,10 @@ bool WorldDatabase::ConnectNewDatabase() {
 	return database_new.Connect();
 }
 
-
+void WorldDatabase::PingNewDB()
+{
+	database_new.PingNewDB();
+}
 
 void WorldDatabase::DeleteBuyBack(int32 char_id, int32 item_id, int16 quantity, int32 price) {
 	LogWrite(MERCHANT__DEBUG, 0, "Merchant", "Deleting Buyback - Player: %u, Item ID: %u, Qty: %i, Price: %u", char_id, item_id, quantity, price);

+ 3 - 0
EQ2/source/WorldServer/WorldDatabase.h

@@ -123,6 +123,9 @@ public:
 	~WorldDatabase();
 
 	bool ConnectNewDatabase();
+
+	void PingNewDB();
+
 	string*	GetZoneName(int32 id);
 	string	GetZoneDescription(int32 id);
 	int32	LoadCharacterSkills(int32 char_id, Player* player);

+ 1 - 0
EQ2/source/WorldServer/net.cpp

@@ -464,6 +464,7 @@ int main(int argc, char** argv) {
 			if (InterserverTimer.Check()) {
 				InterserverTimer.Start();
 				database.ping();
+				database.PingNewDB();
 				database.PingAsyncDatabase();
 
 				if (net.LoginServerInfo && loginserver.Connected() == false && loginserver.CanReconnect()) {

+ 23 - 0
EQ2/source/common/DatabaseNew.cpp

@@ -392,3 +392,26 @@ bool DatabaseNew::IsIgnoredErrno(unsigned int db_errno) {
 
 	return false;
 }
+
+// Sends the MySQL server a keepalive
+void DatabaseNew::PingNewDB() {
+	MMysql.writelock(__FUNCTION__, __LINE__);
+	mysql_ping(&mysql);
+
+	int32* errnum = new int32;
+	*errnum = mysql_errno(&mysql);
+
+	switch (*errnum)
+	{
+		case CR_COMMANDS_OUT_OF_SYNC:
+		case CR_SERVER_GONE_ERROR:
+		case CR_UNKNOWN_ERROR:
+		{
+			LogWrite(DATABASE__ERROR, 0, "Database", "[Database] We lost connection to the database., errno: %i", errno);
+			break;
+		}
+	}
+
+	safe_delete(errnum);
+	MMysql.releasewritelock(__FUNCTION__, __LINE__);
+}

+ 1 - 0
EQ2/source/common/DatabaseNew.h

@@ -38,6 +38,7 @@ public:
 	void RemoveIgnoredErrno(unsigned int db_errno);
 	bool IsIgnoredErrno(unsigned int db_errno);
 
+	void PingNewDB();
 private:
 	MYSQL mysql;
 	Mutex MMysql;