├── InnoDB_ A hands-on exploration of on-disk storage with innodb_ruby - Google Drive.pdf ├── README.md └── innodb ├── include.py ├── include.pyc ├── mylib.py ├── mylib.pyc └── py_innodb_page_info.py /InnoDB_ A hands-on exploration of on-disk storage with innodb_ruby - Google Drive.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luodw/Innodb/5a68a6141ed3c4d7cec3832b6c8235b1ec86c426/InnoDB_ A hands-on exploration of on-disk storage with innodb_ruby - Google Drive.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Innodb 2 | 学习Innodb的一些资料和网站 3 | -------------------------------------------------------------------------------- /innodb/include.py: -------------------------------------------------------------------------------- 1 | #encoding=utf-8 2 | INNODB_PAGE_SIZE = 16*1024*1024 3 | 4 | # Start of the data on the page 5 | FIL_PAGE_DATA = 38 6 | 7 | 8 | FIL_PAGE_OFFSET = 4 # page offset inside space 9 | FIL_PAGE_TYPE = 24 # File page type 10 | 11 | # Types of an undo log segment */ 12 | TRX_UNDO_INSERT = 1 13 | TRX_UNDO_UPDATE = 2 14 | 15 | # On a page of any file segment, data may be put starting from this offset 16 | FSEG_PAGE_DATA = FIL_PAGE_DATA 17 | 18 | # The offset of the undo log page header on pages of the undo log 19 | TRX_UNDO_PAGE_HDR = FSEG_PAGE_DATA 20 | 21 | PAGE_LEVEL = 26 #level of the node in an index tree; the leaf level is the level 0 */ 22 | 23 | innodb_page_type={ 24 | '0000':u'Freshly Allocated Page', 25 | '0002':u'Undo Log Page', 26 | '0003':u'File Segment inode', 27 | '0004':u'Insert Buffer Free List', 28 | '0005':u'Insert Buffer Bitmap', 29 | '0006':u'System Page', 30 | '0007':u'Transaction system Page', 31 | '0008':u'File Space Header', 32 | '0009':u'扩展描述页', 33 | '000a':u'Uncompressed BLOB Page', 34 | '000b':u'1st compressed BLOB Page', 35 | '000c':u'Subsequent compressed BLOB Page', 36 | '45bf':u'B-tree Node' 37 | } 38 | 39 | innodb_page_direction={ 40 | '0000': 'Unknown(0x0000)', 41 | '0001': 'Page Left', 42 | '0002': 'Page Right', 43 | '0003': 'Page Same Rec', 44 | '0004': 'Page Same Page', 45 | '0005': 'Page No Direction', 46 | 'ffff': 'Unkown2(0xffff)' 47 | } 48 | 49 | 50 | INNODB_PAGE_SIZE=1024*16 # InnoDB Page 16K -------------------------------------------------------------------------------- /innodb/include.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luodw/Innodb/5a68a6141ed3c4d7cec3832b6c8235b1ec86c426/innodb/include.pyc -------------------------------------------------------------------------------- /innodb/mylib.py: -------------------------------------------------------------------------------- 1 | #encoding=utf-8 2 | import os 3 | import include 4 | from include import * 5 | 6 | TABLESPACE_NAME='D:\\mysql_data\\test\\t.ibd' 7 | VARIABLE_FIELD_COUNT = 1 8 | NULL_FIELD_COUNT = 0 9 | 10 | class myargv(object): 11 | def __init__(self, argv): 12 | self.argv = argv 13 | self.parms = {} 14 | self.tablespace = '' 15 | 16 | def parse_cmdline(self): 17 | argv = self.argv 18 | if len(argv) == 1: 19 | print 'Usage: python py_innodb_page_info.py [OPTIONS] tablespace_file' 20 | print 'For more options, use python py_innodb_page_info.py -h' 21 | return 0 22 | while argv: 23 | if argv[0][0] == '-': 24 | if argv[0][1] == 'h': 25 | self.parms[argv[0]] = '' 26 | argv = argv[1:] 27 | break 28 | if argv[0][1] == 'v': 29 | self.parms[argv[0]] = '' 30 | argv = argv[1:] 31 | else: 32 | self.parms[argv[0]] = argv[1] 33 | argv = argv[2:] 34 | else: 35 | self.tablespace = argv[0] 36 | argv = argv[1:] 37 | if self.parms.has_key('-h'): 38 | print 'Get InnoDB Page Info' 39 | print 'Usage: python py_innodb_page_info.py [OPTIONS] tablespace_file\n' 40 | print 'The following options may be given as the first argument:' 41 | print '-h help ' 42 | print '-o output put the result to file' 43 | print '-t number thread to anayle the tablespace file' 44 | print '-v verbose mode' 45 | return 0 46 | return 1 47 | 48 | def mach_read_from_n(page,start_offset,length): 49 | ret = page[start_offset:start_offset+length] 50 | return ret.encode('hex') 51 | 52 | def get_innodb_page_type(myargv): 53 | f=file(myargv.tablespace,'rb') 54 | fsize = os.path.getsize(f.name)/INNODB_PAGE_SIZE 55 | ret = {} 56 | for i in range(fsize): 57 | page = f.read(INNODB_PAGE_SIZE) 58 | page_offset = mach_read_from_n(page,FIL_PAGE_OFFSET,4) 59 | page_type = mach_read_from_n(page,FIL_PAGE_TYPE,2) 60 | if myargv.parms.has_key('-v'): 61 | if page_type == '45bf': 62 | page_level = mach_read_from_n(page,FIL_PAGE_DATA+PAGE_LEVEL,2) 63 | print "page offset %s, page type <%s>, page level <%s>"%(page_offset,innodb_page_type[page_type],page_level) 64 | else: 65 | print "page offset %s, page type <%s>"%(page_offset,innodb_page_type[page_type]) 66 | if not ret.has_key(page_type): 67 | ret[page_type] = 1 68 | else: 69 | ret[page_type] = ret[page_type] + 1 70 | print "Total number of page: %d:"%fsize 71 | for type in ret: 72 | print "%s: %s"%(innodb_page_type[type],ret[type]) -------------------------------------------------------------------------------- /innodb/mylib.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/luodw/Innodb/5a68a6141ed3c4d7cec3832b6c8235b1ec86c426/innodb/mylib.pyc -------------------------------------------------------------------------------- /innodb/py_innodb_page_info.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | #encoding=utf-8 3 | import mylib 4 | from sys import argv 5 | from mylib import myargv 6 | 7 | if __name__ == '__main__': 8 | myargv = myargv(argv) 9 | if myargv.parse_cmdline() == 0: 10 | pass 11 | else: 12 | mylib.get_innodb_page_type(myargv) 13 | --------------------------------------------------------------------------------