[MDEV-4501] table data is lost after disconnect from db following truncate and repopulate Created: 2013-05-09 Updated: 2013-05-09 Resolved: 2013-05-09 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 5.5.30 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major |
| Reporter: | John Lips | Assignee: | Elena Stepanova |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | None | ||
| Environment: |
gentoo 64-bit, python with MySQLdb module |
||
| Attachments: |
|
| Description |
|
If you truncate a table, then repopulate that table and disconnect from db, the data in this table is lost. I've attached a python script which demonstrates this behavior. The steps involved in the script: 1. drop existing test_mariadb table This same script run on a mysql server ultimately returns a populated set as expected. |
| Comments |
| Comment by Elena Stepanova [ 2013-05-09 ] |
|
Hi John, Your script creates a table without specifying the table engine explicitly. In 5.5 (both MariaDB and MySQL) the default storage engine is InnoDB, unless it's set otherwise. InnoDB is a transactional engine. Now, if you are saying it does not work like that with MySQL, it can be on one of two reasons. You can fix it by adding COMMIT before closing the connection. Please let us know if the explanation is sufficient. |
| Comment by John Lips [ 2013-05-09 ] |
|
Elena, Thank you for your quick response and thorough explaination. You were The good news is that I can now go ahead and convert my server over to Thanks, On Wed, May 8, 2013 at 4:45 PM, Elena Stepanova (JIRA) < |
| Comment by Elena Stepanova [ 2013-05-09 ] |
|
Please be aware that there was another important change in behavior happened in MySQL 5.5 (and consequently in MariaDB 5.5) which might make your current setup work not quite as you expected. I think python scripts are particularly affected due to this automatic 'autocommit = 0' setting on connection. The problem is discussed with original developers here: http://lists.mysql.com/internals/38580, or if you are interested in more details, you could search for "MySQL MDL". In the essence, if you are using non-transactional tables (and hence naturally don't care to do COMMIT in your scripts), you might get in trouble with nearly-ever-lasting table locks. As a quick workaround, I would recommend setting lock_wait_timeout to a fairly low value, probably a few seconds, instead of 1 year which is the default. But it won't solve the problem, it will just avoid getting deadlocks. Then you will probably want to consider the whole thing more carefully – possibly there are settings for python that override the 'autocommit = 0' behavior; or, you might need to set it back to 1 at the beginning of your scripts; or, you might want to edit your existing scripts to add COMMIT when it's due (of course it only makes sense if you want to switch to the transactional engine). In any case, it's up to you. |