diff options
author | Daniel Black <daniel@mariadb.org> | 2021-02-17 16:15:19 +1100 |
---|---|---|
committer | Daniel Black <daniel@mariadb.org> | 2021-02-21 19:31:23 +1100 |
commit | 2a72b642f7176cba611d6a08dbab269ac0726ffc (patch) | |
tree | f81777250b76051270b5ec574f281dca117e60b3 | |
parent | 348739b37e15c83fcf6df2996a6eff81d37a166d (diff) | |
download | mariadb-git-bb-10.5-danielblack-MDEV-23510-arm-lfhash.tar.gz |
innodb/extrabackup: use global my_{[cm]alloc,free}_alignedbb-10.5-danielblack-MDEV-23510-arm-lfhash
Add error handling to most of the mariabackup/innodb
paths to handle failure to allocate memory.
-rw-r--r-- | extra/innochecksum.cc | 17 | ||||
-rw-r--r-- | extra/mariabackup/fil_cur.cc | 11 | ||||
-rw-r--r-- | extra/mariabackup/xtrabackup.cc | 40 | ||||
-rw-r--r-- | storage/innobase/buf/buf0buf.cc | 14 | ||||
-rw-r--r-- | storage/innobase/buf/buf0dblwr.cc | 25 | ||||
-rw-r--r-- | storage/innobase/buf/buf0flu.cc | 5 | ||||
-rw-r--r-- | storage/innobase/fil/fil0fil.cc | 16 | ||||
-rw-r--r-- | storage/innobase/fsp/fsp0file.cc | 17 | ||||
-rw-r--r-- | storage/innobase/include/buf0buf.h | 34 | ||||
-rw-r--r-- | storage/innobase/os/os0file.cc | 30 | ||||
-rw-r--r-- | storage/innobase/page/page0zip.cc | 8 | ||||
-rw-r--r-- | storage/innobase/row/row0ftsort.cc | 10 | ||||
-rw-r--r-- | storage/innobase/row/row0import.cc | 59 | ||||
-rw-r--r-- | storage/innobase/srv/srv0start.cc | 13 |
14 files changed, 182 insertions, 117 deletions
diff --git a/extra/innochecksum.cc b/extra/innochecksum.cc index 833e66341c7..43462e71d55 100644 --- a/extra/innochecksum.cc +++ b/extra/innochecksum.cc @@ -1628,10 +1628,15 @@ int main( } - buf = static_cast<byte*>(aligned_malloc(UNIV_PAGE_SIZE_MAX, - UNIV_PAGE_SIZE_MAX)); - xdes = static_cast<byte*>(aligned_malloc(UNIV_PAGE_SIZE_MAX, - UNIV_PAGE_SIZE_MAX)); + buf = static_cast<byte*>(my_malloc_aligned(UNIV_PAGE_SIZE_MAX, + UNIV_PAGE_SIZE_MAX)); + xdes = static_cast<byte*>(my_malloc_aligned(UNIV_PAGE_SIZE_MAX, + UNIV_PAGE_SIZE_MAX)); + if (!buf || !xdes) { + fprintf(stderr, "Error: allocating memory 2*%u bytes\n", UNIV_PAGE_SIZE_MAX); + exit_status = 1; + goto my_exit; + } /* The file name is not optional. */ for (int i = 0; i < argc; ++i) { @@ -2022,8 +2027,8 @@ my_exit: } common_exit: - aligned_free(buf); - aligned_free(xdes); + my_free_aligned(buf); + my_free_aligned(xdes); my_end(exit_status); DBUG_RETURN(exit_status); } diff --git a/extra/mariabackup/fil_cur.cc b/extra/mariabackup/fil_cur.cc index 1364b337bec..e1de85e1f3d 100644 --- a/extra/mariabackup/fil_cur.cc +++ b/extra/mariabackup/fil_cur.cc @@ -217,9 +217,14 @@ xb_fil_cur_open( /* Allocate read buffer */ cursor->buf_size = XB_FIL_CUR_PAGES * cursor->page_size; - cursor->buf = static_cast<byte*>(aligned_malloc(cursor->buf_size, - srv_page_size)); + cursor->buf = static_cast<byte*>(my_malloc_aligned(cursor->buf_size, + srv_page_size)); + if (!cursor->buf) { + msg(thread_n, "mariabackup: error: cannot allocate %zu bytes", + cursor->buf_size); + return XB_FIL_CUR_ERROR; + } cursor->buf_read = 0; cursor->buf_npages = 0; cursor->buf_offset = 0; @@ -491,7 +496,7 @@ xb_fil_cur_close( cursor->read_filter->deinit(&cursor->read_filter_ctxt); } - aligned_free(cursor->buf); + my_free_aligned(cursor->buf); cursor->buf = NULL; if (cursor->node != NULL) { diff --git a/extra/mariabackup/xtrabackup.cc b/extra/mariabackup/xtrabackup.cc index 495c7d7e2fe..4511f2a4aec 100644 --- a/extra/mariabackup/xtrabackup.cc +++ b/extra/mariabackup/xtrabackup.cc @@ -507,8 +507,10 @@ void CorruptedPages::zero_out_free_pages() { container_t non_free_pages; byte *zero_page= - static_cast<byte *>(aligned_malloc(srv_page_size, srv_page_size)); - memset(zero_page, 0, srv_page_size); + static_cast<byte *>(my_calloc_aligned(srv_page_size, srv_page_size)); + + if (!zero_page) + die("Can't allocate %lu bytes of memory", srv_page_size); ut_a(!pthread_mutex_lock(&m_mutex)); for (container_t::const_iterator space_it= m_spaces.begin(); @@ -557,7 +559,7 @@ void CorruptedPages::zero_out_free_pages() } m_spaces.swap(non_free_pages); ut_a(!pthread_mutex_unlock(&m_mutex)); - aligned_free(zero_page); + my_free_aligned(zero_page); } /* Simple datasink creation tracking...add datasinks in the reverse order you @@ -3551,7 +3553,13 @@ static dberr_t xb_assign_undo_space_start() } byte* page = static_cast<byte*> - (aligned_malloc(srv_page_size, srv_page_size)); + (my_malloc_aligned(srv_page_size, srv_page_size)); + + if (!page) { + msg("Allocating %lu bytes of memory.\n", srv_page_size); + error = DB_OUT_OF_MEMORY; + goto func_exit; + } if (os_file_read(IORequestRead, file, page, 0, srv_page_size) != DB_SUCCESS) { @@ -3598,7 +3606,7 @@ retry: srv_undo_space_id_start = space; func_exit: - aligned_free(page); + my_free_aligned(page); ret = os_file_close(file); ut_a(ret); @@ -4750,10 +4758,12 @@ xb_space_create_file( } /* Align the memory for file i/o if we might have O_DIRECT set */ - byte* page = static_cast<byte*>(aligned_malloc(2 * srv_page_size, - srv_page_size)); - - memset(page, '\0', srv_page_size); + byte* page = static_cast<byte*>(my_calloc_aligned(2 * srv_page_size, + srv_page_size)); + if (!page) { + msg("Allocating %lu bytes of memory.", 2 * srv_page_size); + return FALSE; + } fsp_header_init_fields(page, space_id, flags); mach_write_to_4(page + FIL_PAGE_ARCH_LOG_NO_OR_SPACE_ID, space_id); @@ -4786,7 +4796,7 @@ xb_space_create_file( page_zip.data, 0, zip_size); } - aligned_free(page); + my_free_aligned(page); if (ret != DB_SUCCESS) { msg("mariabackup: could not write the first page to %s", @@ -5084,8 +5094,12 @@ xtrabackup_apply_delta( /* allocate buffer for incremental backup (4096 pages) */ incremental_buffer = static_cast<byte *> - (aligned_malloc(page_size / 4 * page_size, page_size)); + (my_malloc_aligned(page_size / 4 * page_size, page_size)); + if (!incremental_buffer) { + msg("Allocating %zu bytes of memory.", page_size / 4 * page_size); + goto error; + } msg("Applying %s to %s...", src_path, dst_path); while (!last_buffer) { @@ -5193,7 +5207,7 @@ xtrabackup_apply_delta( incremental_buffers++; } - aligned_free(incremental_buffer); + my_free_aligned(incremental_buffer); if (src_file != OS_FILE_CLOSED) { os_file_close(src_file); os_file_delete(0,src_path); @@ -5203,7 +5217,7 @@ xtrabackup_apply_delta( return TRUE; error: - aligned_free(incremental_buffer); + my_free_aligned(incremental_buffer); if (src_file != OS_FILE_CLOSED) os_file_close(src_file); if (dst_file != OS_FILE_CLOSED && info.space_id) diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc index d531be43a8b..73bd77cc75c 100644 --- a/storage/innobase/buf/buf0buf.cc +++ b/storage/innobase/buf/buf0buf.cc @@ -1373,14 +1373,15 @@ static void buf_block_free_mutexes(buf_block_t* block) } /** Create the hash table. -@param n the lower bound of n_cells */ -void buf_pool_t::page_hash_table::create(ulint n) +@param n the lower bound of n_cells +@return array */ +hash_cell_t* buf_pool_t::page_hash_table::create(ulint n) { n_cells= ut_find_prime(n); const size_t size= pad(n_cells) * sizeof *array; - void* v= aligned_malloc(size, CPU_LEVEL1_DCACHE_LINESIZE); - memset(v, 0, size); + void* v= my_calloc_aligned(size, CPU_LEVEL1_DCACHE_LINESIZE); array= static_cast<hash_cell_t*>(v); + return array; } /** Create the buffer pool. @@ -1829,7 +1830,10 @@ inline bool buf_pool_t::withdraw_blocks() inline void buf_pool_t::resize_hash() { page_hash_table *new_page_hash= UT_NEW_NOKEY(page_hash_table()); - new_page_hash->create(2 * buf_pool.curr_size); + if (!new_page_hash->create(2 * buf_pool.curr_size)) + { + /* FIXME: FAIL OOM */ + } new_page_hash->write_lock_all(); for (auto i= page_hash.pad(page_hash.n_cells); i--; ) diff --git a/storage/innobase/buf/buf0dblwr.cc b/storage/innobase/buf/buf0dblwr.cc index afaa02e7ab1..b37ffd19cfb 100644 --- a/storage/innobase/buf/buf0dblwr.cc +++ b/storage/innobase/buf/buf0dblwr.cc @@ -66,9 +66,10 @@ inline void buf_dblwr_t::init(const byte *header) for (int i= 0; i < 2; i++) { slots[i].write_buf= static_cast<byte*> - (aligned_malloc(buf_size << srv_page_size_shift, srv_page_size)); + (my_malloc_aligned(buf_size << srv_page_size_shift, srv_page_size)); slots[i].buf_block_arr= static_cast<element*> (ut_zalloc_nokey(buf_size * sizeof(element))); + /* FIXME: OOM */ } active_slot= &slots[0]; } @@ -243,8 +244,12 @@ dberr_t buf_dblwr_t::init_or_load_pages(pfs_os_file_t file, const char *path) const uint32_t size= block_size(); /* We do the file i/o past the buffer pool */ - byte *read_buf= static_cast<byte*>(aligned_malloc(srv_page_size, - srv_page_size)); + byte *read_buf= static_cast<byte*>(my_malloc_aligned(srv_page_size, + srv_page_size)); + if (!read_buf) + { + return DB_OUT_OF_MEMORY; + } /* Read the TRX_SYS header to check if we are using the doublewrite buffer */ dberr_t err= os_file_read(IORequestRead, file, read_buf, TRX_SYS_PAGE_NO << srv_page_size_shift, @@ -254,7 +259,7 @@ dberr_t buf_dblwr_t::init_or_load_pages(pfs_os_file_t file, const char *path) { ib::error() << "Failed to read the system tablespace header page"; func_exit: - aligned_free(read_buf); + my_free_aligned(read_buf); return err; } @@ -342,8 +347,12 @@ void buf_dblwr_t::recover() return; uint32_t page_no_dblwr= 0; - byte *read_buf= static_cast<byte*>(aligned_malloc(3 * srv_page_size, - srv_page_size)); + byte *read_buf= static_cast<byte*>(my_malloc_aligned(3 * srv_page_size, + srv_page_size)); + if (!read_buf) + { + /* FIXME: OOM */ + } byte *const buf= read_buf + srv_page_size; for (recv_dblwr_t::list::iterator i= recv_sys.dblwr.pages.begin(); @@ -438,7 +447,7 @@ next_page: recv_sys.dblwr.pages.clear(); fil_flush_file_spaces(); - aligned_free(read_buf); + my_free_aligned(read_buf); } /** Free the doublewrite buffer. */ @@ -455,7 +464,7 @@ void buf_dblwr_t::close() pthread_cond_destroy(&cond); for (int i= 0; i < 2; i++) { - aligned_free(slots[i].write_buf); + my_free_aligned(slots[i].write_buf); ut_free(slots[i].buf_block_arr); } mysql_mutex_destroy(&mutex); diff --git a/storage/innobase/buf/buf0flu.cc b/storage/innobase/buf/buf0flu.cc index 21a01dbd2fe..42057ef1295 100644 --- a/storage/innobase/buf/buf0flu.cc +++ b/storage/innobase/buf/buf0flu.cc @@ -621,7 +621,7 @@ static void buf_tmp_reserve_compression_buf(buf_tmp_buffer_t* slot) #elif defined HAVE_SNAPPY size= snappy_max_compressed_length(size); #endif - slot->comp_buf= static_cast<byte*>(aligned_malloc(size, srv_page_size)); + slot->comp_buf= static_cast<byte*>(my_malloc_aligned(size, srv_page_size)); } /** Encrypt a buffer of temporary tablespace @@ -744,6 +744,9 @@ not_compressed: /* First we compress the page content */ buf_tmp_reserve_compression_buf(slot); byte *tmp= slot->comp_buf; + if (!tmp) { + /* TODO handle OOM */ + } ulint len= fil_page_compress(s, tmp, space->flags, fil_space_get_block_size(space, page_no), encrypted); diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index d000bc471d9..59f7ecebd97 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -1402,7 +1402,7 @@ fil_write_flushed_lsn( return DB_ERROR; } - buf = static_cast<byte*>(aligned_malloc(srv_page_size, srv_page_size)); + buf = static_cast<byte*>(my_malloc_aligned(srv_page_size, srv_page_size)); auto fio = fil_system.sys_space->io(IORequestRead, 0, srv_page_size, buf); @@ -1425,7 +1425,7 @@ fil_write_flushed_lsn( fil_system.sys_space->release(); } - aligned_free(buf); + my_free_aligned(buf); return fio.err; } @@ -2357,10 +2357,12 @@ err_exit: flush would write to it. */ /* Align the memory for file i/o if we might have O_DIRECT set */ - page = static_cast<byte*>(aligned_malloc(2 * srv_page_size, - srv_page_size)); - - memset(page, '\0', srv_page_size); + page = static_cast<byte*>(my_calloc_aligned(2 * srv_page_size, + srv_page_size)); + if (!page) { + *err = DB_OUT_OF_MEMORY; + return NULL; + } if (fil_space_t::full_crc32(flags)) { flags |= FSP_FLAGS_FCRC32_PAGE_SSIZE(); @@ -2406,7 +2408,7 @@ err_exit: page, 0, srv_page_size); } - aligned_free(page); + my_free_aligned(page); if (*err != DB_SUCCESS) { ib::error() diff --git a/storage/innobase/fsp/fsp0file.cc b/storage/innobase/fsp/fsp0file.cc index 57164113647..a2b2b82a171 100644 --- a/storage/innobase/fsp/fsp0file.cc +++ b/storage/innobase/fsp/fsp0file.cc @@ -278,7 +278,7 @@ Datafile::set_name(const char* name) /** Reads a few significant fields from the first page of the first datafile. The Datafile must already be open. @param[in] read_only_mode If true, then readonly mode checks are enforced. -@return DB_SUCCESS or DB_IO_ERROR if page cannot be read */ +@return DB_SUCCESS or a DB_* error if page cannot be read */ dberr_t Datafile::read_first_page(bool read_only_mode) { @@ -294,7 +294,10 @@ Datafile::read_first_page(bool read_only_mode) /* Align the memory for a possible read from a raw device */ m_first_page = static_cast<byte*>( - aligned_malloc(UNIV_PAGE_SIZE_MAX, srv_page_size)); + my_malloc_aligned(UNIV_PAGE_SIZE_MAX, srv_page_size)); + if (!m_first_page) { + return DB_OUT_OF_MEMORY; + } dberr_t err = DB_ERROR; size_t page_size = UNIV_PAGE_SIZE_MAX; @@ -376,7 +379,7 @@ Datafile::read_first_page(bool read_only_mode) /** Free the first page from memory when it is no longer needed. */ void Datafile::free_first_page() { - aligned_free(m_first_page); + my_free_aligned(m_first_page); m_first_page= nullptr; } @@ -654,7 +657,11 @@ Datafile::find_space_id() << ". Pages to analyze:" << page_count; byte* page = static_cast<byte*>( - aligned_malloc(page_size, page_size)); + my_malloc_aligned(page_size, page_size)); + if (!page) { + ib::error() << "Could not allocate memory"; + return DB_OUT_OF_MEMORY; + } ulint fsp_flags; /* provide dummy value if the first os_file_read() fails */ @@ -720,7 +727,7 @@ Datafile::find_space_id() } } - aligned_free(page); + my_free_aligned(page); ib::info() << "Page size: " << page_size diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index 12fb139f1bf..ef2fee09b58 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -511,27 +511,6 @@ buf_page_is_corrupted( ulint fsp_flags) MY_ATTRIBUTE((warn_unused_result)); -inline void *aligned_malloc(size_t size, size_t align) -{ -#ifdef _MSC_VER - return _aligned_malloc(size, align); -#else - void *result; - if (posix_memalign(&result, align, size)) - result= NULL; - return result; -#endif -} - -inline void aligned_free(void *ptr) -{ -#ifdef _MSC_VER - _aligned_free(ptr); -#else - free(ptr); -#endif -} - /** Read the key version from the page. In full crc32 format, key version is stored at {0-3th} bytes. In other format, it is stored in 26th position. @@ -739,7 +718,7 @@ public: { if (!crypt_buf) crypt_buf= static_cast<byte*> - (aligned_malloc(srv_page_size, srv_page_size)); + (my_malloc_aligned(srv_page_size, srv_page_size)); } }; @@ -1840,11 +1819,12 @@ public: hash_cell_t *array; /** Create the hash table. - @param n the lower bound of n_cells */ - void create(ulint n); + @param n the lower bound of n_cells + @return array pointer to start of lower bound */ + hash_cell_t *create(ulint n); /** Free the hash table. */ - void free() { aligned_free(array); array= nullptr; } + void free() { my_free_aligned(array); array= nullptr; } /** @return the index of an array element */ ulint calc_hash(ulint fold) const { return calc_hash(fold, n_cells); } @@ -2080,8 +2060,8 @@ private: { for (buf_tmp_buffer_t *s= slots, *e= slots + n_slots; s != e; s++) { - aligned_free(s->crypt_buf); - aligned_free(s->comp_buf); + my_free_aligned(s->crypt_buf); + my_free_aligned(s->comp_buf); } ut_free(slots); slots= nullptr; diff --git a/storage/innobase/os/os0file.cc b/storage/innobase/os/os0file.cc index 982380b93fb..215b8025a9d 100644 --- a/storage/innobase/os/os0file.cc +++ b/storage/innobase/os/os0file.cc @@ -3640,10 +3640,12 @@ fallback: << srv_page_size_shift; /* Align the buffer for possible raw i/o */ - byte* buf = static_cast<byte*>(aligned_malloc(buf_size, - srv_page_size)); - /* Write buffer full of zeros */ - memset(buf, 0, buf_size); + byte* buf = static_cast<byte*>(my_calloc_aligned(buf_size, + srv_page_size)); + if (!buf) { + errno = ENOMEM; + return false; + } os_offset_t current_size = os_file_get_size(file); @@ -3666,7 +3668,7 @@ fallback: current_size += n_bytes; } - aligned_free(buf); + my_free_aligned(buf); return(current_size >= size && os_file_flush(file)); } @@ -3940,9 +3942,15 @@ static bool is_linux_native_aio_supported() memset(&io_event, 0x0, sizeof(io_event)); - byte* ptr = static_cast<byte*>(aligned_malloc(srv_page_size, - srv_page_size)); + byte* ptr = static_cast<byte*>(my_malloc_aligned(srv_page_size, + srv_page_size)); + if (!ptr) { + ib::warn() + << "Could not allocate memory to test AIO"; + my_close(fd, MYF(MY_WME)); + return false; + } struct iocb iocb; /* Suppress valgrind warning. */ @@ -3969,7 +3977,7 @@ static bool is_linux_native_aio_supported() err = io_getevents(io_ctx, 1, 1, &io_event, NULL); } - aligned_free(ptr); + my_free_aligned(ptr); my_close(fd, MYF(MY_WME)); switch (err) { @@ -4493,12 +4501,12 @@ bool fil_node_t::read_page0() return false; } - page_t *page= static_cast<byte*>(aligned_malloc(psize, psize)); + page_t *page= static_cast<byte*>(my_malloc_aligned(psize, psize)); if (os_file_read(IORequestRead, handle, page, 0, psize) != DB_SUCCESS) { ib::error() << "Unable to read first page of file " << name; corrupted: - aligned_free(page); + my_free_aligned(page); return false; } @@ -4542,7 +4550,7 @@ invalid: space->crypt_data = fil_space_read_crypt_data( fil_space_t::zip_size(flags), page); } - aligned_free(page); + my_free_aligned(page); if (UNIV_UNLIKELY(space_id != space->id)) { ib::error() << "Expected tablespace id " << space->id diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc index 12c8731ed3d..d04f5c557e9 100644 --- a/storage/innobase/page/page0zip.cc +++ b/storage/innobase/page/page0zip.cc @@ -3345,9 +3345,13 @@ page_zip_validate_low( /* page_zip_decompress() expects the uncompressed page to be srv_page_size aligned. */ - page_t* temp_page = static_cast<byte*>(aligned_malloc(srv_page_size, + page_t* temp_page = static_cast<byte*>(my_malloc_aligned(srv_page_size, srv_page_size)); + if (!temp_page) { + page_zip_fail(("page_zip_validate: couldn't allocate memory\n")); + return(FALSE); + } MEM_CHECK_DEFINED(page, srv_page_size); MEM_CHECK_DEFINED(page_zip->data, page_zip_get_size(page_zip)); @@ -3503,7 +3507,7 @@ func_exit: page_zip_hexdump(page, srv_page_size); page_zip_hexdump(temp_page, srv_page_size); } - aligned_free(temp_page); + my_free_aligned(temp_page); return(valid); } diff --git a/storage/innobase/row/row0ftsort.cc b/storage/innobase/row/row0ftsort.cc index baf63650347..f79db690e4f 100644 --- a/storage/innobase/row/row0ftsort.cc +++ b/storage/innobase/row/row0ftsort.cc @@ -255,7 +255,7 @@ row_fts_psort_info_init( /* Need to align memory for O_DIRECT write */ psort_info[j].merge_block[i] = static_cast<row_merge_block_t*>( - aligned_malloc(block_size, 1024)); + my_malloc_aligned(block_size, 1024)); if (!psort_info[j].merge_block[i]) { ret = FALSE; @@ -268,8 +268,8 @@ row_fts_psort_info_init( /* Need to align memory for O_DIRECT write */ psort_info[j].crypt_block[i] = static_cast<row_merge_block_t*>( - aligned_malloc(block_size, - 1024)); + my_malloc_aligned(block_size, + 1024)); if (!psort_info[j].crypt_block[i]) { ret = FALSE; @@ -327,9 +327,9 @@ row_fts_psort_info_destroy( psort_info[j].merge_file[i]); } - aligned_free(psort_info[j].merge_block[i]); + my_free_aligned(psort_info[j].merge_block[i]); ut_free(psort_info[j].merge_file[i]); - aligned_free(psort_info[j].crypt_block[i]); + my_free_aligned(psort_info[j].crypt_block[i]); } mutex_free(&psort_info[j].mutex); diff --git a/storage/innobase/row/row0import.cc b/storage/innobase/row/row0import.cc index 8376fbb4ba6..96ee1689256 100644 --- a/storage/innobase/row/row0import.cc +++ b/storage/innobase/row/row0import.cc @@ -3746,11 +3746,20 @@ fil_tablespace_iterate( can determine the page size and zip_size (if it is compressed). We allocate an extra page in case it is a compressed table. */ - byte* page = static_cast<byte*>(aligned_malloc(2 * srv_page_size, - srv_page_size)); - + byte* page = static_cast<byte*>(my_malloc_aligned(2 * srv_page_size, + srv_page_size)); buf_block_t* block = reinterpret_cast<buf_block_t*> (ut_zalloc_nokey(sizeof *block)); + + if (!page) { + err = DB_OUT_OF_MEMORY; + goto cleanup_file; + } + if (!block) { + err = DB_OUT_OF_MEMORY; + goto cleanup_page; + } + block->frame = page; block->page.init(BUF_BLOCK_FILE_PAGE, page_id_t(~0ULL), 1); @@ -3794,30 +3803,34 @@ fil_tablespace_iterate( /* Add an extra page for compressed page scratch area. */ iter.io_buffer = static_cast<byte*>( - aligned_malloc((1 + iter.n_io_buffers) - << srv_page_size_shift, srv_page_size)); + my_malloc_aligned((1 + iter.n_io_buffers) + << srv_page_size_shift, srv_page_size)); iter.crypt_io_buffer = iter.crypt_data ? static_cast<byte*>( - aligned_malloc((1 + iter.n_io_buffers) - << srv_page_size_shift, - srv_page_size)) + my_malloc_aligned((1 + iter.n_io_buffers) + << srv_page_size_shift, + srv_page_size)) : NULL; - if (block->page.zip.ssize) { - ut_ad(iter.n_io_buffers == 1); - block->frame = iter.io_buffer; - block->page.zip.data = block->frame + srv_page_size; - } + if (!iter.io_buffer || (iter.crypt_data && !iter.crypt_io_buffer)) { + err = DB_OUT_OF_MEMORY; + } else { + if (block->page.zip.ssize) { + ut_ad(iter.n_io_buffers == 1); + block->frame = iter.io_buffer; + block->page.zip.data = block->frame + srv_page_size; + } - err = fil_iterate(iter, block, callback); + err = fil_iterate(iter, block, callback); - if (iter.crypt_data) { - fil_space_destroy_crypt_data(&iter.crypt_data); + if (iter.crypt_data) { + fil_space_destroy_crypt_data(&iter.crypt_data); + } } - aligned_free(iter.crypt_io_buffer); - aligned_free(iter.io_buffer); + my_free_aligned(iter.crypt_io_buffer); + my_free_aligned(iter.io_buffer); } if (err == DB_SUCCESS) { @@ -3831,11 +3844,17 @@ fil_tablespace_iterate( } } + ut_free(block); + +cleanup_page: + + my_free_aligned(page); + +cleanup_file: + os_file_close(file); - aligned_free(page); ut_free(filepath); - ut_free(block); return(err); } diff --git a/storage/innobase/srv/srv0start.cc b/storage/innobase/srv/srv0start.cc index 9ea554ec622..e26ec95ba55 100644 --- a/storage/innobase/srv/srv0start.cc +++ b/storage/innobase/srv/srv0start.cc @@ -515,14 +515,19 @@ static ulint srv_undo_tablespace_open(bool create, const char* name, ulint i) if (!create) { - page_t *page= static_cast<byte*>(aligned_malloc(srv_page_size, - srv_page_size)); + page_t *page= static_cast<byte*>(my_malloc_aligned(srv_page_size, + srv_page_size)); + if (!page) { + ib::error() << "Unable to allocate " << srv_page_size << " bytes"; + return 0; + } + dberr_t err= os_file_read(IORequestRead, fh, page, 0, srv_page_size); if (err != DB_SUCCESS) { err_exit: ib::error() << "Unable to read first page of file " << name; - aligned_free(page); + my_free_aligned(page); return err; } @@ -546,7 +551,7 @@ err_exit: space_id= id; snprintf(undo_name, sizeof undo_name, "innodb_undo%03u", id); - aligned_free(page); + my_free_aligned(page); } /* Load the tablespace into InnoDB's internal data structures. */ |