| 1 | /* |
| 2 | Copyright (c) 2000, 2010, Oracle and/or its affiliates |
| 3 | |
| 4 | This program is free software; you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by |
| 6 | the Free Software Foundation; version 2 of the License. |
| 7 | |
| 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program; if not, write to the Free Software |
| 15 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ |
| 16 | |
| 17 | /* Read and write key blocks */ |
| 18 | |
| 19 | #include "myisamdef.h"cxx . . $ `<file>/storage/myisam/myisamdef.h`/ |
| 20 | |
| 21 | /* Fetch a key-page in memory */ |
| 22 | |
| 23 | ucharcxx . . $ uchar# *_mi_fetch_keypagecxx . . $ _mi_fetch_keypage(561755aa1cfa84ee).(register MI_INFOcxx . . $ MI_INFO# *info, MI_KEYDEFcxx . . $ MI_KEYDEF# *keyinfo, |
| 24 | my_off_tcxx . . $ my_off_t# page, int level, |
| 25 | ucharcxx . . $ uchar# *buff, int return_buffer) |
| 26 | { |
| 27 | ucharcxx . . $ uchar# *tmp; |
| 28 | uintcxx . . $ uint# page_size; |
| 29 | DBUG_ENTERcxx . . $ `include/my_dbug.h:165:9`!("_mi_fetch_keypage"); |
| 30 | DBUG_PRINTcxx . . $ `include/my_dbug.h:174:9`!("enter",("page: %ld", (long) page)); |
| 31 | |
| 32 | tmp=(ucharcxx . . $ uchar#*) key_cache_readcxx . . $ key_cache_read(d8271c7699f8b4b8).(info->scxx . . $ st_myisam_info#s.->key_cachecxx . . $ st_mi_isam_share#key_cache., |
| 33 | info->scxx . . $ st_myisam_info#s.->kfilecxx . . $ st_mi_isam_share#kfile., page, level, (ucharcxx . . $ uchar#*) buff, |
| 34 | (uintcxx . . $ uint#) keyinfo->block_lengthcxx . . $ st_mi_keydef#block_length., |
| 35 | (uintcxx . . $ uint#) keyinfo->block_lengthcxx . . $ st_mi_keydef#block_length., |
| 36 | return_buffer); |
| 37 | if (tmp == info->buffcxx . . $ st_myisam_info#buff.) |
| 38 | info->buff_usedcxx . . $ st_myisam_info#buff_used.=1; |
| 39 | else if (!tmp) |
| 40 | { |
| 41 | DBUG_PRINTcxx . . $ `include/my_dbug.h:174:9`!("error",("Got errno: %d from key_cache_read",my_errno)); |
| 42 | info->last_keypagecxx . . $ st_myisam_info#last_keypage.=HA_OFFSET_ERRORcxx . . $ `include/my_base.h:695:9`!; |
| 43 | mi_print_errorcxx . . $ `storage/myisam/myisamdef.h:361:9`!(info->s, HA_ERR_CRASHEDcxx . . $ `include/my_base.h:471:9`!); |
| 44 | my_errnocxx . . $ `include/my_pthread.h:720:9`!=HA_ERR_CRASHEDcxx . . $ `include/my_base.h:471:9`!; |
| 45 | DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!(0); |
| 46 | } |
| 47 | info->last_keypagecxx . . $ st_myisam_info#last_keypage.=page; |
| 48 | page_size=mi_getintcxx . . $ `storage/myisam/myisamdef.h:344:9`!(tmp); |
| 49 | if (page_size < 4 || page_size > keyinfo->block_lengthcxx . . $ st_mi_keydef#block_length.) |
| 50 | { |
| 51 | DBUG_PRINTcxx . . $ `include/my_dbug.h:174:9`!("error",("page %lu had wrong page length: %u", |
| 52 | (ulong) page, page_size)); |
| 53 | DBUG_DUMPcxx . . $ `include/my_dbug.h:182:9`!("page", tmp, keyinfo->block_length); |
| 54 | info->last_keypagecxx . . $ st_myisam_info#last_keypage. = HA_OFFSET_ERRORcxx . . $ `include/my_base.h:695:9`!; |
| 55 | mi_print_errorcxx . . $ `storage/myisam/myisamdef.h:361:9`!(info->s, HA_ERR_CRASHEDcxx . . $ `include/my_base.h:471:9`!); |
| 56 | my_errnocxx . . $ `include/my_pthread.h:720:9`! = HA_ERR_CRASHEDcxx . . $ `include/my_base.h:471:9`!; |
| 57 | tmp = 0; |
| 58 | } |
| 59 | DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!(tmp); |
| 60 | } /* _mi_fetch_keypage */ |
| 61 | |
| 62 | |
| 63 | /* Write a key-page on disk */ |
| 64 | |
| 65 | int _mi_write_keypagecxx . . $ _mi_write_keypage(ea05f370fcadba31).(register MI_INFOcxx . . $ MI_INFO# *info, register MI_KEYDEFcxx . . $ MI_KEYDEF# *keyinfo, |
| 66 | my_off_tcxx . . $ my_off_t# page, int level, ucharcxx . . $ uchar# *buff) |
| 67 | { |
| 68 | reg3cxx . . $ `include/my_global.h:995:9`! uintcxx . . $ uint# length; |
| 69 | DBUG_ENTERcxx . . $ `include/my_dbug.h:165:9`!("_mi_write_keypage"); |
| 70 | |
| 71 | #ifndef FAST /* Safety check */ |
| 72 | if (page < info->scxx . . $ st_myisam_info#s.->basecxx . . $ st_mi_isam_share#base..keystartcxx . . $ st_mi_base_info#keystart. || |
| 73 | page+keyinfo->block_lengthcxx . . $ st_mi_keydef#block_length. > info->statecxx . . $ st_myisam_info#state.->key_file_lengthcxx . . $ st_mi_status_info#key_file_length. || |
| 74 | (page & (MI_MIN_KEY_BLOCK_LENGTHcxx . . $ `include/myisam.h:56:9`!-1))) |
| 75 | { |
| 76 | DBUG_PRINTcxx . . $ `include/my_dbug.h:174:9`!("error",("Trying to write inside key status region: key_start: %lu length: %lu page: %lu", |
| 77 | (long) info->s->base.keystart, |
| 78 | (long) info->state->key_file_length, |
| 79 | (long) page)); |
| 80 | my_errnocxx . . $ `include/my_pthread.h:720:9`!=EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 81 | DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!((-1)); |
| 82 | } |
| 83 | DBUG_PRINTcxx . . $ `include/my_dbug.h:174:9`!("page",("write page at: %lu",(long) page)); |
| 84 | DBUG_DUMPcxx . . $ `include/my_dbug.h:182:9`!("buff",(uchar*) buff,mi_getint(buff)); |
| 85 | #endif |
| 86 | |
| 87 | if ((length=keyinfo->block_lengthcxx . . $ st_mi_keydef#block_length.) > IO_SIZEcxx . . $ `include/my_global.h:672:9`!*2 && |
| 88 | info->statecxx . . $ st_myisam_info#state.->key_file_lengthcxx . . $ st_mi_status_info#key_file_length. != page+length) |
| 89 | length= ((mi_getintcxx . . $ `storage/myisam/myisamdef.h:344:9`!(buff)+IO_SIZEcxx . . $ `include/my_global.h:672:9`!-1) & (uintcxx . . $ uint#) ~(IO_SIZEcxx . . $ `include/my_global.h:672:9`!-1)); |
| 90 | DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!((key_cache_write(info->s->key_cache, |
| 91 | info->s->kfile, &info->s->dirty_part_map, |
| 92 | page, level, (uchar*) buff, length, |
| 93 | (uint) keyinfo->block_length, |
| 94 | (int) ((info->lock_type != F_UNLCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:225:10`!) || |
| 95 | info->s->delay_key_write)))); |
| 96 | } /* mi_write_keypage */ |
| 97 | |
| 98 | |
| 99 | /* Remove page from disk */ |
| 100 | |
| 101 | int _mi_disposecxx . . $ _mi_dispose(9d24ea4dc72bd9fd).(register MI_INFOcxx . . $ MI_INFO# *info, MI_KEYDEFcxx . . $ MI_KEYDEF# *keyinfo, my_off_tcxx . . $ my_off_t# pos, |
| 102 | int level) |
| 103 | { |
| 104 | my_off_tcxx . . $ my_off_t# old_link; |
| 105 | ucharcxx . . $ uchar# buff[8]; |
| 106 | DBUG_ENTERcxx . . $ `include/my_dbug.h:165:9`!("_mi_dispose"); |
| 107 | DBUG_PRINTcxx . . $ `include/my_dbug.h:174:9`!("enter",("pos: %ld", (long) pos)); |
| 108 | |
| 109 | old_link= info->scxx . . $ st_myisam_info#s.->statecxx . . $ st_mi_isam_share#state..key_delcxx . . $ st_mi_state_info#key_del.[keyinfo->block_size_indexcxx . . $ st_mi_keydef#block_size_index.]; |
| 110 | info->scxx . . $ st_myisam_info#s.->statecxx . . $ st_mi_isam_share#state..key_delcxx . . $ st_mi_state_info#key_del.[keyinfo->block_size_indexcxx . . $ st_mi_keydef#block_size_index.]= pos; |
| 111 | mi_sizestorecxx . . $ `include/myisampack.h:241:9`!(buff,old_link); |
| 112 | info->scxx . . $ st_myisam_info#s.->statecxx . . $ st_mi_isam_share#state..changedcxx . . $ st_mi_state_info#changed.|= STATE_NOT_SORTED_PAGEScxx . . $ `storage/myisam/myisamdef.h:338:9`!; |
| 113 | DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!(key_cache_write(info->s->key_cache, |
| 114 | info->s->kfile, &info->s->dirty_part_map, |
| 115 | pos , level, buff, |
| 116 | sizeof(buff), |
| 117 | (uint) keyinfo->block_length, |
| 118 | (int) (info->lock_type != F_UNLCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:225:10`!))); |
| 119 | } /* _mi_dispose */ |
| 120 | |
| 121 | |
| 122 | /* Make new page on disk */ |
| 123 | |
| 124 | my_off_tcxx . . $ my_off_t# _mi_newcxx . . $ _mi_new(abf43b5ec4b0f23d).(register MI_INFOcxx . . $ MI_INFO# *info, MI_KEYDEFcxx . . $ MI_KEYDEF# *keyinfo, int level) |
| 125 | { |
| 126 | my_off_tcxx . . $ my_off_t# pos; |
| 127 | ucharcxx . . $ uchar# buff[8]; |
| 128 | DBUG_ENTERcxx . . $ `include/my_dbug.h:165:9`!("_mi_new"); |
| 129 | |
| 130 | if ((pos= info->scxx . . $ st_myisam_info#s.->statecxx . . $ st_mi_isam_share#state..key_delcxx . . $ st_mi_state_info#key_del.[keyinfo->block_size_indexcxx . . $ st_mi_keydef#block_size_index.]) == |
| 131 | HA_OFFSET_ERRORcxx . . $ `include/my_base.h:695:9`!) |
| 132 | { |
| 133 | if (info->statecxx . . $ st_myisam_info#state.->key_file_lengthcxx . . $ st_mi_status_info#key_file_length. >= |
| 134 | info->scxx . . $ st_myisam_info#s.->basecxx . . $ st_mi_isam_share#base..max_key_file_lengthcxx . . $ st_mi_base_info#max_key_file_length. - keyinfo->block_lengthcxx . . $ st_mi_keydef#block_length.) |
| 135 | { |
| 136 | my_errnocxx . . $ `include/my_pthread.h:720:9`!=HA_ERR_INDEX_FILE_FULLcxx . . $ `include/my_base.h:481:9`!; |
| 137 | DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!(HA_OFFSET_ERRORcxx . . $ `include/my_base.h:695:9`!); |
| 138 | } |
| 139 | pos=info->statecxx . . $ st_myisam_info#state.->key_file_lengthcxx . . $ st_mi_status_info#key_file_length.; |
| 140 | info->statecxx . . $ st_myisam_info#state.->key_file_lengthcxx . . $ st_mi_status_info#key_file_length.+= keyinfo->block_lengthcxx . . $ st_mi_keydef#block_length.; |
| 141 | } |
| 142 | else |
| 143 | { |
| 144 | if (!key_cache_readcxx . . $ key_cache_read(d8271c7699f8b4b8).(info->scxx . . $ st_myisam_info#s.->key_cachecxx . . $ st_mi_isam_share#key_cache., |
| 145 | info->scxx . . $ st_myisam_info#s.->kfilecxx . . $ st_mi_isam_share#kfile., pos, level, |
| 146 | buff, |
| 147 | (uintcxx . . $ uint#) sizeof(buff), |
| 148 | (uintcxx . . $ uint#) keyinfo->block_lengthcxx . . $ st_mi_keydef#block_length.,0)) |
| 149 | pos= HA_OFFSET_ERRORcxx . . $ `include/my_base.h:695:9`!; |
| 150 | else |
| 151 | info->scxx . . $ st_myisam_info#s.->statecxx . . $ st_mi_isam_share#state..key_delcxx . . $ st_mi_state_info#key_del.[keyinfo->block_size_indexcxx . . $ st_mi_keydef#block_size_index.]= mi_sizekorrcxx . . $ `include/myisampack.h:242:9`!(buff); |
| 152 | } |
| 153 | info->scxx . . $ st_myisam_info#s.->statecxx . . $ st_mi_isam_share#state..changedcxx . . $ st_mi_state_info#changed.|= STATE_NOT_SORTED_PAGEScxx . . $ `storage/myisam/myisamdef.h:338:9`!; |
| 154 | DBUG_PRINTcxx . . $ `include/my_dbug.h:174:9`!("exit",("Pos: %ld",(long) pos)); |
| 155 | DBUG_RETURNcxx . . $ `include/my_dbug.h:168:9`!(pos); |
| 156 | } /* _mi_new */ |