https://wiki.zimbra.com/wiki/Zmdbintegrityreport

https://wiki.zimbra.com/wiki/Mysql_Crash_Recovery

This forum post saved by bacon…

Index mail_item is corrupted: https://www.zimbrafr.org/forum/topic/7340-index-mail-item-is-corrupted/

Bonjour,

Suite à une défaillance disque, ma VM de Zimbra a crash.
Après redémarrage, tout se relance correctement sauf une boite mail qui semble être corrompue.

Lorsqu'on tente de se logger, l'écran reste figé et mailbox.log contient:
com.zimbra.common.service.ServiceException: system failure: fetching folder data for mailbox 40
ExceptionId:LmtpServer-102:1447763313195:358d3fef8cfc371b
Code:service.FAILURE
at com.zimbra.common.service.ServiceException.FAILURE(ServiceException.java:260)
at com.zimbra.cs.db.DbMailItem.getFoldersAndTags(DbMailItem.java:2230)
at com.zimbra.cs.mailbox.Mailbox.loadFoldersAndTags(Mailbox.java:2201)
at com.zimbra.cs.mailbox.Mailbox.beginTransaction(Mailbox.java:1771)
at com.zimbra.cs.mailbox.Mailbox.beginReadTransaction(Mailbox.java:1686)
at com.zimbra.cs.mailbox.Mailbox.getItemById(Mailbox.java:2773)
at com.zimbra.cs.mailbox.Mailbox.getItemById(Mailbox.java:2765)
at com.zimbra.cs.mailbox.Mailbox.getFolderById(Mailbox.java:3903)
at com.zimbra.cs.filter.IncomingMessageHandler.getDefaultFolderPath(IncomingMessageHandler.java:87)
at com.zimbra.cs.filter.RuleManager.applyRulesToIncomingMessage(RuleManager.java:345)
at com.zimbra.cs.filter.RuleManager.applyRulesToIncomingMessage(RuleManager.java:302)
at com.zimbra.cs.lmtpserver.ZimbraLmtpBackend.deliverMessageToLocalMailboxes(ZimbraLmtpBackend.java:614)
at com.zimbra.cs.lmtpserver.ZimbraLmtpBackend.deliver(ZimbraLmtpBackend.java:384)
at com.zimbra.cs.lmtpserver.LmtpHandler.processMessageData(LmtpHandler.java:444)
at com.zimbra.cs.lmtpserver.TcpLmtpHandler.continueDATA(TcpLmtpHandler.java:79)
at com.zimbra.cs.lmtpserver.LmtpHandler.doDATA(LmtpHandler.java:433)
at com.zimbra.cs.lmtpserver.LmtpHandler.processCommand(LmtpHandler.java:216)
at com.zimbra.cs.lmtpserver.TcpLmtpHandler.processCommand(TcpLmtpHandler.java:72)
at com.zimbra.cs.server.ProtocolHandler.processConnection(ProtocolHandler.java:190)
at com.zimbra.cs.server.ProtocolHandler.run(ProtocolHandler.java:129)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.sql.SQLException: Index mail_item is corrupted
Query being executed when exception was thrown:
SELECT mi.id, mi.type, mi.parent_id, mi.folder_id, mi.prev_folders, mi.index_id,mi.imap_id, mi.date, mi.size, mi.locator, mi.blob_digest, mi.unread, mi.flags, mi.tag_names, mi.subject,mi.name, mi.metadata, mi.mod_metadata, mi.change_date, mi.mod_content, mi.uuid FROM mboxgroup40.mail_item AS mi WHERE mailbox_id = 40 AND type IN (1,2,13)

at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1086)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4237)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4169)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:928)
at com.mysql.jdbc.MysqlIO.nextRow(MysqlIO.java:2053)
at com.mysql.jdbc.MysqlIO.readSingleRowSet(MysqlIO.java:3543)
at com.mysql.jdbc.MysqlIO.getResultSet(MysqlIO.java:491)
at com.mysql.jdbc.MysqlIO.readResultsForQueryOrUpdate(MysqlIO.java:3245)
at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:2413)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2836)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2834)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2156)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2313)
at com.zimbra.cs.db.DebugPreparedStatement.executeQuery(DebugPreparedStatement.java:165)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96)
at com.zimbra.cs.db.StatTrackingPreparedStatement.executeQuery(StatTrackingPreparedStatement.java:352)
at com.zimbra.cs.db.DbMailItem.getFoldersAndTags(DbMailItem.java:2108)
... 21 more

zmblobchk start -v 
crash sur la maibox 40 (com.zimbra.common.soap.SoapFaultException: system failure: getting items with blobs for mailbox 40)

mysql_error.log contient:
151117 14:40:06 [ERROR] Got error 180 when reading table './mboxgroup40/mail_item'
Bonjour et merci pour vos réponses.

Citation

Tu as essayé de la restaurer?
Je fais des backups de la VM, pas compte par compte. Politique à réviser très certainement

Citation

un petit zmdbintegrety éventuellement.
J'avais des erreurs partout (liée à la mbox 40). Il n'y a plus qu'une erreur (cf. ci-dessous)

--

Au final, j'ai appliqué à la lettre la procédure https://wiki.zimbra...._Crash_Recovery qui a parfaitement fonctionée.
Tout marche désormais (zmblobchk ne retourne pas d'erreur, le réindexage des mailbox fonctionne...)

zmdbintegrityreport remonte tout de même un problème (qui n'existait pas avant l'application de la procédure de recovery du mysql) :
Database errors found.
/opt/zimbra/mysql/bin/mysqlcheck --defaults-file=/opt/zimbra/conf/my.cnf -S /opt/zimbra/db/mysql.sock -A -C -s -u root --password=XXXXXXXX
mysql.gtid_slave_pos
Error : Table 'mysql.gtid_slave_pos' doesn't exist in engine
mysql.innodb_index_stats
Error : Table 'mysql.innodb_index_stats' doesn't exist in engine
mysql.innodb_table_stats
Error : Table 'mysql.innodb_table_stats' doesn't exist in engine

C'est exactement le même problème qu'ici : http://www.programer...TN0MzMwATM.html
Avant d'effectuer l'étape 5 de cette procédure, je voudrais savoir si quelqu'un a déjà rencontré ce problème dans un contexte zimbra (et ce qu'il est préconisé de faire).
OK j'ai appliqué ceci : http://www.programer...TN0MzMwATM.html
Tout remarche et aucun erreur dans les logs.
Voilà le détail de ce que j'ai fait, si ça peut servir à quelqu'un d'autre:

1/ L'ERREUR
su - zimbra
/opt/zimbra/libexec/zmdbintegrityreport -v

Ce qui retourne:
Database errors found.
/opt/zimbra/mysql/bin/mysqlcheck --defaults-file=/opt/zimbra/conf/my.cnf -S /opt/zimbra/db/mysql.sock -A -C -s -u root --password=XXXXXXXX
mysql.gtid_slave_pos
Error : Table 'mysql.gtid_slave_pos' doesn't exist in engine
mysql.innodb_index_stats
Error : Table 'mysql.innodb_index_stats' doesn't exist in engine
mysql.innodb_table_stats
Error : Table 'mysql.innodb_table_stats' doesn't exist in engine

Pourtant les tables existent....
mysql mysql -e "show tables"
+---------------------------+
| Tables_in_mysql                |
+---------------------------+
| column_stats                   |
| columns_priv                   |
| db                                     |
| event                                  |
| func                                   |
| general_log                    |
| gtid_slave_pos                 |
| help_category                  |
| help_keyword                   |
| help_relation                  |
| help_topic                     |
| host                                   |
| index_stats                    |
| innodb_index_stats     |
| innodb_table_stats     |
| plugin                                 |
| proc                                   |
| procs_priv                     |
| proxies_priv                   |
| roles_mapping                  |
| servers                                |
| slow_log                               |
| table_stats                    |
| tables_priv                    |
| time_zone                              |
| time_zone_leap_second  |
| time_zone_name                 |
| time_zone_transition   |
| time_zone_transition_type |
| user                                   |
+---------------------------+

Mais on ne peut pas y accéder...
zimbra@mail:~$ mysql mysql -e "select * from innodb_index_stats"
ERROR 1932 (42S02) at line 1: Table 'mysql.innodb_index_stats' doesn't exist in engine

2/ FIX

Couper zimbra
zmcontrol stop

Supprimer les tables concernées (FAITES UN BACKUP AVANT)
cd /opt/zimbra/db/data/mysql/
rm -f innodb_* gtid_slave_pos.*

Démarrer le serveur mysql
mysql.server start

Extraire du fichier de configuration des tables système de mysql les commande permettant de recréer les tables précédement supprimées.
Pour localiser le fichier :
find /opt/zimbra/ -name mysql_system_tables.sql

Ce qui retourne chez moi :
/opt/zimbra/mta/mariadb-10.0.15/share/mysql_system_tables.sql
/opt/zimbra/mariadb-10.0.15/share/mysql_system_tables.sql

Lancer les commandes pour recréer les 3 tables :
mysql mysql -e "CREATE TABLE innodb_index_stats (
         database_name                           VARCHAR(64) NOT NULL,
         table_name                                      VARCHAR(64) NOT NULL,
         index_name                                      VARCHAR(64) NOT NULL,
         last_update                                     TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
         /* there are at least:
         stat_name='size'
         stat_name='n_leaf_pages'
         stat_name='n_diff_pfx%' */
         stat_name                                       VARCHAR(64) NOT NULL,
         stat_value                                      BIGINT UNSIGNED NOT NULL,
         sample_size                                     BIGINT UNSIGNED,
         stat_description                        VARCHAR(1024) NOT NULL,
         PRIMARY KEY (database_name, table_name, index_name, stat_name)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0"

mysql mysql -e "CREATE TABLE IF NOT EXISTS innodb_table_stats (
         database_name                           VARCHAR(64) NOT NULL,
         table_name                                      VARCHAR(64) NOT NULL,
         last_update                                     TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
         n_rows                                          BIGINT UNSIGNED NOT NULL,
         clustered_index_size            BIGINT UNSIGNED NOT NULL,
         sum_of_other_index_sizes        BIGINT UNSIGNED NOT NULL,
         PRIMARY KEY (database_name, table_name)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0"

mysql mysql -e "CREATE TABLE IF NOT EXISTS gtid_slave_pos (
domain_id INT UNSIGNED NOT NULL,
sub_id BIGINT UNSIGNED NOT NULL,
server_id INT UNSIGNED NOT NULL,
seq_no BIGINT UNSIGNED NOT NULL,
PRIMARY KEY (domain_id, sub_id))
COMMENT='Replication slave GTID position'"

Couper le serveur mysql
mysql.server stop

relancer zimbra
zmcontrol start

3/ CHECKS
zmdbintegrityreport ne doit plus retourner d'erreur :
/opt/zimbra/libexec/zmdbintegrityreport -v

J'ai également relancé le zmblobchk qui ne retourne aucune erreur non plus.
zmblobchk start -v

Au passage j'ai réindexé les mailboxes
zmprov -v rim <user@domain.tld> start