Opened 16 years ago

Closed 16 years ago

#5482 closed patch (fixed)

PATCH: Purge unused database-connections after 3600 secs [SVN: Trunk]

Reported by: tomimo@… Owned by: danielk
Priority: minor Milestone: 0.22
Component: mythtv Version: head
Severity: medium Keywords:
Cc: Ticket locked: no

Description

Mysql has this variable max_connect_errors which is used to protect the db from possible attackers. If connect errors increase over time to the max_connect_errors the Mysql db will block the host from connecting for ever.

The attached patch purges unsused db-connections after they have been idle more than 1 hour in the hope that mysql will not count those connections into max_connect_errors counter if they would be allowed be terminated by MySQL instead.

Mythtv will create additional threads in case there are more incoming processing requests than available threads. The created threads will go into pool later on. However, there might be days and days until the next busy period where the same amount of db-connections are really required.

The attached patch also rotates the db-connections in the pool instead of always preferring on using the same threads.

Attachments (3)

purge_connections.patch (1.8 KB) - added by tomimo@… 16 years ago.
Purge un-used db-connections after 3600s of idle time
remove_db.patch (484 bytes) - added by tomimo@… 16 years ago.
Always call the QSqlDatabase::removeDatabase() as we call addDatabase() in constructor and not in openDatabase() or such.
purge_connections-v2.patch (2.0 KB) - added by tomimo@… 16 years ago.
Fixed version: Purge un-used db-connections after 3600s of idle time

Download all attachments as: .zip

Change History (6)

Changed 16 years ago by tomimo@…

Attachment: purge_connections.patch added

Purge un-used db-connections after 3600s of idle time

comment:1 Changed 16 years ago by tomimo@…

In addition to the previous patch, the following change should be applied:

diff -u -b -w mythdbcon.cpp mythdbcon.cpp.mod --- mythdbcon.cpp 2008-06-28 11:15:53.000000000 +0300 +++ mythdbcon.cpp.mod 2008-06-28 11:15:43.000000000 +0300 @@ -33,8 +33,8 @@

m_db = QSqlDatabase(); forces a destroy and must be done before

removeDatabase() so that connections and queries are cleaned up correctly

  • QSqlDatabase::removeDatabase(m_name);

}

+ QSqlDatabase::removeDatabase(m_name);

}

bool MSqlDatabase::isOpen()


As the QSqlDatabase::addDatabase() call is done in constructor regardles if the db-connection is openede or not, also the call to QSqlDatabase::removeDatabase should be done always when destroying the object. Currently, if the db-connection is for some reason never openeded, we possibly leak resources (or QSqlDatabase leaks resources).

Changed 16 years ago by tomimo@…

Attachment: remove_db.patch added

Always call the QSqlDatabase::removeDatabase() as we call addDatabase() in constructor and not in openDatabase() or such.

comment:2 Changed 16 years ago by danielk

Milestone: unknown0.22
Owner: changed from Isaac Richards to danielk
Status: newassigned

Changed 16 years ago by tomimo@…

Attachment: purge_connections-v2.patch added

Fixed version: Purge un-used db-connections after 3600s of idle time

comment:3 Changed 16 years ago by danielk

Resolution: fixed
Status: assignedclosed

(In [17834]) Fixes #5482. Avoids having DB connections go stale using with two simple modificatinos to mythdbcon.

1st we rotate our DB connections. 2nd we expire connections that have gone unused for 1-2 hours.

Patch from tomino, modified slightly by me.

Unfortunately the binary revision must be updated, so plugins must be recompiled.

Note: See TracTickets for help on using tickets.