I have a TokuDB table that works fine for most queries, but segfaults on others. I did a CHECK TABLE which indicated that the table had errors. However, TokuDB doesn't support REPAIR TABLE. How can I fix a corrupted TokuDB table?

mysql> check table XXX;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    1
Current database: XXX

| Table                                          | Op    | Msg_type |     Msg_text |
| XXX.XXX | check | error    | Corrupt  |
1 row in set (14 hours 17 min 55.05 sec)

mysql> repair table XXX;
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    2
Current database: XXX

| Table                                          | Op     | Msg_type |     Msg_text                                                |
| XXX.XXX | repair | note     | The storage engine for the table doesn't support repair |
1 row in set (0.84 sec)

TokuDB does not support the repair table command, just like InnoDB, so you can't repair the table in question. If you don't have a backup or slave to pull from the best you can do is select the rows from the readable portion of the table itself. I'd recommend using "select * from table_name where table_pk < ? into ;" and "select * from table_name where table_pk > ? into ;". You'll need to experiment with the ? for each statement, because once you read the damaged part of the file the server will crash.


Since most queries work, your best shot is simply to mysqldump the table

mysqldump --no-data --skip-disable-keys --skip-lock-tables ${DB} ${TB} > ${DUMPSCHM} 
mysqldump --no-create-info --skip-disable-keys --skip-lock-tables ${DB} ${TB} > ${DUMPDATA}

Then, rename the table using

mysql> ALTER TABLE mydb.mytable RENAME mydb.myoldtable;

Then, reload the table using

mysql> source mydb_mytable_schema.sql
mysql> source mydb_mytable_data.sql

Give it a Try (Hope it works) !!!

CAVEAT : Hopefully, there is some TokuDB Doc you can look up at the Tokutek site.

According to one of the Docs, it says:

When using any transaction-safe database, it is essential that you understand the write-caching characteristics of your hardware. TokuDB provides transaction safe (ACID compliant) data storage for MySQL. However, if the underlying operating system or hardware does not actually write data to disk when it says it did, the system can corrupt your database when the machine crashes. For example, TokuDB can not guarantee proper recovery if it is mounted on an NFS volume. It is always safe to disable the write cache, but you may be giving up some performance

If you have this corrupt state due to a system crash or a false positive on a successful write to disk, you will have to consult Tokutek directly as Tokutek is a little out of my wheelhouse.

  • I tried to do a "CREATE TABLE YYY LIKE XXX" and then "INSERT INTO YYY (SELECT * FROM XXX)" and got a segfault on that. Would mysqldump act differently? – Thomas Johnson Feb 23 '14 at 1:10
  • mysqldump will do a full SELECT * FROM XXX with SQL_NO_CACHE. Try it and see... – RolandoMySQLDBA Feb 23 '14 at 1:14
  • @RolandoMySQLDBA some attempts at corrupt toku tables in my answer below. – Kshitij Banerjee May 9 '17 at 15:51

And if it's completely corrupt. Here's my post describing how I got my data back from raw files.

In gist, I was able to recover my files from the main toku files.

The toku-ft repository has an internal debugging tool called tokuftdump.

After it parses the tree, it dumps bytestreams on the leaf entries that are unpacked. Some quick hex editing on the converted hexstreams reveals the structure, and then you can modify the original utility to dump the exact values post parsing as revealed by the structure.

Since toku has message buffers on nodes, you also may need some additional message processing. In my case this was simple since I only had inserts...

Update: More details can be found here


(Disclaimer: This is reverse engineering the files. I would recommend doing a sanity check on the data after you've recovered it).

  • 1
    Please consider adding at least the main points of your blog post to the answer, otherwise it will be completely meaningless when the link goes stale. – mustaccio May 9 '17 at 17:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.