溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

MYSQL出現(xiàn)Space id in fsp header,but in the page header錯(cuò)誤怎么辦

發(fā)布時(shí)間:2021-11-06 17:26:15 來(lái)源:億速云 閱讀:315 作者:小新 欄目:MySQL數(shù)據(jù)庫(kù)

這篇文章將為大家詳細(xì)講解有關(guān)MYSQL出現(xiàn)Space id in fsp header,but in the page header錯(cuò)誤怎么辦,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

啟動(dòng)MYSQL的時(shí)候發(fā)現(xiàn)如下問(wèn)題:
2015-12-14 20:51:59 2098 [ERROR] InnoDB: Space id in fsp header 131225,but in the page header 65
2015-12-14 20:51:59 2098 [ERROR] InnoDB: inconsistent data in space header in tablespace ./test/oneblock.ibd (table test/oneblock)

innodb的存儲(chǔ)包含

tablespace--segment--extent--block(pages)

而tablespace有一個(gè)space id 及用于描述表空間的唯一編號(hào),ibdata的space id為0,這個(gè)ibdata為,
SYSTEM SPACE,其中會(huì)包含很多普通SPACE_ID 不包含的數(shù)據(jù)段,或者說(shuō)數(shù)據(jù)塊,如回滾段。
如果開(kāi)啟了innodb_file_per_table,每個(gè)innodb 表文件都有space id,其中文件包含了表的數(shù)據(jù)和索引數(shù)據(jù)。
而普通的space 包含的信息較少一些

我們這里主要分析這里也只要分析普通的space,也就是innodb_file_per_table建立的ibd文件。
使用工具(自己寫的工具):
[root@hadoop1 test]# mysqlblock c1.ibd -t
***************************************************
USEAGE: mysqlblock datafile -t/-d                  
This small tool used in study and test database,not
uesd on online database!                           
This tool is used to find how many blocks and types
in specified datafile,Exp:how many undo block in d
ata file!                                          
QQ:22389860                                        
***************************************************
-t Only Total blocks types in ibdata!              
-d Blocks types detail  in ibdata!                 
***************************************************
FILE SIZE IS : 10485760
Total Block Status    :
Total  block                   :   640,Total size is: 10.000000 MB
Total undo block               :     0,Total size is: 0.000000 MB
Total index node block         :     1,Total size is: 0.015625 MB
Total insert buffer free blocks:     0,Total size is: 0.000000 MB
Total data(leaf node) block    :   113,Total size is: 1.765625 MB
Total new allocate blocks      :   524,Total size is: 8.187500 MB
Total insert buf bitmap blocks :     1,Total size is: 0.015625 MB
Total system blocks            :     0,Total size is: 0.000000 MB
Total transaction system blocks:     0,Total size is: 0.000000 MB
Total file space header blocks :     1,Total size is: 0.015625 MB
Total extrenl disc blocks      :     0,Total size is: 0.000000 MB
Total LOB blocks               :     0,Total size is: 0.000000 MB
Total Unkown blocks            :     0,Total size is: 0.000000 MB

這里我們可以清晰的看到每種塊的數(shù)量,其中注意一個(gè)特殊的塊
Total file space header blocks及FSP_HDR BLOCK,這個(gè)塊是每個(gè)space 必須的,
即使SYSTEM SPACE也包含,他總是SPACE的第一個(gè)塊。
而每個(gè)塊同樣包含了file header.
Space id in fsp header 131225,but in the page header 65
這里的fsp header就是 file space header ,及第一個(gè)塊的后38到150字節(jié),
而 page header這里實(shí)際上是file header 及 FIL header,這個(gè)是塊固有的前38字節(jié)。
這里有點(diǎn)繞:
一個(gè)是file header(每個(gè)塊固有的前38字節(jié))
一個(gè)是file space header(space的第一個(gè)塊的38-150字節(jié))

 file  header(FIL header)
 包含如下0-37字節(jié)
 
 checksum(4) 0-3
 offset(4)   4-7
 previous page(4) 8-11
 next page(4)     12-15
 LSN for last page modification(8) 16-23
 page type (2)      24-25
 FLUSH LSN(8)       26-33
 SPACE ID(4)        34-37
 其中的每個(gè)值的意思有些是自解釋的,而有些需要更深入的研究,但是一個(gè)塊是一個(gè)雙向指針的節(jié)點(diǎn)可以肯定。
 并且記錄每個(gè)塊的LSN記錄,應(yīng)該用于塊恢復(fù)。這部分是每個(gè)塊都一樣的。而這里SPCAE ID在
 page header 中說(shuō)明每個(gè)塊中都會(huì)有個(gè)這個(gè)值。記錄的就是SPACE_ID不用過(guò)多解釋
 接下來(lái)我們來(lái)看file space header block 特有的
 38-150字節(jié):file space header(FSP HEADER)
 SPACE_ID (4)
 unused(4)
 highest page number in file(size)(4)
 highest page number initialized (free limit)(4)
 flags(4)
 number of pages uesd in "free_frag" list(4)
 list base node for "free" list(16)
 list base node for "free_frag" list(16)
 list base node for "full_frag" list(16)
   nex unused segment id(8)
 list base node for "full_nodes" list(16)
 list base node for "free_nodes" list(16)
 其中很多值還需要深入的研究 但是我們發(fā)現(xiàn)在38-41字節(jié)就包含了SPACE_ID。
那么我們就找到了
Space id in fsp header 131225,but in the page header 65
中的 fsp header 來(lái)自哪里 ,他來(lái)自FSP HEADER及ibd 文件的第一個(gè)塊的第38-41字節(jié)
而page header 65,來(lái)自每個(gè)塊的第34-37字節(jié)。

既然如此我們可以進(jìn)行測(cè)試模擬這種現(xiàn)象,我們手動(dòng)修改這4個(gè)字節(jié)。使用我自己寫的工具,由于LINUX下沒(méi)找到合適工具干脆自己寫了兩個(gè)。
bctool和bcview
bctool 用于修改
bcview 用于查看
主要測(cè)試方式
1、修改FSP HEADER的38-41字節(jié)查看MYSQL INNODB 報(bào)錯(cuò),然后修改回去后是否能夠順利啟動(dòng)
2、修改第一個(gè)塊file space header的34-37字節(jié) 查看看MYSQL INNODB 報(bào)錯(cuò),然后修改回去后是否能夠順利啟動(dòng)
3、修改任意一個(gè)塊的file space header的34-37字節(jié) 查看看MYSQL INNODB 報(bào)錯(cuò),然后修改回去后是否能夠順利啟動(dòng)

我們依然使用test數(shù)據(jù)庫(kù)下的c1 表其innodb 數(shù)據(jù)文件為c1.ibd

一、修改FSP HEADER的38-41字節(jié)查看MYSQL INNODB 報(bào)錯(cuò),然后修改回去后是否能夠順利啟動(dòng)
    
    通過(guò)bcview查看塊的34-37字節(jié)
    [root@hadoop1 test]# bcview c1.ibd 16 34 4|more
******************************************************************
This Tool Is Uesed For Find The Data In Binary format(Hexadecimal)
Usage:./bcview file blocksize offset cnt-bytes!                   
file: Is Your File Will To Find Data!                             
blocksize: Is N kb Block.Eg: 8 Is 8 Kb Blocksize(Oracle)!         
                         Eg: 16 Is 16 Kb Blocksize(Innodb)!       
offset:Is Every Block Offset Your Want Start!                                     
cnt-bytes:Is After Offset,How Bytes Your Want Gets!                               
Edtor QQ:22389860!                                                
Used gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)                
******************************************************************
----Current file size is :10.000000 Mb
----Current use set blockszie is 16 Kb
current block:00000000--Offset:00034--cnt bytes:04--data is:00000048
current block:00000001--Offset:00034--cnt bytes:04--data is:00000048
current block:00000002--Offset:00034--cnt bytes:04--data is:00000048
current block:00000003--Offset:00034--cnt bytes:04--data is:00000048
current block:00000004--Offset:00034--cnt bytes:04--data is:00000048
current block:00000005--Offset:00034--cnt bytes:04--data is:00000048
current block:00000006--Offset:00034--cnt bytes:04--data is:00000048
current block:00000007--Offset:00034--cnt bytes:04--data is:00000048
current block:00000008--Offset:00034--cnt bytes:04--data is:00000048
current block:00000009--Offset:00034--cnt bytes:04--data is:00000048
current block:00000010--Offset:00034--cnt bytes:04--data is:00000048
.......
當(dāng)然后面還有很多塊,但是這里bcview c1.ibd 16 34 4 就是16KB大小34字節(jié)開(kāi)始,一共4個(gè)字節(jié)輸出。
我們發(fā)現(xiàn)全是00000048,因?yàn)槊總€(gè)space_id在page header 都會(huì)記錄,
那么他的space id 就是0X48 10進(jìn)制就是72,我們?cè)贛YSQL中驗(yàn)證一下:
mysql> select * from INNODB_SYS_TABLESPACES  where space=72;
+-------+---------+------+-------------+----------------------+-----------+---------------+
| SPACE | NAME    | FLAG | FILE_FORMAT | ROW_FORMAT           | PAGE_SIZE | ZIP_PAGE_SIZE |
+-------+---------+------+-------------+----------------------+-----------+---------------+
|    72 | test/c1 |    0 | Antelope    | Compact or Redundant |     16384 |             0 |
+-------+---------+------+-------------+----------------------+-----------+---------------+
1 row in set (0.01 sec)

可以看到?jīng)]有問(wèn)題。
那么接下我們來(lái)看38到41字節(jié),為了更好的說(shuō)明我使用 mysqlblock c1.ibd -d|more的d選項(xiàng)查看詳細(xì)塊信息
并且使用bcview c1.ibd 16 38 4|more

current block:00000000--Offset:00038--cnt bytes:04--data is:00000048           
current block:00000001--Offset:00038--cnt bytes:04--data is:00000000
current block:00000002--Offset:00038--cnt bytes:04--data is:ffffffff
current block:00000003--Offset:00038--cnt bytes:04--data is:000601c8
current block:00000004--Offset:00038--cnt bytes:04--data is:00343b26
current block:00000005--Offset:00038--cnt bytes:04--data is:00663b26
current block:00000006--Offset:00038--cnt bytes:04--data is:00663b26
current block:00000007--Offset:00038--cnt bytes:04--data is:00663b26
current block:00000008--Offset:00038--cnt bytes:04--data is:00663b26
current block:00000009--Offset:00038--cnt bytes:04--data is:00663b26
current block:00000010--Offset:00038--cnt bytes:04--data is:00663b26
current block:00000011--Offset:00038--cnt bytes:04--data is:00663b26
current block:00000012--Offset:00038--cnt bytes:04--data is:00663b26
current block:00000013--Offset:00038--cnt bytes:04--data is:00663b26


current read blocks is : 0 --This Block is file space header blocks!    
current read blocks is : 1 --This Block is insert buffer bitmap  blocks!
current read blocks is : 2 --This Block is index node blocks!           
current read blocks is : 3 --This Block is data blocks(Tree leaf node)!
current read blocks is : 4 --This Block is data blocks(Tree leaf node)!
current read blocks is : 5 --This Block is data blocks(Tree leaf node)!
current read blocks is : 6 --This Block is data blocks(Tree leaf node)!
current read blocks is : 7 --This Block is data blocks(Tree leaf node)!
current read blocks is : 8 --This Block is data blocks(Tree leaf node)!
current read blocks is : 9 --This Block is data blocks(Tree leaf node)!
current read blocks is : 10 --This Block is data blocks(Tree leaf node)!
current read blocks is : 11 --This Block is data blocks(Tree leaf node)!
current read blocks is : 12 --This Block is data blocks(Tree leaf node)!
current read blocks is : 13 --This Block is data blocks(Tree leaf node)!
current read blocks is : 14 --This Block is data blocks(Tree leaf node)!

現(xiàn)在我們清楚的看到了38-41這4個(gè)字節(jié)只有fsp_header塊是00000048就是space_id
其他類型的塊并不是。

接下來(lái)我們使用bctool進(jìn)行修改FSP HEADER的38-41字節(jié)。還是關(guān)閉數(shù)據(jù)庫(kù)后進(jìn)行更改
為了安全首先備份一下
[root@hadoop1 test]# cp c1.ibd c1.ibdbak
然后:
[root@hadoop1 test]# bctool c1.ibd 0 38 000000ee                                
******************************************************************
This tool is uesed to check data ues binary format,no Big-Endian  
or Little-Endian diff,this tool is base one byte on byte to change
!block is 16k.if want change other block eg:8k! please set blocks
0 and offset blocks*8192+offset!                                  
usage:./bctool yfile blocks offset yourdata(XX)!                  
Warings:backup file frist!!!!!!!!!                                
Editor QQ:22389860                                                
Ues gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)                 
******************************************************************
0-0-0-ee            
再次查看:
bcview c1.ibd 16 38 4|more           
current block:00000000--Offset:00038--cnt bytes:04--data is:000000ee                                    
current block:00000001--Offset:00038--cnt bytes:04--data is:00000000
current block:00000002--Offset:00038--cnt bytes:04--data is:ffffffff
current block:00000003--Offset:00038--cnt bytes:04--data is:000601c8
已經(jīng)被我更改為ee了
然后啟動(dòng)MYSQL,雖然數(shù)據(jù)庫(kù)起來(lái)了但是

mysql> select count(*) from c1;
ERROR 2013 (HY000): Lost connection to MySQL server during query
數(shù)據(jù)庫(kù)立即宕機(jī)
[root@hadoop1 test]# service mysqldefault start
Starting MySQL..The server quit without updating PID file (/mysql/data/hadoop1.pid).[FAILED]
再次啟動(dòng)已經(jīng)無(wú)用,查看日志:
2015-12-26 01:05:38 5074 [ERROR] InnoDB: Space id in fsp header 238,but in the page header 72
2015-12-26 01:05:38 5074 [ERROR] InnoDB: checksum mismatch in tablespace ./test/c1.ibd (table test/c1)
2015-12-26 01:05:38 5074 [Note] InnoDB: Page size:1024 Pages to analyze:64
2015-12-26 01:05:38 5074 [Note] InnoDB: Page size: 1024, Possible space_id count:0
2015-12-26 01:05:38 5074 [Note] InnoDB: Page size:2048 Pages to analyze:64
2015-12-26 01:05:38 5074 [Note] InnoDB: Page size: 2048, Possible space_id count:0
2015-12-26 01:05:38 5074 [Note] InnoDB: Page size:4096 Pages to analyze:64
2015-12-26 01:05:38 5074 [Note] InnoDB: Page size: 4096, Possible space_id count:0
2015-12-26 01:05:38 5074 [Note] InnoDB: Page size:8192 Pages to analyze:64
2015-12-26 01:05:38 5074 [Note] InnoDB: Page size: 8192, Possible space_id count:0
2015-12-26 01:05:38 5074 [Note] InnoDB: Page size:16384 Pages to analyze:64
.....

我們發(fā)現(xiàn)錯(cuò)誤重現(xiàn)238 換算為16進(jìn)制就是我們修改的0XEE.
這種情況也許innodb_force_recovery > 0 有用,但是我沒(méi)有試驗(yàn)。
接著我來(lái)將fsp header 的38-41字節(jié)改回0X48,然后啟動(dòng)。
[root@hadoop1 test]# bctool c1.ibd 0 38 00000048
再次查看
[root@hadoop1 test]# bcview c1.ibd 16 38 4|more
current block:00000000--Offset:00038--cnt bytes:04--data is:00000048
啟動(dòng):
[root@hadoop1 test]# service mysqldefault start
Starting MySQL...[  OK  ]
啟動(dòng)完成。
mysql> select count(*) from c1;
+----------+
| count(*) |
+----------+
|     8192 |
+----------+
1 row in set (0.01 sec)
查詢沒(méi)有問(wèn)題。


二、修改第一個(gè)塊file space header的34-37字節(jié) 查看看MYSQL INNODB 報(bào)錯(cuò),然后修改回去后是否能夠順利啟動(dòng)
    
    再次關(guān)閉數(shù)據(jù),
    使用bcview查看
    [root@hadoop1 test]# bcview c1.ibd 16 34 4|more
    current block:00000000--Offset:00034--cnt bytes:04--data is:00000048
    修改:
    [root@hadoop1 test]# bctool c1.ibd 0 34 00000099
    查看
    [root@hadoop1 test]# bcview c1.ibd 16 34 4|more
    current block:00000000--Offset:00034--cnt bytes:04--data is:00000099
    啟動(dòng)數(shù)據(jù)庫(kù),查看數(shù)據(jù)
    mysql> select count(*) from c1;
    ERROR 2013 (HY000): Lost connection to MySQL server during query
    查看日志:
    2015-12-26 01:17:46 6122 [ERROR] InnoDB: Space id in fsp header 72,but in the page header 153
    這里的153就是0X99對(duì)比剛才的
    2015-12-26 01:05:38 5074 [ERROR] InnoDB: Space id in fsp header 238,but in the page header 72
    可以從日志中看出這次是fsp header正常,file header 錯(cuò)誤。
    那么我們同樣修改回來(lái):
    [root@hadoop1 test]# bctool c1.ibd 0 34 00000048
    查看
    current block:00000000--Offset:00034--cnt bytes:04--data is:00000048
    已經(jīng)修改回來(lái),接著啟動(dòng)
    mysql> select count(*) from c1;
+----------+
| count(*) |
+----------+
|     8192 |
+----------+
1 row in set (0.01 sec)
沒(méi)有問(wèn)題可以查詢
   三、修改任意一個(gè)塊的file space header的34-37字節(jié) 查看看MYSQL INNODB 報(bào)錯(cuò),然后修改回去后是否能夠順利啟動(dòng)
       
       既然每個(gè)數(shù)據(jù)塊的file header都包含了space id,那么我們隨意更改一個(gè)塊的
current read blocks is : 0 --This Block is file space header blocks!    
current read blocks is : 1 --This Block is insert buffer bitmap  blocks!
current read blocks is : 2 --This Block is index node blocks!           
current read blocks is : 3 --This Block is data blocks(Tree leaf node)!
current read blocks is : 4 --This Block is data blocks(Tree leaf node)!
current read blocks is : 5 --This Block is data blocks(Tree leaf node)!
      這里就選擇5號(hào)塊(0開(kāi)始實(shí)際是第6個(gè)),這個(gè)塊為數(shù)據(jù)塊。
      具體過(guò)程不再給出,給出命令
      [root@hadoop1 test]# bctool c1.ibd 5 34 00000088
      [root@hadoop1 test]# bcview c1.ibd 16 34 4|more
      current block:00000005--Offset:00034--cnt bytes:04--data is:00000088
      查看數(shù)據(jù)沒(méi)有問(wèn)題,但是日志有報(bào)錯(cuò)
      2015-12-26 01:25:58 403be940  InnoDB: Error: space id and page n:o stored in the page
      InnoDB: read in are 136:5, should be 72:5!
      可以看到innodb 說(shuō) 5號(hào)塊的space id是136 就是0X88,應(yīng)該是72,雖然數(shù)據(jù)還能跑,這個(gè)錯(cuò)誤到底
      影響多大未知但是我們知道原因,修改回去
      關(guān)閉數(shù)據(jù)庫(kù):
      [root@hadoop1 test]# bctool c1.ibd 0 34 00000048
      [root@hadoop1 test]# bcview c1.ibd 16 34 4|more
      current block:00000005--Offset:00034--cnt bytes:04--data is:00000048
      錯(cuò)誤消失
      
 總結(jié):
 1、我們可以知道什么是space id,space id 就是表空間的唯一標(biāo)識(shí)
 2、我們可以知道什么是FSP HEADER BLOCK 及每個(gè)space 文件第一個(gè)塊,
    而FSP HEADER 存放在每一個(gè)SPACE文件的第一個(gè)塊的38-150字節(jié),實(shí)際這個(gè)塊還會(huì)存放XDS信息就是EXTENTS的信息這里不
    再介紹
 3、我們可以知道訪問(wèn)表的時(shí)候如果第一個(gè)塊的FIL HEADER的34-37字節(jié)的SPCAE_ID和FSP HEADER的38-41字節(jié)對(duì)應(yīng)不上數(shù)據(jù)庫(kù)會(huì)
    立即宕機(jī)。
    報(bào)錯(cuò):
    2015-12-26 01:05:38 5074 [ERROR] InnoDB: Space id in fsp header 238,but in the page header 72
 4、我們還知道了如果不是第一個(gè)塊的FIL HEADER 34-37字節(jié) space id出現(xiàn)問(wèn)題,日志只會(huì)報(bào)錯(cuò),但是不影響使用
    報(bào)錯(cuò):
    2015-12-26 01:25:58 403be940  InnoDB: Error: space id and page n:o stored in the page
    InnoDB: read in are 136:5, should be 72:5!    
 5、為了完成這個(gè)實(shí)驗(yàn),我使用了3個(gè)工具,均為自己寫的,如果沒(méi)有這3個(gè)工具這個(gè)實(shí)驗(yàn)無(wú)法完成,或者很困難
  ---mysqlblock :用于查看數(shù)據(jù)文件中塊的類型
    ***************************************************
USEAGE: mysqlblock datafile -t/-d                  
This small tool used in study and test database,not
uesd on online database!                           
This tool is used to find how many blocks and types
in specified datafile,Exp:how many undo block in d
ata file!                                          
QQ:22389860                                        
***************************************************
-t Only Total blocks types in ibdata!              
-d Blocks types detail  in ibdata!                 
***************************************************
USEAGE: mysqlblock datafile -t/-d
   ---bcview:用于查看塊的固定字節(jié)輸出
******************************************************************
This Tool Is Uesed For Find The Data In Binary format(Hexadecimal)
Usage:./bcview file blocksize offset cnt-bytes!                   
file: Is Your File Will To Find Data!                             
blocksize: Is N kb Block.Eg: 8 Is 8 Kb Blocksize(Oracle)!         
                         Eg: 16 Is 16 Kb Blocksize(Innodb)!       
offset:Is Every Block Offset Your Want Start!                                     
cnt-bytes:Is After Offset,How Bytes Your Want Gets!                               
Edtor QQ:22389860!                                                
Used gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)                
******************************************************************
usage:./bcview file blocksize offset cnt-bytes!
   ---bctool:用于修改某個(gè)塊的某個(gè)字節(jié)的數(shù)據(jù)(現(xiàn)支持16K)
******************************************************************
This tool is uesed to check data ues binary format,no Big-Endian  
or Little-Endian diff,this tool is base one byte on byte to change
!block is 16k.if want change other block eg:8k! please set blocks
0 and offset blocks*8192+offset!                                  
usage:./bctool yfile blocks offset yourdata(XX)!                  
Warings:backup file frist!!!!!!!!!                                
Editor QQ:22389860                                                
Ues gcc version 4.1.2 20080704 (Red Hat 4.1.2-46)                 
******************************************************************
usage:./bctool file block offset yourdata(XX)!

當(dāng)然bctool和bcview 可以修改和查看任何文件,不光是INNODB BLOCK。

關(guān)于“MYSQL出現(xiàn)Space id in fsp header,but in the page header錯(cuò)誤怎么辦”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI