Bug #37288 Maria - zerofill corrupts table
Submitted: 9 Jun 2008 16:31 Modified: 30 Jun 2008 10:02
Reporter: Guilhem Bichot Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Maria storage engine Severity:S3 (Non-critical)
Version:5.1-maria OS:Any
Assigned to: Guilhem Bichot CPU Architecture:Any

[9 Jun 2008 16:31] Guilhem Bichot
Description:
A table generated during ma_test_recovery.pl on Windows, but which seems ok to maria_chk -e, is corrupted after maria_chk -z:
[INS 18:27 ~/bug $] /m/bzrrepos/mysql-maria-after-cs/storage/maria/maria_chk -e test2
Checking MARIA file: test2
Data records:     376   Deleted blocks:       0
- check file-size
- check key delete-chain
- check index reference
- check data record references index: 1
- check data record references index: 2
- check data record references index: 3
- check data record references index: 4
- check data record references index: 5
- check data record references index: 6
- check records and index references
[INS 18:27 ~/bug $] /m/bzrrepos/mysql-maria-after-cs/storage/maria/maria_chk -z test2
- Zerofilling index for MARIA-table 'test2'
- Zerofilling data  for MARIA-table 'test2'
[INS 18:27 ~/bug $] /m/bzrrepos/mysql-maria-after-cs/storage/maria/maria_chk -e test2
Checking MARIA file: test2
Data records:     376   Deleted blocks:       0
- check file-size
- check key delete-chain
- check index reference
- check data record references index: 1
- check data record references index: 2
- check data record references index: 3
- check data record references index: 4
- check data record references index: 5
- check data record references index: 6
- check records and index references
maria_chk: error: Page        10:  Wrong data in bitmap.  Page_type: 1  empty_space: 3321  Bitmap-bits: 3
MARIA-table 'test2' is corrupted
Fix it using switch "-r" or "-o"

How to repeat:
ma_test_recovery.pl was failing under Windows, and I noticed that the cause was this table.
This table was created by running "ma_test2 -L -K -W -P -M -T -c -d500 -C" and then applying the log, all under Windows.
But taking the table created by log applying above under Windows, and zerofilling it under Linux, shows same corruption message.
[9 Jun 2008 19:03] Guilhem Bichot
tables for BUG#37288, just zerofill and check them

Attachment: bug37288.tar.bz2 (application/x-bzip2, text), 27.16 KiB.

[9 Jun 2008 20:43] Guilhem Bichot
storage/maria/ma_check.c
    When zerofilling the data file, _ma_compact_block_page() may increase free space in a page
    so bitmap page needs to be corrected
=== modified file 'storage/maria/ma_check.c'
--- a/storage/maria/ma_check.c  2008-05-29 18:39:25 +0000
+++ b/storage/maria/ma_check.c  2008-06-09 20:31:04 +0000
@@ -3240,11 +3240,16 @@ static my_bool maria_zerofill_data(HA_CH
         bzero(buff, LSN_SIZE);
       if (max_entry != 0)
       {
+        my_bool is_head_page= (page_type == HEAD_PAGE);
         dir= dir_entry_pos(buff, block_size, max_entry - 1);
         _ma_compact_block_page(buff, block_size, max_entry -1, 0,
-                               page_type == HEAD_PAGE ? ~(TrID) 0 : 0,
-                               page_type == HEAD_PAGE ?
+                               is_head_page ? ~(TrID) 0 : 0,
+                               is_head_page ?
                                share->base.min_block_length : 0);
+        /* compactation may have increased free space */
+        if (_ma_bitmap_set(info, page, is_head_page,
+                           uint2korr(buff + EMPTY_SPACE_OFFSET)))
+          goto err;

         /* Zerofille the not used part */
         offset= uint2korr(dir) + uint2korr(dir+2);
@@ -3266,10 +3271,9 @@ static my_bool maria_zerofill_data(HA_CH
                              PAGECACHE_UNPIN, LSN_IMPOSSIBLE,
                              LSN_IMPOSSIBLE, 1);
   }
-  if (flush_pagecache_blocks(share->pagecache, &info->dfile,
-                             FLUSH_FORCE_WRITE))
-    DBUG_RETURN(1);
-  DBUG_RETURN(0);
+  DBUG_RETURN(_ma_bitmap_flush(share) ||
+              flush_pagecache_blocks(share->pagecache, &info->dfile,
+                                     FLUSH_FORCE_WRITE));

 err:
   pagecache_unlock_by_link(share->pagecache, page_link.link,
[10 Jun 2008 20:27] Guilhem Bichot
Newer patch at http://lists.mysql.com/maria/63
[30 Jun 2008 10:02] Guilhem Bichot
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html
[30 Jun 2008 17:59] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:00] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:01] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:02] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:04] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:05] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:07] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:08] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:09] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:10] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:12] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:13] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:14] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:24] Bugs System
Pushed into 5.1.25-maria-alpha
[30 Jun 2008 18:36] Bugs System
Pushed into 5.1.25-maria-alpha