diff --git a/storage/maria/ma_blockrec.c b/storage/maria/ma_blockrec.c index 0b338e633d7124ab24762e43797f946abe70b5e3..6d66bb3389a5a7e3c6a9f8750a380b015f68b679 100644 --- a/storage/maria/ma_blockrec.c +++ b/storage/maria/ma_blockrec.c @@ -7115,7 +7115,10 @@ my_bool _ma_apply_undo_bulk_insert(MARIA_HA *info, LSN undo_lsn) error= (maria_delete_all_rows(info) || maria_enable_indexes(info) || /* we enabled indices so need '2' below */ - _ma_state_info_write(info->s, 1|2|4) || + _ma_state_info_write(info->s, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET | + MA_STATE_INFO_WRITE_FULL_INFO | + MA_STATE_INFO_WRITE_LOCK) || _ma_write_clr(info, undo_lsn, LOGREC_UNDO_BULK_INSERT, FALSE, 0, &lsn, NULL)); DBUG_RETURN(error); diff --git a/storage/maria/ma_check.c b/storage/maria/ma_check.c index 38cfeb89f3354b265444500e3a081a912f719172..8f5e07e27f28427a85dab81a1f38ad9be34e63d5 100644 --- a/storage/maria/ma_check.c +++ b/storage/maria/ma_check.c @@ -2204,7 +2204,11 @@ static my_bool protect_against_repair_crash(MARIA_HA *info, FLUSH_FORCE_WRITE, discard_index ? FLUSH_IGNORE_CHANGED : FLUSH_FORCE_WRITE) || - (share->changed && _ma_state_info_write(share, 1|2|4))) + (share->changed && + _ma_state_info_write(share, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET | + MA_STATE_INFO_WRITE_FULL_INFO | + MA_STATE_INFO_WRITE_LOCK))) return TRUE; /* In maria_chk this is not needed: */ if (maria_multi_threaded && share->base.born_transactional) @@ -2213,7 +2217,9 @@ static my_bool protect_against_repair_crash(MARIA_HA *info, { /* this can be true only for a transactional table */ maria_mark_crashed_on_repair(info); - if (_ma_state_info_write(share, 1|4)) + if (_ma_state_info_write(share, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET | + MA_STATE_INFO_WRITE_LOCK)) return TRUE; } if (translog_status == TRANSLOG_OK && @@ -5960,7 +5966,9 @@ int maria_update_state_info(HA_CHECK *param, MARIA_HA *info,uint update) if (!share->state.create_time) share->state.create_time= share->state.check_time; } - if (_ma_state_info_write(share, 1|2)) + if (_ma_state_info_write(share, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET | + MA_STATE_INFO_WRITE_FULL_INFO)) goto err; share->changed=0; } diff --git a/storage/maria/ma_checkpoint.c b/storage/maria/ma_checkpoint.c index ac44bbdf7a14405fb35c63e662382d1bf2340647..a78b31edce76db7a5423eb169fe08149f1895f8e 100644 --- a/storage/maria/ma_checkpoint.c +++ b/storage/maria/ma_checkpoint.c @@ -368,7 +368,9 @@ static void flush_all_tables(int what_to_flush) FLUSH_KEEP, FLUSH_KEEP); break; case 1: - res= _ma_state_info_write(info->s, 1|4); + res= _ma_state_info_write(info->s, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET| + MA_STATE_INFO_WRITE_LOCK); DBUG_PRINT("maria_flush_states", ("is_of_horizon: LSN (%lu,0x%lx)", LSN_IN_PARTS(info->s->state.is_of_horizon))); @@ -1046,7 +1048,8 @@ static int collect_tables(LEX_STRING *str, LSN checkpoint_start_log_horizon) state_copies_horizon; if (kfile.file >= 0) sync_error|= - _ma_state_info_write_sub(kfile.file, &state_copy->state, 1); + _ma_state_info_write_sub(kfile.file, &state_copy->state, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET); /* We don't set share->changed=0 because it may interfere with a concurrent _ma_writeinfo() doing share->changed=1 (cancel its diff --git a/storage/maria/ma_close.c b/storage/maria/ma_close.c index f627078861d218d19161c1d2b52fd03cf9002fba..235b37f703094ec15a4be9bd3c01d34c6ea5aece 100644 --- a/storage/maria/ma_close.c +++ b/storage/maria/ma_close.c @@ -101,7 +101,7 @@ int maria_close(register MARIA_HA *info) State must be written to file as it was not done at table's unlocking. */ - if (_ma_state_info_write(share, 1)) + if (_ma_state_info_write(share, MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET)) error= my_errno; } /* diff --git a/storage/maria/ma_create.c b/storage/maria/ma_create.c index 903ef6bca9ec94f27e7ce6946a410f3ca39c39a7..d290007c86e08c0f2772268d54db2b9468a8ac1b 100644 --- a/storage/maria/ma_create.c +++ b/storage/maria/ma_create.c @@ -854,7 +854,8 @@ int maria_create(const char *name, enum data_file_type datafile_type, errpos=1; DBUG_PRINT("info", ("write state info and base info")); - if (_ma_state_info_write_sub(file, &share.state, 2) || + if (_ma_state_info_write_sub(file, &share.state, + MA_STATE_INFO_WRITE_FULL_INFO) || _ma_base_info_write(file, &share.base)) goto err; DBUG_PRINT("info", ("base_pos: %d base_info_size: %d", diff --git a/storage/maria/ma_delete_all.c b/storage/maria/ma_delete_all.c index bca4ef9655448968213e612a85fa16352d2bb581..4661ea0ab590252f8b55d68ac00634176aad3244 100644 --- a/storage/maria/ma_delete_all.c +++ b/storage/maria/ma_delete_all.c @@ -122,7 +122,9 @@ int maria_delete_all_rows(MARIA_HA *info) and fail, saying that it sees that the first page has to be created though the inserted row has rownr>0. */ - my_bool error= _ma_state_info_write(share, 1|4) || + my_bool error= _ma_state_info_write(share, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET | + MA_STATE_INFO_WRITE_LOCK) || _ma_update_state_lsns(share, lsn, trnman_get_min_trid(), FALSE, FALSE) || _ma_sync_table_files(info); info->trn->rec_lsn= LSN_IMPOSSIBLE; diff --git a/storage/maria/ma_extra.c b/storage/maria/ma_extra.c index 301d3af354973593296ebb59b4418360d9a90854..c311a035e9bfa1bf9f55a174a3da509aec6aa2b6 100644 --- a/storage/maria/ma_extra.c +++ b/storage/maria/ma_extra.c @@ -272,7 +272,9 @@ int maria_extra(MARIA_HA *info, enum ha_extra_function function, for the posterity is by writing it to disk. */ DBUG_ASSERT(!maria_in_recovery); - error= _ma_state_info_write(share, 1|2); + error= _ma_state_info_write(share, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET | + MA_STATE_INFO_WRITE_FULL_INFO); } pthread_mutex_unlock(&share->intern_lock); break; @@ -289,7 +291,9 @@ int maria_extra(MARIA_HA *info, enum ha_extra_function function, if (!error && share->changed) { pthread_mutex_lock(&share->intern_lock); - if (!(error= _ma_state_info_write(share, 1|2))) + if (!(error= _ma_state_info_write(share, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET| + MA_STATE_INFO_WRITE_FULL_INFO))) share->changed= 0; pthread_mutex_unlock(&share->intern_lock); } @@ -347,7 +351,10 @@ int maria_extra(MARIA_HA *info, enum ha_extra_function function, if (do_flush) { /* Save the state so that others can find it from disk. */ - if ((share->changed && _ma_state_info_write(share, 1 | 2)) || + if ((share->changed && + _ma_state_info_write(share, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET | + MA_STATE_INFO_WRITE_FULL_INFO)) || my_sync(share->kfile.file, MYF(0))) error= my_errno; else diff --git a/storage/maria/ma_key_recover.c b/storage/maria/ma_key_recover.c index 83e8b3cf72519f9fb8ec6e47bb9a4c6486e3f6c6..c4fe6613bb8d9dd74a57d728607d330789391eb2 100644 --- a/storage/maria/ma_key_recover.c +++ b/storage/maria/ma_key_recover.c @@ -192,7 +192,9 @@ my_bool write_hook_for_clr_end(enum translog_record_type type safe_mutex_assert_owner(&share->intern_lock); error= (maria_enable_indexes(tbl_info) || /* we enabled indices, need '2' below */ - _ma_state_info_write(share, 1|2)); + _ma_state_info_write(share, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET | + MA_STATE_INFO_WRITE_FULL_INFO)); /* no need for _ma_reset_status(): REDO_DELETE_ALL is just before us */ break; default: diff --git a/storage/maria/ma_locking.c b/storage/maria/ma_locking.c index 1ad41e5b213928a20a940b65c9a9fa251b0990bb..2a34d1fe9f3aec65d8d5f3ec67f73a436fed35af 100644 --- a/storage/maria/ma_locking.c +++ b/storage/maria/ma_locking.c @@ -112,7 +112,8 @@ int maria_lock_database(MARIA_HA *info, int lock_type) /* transactional tables rather flush their state at Checkpoint */ if (!share->base.born_transactional) { - if (_ma_state_info_write_sub(share->kfile.file, &share->state, 1)) + if (_ma_state_info_write_sub(share->kfile.file, &share->state, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET)) error= my_errno; else { @@ -316,8 +317,10 @@ int _ma_writeinfo(register MARIA_HA *info, uint operation) share->state.update_count= info->last_loop= ++info->this_loop; #endif - if ((error= _ma_state_info_write_sub(share->kfile.file, - &share->state, 1))) + if ((error= + _ma_state_info_write_sub(share->kfile.file, + &share->state, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET))) olderror=my_errno; #ifdef __WIN__ if (maria_flush) diff --git a/storage/maria/ma_open.c b/storage/maria/ma_open.c index 88f7feb41fd60af19b619e4e33f31eeba237e256..c6c786910db1d6bf630c6c1a60dc528059d71ace 100644 --- a/storage/maria/ma_open.c +++ b/storage/maria/ma_open.c @@ -1172,11 +1172,13 @@ static void setup_key_functions(register MARIA_KEYDEF *keyinfo) Then calls _ma_state_info_write_sub(). @param share table - @param pWrite bitmap: if 1 is set my_pwrite() is used otherwise - my_write(); if 2 is set, info about keys is written - (should only be needed after ALTER TABLE - ENABLE/DISABLE KEYS, and REPAIR/OPTIMIZE); if 4 is - set, MARIA_SHARE::intern_lock is taken. + @param pWrite bitmap: if 1 (MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET) + is set my_pwrite() is used otherwise my_write(); + if 2 (MA_STATE_INFO_WRITE_FULL_INFO) is set, info + about keys is written (should only be needed + after ALTER TABLE ENABLE/DISABLE KEYS, and + REPAIR/OPTIMIZE); if 4 (MA_STATE_INFO_WRITE_LOCK) + is set, MARIA_SHARE::intern_lock is taken. @return Operation status @retval 0 OK @@ -1189,7 +1191,7 @@ uint _ma_state_info_write(MARIA_SHARE *share, uint pWrite) if (share->options & HA_OPTION_READ_ONLY_DATA) return 0; - if (pWrite & 4) + if (pWrite & MA_STATE_INFO_WRITE_LOCK) pthread_mutex_lock(&share->intern_lock); else if (maria_multi_threaded) { @@ -1208,7 +1210,7 @@ uint _ma_state_info_write(MARIA_SHARE *share, uint pWrite) LSN_IN_PARTS(share->state.is_of_horizon))); } res= _ma_state_info_write_sub(share->kfile.file, &share->state, pWrite); - if (pWrite & 4) + if (pWrite & MA_STATE_INFO_WRITE_LOCK) pthread_mutex_unlock(&share->intern_lock); share->changed= 0; return res; @@ -1222,10 +1224,12 @@ uint _ma_state_info_write(MARIA_SHARE *share, uint pWrite) @param file descriptor of the index file to write @param state state information to write to the file - @param pWrite bitmap: if 1 is set my_pwrite() is used otherwise - my_write(); if 2 is set, info about keys is written - (should only be needed after ALTER TABLE - ENABLE/DISABLE KEYS, and REPAIR/OPTIMIZE). + @param pWrite bitmap: if 1 (MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET) + is set my_pwrite() is used otherwise my_write(); + if 2 (MA_STATE_INFO_WRITE_FULL_INFO) is set, info + about keys is written (should only be needed + after ALTER TABLE ENABLE/DISABLE KEYS, and + REPAIR/OPTIMIZE). @notes For transactional multiuser tables, this function is called @@ -1285,7 +1289,7 @@ uint _ma_state_info_write_sub(File file, MARIA_STATE_INFO *state, uint pWrite) mi_sizestore(ptr,state->key_root[i]); ptr+= 8; } mi_sizestore(ptr,state->key_del); ptr+= 8; - if (pWrite & 2) /* From maria_chk */ + if (pWrite & MA_STATE_INFO_WRITE_FULL_INFO) /* From maria_chk */ { uint key_parts= mi_uint2korr(state->header.key_parts); mi_int4store(ptr,state->sec_index_changed); ptr+= 4; @@ -1305,7 +1309,7 @@ uint _ma_state_info_write_sub(File file, MARIA_STATE_INFO *state, uint pWrite) } } - res= (pWrite & 1) ? + res= (pWrite & MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET) ? my_pwrite(file, buff, (size_t) (ptr-buff), 0L, MYF(MY_NABP | MY_THREADSAFE)) : my_write(file, buff, (size_t) (ptr-buff), diff --git a/storage/maria/ma_recovery.c b/storage/maria/ma_recovery.c index a63df9c1b79ee76d9a585b2d78adeffe04ff6bea..8470f509140c52d91f5ad6530c110b4ced877a6b 100644 --- a/storage/maria/ma_recovery.c +++ b/storage/maria/ma_recovery.c @@ -2809,7 +2809,8 @@ static void prepare_table_for_close(MARIA_HA *info, TRANSLOG_ADDRESS horizon) cmp_translog_addr(share->lsn_of_file_id, horizon) < 0) { share->state.is_of_horizon= horizon; - _ma_state_info_write_sub(share->kfile.file, &share->state, 1); + _ma_state_info_write_sub(share->kfile.file, &share->state, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET); } /* @@ -3364,7 +3365,9 @@ my_bool _ma_reenable_logging_for_table(MARIA_HA *info, my_bool flush_pages) */ if (_ma_flush_table_files(info, MARIA_FLUSH_DATA | MARIA_FLUSH_INDEX, FLUSH_RELEASE, FLUSH_RELEASE) || - _ma_state_info_write(share, 1|4) || + _ma_state_info_write(share, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET | + MA_STATE_INFO_WRITE_LOCK) || _ma_sync_table_files(info)) DBUG_RETURN(1); } diff --git a/storage/maria/maria_def.h b/storage/maria/maria_def.h index 52b14b80aa6e496510c8a51f49e94bd72fa6f15f..7c2017c46715632ffb202d6fa155b0557fa76add 100644 --- a/storage/maria/maria_def.h +++ b/storage/maria/maria_def.h @@ -1076,6 +1076,12 @@ extern size_t _ma_nommap_pread(MARIA_HA *info, uchar *Buffer, extern size_t _ma_nommap_pwrite(MARIA_HA *info, const uchar *Buffer, size_t Count, my_off_t offset, myf MyFlags); +/* my_pwrite instead of my_write used */ +#define MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET 1 +/* info should be written */ +#define MA_STATE_INFO_WRITE_FULL_INFO 2 +/* intern_lock taking is needed */ +#define MA_STATE_INFO_WRITE_LOCK 4 uint _ma_state_info_write(MARIA_SHARE *share, uint pWrite); uint _ma_state_info_write_sub(File file, MARIA_STATE_INFO *state, uint pWrite); uint _ma_state_info_read_dsk(File file, MARIA_STATE_INFO *state); diff --git a/storage/maria/maria_pack.c b/storage/maria/maria_pack.c index b946647554839950a7bbbc6de8e055f9637baf31..234ac61c08dadd48ba85d26addbd7a6af9e21711 100644 --- a/storage/maria/maria_pack.c +++ b/storage/maria/maria_pack.c @@ -3006,7 +3006,9 @@ static int save_state(MARIA_HA *isam_file,PACK_MRG_INFO *mrg, if (share->base.keys) isamchk_neaded=1; DBUG_RETURN(_ma_state_info_write_sub(share->kfile.file, - &share->state, (1 + 2))); + &share->state, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET | + MA_STATE_INFO_WRITE_FULL_INFO)); } @@ -3046,7 +3048,9 @@ static int save_state_mrg(File file,PACK_MRG_INFO *mrg,my_off_t new_length, if (isam_file->s->base.keys) isamchk_neaded=1; state.changed=STATE_CHANGED | STATE_NOT_ANALYZED; /* Force check of table */ - DBUG_RETURN (_ma_state_info_write_sub(file,&state,1+2)); + DBUG_RETURN (_ma_state_info_write_sub(file, &state, + MA_STATE_INFO_WRITE_DONT_MOVE_OFFSET | + MA_STATE_INFO_WRITE_FULL_INFO)); }