twitter-forks / mysql

MySQL fork maintained and used at Twitter
https://github.com/twitter/mysql/wiki
GNU General Public License v2.0
1.73k stars 442 forks source link

Salvaging an ARCHIVE table with archive_reader #12

Open alpha0010 opened 2 years ago

alpha0010 commented 2 years ago

While trying to recover a corrupted ARCHIVE table, my searching lead me here. Posting my findings in case it also helps someone in the future. (Note that archive_reader is not specific to this fork - this fork is just where I was lead.)

Patched code with:

diff --git a/storage/archive/CMakeLists.txt b/storage/archive/CMakeLists.txt
index 78fb95c0d2..799ad44a6f 100644
--- a/storage/archive/CMakeLists.txt
+++ b/storage/archive/CMakeLists.txt
@@ -16,3 +16,5 @@
 SET(ARCHIVE_SOURCES  azio.c ha_archive.cc ha_archive.h)
 MYSQL_ADD_PLUGIN(archive ${ARCHIVE_SOURCES} STORAGE_ENGINE LINK_LIBRARIES ${ZLIB_LIBRARY})

+MYSQL_ADD_EXECUTABLE(archive_reader archive_reader.c azio.c)
+TARGET_LINK_LIBRARIES(archive_reader mysys)
diff --git a/storage/archive/archive_reader.c b/storage/archive/archive_reader.c
index 2475418fef..7a3fd792c7 100644
--- a/storage/archive/archive_reader.c
+++ b/storage/archive/archive_reader.c
@@ -39,6 +39,8 @@ static char **default_argv;
 int opt_check, opt_force, opt_quiet, opt_backup= 0, opt_extract_frm;
 int opt_autoincrement;

+PSI_file_key arch_key_file_metadata, arch_key_file_data, arch_key_file_frm;
+
 int main(int argc, char *argv[])
 {
   unsigned int ret;

We found ARCHIVE engine to be 6x smaller than compressed InnoDB (and 10x smaller than uncompressed), so still has value. If you too must stay with ARCHIVE, I recommend FLUSHing the table after completing any major write.